Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5462)

Unified Diff: chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm

Issue 275693002: Fix the bug that minimized panel window might steal focus on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix trybots Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
diff --git a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
index 8337fcf1e940fc4a05b98791732e81dea7e75a93..816e608aa7549c1db9d1d5171cdba45d62463e1f 100644
--- a/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
+++ b/chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.mm
@@ -96,17 +96,6 @@ const double kWidthOfMouseResizeArea = 15.0;
[[self windowController] minimizeButtonClicked:0];
}
-// Ignore key events if window cannot become key window to fix problem
-// where keyboard input is still going into a minimized panel even though
-// the app has been deactivated in -[PanelWindowControllerCocoa deactivate:].
-- (void)sendEvent:(NSEvent*)anEvent {
- NSEventType eventType = [anEvent type];
- if ((eventType == NSKeyDown || eventType == NSKeyUp) &&
- ![self canBecomeKeyWindow])
- return;
- [super sendEvent:anEvent];
-}
-
- (void)mouseMoved:(NSEvent*)event {
// Cocoa does not support letting the application determine the edges that
// can trigger the user resizing. To work around this, we track the mouse
@@ -611,13 +600,6 @@ const double kWidthOfMouseResizeArea = 15.0;
return;
[self onWindowDidResignKey];
-
- // Make the window not user-resizable when it loses the focus. This is to
- // solve the problem that the bottom edge of the active panel does not
- // trigger the user-resizing if this panel stacks with another inactive
- // panel at the bottom.
- [[self window] setStyleMask:
- [[self window] styleMask] & ~NSResizableWindowMask];
}
- (void)windowWillStartLiveResize:(NSNotification*)notification {
@@ -723,10 +705,33 @@ const double kWidthOfMouseResizeArea = 15.0;
if (![[self window] isMainWindow])
return;
- // Cocoa does not support deactivating a window, so we deactivate the app.
[NSApp deactivate];
- // Deactivating the app does not trigger windowDidResignKey. Do it manually.
+ // Cocoa does not support deactivating a NSWindow explicitly. To work around
+ // this, we call orderOut and orderFront to force the window to lose its key
+ // window state.
+
+ // Before doing this, we need to disable screen updates to prevent flickering.
+ NSDisableScreenUpdates();
+
+ // If a panel is in stacked mode, the window has a background parent window.
+ // We need to detach it from its parent window before applying the ordering
+ // change and then put it back because otherwise tha background parent window
+ // might show up.
+ NSWindow* parentWindow = [[self window] parentWindow];
+ if (parentWindow)
+ [parentWindow removeChildWindow:[self window]];
+
+ [[self window] orderOut:nil];
+ [[self window] orderFront:nil];
+
+ if (parentWindow)
+ [parentWindow addChildWindow:[self window] ordered:NSWindowAbove];
+
+ NSEnableScreenUpdates();
+
+ // Though the above workaround causes the window to lose its key window state,
+ // it does not trigger the system to call windowDidResignKey.
[self onWindowDidResignKey];
}
@@ -740,6 +745,13 @@ const double kWidthOfMouseResizeArea = 15.0;
}
windowShim_->panel()->OnActiveStateChanged(false);
+
+ // Make the window not user-resizable when it loses the focus. This is to
+ // solve the problem that the bottom edge of the active panel does not
+ // trigger the user-resizing if this panel stacks with another inactive
+ // panel at the bottom.
+ [[self window] setStyleMask:
+ [[self window] styleMask] & ~NSResizableWindowMask];
}
- (void)preventBecomingKeyWindow:(BOOL)prevent {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698