diff options
Diffstat (limited to 'chrome/browser/ui')
18 files changed, 140 insertions, 45 deletions
diff --git a/chrome/browser/ui/base_window.h b/chrome/browser/ui/base_window.h index deaa700..823b7dc 100644 --- a/chrome/browser/ui/base_window.h +++ b/chrome/browser/ui/base_window.h @@ -6,6 +6,7 @@ #define CHROME_BROWSER_UI_BASE_WINDOW_H_ #include "base/compiler_specific.h" +#include "ui/base/ui_base_types.h" // WindowShowState #include "ui/gfx/native_widget_types.h" namespace gfx { @@ -38,6 +39,9 @@ class BaseWindow { // currently maximized or minimized) in terms of the screen coordinates. virtual gfx::Rect GetRestoredBounds() const = 0; + // Returns the restore state for the window (platform dependent). + virtual ui::WindowShowState GetRestoredState() const = 0; + // Retrieves the window's current bounds, including its window. // This will only differ from GetRestoredBounds() for maximized // and minimized windows. diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.h b/chrome/browser/ui/cocoa/browser_window_cocoa.h index 71a3666..925f288 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.h +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.h @@ -60,6 +60,7 @@ class BrowserWindowCocoa : virtual void SetStarredState(bool is_starred) OVERRIDE; virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual bool IsMaximized() const OVERRIDE; virtual bool IsMinimized() const OVERRIDE; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 773dff8..65c506b 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -316,6 +316,14 @@ gfx::Rect BrowserWindowCocoa::GetRestoredBounds() const { return bounds; } +ui::WindowShowState BrowserWindowCocoa::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; + if (IsMinimized()) + return ui::SHOW_STATE_MINIMIZED; + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect BrowserWindowCocoa::GetBounds() const { return GetRestoredBounds(); } diff --git a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h index e9f12a0..d021e36 100644 --- a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h +++ b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h @@ -53,6 +53,7 @@ class NativeAppWindowCocoa : public NativeAppWindow { virtual bool IsFullscreen() const OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void Show() OVERRIDE; virtual void ShowInactive() OVERRIDE; @@ -104,6 +105,7 @@ class NativeAppWindowCocoa : public NativeAppWindow { // NativeAppWindow implementation. virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual bool IsFullscreenOrPending() const OVERRIDE; + virtual bool IsDetached() const OVERRIDE; virtual void UpdateWindowIcon() OVERRIDE; virtual void UpdateWindowTitle() OVERRIDE; virtual void UpdateDraggableRegions( diff --git a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm index 21dbb2d..34dbc59 100644 --- a/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm @@ -394,6 +394,10 @@ bool NativeAppWindowCocoa::IsFullscreenOrPending() const { return is_fullscreen_; } +bool NativeAppWindowCocoa::IsDetached() const { + return false; +} + gfx::NativeWindow NativeAppWindowCocoa::GetNativeWindow() { return window(); } @@ -407,6 +411,12 @@ gfx::Rect NativeAppWindowCocoa::GetRestoredBounds() const { return bounds; } +ui::WindowShowState NativeAppWindowCocoa::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect NativeAppWindowCocoa::GetBounds() const { return GetRestoredBounds(); } diff --git a/chrome/browser/ui/extensions/native_app_window.h b/chrome/browser/ui/extensions/native_app_window.h index 811f4ed..447a9e0 100644 --- a/chrome/browser/ui/extensions/native_app_window.h +++ b/chrome/browser/ui/extensions/native_app_window.h @@ -26,6 +26,9 @@ class NativeAppWindow : public BaseWindow, public WebContentsModalDialogHost { virtual void SetFullscreen(bool fullscreen) = 0; virtual bool IsFullscreenOrPending() const = 0; + // Returns true if the window is a panel that has been detached. + virtual bool IsDetached() const = 0; + // Called when the icon of the window changes. virtual void UpdateWindowIcon() = 0; diff --git a/chrome/browser/ui/extensions/shell_window.cc b/chrome/browser/ui/extensions/shell_window.cc index e6c48ed..f167e74 100644 --- a/chrome/browser/ui/extensions/shell_window.cc +++ b/chrome/browser/ui/extensions/shell_window.cc @@ -72,7 +72,7 @@ ShellWindow::CreateParams::CreateParams() transparent_background(false), bounds(INT_MIN, INT_MIN, 0, 0), creator_process_id(0), - state(STATE_NORMAL), + state(ui::SHOW_STATE_DEFAULT), hidden(false), resizable(true), focused(true) { @@ -104,7 +104,7 @@ ShellWindow::ShellWindow(Profile* profile, void ShellWindow::Init(const GURL& url, ShellWindowContents* shell_window_contents, - const ShellWindow::CreateParams& params) { + const CreateParams& params) { // Initialize the render interface and web contents shell_window_contents_.reset(shell_window_contents); shell_window_contents_->Initialize(profile(), url); @@ -130,6 +130,7 @@ void ShellWindow::Init(const GURL& url, // If left and top are left undefined, the native shell window will center // the window on the main screen in a platform-defined manner. + ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; if (!params.window_key.empty()) { window_key_ = params.window_key; @@ -138,11 +139,12 @@ void ShellWindow::Init(const GURL& url, shell_window_geometry_cache(); gfx::Rect cached_bounds; if (cache->GetGeometry(extension()->id(), params.window_key, - &cached_bounds)) + &cached_bounds, &cached_state)) { bounds = cached_bounds; + } } - ShellWindow::CreateParams new_params = params; + CreateParams new_params = params; gfx::Size& minimum_size = new_params.minimum_size; gfx::Size& maximum_size = new_params.maximum_size; @@ -166,30 +168,27 @@ void ShellWindow::Init(const GURL& url, new_params.bounds = bounds; - native_app_window_.reset(NativeAppWindow::Create(this, new_params)); - OnNativeWindowChanged(); + if (cached_state != ui::SHOW_STATE_DEFAULT) + new_params.state = cached_state; - switch (params.state) { - case CreateParams::STATE_NORMAL: - break; - case CreateParams::STATE_FULLSCREEN: - Fullscreen(); - break; - case CreateParams::STATE_MAXIMIZED: - Maximize(); - break; - case CreateParams::STATE_MINIMIZED: - Minimize(); - break; - } + native_app_window_.reset(NativeAppWindow::Create(this, new_params)); - if (!params.hidden) { + if (!new_params.hidden) { if (window_type_is_panel()) GetBaseWindow()->ShowInactive(); // Panels are not activated by default. else GetBaseWindow()->Show(); } + if (new_params.state == ui::SHOW_STATE_FULLSCREEN) + Fullscreen(); + else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) + Maximize(); + else if (new_params.state == ui::SHOW_STATE_MINIMIZED) + Minimize(); + + OnNativeWindowChanged(); + // When the render view host is changed, the native window needs to know // about it in case it has any setup to do to make the renderer appear // properly. In particular, on Windows, the view's clickthrough region needs @@ -576,7 +575,8 @@ void ShellWindow::SaveWindowPosition() { gfx::Rect bounds = native_app_window_->GetRestoredBounds(); bounds.Inset(native_app_window_->GetFrameInsets()); - cache->SaveGeometry(extension()->id(), window_key_, bounds); + ui::WindowShowState window_state = native_app_window_->GetRestoredState(); + cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); } // static diff --git a/chrome/browser/ui/extensions/shell_window.h b/chrome/browser/ui/extensions/shell_window.h index 7b28a5c..05b06ab 100644 --- a/chrome/browser/ui/extensions/shell_window.h +++ b/chrome/browser/ui/extensions/shell_window.h @@ -15,6 +15,7 @@ #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_delegate.h" #include "content/public/common/console_message_level.h" +#include "ui/base/ui_base_types.h" // WindowShowState #include "ui/gfx/image/image.h" #include "ui/gfx/rect.h" @@ -102,15 +103,8 @@ class ShellWindow : public content::NotificationObserver, // The process ID of the process that requested the create. int32 creator_process_id; - enum State { - STATE_NORMAL, - STATE_FULLSCREEN, - STATE_MAXIMIZED, - STATE_MINIMIZED - }; - // Initial state of the window. - State state; + ui::WindowShowState state; // If true, don't show the window after creation. bool hidden; diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index e594a6c..22ac92a 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -799,6 +799,14 @@ gfx::Rect BrowserWindowGtk::GetRestoredBounds() const { return restored_bounds_; } +ui::WindowShowState BrowserWindowGtk::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; + if (IsMinimized()) + return ui::SHOW_STATE_MINIMIZED; + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect BrowserWindowGtk::GetBounds() const { return bounds_; } diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h index 5ff445f..67dac6b 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.h +++ b/chrome/browser/ui/gtk/browser_window_gtk.h @@ -59,13 +59,13 @@ class PrefRegistrySyncable; // An implementation of BrowserWindow for GTK. Cross-platform code will interact // with this object when it needs to manipulate the window. -class BrowserWindowGtk : - public BrowserWindow, - public content::NotificationObserver, - public TabStripModelObserver, - public ui::ActiveWindowWatcherXObserver, - public InfoBarContainer::Delegate, - public extensions::ExtensionKeybindingRegistry::Delegate { +class BrowserWindowGtk + : public BrowserWindow, + public content::NotificationObserver, + public TabStripModelObserver, + public ui::ActiveWindowWatcherXObserver, + public InfoBarContainer::Delegate, + public extensions::ExtensionKeybindingRegistry::Delegate { public: explicit BrowserWindowGtk(Browser* browser); virtual ~BrowserWindowGtk(); @@ -95,6 +95,7 @@ class BrowserWindowGtk : virtual void SetStarredState(bool is_starred) OVERRIDE; virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual bool IsMaximized() const OVERRIDE; virtual bool IsMinimized() const OVERRIDE; diff --git a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc index b717e10..6e3a488 100644 --- a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc +++ b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.cc @@ -170,6 +170,12 @@ gfx::Rect NativeAppWindowGtk::GetRestoredBounds() const { return window_bounds; } +ui::WindowShowState NativeAppWindowGtk::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect NativeAppWindowGtk::GetBounds() const { gfx::Rect window_bounds = bounds_; window_bounds.Inset(-GetFrameInsets()); @@ -485,6 +491,10 @@ bool NativeAppWindowGtk::IsFullscreenOrPending() const { return content_thinks_its_fullscreen_; } +bool NativeAppWindowGtk::IsDetached() const { + return false; +} + void NativeAppWindowGtk::UpdateWindowIcon() { Profile* profile = shell_window_->profile(); gfx::Image app_icon = shell_window_->app_icon(); diff --git a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h index 7facadd..c75c46a 100644 --- a/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h +++ b/chrome/browser/ui/gtk/extensions/native_app_window_gtk.h @@ -36,8 +36,10 @@ class NativeAppWindowGtk : public NativeAppWindow, virtual bool IsMaximized() const OVERRIDE; virtual bool IsMinimized() const OVERRIDE; virtual bool IsFullscreen() const OVERRIDE; + virtual bool IsDetached() const OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void Show() OVERRIDE; virtual void ShowInactive() OVERRIDE; diff --git a/chrome/browser/ui/panels/panel.cc b/chrome/browser/ui/panels/panel.cc index 7fadec8..02af37e 100644 --- a/chrome/browser/ui/panels/panel.cc +++ b/chrome/browser/ui/panels/panel.cc @@ -253,6 +253,10 @@ gfx::Rect Panel::GetRestoredBounds() const { return bounds; } +ui::WindowShowState Panel::GetRestoredState() const { + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect Panel::GetBounds() const { return native_panel_->GetPanelBounds(); } diff --git a/chrome/browser/ui/panels/panel.h b/chrome/browser/ui/panels/panel.h index b2362a4..1542aa9 100644 --- a/chrome/browser/ui/panels/panel.h +++ b/chrome/browser/ui/panels/panel.h @@ -119,6 +119,7 @@ class Panel : public BaseWindow, virtual bool IsFullscreen() const OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void Show() OVERRIDE; virtual void Hide() OVERRIDE; diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.cc b/chrome/browser/ui/views/extensions/native_app_window_views.cc index e981a84..6781fcd 100644 --- a/chrome/browser/ui/views/extensions/native_app_window_views.cc +++ b/chrome/browser/ui/views/extensions/native_app_window_views.cc @@ -41,7 +41,9 @@ #include "ash/wm/panels/panel_frame_view.h" #include "ash/wm/window_properties.h" #include "chrome/browser/ui/ash/ash_util.h" +#include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" +#include "ui/aura/window.h" #endif namespace { @@ -261,15 +263,21 @@ void NativeAppWindowViews::InitializePanelWindow( window_->Init(params); window_->set_focus_on_creation(create_params.focused); -#if !defined(USE_ASH) - // TODO(oshima|stevenjb): Ideally, we should be able to just pre-determine - // the exact location and size, but this doesn't work well - // on non-ash environment where we don't have full control over - // window management. - gfx::Rect window_bounds = - window_->non_client_view()->GetWindowBoundsForClientBounds( - create_params.bounds); - window_->SetBounds(window_bounds); +#if defined(USE_ASH) + if (create_params.state == ui::SHOW_STATE_DETACHED) { + gfx::Rect window_bounds(create_params.bounds.x(), + create_params.bounds.y(), + preferred_size_.width(), + preferred_size_.height()); + aura::Window* native_window = GetNativeWindow(); + native_window->SetProperty(ash::internal::kPanelAttachedKey, false); + native_window->SetDefaultParentByRootWindow( + native_window->GetRootWindow(), native_window->GetBoundsInScreen()); + window_->SetBounds(window_bounds); + } +#else + // TODO(stevenjb): NativeAppWindow panels need to be implemented for other + // platforms. #endif } @@ -299,6 +307,23 @@ gfx::Rect NativeAppWindowViews::GetRestoredBounds() const { return window_->GetRestoredBounds(); } +ui::WindowShowState NativeAppWindowViews::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; +#if defined(USE_ASH) + // On Ash, restore fullscreen. + if (IsFullscreen()) + return ui::SHOW_STATE_FULLSCREEN; + // Use kRestoreShowStateKey in case a window is minimized/hidden. + ui::WindowShowState restore_state = + window_->GetNativeWindow()->GetProperty( + aura::client::kRestoreShowStateKey); + if (restore_state != ui::SHOW_STATE_MINIMIZED) + return restore_state; +#endif + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect NativeAppWindowViews::GetBounds() const { return window_->GetWindowBoundsInScreen(); } @@ -670,6 +695,17 @@ bool NativeAppWindowViews::IsFullscreenOrPending() const { return is_fullscreen_; } +bool NativeAppWindowViews::IsDetached() const { + if (!shell_window_->window_type_is_panel()) + return false; +#if defined(USE_ASH) + return !window_->GetNativeWindow()->GetProperty( + ash::internal::kPanelAttachedKey); +#else + return false; +#endif +} + views::View* NativeAppWindowViews::GetContentsView() { return this; } diff --git a/chrome/browser/ui/views/extensions/native_app_window_views.h b/chrome/browser/ui/views/extensions/native_app_window_views.h index 4a5cbac..90448d2 100644 --- a/chrome/browser/ui/views/extensions/native_app_window_views.h +++ b/chrome/browser/ui/views/extensions/native_app_window_views.h @@ -69,6 +69,7 @@ class NativeAppWindowViews : public NativeAppWindow, virtual bool IsFullscreen() const OVERRIDE; virtual gfx::NativeWindow GetNativeWindow() OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual void Show() OVERRIDE; virtual void ShowInactive() OVERRIDE; @@ -129,6 +130,7 @@ class NativeAppWindowViews : public NativeAppWindow, // NativeAppWindow implementation. virtual void SetFullscreen(bool fullscreen) OVERRIDE; virtual bool IsFullscreenOrPending() const OVERRIDE; + virtual bool IsDetached() const OVERRIDE; virtual void UpdateWindowIcon() OVERRIDE; virtual void UpdateWindowTitle() OVERRIDE; virtual void UpdateDraggableRegions( diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 0604615..ebe1f38 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -774,6 +774,14 @@ gfx::Rect BrowserView::GetRestoredBounds() const { return frame_->GetRestoredBounds(); } +ui::WindowShowState BrowserView::GetRestoredState() const { + if (IsMaximized()) + return ui::SHOW_STATE_MAXIMIZED; + if (IsMinimized()) + return ui::SHOW_STATE_MINIMIZED; + return ui::SHOW_STATE_NORMAL; +} + gfx::Rect BrowserView::GetBounds() const { return frame_->GetWindowBoundsInScreen(); } diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index d307e87..4744a17 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -276,6 +276,7 @@ class BrowserView : public BrowserWindow, virtual void SetStarredState(bool is_starred) OVERRIDE; virtual void ZoomChangedForActiveTab(bool can_show_bubble) OVERRIDE; virtual gfx::Rect GetRestoredBounds() const OVERRIDE; + virtual ui::WindowShowState GetRestoredState() const OVERRIDE; virtual gfx::Rect GetBounds() const OVERRIDE; virtual bool IsMaximized() const OVERRIDE; virtual bool IsMinimized() const OVERRIDE; |