Chromium Code Reviews| 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 "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/timer.h" | 10 #include "base/timer.h" |
| 11 #include "ui/aura/window_observer.h" | |
| 11 #include "ui/views/controls/button/image_button.h" | 12 #include "ui/views/controls/button/image_button.h" |
| 12 | 13 |
| 13 namespace views { | 14 namespace views { |
| 14 class NonClientFrameView; | 15 class NonClientFrameView; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace ash { | 18 namespace ash { |
| 18 | 19 |
| 19 namespace internal { | 20 namespace internal { |
| 20 class PhantomWindowController; | 21 class PhantomWindowController; |
| 21 class SnapSizer; | 22 class SnapSizer; |
| 22 } | 23 } |
| 23 | 24 |
| 25 class MaximizeBubble; | |
| 26 | |
| 24 // Button used for the maximize control on the frame. Handles snapping logic. | 27 // Button used for the maximize control on the frame. Handles snapping logic. |
| 25 class ASH_EXPORT FrameMaximizeButton : public views::ImageButton { | 28 class ASH_EXPORT FrameMaximizeButton : public views::ImageButton, |
| 29 public aura::WindowObserver { | |
| 26 public: | 30 public: |
| 31 // Where to snap to. | |
| 32 enum SnapType { | |
| 33 SNAP_LEFT, | |
| 34 SNAP_RIGHT, | |
| 35 SNAP_MAXIMIZE, | |
| 36 SNAP_MINIMIZE, | |
| 37 SNAP_RESTORE, | |
| 38 SNAP_NONE | |
| 39 }; | |
| 40 | |
| 27 FrameMaximizeButton(views::ButtonListener* listener, | 41 FrameMaximizeButton(views::ButtonListener* listener, |
| 28 views::NonClientFrameView* frame); | 42 views::NonClientFrameView* frame); |
| 29 virtual ~FrameMaximizeButton(); | 43 virtual ~FrameMaximizeButton(); |
| 30 | 44 |
| 45 // WindowObserver overrides: | |
| 46 virtual void OnWindowBoundsChanged(aura::Window* window, | |
| 47 const gfx::Rect& old_bounds, | |
| 48 const gfx::Rect& new_bounds) OVERRIDE; | |
| 49 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | |
| 50 | |
| 31 // ImageButton overrides: | 51 // ImageButton overrides: |
| 32 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; | 52 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE; |
| 33 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 53 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
| 34 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 54 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
| 35 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; | 55 virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE; |
| 36 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; | 56 virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE; |
| 37 virtual void OnMouseCaptureLost() OVERRIDE; | 57 virtual void OnMouseCaptureLost() OVERRIDE; |
| 38 virtual ui::GestureStatus OnGestureEvent( | 58 virtual ui::GestureStatus OnGestureEvent( |
| 39 const views::GestureEvent& event) OVERRIDE; | 59 const views::GestureEvent& event) OVERRIDE; |
| 40 | 60 |
| 61 // Updates |snap_type_| based on a a given snap type. This is used by | |
| 62 // external hover events from the button menu. | |
| 63 void SnapButtonHovered(SnapType type); | |
| 64 | |
| 65 // The user clicked the |type| button and the action needs to be performed, | |
| 66 // which will at the same time close the window. | |
| 67 void ExecuteSnapAndCloseMenu(SnapType type); | |
| 68 | |
| 69 // The menu should reflect the user selected type. | |
| 70 void UpdateVisibleMenu(SnapType type); | |
| 71 | |
| 72 // Remove the maximize menu from the screen (and destroy it). | |
| 73 void DestroyMaximizeMenu(); | |
| 74 | |
| 75 // Returns true when the user clicks and drags the button. | |
| 76 bool is_snap_enabled() { return is_snap_enabled_; } | |
| 77 | |
| 41 protected: | 78 protected: |
| 42 // ImageButton overrides: | 79 // ImageButton overrides: |
| 43 virtual gfx::ImageSkia GetImageToPaint() OVERRIDE; | 80 virtual gfx::ImageSkia GetImageToPaint() OVERRIDE; |
| 44 | 81 |
| 45 private: | 82 private: |
| 46 class EscapeEventFilter; | 83 class EscapeEventFilter; |
| 47 | 84 |
| 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 | 85 // 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. | 86 // when the event is confirmed to have started a snap gesture. |
| 60 void ProcessStartEvent(const views::LocatedEvent& event); | 87 void ProcessStartEvent(const views::LocatedEvent& event); |
| 61 | 88 |
| 62 // Updates the snap-state based on the current event. This should only be | 89 // Updates the snap-state based on the current event. This should only be |
| 63 // called after the snap gesture has already started. | 90 // called after the snap gesture has already started. |
| 64 void ProcessUpdateEvent(const views::LocatedEvent& event); | 91 void ProcessUpdateEvent(const views::LocatedEvent& event); |
| 65 | 92 |
| 66 // Returns true if the window was snapped. Returns false otherwise. | 93 // Returns true if the window was snapped. Returns false otherwise. |
| 67 bool ProcessEndEvent(const views::LocatedEvent& event); | 94 bool ProcessEndEvent(const views::LocatedEvent& event); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 99 // Renders the snap position. | 126 // Renders the snap position. |
| 100 scoped_ptr<internal::PhantomWindowController> phantom_window_; | 127 scoped_ptr<internal::PhantomWindowController> phantom_window_; |
| 101 | 128 |
| 102 // Is snapping enabled? Set on press so that in drag we know whether we | 129 // Is snapping enabled? Set on press so that in drag we know whether we |
| 103 // should show the snap locations. | 130 // should show the snap locations. |
| 104 bool is_snap_enabled_; | 131 bool is_snap_enabled_; |
| 105 | 132 |
| 106 // Did the user drag far enough to trigger snapping? | 133 // Did the user drag far enough to trigger snapping? |
| 107 bool exceeded_drag_threshold_; | 134 bool exceeded_drag_threshold_; |
| 108 | 135 |
| 136 // A window listener for window move / size operations was installed for | |
| 137 // this window. It monitors window changes so that the menu can get removed | |
| 138 // if it moves. The listener will automatically be removed when the attached | |
| 139 // window gets deleted. | |
| 140 aura::Window* window_moved_listener_installed_for_; | |
|
sky
2012/07/31 16:11:06
Name this |window_| with a comment indicating this
Mr4D (OOO till 08-26)
2012/08/01 20:48:22
Done.
| |
| 141 | |
| 109 // Location of the press. | 142 // Location of the press. |
| 110 gfx::Point press_location_; | 143 gfx::Point press_location_; |
| 111 | 144 |
| 112 // Current snap type. | 145 // Current snap type. |
| 113 SnapType snap_type_; | 146 SnapType snap_type_; |
| 114 | 147 |
| 115 scoped_ptr<internal::SnapSizer> snap_sizer_; | 148 scoped_ptr<internal::SnapSizer> snap_sizer_; |
| 116 | 149 |
| 117 scoped_ptr<EscapeEventFilter> escape_event_filter_; | 150 scoped_ptr<EscapeEventFilter> escape_event_filter_; |
| 118 | 151 |
| 119 base::OneShotTimer<FrameMaximizeButton> update_timer_; | 152 base::OneShotTimer<FrameMaximizeButton> update_timer_; |
| 120 | 153 |
| 154 scoped_ptr<MaximizeBubble> maximizer_; | |
| 155 | |
| 121 DISALLOW_COPY_AND_ASSIGN(FrameMaximizeButton); | 156 DISALLOW_COPY_AND_ASSIGN(FrameMaximizeButton); |
| 122 }; | 157 }; |
| 123 | 158 |
| 124 } // namespace ash | 159 } // namespace ash |
| 125 | 160 |
| 126 #endif // ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ | 161 #endif // ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_ |
| OLD | NEW |