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/command_line.h" | |
| 11 #include "base/logging.h" | 10 #include "base/logging.h" |
| 12 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 13 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 14 #include "base/mac/scoped_nsautorelease_pool.h" | 13 #include "base/mac/scoped_nsautorelease_pool.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 16 #include "chrome/app/chrome_command_ids.h" // IDC_* | 15 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| 17 #include "chrome/browser/chrome_browser_application_mac.h" | 16 #include "chrome/browser/chrome_browser_application_mac.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #import "chrome/browser/ui/cocoa/browser_command_executor.h" | 18 #import "chrome/browser/ui/cocoa/browser_command_executor.h" |
| 20 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 19 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 21 #import "chrome/browser/ui/cocoa/panels/mouse_drag_controller.h" | 20 #import "chrome/browser/ui/cocoa/panels/mouse_drag_controller.h" |
| 22 #import "chrome/browser/ui/cocoa/panels/panel_cocoa.h" | 21 #import "chrome/browser/ui/cocoa/panels/panel_cocoa.h" |
| 23 #import "chrome/browser/ui/cocoa/panels/panel_titlebar_view_cocoa.h" | 22 #import "chrome/browser/ui/cocoa/panels/panel_titlebar_view_cocoa.h" |
| 24 #import "chrome/browser/ui/cocoa/panels/panel_utils_cocoa.h" | 23 #import "chrome/browser/ui/cocoa/panels/panel_utils_cocoa.h" |
| 25 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" | 24 #import "chrome/browser/ui/cocoa/tab_contents/favicon_util_mac.h" |
| 26 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" | 25 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" |
| 27 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" | 26 #import "chrome/browser/ui/cocoa/tabs/throbber_view.h" |
| 28 #include "chrome/browser/ui/panels/panel_bounds_animation.h" | 27 #include "chrome/browser/ui/panels/panel_bounds_animation.h" |
| 29 #include "chrome/browser/ui/panels/panel_collection.h" | 28 #include "chrome/browser/ui/panels/panel_collection.h" |
| 30 #include "chrome/browser/ui/panels/panel_constants.h" | 29 #include "chrome/browser/ui/panels/panel_constants.h" |
| 31 #include "chrome/browser/ui/panels/panel_manager.h" | 30 #include "chrome/browser/ui/panels/panel_manager.h" |
| 32 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 31 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 33 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 32 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
| 34 #include "chrome/common/chrome_version_info.h" | |
| 35 #include "content/public/browser/render_widget_host_view.h" | 33 #include "content/public/browser/render_widget_host_view.h" |
| 36 #include "content/public/browser/web_contents.h" | 34 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/browser/web_contents_view.h" | 35 #include "content/public/browser/web_contents_view.h" |
| 38 #include "grit/ui_resources.h" | 36 #include "grit/ui_resources.h" |
| 39 #include "third_party/WebKit/public/web/WebCursorInfo.h" | 37 #include "third_party/WebKit/public/web/WebCursorInfo.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 38 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
| 42 #include "webkit/common/cursors/webcursor.h" | 40 #include "webkit/common/cursors/webcursor.h" |
| 43 | 41 |
| 44 using content::WebContents; | 42 using content::WebContents; |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 // message, since it just means that a menu extra (on the "system status bar") | 800 // message, since it just means that a menu extra (on the "system status bar") |
| 803 // was activated; we'll get another |-windowDidResignKey| if we ever really | 801 // was activated; we'll get another |-windowDidResignKey| if we ever really |
| 804 // lose key window status. | 802 // lose key window status. |
| 805 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) | 803 if ([NSApp isActive] && ([NSApp keyWindow] == [self window])) |
| 806 return; | 804 return; |
| 807 | 805 |
| 808 [self onWindowDidResignKey]; | 806 [self onWindowDidResignKey]; |
| 809 } | 807 } |
| 810 | 808 |
| 811 - (void)windowDidResize:(NSNotification*)notification { | 809 - (void)windowDidResize:(NSNotification*)notification { |
| 812 // This is a temporary check to track down a crash that occurs occasionally | 810 // Remove the web contents view from the view hierarchy when the panel is not |
| 813 // (http://crbug.com/265932). | 811 // taller than the titlebar. Put it back when the panel grows taller than |
| 814 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); | 812 // the titlebar. Note that RenderWidgetHostViewMac works for the case that |
| 815 if (channel == chrome::VersionInfo::CHANNEL_CANARY && | 813 // the web contents view does not exist in the view hierarchy (i.e. the tab |
| 816 CommandLine::ForCurrentProcess()->HasSwitch("enable-panel-experiment")) | 814 // is not the main one), but it does not work well, like occasional crashes, |
| 815 // if the web contents view is made hidden. | |
|
Dmitry Titov
2013/08/12 23:04:45
lets put a bug number here, for reference to those
jianli
2013/08/12 23:43:14
Done.
| |
| 816 // | |
| 817 // The reason for doing this is to ensure that our titlebar view, that is | |
| 818 // somewhat taller than the standard titlebar, does not overlap with the web | |
| 819 // contents view because the the web contents view assumes that its view will | |
| 820 // never overlap with another view in order to perform optimization. If we do | |
|
Dmitry Titov
2013/08/12 23:04:45
"in order to perform optimization" is unclear. Do
jianli
2013/08/12 23:43:14
Updated comment.
| |
| 821 // not do this, some part of the web contents view will become visible and | |
| 822 // overlapp the bottom area of the titlebar. | |
| 823 content::WebContents* webContents = windowShim_->panel()->GetWebContents(); | |
| 824 if (!webContents) | |
| 817 return; | 825 return; |
| 818 // Hide the web contents view when the panel is not taller than the titlebar. | 826 NSView* contentView = webContents->GetView()->GetNativeView(); |
| 819 // This is to ensure that the titlebar view is not overlapped with the web | 827 if (NSHeight([self contentRectForFrameRect:[[self window] frame]]) <= |
| 820 // contents view because the the web contents view assumes that its | 828 panel::kTitlebarHeight) { |
|
Dmitry Titov
2013/08/12 23:04:45
This condition happens when titlebar is all we can
jianli
2013/08/12 23:43:14
When we minimize a panel, the window is being anim
| |
| 821 // view will never be overlapped by another view in order to perform | 829 // No need to retain the view before it is removed from its superview |
| 822 // optimization. If we do not do this, some part of the web contents view | 830 // because WebContentsView keeps a reference to this view. |
| 823 // will become visible and overlapp the bottom area of the titlebar. | 831 if ([contentView superview]) |
| 824 if (WebContents* contents = windowShim_->panel()->GetWebContents()) { | 832 [contentView removeFromSuperview]; |
| 825 BOOL hideContents = | 833 } else { |
| 826 NSHeight([self contentRectForFrameRect:[[self window] frame]]) <= | 834 if (![contentView superview]) |
| 827 panel::kTitlebarHeight; | 835 [[[self window] contentView] addSubview:contentView]; |
|
Dmitry Titov
2013/08/12 23:04:45
Perhaps enableWebContentsViewAutosizing should be
jianli
2013/08/12 23:43:14
We can't enable the autosizing for the web content
| |
| 828 [contents->GetView()->GetNativeView() setHidden:hideContents]; | |
| 829 } | 836 } |
| 830 } | 837 } |
| 831 | 838 |
| 832 - (void)activate { | 839 - (void)activate { |
| 833 // Activate the window. -|windowDidBecomeKey:| will be called when | 840 // Activate the window. -|windowDidBecomeKey:| will be called when |
| 834 // window becomes active. | 841 // window becomes active. |
| 835 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true); | 842 base::AutoReset<BOOL> pin(&activationRequestedByPanel_, true); |
| 836 [BrowserWindowUtils activateWindowForController:self]; | 843 [BrowserWindowUtils activateWindowForController:self]; |
| 837 } | 844 } |
| 838 | 845 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 975 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 982 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 976 NSRect contentRect = [[[self window] contentView] convertRect:frameRect | 983 NSRect contentRect = [[[self window] contentView] convertRect:frameRect |
| 977 fromView:nil]; | 984 fromView:nil]; |
| 978 contentRect.size.height -= panel::kTitlebarHeight; | 985 contentRect.size.height -= panel::kTitlebarHeight; |
| 979 if (contentRect.size.height < 0) | 986 if (contentRect.size.height < 0) |
| 980 contentRect.size.height = 0; | 987 contentRect.size.height = 0; |
| 981 return contentRect; | 988 return contentRect; |
| 982 } | 989 } |
| 983 | 990 |
| 984 @end | 991 @end |
| OLD | NEW |