Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 - (int)titlebarHeightInScreenCoordinates { | 581 - (int)titlebarHeightInScreenCoordinates { |
| 582 NSView* titlebar = [self titlebarView]; | 582 NSView* titlebar = [self titlebarView]; |
| 583 return NSHeight([titlebar convertRect:[titlebar bounds] toView:nil]); | 583 return NSHeight([titlebar convertRect:[titlebar bounds] toView:nil]); |
| 584 } | 584 } |
| 585 | 585 |
| 586 // TODO(dcheng): These two selectors are almost copy-and-paste from | 586 // TODO(dcheng): These two selectors are almost copy-and-paste from |
| 587 // BrowserWindowController. Figure out the appropriate way of code sharing, | 587 // BrowserWindowController. Figure out the appropriate way of code sharing, |
| 588 // whether it's refactoring more things into BrowserWindowUtils or making a | 588 // whether it's refactoring more things into BrowserWindowUtils or making a |
| 589 // common base controller for browser windows. | 589 // common base controller for browser windows. |
| 590 - (void)windowDidBecomeKey:(NSNotification*)notification { | 590 - (void)windowDidBecomeKey:(NSNotification*)notification { |
| 591 // Prevent the minimized panel from invoking any activation logic. This is | |
|
Dmitry Titov
2014/05/16 16:37:38
I'm not sure I understand the change being made. I
jianli
2014/05/20 00:56:00
We do instruct canBecomeKeyWindow to return NO bu
| |
| 592 // because Cocoa does not support deactivating a window and it could still | |
| 593 // try to activate the minimized panel window. | |
| 594 if (windowShim_->panel()->IsMinimized()) | |
| 595 return; | |
| 596 | |
| 591 // We need to activate the controls (in the "WebView"). To do this, get the | 597 // We need to activate the controls (in the "WebView"). To do this, get the |
| 592 // selected WebContents's RenderWidgetHostView and tell it to activate. | 598 // selected WebContents's RenderWidgetHostView and tell it to activate. |
| 593 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { | 599 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { |
| 594 if (content::RenderWidgetHostView* rwhv = | 600 if (content::RenderWidgetHostView* rwhv = |
| 595 contents->GetRenderWidgetHostView()) | 601 contents->GetRenderWidgetHostView()) |
| 596 rwhv->SetActive(true); | 602 rwhv->SetActive(true); |
| 597 } | 603 } |
| 598 | 604 |
| 599 windowShim_->panel()->OnActiveStateChanged(true); | 605 windowShim_->panel()->OnActiveStateChanged(true); |
| 600 | 606 |
| 601 // Make the window user-resizable when it gains the focus. | 607 // Make the window user-resizable when it gains the focus. |
| 602 [[self window] setStyleMask: | 608 [[self window] setStyleMask: |
| 603 [[self window] styleMask] | NSResizableWindowMask]; | 609 [[self window] styleMask] | NSResizableWindowMask]; |
| 604 } | 610 } |
| 605 | 611 |
| 606 - (void)windowDidResignKey:(NSNotification*)notification { | 612 - (void)windowDidResignKey:(NSNotification*)notification { |
| 607 // If our app is still active and we're still the key window, ignore this | 613 // If our app is still active and we're still the key window, ignore this |
| 608 // message, since it just means that a menu extra (on the "system status bar") | 614 // message, since it just means that a menu extra (on the "system status bar") |
| 609 // was activated; we'll get another |-windowDidResignKey| if we ever really | 615 // was activated; we'll get another |-windowDidResignKey| if we ever really |
| 610 // lose key window status. | 616 // lose key window status. |
| 611 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) | 617 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) |
| 612 return; | 618 return; |
| 613 | 619 |
| 614 [self onWindowDidResignKey]; | 620 [self onWindowDidResignKey]; |
| 615 | |
| 616 // Make the window not user-resizable when it loses the focus. This is to | |
| 617 // solve the problem that the bottom edge of the active panel does not | |
| 618 // trigger the user-resizing if this panel stacks with another inactive | |
| 619 // panel at the bottom. | |
| 620 [[self window] setStyleMask: | |
| 621 [[self window] styleMask] & ~NSResizableWindowMask]; | |
| 622 } | 621 } |
| 623 | 622 |
| 624 - (void)windowWillStartLiveResize:(NSNotification*)notification { | 623 - (void)windowWillStartLiveResize:(NSNotification*)notification { |
| 625 // Check if the user-resizing is allowed for the triggering edge/corner. | 624 // Check if the user-resizing is allowed for the triggering edge/corner. |
| 626 // This is an extra safe guard because we are not able to track the mouse | 625 // This is an extra safe guard because we are not able to track the mouse |
| 627 // movement outside the window and Cocoa could trigger the user-resizing | 626 // movement outside the window and Cocoa could trigger the user-resizing |
| 628 // when the mouse moves a bit outside the edge/corner. | 627 // when the mouse moves a bit outside the edge/corner. |
| 629 if (![self canResizeByMouseAtCurrentLocation]) | 628 if (![self canResizeByMouseAtCurrentLocation]) |
| 630 return; | 629 return; |
| 631 userResizing_ = YES; | 630 userResizing_ = YES; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 734 - (void)onWindowDidResignKey { | 733 - (void)onWindowDidResignKey { |
| 735 // We need to deactivate the controls (in the "WebView"). To do this, get the | 734 // We need to deactivate the controls (in the "WebView"). To do this, get the |
| 736 // selected WebContents's RenderWidgetHostView and tell it to deactivate. | 735 // selected WebContents's RenderWidgetHostView and tell it to deactivate. |
| 737 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { | 736 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { |
| 738 if (content::RenderWidgetHostView* rwhv = | 737 if (content::RenderWidgetHostView* rwhv = |
| 739 contents->GetRenderWidgetHostView()) | 738 contents->GetRenderWidgetHostView()) |
| 740 rwhv->SetActive(false); | 739 rwhv->SetActive(false); |
| 741 } | 740 } |
| 742 | 741 |
| 743 windowShim_->panel()->OnActiveStateChanged(false); | 742 windowShim_->panel()->OnActiveStateChanged(false); |
| 743 | |
| 744 // Make the window not user-resizable when it loses the focus. This is to | |
| 745 // solve the problem that the bottom edge of the active panel does not | |
| 746 // trigger the user-resizing if this panel stacks with another inactive | |
| 747 // panel at the bottom. | |
| 748 [[self window] setStyleMask: | |
| 749 [[self window] styleMask] & ~NSResizableWindowMask]; | |
| 744 } | 750 } |
| 745 | 751 |
| 746 - (void)preventBecomingKeyWindow:(BOOL)prevent { | 752 - (void)preventBecomingKeyWindow:(BOOL)prevent { |
| 747 canBecomeKeyWindow_ = !prevent; | 753 canBecomeKeyWindow_ = !prevent; |
| 748 } | 754 } |
| 749 | 755 |
| 750 - (void)fullScreenModeChanged:(bool)isFullScreen { | 756 - (void)fullScreenModeChanged:(bool)isFullScreen { |
| 751 [self updateWindowLevel]; | 757 [self updateWindowLevel]; |
| 752 | 758 |
| 753 // If the panel is not always on top, its z-order should not be affected if | 759 // 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 Loading... | |
| 909 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 915 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 910 NSRect contentRect = [[[self window] contentView] convertRect:frameRect | 916 NSRect contentRect = [[[self window] contentView] convertRect:frameRect |
| 911 fromView:nil]; | 917 fromView:nil]; |
| 912 contentRect.size.height -= panel::kTitlebarHeight; | 918 contentRect.size.height -= panel::kTitlebarHeight; |
| 913 if (contentRect.size.height < 0) | 919 if (contentRect.size.height < 0) |
| 914 contentRect.size.height = 0; | 920 contentRect.size.height = 0; |
| 915 return contentRect; | 921 return contentRect; |
| 916 } | 922 } |
| 917 | 923 |
| 918 @end | 924 @end |
| OLD | NEW |