OLD | NEW |
---|---|
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/frame_maximize_button.h" | 5 #include "ash/wm/workspace/frame_maximize_button.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/property_util.h" | 10 #include "ash/wm/property_util.h" |
11 #include "ash/wm/window_maximize.h" | |
11 #include "ash/wm/workspace/phantom_window_controller.h" | 12 #include "ash/wm/workspace/phantom_window_controller.h" |
12 #include "ash/wm/workspace/snap_sizer.h" | 13 #include "ash/wm/workspace/snap_sizer.h" |
13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
14 #include "grit/ui_resources.h" | 15 #include "grit/ui_resources.h" |
15 #include "ui/aura/event.h" | 16 #include "ui/aura/event.h" |
16 #include "ui/aura/event_filter.h" | 17 #include "ui/aura/event_filter.h" |
17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 } | 99 } |
99 | 100 |
100 // FrameMaximizeButton --------------------------------------------------------- | 101 // FrameMaximizeButton --------------------------------------------------------- |
101 | 102 |
102 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, | 103 FrameMaximizeButton::FrameMaximizeButton(views::ButtonListener* listener, |
103 views::NonClientFrameView* frame) | 104 views::NonClientFrameView* frame) |
104 : ImageButton(listener), | 105 : ImageButton(listener), |
105 frame_(frame), | 106 frame_(frame), |
106 is_snap_enabled_(false), | 107 is_snap_enabled_(false), |
107 exceeded_drag_threshold_(false), | 108 exceeded_drag_threshold_(false), |
108 snap_type_(SNAP_NONE) { | 109 window_moved_listener_installed_for_(NULL), |
110 snap_type_(SNAP_NONE), | |
111 maximizer_(NULL) { | |
109 // TODO(sky): nuke this. It's temporary while we don't have good images. | 112 // TODO(sky): nuke this. It's temporary while we don't have good images. |
110 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); | 113 SetImageAlignment(ALIGN_LEFT, ALIGN_BOTTOM); |
111 SetTooltipText(l10n_util::GetStringUTF16(IDS_FRAME_MAXIMIZE_BUTTON_TOOLTIP)); | |
112 } | 114 } |
113 | 115 |
114 FrameMaximizeButton::~FrameMaximizeButton() { | 116 FrameMaximizeButton::~FrameMaximizeButton() { |
115 } | 117 } |
116 | 118 |
119 void FrameMaximizeButton::OnWindowDestroying(aura::Window* window) { | |
120 maximizer_.reset(NULL); | |
sky
2012/07/31 16:11:06
.reset()
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
121 if (window_moved_listener_installed_for_) { | |
122 CHECK_EQ(window_moved_listener_installed_for_, window); | |
123 window_moved_listener_installed_for_->RemoveObserver(this); | |
124 window_moved_listener_installed_for_ = NULL; | |
125 } | |
126 } | |
127 | |
128 void FrameMaximizeButton::OnWindowBoundsChanged( | |
sky
2012/07/31 16:11:06
Make order match header.
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
129 aura::Window* window, | |
130 const gfx::Rect& old_bounds, | |
131 const gfx::Rect& new_bounds) { | |
132 maximizer_.reset(NULL); | |
sky
2012/07/31 16:11:06
Cancel() ?
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
133 // Make sure that all remaining snap hover states get removed. | |
134 SnapButtonHovered(SNAP_NONE); | |
135 } | |
136 | |
117 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { | 137 bool FrameMaximizeButton::OnMousePressed(const views::MouseEvent& event) { |
118 is_snap_enabled_ = event.IsLeftMouseButton(); | 138 is_snap_enabled_ = event.IsLeftMouseButton(); |
119 if (is_snap_enabled_) | 139 if (is_snap_enabled_) |
120 ProcessStartEvent(event); | 140 ProcessStartEvent(event); |
121 ImageButton::OnMousePressed(event); | 141 ImageButton::OnMousePressed(event); |
122 return true; | 142 return true; |
123 } | 143 } |
124 | 144 |
125 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { | 145 void FrameMaximizeButton::OnMouseEntered(const views::MouseEvent& event) { |
126 ImageButton::OnMouseEntered(event); | 146 ImageButton::OnMouseEntered(event); |
147 if (!maximizer_.get()) { | |
148 if (!window_moved_listener_installed_for_ && parent() && | |
sky
2012/07/31 16:11:06
No need to check parent() here, you can invoke Get
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Hmmm.. But I *want* to add the observer on the par
| |
149 parent()->GetWidget()) { | |
150 window_moved_listener_installed_for_ = | |
151 parent()->GetWidget()->GetNativeWindow(); | |
152 window_moved_listener_installed_for_->AddObserver(this); | |
sky
2012/07/31 16:11:06
You need to remove the observer at the right point
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Please correct me if I am wrong - but isn't the "F
| |
153 } | |
154 maximizer_.reset(new MaximizeBubble(this, | |
155 frame_->GetWidget()->IsMaximized())); | |
156 } | |
127 } | 157 } |
128 | 158 |
129 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { | 159 void FrameMaximizeButton::OnMouseExited(const views::MouseEvent& event) { |
130 ImageButton::OnMouseExited(event); | 160 ImageButton::OnMouseExited(event); |
161 // Remove the bubble menu when the button is not pressed and the mouse is not | |
162 // within the bubble. | |
163 if (!is_snap_enabled_ && maximizer_.get() && maximizer_->GetMenuWindow()) { | |
164 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); | |
165 if (!maximizer_->GetMenuWindow()->bounds().Contains(screen_location)) { | |
166 maximizer_.reset(NULL); | |
167 // Make sure that all remaining snap hover states get removed. | |
168 SnapButtonHovered(SNAP_NONE); | |
169 } | |
170 } | |
131 } | 171 } |
132 | 172 |
133 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { | 173 bool FrameMaximizeButton::OnMouseDragged(const views::MouseEvent& event) { |
134 if (is_snap_enabled_) | 174 if (is_snap_enabled_) |
135 ProcessUpdateEvent(event); | 175 ProcessUpdateEvent(event); |
136 return ImageButton::OnMouseDragged(event); | 176 return ImageButton::OnMouseDragged(event); |
137 } | 177 } |
138 | 178 |
139 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { | 179 void FrameMaximizeButton::OnMouseReleased(const views::MouseEvent& event) { |
140 if (!ProcessEndEvent(event)) | 180 if (!ProcessEndEvent(event)) |
141 ImageButton::OnMouseReleased(event); | 181 ImageButton::OnMouseReleased(event); |
182 maximizer_.reset(NULL); | |
142 } | 183 } |
143 | 184 |
144 void FrameMaximizeButton::OnMouseCaptureLost() { | 185 void FrameMaximizeButton::OnMouseCaptureLost() { |
145 Cancel(); | 186 Cancel(); |
146 ImageButton::OnMouseCaptureLost(); | 187 ImageButton::OnMouseCaptureLost(); |
188 if (!is_snap_enabled_) { | |
sky
2012/07/31 16:11:06
All of this should be moved to Cancel().
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
189 maximizer_.reset(NULL); | |
190 // Make sure that all remaining snap hover states get removed. | |
191 SnapButtonHovered(SNAP_NONE); | |
sky
2012/07/31 16:11:06
spacing is off.
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
192 } | |
147 } | 193 } |
148 | 194 |
149 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( | 195 ui::GestureStatus FrameMaximizeButton::OnGestureEvent( |
150 const views::GestureEvent& event) { | 196 const views::GestureEvent& event) { |
151 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { | 197 if (event.type() == ui::ET_GESTURE_TAP_DOWN) { |
152 is_snap_enabled_ = true; | 198 is_snap_enabled_ = true; |
153 ProcessStartEvent(event); | 199 ProcessStartEvent(event); |
154 return ui::GESTURE_STATUS_CONSUMED; | 200 return ui::GESTURE_STATUS_CONSUMED; |
155 } | 201 } |
156 | 202 |
(...skipping 20 matching lines...) Expand all Loading... | |
177 } | 223 } |
178 } | 224 } |
179 | 225 |
180 return ImageButton::OnGestureEvent(event); | 226 return ImageButton::OnGestureEvent(event); |
181 } | 227 } |
182 | 228 |
183 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { | 229 gfx::ImageSkia FrameMaximizeButton::GetImageToPaint() { |
184 if (is_snap_enabled_) { | 230 if (is_snap_enabled_) { |
185 int id = 0; | 231 int id = 0; |
186 if (frame_->GetWidget()->IsMaximized()) { | 232 if (frame_->GetWidget()->IsMaximized()) { |
187 switch (snap_type_) { | 233 // TODO(SKUHNE): Remove old bitmaps as soon as the final artwork comes in: |
188 case SNAP_LEFT: | 234 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P |
189 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_LEFT_P; | 235 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P |
190 break; | 236 // IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P |
191 case SNAP_RIGHT: | 237 // IDR_AURA_WINDOW_SNAP_LEFT_P |
192 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_RIGHT_P; | 238 // IDR_AURA_WINDOW_SNAP_RIGHT_P |
193 break; | 239 // IDR_AURA_WINDOW_SNAP_MINIMIZE_P |
194 case SNAP_MAXIMIZE: | 240 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; |
195 case SNAP_RESTORE: | 241 } else |
196 case SNAP_NONE: | 242 id = IDR_AURA_WINDOW_SNAP_P; |
197 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_P; | |
198 break; | |
199 case SNAP_MINIMIZE: | |
200 id = IDR_AURA_WINDOW_MAXIMIZED_SNAP_MINIMIZE_P; | |
201 break; | |
202 default: | |
203 NOTREACHED(); | |
204 } | |
205 } else { | |
206 switch (snap_type_) { | |
207 case SNAP_LEFT: | |
208 id = IDR_AURA_WINDOW_SNAP_LEFT_P; | |
209 break; | |
210 case SNAP_RIGHT: | |
211 id = IDR_AURA_WINDOW_SNAP_RIGHT_P; | |
212 break; | |
213 case SNAP_MAXIMIZE: | |
214 case SNAP_RESTORE: | |
215 case SNAP_NONE: | |
216 id = IDR_AURA_WINDOW_SNAP_P; | |
217 break; | |
218 case SNAP_MINIMIZE: | |
219 id = IDR_AURA_WINDOW_SNAP_MINIMIZE_P; | |
220 break; | |
221 default: | |
222 NOTREACHED(); | |
223 } | |
224 } | |
225 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); | 243 return *ResourceBundle::GetSharedInstance().GetImageNamed(id).ToImageSkia(); |
226 } | 244 } |
227 // Hot and pressed states handled by regular ImageButton. | 245 // Hot and pressed states handled by regular ImageButton. |
228 return ImageButton::GetImageToPaint(); | 246 return ImageButton::GetImageToPaint(); |
229 } | 247 } |
230 | 248 |
231 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { | 249 void FrameMaximizeButton::ProcessStartEvent(const views::LocatedEvent& event) { |
232 DCHECK(is_snap_enabled_); | 250 DCHECK(is_snap_enabled_); |
251 // Prepare the help / helo menu. | |
sky
2012/07/31 16:11:06
halo?
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
252 if (!maximizer_.get()) { | |
253 maximizer_.reset(new MaximizeBubble(this, | |
254 frame_->GetWidget()->IsMaximized())); | |
255 } else { | |
256 // If the menu did not show up yet, we delay it even a bit more. | |
257 maximizer_->DelayCreation(); | |
258 } | |
233 snap_sizer_.reset(NULL); | 259 snap_sizer_.reset(NULL); |
234 InstallEventFilter(); | 260 InstallEventFilter(); |
235 snap_type_ = SNAP_NONE; | 261 snap_type_ = SNAP_NONE; |
236 press_location_ = event.location(); | 262 press_location_ = event.location(); |
237 exceeded_drag_threshold_ = false; | 263 exceeded_drag_threshold_ = false; |
238 update_timer_.Start( | 264 update_timer_.Start( |
239 FROM_HERE, | 265 FROM_HERE, |
240 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), | 266 base::TimeDelta::FromMilliseconds(kUpdateDelayMS), |
241 this, | 267 this, |
242 &FrameMaximizeButton::UpdateSnapFromEventLocation); | 268 &FrameMaximizeButton::UpdateSnapFromEventLocation); |
243 } | 269 } |
244 | 270 |
245 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { | 271 void FrameMaximizeButton::ProcessUpdateEvent(const views::LocatedEvent& event) { |
246 DCHECK(is_snap_enabled_); | 272 DCHECK(is_snap_enabled_); |
247 int delta_x = event.x() - press_location_.x(); | 273 int delta_x = event.x() - press_location_.x(); |
248 int delta_y = event.y() - press_location_.y(); | 274 int delta_y = event.y() - press_location_.y(); |
249 if (!exceeded_drag_threshold_) { | 275 if (!exceeded_drag_threshold_) { |
250 exceeded_drag_threshold_ = | 276 exceeded_drag_threshold_ = |
251 views::View::ExceededDragThreshold(delta_x, delta_y); | 277 views::View::ExceededDragThreshold(delta_x, delta_y); |
252 } | 278 } |
253 if (exceeded_drag_threshold_) | 279 if (exceeded_drag_threshold_) |
254 UpdateSnap(event.location()); | 280 UpdateSnap(event.location()); |
281 | |
282 // Update the halo menu. | |
283 if (maximizer_.get() && maximizer_->IsRadialMenu()) { | |
284 gfx::Point pt = event.location(); | |
285 views::View::ConvertPointToScreen(this, &pt); | |
286 FrameMaximizeButton::SnapType type; | |
287 maximizer_->SnapTypeForLocation(pt, type); | |
288 } | |
255 } | 289 } |
256 | 290 |
257 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { | 291 bool FrameMaximizeButton::ProcessEndEvent(const views::LocatedEvent& event) { |
258 update_timer_.Stop(); | 292 update_timer_.Stop(); |
259 UninstallEventFilter(); | 293 UninstallEventFilter(); |
260 bool should_snap = is_snap_enabled_; | 294 bool should_snap = is_snap_enabled_; |
261 is_snap_enabled_ = false; | 295 is_snap_enabled_ = false; |
262 | 296 |
297 // Remove our help / halo menu if the mouse cursor is not still over it. | |
298 gfx::Point screen_location = gfx::Screen::GetCursorScreenPoint(); | |
299 if (!GetBoundsInScreen().Contains(screen_location)) | |
300 maximizer_.reset(); | |
301 | |
263 if (!should_snap || snap_type_ == SNAP_NONE) | 302 if (!should_snap || snap_type_ == SNAP_NONE) |
264 return false; | 303 return false; |
265 | 304 |
266 SetState(BS_NORMAL); | 305 SetState(BS_NORMAL); |
267 // SetState will not call SchedulePaint() if state was already set to | 306 // SetState will not call SchedulePaint() if state was already set to |
268 // BS_NORMAL during a drag. | 307 // BS_NORMAL during a drag. |
269 SchedulePaint(); | 308 SchedulePaint(); |
270 phantom_window_.reset(); | 309 phantom_window_.reset(); |
271 Snap(); | 310 Snap(); |
272 return true; | 311 return true; |
273 } | 312 } |
274 | 313 |
275 void FrameMaximizeButton::Cancel() { | 314 void FrameMaximizeButton::Cancel() { |
276 UninstallEventFilter(); | 315 UninstallEventFilter(); |
277 is_snap_enabled_ = false; | 316 is_snap_enabled_ = false; |
278 phantom_window_.reset(); | 317 phantom_window_.reset(); |
279 snap_sizer_.reset(); | 318 snap_sizer_.reset(); |
319 snap_type_ = SNAP_NONE; | |
280 update_timer_.Stop(); | 320 update_timer_.Stop(); |
281 SchedulePaint(); | 321 SchedulePaint(); |
282 } | 322 } |
283 | 323 |
284 void FrameMaximizeButton::InstallEventFilter() { | 324 void FrameMaximizeButton::InstallEventFilter() { |
285 if (escape_event_filter_.get()) | 325 if (escape_event_filter_.get()) |
286 return; | 326 return; |
287 | 327 |
288 escape_event_filter_.reset(new EscapeEventFilter(this)); | 328 escape_event_filter_.reset(new EscapeEventFilter(this)); |
289 } | 329 } |
290 | 330 |
291 void FrameMaximizeButton::UninstallEventFilter() { | 331 void FrameMaximizeButton::UninstallEventFilter() { |
292 escape_event_filter_.reset(NULL); | 332 escape_event_filter_.reset(NULL); |
293 } | 333 } |
294 | 334 |
295 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 335 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
296 // If the drag threshold has been exceeded the snap location is up to date. | 336 // If the drag threshold has been exceeded the snap location is up to date. |
297 if (exceeded_drag_threshold_) | 337 if (exceeded_drag_threshold_) |
298 return; | 338 return; |
299 exceeded_drag_threshold_ = true; | 339 exceeded_drag_threshold_ = true; |
300 UpdateSnap(press_location_); | 340 UpdateSnap(press_location_); |
301 } | 341 } |
302 | 342 |
343 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { | |
344 // Make sure to only show hover operations when no button is pressed and | |
345 // a similar snap operation in progress does not get re-applied. | |
346 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_.get())) | |
347 return; | |
348 // Prime the mouse location with the center of the (local) button. | |
349 press_location_ = gfx::Point(width() / 2, height() / 2); | |
350 // Then get an adjusted mouse position to initiate the effect. | |
351 gfx::Point location = press_location_; | |
352 switch (type) { | |
353 case SNAP_LEFT: | |
354 location.set_x(location.x() - width()); | |
355 break; | |
356 case SNAP_RIGHT: | |
357 location.set_x(location.x() + width()); | |
358 break; | |
359 case SNAP_MINIMIZE: | |
360 location.set_y(location.y() + height()); | |
361 break; | |
362 case SNAP_MAXIMIZE: | |
363 case SNAP_RESTORE: | |
364 break; | |
365 case SNAP_NONE: | |
366 snap_type_ = type; | |
367 snap_sizer_.reset(); | |
368 SchedulePaint(); | |
369 phantom_window_.reset(); | |
370 return; | |
371 default: | |
372 // We should not come here. | |
373 DCHECK(false); | |
374 return; | |
375 } | |
376 UpdateSnap(location); | |
377 } | |
378 | |
303 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { | 379 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location) { |
304 SnapType type = SnapTypeForLocation(location); | 380 SnapType type = SnapTypeForLocation(location); |
305 if (type == snap_type_) { | 381 if (type == snap_type_) { |
306 if (snap_sizer_.get()) { | 382 if (snap_sizer_.get()) { |
307 snap_sizer_->Update(LocationForSnapSizer(location)); | 383 snap_sizer_->Update(LocationForSnapSizer(location)); |
308 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | 384 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
309 frame_->GetWidget()->GetNativeView()->parent(), | 385 frame_->GetWidget()->GetNativeView()->parent(), |
310 snap_sizer_->target_bounds())); | 386 snap_sizer_->target_bounds())); |
311 } | 387 } |
312 return; | 388 return; |
(...skipping 13 matching lines...) Expand all Loading... | |
326 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; | 402 SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
327 int grid_size = Shell::GetInstance()->GetGridSize(); | 403 int grid_size = Shell::GetInstance()->GetGridSize(); |
328 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | 404 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
329 LocationForSnapSizer(location), | 405 LocationForSnapSizer(location), |
330 snap_edge, grid_size)); | 406 snap_edge, grid_size)); |
331 } | 407 } |
332 if (!phantom_window_.get()) { | 408 if (!phantom_window_.get()) { |
333 phantom_window_.reset(new internal::PhantomWindowController( | 409 phantom_window_.reset(new internal::PhantomWindowController( |
334 frame_->GetWidget()->GetNativeWindow())); | 410 frame_->GetWidget()->GetNativeWindow())); |
335 } | 411 } |
412 if (maximizer_.get()) | |
413 phantom_window_->set_phantom_below_window(maximizer_->GetMenuWindow()); | |
414 | |
336 phantom_window_->Show(ScreenBoundsForType(snap_type_)); | 415 phantom_window_->Show(ScreenBoundsForType(snap_type_)); |
416 | |
417 if (maximizer_.get()) | |
418 maximizer_->SetMenuState(snap_type_); | |
337 } | 419 } |
338 | 420 |
339 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( | 421 FrameMaximizeButton::SnapType FrameMaximizeButton::SnapTypeForLocation( |
340 const gfx::Point& location) const { | 422 const gfx::Point& location) const { |
423 if (maximizer_.get() && maximizer_->IsRadialMenu()) { | |
424 FrameMaximizeButton::SnapType code; | |
425 gfx::Point pt = location; | |
426 views::View::ConvertPointToScreen(this, &pt); | |
427 maximizer_->SnapTypeForLocation(pt, code); | |
428 if (code != SNAP_NONE) | |
429 return code; | |
430 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | |
431 } | |
341 int delta_x = location.x() - press_location_.x(); | 432 int delta_x = location.x() - press_location_.x(); |
342 int delta_y = location.y() - press_location_.y(); | 433 int delta_y = location.y() - press_location_.y(); |
343 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) | 434 if (!views::View::ExceededDragThreshold(delta_x, delta_y)) |
344 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; | 435 return !frame_->GetWidget()->IsMaximized() ? SNAP_MAXIMIZE : SNAP_RESTORE; |
345 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) | 436 else if (delta_x < 0 && delta_y > delta_x && delta_y < -delta_x) |
346 return SNAP_LEFT; | 437 return SNAP_LEFT; |
347 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) | 438 else if (delta_x > 0 && delta_y > -delta_x && delta_y < delta_x) |
348 return SNAP_RIGHT; | 439 return SNAP_RIGHT; |
349 else if (delta_y > 0) | 440 else if (delta_y > 0) |
350 return SNAP_MINIMIZE; | 441 return SNAP_MINIMIZE; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 return gfx::Rect(); | 476 return gfx::Rect(); |
386 } | 477 } |
387 | 478 |
388 gfx::Point FrameMaximizeButton::LocationForSnapSizer( | 479 gfx::Point FrameMaximizeButton::LocationForSnapSizer( |
389 const gfx::Point& location) const { | 480 const gfx::Point& location) const { |
390 gfx::Point result(location); | 481 gfx::Point result(location); |
391 views::View::ConvertPointToScreen(this, &result); | 482 views::View::ConvertPointToScreen(this, &result); |
392 return result; | 483 return result; |
393 } | 484 } |
394 | 485 |
486 void FrameMaximizeButton::ExecuteSnapAndCloseMenu(SnapType snap_type) { | |
487 snap_type_ = snap_type; | |
488 Snap(); | |
489 // Remove any pending snap previews. | |
490 SnapButtonHovered(SNAP_NONE); | |
491 // At this point the operation has been performed and the menu should be | |
492 // closed (due to the resize operation). If not, it'll get now closed. | |
493 if (maximizer_.get()) | |
494 maximizer_.reset(); | |
495 } | |
496 | |
395 void FrameMaximizeButton::Snap() { | 497 void FrameMaximizeButton::Snap() { |
396 switch (snap_type_) { | 498 switch (snap_type_) { |
397 case SNAP_LEFT: | 499 case SNAP_LEFT: |
398 case SNAP_RIGHT: | 500 case SNAP_RIGHT: |
399 if (frame_->GetWidget()->IsMaximized()) { | 501 if (frame_->GetWidget()->IsMaximized()) { |
400 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), | 502 ash::SetRestoreBoundsInScreen(frame_->GetWidget()->GetNativeWindow(), |
401 ScreenBoundsForType(snap_type_)); | 503 ScreenBoundsForType(snap_type_)); |
402 frame_->GetWidget()->Restore(); | 504 frame_->GetWidget()->Restore(); |
403 } else { | 505 } else { |
404 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); | 506 frame_->GetWidget()->SetBounds(ScreenBoundsForType(snap_type_)); |
405 } | 507 } |
406 break; | 508 break; |
407 case SNAP_MAXIMIZE: | 509 case SNAP_MAXIMIZE: |
408 frame_->GetWidget()->Maximize(); | 510 frame_->GetWidget()->Maximize(); |
409 break; | 511 break; |
410 case SNAP_MINIMIZE: | 512 case SNAP_MINIMIZE: |
411 frame_->GetWidget()->Minimize(); | 513 frame_->GetWidget()->Minimize(); |
412 break; | 514 break; |
413 case SNAP_RESTORE: | 515 case SNAP_RESTORE: |
414 frame_->GetWidget()->Restore(); | 516 frame_->GetWidget()->Restore(); |
415 break; | 517 break; |
416 case SNAP_NONE: | 518 case SNAP_NONE: |
417 NOTREACHED(); | 519 NOTREACHED(); |
418 } | 520 } |
419 } | 521 } |
420 | 522 |
523 void FrameMaximizeButton::DestroyMaximizeMenu() { | |
524 if (maximizer_.get()) | |
525 maximizer_.reset(NULL); | |
526 } | |
527 | |
421 } // namespace ash | 528 } // namespace ash |
OLD | NEW |