diff options
author | varkha <varkha@chromium.org> | 2015-05-05 11:12:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-05 18:13:09 +0000 |
commit | 74014e0e926e2170188c9d7cc4706ccba36448c9 (patch) | |
tree | 1675abdf89ce226c93b6cf249eba29f7ff106b7e | |
parent | e28d513833e8084b1036af9cbc076541d3d9db62 (diff) | |
download | chromium_src-74014e0e926e2170188c9d7cc4706ccba36448c9.zip chromium_src-74014e0e926e2170188c9d7cc4706ccba36448c9.tar.gz chromium_src-74014e0e926e2170188c9d7cc4706ccba36448c9.tar.bz2 |
[Docking] Persists docked state for chrome app and extension windows on Chrome OS. Browser windows should not be affected - the browser will start normal or maximized but never initially docked.
BUG=271582
Review URL: https://codereview.chromium.org/1056793006
Cr-Commit-Position: refs/heads/master@{#328356}
-rw-r--r-- | ash/wm/dock/docked_window_resizer.cc | 4 | ||||
-rw-r--r-- | ash/wm/window_state.cc | 2 | ||||
-rw-r--r-- | ash/wm/wm_types.cc | 5 | ||||
-rw-r--r-- | ash/wm/wm_types.h | 2 | ||||
-rw-r--r-- | chrome/browser/extensions/api/sessions/sessions_api.cc | 1 | ||||
-rw-r--r-- | chrome/browser/extensions/api/tabs/tabs_api.cc | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views.cc | 17 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views.h | 3 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc | 25 | ||||
-rw-r--r-- | chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.h | 8 | ||||
-rw-r--r-- | chrome/common/extensions/api/windows.json | 2 | ||||
-rw-r--r-- | components/sessions/session_service_commands.cc | 7 | ||||
-rw-r--r-- | ui/base/ui_base_types.h | 3 | ||||
-rw-r--r-- | ui/views/widget/native_widget_mac.mm | 1 |
14 files changed, 69 insertions, 14 deletions
diff --git a/ash/wm/dock/docked_window_resizer.cc b/ash/wm/dock/docked_window_resizer.cc index d0b86f9..91486c6 100644 --- a/ash/wm/dock/docked_window_resizer.cc +++ b/ash/wm/dock/docked_window_resizer.cc @@ -299,13 +299,15 @@ DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( action = was_docked_ ? DOCKED_ACTION_UNDOCK : DOCKED_ACTION_NONE; } } else { - // Docked state was not changed but still need to record a UMA action. + // |action| is recorded in UMA and used to maintain |window_state_|. if (is_resized && is_docked_ && was_docked_) action = DOCKED_ACTION_RESIZE; else if (is_docked_ && was_docked_) action = DOCKED_ACTION_REORDER; else if (is_docked_ && !was_docked_) action = DOCKED_ACTION_DOCK; + else if (!is_docked_ && was_docked_) + action = DOCKED_ACTION_UNDOCK; else action = DOCKED_ACTION_NONE; } diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc index ffe25f3..94335cc 100644 --- a/ash/wm/window_state.cc +++ b/ash/wm/window_state.cc @@ -71,6 +71,8 @@ WMEventType WMEventTypeFromShowState(ui::WindowShowState requested_show_state) { return WM_EVENT_FULLSCREEN; case ui::SHOW_STATE_INACTIVE: return WM_EVENT_SHOW_INACTIVE; + case ui::SHOW_STATE_DOCKED: + return WM_EVENT_DOCK; case ui::SHOW_STATE_END: NOTREACHED() << "No WMEvent defined for the show state:" << requested_show_state; diff --git a/ash/wm/wm_types.cc b/ash/wm/wm_types.cc index 643520c..2077bd2 100644 --- a/ash/wm/wm_types.cc +++ b/ash/wm/wm_types.cc @@ -27,10 +27,11 @@ ui::WindowShowState ToWindowShowState(WindowStateType type) { case WINDOW_STATE_TYPE_RIGHT_SNAPPED: case WINDOW_STATE_TYPE_LEFT_SNAPPED: case WINDOW_STATE_TYPE_AUTO_POSITIONED: - case WINDOW_STATE_TYPE_DOCKED: return ui::SHOW_STATE_NORMAL; - case WINDOW_STATE_TYPE_MINIMIZED: + case WINDOW_STATE_TYPE_DOCKED: case WINDOW_STATE_TYPE_DOCKED_MINIMIZED: + return ui::SHOW_STATE_DOCKED; + case WINDOW_STATE_TYPE_MINIMIZED: return ui::SHOW_STATE_MINIMIZED; case WINDOW_STATE_TYPE_MAXIMIZED: return ui::SHOW_STATE_MAXIMIZED; diff --git a/ash/wm/wm_types.h b/ash/wm/wm_types.h index 7a78bcb..89747b8 100644 --- a/ash/wm/wm_types.h +++ b/ash/wm/wm_types.h @@ -27,6 +27,7 @@ enum WindowStateType { WINDOW_STATE_TYPE_MAXIMIZED, WINDOW_STATE_TYPE_INACTIVE, WINDOW_STATE_TYPE_FULLSCREEN, + WINDOW_STATE_TYPE_DOCKED, WINDOW_STATE_TYPE_END, // to avoid using SHOW_STATE_END // Ash specific states: @@ -34,7 +35,6 @@ enum WindowStateType { WINDOW_STATE_TYPE_LEFT_SNAPPED, WINDOW_STATE_TYPE_RIGHT_SNAPPED, - WINDOW_STATE_TYPE_DOCKED, WINDOW_STATE_TYPE_DOCKED_MINIMIZED, // A window is in this state when it is automatically placed and diff --git a/chrome/browser/extensions/api/sessions/sessions_api.cc b/chrome/browser/extensions/api/sessions/sessions_api.cc index e900b59..a09ceeb 100644 --- a/chrome/browser/extensions/api/sessions/sessions_api.cc +++ b/chrome/browser/extensions/api/sessions/sessions_api.cc @@ -300,6 +300,7 @@ scoped_ptr<windows::Window> SessionsGetDevicesFunction::CreateWindowModel( windows::WindowState state = windows::WINDOW_STATE_NONE; switch (window.show_state) { case ui::SHOW_STATE_NORMAL: + case ui::SHOW_STATE_DOCKED: state = windows::WINDOW_STATE_NORMAL; break; case ui::SHOW_STATE_MINIMIZED: diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc index dce6c5b..6ec55f2 100644 --- a/chrome/browser/extensions/api/tabs/tabs_api.cc +++ b/chrome/browser/extensions/api/tabs/tabs_api.cc @@ -184,6 +184,7 @@ void AssignOptionalValue(const scoped_ptr<T>& source, ui::WindowShowState ConvertToWindowShowState(windows::WindowState state) { switch (state) { case windows::WINDOW_STATE_NORMAL: + case windows::WINDOW_STATE_DOCKED: return ui::SHOW_STATE_NORMAL; case windows::WINDOW_STATE_MINIMIZED: return ui::SHOW_STATE_MINIMIZED; @@ -220,6 +221,7 @@ bool IsValidStateForWindowsCreateFunction( return !(create_data->focused && !*create_data->focused) && !has_bound && !is_panel; case windows::WINDOW_STATE_NORMAL: + case windows::WINDOW_STATE_DOCKED: case windows::WINDOW_STATE_NONE: return true; } @@ -562,6 +564,7 @@ bool WindowsCreateFunction::RunSync() { if (chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) { AppWindow::CreateParams create_params; create_params.window_type = AppWindow::WINDOW_TYPE_V1_PANEL; + create_params.window_key = extension_id; create_params.window_spec.bounds = window_bounds; create_params.focused = saw_focus_key && focused; AppWindow* app_window = new AppWindow( diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc index e242729..2942aec 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views.cc @@ -108,6 +108,7 @@ void ChromeNativeAppWindowViews::OnBeforeWidgetInit( } void ChromeNativeAppWindowViews::OnBeforePanelWidgetInit( + bool use_default_bounds, views::Widget::InitParams* init_params, views::Widget* widget) { } @@ -142,7 +143,7 @@ void ChromeNativeAppWindowViews::InitializeDefaultWindow( SetContentSizeConstraints(create_params.GetContentMinimumSize(frame_insets), create_params.GetContentMaximumSize(frame_insets)); if (!window_bounds.IsEmpty()) { - typedef AppWindow::BoundsSpecification BoundsSpecification; + using BoundsSpecification = AppWindow::BoundsSpecification; bool position_specified = window_bounds.x() != BoundsSpecification::kUnspecifiedPosition && window_bounds.y() != BoundsSpecification::kUnspecifiedPosition; @@ -210,8 +211,18 @@ void ChromeNativeAppWindowViews::InitializePanelWindow( else if (preferred_size_.height() < kMinPanelHeight) preferred_size_.set_height(kMinPanelHeight); - params.bounds = gfx::Rect(preferred_size_); - OnBeforePanelWidgetInit(¶ms, widget()); + // When a panel is not docked it will be placed at a default origin in the + // currently active target root window. + bool use_default_bounds = create_params.state != ui::SHOW_STATE_DOCKED; + // Sanitize initial origin reseting it in case it was not specified. + using BoundsSpecification = AppWindow::BoundsSpecification; + bool position_specified = + initial_window_bounds.x() != BoundsSpecification::kUnspecifiedPosition && + initial_window_bounds.y() != BoundsSpecification::kUnspecifiedPosition; + params.bounds = (use_default_bounds || !position_specified) ? + gfx::Rect(preferred_size_) : + gfx::Rect(initial_window_bounds.origin(), preferred_size_); + OnBeforePanelWidgetInit(use_default_bounds, ¶ms, widget()); widget()->Init(params); widget()->set_focus_on_creation(create_params.focused); } diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views.h b/chrome/browser/ui/views/apps/chrome_native_app_window_views.h index 685b69b..65357bb 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views.h +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views.h @@ -32,7 +32,8 @@ class ChromeNativeAppWindowViews views::Widget* widget); // Called before views::Widget::Init() in InitializeDefaultWindow() to allow // subclasses to customize the InitParams that would be passed. - virtual void OnBeforePanelWidgetInit(views::Widget::InitParams* init_params, + virtual void OnBeforePanelWidgetInit(bool use_default_bounds, + views::Widget::InitParams* init_params, views::Widget* widget); virtual void InitializeDefaultWindow( diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc b/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc index 6fcaf86..c6540d0 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.cc @@ -118,6 +118,19 @@ ChromeNativeAppWindowViewsAura::ChromeNativeAppWindowViewsAura() { ChromeNativeAppWindowViewsAura::~ChromeNativeAppWindowViewsAura() { } +void ChromeNativeAppWindowViewsAura::InitializeWindow( + AppWindow* app_window, + const AppWindow::CreateParams& create_params) { + ChromeNativeAppWindowViews::InitializeWindow(app_window, create_params); + // Restore docked state on ash desktop and ignore it elsewhere. + if (create_params.state == ui::SHOW_STATE_DOCKED && + chrome::GetHostDesktopTypeForNativeWindow(widget()->GetNativeWindow()) == + chrome::HOST_DESKTOP_TYPE_ASH) { + widget()->GetNativeWindow()->SetProperty(aura::client::kShowStateKey, + create_params.state); + } +} + void ChromeNativeAppWindowViewsAura::OnBeforeWidgetInit( const AppWindow::CreateParams& create_params, views::Widget::InitParams* init_params, @@ -147,11 +160,14 @@ void ChromeNativeAppWindowViewsAura::OnBeforeWidgetInit( } void ChromeNativeAppWindowViewsAura::OnBeforePanelWidgetInit( + bool use_default_bounds, views::Widget::InitParams* init_params, views::Widget* widget) { - ChromeNativeAppWindowViews::OnBeforePanelWidgetInit(init_params, widget); + ChromeNativeAppWindowViews::OnBeforePanelWidgetInit(use_default_bounds, + init_params, + widget); - if (ash::Shell::HasInstance()) { + if (ash::Shell::HasInstance() && use_default_bounds) { // Open a new panel on the target root. init_params->bounds = ash::ScreenUtil::ConvertRectToScreen( ash::Shell::GetTargetRootWindow(), gfx::Rect(GetPreferredSize())); @@ -223,6 +239,10 @@ ui::WindowShowState ChromeNativeAppWindowViewsAura::GetRestoredState() const { } return ui::SHOW_STATE_FULLSCREEN; } + if (widget()->GetNativeWindow()->GetProperty(aura::client::kShowStateKey) == + ui::SHOW_STATE_DOCKED) { + return ui::SHOW_STATE_DOCKED; + } } // Whitelist states to return so that invalid and transient states // are not saved and used to restore windows when they are recreated. @@ -235,6 +255,7 @@ ui::WindowShowState ChromeNativeAppWindowViewsAura::GetRestoredState() const { case ui::SHOW_STATE_DEFAULT: case ui::SHOW_STATE_MINIMIZED: case ui::SHOW_STATE_INACTIVE: + case ui::SHOW_STATE_DOCKED: case ui::SHOW_STATE_END: return ui::SHOW_STATE_NORMAL; } diff --git a/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.h b/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.h index a8ad016..c105070 100644 --- a/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.h +++ b/chrome/browser/ui/views/apps/chrome_native_app_window_views_aura.h @@ -30,12 +30,18 @@ class ChromeNativeAppWindowViewsAura : public ChromeNativeAppWindowViews, ~ChromeNativeAppWindowViewsAura() override; protected: + // NativeAppWindowViews implementation. + void InitializeWindow( + extensions::AppWindow* app_window, + const extensions::AppWindow::CreateParams& create_params) override; + // ChromeNativeAppWindowViews implementation. void OnBeforeWidgetInit( const extensions::AppWindow::CreateParams& create_params, views::Widget::InitParams* init_params, views::Widget* widget) override; - void OnBeforePanelWidgetInit(views::Widget::InitParams* init_params, + void OnBeforePanelWidgetInit(bool use_default_bounds, + views::Widget::InitParams* init_params, views::Widget* widget) override; apps::AppWindowFrameView* CreateNonStandardAppFrame() override; diff --git a/chrome/common/extensions/api/windows.json b/chrome/common/extensions/api/windows.json index f76ced9..7d16e29 100644 --- a/chrome/common/extensions/api/windows.json +++ b/chrome/common/extensions/api/windows.json @@ -20,7 +20,7 @@ "id": "WindowState", "type": "string", "description": "The state of this browser window. Under some circumstances a Window may not be assigned state property, for example when querying closed windows from the $(ref:sessions) API.", - "enum": ["normal", "minimized", "maximized", "fullscreen"] + "enum": ["normal", "minimized", "maximized", "fullscreen", "docked"] }, { "id": "Window", diff --git a/components/sessions/session_service_commands.cc b/components/sessions/session_service_commands.cc index 3b5f8a1..eca2b4d 100644 --- a/components/sessions/session_service_commands.cc +++ b/components/sessions/session_service_commands.cc @@ -99,7 +99,8 @@ enum PersistedWindowShowState { // SHOW_STATE_INACTIVE (4) never persisted. PERSISTED_SHOW_STATE_FULLSCREEN = 5, PERSISTED_SHOW_STATE_DETACHED_DEPRECATED = 6, - PERSISTED_SHOW_STATE_END = 6 + PERSISTED_SHOW_STATE_DOCKED = 7, + PERSISTED_SHOW_STATE_END = 7 }; typedef std::map<SessionID::id_type, SessionTab*> IdToSessionTab; @@ -123,6 +124,8 @@ PersistedWindowShowState ShowStateToPersistedShowState( return PERSISTED_SHOW_STATE_MAXIMIZED; case ui::SHOW_STATE_FULLSCREEN: return PERSISTED_SHOW_STATE_FULLSCREEN; + case ui::SHOW_STATE_DOCKED: + return PERSISTED_SHOW_STATE_DOCKED; case ui::SHOW_STATE_DEFAULT: case ui::SHOW_STATE_INACTIVE: @@ -146,6 +149,8 @@ ui::WindowShowState PersistedShowStateToShowState(int state) { return ui::SHOW_STATE_MAXIMIZED; case PERSISTED_SHOW_STATE_FULLSCREEN: return ui::SHOW_STATE_FULLSCREEN; + case PERSISTED_SHOW_STATE_DOCKED: + return ui::SHOW_STATE_DOCKED; case PERSISTED_SHOW_STATE_DETACHED_DEPRECATED: return ui::SHOW_STATE_NORMAL; } diff --git a/ui/base/ui_base_types.h b/ui/base/ui_base_types.h index b40815a..4ed9f25 100644 --- a/ui/base/ui_base_types.h +++ b/ui/base/ui_base_types.h @@ -20,7 +20,8 @@ enum WindowShowState { SHOW_STATE_MAXIMIZED = 3, SHOW_STATE_INACTIVE = 4, // Views only, not persisted. SHOW_STATE_FULLSCREEN = 5, - SHOW_STATE_END = 6 // The end of show state enum. + SHOW_STATE_DOCKED = 6, + SHOW_STATE_END = 7 // The end of show state enum. }; // Dialog button identifiers used to specify which buttons to show the user. diff --git a/ui/views/widget/native_widget_mac.mm b/ui/views/widget/native_widget_mac.mm index ca8fcb6..10a1c9f 100644 --- a/ui/views/widget/native_widget_mac.mm +++ b/ui/views/widget/native_widget_mac.mm @@ -345,6 +345,7 @@ void NativeWidgetMac::ShowWithWindowState(ui::WindowShowState state) { case ui::SHOW_STATE_MINIMIZED: case ui::SHOW_STATE_MAXIMIZED: case ui::SHOW_STATE_FULLSCREEN: + case ui::SHOW_STATE_DOCKED: NOTIMPLEMENTED(); break; case ui::SHOW_STATE_END: |