| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame/caption_buttons/frame_size_button.h" | 5 #include "ash/frame/caption_buttons/frame_size_button.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_window_aura.h" | 7 #include "ash/aura/wm_window_aura.h" |
| 8 #include "ash/common/wm/window_positioning_utils.h" | 8 #include "ash/common/wm/window_positioning_utils.h" |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/wm/window_state.h" |
| 10 #include "ash/common/wm/wm_event.h" | 10 #include "ash/common/wm/wm_event.h" |
| 11 #include "ash/common/wm/workspace/phantom_window_controller.h" | 11 #include "ash/common/wm/workspace/phantom_window_controller.h" |
| 12 #include "ash/metrics/user_metrics_recorder.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/screen_util.h" | 13 #include "ash/screen_util.h" |
| 14 #include "ash/shell.h" | |
| 15 #include "ash/wm/window_state_aura.h" | 14 #include "ash/wm/window_state_aura.h" |
| 16 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 17 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
| 17 #include "ui/aura/window.h" |
| 18 #include "ui/gfx/geometry/vector2d.h" | 18 #include "ui/gfx/geometry/vector2d.h" |
| 19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 20 | 20 |
| 21 namespace ash { |
| 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // The default delay between the user pressing the size button and the buttons | 25 // The default delay between the user pressing the size button and the buttons |
| 24 // adjacent to the size button morphing into buttons for snapping left and | 26 // adjacent to the size button morphing into buttons for snapping left and |
| 25 // right. | 27 // right. |
| 26 const int kSetButtonsToSnapModeDelayMs = 150; | 28 const int kSetButtonsToSnapModeDelayMs = 150; |
| 27 | 29 |
| 28 // The amount that a user can overshoot one of the caption buttons while in | 30 // The amount that a user can overshoot one of the caption buttons while in |
| 29 // "snap mode" and keep the button hovered/pressed. | 31 // "snap mode" and keep the button hovered/pressed. |
| 30 const int kMaxOvershootX = 200; | 32 const int kMaxOvershootX = 200; |
| 31 const int kMaxOvershootY = 50; | 33 const int kMaxOvershootY = 50; |
| 32 | 34 |
| 33 // Returns true if a mouse drag while in "snap mode" at |location_in_screen| | 35 // Returns true if a mouse drag while in "snap mode" at |location_in_screen| |
| 34 // would hover/press |button| or keep it hovered/pressed. | 36 // would hover/press |button| or keep it hovered/pressed. |
| 35 bool HitTestButton(const ash::FrameCaptionButton* button, | 37 bool HitTestButton(const FrameCaptionButton* button, |
| 36 const gfx::Point& location_in_screen) { | 38 const gfx::Point& location_in_screen) { |
| 37 gfx::Rect expanded_bounds_in_screen = button->GetBoundsInScreen(); | 39 gfx::Rect expanded_bounds_in_screen = button->GetBoundsInScreen(); |
| 38 if (button->state() == views::Button::STATE_HOVERED || | 40 if (button->state() == views::Button::STATE_HOVERED || |
| 39 button->state() == views::Button::STATE_PRESSED) { | 41 button->state() == views::Button::STATE_PRESSED) { |
| 40 expanded_bounds_in_screen.Inset(-kMaxOvershootX, -kMaxOvershootY); | 42 expanded_bounds_in_screen.Inset(-kMaxOvershootX, -kMaxOvershootY); |
| 41 } | 43 } |
| 42 return expanded_bounds_in_screen.Contains(location_in_screen); | 44 return expanded_bounds_in_screen.Contains(location_in_screen); |
| 43 } | 45 } |
| 44 | 46 |
| 45 } // namespace | 47 } // namespace |
| 46 | 48 |
| 47 namespace ash { | |
| 48 | |
| 49 FrameSizeButton::FrameSizeButton( | 49 FrameSizeButton::FrameSizeButton( |
| 50 views::ButtonListener* listener, | 50 views::ButtonListener* listener, |
| 51 views::Widget* frame, | 51 views::Widget* frame, |
| 52 FrameSizeButtonDelegate* delegate) | 52 FrameSizeButtonDelegate* delegate) |
| 53 : FrameCaptionButton(listener, CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE), | 53 : FrameCaptionButton(listener, CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE), |
| 54 frame_(frame), | 54 frame_(frame), |
| 55 delegate_(delegate), | 55 delegate_(delegate), |
| 56 set_buttons_to_snap_mode_delay_ms_(kSetButtonsToSnapModeDelayMs), | 56 set_buttons_to_snap_mode_delay_ms_(kSetButtonsToSnapModeDelayMs), |
| 57 in_snap_mode_(false), | 57 in_snap_mode_(false), |
| 58 snap_type_(SNAP_NONE) { | 58 snap_type_(SNAP_NONE) { |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 253 |
| 254 bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) { | 254 bool FrameSizeButton::CommitSnap(const ui::LocatedEvent& event) { |
| 255 // The position of |event| may be different than the position of the previous | 255 // The position of |event| may be different than the position of the previous |
| 256 // event. | 256 // event. |
| 257 UpdateSnapType(event); | 257 UpdateSnapType(event); |
| 258 | 258 |
| 259 if (in_snap_mode_ && | 259 if (in_snap_mode_ && |
| 260 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { | 260 (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { |
| 261 wm::WindowState* window_state = | 261 wm::WindowState* window_state = |
| 262 wm::GetWindowState(frame_->GetNativeWindow()); | 262 wm::GetWindowState(frame_->GetNativeWindow()); |
| 263 UserMetricsRecorder* metrics = Shell::GetInstance()->metrics(); | |
| 264 const wm::WMEvent snap_event( | 263 const wm::WMEvent snap_event( |
| 265 snap_type_ == SNAP_LEFT ? | 264 snap_type_ == SNAP_LEFT ? |
| 266 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); | 265 wm::WM_EVENT_SNAP_LEFT : wm::WM_EVENT_SNAP_RIGHT); |
| 267 window_state->OnWMEvent(&snap_event); | 266 window_state->OnWMEvent(&snap_event); |
| 268 metrics->RecordUserMetricsAction( | 267 WmShell::Get()->RecordUserMetricsAction( |
| 269 snap_type_ == SNAP_LEFT ? | 268 snap_type_ == SNAP_LEFT ? |
| 270 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : | 269 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_LEFT : |
| 271 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); | 270 UMA_WINDOW_MAXIMIZE_BUTTON_MAXIMIZE_RIGHT); |
| 272 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_NO); | 271 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_NO); |
| 273 return true; | 272 return true; |
| 274 } | 273 } |
| 275 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_YES); | 274 SetButtonsToNormalMode(FrameSizeButtonDelegate::ANIMATE_YES); |
| 276 return false; | 275 return false; |
| 277 } | 276 } |
| 278 | 277 |
| 279 void FrameSizeButton::SetButtonsToNormalMode( | 278 void FrameSizeButton::SetButtonsToNormalMode( |
| 280 FrameSizeButtonDelegate::Animate animate) { | 279 FrameSizeButtonDelegate::Animate animate) { |
| 281 in_snap_mode_ = false; | 280 in_snap_mode_ = false; |
| 282 snap_type_ = SNAP_NONE; | 281 snap_type_ = SNAP_NONE; |
| 283 set_buttons_to_snap_mode_timer_.Stop(); | 282 set_buttons_to_snap_mode_timer_.Stop(); |
| 284 delegate_->SetButtonsToNormal(animate); | 283 delegate_->SetButtonsToNormal(animate); |
| 285 phantom_window_controller_.reset(); | 284 phantom_window_controller_.reset(); |
| 286 } | 285 } |
| 287 | 286 |
| 288 } // namespace ash | 287 } // namespace ash |
| OLD | NEW |