Skip to content

Commit

Permalink
Add a 'quit' parameter to 'close' event cb
Browse files Browse the repository at this point in the history
On OSX, when user hit 'Cmd-Q', the close event is
sent with a 'quit' parameter to distinguish with
other cases for closing window

Fix #430
  • Loading branch information
rogerwang committed Dec 27, 2013
1 parent a0de620 commit e342d2c
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/api/app/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ void App::Call(Shell* shell,
}

// static
void App::CloseAllWindows(bool force) {
void App::CloseAllWindows(bool force, bool quit) {
std::vector<Shell*> windows = Shell::windows();

for (size_t i = 0; i < windows.size(); ++i) {
// Only send close event to browser windows, since devtools windows will
// be automatically closed.
if (!windows[i]->is_devtools()) {
// If there is no js object bound to the window, then just close.
if (force || windows[i]->ShouldCloseWindow())
if (force || windows[i]->ShouldCloseWindow(quit))
// we used to delete the Shell object here
// but it should be deleted on native window destruction
windows[i]->window()->Close();
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class App {
base::ListValue* result);

// Try to close all windows (then will cause whole app to quit).
static void CloseAllWindows(bool force = false);
static void CloseAllWindows(bool force = false, bool quit = false);

// Quit the whole app.
static void Quit(content::RenderProcessHost* rph = NULL);
Expand Down
6 changes: 3 additions & 3 deletions src/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ @interface ShellNSWindow : ChromeEventProcessingWindow {
}
- (void)setShell:(const base::WeakPtr<content::Shell>&)shell;
- (void)showDevTools:(id)sender;
- (void)closeAllWindows:(id)sender;
- (void)closeAllWindowsQuit:(id)sender;
@end

@implementation ShellNSWindow
Expand All @@ -249,8 +249,8 @@ - (void)showDevTools:(id)sender {
shell_->ShowDevTools();
}

- (void)closeAllWindows:(id)sender {
nwapi::App::CloseAllWindows();
- (void)closeAllWindowsQuit:(id)sender {
nwapi::App::CloseAllWindows(false, true);
}

- (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen
Expand Down
2 changes: 1 addition & 1 deletion src/browser/standard_menus_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ - (void)setAppleMenu:(NSMenu *)menu;
[appleMenu addItem:[NSMenuItem separatorItem]];

[appleMenu addItemWithTitle:l10n_util::GetNSStringFWithFixup(IDS_EXIT_MAC, name)
action:@selector(closeAllWindows:)
action:@selector(closeAllWindowsQuit:)
keyEquivalent:@"q"];

// Add to menubar.
Expand Down
4 changes: 2 additions & 2 deletions src/nw_shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ void Shell::SendEvent(const std::string& event, const base::ListValue& args) {
web_contents->GetRoutingID(), id(), event, args));
}

bool Shell::ShouldCloseWindow() {
bool Shell::ShouldCloseWindow(bool quit) {
if (id() < 0 || force_close_)
return true;

SendEvent("close");
SendEvent("close", quit ? "quit" : "");
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/nw_shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class Shell : public WebContentsDelegate,
void SendEvent(const std::string& event, const base::ListValue& args);

// Decide whether we should close the window.
bool ShouldCloseWindow();
bool ShouldCloseWindow(bool quit = false);

virtual GURL OverrideDOMStorageOrigin(const GURL& origin);

Expand Down

0 comments on commit e342d2c

Please sign in to comment.