diff options
author | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 21:21:39 +0000 |
---|---|---|
committer | stevenjb@chromium.org <stevenjb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 21:21:39 +0000 |
commit | fde9df6ff7ec8e225f1a68567a4c6ad01322a895 (patch) | |
tree | 4588e81319fedbd717534c242a6201bde918912a /chrome | |
parent | d1ba9e285f600cdee91f92b6837576ecdbff3a2e (diff) | |
download | chromium_src-fde9df6ff7ec8e225f1a68567a4c6ad01322a895.zip chromium_src-fde9df6ff7ec8e225f1a68567a4c6ad01322a895.tar.gz chromium_src-fde9df6ff7ec8e225f1a68567a4c6ad01322a895.tar.bz2 |
Implement Panel::GetDispositionForPopupBounds() and move shared logic to browser_navigator.cc.
This CL is mostly cleanup. There are four places where we need to check the size of popups against a window size to determine whether they should become popups or new tabs:
* BrowserView for Aura
* Panel for Aura
* chromeos::BrowserView
* chromeos::PanelBrowserView
All of these cases except BrowserView will become deprecated soon, so browser_navigator (which calls GetDispositionForPopupBounds) seemed like the right place for the shared logic.
BUG=108363
TEST=See issue for test. Only behavioral change should be for Panel windows on Aura opening large windows with window.open().
Review URL: http://codereview.chromium.org/9020033
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115610 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/chromeos/frame/browser_view.cc | 28 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/browser_view.h | 4 | ||||
-rw-r--r-- | chrome/browser/chromeos/frame/panel_browser_view.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/browser_navigator.cc | 22 | ||||
-rw-r--r-- | chrome/browser/ui/browser_navigator.h | 7 | ||||
-rw-r--r-- | chrome/browser/ui/panels/panel.cc | 14 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 27 |
7 files changed, 56 insertions, 51 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index 0c0f9c6..ca97e16 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -54,10 +54,6 @@ namespace { // Amount to tweak the position of the status area to get it to look right. const int kStatusAreaVerticalAdjustment = -1; -// If a popup window is larger than this fraction of the screen, create a tab. -const float kPopupMaxWidthFactor = 0.5; -const float kPopupMaxHeightFactor = 0.6; - // GDK representation of the _CHROME_STATE X atom. static GdkAtom g_chrome_state_gdk_atom = 0; @@ -455,28 +451,12 @@ void BrowserView::Paste() { gtk_util::DoPaste(this); } -// This is a static function so that the logic can be shared by -// chromeos::PanelBrowserView. -WindowOpenDisposition BrowserView::DispositionForPopupBounds( - const gfx::Rect& bounds) { - // If a popup is larger than a given fraction of the screen, turn it into - // a foreground tab. Also check for width or height == 0, which would - // indicate a tab sized popup window. - GdkScreen* screen = gdk_screen_get_default(); - int max_width = gdk_screen_get_width(screen) * kPopupMaxWidthFactor; - int max_height = gdk_screen_get_height(screen) * kPopupMaxHeightFactor; - if (bounds.width() > max_width || - bounds.width() == 0 || - bounds.height() > max_height || - bounds.height() == 0) { - return NEW_FOREGROUND_TAB; - } - return NEW_POPUP; -} - WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( const gfx::Rect& bounds) { - return DispositionForPopupBounds(bounds); + GdkScreen* screen = gdk_screen_get_default(); + int width = gdk_screen_get_width(screen); + int height = gdk_screen_get_height(screen); + return browser::DispositionForPopupBounds(bounds, width, height); } // views::ContextMenuController implementation. diff --git a/chrome/browser/chromeos/frame/browser_view.h b/chrome/browser/chromeos/frame/browser_view.h index 62aae9e..215dc6d 100644 --- a/chrome/browser/chromeos/frame/browser_view.h +++ b/chrome/browser/chromeos/frame/browser_view.h @@ -118,10 +118,6 @@ class BrowserView : public ::BrowserView, return should_show_layout_mode_button_; } - // static implementation for chromeos::PanelBrowserView. - static WindowOpenDisposition DispositionForPopupBounds( - const gfx::Rect& bounds); - protected: virtual void GetAccessiblePanes( std::vector<views::AccessiblePaneView*>* panes) OVERRIDE; diff --git a/chrome/browser/chromeos/frame/panel_browser_view.cc b/chrome/browser/chromeos/frame/panel_browser_view.cc index 8340dfc..578b52a 100644 --- a/chrome/browser/chromeos/frame/panel_browser_view.cc +++ b/chrome/browser/chromeos/frame/panel_browser_view.cc @@ -107,7 +107,10 @@ void PanelBrowserView::SetCreatorView(PanelBrowserView* creator) { WindowOpenDisposition PanelBrowserView::GetDispositionForPopupBounds( const gfx::Rect& bounds) { - return chromeos::BrowserView::DispositionForPopupBounds(bounds); + GdkScreen* screen = gdk_screen_get_default(); + int width = gdk_screen_get_width(screen); + int height = gdk_screen_get_height(screen); + return browser::DispositionForPopupBounds(bounds, width, height); } bool PanelBrowserView::GetSavedWindowPlacement( diff --git a/chrome/browser/ui/browser_navigator.cc b/chrome/browser/ui/browser_navigator.cc index bbe00e4..8005699 100644 --- a/chrome/browser/ui/browser_navigator.cc +++ b/chrome/browser/ui/browser_navigator.cc @@ -647,4 +647,26 @@ bool IsURLAllowedInIncognito(const GURL& url) { url.host() == chrome::kChromeUISyncPromoHost)); } +#if defined(OS_CHROMEOS) || defined(USE_AURA) +// On Chrome desktop platforms (Aura, ChromeOS), if a popup window is larger +// than this fraction of the screen, create a foreground tab instead. +const float kPopupMaxWidthFactor = 0.5; +const float kPopupMaxHeightFactor = 0.6; + +WindowOpenDisposition DispositionForPopupBounds( + const gfx::Rect& popup_bounds, int window_width, int window_height) { + // Check against scaled window bounds. Also check for width or height == 0, + // which would indicate a tab sized popup window. + int max_width = window_width * kPopupMaxWidthFactor; + int max_height = window_height * kPopupMaxHeightFactor; + if (popup_bounds.width() > max_width || + popup_bounds.height() > max_height || + popup_bounds.width() == 0 || + popup_bounds.height() == 0) { + return NEW_FOREGROUND_TAB; + } + return NEW_POPUP; +} +#endif + } // namespace browser diff --git a/chrome/browser/ui/browser_navigator.h b/chrome/browser/ui/browser_navigator.h index 026dd40..ef37d3f 100644 --- a/chrome/browser/ui/browser_navigator.h +++ b/chrome/browser/ui/browser_navigator.h @@ -201,6 +201,13 @@ int GetIndexOfSingletonTab(NavigateParams* params); // Returns true if the url is allowed to open in incognito window. bool IsURLAllowedInIncognito(const GURL& url); +#if defined(OS_CHROMEOS) || defined(USE_AURA) +// Returns NEW_FOREGROUND_TAB if popup_bounds exceeds a specified percentage +// of the window size, otherwise returns NEW_POPUP. +WindowOpenDisposition DispositionForPopupBounds( + const gfx::Rect& popup_bounds, int window_width, int window_height); +#endif + } // namespace browser #endif // CHROME_BROWSER_UI_BROWSER_NAVIGATOR_H_ diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 321155e..497f79d 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -23,6 +23,10 @@ #include "content/public/browser/notification_types.h" #include "ui/gfx/rect.h" +#if defined(USE_AURA) +#include "ui/gfx/screen.h" +#endif + // static const Extension* Panel::GetExtensionFromBrowser(Browser* browser) { // Find the extension. When we create a panel from an extension, the extension @@ -529,8 +533,16 @@ gfx::Rect Panel::GetInstantBounds() { WindowOpenDisposition Panel::GetDispositionForPopupBounds( const gfx::Rect& bounds) { - NOTIMPLEMENTED(); +#if defined(USE_AURA) + // TODO(stevenjb): Remove this platform specific behavior after R18 when + // the panel code has moved to aura_shell. + gfx::Size window_size = gfx::Screen::GetMonitorAreaNearestWindow( + native_panel_->GetNativePanelHandle()).size(); + return browser::DispositionForPopupBounds( + bounds, window_size.width(), window_size.height()); +#else return NEW_POPUP; +#endif } FindBar* Panel::CreateFindBar() { diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 2135353..8597f9a 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -157,12 +157,6 @@ const int kDefaultHungPluginDetectFrequency = 2000; const int kMinDevToolsHeight = 50; const int kMinContentsHeight = 50; -#if defined(USE_AURA) && defined(OS_CHROMEOS) -// If a popup window is larger than this fraction of the screen, create a tab. -const float kPopupMaxWidthFactor = 0.5; -const float kPopupMaxHeightFactor = 0.6; -#endif - // How long do we wait before we consider a window hung (in ms). const int kDefaultPluginMessageResponseTimeout = 30000; // The number of milliseconds between loading animation frames. @@ -1328,23 +1322,14 @@ gfx::Rect BrowserView::GetInstantBounds() { WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( const gfx::Rect& bounds) { -#if defined(USE_AURA) && defined(OS_CHROMEOS) - // If a popup is larger than a given fraction of the screen, turn it into - // a foreground tab. Also check for width or height == 0, which would - // indicate a tab sized popup window. - gfx::Size size = gfx::Screen::GetMonitorAreaNearestWindow( +#if defined(USE_AURA) + gfx::Size window_size = gfx::Screen::GetMonitorAreaNearestWindow( GetWidget()->GetNativeView()).size(); - int max_width = size.width() * kPopupMaxWidthFactor; - int max_height = size.height() * kPopupMaxHeightFactor; - - if (bounds.width() > max_width || - bounds.width() == 0 || - bounds.height() > max_height || - bounds.height() == 0) { - return NEW_FOREGROUND_TAB; - } -#endif + return browser::DispositionForPopupBounds( + bounds, window_size.width(), window_size.height()); +#else return NEW_POPUP; +#endif } FindBar* BrowserView::CreateFindBar() { |