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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.h" 5 #include "chrome/browser/ui/cocoa/panels/panel_window_controller_cocoa.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 [controller activationRequestedByPanel] || 89 [controller activationRequestedByPanel] ||
90 [app isCyclingWindows] || 90 [app isCyclingWindows] ||
91 [app previousKeyWindow] == self || 91 [app previousKeyWindow] == self ||
92 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]); 92 [[app windows] count] == static_cast<NSUInteger>([controller numPanels]);
93 } 93 }
94 94
95 - (void)performMiniaturize:(id)sender { 95 - (void)performMiniaturize:(id)sender {
96 [[self windowController] minimizeButtonClicked:0]; 96 [[self windowController] minimizeButtonClicked:0];
97 } 97 }
98 98
99 // Ignore key events if window cannot become key window to fix problem
100 // where keyboard input is still going into a minimized panel even though
101 // the app has been deactivated in -[PanelWindowControllerCocoa deactivate:].
102 - (void)sendEvent:(NSEvent*)anEvent {
103 NSEventType eventType = [anEvent type];
104 if ((eventType == NSKeyDown || eventType == NSKeyUp) &&
105 ![self canBecomeKeyWindow])
106 return;
107 [super sendEvent:anEvent];
108 }
109
110 - (void)mouseMoved:(NSEvent*)event { 99 - (void)mouseMoved:(NSEvent*)event {
111 // Cocoa does not support letting the application determine the edges that 100 // Cocoa does not support letting the application determine the edges that
112 // can trigger the user resizing. To work around this, we track the mouse 101 // can trigger the user resizing. To work around this, we track the mouse
113 // location. When it is close to the edge/corner where the user resizing 102 // location. When it is close to the edge/corner where the user resizing
114 // is not desired, we force the min and max size of the window to be same 103 // is not desired, we force the min and max size of the window to be same
115 // as current window size. For all other cases, we restore the min and max 104 // as current window size. For all other cases, we restore the min and max
116 // size. 105 // size.
117 PanelWindowControllerCocoa* controller = 106 PanelWindowControllerCocoa* controller =
118 base::mac::ObjCCast<PanelWindowControllerCocoa>([self windowController]); 107 base::mac::ObjCCast<PanelWindowControllerCocoa>([self windowController]);
119 NSRect frame = [self frame]; 108 NSRect frame = [self frame];
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 593
605 - (void)windowDidResignKey:(NSNotification*)notification { 594 - (void)windowDidResignKey:(NSNotification*)notification {
606 // If our app is still active and we're still the key window, ignore this 595 // If our app is still active and we're still the key window, ignore this
607 // message, since it just means that a menu extra (on the "system status bar") 596 // message, since it just means that a menu extra (on the "system status bar")
608 // was activated; we'll get another |-windowDidResignKey| if we ever really 597 // was activated; we'll get another |-windowDidResignKey| if we ever really
609 // lose key window status. 598 // lose key window status.
610 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) 599 if ([NSApp isActive] && ([NSApp keyWindow] == [self window]))
611 return; 600 return;
612 601
613 [self onWindowDidResignKey]; 602 [self onWindowDidResignKey];
614
615 // Make the window not user-resizable when it loses the focus. This is to
616 // solve the problem that the bottom edge of the active panel does not
617 // trigger the user-resizing if this panel stacks with another inactive
618 // panel at the bottom.
619 [[self window] setStyleMask:
620 [[self window] styleMask] & ~NSResizableWindowMask];
621 } 603 }
622 604
623 - (void)windowWillStartLiveResize:(NSNotification*)notification { 605 - (void)windowWillStartLiveResize:(NSNotification*)notification {
624 // Check if the user-resizing is allowed for the triggering edge/corner. 606 // Check if the user-resizing is allowed for the triggering edge/corner.
625 // This is an extra safe guard because we are not able to track the mouse 607 // This is an extra safe guard because we are not able to track the mouse
626 // movement outside the window and Cocoa could trigger the user-resizing 608 // movement outside the window and Cocoa could trigger the user-resizing
627 // when the mouse moves a bit outside the edge/corner. 609 // when the mouse moves a bit outside the edge/corner.
628 if (![self canResizeByMouseAtCurrentLocation]) 610 if (![self canResizeByMouseAtCurrentLocation])
629 return; 611 return;
630 userResizing_ = YES; 612 userResizing_ = YES;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 // Activate the window. -|windowDidBecomeKey:| will be called when 698 // Activate the window. -|windowDidBecomeKey:| will be called when
717 // window becomes active. 699 // window becomes active.
718 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true); 700 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true);
719 [BrowserWindowUtils activateWindowForController:self]; 701 [BrowserWindowUtils activateWindowForController:self];
720 } 702 }
721 703
722 - (void)deactivate { 704 - (void)deactivate {
723 if (![[self window] isMainWindow]) 705 if (![[self window] isMainWindow])
724 return; 706 return;
725 707
726 // Cocoa does not support deactivating a window, so we deactivate the app.
727 [NSApp deactivate]; 708 [NSApp deactivate];
728 709
729 // Deactivating the app does not trigger windowDidResignKey. Do it manually. 710 // Cocoa does not support deactivating a NSWindow explicitly. To work around
711 // this, we call orderOut and orderFront to force the window to lose its key
712 // window state.
713
714 // Before doing this, we need to disable screen updates to prevent flickering.
715 NSDisableScreenUpdates();
716
717 // If a panel is in stacked mode, the window has a background parent window.
718 // We need to detach it from its parent window before applying the ordering
719 // change and then put it back because otherwise tha background parent window
720 // might show up.
721 NSWindow* parentWindow = [[self window] parentWindow];
722 if (parentWindow)
723 [parentWindow removeChildWindow:[self window]];
724
725 [[self window] orderOut:nil];
726 [[self window] orderFront:nil];
727
728 if (parentWindow)
729 [parentWindow addChildWindow:[self window] ordered:NSWindowAbove];
730
731 NSEnableScreenUpdates();
732
733 // Though the above workaround causes the window to lose its key window state,
734 // it does not trigger the system to call windowDidResignKey.
730 [self onWindowDidResignKey]; 735 [self onWindowDidResignKey];
731 } 736 }
732 737
733 - (void)onWindowDidResignKey { 738 - (void)onWindowDidResignKey {
734 // We need to deactivate the controls (in the "WebView"). To do this, get the 739 // We need to deactivate the controls (in the "WebView"). To do this, get the
735 // selected WebContents's RenderWidgetHostView and tell it to deactivate. 740 // selected WebContents's RenderWidgetHostView and tell it to deactivate.
736 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { 741 if (WebContents* contents = windowShim_->panel()->GetWebContents()) {
737 if (content::RenderWidgetHostView* rwhv = 742 if (content::RenderWidgetHostView* rwhv =
738 contents->GetRenderWidgetHostView()) 743 contents->GetRenderWidgetHostView())
739 rwhv->SetActive(false); 744 rwhv->SetActive(false);
740 } 745 }
741 746
742 windowShim_->panel()->OnActiveStateChanged(false); 747 windowShim_->panel()->OnActiveStateChanged(false);
748
749 // Make the window not user-resizable when it loses the focus. This is to
750 // solve the problem that the bottom edge of the active panel does not
751 // trigger the user-resizing if this panel stacks with another inactive
752 // panel at the bottom.
753 [[self window] setStyleMask:
754 [[self window] styleMask] & ~NSResizableWindowMask];
743 } 755 }
744 756
745 - (void)preventBecomingKeyWindow:(BOOL)prevent { 757 - (void)preventBecomingKeyWindow:(BOOL)prevent {
746 canBecomeKeyWindow_ = !prevent; 758 canBecomeKeyWindow_ = !prevent;
747 } 759 }
748 760
749 - (void)fullScreenModeChanged:(bool)isFullScreen { 761 - (void)fullScreenModeChanged:(bool)isFullScreen {
750 [self updateWindowLevel]; 762 [self updateWindowLevel];
751 763
752 // If the panel is not always on top, its z-order should not be affected if 764 // If the panel is not always on top, its z-order should not be affected if
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { 920 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
909 NSRect contentRect = [[[self window] contentView] convertRect:frameRect 921 NSRect contentRect = [[[self window] contentView] convertRect:frameRect
910 fromView:nil]; 922 fromView:nil];
911 contentRect.size.height -= panel::kTitlebarHeight; 923 contentRect.size.height -= panel::kTitlebarHeight;
912 if (contentRect.size.height < 0) 924 if (contentRect.size.height < 0)
913 contentRect.size.height = 0; 925 contentRect.size.height = 0;
914 return contentRect; 926 return contentRect;
915 } 927 }
916 928
917 @end 929 @end
OLDNEW
« 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