OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ | 5 #ifndef ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ |
6 #define ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ | 6 #define ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/wm/caption_buttons/alternate_frame_size_button_delegate.h" | 9 #include "ash/wm/caption_buttons/alternate_frame_size_button_delegate.h" |
10 #include "ash/wm/caption_buttons/frame_caption_button.h" | 10 #include "ash/wm/caption_buttons/frame_caption_button.h" |
11 #include "ash/wm/workspace/snap_types.h" | 11 #include "ash/wm/workspace/snap_types.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 class Widget; | 15 class Widget; |
16 } | 16 } |
17 | 17 |
18 namespace ash { | 18 namespace ash { |
19 class AlternateFrameSizeButtonDelegate; | 19 class AlternateFrameSizeButtonDelegate; |
20 | 20 |
21 namespace internal { | 21 namespace internal { |
22 class PhantomWindowController; | 22 class PhantomWindowController; |
23 } | 23 } |
24 | 24 |
25 // The maximize/restore button when using the alternate button style. | 25 // The maximize/restore button when using the alternate button style. |
26 // When the mouse is pressed over the size button or the size button is touched: | 26 // When the mouse is pressed over the size button or the size button is touched: |
27 // - The minimize and close buttons are set to snap left and snap right | 27 // - The minimize and close buttons are set to snap left and snap right |
28 // respectively. | 28 // respectively. |
29 // - The pressed button is updated during the drag to reflect the button | 29 // - The size button stays pressed while the mouse is over the buttons to snap |
30 // underneath the mouse cursor. (The size button is potentially unpressed). | 30 // left and to snap right. The button underneath the mouse is hovered. |
31 // When the drag terminates, the action for the pressed button is executed. | 31 // When the drag terminates, the action for the button underneath the mouse |
32 // For the sake of simplicity, the size button is the event handler for a click | 32 // is executed. For the sake of simplicity, the size button is the event |
33 // starting on the size button and the entire drag (including when the size | 33 // handler for a click starting on the size button and the entire drag. |
34 // button is unpressed). | |
35 class ASH_EXPORT AlternateFrameSizeButton : public FrameCaptionButton { | 34 class ASH_EXPORT AlternateFrameSizeButton : public FrameCaptionButton { |
36 public: | 35 public: |
37 AlternateFrameSizeButton(views::ButtonListener* listener, | 36 AlternateFrameSizeButton(views::ButtonListener* listener, |
38 views::Widget* frame, | 37 views::Widget* frame, |
39 AlternateFrameSizeButtonDelegate* delegate); | 38 AlternateFrameSizeButtonDelegate* delegate); |
40 | 39 |
41 virtual ~AlternateFrameSizeButton(); | 40 virtual ~AlternateFrameSizeButton(); |
42 | 41 |
43 // views::CustomButton overrides: | 42 // views::CustomButton overrides: |
44 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; | 43 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; |
45 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; | 44 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE; |
46 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; | 45 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; |
47 virtual void OnMouseCaptureLost() OVERRIDE; | 46 virtual void OnMouseCaptureLost() OVERRIDE; |
| 47 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE; |
48 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; | 48 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; |
49 | 49 |
50 void set_delay_to_set_buttons_to_snap_mode(int delay_ms) { | 50 void set_delay_to_set_buttons_to_snap_mode(int delay_ms) { |
51 set_buttons_to_snap_mode_delay_ms_ = delay_ms; | 51 set_buttons_to_snap_mode_delay_ms_ = delay_ms; |
52 } | 52 } |
53 | 53 |
54 private: | 54 private: |
55 // Starts |set_buttons_to_snap_mode_timer_|. | 55 // Starts |set_buttons_to_snap_mode_timer_|. |
56 void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event); | 56 void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event); |
57 | 57 |
58 // Sets the buttons adjacent to the size button to snap left and right. | 58 // Sets the buttons adjacent to the size button to snap left and right. |
59 void SetButtonsToSnapMode(); | 59 void SetButtonsToSnapMode(); |
60 | 60 |
61 // Updates the pressed button based on |event_location|. | 61 // Updates |snap_type_|, whether the size button is pressed and whether any |
62 void UpdatePressedButton(const ui::LocatedEvent& event); | 62 // other buttons are hovered. |
| 63 void UpdateSnapType(const ui::LocatedEvent& event); |
| 64 |
| 65 // Returns the button which should be hovered (if any) while in "snap mode" |
| 66 // for |event_location_in_screen|. |
| 67 const FrameCaptionButton* GetButtonToHover( |
| 68 const gfx::Point& event_location_in_screen) const; |
63 | 69 |
64 // Snaps |frame_| according to |snap_type_|. Returns true if |frame_| was | 70 // Snaps |frame_| according to |snap_type_|. Returns true if |frame_| was |
65 // snapped. | 71 // snapped. |
66 bool CommitSnap(const ui::LocatedEvent& event); | 72 bool CommitSnap(const ui::LocatedEvent& event); |
67 | 73 |
68 // Sets the buttons adjacent to the size button to minimize and close again. | 74 // Sets the buttons adjacent to the size button to minimize and close again. |
69 // Clears any state set while snapping was enabled. |animate| indicates | 75 // Clears any state set while snapping was enabled. |animate| indicates |
70 // whether the buttons should animate back to their original icons. | 76 // whether the buttons should animate back to their original icons. |
71 void SetButtonsToNormalMode( | 77 void SetButtonsToNormalMode( |
72 AlternateFrameSizeButtonDelegate::Animate animate); | 78 AlternateFrameSizeButtonDelegate::Animate animate); |
(...skipping 12 matching lines...) Expand all Loading... |
85 // adjacent to the size button morphing into buttons for snapping left and | 91 // adjacent to the size button morphing into buttons for snapping left and |
86 // right. | 92 // right. |
87 int set_buttons_to_snap_mode_delay_ms_; | 93 int set_buttons_to_snap_mode_delay_ms_; |
88 | 94 |
89 base::OneShotTimer<AlternateFrameSizeButton> set_buttons_to_snap_mode_timer_; | 95 base::OneShotTimer<AlternateFrameSizeButton> set_buttons_to_snap_mode_timer_; |
90 | 96 |
91 // Whether the buttons adjacent to the size button snap the window left and | 97 // Whether the buttons adjacent to the size button snap the window left and |
92 // right. | 98 // right. |
93 bool in_snap_mode_; | 99 bool in_snap_mode_; |
94 | 100 |
95 // The action of the currently pressed button. If |snap_type_| == SNAP_NONE, | 101 // The action to execute when the drag/click is ended. If |
96 // the size button's default action is run when clicked. | 102 // |snap_type_| == SNAP_NONE, the size button's default action is run when the |
| 103 // drag/click is ended. |
97 SnapType snap_type_; | 104 SnapType snap_type_; |
98 | 105 |
99 // Displays a preview of how the window's bounds will change as a result of | 106 // Displays a preview of how the window's bounds will change as a result of |
100 // snapping the window left or right. The preview is only visible if the snap | 107 // snapping the window left or right. The preview is only visible if the snap |
101 // left or snap right button is pressed. | 108 // left or snap right button is pressed. |
102 scoped_ptr<internal::PhantomWindowController> phantom_window_controller_; | 109 scoped_ptr<internal::PhantomWindowController> phantom_window_controller_; |
103 | 110 |
104 DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButton); | 111 DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButton); |
105 }; | 112 }; |
106 | 113 |
107 } // namespace ash | 114 } // namespace ash |
108 | 115 |
109 #endif // ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ | 116 #endif // ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_ |
OLD | NEW |