Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: ash/wm/workspace/workspace_event_handler.cc

Issue 24108003: [Cleanup] Rename WindowSettings to WindowState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/workspace/workspace_event_handler.h" 5 #include "ash/wm/workspace/workspace_event_handler.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.h"
10 #include "ash/touch/touch_uma.h" 10 #include "ash/touch/touch_uma.h"
11 #include "ash/wm/coordinate_conversion.h" 11 #include "ash/wm/coordinate_conversion.h"
12 #include "ash/wm/property_util.h" 12 #include "ash/wm/window_state.h"
13 #include "ash/wm/window_util.h" 13 #include "ash/wm/window_util.h"
14 #include "ash/wm/workspace/workspace_window_resizer.h" 14 #include "ash/wm/workspace/workspace_window_resizer.h"
15 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_delegate.h" 17 #include "ui/aura/window_delegate.h"
18 #include "ui/base/events/event.h" 18 #include "ui/base/events/event.h"
19 #include "ui/base/events/event_utils.h" 19 #include "ui/base/events/event_utils.h"
20 #include "ui/base/hit_test.h" 20 #include "ui/base/hit_test.h"
21 #include "ui/compositor/scoped_layer_animation_settings.h" 21 #include "ui/compositor/scoped_layer_animation_settings.h"
22 #include "ui/gfx/screen.h" 22 #include "ui/gfx/screen.h"
23 23
24 namespace ash { 24 namespace ash {
25 namespace { 25 namespace {
26 26
27 void SingleAxisMaximize(aura::Window* window, 27 void SingleAxisMaximize(wm::WindowState* window_state,
28 const gfx::Rect& maximize_rect_in_screen) { 28 const gfx::Rect& maximize_rect_in_screen) {
29 gfx::Rect bounds_in_screen = 29 window_state->SaveCurrentBoundsForRestore();
30 ScreenAsh::ConvertRectToScreen(window->parent(), window->bounds()); 30 window_state->SetBoundsInScreen(maximize_rect_in_screen);
31 SetRestoreBoundsInScreen(window, bounds_in_screen);
32 gfx::Rect bounds_in_parent =
33 ScreenAsh::ConvertRectFromScreen(window->parent(),
34 maximize_rect_in_screen);
35 window->SetBounds(bounds_in_parent);
36 } 31 }
37 32
38 void SingleAxisUnmaximize(aura::Window* window, 33 void SingleAxisUnmaximize(wm::WindowState* window_state,
39 const gfx::Rect& restore_bounds_in_screen) { 34 const gfx::Rect& restore_bounds_in_screen) {
40 gfx::Rect restore_bounds = ScreenAsh::ConvertRectFromScreen( 35 window_state->SetBoundsInScreen(restore_bounds_in_screen);
41 window->parent(), restore_bounds_in_screen); 36 window_state->ClearRestoreBounds();
42 window->SetBounds(restore_bounds);
43 ClearRestoreBounds(window);
44 } 37 }
45 38
46 void ToggleMaximizedState(aura::Window* window) { 39 void ToggleMaximizedState(wm::WindowState* window_state) {
47 if (GetRestoreBoundsInScreen(window)) { 40 if (window_state->HasRestoreBounds()) {
48 if (window->GetProperty(aura::client::kShowStateKey) == 41 if (window_state->GetShowState() == ui::SHOW_STATE_NORMAL) {
49 ui::SHOW_STATE_NORMAL) { 42 window_state->window()->SetBounds(
50 window->SetBounds(GetRestoreBoundsInParent(window)); 43 window_state->GetRestoreBoundsInParent());
51 ClearRestoreBounds(window); 44 window_state->ClearRestoreBounds();
52 } else { 45 } else {
53 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); 46 window_state->Normalize();
54 } 47 }
55 } else if (wm::CanMaximizeWindow(window)) { 48 } else if (window_state->CanMaximize()) {
56 window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_MAXIMIZED); 49 window_state->Maximize();
57 } 50 }
58 } 51 }
59 52
60 } // namespace 53 } // namespace
61 54
62 namespace internal { 55 namespace internal {
63 56
64 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner) 57 WorkspaceEventHandler::WorkspaceEventHandler(aura::Window* owner)
65 : ToplevelWindowEventHandler(owner), 58 : ToplevelWindowEventHandler(owner),
66 destroyed_(NULL) { 59 destroyed_(NULL) {
(...skipping 19 matching lines...) Expand all
86 case ui::ET_MOUSE_CAPTURE_CHANGED: 79 case ui::ET_MOUSE_CAPTURE_CHANGED:
87 case ui::ET_MOUSE_EXITED: 80 case ui::ET_MOUSE_EXITED:
88 break; 81 break;
89 case ui::ET_MOUSE_PRESSED: { 82 case ui::ET_MOUSE_PRESSED: {
90 // Maximize behavior is implemented as post-target handling so the target 83 // Maximize behavior is implemented as post-target handling so the target
91 // can cancel it. 84 // can cancel it.
92 if (ui::EventCanceledDefaultHandling(*event)) { 85 if (ui::EventCanceledDefaultHandling(*event)) {
93 ToplevelWindowEventHandler::OnMouseEvent(event); 86 ToplevelWindowEventHandler::OnMouseEvent(event);
94 return; 87 return;
95 } 88 }
96 89 wm::WindowState* target_state = wm::GetWindowState(target);
97 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && 90 if (event->flags() & ui::EF_IS_DOUBLE_CLICK &&
98 event->IsOnlyLeftMouseButton() && 91 event->IsOnlyLeftMouseButton() &&
99 target->delegate()->GetNonClientComponent(event->location()) == 92 target->delegate()->GetNonClientComponent(event->location()) ==
100 HTCAPTION && 93 HTCAPTION &&
101 !ash::Shell::IsForcedMaximizeMode()) { 94 !ash::Shell::IsForcedMaximizeMode()) {
102 bool destroyed = false; 95 bool destroyed = false;
103 destroyed_ = &destroyed; 96 destroyed_ = &destroyed;
104 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( 97 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction(
105 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK); 98 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_CLICK);
106 ToggleMaximizedState(target); 99 ToggleMaximizedState(target_state);
107 if (destroyed) 100 if (destroyed)
108 return; 101 return;
109 destroyed_ = NULL; 102 destroyed_ = NULL;
110 } 103 }
111 multi_window_resize_controller_.Hide(); 104 multi_window_resize_controller_.Hide();
112 HandleVerticalResizeDoubleClick(target, event); 105 HandleVerticalResizeDoubleClick(target_state, event);
113 break; 106 break;
114 } 107 }
115 default: 108 default:
116 break; 109 break;
117 } 110 }
118 ToplevelWindowEventHandler::OnMouseEvent(event); 111 ToplevelWindowEventHandler::OnMouseEvent(event);
119 } 112 }
120 113
121 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) { 114 void WorkspaceEventHandler::OnGestureEvent(ui::GestureEvent* event) {
122 aura::Window* target = static_cast<aura::Window*>(event->target()); 115 aura::Window* target = static_cast<aura::Window*>(event->target());
123 if (event->type() == ui::ET_GESTURE_TAP && 116 if (event->type() == ui::ET_GESTURE_TAP &&
124 target->delegate()->GetNonClientComponent(event->location()) == 117 target->delegate()->GetNonClientComponent(event->location()) ==
125 HTCAPTION) { 118 HTCAPTION) {
126 if (event->details().tap_count() == 2) { 119 if (event->details().tap_count() == 2) {
127 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction( 120 ash::Shell::GetInstance()->delegate()->RecordUserMetricsAction(
128 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE); 121 ash::UMA_TOGGLE_MAXIMIZE_CAPTION_GESTURE);
129 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time 122 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice each time
130 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once. 123 // TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP is counted once.
131 TouchUMA::GetInstance()->RecordGestureAction( 124 TouchUMA::GetInstance()->RecordGestureAction(
132 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP); 125 TouchUMA::GESTURE_MAXIMIZE_DOUBLETAP);
133 ToggleMaximizedState(target); // |this| may be destroyed from here. 126 // |this| may be destroyed from here.
127 ToggleMaximizedState(wm::GetWindowState(target));
134 event->StopPropagation(); 128 event->StopPropagation();
135 return; 129 return;
136 } else { 130 } else {
137 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap. 131 // Note: TouchUMA::GESTURE_FRAMEVIEW_TAP is counted twice for each tap.
138 TouchUMA::GetInstance()->RecordGestureAction( 132 TouchUMA::GetInstance()->RecordGestureAction(
139 TouchUMA::GESTURE_FRAMEVIEW_TAP); 133 TouchUMA::GESTURE_FRAMEVIEW_TAP);
140 } 134 }
141 } 135 }
142 ToplevelWindowEventHandler::OnGestureEvent(event); 136 ToplevelWindowEventHandler::OnGestureEvent(event);
143 } 137 }
144 138
145 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick( 139 void WorkspaceEventHandler::HandleVerticalResizeDoubleClick(
146 aura::Window* target, 140 wm::WindowState* target,
James Cook 2013/09/18 20:44:17 Are you sure you want to change target to a Window
oshima 2013/09/19 01:52:01 how does it look to you now?
James Cook 2013/09/19 03:49:53 Better, thanks.
147 ui::MouseEvent* event) { 141 ui::MouseEvent* event) {
148 gfx::Rect max_size(target->delegate()->GetMaximumSize()); 142 gfx::Rect max_size(target->window()->delegate()->GetMaximumSize());
149 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && 143 if (event->flags() & ui::EF_IS_DOUBLE_CLICK && !target->IsMaximized()) {
150 !wm::IsWindowMaximized(target)) {
151 int component = 144 int component =
152 target->delegate()->GetNonClientComponent(event->location()); 145 target->window()->delegate()->GetNonClientComponent(event->location());
153 gfx::Rect work_area = 146 gfx::Rect work_area = Shell::GetScreen()->GetDisplayNearestWindow(
154 Shell::GetScreen()->GetDisplayNearestWindow(target).work_area(); 147 target->window()).work_area();
155 const gfx::Rect* restore_bounds =
156 GetRestoreBoundsInScreen(target);
157 if (component == HTBOTTOM || component == HTTOP) { 148 if (component == HTBOTTOM || component == HTTOP) {
158 // Don't maximize vertically if the window has a max height defined. 149 // Don't maximize vertically if the window has a max height defined.
159 if (max_size.height() != 0) 150 if (max_size.height() != 0)
160 return; 151 return;
161 if (restore_bounds && 152 if (target->HasRestoreBounds() &&
162 (target->bounds().height() == work_area.height() && 153 (target->window()->bounds().height() == work_area.height() &&
163 target->bounds().y() == work_area.y())) { 154 target->window()->bounds().y() == work_area.y())) {
164 SingleAxisUnmaximize(target, *restore_bounds); 155 SingleAxisUnmaximize(target, target->GetRestoreBoundsInScreen());
165 } else { 156 } else {
166 gfx::Point origin = target->bounds().origin(); 157 gfx::Point origin = target->window()->bounds().origin();
167 wm::ConvertPointToScreen(target->parent(), &origin); 158 wm::ConvertPointToScreen(target->window()->parent(), &origin);
168 SingleAxisMaximize(target, 159 SingleAxisMaximize(target,
169 gfx::Rect(origin.x(), 160 gfx::Rect(origin.x(),
170 work_area.y(), 161 work_area.y(),
171 target->bounds().width(), 162 target->window()->bounds().width(),
172 work_area.height())); 163 work_area.height()));
173 } 164 }
174 } else if (component == HTLEFT || component == HTRIGHT) { 165 } else if (component == HTLEFT || component == HTRIGHT) {
175 // Don't maximize horizontally if the window has a max width defined. 166 // Don't maximize horizontally if the window has a max width defined.
176 if (max_size.width() != 0) 167 if (max_size.width() != 0)
177 return; 168 return;
178 if (restore_bounds && 169 if (target->HasRestoreBounds() &&
179 (target->bounds().width() == work_area.width() && 170 (target->window()->bounds().width() == work_area.width() &&
180 target->bounds().x() == work_area.x())) { 171 target->window()->bounds().x() == work_area.x())) {
181 SingleAxisUnmaximize(target, *restore_bounds); 172 SingleAxisUnmaximize(target, target->GetRestoreBoundsInScreen());
182 } else { 173 } else {
183 gfx::Point origin = target->bounds().origin(); 174 gfx::Point origin = target->window()->bounds().origin();
184 wm::ConvertPointToScreen(target->parent(), &origin); 175 wm::ConvertPointToScreen(target->window()->parent(), &origin);
185 SingleAxisMaximize(target, 176 SingleAxisMaximize(target,
186 gfx::Rect(work_area.x(), 177 gfx::Rect(work_area.x(),
187 origin.y(), 178 origin.y(),
188 work_area.width(), 179 work_area.width(),
189 target->bounds().height())); 180 target->window()->bounds().height()));
190 } 181 }
191 } 182 }
192 } 183 }
193 } 184 }
194 185
195 } // namespace internal 186 } // namespace internal
196 } // namespace ash 187 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698