diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index a755e3b56a9c6b..00625c5b6bce51 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -23,6 +23,7 @@ #include "ash/test/test_shell_delegate.h" #include "ash/test/test_volume_control_delegate.h" #include "ash/volume_control_delegate.h" +#include "ash/wm/common/window_positioning_utils.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/lock_state_controller.h" #include "ash/wm/panels/panel_layout_manager.h" @@ -450,13 +451,13 @@ TEST_F(AcceleratorControllerTest, WindowSnap) { { GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( - window.get()); + wm::WmWindowAura::Get(window.get())); EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); } { GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( - window.get()); + wm::WmWindowAura::Get(window.get())); EXPECT_EQ(expected_bounds.ToString(), window->bounds().ToString()); } { @@ -505,7 +506,7 @@ TEST_F(AcceleratorControllerTest, WindowSnapLeftDockLeftRestore) { GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( - window1.get()); + wm::WmWindowAura::Get(window1.get())); EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); EXPECT_TRUE(window1_state->IsSnapped()); GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); @@ -527,8 +528,8 @@ TEST_F(AcceleratorControllerTest, WindowSnapRightDockRightRestore) { GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); gfx::Rect normal_bounds = window1_state->GetRestoreBoundsInParent(); - gfx::Rect expected_bounds = - wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get()); + gfx::Rect expected_bounds = wm::GetDefaultRightSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window1.get())); EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); EXPECT_TRUE(window1_state->IsSnapped()); GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_RIGHT); @@ -549,10 +550,10 @@ TEST_F(AcceleratorControllerTest, WindowSnapLeftDockLeftSnapRight) { window1_state->Activate(); GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); - gfx::Rect expected_bounds = - wm::GetDefaultLeftSnappedWindowBoundsInParent(window1.get()); - gfx::Rect expected_bounds2 = - wm::GetDefaultRightSnappedWindowBoundsInParent(window1.get()); + gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window1.get())); + gfx::Rect expected_bounds2 = wm::GetDefaultRightSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window1.get())); EXPECT_EQ(expected_bounds.ToString(), window1->bounds().ToString()); EXPECT_TRUE(window1_state->IsSnapped()); GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); @@ -621,8 +622,8 @@ TEST_F(AcceleratorControllerTest, WindowPanelDockLeftDockRightRestore) { gfx::Rect window_restore_bounds2 = window->bounds(); GetController()->PerformActionIfEnabled(WINDOW_CYCLE_SNAP_DOCK_LEFT); - gfx::Rect expected_bounds = - wm::GetDefaultLeftSnappedWindowBoundsInParent(window.get()); + gfx::Rect expected_bounds = wm::GetDefaultLeftSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window.get())); gfx::Rect window_restore_bounds = window_state->GetRestoreBoundsInScreen(); EXPECT_NE(expected_bounds.ToString(), window->bounds().ToString()); diff --git a/ash/ash.gyp b/ash/ash.gyp index c911374acf5c0f..5e7caf48acc069 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -535,8 +535,13 @@ 'wm/aura/wm_window_aura.h', 'wm/boot_splash_screen_chromeos.cc', 'wm/boot_splash_screen_chromeos.h', + 'wm/common/window_animation_types.h', + 'wm/common/window_parenting_utils.cc', + 'wm/common/window_parenting_utils.h', 'wm/common/window_positioning_utils.cc', 'wm/common/window_positioning_utils.h', + 'wm/common/window_state_util.cc', + 'wm/common/window_state_util.h', 'wm/common/wm_event.cc', 'wm/common/wm_event.h', 'wm/common/wm_globals.h', @@ -550,6 +555,7 @@ 'wm/common/wm_window_observer.h', 'wm/common/wm_window_property.h', 'wm/common/workspace/workspace_layout_manager_delegate.h', + 'wm/common/workspace/workspace_types.h', 'wm/coordinate_conversion.cc', 'wm/coordinate_conversion.h', 'wm/cursor_manager_chromeos.cc', @@ -682,8 +688,6 @@ 'wm/window_state_delegate.cc', 'wm/window_state_delegate.h', 'wm/window_state_observer.h', - 'wm/window_state_util.cc', - 'wm/window_state_util.h', 'wm/window_util.cc', 'wm/window_util.h', 'wm/workspace/magnetism_matcher.cc', @@ -699,7 +703,6 @@ 'wm/workspace/workspace_layout_manager.cc', 'wm/workspace/workspace_layout_manager.h', 'wm/workspace/workspace_layout_manager_backdrop_delegate.h', - 'wm/workspace/workspace_types.h', 'wm/workspace/workspace_window_resizer.cc', 'wm/workspace/workspace_window_resizer.h', 'wm/workspace_controller.cc', diff --git a/ash/frame/caption_buttons/frame_size_button.cc b/ash/frame/caption_buttons/frame_size_button.cc index 0ae229f02bea65..7426c57cd20ce8 100644 --- a/ash/frame/caption_buttons/frame_size_button.cc +++ b/ash/frame/caption_buttons/frame_size_button.cc @@ -7,6 +7,8 @@ #include "ash/metrics/user_metrics_recorder.h" #include "ash/screen_util.h" #include "ash/shell.h" +#include "ash/wm/aura/wm_window_aura.h" +#include "ash/wm/common/window_positioning_utils.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_aura.h" @@ -223,11 +225,14 @@ void FrameSizeButton::UpdateSnapType(const ui::LocatedEvent& event) { if (!phantom_window_controller_.get()) { phantom_window_controller_.reset(new PhantomWindowController(window)); } - gfx::Rect phantom_bounds_in_parent = (snap_type_ == SNAP_LEFT) ? - wm::GetDefaultLeftSnappedWindowBoundsInParent(window) : - wm::GetDefaultRightSnappedWindowBoundsInParent(window); + gfx::Rect phantom_bounds_in_parent = + (snap_type_ == SNAP_LEFT) + ? wm::GetDefaultLeftSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window)) + : wm::GetDefaultRightSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window)); phantom_window_controller_->Show(ScreenUtil::ConvertRectToScreen( - window->parent(), phantom_bounds_in_parent)); + window->parent(), phantom_bounds_in_parent)); } else { phantom_window_controller_.reset(); } diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 0f998069d4a237..12d433c839d1b0 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -33,6 +33,7 @@ #include "ash/touch/touch_hud_projection.h" #include "ash/touch/touch_observer_hud.h" #include "ash/wm/always_on_top_controller.h" +#include "ash/wm/aura/wm_window_aura.h" #include "ash/wm/common/workspace/workspace_layout_manager_delegate.h" #include "ash/wm/dock/docked_window_layout_manager.h" #include "ash/wm/lock_layout_manager.h" @@ -134,7 +135,7 @@ void ReparentWindow(aura::Window* window, aura::Window* new_parent) { new_parent->id() != kShellWindowId_DockedContainer; gfx::Rect local_bounds; if (update_bounds) { - local_bounds = state->aura_window()->bounds(); + local_bounds = wm::WmWindowAura::GetAuraWindow(state->window())->bounds(); MoveOriginRelativeToSize(src_size, dst_size, &local_bounds); } diff --git a/ash/shelf/shelf_layout_manager.cc b/ash/shelf/shelf_layout_manager.cc index d37901b81ec2da..88be2c2085559d 100644 --- a/ash/shelf/shelf_layout_manager.cc +++ b/ash/shelf/shelf_layout_manager.cc @@ -279,9 +279,10 @@ void ShelfLayoutManager::UpdateVisibilityState() { } else { // TODO(zelidrag): Verify shelf drag animation still shows on the device // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. - WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); + wm::WorkspaceWindowState window_state( + workspace_controller_->GetWindowState()); switch (window_state) { - case WORKSPACE_WINDOW_STATE_FULL_SCREEN: { + case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { const aura::Window* fullscreen_window = GetRootWindowController( root_window_)->GetWindowForFullscreenMode(); if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> @@ -295,15 +296,15 @@ void ShelfLayoutManager::UpdateVisibilityState() { break; } - case WORKSPACE_WINDOW_STATE_MAXIMIZED: + case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: SetState(CalculateShelfVisibility()); break; - case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: - case WORKSPACE_WINDOW_STATE_DEFAULT: + case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: + case wm::WORKSPACE_WINDOW_STATE_DEFAULT: SetState(CalculateShelfVisibility()); - SetWindowOverlapsShelf(window_state == - WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); + SetWindowOverlapsShelf( + window_state == wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); break; } } @@ -516,8 +517,9 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { State state; state.visibility_state = visibility_state; state.auto_hide_state = CalculateAutoHideState(visibility_state); - state.window_state = workspace_controller_ ? - workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT; + state.window_state = workspace_controller_ + ? workspace_controller_->GetWindowState() + : wm::WORKSPACE_WINDOW_STATE_DEFAULT; // Preserve the log in screen states. state.is_adding_user_screen = state_.is_adding_user_screen; state.is_screen_locked = state_.is_screen_locked; @@ -557,7 +559,7 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { // - Going from an auto hidden shelf in maximized mode to a visible shelf in // maximized mode. if (state.visibility_state == SHELF_VISIBLE && - state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED && + state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && old_state.visibility_state != SHELF_VISIBLE) { change_type = BACKGROUND_CHANGE_IMMEDIATE; } else { @@ -579,9 +581,9 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { UpdateShelfBackground(change_type); } - shelf_->SetDimsShelf( - state.visibility_state == SHELF_VISIBLE && - state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED); + shelf_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && + state.window_state == + wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); TargetBounds target_bounds; CalculateTargetBounds(state_, &target_bounds); @@ -875,7 +877,7 @@ void ShelfLayoutManager::UpdateShelfBackground( ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { if (state_.visibility_state != SHELF_AUTO_HIDE && - state_.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED) { + state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { return SHELF_BACKGROUND_MAXIMIZED; } diff --git a/ash/shelf/shelf_layout_manager.h b/ash/shelf/shelf_layout_manager.h index 3689d017472e82..a08531e5c4be80 100644 --- a/ash/shelf/shelf_layout_manager.h +++ b/ash/shelf/shelf_layout_manager.h @@ -16,9 +16,9 @@ #include "ash/shell_observer.h" #include "ash/snap_to_pixel_layout_manager.h" #include "ash/system/status_area_widget.h" +#include "ash/wm/common/workspace/workspace_types.h" #include "ash/wm/dock/docked_window_layout_manager_observer.h" #include "ash/wm/lock_state_observer.h" -#include "ash/wm/workspace/workspace_types.h" #include "base/compiler_specific.h" #include "base/gtest_prod_util.h" #include "base/logging.h" @@ -238,11 +238,12 @@ class ASH_EXPORT ShelfLayoutManager }; struct State { - State() : visibility_state(SHELF_VISIBLE), - auto_hide_state(SHELF_AUTO_HIDE_HIDDEN), - window_state(WORKSPACE_WINDOW_STATE_DEFAULT), - is_screen_locked(false), - is_adding_user_screen(false) {} + State() + : visibility_state(SHELF_VISIBLE), + auto_hide_state(SHELF_AUTO_HIDE_HIDDEN), + window_state(wm::WORKSPACE_WINDOW_STATE_DEFAULT), + is_screen_locked(false), + is_adding_user_screen(false) {} // Returns true if the two states are considered equal. As // |auto_hide_state| only matters if |visibility_state| is @@ -259,7 +260,7 @@ class ASH_EXPORT ShelfLayoutManager ShelfVisibilityState visibility_state; ShelfAutoHideState auto_hide_state; - WorkspaceWindowState window_state; + wm::WorkspaceWindowState window_state; bool is_screen_locked; bool is_adding_user_screen; }; diff --git a/ash/wm/aura/wm_globals_aura.cc b/ash/wm/aura/wm_globals_aura.cc index daa7082bdc251f..f308d936c73544 100644 --- a/ash/wm/aura/wm_globals_aura.cc +++ b/ash/wm/aura/wm_globals_aura.cc @@ -4,6 +4,7 @@ #include "ash/wm/aura/wm_globals_aura.h" +#include "ash/display/window_tree_host_manager.h" #include "ash/session/session_state_delegate.h" #include "ash/shell.h" #include "ash/shell_delegate.h" @@ -45,6 +46,12 @@ WmWindow* WmGlobalsAura::GetActiveWindow() { return WmWindowAura::Get(wm::GetActiveWindow()); } +WmWindow* WmGlobalsAura::GetRootWindowForDisplayId(int64_t display_id) { + return WmWindowAura::Get(Shell::GetInstance() + ->window_tree_host_manager() + ->GetRootWindowForDisplayId(display_id)); +} + WmWindow* WmGlobalsAura::GetRootWindowForNewWindows() { return WmWindowAura::Get(Shell::GetTargetRootWindow()); } diff --git a/ash/wm/aura/wm_globals_aura.h b/ash/wm/aura/wm_globals_aura.h index 16f5e3a6f72643..d2195df499e079 100644 --- a/ash/wm/aura/wm_globals_aura.h +++ b/ash/wm/aura/wm_globals_aura.h @@ -23,6 +23,7 @@ class ASH_EXPORT WmGlobalsAura : public WmGlobals { // WmGlobals: WmWindow* GetActiveWindow() override; + WmWindow* GetRootWindowForDisplayId(int64_t display_id) override; WmWindow* GetRootWindowForNewWindows() override; std::vector GetMruWindowListIgnoreModals() override; bool IsForceMaximizeOnFirstRun() override; diff --git a/ash/wm/aura/wm_root_window_controller_aura.cc b/ash/wm/aura/wm_root_window_controller_aura.cc index 5b4a8890b8d815..812987591bacfe 100644 --- a/ash/wm/aura/wm_root_window_controller_aura.cc +++ b/ash/wm/aura/wm_root_window_controller_aura.cc @@ -6,6 +6,7 @@ #include "ash/root_window_controller.h" #include "ash/wm/aura/wm_globals_aura.h" +#include "ash/wm/workspace_controller.h" #include "ui/aura/window.h" #include "ui/aura/window_property.h" @@ -57,5 +58,9 @@ WmGlobals* WmRootWindowControllerAura::GetGlobals() { return WmGlobalsAura::Get(); } +WorkspaceWindowState WmRootWindowControllerAura::GetWorkspaceWindowState() { + return root_window_controller_->workspace_controller()->GetWindowState(); +} + } // namespace wm } // namespace ash diff --git a/ash/wm/aura/wm_root_window_controller_aura.h b/ash/wm/aura/wm_root_window_controller_aura.h index 160bffdf5f5fcf..1b22850c6e1b40 100644 --- a/ash/wm/aura/wm_root_window_controller_aura.h +++ b/ash/wm/aura/wm_root_window_controller_aura.h @@ -34,6 +34,7 @@ class ASH_EXPORT WmRootWindowControllerAura : public WmRootWindowController { // WmRootWindowController: bool HasShelf() override; WmGlobals* GetGlobals() override; + WorkspaceWindowState GetWorkspaceWindowState() override; private: RootWindowController* root_window_controller_; diff --git a/ash/wm/aura/wm_window_aura.cc b/ash/wm/aura/wm_window_aura.cc index b7c07124359e3a..9dcb68bcbdcf20 100644 --- a/ash/wm/aura/wm_window_aura.cc +++ b/ash/wm/aura/wm_window_aura.cc @@ -190,6 +190,10 @@ WmWindow* WmWindowAura::GetToplevelWindow() { return Get(window_->GetToplevelWindow()); } +void WmWindowAura::AddChild(WmWindow* window) { + window_->AddChild(GetAuraWindow(window)); +} + WmWindow* WmWindowAura::GetParent() { return Get(window_->parent()); } @@ -207,6 +211,14 @@ std::vector WmWindowAura::GetTransientChildren() { return wm_windows; } +void WmWindowAura::SetVisibilityAnimationType(int type) { + ::wm::SetWindowVisibilityAnimationType(window_, type); +} + +void WmWindowAura::Animate(::wm::WindowAnimationType type) { + ::wm::AnimateWindow(window_, type); +} + void WmWindowAura::SetBounds(const gfx::Rect& bounds) { window_->SetBounds(bounds); } @@ -315,6 +327,10 @@ ui::WindowShowState WmWindowAura::GetShowState() const { return window_->GetProperty(aura::client::kShowStateKey); } +void WmWindowAura::SetRestoreShowState(ui::WindowShowState show_state) { + window_->SetProperty(aura::client::kRestoreShowStateKey, show_state); +} + void WmWindowAura::SetCapture() { window_->SetCapture(); } diff --git a/ash/wm/aura/wm_window_aura.h b/ash/wm/aura/wm_window_aura.h index e07191a81d95a3..c714feebc21f89 100644 --- a/ash/wm/aura/wm_window_aura.h +++ b/ash/wm/aura/wm_window_aura.h @@ -57,9 +57,12 @@ class ASH_EXPORT WmWindowAura : public WmWindow, public aura::WindowObserver { bool GetBoolProperty(WmWindowProperty key) override; const WindowState* GetWindowState() const override; WmWindow* GetToplevelWindow() override; + void AddChild(WmWindow* window) override; WmWindow* GetParent() override; WmWindow* GetTransientParent() override; std::vector GetTransientChildren() override; + void SetVisibilityAnimationType(int type) override; + void Animate(::wm::WindowAnimationType type) override; void SetBounds(const gfx::Rect& bounds) override; void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, base::TimeDelta delta) override; @@ -78,6 +81,7 @@ class ASH_EXPORT WmWindowAura : public WmWindow, public aura::WindowObserver { bool Contains(const WmWindow* other) const override; void SetShowState(ui::WindowShowState show_state) override; ui::WindowShowState GetShowState() const override; + void SetRestoreShowState(ui::WindowShowState show_state) override; void SetCapture() override; bool HasCapture() override; void ReleaseCapture() override; diff --git a/ash/wm/common/window_animation_types.h b/ash/wm/common/window_animation_types.h new file mode 100644 index 00000000000000..a75e2bcefafe0c --- /dev/null +++ b/ash/wm/common/window_animation_types.h @@ -0,0 +1,27 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WM_COMMON_WINDOW_ANIMATION_TYPES_H_ +#define ASH_WM_COMMON_WINDOW_ANIMATION_TYPES_H_ + +#include "ash/ash_export.h" +#include "ui/wm/core/window_animations.h" + +namespace ash { +namespace wm { + +// An extension of the window animations provided by CoreWm. These are +// Ash-specific only. +enum WindowVisibilityAnimationType { + // Window scale/rotates down to its launcher icon. + WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE = + ::wm::WINDOW_VISIBILITY_ANIMATION_MAX, + // Fade in/out using brightness and grayscale web filters. + WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE +}; + +} // namespace wm +} // namespace ash + +#endif // ASH_WM_COMMON_WINDOW_ANIMATION_TYPES_H_ diff --git a/ash/wm/common/window_parenting_utils.cc b/ash/wm/common/window_parenting_utils.cc new file mode 100644 index 00000000000000..1e31fc4417ab26 --- /dev/null +++ b/ash/wm/common/window_parenting_utils.cc @@ -0,0 +1,28 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/wm/common/window_parenting_utils.h" + +#include "ash/wm/common/wm_window.h" + +namespace ash { +namespace wm { + +void ReparentChildWithTransientChildren(WmWindow* child, + WmWindow* old_parent, + WmWindow* new_parent) { + if (child->GetParent() == old_parent) + new_parent->AddChild(child); + ReparentTransientChildrenOfChild(child, old_parent, new_parent); +} + +void ReparentTransientChildrenOfChild(WmWindow* child, + WmWindow* old_parent, + WmWindow* new_parent) { + for (WmWindow* transient_child : child->GetTransientChildren()) + ReparentChildWithTransientChildren(transient_child, old_parent, new_parent); +} + +} // namespace wm +} // namespace ash diff --git a/ash/wm/common/window_parenting_utils.h b/ash/wm/common/window_parenting_utils.h new file mode 100644 index 00000000000000..0e0ce3c4815af1 --- /dev/null +++ b/ash/wm/common/window_parenting_utils.h @@ -0,0 +1,31 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef ASH_WM_COMMON_WINDOW_PARENTING_UTILS_H_ +#define ASH_WM_COMMON_WINDOW_PARENTING_UTILS_H_ + +#include "ash/ash_export.h" + +namespace ash { +namespace wm { + +class WmWindow; + +// Changes the parent of a |child| and all its transient children that are +// themselves children of |old_parent| to |new_parent|. +void ReparentChildWithTransientChildren(WmWindow* child, + WmWindow* old_parent, + WmWindow* new_parent); + +// Changes the parent of all transient children of a |child| to |new_parent|. +// Does not change parent of the transient children that are not themselves +// children of |old_parent|. +void ReparentTransientChildrenOfChild(WmWindow* child, + WmWindow* old_parent, + WmWindow* new_parent); + +} // namespace wm +} // namespace ash + +#endif // ASH_WM_COMMON_WINDOW_PARENTING_UTILS_H_ diff --git a/ash/wm/common/window_positioning_utils.cc b/ash/wm/common/window_positioning_utils.cc index 7ba629babc2ead..a1105ea4df1dc0 100644 --- a/ash/wm/common/window_positioning_utils.cc +++ b/ash/wm/common/window_positioning_utils.cc @@ -6,12 +6,29 @@ #include +#include "ash/wm/common/wm_screen_util.h" +#include "ash/wm/common/wm_window.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" namespace ash { namespace wm { +namespace { + +// Returns the default width of a snapped window. +int GetDefaultSnappedWindowWidth(WmWindow* window) { + const float kSnappedWidthWorkspaceRatio = 0.5f; + + int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width(); + int min_width = window->GetMinimumSize().width(); + int ideal_width = + static_cast(work_area_width * kSnappedWidthWorkspaceRatio); + return std::min(work_area_width, std::max(ideal_width, min_width)); +} + +} // namespace + void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) { bounds->set_width(std::min(bounds->width(), max_size.width())); bounds->set_height(std::min(bounds->height(), max_size.height())); @@ -46,5 +63,19 @@ void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, kMinimumOnScreenArea, bounds); } +gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(wm::WmWindow* window) { + gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); + return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), + GetDefaultSnappedWindowWidth(window), + work_area_in_parent.height()); +} + +gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(wm::WmWindow* window) { + gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); + int width = GetDefaultSnappedWindowWidth(window); + return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), + width, work_area_in_parent.height()); +} + } // namespace wm } // namespace ash diff --git a/ash/wm/common/window_positioning_utils.h b/ash/wm/common/window_positioning_utils.h index 8145082f7890b7..b0ad13501500bd 100644 --- a/ash/wm/common/window_positioning_utils.h +++ b/ash/wm/common/window_positioning_utils.h @@ -15,6 +15,8 @@ class Size; namespace ash { namespace wm { +class WmWindow; + // We force at least this many DIPs for any window on the screen. const int kMinimumOnScreenArea = 25; @@ -38,6 +40,16 @@ ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility( const gfx::Rect& visible_area, gfx::Rect* bounds); +// Returns the bounds of a left snapped window with default width in parent +// coordinates. +ASH_EXPORT gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent( + WmWindow* window); + +// Returns the bounds of a right snapped window with default width in parent +// coordinates. +ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent( + WmWindow* window); + } // namespace wm } // namespace ash diff --git a/ash/wm/window_state_util.cc b/ash/wm/common/window_state_util.cc similarity index 95% rename from ash/wm/window_state_util.cc rename to ash/wm/common/window_state_util.cc index 36d874433e82a9..feb019d5a9172e 100644 --- a/ash/wm/window_state_util.cc +++ b/ash/wm/common/window_state_util.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ash/wm/window_state_util.h" +#include "ash/wm/common/window_state_util.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_delegate.h" diff --git a/ash/wm/window_state_util.h b/ash/wm/common/window_state_util.h similarity index 76% rename from ash/wm/window_state_util.h rename to ash/wm/common/window_state_util.h index 48d3cb6287ab5b..215121e7b02090 100644 --- a/ash/wm/window_state_util.h +++ b/ash/wm/common/window_state_util.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ASH_WM_WINDOW_STATE_UTIL_H_ -#define ASH_WM_WINDOW_STATE_UTIL_H_ +#ifndef ASH_WM_COMMON_WINDOW_STATE_UTIL_H_ +#define ASH_WM_COMMON_WINDOW_STATE_UTIL_H_ namespace ash { namespace wm { @@ -16,4 +16,4 @@ void ToggleFullScreen(WindowState* window_state, WindowStateDelegate* delegate); } // namespace wm } // namespace ash -#endif // ASH_WM_WINDOW_STATE_UTIL_H_ +#endif // ASH_WM_COMMON_WINDOW_STATE_UTIL_H_ diff --git a/ash/wm/common/wm_globals.h b/ash/wm/common/wm_globals.h index 7c977230fc9b41..9343281d273829 100644 --- a/ash/wm/common/wm_globals.h +++ b/ash/wm/common/wm_globals.h @@ -5,6 +5,8 @@ #ifndef ASH_WM_COMMON_WM_GLOBALS_H_ #define ASH_WM_COMMON_WM_GLOBALS_H_ +#include + #include #include "ash/ash_export.h" @@ -29,6 +31,9 @@ class ASH_EXPORT WmGlobals { virtual WmWindow* GetActiveWindow() = 0; + // Returns the root window for the specified display. + virtual WmWindow* GetRootWindowForDisplayId(int64_t display_id) = 0; + // Returns the root window that newly created windows should be added to. // NOTE: this returns the root, newly created window should be added to the // appropriate container in the returned window. diff --git a/ash/wm/common/wm_root_window_controller.h b/ash/wm/common/wm_root_window_controller.h index 8d047e74b0ceea..a2b06ddc85799f 100644 --- a/ash/wm/common/wm_root_window_controller.h +++ b/ash/wm/common/wm_root_window_controller.h @@ -6,6 +6,7 @@ #define ASH_WM_COMMON_WM_ROOT_CONTROLLER_H_ #include "ash/ash_export.h" +#include "ash/wm/common/workspace/workspace_types.h" namespace ash { namespace wm { @@ -20,6 +21,8 @@ class ASH_EXPORT WmRootWindowController { virtual bool HasShelf() = 0; virtual WmGlobals* GetGlobals() = 0; + + virtual WorkspaceWindowState GetWorkspaceWindowState() = 0; }; } // namespace wm diff --git a/ash/wm/common/wm_window.h b/ash/wm/common/wm_window.h index e343e2c36ff95e..c8294069236643 100644 --- a/ash/wm/common/wm_window.h +++ b/ash/wm/common/wm_window.h @@ -10,6 +10,7 @@ #include "ash/ash_export.h" #include "base/time/time.h" #include "ui/base/ui_base_types.h" +#include "ui/wm/core/window_animations.h" #include "ui/wm/public/window_types.h" namespace gfx { @@ -88,11 +89,17 @@ class ASH_EXPORT WmWindow { virtual WmWindow* GetToplevelWindow() = 0; + virtual void AddChild(WmWindow* window) = 0; + virtual WmWindow* GetParent() = 0; virtual WmWindow* GetTransientParent() = 0; virtual std::vector GetTransientChildren() = 0; + // |type| is WindowVisibilityAnimationType. Has to be an int to match aura. + virtual void SetVisibilityAnimationType(int type) = 0; + virtual void Animate(::wm::WindowAnimationType type) = 0; + virtual void SetBounds(const gfx::Rect& bounds) = 0; virtual void SetBoundsWithTransitionDelay(const gfx::Rect& bounds, base::TimeDelta delta) = 0; @@ -117,6 +124,8 @@ class ASH_EXPORT WmWindow { virtual void SetShowState(ui::WindowShowState show_state) = 0; virtual ui::WindowShowState GetShowState() const = 0; + virtual void SetRestoreShowState(ui::WindowShowState show_state) = 0; + virtual void SetCapture() = 0; virtual bool HasCapture() = 0; virtual void ReleaseCapture() = 0; diff --git a/ash/wm/workspace/workspace_types.h b/ash/wm/common/workspace/workspace_types.h similarity index 76% rename from ash/wm/workspace/workspace_types.h rename to ash/wm/common/workspace/workspace_types.h index 9572a328d8b648..dadd70f1d2bf37 100644 --- a/ash/wm/workspace/workspace_types.h +++ b/ash/wm/common/workspace/workspace_types.h @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef ASH_WM_WORKSPACE_WORKSPACE_TYPES_H_ -#define ASH_WM_WORKSPACE_WORKSPACE_TYPES_H_ +#ifndef ASH_WM_COMMON_WORKSPACE_WORKSPACE_TYPES_H_ +#define ASH_WM_COMMON_WORKSPACE_WORKSPACE_TYPES_H_ namespace ash { +namespace wm { // Enumeration of the possible window states. enum WorkspaceWindowState { @@ -22,6 +23,7 @@ enum WorkspaceWindowState { WORKSPACE_WINDOW_STATE_DEFAULT, }; +} // namespace wm } // namespace ash -#endif // ASH_WM_WORKSPACE_WORKSPACE_TYPES_H_ +#endif // ASH_WM_COMMON_WORKSPACE_WORKSPACE_TYPES_H_ diff --git a/ash/wm/default_state.cc b/ash/wm/default_state.cc index 4aab8da91c83b1..902db7ec69e034 100644 --- a/ash/wm/default_state.cc +++ b/ash/wm/default_state.cc @@ -4,27 +4,23 @@ #include "ash/wm/default_state.h" -#include "ash/display/window_tree_host_manager.h" -#include "ash/root_window_controller.h" -#include "ash/screen_util.h" -#include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/aura/wm_window_aura.h" +#include "ash/wm/common/window_animation_types.h" +#include "ash/wm/common/window_parenting_utils.h" #include "ash/wm/common/window_positioning_utils.h" +#include "ash/wm/common/window_state_util.h" #include "ash/wm/common/wm_event.h" -#include "ash/wm/coordinate_conversion.h" +#include "ash/wm/common/wm_globals.h" +#include "ash/wm/common/wm_root_window_controller.h" +#include "ash/wm/common/wm_screen_util.h" #include "ash/wm/dock/docked_window_layout_manager.h" -#include "ash/wm/window_animations.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_delegate.h" -#include "ash/wm/window_state_util.h" -#include "ash/wm/window_util.h" -#include "ash/wm/workspace/workspace_window_resizer.h" -#include "ash/wm/workspace_controller.h" -#include "ui/aura/client/aura_constants.h" #include "ui/aura/window.h" -#include "ui/aura/window_delegate.h" #include "ui/gfx/display.h" #include "ui/gfx/geometry/rect.h" +#include "ui/gfx/screen.h" namespace ash { namespace wm { @@ -56,36 +52,33 @@ void MoveToDisplayForRestore(WindowState* window_state) { // work area information like WindowResizer does for the // last window location. gfx::Rect display_area = - gfx::Screen::GetScreen() - ->GetDisplayNearestWindow(window_state->aura_window()) - .bounds(); + window_state->window()->GetDisplayNearestWindow().bounds(); if (!display_area.Intersects(restore_bounds)) { const gfx::Display& display = gfx::Screen::GetScreen()->GetDisplayMatching(restore_bounds); - WindowTreeHostManager* window_tree_host_manager = - Shell::GetInstance()->window_tree_host_manager(); - aura::Window* new_root = - window_tree_host_manager->GetRootWindowForDisplayId(display.id()); - if (new_root != window_state->aura_window()->GetRootWindow()) { - aura::Window* new_container = Shell::GetContainer( - new_root, window_state->aura_window()->parent()->id()); - new_container->AddChild(window_state->aura_window()); + WmGlobals* globals = window_state->window()->GetGlobals(); + WmWindow* new_root = globals->GetRootWindowForDisplayId(display.id()); + if (new_root != window_state->window()->GetRootWindow()) { + WmWindow* new_container = new_root->GetChildByShellWindowId( + window_state->window()->GetParent()->GetShellWindowId()); + new_container->AddChild(window_state->window()); } } } -DockedWindowLayoutManager* GetDockedWindowLayoutManager() { - aura::Window* active_window = ash::wm::GetActiveWindow(); - if (active_window) { - aura::Window* dock_container = Shell::GetContainer( - active_window->GetRootWindow(), kShellWindowId_DockedContainer); - DockedWindowLayoutManager* dock_layout = +DockedWindowLayoutManager* GetDockedWindowLayoutManager(WmGlobals* globals) { + WmWindow* active_window = globals->GetActiveWindow(); + if (!active_window) + return nullptr; + + WmWindow* dock_container = + active_window->GetRootWindow()->GetChildByShellWindowId( + kShellWindowId_DockedContainer); + DockedWindowLayoutManager* dock_layout = static_cast( - dock_container->layout_manager()); - return dock_layout; - } - return NULL; + WmWindowAura::GetAuraWindow(dock_container)->layout_manager()); + return dock_layout; } class ScopedPreferredAlignmentResetter { @@ -125,7 +118,8 @@ class ScopedDockedLayoutEventSourceResetter { }; void CycleSnapDock(WindowState* window_state, WMEventType event) { - DockedWindowLayoutManager* dock_layout = GetDockedWindowLayoutManager(); + DockedWindowLayoutManager* dock_layout = + GetDockedWindowLayoutManager(window_state->window()->GetGlobals()); wm::WindowStateType desired_snap_state = event == WM_EVENT_CYCLE_SNAP_DOCK_LEFT ? wm::WINDOW_STATE_TYPE_LEFT_SNAPPED : wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED; @@ -140,7 +134,7 @@ void CycleSnapDock(WindowState* window_state, WMEventType event) { current_dock_alignment != desired_dock_alignment)) { if (window_state->CanSnap() && window_state->GetStateType() != desired_snap_state && - window_state->aura_window()->type() != ui::wm::WINDOW_TYPE_PANEL) { + window_state->window()->GetType() != ui::wm::WINDOW_TYPE_PANEL) { const wm::WMEvent event(desired_snap_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ? wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); @@ -170,8 +164,7 @@ void CycleSnapDock(WindowState* window_state, WMEventType event) { window_state->Restore(); return; } - ::wm::AnimateWindow(window_state->aura_window(), - ::wm::WINDOW_ANIMATION_TYPE_BOUNCE); + window_state->window()->Animate(::wm::WINDOW_ANIMATION_TYPE_BOUNCE); } } // namespace @@ -264,8 +257,7 @@ void DefaultState::AttachState( // If the display has changed while in the another mode, // we need to let windows know the change. gfx::Display current_display = - gfx::Screen::GetScreen()->GetDisplayNearestWindow( - window_state->aura_window()); + window_state->window()->GetDisplayNearestWindow(); if (stored_display_state_.bounds() != current_display.bounds()) { const WMEvent event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); window_state->OnWMEvent(&event); @@ -277,22 +269,20 @@ void DefaultState::AttachState( void DefaultState::DetachState(WindowState* window_state) { stored_window_state_ = window_state; - aura::Window* window = window_state->aura_window(); - stored_bounds_ = window->bounds(); + stored_bounds_ = window_state->window()->GetBounds(); stored_restore_bounds_ = window_state->HasRestoreBounds() ? window_state->GetRestoreBoundsInParent() : gfx::Rect(); // Remember the display state so that in case of the display change // while in the other mode, we can perform necessary action to // restore the window state to the proper state for the current // display. - stored_display_state_ = gfx::Screen::GetScreen()->GetDisplayNearestWindow( - window_state->aura_window()); + stored_display_state_ = window_state->window()->GetDisplayNearestWindow(); } // static bool DefaultState::ProcessCompoundEvents(WindowState* window_state, const WMEvent* event) { - aura::Window* window = window_state->aura_window(); + WmWindow* window = window_state->window(); switch (event->type()) { case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: @@ -317,27 +307,25 @@ bool DefaultState::ProcessCompoundEvents(WindowState* window_state, } return true; case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: { - gfx::Rect work_area = - ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); + gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); // Maximize vertically if: // - The window does not have a max height defined. // - The window has the normal state type. Snapped windows are excluded // because they are already maximized vertically and reverting to the // restored bounds looks weird. - if (window->delegate()->GetMaximumSize().height() != 0 || + if (window->GetMaximumSize().height() != 0 || !window_state->IsNormalStateType()) { return true; } if (window_state->HasRestoreBounds() && - (window->bounds().height() == work_area.height() && - window->bounds().y() == work_area.y())) { + (window->GetBounds().height() == work_area.height() && + window->GetBounds().y() == work_area.y())) { window_state->SetAndClearRestoreBounds(); } else { window_state->SaveCurrentBoundsForRestore(); - window->SetBounds(gfx::Rect(window->bounds().x(), - work_area.y(), - window->bounds().width(), + window->SetBounds(gfx::Rect(window->GetBounds().x(), work_area.y(), + window->GetBounds().width(), work_area.height())); } return true; @@ -346,24 +334,21 @@ bool DefaultState::ProcessCompoundEvents(WindowState* window_state, // Maximize horizontally if: // - The window does not have a max width defined. // - The window is snapped or has the normal state type. - if (window->delegate()->GetMaximumSize().width() != 0) + if (window->GetMaximumSize().width() != 0) return true; if (!window_state->IsNormalOrSnapped()) return true; - gfx::Rect work_area = - ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); + gfx::Rect work_area = GetDisplayWorkAreaBoundsInParent(window); if (window_state->IsNormalStateType() && window_state->HasRestoreBounds() && - (window->bounds().width() == work_area.width() && - window->bounds().x() == work_area.x())) { + (window->GetBounds().width() == work_area.width() && + window->GetBounds().x() == work_area.x())) { window_state->SetAndClearRestoreBounds(); } else { - gfx::Rect new_bounds(work_area.x(), - window->bounds().y(), - work_area.width(), - window->bounds().height()); + gfx::Rect new_bounds(work_area.x(), window->GetBounds().y(), + work_area.width(), window->GetBounds().height()); - gfx::Rect restore_bounds = window->bounds(); + gfx::Rect restore_bounds = window->GetBounds(); if (window_state->IsSnapped()) { window_state->SetRestoreBoundsInParent(new_bounds); window_state->Restore(); @@ -421,8 +406,8 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, return true; } - aura::Window* window = window_state->aura_window(); - gfx::Rect bounds = window->bounds(); + WmWindow* window = window_state->window(); + gfx::Rect bounds = window->GetBounds(); // Don't adjust window bounds if the bounds are empty as this // happens when a new views::Widget is created. @@ -440,13 +425,13 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, // be further shrunk by the docked area. The logic ensures 30% // visibility which should be enough to see where the window gets // moved. - gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window); + gfx::Rect display_area = GetDisplayBoundsInParent(window); int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, min_height, &bounds); window_state->AdjustSnappedBounds(&bounds); - if (window->bounds() != bounds) + if (window->GetBounds() != bounds) window_state->SetBoundsConstrained(bounds); return true; } @@ -456,14 +441,13 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, return true; } gfx::Rect work_area_in_parent = - ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window_state->aura_window()); - gfx::Rect bounds = window_state->aura_window()->bounds(); + GetDisplayWorkAreaBoundsInParent(window_state->window()); + gfx::Rect bounds = window_state->window()->GetBounds(); // When display bounds has changed, make sure the entire window is fully // visible. bounds.AdjustToFit(work_area_in_parent); window_state->AdjustSnappedBounds(&bounds); - if (window_state->aura_window()->bounds() != bounds) + if (window_state->window()->GetBounds() != bounds) window_state->SetBoundsDirectAnimated(bounds); return true; } @@ -471,9 +455,9 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, // Don't resize the maximized window when the desktop is covered // by fullscreen window. crbug.com/504299. bool in_fullscreen = - RootWindowController::ForWindow(window_state->aura_window()) - ->workspace_controller() - ->GetWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; + window_state->window() + ->GetRootWindowController() + ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; if (in_fullscreen && window_state->IsMaximized()) return true; @@ -482,13 +466,12 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, return true; } gfx::Rect work_area_in_parent = - ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window_state->aura_window()); - gfx::Rect bounds = window_state->aura_window()->bounds(); + GetDisplayWorkAreaBoundsInParent(window_state->window()); + gfx::Rect bounds = window_state->window()->GetBounds(); wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, &bounds); window_state->AdjustSnappedBounds(&bounds); - if (window_state->aura_window()->bounds() != bounds) + if (window_state->window()->GetBounds() != bounds) window_state->SetBoundsDirectAnimated(bounds); return true; } @@ -518,13 +501,13 @@ bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { DCHECK(!window_state->is_dragged()); if (window_state->IsMaximized()) { - window_state->SetBoundsDirect(ScreenUtil::GetMaximizedWindowBoundsInParent( - window_state->aura_window())); + window_state->SetBoundsDirect( + GetMaximizedWindowBoundsInParent(window_state->window())); return true; } if (window_state->IsFullscreen()) { window_state->SetBoundsDirect( - ScreenUtil::GetDisplayBoundsInParent(window_state->aura_window())); + GetDisplayBoundsInParent(window_state->window())); return true; } return false; @@ -539,8 +522,7 @@ void DefaultState::SetBounds(WindowState* window_state, window_state->SetBoundsDirect(event->requested_bounds()); } else if (window_state->IsSnapped()) { gfx::Rect work_area_in_parent = - ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window_state->aura_window()); + GetDisplayWorkAreaBoundsInParent(window_state->window()); gfx::Rect child_bounds(event->requested_bounds()); wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); window_state->AdjustSnappedBounds(&child_bounds); @@ -562,7 +544,7 @@ void DefaultState::EnterToNextState(WindowState* window_state, window_state->UpdateWindowShowStateFromStateType(); window_state->NotifyPreStateTypeChange(previous_state_type); - if (window_state->aura_window()->parent()) { + if (window_state->window()->GetParent()) { if (!window_state->HasRestoreBounds() && (previous_state_type == WINDOW_STATE_TYPE_DEFAULT || previous_state_type == WINDOW_STATE_TYPE_NORMAL) && @@ -636,23 +618,24 @@ void DefaultState::ReenterToCurrentState( void DefaultState::UpdateBoundsFromState(WindowState* window_state, WindowStateType previous_state_type) { - aura::Window* window = window_state->aura_window(); + WmWindow* window = window_state->window(); gfx::Rect bounds_in_parent; switch (state_type_) { case WINDOW_STATE_TYPE_LEFT_SNAPPED: case WINDOW_STATE_TYPE_RIGHT_SNAPPED: - bounds_in_parent = state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED ? - GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) : - GetDefaultRightSnappedWindowBoundsInParent(window_state->window()); + bounds_in_parent = + state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED + ? GetDefaultLeftSnappedWindowBoundsInParent(window) + : GetDefaultRightSnappedWindowBoundsInParent(window); break; case WINDOW_STATE_TYPE_DOCKED: { - if (window->parent()->id() != kShellWindowId_DockedContainer) { - aura::Window* docked_container = Shell::GetContainer( - window->GetRootWindow(), - kShellWindowId_DockedContainer); - wm::ReparentChildWithTransientChildren(window, - window->parent(), - docked_container); + if (window->GetParent()->GetShellWindowId() != + kShellWindowId_DockedContainer) { + WmWindow* docked_container = + window->GetRootWindow()->GetChildByShellWindowId( + kShellWindowId_DockedContainer); + ReparentChildWithTransientChildren(window, window->GetParent(), + docked_container); } // Return early because we don't want to update the bounds of the // window below; as the bounds are managed by the dock layout. @@ -660,9 +643,7 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, } case WINDOW_STATE_TYPE_DEFAULT: case WINDOW_STATE_TYPE_NORMAL: { - gfx::Rect work_area_in_parent = - ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window_state->aura_window()); + gfx::Rect work_area_in_parent = GetDisplayWorkAreaBoundsInParent(window); if (window_state->HasRestoreBounds()) { bounds_in_parent = window_state->GetRestoreBoundsInParent(); // Check if the |window|'s restored size is bigger than the working area @@ -676,7 +657,7 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, kMaximizedWindowInset, kMaximizedWindowInset); } } else { - bounds_in_parent = window->bounds(); + bounds_in_parent = window->GetBounds(); } // Make sure that part of the window is always visible. wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, @@ -684,11 +665,11 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, break; } case WINDOW_STATE_TYPE_MAXIMIZED: - bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window); + bounds_in_parent = GetMaximizedWindowBoundsInParent(window); break; case WINDOW_STATE_TYPE_FULLSCREEN: - bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window); + bounds_in_parent = GetDisplayBoundsInParent(window); break; case WINDOW_STATE_TYPE_DOCKED_MINIMIZED: @@ -718,23 +699,21 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, if (window_state->IsMinimized()) { // Save the previous show state so that we can correctly restore it. - window_state->aura_window()->SetProperty( - aura::client::kRestoreShowStateKey, - ToWindowShowState(previous_state_type)); - ::wm::SetWindowVisibilityAnimationType( - window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); + window->SetRestoreShowState(ToWindowShowState(previous_state_type)); + window->SetVisibilityAnimationType( + WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); // Hide the window. - window_state->window()->Hide(); + window->Hide(); // Activate another window. if (window_state->IsActive()) window_state->Deactivate(); - } else if ((window_state->window()->GetTargetVisibility() || + } else if ((window->GetTargetVisibility() || IsMinimizedWindowState(previous_state_type)) && - !window_state->aura_window()->layer()->visible()) { + !window->GetLayer()->visible()) { // The layer may be hidden if the window was previously minimized. Make // sure it's visible. - window_state->window()->Show(); + window->Show(); if (IsMinimizedWindowState(previous_state_type) && !window_state->IsMaximizedOrFullscreen()) { window_state->set_unminimize_to_restore_bounds(false); @@ -746,20 +725,18 @@ void DefaultState::UpdateBoundsFromState(WindowState* window_state, void DefaultState::CenterWindow(WindowState* window_state) { if (!window_state->IsNormalOrSnapped()) return; - aura::Window* window = window_state->aura_window(); + WmWindow* window = window_state->window(); if (window_state->IsSnapped()) { - gfx::Rect center_in_screen = - gfx::Screen::GetScreen()->GetDisplayNearestWindow(window).work_area(); - gfx::Size size = window_state->HasRestoreBounds() ? - window_state->GetRestoreBoundsInScreen().size() : - window->bounds().size(); + gfx::Rect center_in_screen = window->GetDisplayNearestWindow().work_area(); + gfx::Size size = window_state->HasRestoreBounds() + ? window_state->GetRestoreBoundsInScreen().size() + : window->GetBounds().size(); center_in_screen.ClampToCenteredSize(size); window_state->SetRestoreBoundsInScreen(center_in_screen); window_state->Restore(); } else { - gfx::Rect center_in_parent = - ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); - center_in_parent.ClampToCenteredSize(window->bounds().size()); + gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); + center_in_parent.ClampToCenteredSize(window->GetBounds().size()); window_state->SetBoundsDirectAnimated(center_in_parent); } // Centering window is treated as if a user moved and resized the window. diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc index facbdbf8e5d4ca..6d318aec8cf90a 100644 --- a/ash/wm/dock/docked_window_layout_manager.cc +++ b/ash/wm/dock/docked_window_layout_manager.cc @@ -13,6 +13,8 @@ #include "ash/shelf/shelf_widget.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/common/window_animation_types.h" +#include "ash/wm/common/window_parenting_utils.h" #include "ash/wm/coordinate_conversion.h" #include "ash/wm/window_animations.h" #include "ash/wm/window_properties.h" @@ -244,8 +246,11 @@ void UndockWindow(aura::Window* window) { gfx::Rect previous_bounds = window->bounds(); aura::Window* old_parent = window->parent(); aura::client::ParentWindowWithContext(window, window, gfx::Rect()); - if (window->parent() != old_parent) - wm::ReparentTransientChildrenOfChild(window, old_parent, window->parent()); + if (window->parent() != old_parent) { + wm::ReparentTransientChildrenOfChild( + wm::WmWindowAura::Get(window), wm::WmWindowAura::Get(old_parent), + wm::WmWindowAura::Get(window->parent())); + } // Start maximize or fullscreen (affecting packaged apps) animation from // previous window bounds. window->layer()->SetBounds(previous_bounds); @@ -432,7 +437,7 @@ DockedWindowLayoutManager::DockedWindowLayoutManager( shelf_(nullptr), workspace_controller_(workspace_controller), in_fullscreen_(workspace_controller_->GetWindowState() == - WORKSPACE_WINDOW_STATE_FULL_SCREEN), + wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN), docked_width_(0), alignment_(DOCKED_ALIGNMENT_NONE), preferred_alignment_(DOCKED_ALIGNMENT_NONE), @@ -792,7 +797,7 @@ void DockedWindowLayoutManager::OnFullscreenStateChanged( return; // Entering fullscreen mode (including immersive) hides docked windows. in_fullscreen_ = workspace_controller_->GetWindowState() == - WORKSPACE_WINDOW_STATE_FULL_SCREEN; + wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN; { // prevent Relayout from getting called multiple times during this base::AutoReset auto_reset_in_layout(&in_layout_, true); @@ -892,7 +897,7 @@ void DockedWindowLayoutManager::OnWindowVisibilityChanging( ::wm::SetWindowVisibilityAnimationDuration( window, base::TimeDelta::FromMilliseconds(kFadeDurationMs)); } else if (wm::GetWindowState(window)->IsMinimized()) { - animation_type = WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE; + animation_type = wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE; } ::wm::SetWindowVisibilityAnimationType(window, animation_type); } diff --git a/ash/wm/dock/docked_window_resizer.cc b/ash/wm/dock/docked_window_resizer.cc index 3de281ec546601..974d4486598b19 100644 --- a/ash/wm/dock/docked_window_resizer.cc +++ b/ash/wm/dock/docked_window_resizer.cc @@ -12,6 +12,8 @@ #include "ash/shelf/shelf_widget.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/aura/wm_window_aura.h" +#include "ash/wm/common/window_parenting_utils.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/dock/docked_window_layout_manager.h" #include "ash/wm/window_state.h" @@ -210,9 +212,10 @@ void DockedWindowResizer::StartedDragging( aura::Window* docked_container = Shell::GetContainer( GetTarget()->GetRootWindow(), kShellWindowId_DockedContainer); - wm::ReparentChildWithTransientChildren(GetTarget(), - GetTarget()->parent(), - docked_container); + ReparentChildWithTransientChildren( + ash::wm::WmWindowAura::Get(GetTarget()), + ash::wm::WmWindowAura::Get(GetTarget()->parent()), + ash::wm::WmWindowAura::Get(docked_container)); if (!resizer) return; } @@ -286,9 +289,10 @@ DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( if ((is_resized || !is_attached_panel) && is_docked_ != (window->parent() == dock_container)) { if (is_docked_) { - wm::ReparentChildWithTransientChildren(window, - window->parent(), - dock_container); + wm::ReparentChildWithTransientChildren( + wm::WmWindowAura::Get(window), + wm::WmWindowAura::Get(window->parent()), + wm::WmWindowAura::Get(dock_container)); action = DOCKED_ACTION_DOCK; } else if (window->parent()->id() == kShellWindowId_DockedContainer) { // Reparent the window back to workspace. @@ -302,9 +306,10 @@ DockedAction DockedWindowResizer::MaybeReparentWindowOnDragCompletion( aura::Window* previous_parent = window->parent(); aura::client::ParentWindowWithContext(window, window, near_last_location); if (window->parent() != previous_parent) { - wm::ReparentTransientChildrenOfChild(window, - previous_parent, - window->parent()); + wm::ReparentTransientChildrenOfChild( + ash::wm::WmWindowAura::Get(window), + ash::wm::WmWindowAura::Get(previous_parent), + ash::wm::WmWindowAura::Get(window->parent())); } action = was_docked_ ? DOCKED_ACTION_UNDOCK : DOCKED_ACTION_NONE; } diff --git a/ash/wm/lock_window_state.cc b/ash/wm/lock_window_state.cc index 1ebd6bc9ebc248..c14c1ca561ac2a 100644 --- a/ash/wm/lock_window_state.cc +++ b/ash/wm/lock_window_state.cc @@ -9,13 +9,14 @@ #include "ash/display/display_manager.h" #include "ash/screen_util.h" #include "ash/shell.h" +#include "ash/wm/common/window_animation_types.h" +#include "ash/wm/common/window_state_util.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/lock_layout_manager.h" #include "ash/wm/window_animations.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_aura.h" #include "ash/wm/window_state_delegate.h" -#include "ash/wm/window_state_util.h" #include "ash/wm/window_util.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" @@ -134,7 +135,8 @@ void LockWindowState::UpdateWindow(wm::WindowState* window_state, current_state_type_ = target_state; ::wm::SetWindowVisibilityAnimationType( - window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); + window_state->aura_window(), + wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); window_state->window()->Hide(); if (window_state->IsActive()) window_state->Deactivate(); diff --git a/ash/wm/maximize_mode/maximize_mode_window_state.cc b/ash/wm/maximize_mode/maximize_mode_window_state.cc index 997ec638db5957..34a962d04b1895 100644 --- a/ash/wm/maximize_mode/maximize_mode_window_state.cc +++ b/ash/wm/maximize_mode/maximize_mode_window_state.cc @@ -9,6 +9,8 @@ #include "ash/screen_util.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/common/window_animation_types.h" +#include "ash/wm/common/window_state_util.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/coordinate_conversion.h" #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" @@ -16,7 +18,6 @@ #include "ash/wm/window_properties.h" #include "ash/wm/window_state_aura.h" #include "ash/wm/window_state_delegate.h" -#include "ash/wm/window_state_util.h" #include "ash/wm/window_util.h" #include "ash/wm/workspace/workspace_window_resizer.h" #include "ui/aura/client/aura_constants.h" @@ -256,7 +257,8 @@ void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, current_state_type_ = target_state; ::wm::SetWindowVisibilityAnimationType( - window_state->aura_window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); + window_state->aura_window(), + wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); window_state->window()->Hide(); if (window_state->IsActive()) window_state->Deactivate(); diff --git a/ash/wm/panels/panel_layout_manager.cc b/ash/wm/panels/panel_layout_manager.cc index 3fb4738b014cad..e316b3044f9fdc 100644 --- a/ash/wm/panels/panel_layout_manager.cc +++ b/ash/wm/panels/panel_layout_manager.cc @@ -16,6 +16,9 @@ #include "ash/shelf/shelf_widget.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/aura/wm_window_aura.h" +#include "ash/wm/common/window_animation_types.h" +#include "ash/wm/common/window_parenting_utils.h" #include "ash/wm/overview/window_selector_controller.h" #include "ash/wm/window_animations.h" #include "ash/wm/window_state.h" @@ -349,7 +352,9 @@ void PanelLayoutManager::OnWindowAddedToLayout(aura::Window* child) { aura::Window* old_parent = child->parent(); aura::client::ParentWindowWithContext( child, child, child->GetRootWindow()->GetBoundsInScreen()); - wm::ReparentTransientChildrenOfChild(child, old_parent, child->parent()); + wm::ReparentTransientChildrenOfChild( + wm::WmWindowAura::Get(child), wm::WmWindowAura::Get(old_parent), + wm::WmWindowAura::Get(child->parent())); DCHECK(child->parent()->id() != kShellWindowId_PanelContainer); return; } @@ -561,7 +566,7 @@ void PanelLayoutManager::WillChangeVisibilityState( void PanelLayoutManager::MinimizePanel(aura::Window* panel) { ::wm::SetWindowVisibilityAnimationType( - panel, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); + panel, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); ui::Layer* layer = panel->layer(); ui::ScopedLayerAnimationSettings panel_slide_settings(layer->GetAnimator()); panel_slide_settings.SetPreemptionStrategy( diff --git a/ash/wm/panels/panel_window_resizer.cc b/ash/wm/panels/panel_window_resizer.cc index b5c44bc162c116..987c0c74a1fd9f 100644 --- a/ash/wm/panels/panel_window_resizer.cc +++ b/ash/wm/panels/panel_window_resizer.cc @@ -11,6 +11,7 @@ #include "ash/shelf/shelf_widget.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/common/window_parenting_utils.h" #include "ash/wm/panels/panel_layout_manager.h" #include "ash/wm/window_state.h" #include "ash/wm/window_util.h" @@ -181,7 +182,10 @@ void PanelWindowResizer::StartedDragging() { aura::Window* old_parent = target->parent(); aura::client::ParentWindowWithContext( target, target_root, target_root->GetBoundsInScreen()); - wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); + ash::wm::ReparentTransientChildrenOfChild( + ash::wm::WmWindowAura::Get(target), + ash::wm::WmWindowAura::Get(old_parent), + ash::wm::WmWindowAura::Get(target->parent())); } } @@ -197,7 +201,10 @@ void PanelWindowResizer::FinishDragging() { aura::Window* old_parent = target->parent(); aura::client::ParentWindowWithContext( target, target_root, gfx::Rect(last_location_, gfx::Size())); - wm::ReparentTransientChildrenOfChild(target, old_parent, target->parent()); + ash::wm::ReparentTransientChildrenOfChild( + ash::wm::WmWindowAura::Get(target), + ash::wm::WmWindowAura::Get(old_parent), + ash::wm::WmWindowAura::Get(target->parent())); } // If we started the drag in one root window and moved into another root diff --git a/ash/wm/system_gesture_event_filter_unittest.cc b/ash/wm/system_gesture_event_filter_unittest.cc index d8d6d58a562a2e..902154d5e4f0ae 100644 --- a/ash/wm/system_gesture_event_filter_unittest.cc +++ b/ash/wm/system_gesture_event_filter_unittest.cc @@ -16,10 +16,11 @@ #include "ash/test/display_manager_test_api.h" #include "ash/test/shell_test_api.h" #include "ash/test/test_shelf_delegate.h" +#include "ash/wm/aura/wm_window_aura.h" +#include "ash/wm/common/window_positioning_utils.h" #include "ash/wm/gestures/long_press_affordance_handler.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_aura.h" -#include "ash/wm/window_util.h" #include "base/time/time.h" #include "base/timer/timer.h" #include "ui/aura/env.h" @@ -485,8 +486,9 @@ TEST_F(SystemGestureEventFilterTest, DragLeftNearEdgeSnaps) { generator.GestureMultiFingerScroll( kTouchPoints, points, 120, kSteps, drag_x, 0); - EXPECT_EQ(wm::GetDefaultLeftSnappedWindowBoundsInParent( - toplevel_window).ToString(), + EXPECT_EQ(ash::wm::GetDefaultLeftSnappedWindowBoundsInParent( + ash::wm::WmWindowAura::Get(toplevel_window)) + .ToString(), toplevel_window->bounds().ToString()); } @@ -514,7 +516,8 @@ TEST_F(SystemGestureEventFilterTest, DragRightNearEdgeSnaps) { generator.GestureMultiFingerScroll( kTouchPoints, points, 120, kSteps, drag_x, 0); EXPECT_EQ(wm::GetDefaultRightSnappedWindowBoundsInParent( - toplevel_window).ToString(), + wm::WmWindowAura::Get(toplevel_window)) + .ToString(), toplevel_window->bounds().ToString()); } diff --git a/ash/wm/window_animations.cc b/ash/wm/window_animations.cc index 58417ecee30341..6822175846e459 100644 --- a/ash/wm/window_animations.cc +++ b/ash/wm/window_animations.cc @@ -13,6 +13,7 @@ #include "ash/shelf/shelf.h" #include "ash/shelf/shelf_layout_manager.h" #include "ash/shelf/shelf_widget.h" +#include "ash/wm/common/window_animation_types.h" #include "ash/wm/window_util.h" #include "ash/wm/workspace_controller.h" #include "base/command_line.h" @@ -227,10 +228,10 @@ bool AnimateShowWindow(aura::Window* window) { } switch (::wm::GetWindowVisibilityAnimationType(window)) { - case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: + case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: AnimateShowWindow_Minimize(window); return true; - case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: + case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: AnimateShowWindow_BrightnessGrayscale(window); return true; default: @@ -246,10 +247,10 @@ bool AnimateHideWindow(aura::Window* window) { } switch (::wm::GetWindowVisibilityAnimationType(window)) { - case WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: + case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE: AnimateHideWindow_Minimize(window); return true; - case WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: + case wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE: AnimateHideWindow_BrightnessGrayscale(window); return true; default: diff --git a/ash/wm/window_animations.h b/ash/wm/window_animations.h index 2e5d24bdbefb03..114086d662a775 100644 --- a/ash/wm/window_animations.h +++ b/ash/wm/window_animations.h @@ -26,16 +26,6 @@ namespace views { // with desktop Chrome, see ui/views/corewm/window_animations.h. namespace ash { -// An extension of the window animations provided by CoreWm. These should be -// Ash-specific only. -enum WindowVisibilityAnimationType { - // Window scale/rotates down to its launcher icon. - WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE = - ::wm::WINDOW_VISIBILITY_ANIMATION_MAX, - // Fade in/out using brightness and grayscale web filters. - WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE -}; - // Direction for ash-specific window animations used in workspaces and // lock/unlock animations. enum LayerScaleAnimationDirection { diff --git a/ash/wm/window_animations_unittest.cc b/ash/wm/window_animations_unittest.cc index d96dd286e7c090..3af7aee4038b6c 100644 --- a/ash/wm/window_animations_unittest.cc +++ b/ash/wm/window_animations_unittest.cc @@ -6,6 +6,7 @@ #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" +#include "ash/wm/common/window_animation_types.h" #include "ash/wm/window_state.h" #include "ash/wm/window_state_aura.h" #include "ash/wm/workspace_controller.h" @@ -71,8 +72,7 @@ TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { // Hiding. ::wm::SetWindowVisibilityAnimationType( - window.get(), - WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); + window.get(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); AnimateOnChildWindowVisibilityChanged(window.get(), false); EXPECT_EQ(0.0f, window->layer()->GetTargetOpacity()); EXPECT_FALSE(window->layer()->GetTargetVisibility()); @@ -80,8 +80,7 @@ TEST_F(WindowAnimationsTest, HideShowBrightnessGrayscaleAnimation) { // Showing. ::wm::SetWindowVisibilityAnimationType( - window.get(), - WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); + window.get(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE); AnimateOnChildWindowVisibilityChanged(window.get(), true); EXPECT_EQ(0.0f, window->layer()->GetTargetBrightness()); EXPECT_EQ(0.0f, window->layer()->GetTargetGrayscale()); diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc index f888f79fb60e51..c8e5f76041080b 100644 --- a/ash/wm/window_util.cc +++ b/ash/wm/window_util.cc @@ -34,25 +34,6 @@ namespace ash { namespace wm { -namespace { - -// Returns the default width of a snapped window. -int GetDefaultSnappedWindowWidth(wm::WmWindow* window) { - const float kSnappedWidthWorkspaceRatio = 0.5f; - - int work_area_width = GetDisplayWorkAreaBoundsInParent(window).width(); - int min_width = window->GetMinimumSize().width(); - int ideal_width = - static_cast(work_area_width * kSnappedWidthWorkspaceRatio); - return std::min(work_area_width, std::max(ideal_width, min_width)); -} - -int GetDefaultSnappedWindowWidth(aura::Window* window) { - return GetDefaultSnappedWindowWidth(WmWindowAura::Get(window)); -} - -} // namespace - // TODO(beng): replace many of these functions with the corewm versions. void ActivateWindow(aura::Window* window) { ::wm::ActivateWindow(window); @@ -92,39 +73,6 @@ void CenterWindow(aura::Window* window) { wm::GetWindowState(window)->OnWMEvent(&event); } -gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(wm::WmWindow* window) { - gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); - return gfx::Rect(work_area_in_parent.x(), work_area_in_parent.y(), - GetDefaultSnappedWindowWidth(window), - work_area_in_parent.height()); -} - -gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(wm::WmWindow* window) { - gfx::Rect work_area_in_parent(GetDisplayWorkAreaBoundsInParent(window)); - int width = GetDefaultSnappedWindowWidth(window); - return gfx::Rect(work_area_in_parent.right() - width, work_area_in_parent.y(), - width, work_area_in_parent.height()); -} - -gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent(aura::Window* window) { - gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window)); - return gfx::Rect(work_area_in_parent.x(), - work_area_in_parent.y(), - GetDefaultSnappedWindowWidth(window), - work_area_in_parent.height()); -} - -gfx::Rect GetDefaultRightSnappedWindowBoundsInParent(aura::Window* window) { - gfx::Rect work_area_in_parent(ScreenUtil::GetDisplayWorkAreaBoundsInParent( - window)); - int width = GetDefaultSnappedWindowWidth(window); - return gfx::Rect(work_area_in_parent.right() - width, - work_area_in_parent.y(), - width, - work_area_in_parent.height()); -} - bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { views::View* target = static_cast(event.target()); if (!target) @@ -140,27 +88,6 @@ bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) { return true; } -void ReparentChildWithTransientChildren(aura::Window* child, - aura::Window* old_parent, - aura::Window* new_parent) { - if (child->parent() == old_parent) - new_parent->AddChild(child); - ReparentTransientChildrenOfChild(child, old_parent, new_parent); -} - -void ReparentTransientChildrenOfChild(aura::Window* child, - aura::Window* old_parent, - aura::Window* new_parent) { - for (size_t i = 0; - i < ::wm::GetTransientChildren(child).size(); - ++i) { - ReparentChildWithTransientChildren( - ::wm::GetTransientChildren(child)[i], - old_parent, - new_parent); - } -} - void SnapWindowToPixelBoundary(aura::Window* window) { aura::Window* snapped_ancestor = window->parent(); while (snapped_ancestor) { diff --git a/ash/wm/window_util.h b/ash/wm/window_util.h index 78091598b503c7..a43f4a006aea17 100644 --- a/ash/wm/window_util.h +++ b/ash/wm/window_util.h @@ -51,39 +51,11 @@ ASH_EXPORT bool IsWindowUserPositionable(aura::Window* window); // Moves the window to the center of the display. ASH_EXPORT void CenterWindow(aura::Window* window); -ASH_EXPORT gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent( - wm::WmWindow* window); -ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent( - wm::WmWindow* window); - -// Returns the bounds of a left snapped window with default width in parent -// coordinates. -ASH_EXPORT gfx::Rect GetDefaultLeftSnappedWindowBoundsInParent( - aura::Window* window); - -// Returns the bounds of a right snapped window with default width in parent -// coordinates. -ASH_EXPORT gfx::Rect GetDefaultRightSnappedWindowBoundsInParent( - aura::Window* window); - // Moves |window| to the root window where the |event| occured if it is not // already in the same root window. Returns true if |window| was moved. ASH_EXPORT bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event); -// Changes the parent of a |child| and all its transient children that are -// themselves children of |old_parent| to |new_parent|. -void ReparentChildWithTransientChildren(aura::Window* child, - aura::Window* old_parent, - aura::Window* new_parent); - -// Changes the parent of all transient children of a |child| to |new_parent|. -// Does not change parent of the transient children that are not themselves -// children of |old_parent|. -void ReparentTransientChildrenOfChild(aura::Window* child, - aura::Window* old_parent, - aura::Window* new_parent); - // Snap the window's layer to physical pixel boundary. void SnapWindowToPixelBoundary(aura::Window* window); diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc index ed20fb5583eee9..16151b8ffc740d 100644 --- a/ash/wm/workspace/workspace_window_resizer.cc +++ b/ash/wm/workspace/workspace_window_resizer.cc @@ -15,6 +15,7 @@ #include "ash/screen_util.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" +#include "ash/wm/common/window_positioning_utils.h" #include "ash/wm/common/wm_event.h" #include "ash/wm/default_window_resizer.h" #include "ash/wm/dock/docked_window_layout_manager.h" @@ -966,9 +967,11 @@ void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, phantom_bounds = ScreenUtil::ConvertRectFromScreen( GetTarget()->parent(), dock_layout_->dragged_bounds()); } else { - phantom_bounds = (snap_type_ == SNAP_LEFT) ? - wm::GetDefaultLeftSnappedWindowBoundsInParent(GetTarget()) : - wm::GetDefaultRightSnappedWindowBoundsInParent(GetTarget()); + phantom_bounds = (snap_type_ == SNAP_LEFT) + ? wm::GetDefaultLeftSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(GetTarget())) + : wm::GetDefaultRightSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(GetTarget())); } if (!snap_phantom_window_controller_) { diff --git a/ash/wm/workspace/workspace_window_resizer_unittest.cc b/ash/wm/workspace/workspace_window_resizer_unittest.cc index c3873bc3a714dd..aac414ab59482c 100644 --- a/ash/wm/workspace/workspace_window_resizer_unittest.cc +++ b/ash/wm/workspace/workspace_window_resizer_unittest.cc @@ -566,7 +566,8 @@ TEST_F(WorkspaceWindowResizerTest, Edge) { { gfx::Rect expected_bounds_in_parent( - wm::GetDefaultLeftSnappedWindowBoundsInParent(window_.get())); + wm::GetDefaultLeftSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window_.get()))); std::unique_ptr resizer( CreateResizerForTest(window_.get(), gfx::Point(), HTCAPTION)); @@ -583,7 +584,8 @@ TEST_F(WorkspaceWindowResizerTest, Edge) { // Try the same with the right side. { gfx::Rect expected_bounds_in_parent( - wm::GetDefaultRightSnappedWindowBoundsInParent(window_.get())); + wm::GetDefaultRightSnappedWindowBoundsInParent( + wm::WmWindowAura::Get(window_.get()))); std::unique_ptr resizer( CreateResizerForTest(window_.get(), gfx::Point(), HTCAPTION)); diff --git a/ash/wm/workspace_controller.cc b/ash/wm/workspace_controller.cc index 76a9c596366e65..7f8fc587c9777f 100644 --- a/ash/wm/workspace_controller.cc +++ b/ash/wm/workspace_controller.cc @@ -62,14 +62,14 @@ WorkspaceController::~WorkspaceController() { viewport_->RemovePreTargetHandler(event_handler_.get()); } -WorkspaceWindowState WorkspaceController::GetWindowState() const { +wm::WorkspaceWindowState WorkspaceController::GetWindowState() const { if (!shelf_) - return WORKSPACE_WINDOW_STATE_DEFAULT; + return wm::WORKSPACE_WINDOW_STATE_DEFAULT; const aura::Window* topmost_fullscreen_window = GetRootWindowController( viewport_->GetRootWindow())->GetWindowForFullscreenMode(); if (topmost_fullscreen_window && !wm::GetWindowState(topmost_fullscreen_window)->ignored_by_shelf()) { - return WORKSPACE_WINDOW_STATE_FULL_SCREEN; + return wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN; } // These are the container ids of containers which may contain windows that @@ -91,7 +91,7 @@ WorkspaceWindowState WorkspaceController::GetWindowState() const { if (!layer->GetTargetVisibility()) continue; if (window_state->IsMaximized()) - return WORKSPACE_WINDOW_STATE_MAXIMIZED; + return wm::WORKSPACE_WINDOW_STATE_MAXIMIZED; if (!window_overlaps_launcher && ((*i)->bounds().Intersects(shelf_bounds))) { window_overlaps_launcher = true; @@ -99,9 +99,9 @@ WorkspaceWindowState WorkspaceController::GetWindowState() const { } } - return (window_overlaps_launcher || IsDockedAreaVisible(shelf_)) ? - WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF : - WORKSPACE_WINDOW_STATE_DEFAULT; + return (window_overlaps_launcher || IsDockedAreaVisible(shelf_)) + ? wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF + : wm::WORKSPACE_WINDOW_STATE_DEFAULT; } void WorkspaceController::SetShelf(ShelfLayoutManager* shelf) { diff --git a/ash/wm/workspace_controller.h b/ash/wm/workspace_controller.h index e34e111dc72d01..92045828335f40 100644 --- a/ash/wm/workspace_controller.h +++ b/ash/wm/workspace_controller.h @@ -8,7 +8,7 @@ #include #include "ash/ash_export.h" -#include "ash/wm/workspace/workspace_types.h" +#include "ash/wm/common/workspace/workspace_types.h" #include "base/macros.h" namespace aura { @@ -36,7 +36,7 @@ class ASH_EXPORT WorkspaceController { virtual ~WorkspaceController(); // Returns the current window state. - WorkspaceWindowState GetWindowState() const; + wm::WorkspaceWindowState GetWindowState() const; void SetShelf(ShelfLayoutManager* shelf); diff --git a/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc b/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc index d91d717b293d75..670ab59f0e1e9e 100644 --- a/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc +++ b/chrome/browser/chromeos/background/ash_user_wallpaper_delegate.cc @@ -6,6 +6,7 @@ #include "ash/desktop_background/user_wallpaper_delegate.h" #include "ash/shell.h" +#include "ash/wm/common/window_animation_types.h" #include "ash/wm/window_animations.h" #include "base/command_line.h" #include "base/logging.h" @@ -48,9 +49,9 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate { ~UserWallpaperDelegate() override {} int GetAnimationType() override { - return ShouldShowInitialAnimation() ? - ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE : - static_cast(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); + return ShouldShowInitialAnimation() + ? ash::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE + : static_cast(::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); } int GetAnimationDurationOverride() override { diff --git a/chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.cc b/chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.cc index c09ef576c11406..43ff95a71f1762 100644 --- a/chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.cc +++ b/chrome/browser/ui/ash/solid_color_user_wallpaper_delegate.cc @@ -7,6 +7,7 @@ #include "ash/desktop_background/desktop_background_controller.h" #include "ash/desktop_background/user_wallpaper_delegate.h" #include "ash/shell.h" +#include "ash/wm/common/window_animation_types.h" #include "ash/wm/window_animations.h" #include "base/macros.h" #include "ui/gfx/image/image_skia.h" @@ -25,9 +26,9 @@ class UserWallpaperDelegate : public ash::UserWallpaperDelegate { ~UserWallpaperDelegate() override {} int GetAnimationType() override { - return ShouldShowInitialAnimation() ? - ash::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE : - static_cast(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); + return ShouldShowInitialAnimation() + ? ash::wm::WINDOW_VISIBILITY_ANIMATION_TYPE_BRIGHTNESS_GRAYSCALE + : static_cast(wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); } bool ShouldShowInitialAnimation() override { return true; }