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/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // Before the window gets destroyed, the maximizer dialog needs to be shut | 97 // Before the window gets destroyed, the maximizer dialog needs to be shut |
98 // down since it would otherwise call into a deleted object. | 98 // down since it would otherwise call into a deleted object. |
99 maximizer_.reset(); | 99 maximizer_.reset(); |
100 if (widget_) | 100 if (widget_) |
101 OnWindowDestroying(widget_->GetNativeWindow()); | 101 OnWindowDestroying(widget_->GetNativeWindow()); |
102 } | 102 } |
103 | 103 |
104 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { | 104 void FrameMaximizeButton::SnapButtonHovered(SnapType type) { |
105 // Make sure to only show hover operations when no button is pressed and | 105 // Make sure to only show hover operations when no button is pressed and |
106 // a similar snap operation in progress does not get re-applied. | 106 // a similar snap operation in progress does not get re-applied. |
107 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_.get())) | 107 if (is_snap_enabled_ || (type == snap_type_ && snap_sizer_)) |
108 return; | 108 return; |
109 // Prime the mouse location with the center of the (local) button. | 109 // Prime the mouse location with the center of the (local) button. |
110 press_location_ = gfx::Point(width() / 2, height() / 2); | 110 press_location_ = gfx::Point(width() / 2, height() / 2); |
111 // Then get an adjusted mouse position to initiate the effect. | 111 // Then get an adjusted mouse position to initiate the effect. |
112 gfx::Point location = press_location_; | 112 gfx::Point location = press_location_; |
113 switch (type) { | 113 switch (type) { |
114 case SNAP_LEFT: | 114 case SNAP_LEFT: |
115 location.set_x(location.x() - width()); | 115 location.set_x(location.x() - width()); |
116 break; | 116 break; |
117 case SNAP_RIGHT: | 117 case SNAP_RIGHT: |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 CHECK_EQ(widget_->GetNativeWindow(), window); | 180 CHECK_EQ(widget_->GetNativeWindow(), window); |
181 widget_->GetNativeWindow()->RemoveObserver(this); | 181 widget_->GetNativeWindow()->RemoveObserver(this); |
182 widget_->RemoveObserver(this); | 182 widget_->RemoveObserver(this); |
183 widget_ = NULL; | 183 widget_ = NULL; |
184 } | 184 } |
185 } | 185 } |
186 | 186 |
187 void FrameMaximizeButton::OnWidgetActivationChanged(views::Widget* widget, | 187 void FrameMaximizeButton::OnWidgetActivationChanged(views::Widget* widget, |
188 bool active) { | 188 bool active) { |
189 // Upon losing focus, the control bubble should hide. | 189 // Upon losing focus, the control bubble should hide. |
190 if (!active && maximizer_.get()) | 190 if (!active && maximizer_) |
191 maximizer_.reset(); | 191 maximizer_.reset(); |
192 } | 192 } |
193 | 193 |
194 bool FrameMaximizeButton::OnMousePressed(const ui::MouseEvent& event) { | 194 bool FrameMaximizeButton::OnMousePressed(const ui::MouseEvent& event) { |
195 // If we are already in a mouse click / drag operation, a second button down | 195 // If we are already in a mouse click / drag operation, a second button down |
196 // call will cancel (this addresses crbug.com/143755). | 196 // call will cancel (this addresses crbug.com/143755). |
197 if (is_snap_enabled_) { | 197 if (is_snap_enabled_) { |
198 Cancel(false); | 198 Cancel(false); |
199 } else { | 199 } else { |
200 is_snap_enabled_ = event.IsOnlyLeftMouseButton(); | 200 is_snap_enabled_ = event.IsOnlyLeftMouseButton(); |
201 if (is_snap_enabled_) | 201 if (is_snap_enabled_) |
202 ProcessStartEvent(event); | 202 ProcessStartEvent(event); |
203 } | 203 } |
204 ImageButton::OnMousePressed(event); | 204 ImageButton::OnMousePressed(event); |
205 return true; | 205 return true; |
206 } | 206 } |
207 | 207 |
208 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { | 208 void FrameMaximizeButton::OnMouseEntered(const ui::MouseEvent& event) { |
209 ImageButton::OnMouseEntered(event); | 209 ImageButton::OnMouseEntered(event); |
210 if (!maximizer_.get()) { | 210 if (!maximizer_) { |
211 DCHECK(GetWidget()); | 211 DCHECK(GetWidget()); |
212 if (!widget_) { | 212 if (!widget_) { |
213 widget_ = frame_->GetWidget(); | 213 widget_ = frame_->GetWidget(); |
214 widget_->GetNativeWindow()->AddObserver(this); | 214 widget_->GetNativeWindow()->AddObserver(this); |
215 widget_->AddObserver(this); | 215 widget_->AddObserver(this); |
216 } | 216 } |
217 maximizer_.reset(new MaximizeBubbleController( | 217 maximizer_.reset(new MaximizeBubbleController( |
218 this, | 218 this, |
219 GetMaximizeBubbleFrameState(), | 219 GetMaximizeBubbleFrameState(), |
220 bubble_appearance_delay_ms_)); | 220 bubble_appearance_delay_ms_)); |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { | 224 void FrameMaximizeButton::OnMouseExited(const ui::MouseEvent& event) { |
225 ImageButton::OnMouseExited(event); | 225 ImageButton::OnMouseExited(event); |
226 // Remove the bubble menu when the button is not pressed and the mouse is not | 226 // Remove the bubble menu when the button is not pressed and the mouse is not |
227 // within the bubble. | 227 // within the bubble. |
228 if (!is_snap_enabled_ && maximizer_.get()) { | 228 if (!is_snap_enabled_ && maximizer_) { |
229 if (maximizer_->GetBubbleWindow()) { | 229 if (maximizer_->GetBubbleWindow()) { |
230 gfx::Point screen_location = Shell::GetScreen()->GetCursorScreenPoint(); | 230 gfx::Point screen_location = Shell::GetScreen()->GetCursorScreenPoint(); |
231 if (!maximizer_->GetBubbleWindow()->GetBoundsInScreen().Contains( | 231 if (!maximizer_->GetBubbleWindow()->GetBoundsInScreen().Contains( |
232 screen_location)) { | 232 screen_location)) { |
233 maximizer_.reset(); | 233 maximizer_.reset(); |
234 // Make sure that all remaining snap hover states get removed. | 234 // Make sure that all remaining snap hover states get removed. |
235 SnapButtonHovered(SNAP_NONE); | 235 SnapButtonHovered(SNAP_NONE); |
236 } | 236 } |
237 } else { | 237 } else { |
238 // The maximize dialog does not show up immediately after creating the | 238 // The maximize dialog does not show up immediately after creating the |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 return; | 302 return; |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 ImageButton::OnGestureEvent(event); | 306 ImageButton::OnGestureEvent(event); |
307 } | 307 } |
308 | 308 |
309 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { | 309 void FrameMaximizeButton::ProcessStartEvent(const ui::LocatedEvent& event) { |
310 DCHECK(is_snap_enabled_); | 310 DCHECK(is_snap_enabled_); |
311 // Prepare the help menu. | 311 // Prepare the help menu. |
312 if (!maximizer_.get()) { | 312 if (!maximizer_) { |
313 maximizer_.reset(new MaximizeBubbleController( | 313 maximizer_.reset(new MaximizeBubbleController( |
314 this, | 314 this, |
315 GetMaximizeBubbleFrameState(), | 315 GetMaximizeBubbleFrameState(), |
316 bubble_appearance_delay_ms_)); | 316 bubble_appearance_delay_ms_)); |
317 } else { | 317 } else { |
318 // If the menu did not show up yet, we delay it even a bit more. | 318 // If the menu did not show up yet, we delay it even a bit more. |
319 maximizer_->DelayCreation(); | 319 maximizer_->DelayCreation(); |
320 } | 320 } |
321 snap_sizer_.reset(NULL); | 321 snap_sizer_.reset(NULL); |
322 InstallEventFilter(); | 322 InstallEventFilter(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 is_snap_enabled_ = false; | 372 is_snap_enabled_ = false; |
373 snap_sizer_.reset(); | 373 snap_sizer_.reset(); |
374 } | 374 } |
375 phantom_window_.reset(); | 375 phantom_window_.reset(); |
376 snap_type_ = SNAP_NONE; | 376 snap_type_ = SNAP_NONE; |
377 update_timer_.Stop(); | 377 update_timer_.Stop(); |
378 SchedulePaint(); | 378 SchedulePaint(); |
379 } | 379 } |
380 | 380 |
381 void FrameMaximizeButton::InstallEventFilter() { | 381 void FrameMaximizeButton::InstallEventFilter() { |
382 if (escape_event_filter_.get()) | 382 if (escape_event_filter_) |
383 return; | 383 return; |
384 | 384 |
385 escape_event_filter_.reset(new EscapeEventFilter(this)); | 385 escape_event_filter_.reset(new EscapeEventFilter(this)); |
386 } | 386 } |
387 | 387 |
388 void FrameMaximizeButton::UninstallEventFilter() { | 388 void FrameMaximizeButton::UninstallEventFilter() { |
389 escape_event_filter_.reset(NULL); | 389 escape_event_filter_.reset(NULL); |
390 } | 390 } |
391 | 391 |
392 void FrameMaximizeButton::UpdateSnapFromEventLocation() { | 392 void FrameMaximizeButton::UpdateSnapFromEventLocation() { |
393 // If the drag threshold has been exceeded the snap location is up to date. | 393 // If the drag threshold has been exceeded the snap location is up to date. |
394 if (exceeded_drag_threshold_) | 394 if (exceeded_drag_threshold_) |
395 return; | 395 return; |
396 exceeded_drag_threshold_ = true; | 396 exceeded_drag_threshold_ = true; |
397 UpdateSnap(press_location_, false, press_is_gesture_); | 397 UpdateSnap(press_location_, false, press_is_gesture_); |
398 } | 398 } |
399 | 399 |
400 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, | 400 void FrameMaximizeButton::UpdateSnap(const gfx::Point& location, |
401 bool select_default, | 401 bool select_default, |
402 bool is_touch) { | 402 bool is_touch) { |
403 SnapType type = SnapTypeForLocation(location); | 403 SnapType type = SnapTypeForLocation(location); |
404 if (type == snap_type_) { | 404 if (type == snap_type_) { |
405 if (snap_sizer_.get()) { | 405 if (snap_sizer_) { |
406 snap_sizer_->Update(LocationForSnapSizer(location)); | 406 snap_sizer_->Update(LocationForSnapSizer(location)); |
407 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( | 407 phantom_window_->Show(ScreenAsh::ConvertRectToScreen( |
408 frame_->GetWidget()->GetNativeView()->parent(), | 408 frame_->GetWidget()->GetNativeView()->parent(), |
409 snap_sizer_->target_bounds())); | 409 snap_sizer_->target_bounds())); |
410 } | 410 } |
411 return; | 411 return; |
412 } | 412 } |
413 | 413 |
414 snap_type_ = type; | 414 snap_type_ = type; |
415 snap_sizer_.reset(); | 415 snap_sizer_.reset(); |
(...skipping 10 matching lines...) Expand all Loading... |
426 SnapSizer::InputType input_type = | 426 SnapSizer::InputType input_type = |
427 is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT : | 427 is_touch ? SnapSizer::TOUCH_MAXIMIZE_BUTTON_INPUT : |
428 SnapSizer::OTHER_INPUT; | 428 SnapSizer::OTHER_INPUT; |
429 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), | 429 snap_sizer_.reset(new SnapSizer(frame_->GetWidget()->GetNativeWindow(), |
430 LocationForSnapSizer(location), | 430 LocationForSnapSizer(location), |
431 snap_edge, | 431 snap_edge, |
432 input_type)); | 432 input_type)); |
433 if (select_default) | 433 if (select_default) |
434 snap_sizer_->SelectDefaultSizeAndDisableResize(); | 434 snap_sizer_->SelectDefaultSizeAndDisableResize(); |
435 } | 435 } |
436 if (!phantom_window_.get()) { | 436 if (!phantom_window_) { |
437 phantom_window_.reset(new internal::PhantomWindowController( | 437 phantom_window_.reset(new internal::PhantomWindowController( |
438 frame_->GetWidget()->GetNativeWindow())); | 438 frame_->GetWidget()->GetNativeWindow())); |
439 } | 439 } |
440 if (maximizer_.get()) { | 440 if (maximizer_) { |
441 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); | 441 phantom_window_->set_phantom_below_window(maximizer_->GetBubbleWindow()); |
442 maximizer_->SetSnapType(snap_type_); | 442 maximizer_->SetSnapType(snap_type_); |
443 } | 443 } |
444 phantom_window_->Show( | 444 phantom_window_->Show( |
445 ScreenBoundsForType(snap_type_, *snap_sizer_.get())); | 445 ScreenBoundsForType(snap_type_, *snap_sizer_.get())); |
446 } | 446 } |
447 | 447 |
448 SnapType FrameMaximizeButton::SnapTypeForLocation( | 448 SnapType FrameMaximizeButton::SnapTypeForLocation( |
449 const gfx::Point& location) const { | 449 const gfx::Point& location) const { |
450 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); | 450 MaximizeBubbleFrameState maximize_type = GetMaximizeBubbleFrameState(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 return FRAME_STATE_SNAP_LEFT; | 600 return FRAME_STATE_SNAP_LEFT; |
601 if (bounds.right() == screen.right()) | 601 if (bounds.right() == screen.right()) |
602 return FRAME_STATE_SNAP_RIGHT; | 602 return FRAME_STATE_SNAP_RIGHT; |
603 // If we come here, it is likely caused by the fact that the | 603 // If we come here, it is likely caused by the fact that the |
604 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case | 604 // "VerticalResizeDoubleClick" stored a restore rectangle. In that case |
605 // we allow all maximize operations (and keep the restore rectangle). | 605 // we allow all maximize operations (and keep the restore rectangle). |
606 return FRAME_STATE_NONE; | 606 return FRAME_STATE_NONE; |
607 } | 607 } |
608 | 608 |
609 } // namespace ash | 609 } // namespace ash |
OLD | NEW |