Index: ash/wm/workspace/workspace_event_handler.cc |
diff --git a/ash/wm/workspace/workspace_event_handler.cc b/ash/wm/workspace/workspace_event_handler.cc |
index 870a925c03d01277e029e7ba4779c345720b4cb3..e174644927d6653e2cc54184f356acef9c0306df 100644 |
--- a/ash/wm/workspace/workspace_event_handler.cc |
+++ b/ash/wm/workspace/workspace_event_handler.cc |
@@ -9,7 +9,7 @@ |
#include "ash/shell_delegate.h" |
#include "ash/touch/touch_uma.h" |
#include "ash/wm/coordinate_conversion.h" |
-#include "ash/wm/property_util.h" |
+#include "ash/wm/window_state.h" |
#include "ash/wm/window_util.h" |
#include "ash/wm/workspace/workspace_window_resizer.h" |
#include "ui/aura/client/aura_constants.h" |
@@ -24,36 +24,29 @@ |
namespace ash { |
namespace { |
-void SingleAxisMaximize(aura::Window* window, |
+void SingleAxisMaximize(wm::WindowState* window_state, |
const gfx::Rect& maximize_rect_in_screen) { |
- gfx::Rect bounds_in_screen = |
- ScreenAsh::ConvertRectToScreen(window->parent(), window->bounds()); |
- SetRestoreBoundsInScreen(window, bounds_in_screen); |
- gfx::Rect bounds_in_parent = |
- ScreenAsh::ConvertRectFromScreen(window->parent(), |
- maximize_rect_in_screen); |
- window->SetBounds(bounds_in_parent); |
+ window_state->SaveCurrentBoundsForRestore(); |
+ window_state->SetBoundsInScreen(maximize_rect_in_screen); |
} |
-void SingleAxisUnmaximize(aura::Window* window, |
+void SingleAxisUnmaximize(wm::WindowState* window_state, |
const gfx::Rect& restore_bounds_in_screen) { |
- gfx::Rect restore_bounds = ScreenAsh::ConvertRectFromScreen( |
- window->parent(), restore_bounds_in_screen); |
- window->SetBounds(restore_bounds); |
- ClearRestoreBounds(window); |
+ window_state->SetBoundsInScreen(restore_bounds_in_screen); |
+ window_state->ClearRestoreBounds(); |
} |
-void ToggleMaximizedState(aura::Window* window) { |
- if (GetRestoreBoundsInScreen(window)) { |
- if (window->GetProperty(aura::client::kShowStateKey) == |
- ui::SHOW_STATE_NORMAL) { |
- window->SetBounds(GetRestoreBoundsInParent(window)); |
- ClearRestoreBounds(window); |
+void ToggleMaximizedState(wm::WindowState* window_state) { |
+ if (window_state->HasRestoreBounds()) { |
+ if (window_state->GetShowState() == ui::SHOW_STATE_NORMAL) { |
+ window_state->window()->SetBounds( |
+ window_state->GetRestoreBoundsInParent()); |
+ window_state->ClearRestoreBounds(); |
} else { |
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); |
+ window_state->Restore(); |
} |
- } else if (wm::CanMaximizeWindow(window)) { |
- window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); |
+ } else if (window_state->CanMaximize()) { |
+ window_state->Maximize(); |
} |
} |
@@ -93,7 +86,7 @@ void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
ToplevelWindowEventHandler::OnMouseEvent(event); |
return; |
} |
- |
+ wm::WindowState* target_state = wm::GetWindowState(target); |
if (event->flags() & ui::EF_IS_DOUBLE_CLICK && |
event->IsOnlyLeftMouseButton() && |
target->delegate()->GetNonClientComponent(event->location()) == |
@@ -103,13 +96,13 @@ void WorkspaceEventHandler::OnMouseEvent(ui::MouseEvent* event) { |
destroyed_ = &destroyed; |
ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( |
ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); |
- ToggleMaximizedState(target); |
+ ToggleMaximizedState(target_state); |
if (destroyed) |
return; |
destroyed_ = NULL; |
} |
multi_window_resize_controller_.Hide(); |
- HandleVerticalResizeDoubleClick(target, event); |
+ HandleVerticalResizeDoubleClick(target_state, event); |
break; |
} |
default: |
@@ -130,7 +123,8 @@ void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
// TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. |
TouchUMA::GetInstance()->RecordGestureAction( |
TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); |
- ToggleMaximizedState(target); // |this| may be destroyed from here. |
+ // |this| may be destroyed from here. |
+ ToggleMaximizedState(wm::GetWindowState(target)); |
event->StopPropagation(); |
return; |
} else { |
@@ -143,29 +137,28 @@ void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
} |
void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
- aura::Window* target, |
+ wm::WindowState* target_state, |
ui::MouseEvent* event) { |
+ aura::Window* target = target_state->window(); |
gfx::Rect max_size(target->delegate()->GetMaximumSize()); |
- if (event->flags() & ui::EF_IS_DOUBLE_CLICK && |
- !wm::IsWindowMaximized(target)) { |
+ if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target_state->IsMaximized()) { |
int component = |
target->delegate()->GetNonClientComponent(event->location()); |
- gfx::Rect work_area = |
- Shell::GetScreen()->GetDisplayNearestWindow(target).work_area(); |
- const gfx::Rect* restore_bounds = |
- GetRestoreBoundsInScreen(target); |
+ gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow( |
+ target).work_area(); |
if (component == HTBOTTOM || component == HTTOP) { |
// Don't maximize vertically if the window has a max height defined. |
if (max_size.height() != 0) |
return; |
- if (restore_bounds && |
+ if (target_state->HasRestoreBounds() && |
(target->bounds().height() == work_area.height() && |
target->bounds().y() == work_area.y())) { |
- SingleAxisUnmaximize(target, *restore_bounds); |
+ SingleAxisUnmaximize(target_state, |
+ target_state->GetRestoreBoundsInScreen()); |
} else { |
gfx::Point origin = target->bounds().origin(); |
wm::ConvertPointToScreen(target->parent(), &origin); |
- SingleAxisMaximize(target, |
+ SingleAxisMaximize(target_state, |
gfx::Rect(origin.x(), |
work_area.y(), |
target->bounds().width(), |
@@ -175,14 +168,15 @@ void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( |
// Don't maximize horizontally if the window has a max width defined. |
if (max_size.width() != 0) |
return; |
- if (restore_bounds && |
+ if (target_state->HasRestoreBounds() && |
(target->bounds().width() == work_area.width() && |
target->bounds().x() == work_area.x())) { |
- SingleAxisUnmaximize(target, *restore_bounds); |
+ SingleAxisUnmaximize(target_state, |
+ target_state->GetRestoreBoundsInScreen()); |
} else { |
gfx::Point origin = target->bounds().origin(); |
wm::ConvertPointToScreen(target->parent(), &origin); |
- SingleAxisMaximize(target, |
+ SingleAxisMaximize(target_state, |
gfx::Rect(work_area.x(), |
origin.y(), |
work_area.width(), |