summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-19 00:52:03 +0000
committerpkotwicz@chromium.org <pkotwicz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-19 00:52:03 +0000
commit40e16762b22d3015ec00b51ff0072d0cbbf5fa43 (patch)
treebecc271f8a5229d6334037f1c3a2d4d650ae3a71
parent2f3cf692518ee451587002f4517060c55704135d (diff)
downloadchromium_src-40e16762b22d3015ec00b51ff0072d0cbbf5fa43.zip
chromium_src-40e16762b22d3015ec00b51ff0072d0cbbf5fa43.tar.gz
chromium_src-40e16762b22d3015ec00b51ff0072d0cbbf5fa43.tar.bz2
Refactor BaseLayoutManager and WorkspaceLayoutManager to use ash::wm::WindowShowType instead of ui::WindowShowState.
BUG=281766 TEST=None Review URL: https://codereview.chromium.org/111643014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241729 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/wm/base_layout_manager.cc55
-rw-r--r--ash/wm/base_layout_manager.h12
-rw-r--r--ash/wm/window_state.cc17
-rw-r--r--ash/wm/window_state.h2
-rw-r--r--ash/wm/wm_types.cc4
-rw-r--r--ash/wm/wm_types.h12
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc148
-rw-r--r--ash/wm/workspace/workspace_layout_manager.h12
8 files changed, 119 insertions, 143 deletions
diff --git a/ash/wm/base_layout_manager.cc b/ash/wm/base_layout_manager.cc
index 5070654..55daac7 100644
--- a/ash/wm/base_layout_manager.cc
+++ b/ash/wm/base_layout_manager.cc
@@ -74,7 +74,7 @@ void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) {
// Only update the bounds if the window has a show state that depends on the
// workspace area.
if (window_state->IsMaximizedOrFullscreen())
- UpdateBoundsFromShowState(window_state);
+ UpdateBoundsFromShowType(window_state);
}
void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
@@ -149,35 +149,30 @@ void BaseLayoutManager::OnDisplayWorkAreaInsetsChanged() {
void BaseLayoutManager::OnWindowShowTypeChanged(wm::WindowState* window_state,
wm::WindowShowType old_type) {
- ui::WindowShowState old_state = ToWindowShowState(old_type);
- ui::WindowShowState new_state = window_state->GetShowState();
-
- if (old_state != new_state && old_state != ui::SHOW_STATE_MINIMIZED &&
+ if (old_type != wm::SHOW_TYPE_MINIMIZED &&
!window_state->HasRestoreBounds() &&
- ((new_state == ui::SHOW_STATE_MAXIMIZED &&
- old_state != ui::SHOW_STATE_FULLSCREEN) ||
- (new_state == ui::SHOW_STATE_FULLSCREEN &&
- old_state != ui::SHOW_STATE_MAXIMIZED))) {
+ window_state->IsMaximizedOrFullscreen() &&
+ !wm::IsMaximizedOrFullscreenWindowShowType(old_type)) {
window_state->SetRestoreBoundsInParent(window_state->window()->bounds());
}
- UpdateBoundsFromShowState(window_state);
- ShowStateChanged(window_state, old_state);
+ UpdateBoundsFromShowType(window_state);
+ ShowTypeChanged(window_state, old_type);
}
//////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, protected:
-void BaseLayoutManager::ShowStateChanged(
+void BaseLayoutManager::ShowTypeChanged(
wm::WindowState* window_state,
- ui::WindowShowState last_show_state) {
+ wm::WindowShowType last_show_type) {
if (window_state->IsMinimized()) {
- if (last_show_state == ui::SHOW_STATE_MINIMIZED)
+ if (last_show_type == wm::SHOW_TYPE_MINIMIZED)
return;
// Save the previous show state so that we can correctly restore it.
window_state->window()->SetProperty(aura::client::kRestoreShowStateKey,
- last_show_state);
+ wm::ToWindowShowState(last_show_type));
views::corewm::SetWindowVisibilityAnimationType(
window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
@@ -187,12 +182,12 @@ void BaseLayoutManager::ShowStateChanged(
if (window_state->IsActive())
window_state->Deactivate();
} else if ((window_state->window()->TargetVisibility() ||
- last_show_state == ui::SHOW_STATE_MINIMIZED) &&
+ last_show_type == wm::SHOW_TYPE_MINIMIZED) &&
!window_state->window()->layer()->visible()) {
// The layer may be hidden if the window was previously minimized. Make
// sure it's visible.
window_state->window()->Show();
- if (last_show_state == ui::SHOW_STATE_MINIMIZED &&
+ if (last_show_type == wm::SHOW_TYPE_MINIMIZED &&
!window_state->IsMaximizedOrFullscreen()) {
window_state->set_always_restores_to_restore_bounds(false);
}
@@ -244,12 +239,12 @@ void BaseLayoutManager::AdjustWindowBoundsForWorkAreaChange(
//////////////////////////////////////////////////////////////////////////////
// BaseLayoutManager, private:
-void BaseLayoutManager::UpdateBoundsFromShowState(
+void BaseLayoutManager::UpdateBoundsFromShowType(
wm::WindowState* window_state) {
aura::Window* window = window_state->window();
- switch (window_state->GetShowState()) {
- case ui::SHOW_STATE_DEFAULT:
- case ui::SHOW_STATE_NORMAL: {
+ switch (window_state->window_show_type()) {
+ case wm::SHOW_TYPE_DEFAULT:
+ case wm::SHOW_TYPE_NORMAL:
if (window_state->HasRestoreBounds()) {
gfx::Rect bounds_in_parent = window_state->GetRestoreBoundsInParent();
SetChildBoundsDirect(window,
@@ -258,21 +253,31 @@ void BaseLayoutManager::UpdateBoundsFromShowState(
}
window_state->ClearRestoreBounds();
break;
- }
- case ui::SHOW_STATE_MAXIMIZED:
+ case wm::SHOW_TYPE_LEFT_SNAPPED:
+ case wm::SHOW_TYPE_RIGHT_SNAPPED:
+ if (window_state->HasRestoreBounds())
+ SetChildBoundsDirect(window, window_state->GetRestoreBoundsInParent());
+ window_state->ClearRestoreBounds();
+ break;
+
+ case wm::SHOW_TYPE_MAXIMIZED:
SetChildBoundsDirect(
window, ScreenAsh::GetMaximizedWindowBoundsInParent(window));
break;
- case ui::SHOW_STATE_FULLSCREEN:
+ case wm::SHOW_TYPE_FULLSCREEN:
// Don't animate the full-screen window transition.
// TODO(jamescook): Use animation here. Be sure the lock screen works.
SetChildBoundsDirect(window,
ScreenAsh::GetDisplayBoundsInParent(window));
break;
- default:
+ case wm::SHOW_TYPE_MINIMIZED:
+ case wm::SHOW_TYPE_INACTIVE:
+ case wm::SHOW_TYPE_DETACHED:
+ case wm::SHOW_TYPE_END:
+ case wm::SHOW_TYPE_AUTO_POSITIONED:
break;
}
}
diff --git a/ash/wm/base_layout_manager.h b/ash/wm/base_layout_manager.h
index 6f74e4c..341915e 100644
--- a/ash/wm/base_layout_manager.h
+++ b/ash/wm/base_layout_manager.h
@@ -10,12 +10,12 @@
#include "ash/ash_export.h"
#include "ash/shell_observer.h"
#include "ash/wm/window_state_observer.h"
+#include "ash/wm/wm_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/aura/client/activation_change_observer.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_observer.h"
-#include "ui/base/ui_base_types.h"
#include "ui/events/event_handler.h"
namespace aura {
@@ -87,9 +87,9 @@ class ASH_EXPORT BaseLayoutManager
ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED,
};
- // Invoked from OnWindowPropertyChanged() if |kShowStateKey| changes.
- virtual void ShowStateChanged(wm::WindowState* window_state,
- ui::WindowShowState last_show_state);
+ // Invoked from OnWindowShowTypeChanged().
+ virtual void ShowTypeChanged(wm::WindowState* window_state,
+ wm::WindowShowType last_show_type);
// Adjusts the window's bounds when the display area changes for given
// window. This happens when the display size, work area insets or
@@ -111,8 +111,8 @@ class ASH_EXPORT BaseLayoutManager
aura::Window* root_window() { return root_window_; }
private:
- // Update window bounds based on a change in show state.
- void UpdateBoundsFromShowState(wm::WindowState* controller);
+ // Update window bounds based on a change in show type.
+ void UpdateBoundsFromShowType(wm::WindowState* controller);
// Set of windows we're listening to.
WindowSet windows_;
diff --git a/ash/wm/window_state.cc b/ash/wm/window_state.cc
index 4bc1484..fdbe06f 100644
--- a/ash/wm/window_state.cc
+++ b/ash/wm/window_state.cc
@@ -24,12 +24,6 @@
namespace ash {
namespace wm {
-// static
-bool WindowState::IsMaximizedOrFullscreenState(ui::WindowShowState show_state) {
- return show_state == ui::SHOW_STATE_FULLSCREEN ||
- show_state == ui::SHOW_STATE_MAXIMIZED;
-}
-
WindowState::WindowState(aura::Window* window)
: window_(window),
window_position_managed_(false),
@@ -88,7 +82,9 @@ bool WindowState::IsFullscreen() const {
}
bool WindowState::IsMaximizedOrFullscreen() const {
- return IsMaximizedOrFullscreenState(GetShowState());
+ ui::WindowShowState show_state(GetShowState());
+ return show_state == ui::SHOW_STATE_FULLSCREEN ||
+ show_state == ui::SHOW_STATE_MAXIMIZED;
}
bool WindowState::IsNormalShowState() const {
@@ -281,13 +277,6 @@ void WindowState::SnapWindow(WindowShowType left_or_right,
// which width to use when the snapped window is moved to the edge.
SetRestoreBoundsInParent(bounds);
- bool was_maximized = IsMaximizedOrFullscreen();
- // Before we can set the bounds we need to restore the window.
- // Restoring the window will set the window to its restored bounds set above.
- // Restore will cause OnWindowPropertyChanged() so it needs to be done
- // before notifying that the WindowShowType has changed to |left_or_right|.
- if (was_maximized)
- Restore();
DCHECK(left_or_right == SHOW_TYPE_LEFT_SNAPPED ||
left_or_right == SHOW_TYPE_RIGHT_SNAPPED);
SetWindowShowType(left_or_right);
diff --git a/ash/wm/window_state.h b/ash/wm/window_state.h
index 618349c..33987d0 100644
--- a/ash/wm/window_state.h
+++ b/ash/wm/window_state.h
@@ -41,8 +41,6 @@ class WindowStateObserver;
// accessing the window using |window()| is cheap.
class ASH_EXPORT WindowState : public aura::WindowObserver {
public:
- static bool IsMaximizedOrFullscreenState(ui::WindowShowState state);
-
explicit WindowState(aura::Window* window);
virtual ~WindowState();
diff --git a/ash/wm/wm_types.cc b/ash/wm/wm_types.cc
index c7f45ce..a6e2553 100644
--- a/ash/wm/wm_types.cc
+++ b/ash/wm/wm_types.cc
@@ -45,5 +45,9 @@ ui::WindowShowState ToWindowShowState(WindowShowType type) {
return ui::SHOW_STATE_DEFAULT;
}
+bool IsMaximizedOrFullscreenWindowShowType(WindowShowType type) {
+ return type == SHOW_TYPE_MAXIMIZED || type == SHOW_TYPE_FULLSCREEN;
+}
+
} // namespace wm
} // namespace ash
diff --git a/ash/wm/wm_types.h b/ash/wm/wm_types.h
index da3db00..df402d1 100644
--- a/ash/wm/wm_types.h
+++ b/ash/wm/wm_types.h
@@ -5,6 +5,7 @@
#ifndef ASH_WM_WM_TYPES_H_
#define ASH_WM_WM_TYPES_H_
+#include "ash/ash_export.h"
#include "ui/base/ui_base_types.h"
namespace ash {
@@ -43,10 +44,13 @@ enum WindowShowType {
// Utility functions to convert WindowShowType <-> ui::WindowShowState.
// Note: LEFT/RIGHT MAXIMIZED, AUTO_POSITIONED type will be lost when
// converting to ui::WindowShowState.
-WindowShowType ToWindowShowType(ui::WindowShowState state);
-ui::WindowShowState ToWindowShowState(WindowShowType type);
+ASH_EXPORT WindowShowType ToWindowShowType(ui::WindowShowState state);
+ASH_EXPORT ui::WindowShowState ToWindowShowState(WindowShowType type);
-} // namespace
-} // namespace
+// Returns true if |type| is SHOW_TYPE_MAXIMIZED or SHOW_TYPE_FULLSCREEN.
+ASH_EXPORT bool IsMaximizedOrFullscreenWindowShowType(WindowShowType type);
+
+} // namespace wm
+} // namespace ash
#endif // ASH_WM_WM_TYPES_H_
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index f388632..672cded 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -166,46 +166,39 @@ void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) {
void WorkspaceLayoutManager::OnWindowShowTypeChanged(
wm::WindowState* window_state,
wm::WindowShowType old_type) {
- ui::WindowShowState old_state = ToWindowShowState(old_type);
- ui::WindowShowState new_state = window_state->GetShowState();
- if (old_state != ui::SHOW_STATE_MINIMIZED &&
+ if (old_type != wm::SHOW_TYPE_MINIMIZED &&
!window_state->HasRestoreBounds() &&
window_state->IsMaximizedOrFullscreen() &&
- !wm::WindowState::IsMaximizedOrFullscreenState(old_state)) {
+ !wm::IsMaximizedOrFullscreenWindowShowType(old_type)) {
window_state->SaveCurrentBoundsForRestore();
}
- // When restoring from a minimized state, we want to restore to the
- // previous (maybe L/R maximized) state. Since we do also want to keep the
- // restore rectangle, we set the restore rectangle to the rectangle we want
- // to restore to and restore it after we switched so that it is preserved.
+ // When restoring from a minimized state, we want to restore to the previous
+ // bounds. However, we want to maintain the restore bounds. (The restore
+ // bounds are set if a user maximized the window in one axis by double
+ // clicking the window border for example).
gfx::Rect restore;
- if (old_state == ui::SHOW_STATE_MINIMIZED &&
- (new_state == ui::SHOW_STATE_NORMAL ||
- new_state == ui::SHOW_STATE_DEFAULT) &&
+ if (old_type == wm::SHOW_TYPE_MINIMIZED &&
+ window_state->IsNormalShowState() &&
window_state->HasRestoreBounds() &&
!window_state->always_restores_to_restore_bounds()) {
restore = window_state->GetRestoreBoundsInScreen();
window_state->SaveCurrentBoundsForRestore();
}
- // Notify observers that fullscreen state may be changing.
- if (old_state != new_state &&
- (new_state == ui::SHOW_STATE_FULLSCREEN ||
- old_state == ui::SHOW_STATE_FULLSCREEN)) {
- UpdateFullscreenState();
- }
- UpdateBoundsFromShowState(window_state, old_state);
- ShowStateChanged(window_state, old_state);
+ UpdateBoundsFromShowType(window_state, old_type);
+ ShowTypeChanged(window_state, old_type);
+
+ if (window_state->IsNormalShowState())
+ window_state->ClearRestoreBounds();
// Set the restore rectangle to the previously set restore rectangle.
if (!restore.IsEmpty())
window_state->SetRestoreBoundsInScreen(restore);
-}
-void WorkspaceLayoutManager::ShowStateChanged(
- wm::WindowState* state,
- ui::WindowShowState last_show_state) {
- BaseLayoutManager::ShowStateChanged(state, last_show_state);
+ // Notify observers that fullscreen state may be changing.
+ if (window_state->IsFullscreen() || old_type == wm::SHOW_TYPE_FULLSCREEN)
+ UpdateFullscreenState();
+
UpdateShelfVisibility();
}
@@ -308,82 +301,67 @@ void WorkspaceLayoutManager::UpdateFullscreenState() {
}
}
-void WorkspaceLayoutManager::UpdateBoundsFromShowState(
+void WorkspaceLayoutManager::UpdateBoundsFromShowType(
wm::WindowState* window_state,
- ui::WindowShowState last_show_state) {
+ wm::WindowShowType old_show_type) {
aura::Window* window = window_state->window();
// See comment in SetMaximizedOrFullscreenBounds() as to why we use parent in
// these calculation.
- // TODO(varkha): Change the switch statement below to use wm::WindowShowType.
- switch (window_state->GetShowState()) {
- case ui::SHOW_STATE_DEFAULT:
- case ui::SHOW_STATE_NORMAL: {
- // Make sure that the part of the window is always visible
- // when restored.
- gfx::Rect bounds_in_parent;
- if (window_state->HasRestoreBounds()) {
+ if (window_state->IsMaximizedOrFullscreen())
+ MoveToDisplayForRestore(window_state);
+
+ wm::WindowShowType show_type = window_state->window_show_type();
+ gfx::Rect bounds_in_parent;
+ switch (show_type) {
+ case wm::SHOW_TYPE_DEFAULT:
+ case wm::SHOW_TYPE_NORMAL:
+ case wm::SHOW_TYPE_LEFT_SNAPPED:
+ case wm::SHOW_TYPE_RIGHT_SNAPPED:
+ if (window_state->HasRestoreBounds())
bounds_in_parent = window_state->GetRestoreBoundsInParent();
- ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
- work_area_in_parent_, &bounds_in_parent);
- } else {
- // Minimized windows have no restore bounds.
- // Use the current bounds instead.
+ else
bounds_in_parent = window->bounds();
- ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
- work_area_in_parent_, &bounds_in_parent);
- // Don't start animation if the bounds didn't change.
- if (bounds_in_parent == window->bounds())
- bounds_in_parent.SetRect(0, 0, 0, 0);
- }
- if (!bounds_in_parent.IsEmpty()) {
- if ((last_show_state == ui::SHOW_STATE_DEFAULT ||
- last_show_state == ui::SHOW_STATE_NORMAL) &&
- window_state->IsSnapped()) {
- AdjustSnappedBounds(window_state, &bounds_in_parent);
- SetChildBoundsAnimated(window, bounds_in_parent);
- } else {
- gfx::Rect new_bounds = BaseLayoutManager::BoundsWithScreenEdgeVisible(
- window->parent()->parent(),
- bounds_in_parent);
- if (last_show_state == ui::SHOW_STATE_MINIMIZED)
- SetChildBoundsDirect(window, new_bounds);
- else
- CrossFadeToBounds(window, new_bounds);
- }
+ // Make sure that part of the window is always visible.
+ wm::AdjustBoundsToEnsureMinimumWindowVisibility(
+ work_area_in_parent_, &bounds_in_parent);
+
+ if (show_type == wm::SHOW_TYPE_LEFT_SNAPPED ||
+ show_type == wm::SHOW_TYPE_RIGHT_SNAPPED) {
+ AdjustSnappedBounds(window_state, &bounds_in_parent);
+ } else {
+ bounds_in_parent = BaseLayoutManager::BoundsWithScreenEdgeVisible(
+ window->parent()->parent(),
+ bounds_in_parent);
}
- window_state->ClearRestoreBounds();
break;
- }
- case ui::SHOW_STATE_MAXIMIZED: {
- MoveToDisplayForRestore(window_state);
- gfx::Rect new_bounds = ScreenAsh::GetMaximizedWindowBoundsInParent(
+ case wm::SHOW_TYPE_MAXIMIZED:
+ bounds_in_parent = ScreenAsh::GetMaximizedWindowBoundsInParent(
window->parent()->parent());
- // If the window is restored from minimized state, do not make the cross
- // fade animation and set the child bounds directly. The restoring
- // animation will be done by ash/wm/window_animations.cc.
- if (last_show_state == ui::SHOW_STATE_MINIMIZED)
- SetChildBoundsDirect(window, new_bounds);
- else
- CrossFadeToBounds(window, new_bounds);
break;
- }
- case ui::SHOW_STATE_FULLSCREEN: {
- MoveToDisplayForRestore(window_state);
- gfx::Rect new_bounds = ScreenAsh::GetDisplayBoundsInParent(
+ case wm::SHOW_TYPE_FULLSCREEN:
+ bounds_in_parent = ScreenAsh::GetDisplayBoundsInParent(
window->parent()->parent());
- if (window_state->animate_to_fullscreen() &&
- last_show_state != ui::SHOW_STATE_MINIMIZED) {
- CrossFadeToBounds(window, new_bounds);
- } else {
- SetChildBoundsDirect(window, new_bounds);
- }
break;
- }
- default:
- break;
+ case wm::SHOW_TYPE_MINIMIZED:
+ case wm::SHOW_TYPE_INACTIVE:
+ case wm::SHOW_TYPE_DETACHED:
+ case wm::SHOW_TYPE_END:
+ case wm::SHOW_TYPE_AUTO_POSITIONED:
+ return;
+ }
+
+ if (old_show_type == wm::SHOW_TYPE_MINIMIZED ||
+ (window_state->IsFullscreen() &&
+ !window_state->animate_to_fullscreen())) {
+ SetChildBoundsDirect(window, bounds_in_parent);
+ } else if (window_state->IsMaximizedOrFullscreen() ||
+ IsMaximizedOrFullscreenWindowShowType(old_show_type)) {
+ CrossFadeToBounds(window, bounds_in_parent);
+ } else {
+ SetChildBoundsAnimated(window, bounds_in_parent);
}
}
diff --git a/ash/wm/workspace/workspace_layout_manager.h b/ash/wm/workspace/workspace_layout_manager.h
index ab4876c..5447ba2 100644
--- a/ash/wm/workspace/workspace_layout_manager.h
+++ b/ash/wm/workspace/workspace_layout_manager.h
@@ -9,9 +9,9 @@
#include "ash/shell_observer.h"
#include "ash/wm/base_layout_manager.h"
+#include "ash/wm/wm_types.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "ui/base/ui_base_types.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/rect.h"
@@ -63,8 +63,6 @@ class ASH_EXPORT WorkspaceLayoutManager : public BaseLayoutManager {
private:
// Overridden from BaseLayoutManager:
- virtual void ShowStateChanged(wm::WindowState* window_state,
- ui::WindowShowState last_show_state) OVERRIDE;
virtual void AdjustAllWindowsBoundsForWorkAreaChange(
AdjustWindowReason reason) OVERRIDE;
virtual void AdjustWindowBoundsForWorkAreaChange(
@@ -80,10 +78,10 @@ class ASH_EXPORT WorkspaceLayoutManager : public BaseLayoutManager {
// has changed.
void UpdateFullscreenState();
- // Updates the bounds of the window for a show state change from
- // |last_show_state|.
- void UpdateBoundsFromShowState(wm::WindowState* window_state,
- ui::WindowShowState last_show_state);
+ // Updates the bounds of the window for a show type change from
+ // |old_show_type|.
+ void UpdateBoundsFromShowType(wm::WindowState* window_state,
+ wm::WindowShowType old_show_type);
// If |window_state| is maximized or fullscreen the bounds of the
// window are set and true is returned. Does nothing otherwise.