| 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 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 // message, since it just means that a menu extra (on the "system status bar") | 796 // message, since it just means that a menu extra (on the "system status bar") |
| 797 // was activated; we'll get another |-windowDidResignKey| if we ever really | 797 // was activated; we'll get another |-windowDidResignKey| if we ever really |
| 798 // lose key window status. | 798 // lose key window status. |
| 799 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) | 799 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) |
| 800 return; | 800 return; |
| 801 | 801 |
| 802 [self onWindowDidResignKey]; | 802 [self onWindowDidResignKey]; |
| 803 } | 803 } |
| 804 | 804 |
| 805 - (void)windowDidResize:(NSNotification*)notification { | 805 - (void)windowDidResize:(NSNotification*)notification { |
| 806 // Hide the web contents view when the panel is not taller than the titlebar. | 806 // Remove the web contents view from the view hierarchy when the panel is not |
| 807 // This is to ensure that the titlebar view is not overlapped with the web | 807 // taller than the titlebar. Put it back when the panel grows taller than |
| 808 // contents view because the the web contents view assumes that its | 808 // the titlebar. Note that RenderWidgetHostViewMac works for the case that |
| 809 // view will never be overlapped by another view in order to perform | 809 // the web contents view does not exist in the view hierarchy (i.e. the tab |
| 810 // optimization. If we do not do this, some part of the web contents view | 810 // is not the main one), but it does not work well, like causing occasional |
| 811 // will become visible and overlapp the bottom area of the titlebar. | 811 // crashes (http://crbug.com/265932), if the web contents view is made hidden. |
| 812 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { | 812 // |
| 813 BOOL hideContents = | 813 // The reason for doing this is to ensure that our titlebar view, that is |
| 814 NSHeight([self contentRectForFrameRect:[[self window] frame]]) <= | 814 // somewhat taller than the standard titlebar, does not overlap with the web |
| 815 panel::kTitlebarHeight; | 815 // contents view because the the web contents view assumes that its view will |
| 816 [contents->GetView()->GetNativeView() setHidden:hideContents]; | 816 // never overlap with another view in order to paint the web contents view |
| 817 // directly. If we do not do this, some part of the web contents view will |
| 818 // become visible and overlap the bottom area of the titlebar. |
| 819 content::WebContents* webContents = windowShim_->panel()->GetWebContents(); |
| 820 if (!webContents) |
| 821 return; |
| 822 NSView* contentView = webContents->GetView()->GetNativeView(); |
| 823 if (NSHeight([self contentRectForFrameRect:[[self window] frame]]) <= |
| 824 panel::kTitlebarHeight) { |
| 825 // No need to retain the view before it is removed from its superview |
| 826 // because WebContentsView keeps a reference to this view. |
| 827 if ([contentView superview]) |
| 828 [contentView removeFromSuperview]; |
| 829 } else { |
| 830 if (![contentView superview]) |
| 831 [[[self window] contentView] addSubview:contentView]; |
| 817 } | 832 } |
| 818 } | 833 } |
| 819 | 834 |
| 820 - (void)activate { | 835 - (void)activate { |
| 821 // Activate the window. -|windowDidBecomeKey:| will be called when | 836 // Activate the window. -|windowDidBecomeKey:| will be called when |
| 822 // window becomes active. | 837 // window becomes active. |
| 823 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true); | 838 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true); |
| 824 [BrowserWindowUtils activateWindowForController:self]; | 839 [BrowserWindowUtils activateWindowForController:self]; |
| 825 } | 840 } |
| 826 | 841 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 978 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 964 NSRect contentRect = [[[self window] contentView] convertRect:frameRect | 979 NSRect contentRect = [[[self window] contentView] convertRect:frameRect |
| 965 fromView:nil]; | 980 fromView:nil]; |
| 966 contentRect.size.height -= panel::kTitlebarHeight; | 981 contentRect.size.height -= panel::kTitlebarHeight; |
| 967 if (contentRect.size.height < 0) | 982 if (contentRect.size.height < 0) |
| 968 contentRect.size.height = 0; | 983 contentRect.size.height = 0; |
| 969 return contentRect; | 984 return contentRect; |
| 970 } | 985 } |
| 971 | 986 |
| 972 @end | 987 @end |
| OLD | NEW |