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 #ifndef ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ | 5 #ifndef ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ |
6 #define ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ | 6 #define ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/wm/workspace/snap_types.h" |
9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
10 #include "base/timer.h" | 11 #include "base/timer.h" |
| 12 #include "ui/aura/window_observer.h" |
11 #include "ui/views/controls/button/image_button.h" | 13 #include "ui/views/controls/button/image_button.h" |
12 | 14 |
13 namespace views { | 15 namespace views { |
14 class NonClientFrameView; | 16 class NonClientFrameView; |
15 } | 17 } |
16 | 18 |
17 namespace ash { | 19 namespace ash { |
18 | 20 |
19 namespace internal { | 21 namespace internal { |
20 class PhantomWindowController; | 22 class PhantomWindowController; |
21 class SnapSizer; | 23 class SnapSizer; |
22 } | 24 } |
23 | 25 |
| 26 class MaximizeBubbleController; |
| 27 |
24 // Button used for the maximize control on the frame. Handles snapping logic. | 28 // Button used for the maximize control on the frame. Handles snapping logic. |
25 class ASH_EXPORT FrameMaximizeButton : public views::ImageButton { | 29 class ASH_EXPORT FrameMaximizeButton : public views::ImageButton, |
| 30 public aura::WindowObserver { |
26 public: | 31 public: |
27 FrameMaximizeButton(views::ButtonListener* listener, | 32 FrameMaximizeButton(views::ButtonListener* listener, |
28 views::NonClientFrameView* frame); | 33 views::NonClientFrameView* frame); |
29 virtual ~FrameMaximizeButton(); | 34 virtual ~FrameMaximizeButton(); |
30 | 35 |
| 36 // Updates |snap_type_| based on a a given snap type. This is used by |
| 37 // external hover events from the button menu. |
| 38 void SnapButtonHovered(SnapType type); |
| 39 |
| 40 // The user clicked the |type| button and the action needs to be performed, |
| 41 // which will at the same time close the window. |
| 42 void ExecuteSnapAndCloseMenu(SnapType type); |
| 43 |
| 44 // Remove the maximize menu from the screen (and destroy it). |
| 45 void DestroyMaximizeMenu(); |
| 46 |
| 47 // Returns true when the user clicks and drags the button. |
| 48 bool is_snap_enabled() const { return is_snap_enabled_; } |
| 49 |
| 50 // WindowObserver overrides: |
| 51 virtual void OnWindowBoundsChanged(aura::Window* window, |
| 52 const gfx::Rect& old_bounds, |
| 53 const gfx::Rect& new_bounds) OVERRIDE; |
| 54 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
| 55 |
31 // ImageButton overrides: | 56 // ImageButton overrides: |
32 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | 57 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
33 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 58 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
34 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 59 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
35 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | 60 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |
36 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 61 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
37 virtual void OnMouseCaptureLost() OVERRIDE; | 62 virtual void OnMouseCaptureLost() OVERRIDE; |
38 virtual ui::GestureStatus OnGestureEvent( | 63 virtual ui::GestureStatus OnGestureEvent( |
39 const views::GestureEvent& event) OVERRIDE; | 64 const views::GestureEvent& event) OVERRIDE; |
40 | 65 |
41 protected: | |
42 // ImageButton overrides: | |
43 virtual gfx::ImageSkia GetImageToPaint() OVERRIDE; | |
44 | |
45 private: | 66 private: |
46 class EscapeEventFilter; | 67 class EscapeEventFilter; |
47 | 68 |
48 // Where to snap to. | |
49 enum SnapType { | |
50 SNAP_LEFT, | |
51 SNAP_RIGHT, | |
52 SNAP_MAXIMIZE, | |
53 SNAP_MINIMIZE, | |
54 SNAP_RESTORE, | |
55 SNAP_NONE | |
56 }; | |
57 | |
58 // Initializes the snap-gesture based on the event. This should only be called | 69 // Initializes the snap-gesture based on the event. This should only be called |
59 // when the event is confirmed to have started a snap gesture. | 70 // when the event is confirmed to have started a snap gesture. |
60 void ProcessStartEvent(const views::LocatedEvent& event); | 71 void ProcessStartEvent(const views::LocatedEvent& event); |
61 | 72 |
62 // Updates the snap-state based on the current event. This should only be | 73 // Updates the snap-state based on the current event. This should only be |
63 // called after the snap gesture has already started. | 74 // called after the snap gesture has already started. |
64 void ProcessUpdateEvent(const views::LocatedEvent& event); | 75 void ProcessUpdateEvent(const views::LocatedEvent& event); |
65 | 76 |
66 // Returns true if the window was snapped. Returns false otherwise. | 77 // Returns true if the window was snapped. Returns false otherwise. |
67 bool ProcessEndEvent(const views::LocatedEvent& event); | 78 bool ProcessEndEvent(const views::LocatedEvent& event); |
68 | 79 |
69 // Cancels snap behavior. | 80 // Cancels snap behavior. If |keep_menu_open| is set, a possibly opened |
70 void Cancel(); | 81 // bubble help will remain open. |
| 82 void Cancel(bool keep_menu_open); |
71 | 83 |
72 // Installs/uninstalls an EventFilter to track when escape is pressed. | 84 // Installs/uninstalls an EventFilter to track when escape is pressed. |
73 void InstallEventFilter(); | 85 void InstallEventFilter(); |
74 void UninstallEventFilter(); | 86 void UninstallEventFilter(); |
75 | 87 |
76 // Updates the snap position from the event location. This is invoked by | 88 // Updates the snap position from the event location. This is invoked by |
77 // |update_timer_|. | 89 // |update_timer_|. |
78 void UpdateSnapFromEventLocation(); | 90 void UpdateSnapFromEventLocation(); |
79 | 91 |
80 // Updates |snap_type_| based on a mouse drag. | 92 // Updates |snap_type_| based on a mouse drag. |
(...skipping 18 matching lines...) Expand all Loading... |
99 // Renders the snap position. | 111 // Renders the snap position. |
100 scoped_ptr<internal::PhantomWindowController> phantom_window_; | 112 scoped_ptr<internal::PhantomWindowController> phantom_window_; |
101 | 113 |
102 // Is snapping enabled? Set on press so that in drag we know whether we | 114 // Is snapping enabled? Set on press so that in drag we know whether we |
103 // should show the snap locations. | 115 // should show the snap locations. |
104 bool is_snap_enabled_; | 116 bool is_snap_enabled_; |
105 | 117 |
106 // Did the user drag far enough to trigger snapping? | 118 // Did the user drag far enough to trigger snapping? |
107 bool exceeded_drag_threshold_; | 119 bool exceeded_drag_threshold_; |
108 | 120 |
| 121 // This is the Window we are contained in. |
| 122 aura::Window* window_; |
| 123 |
109 // Location of the press. | 124 // Location of the press. |
110 gfx::Point press_location_; | 125 gfx::Point press_location_; |
111 | 126 |
112 // Current snap type. | 127 // Current snap type. |
113 SnapType snap_type_; | 128 SnapType snap_type_; |
114 | 129 |
115 scoped_ptr<internal::SnapSizer> snap_sizer_; | 130 scoped_ptr<internal::SnapSizer> snap_sizer_; |
116 | 131 |
117 scoped_ptr<EscapeEventFilter> escape_event_filter_; | 132 scoped_ptr<EscapeEventFilter> escape_event_filter_; |
118 | 133 |
119 base::OneShotTimer<FrameMaximizeButton> update_timer_; | 134 base::OneShotTimer<FrameMaximizeButton> update_timer_; |
120 | 135 |
| 136 scoped_ptr<MaximizeBubbleController> maximizer_; |
| 137 |
121 DISALLOW_COPY_AND_ASSIGN(FrameMaximizeButton); | 138 DISALLOW_COPY_AND_ASSIGN(FrameMaximizeButton); |
122 }; | 139 }; |
123 | 140 |
124 } // namespace ash | 141 } // namespace ash |
125 | 142 |
126 #endif // ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ | 143 #endif // ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ |
OLD | NEW |