| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_SIZE_BUTTON_H_ | |
| 6 #define ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_SIZE_BUTTON_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 | |
| 10 #include "ash/ash_export.h" | |
| 11 #include "ash/common/frame/caption_buttons/frame_caption_button.h" | |
| 12 #include "ash/common/frame/caption_buttons/frame_size_button_delegate.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/timer/timer.h" | |
| 15 | |
| 16 namespace views { | |
| 17 class Widget; | |
| 18 } | |
| 19 | |
| 20 namespace ash { | |
| 21 class FrameSizeButtonDelegate; | |
| 22 class PhantomWindowController; | |
| 23 | |
| 24 // The maximize/restore button. | |
| 25 // When the mouse is pressed over the size button or the size button is touched: | |
| 26 // - The minimize and close buttons are set to snap left and snap right | |
| 27 // respectively. | |
| 28 // - The size button stays pressed while the mouse is over the buttons to snap | |
| 29 // left and to snap right. The button underneath the mouse is hovered. | |
| 30 // When the drag terminates, the action for the button underneath the mouse | |
| 31 // is executed. For the sake of simplicity, the size button is the event | |
| 32 // handler for a click starting on the size button and the entire drag. | |
| 33 class ASH_EXPORT FrameSizeButton : public FrameCaptionButton { | |
| 34 public: | |
| 35 FrameSizeButton(views::ButtonListener* listener, | |
| 36 views::Widget* frame, | |
| 37 FrameSizeButtonDelegate* delegate); | |
| 38 | |
| 39 ~FrameSizeButton() override; | |
| 40 | |
| 41 // views::CustomButton overrides: | |
| 42 bool OnMousePressed(const ui::MouseEvent& event) override; | |
| 43 bool OnMouseDragged(const ui::MouseEvent& event) override; | |
| 44 void OnMouseReleased(const ui::MouseEvent& event) override; | |
| 45 void OnMouseCaptureLost() override; | |
| 46 void OnMouseMoved(const ui::MouseEvent& event) override; | |
| 47 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 48 | |
| 49 void set_delay_to_set_buttons_to_snap_mode(int delay_ms) { | |
| 50 set_buttons_to_snap_mode_delay_ms_ = delay_ms; | |
| 51 } | |
| 52 | |
| 53 private: | |
| 54 enum SnapType { SNAP_LEFT, SNAP_RIGHT, SNAP_NONE }; | |
| 55 | |
| 56 // Starts |set_buttons_to_snap_mode_timer_|. | |
| 57 void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event); | |
| 58 | |
| 59 // Animates the buttons adjacent to the size button to snap left and right. | |
| 60 void AnimateButtonsToSnapMode(); | |
| 61 | |
| 62 // Sets the buttons adjacent to the size button to snap left and right. | |
| 63 // Passing in ANIMATE_NO progresses the animation (if any) to the end. | |
| 64 void SetButtonsToSnapMode(FrameSizeButtonDelegate::Animate animate); | |
| 65 | |
| 66 // Updates |snap_type_|, whether the size button is pressed and whether any | |
| 67 // other buttons are hovered. | |
| 68 void UpdateSnapType(const ui::LocatedEvent& event); | |
| 69 | |
| 70 // Returns the button which should be hovered (if any) while in "snap mode" | |
| 71 // for |event_location_in_screen|. | |
| 72 const FrameCaptionButton* GetButtonToHover( | |
| 73 const gfx::Point& event_location_in_screen) const; | |
| 74 | |
| 75 // Snaps |frame_| according to |snap_type_|. Returns true if |frame_| was | |
| 76 // snapped. | |
| 77 bool CommitSnap(const ui::LocatedEvent& event); | |
| 78 | |
| 79 // Sets the buttons adjacent to the size button to minimize and close again. | |
| 80 // Clears any state set while snapping was enabled. |animate| indicates | |
| 81 // whether the buttons should animate back to their original icons. | |
| 82 void SetButtonsToNormalMode(FrameSizeButtonDelegate::Animate animate); | |
| 83 | |
| 84 // Widget that the size button acts on. | |
| 85 views::Widget* frame_; | |
| 86 | |
| 87 // Not owned. | |
| 88 FrameSizeButtonDelegate* delegate_; | |
| 89 | |
| 90 // Location of the event which started |set_buttons_to_snap_mode_timer_| in | |
| 91 // view coordinates. | |
| 92 gfx::Point set_buttons_to_snap_mode_timer_event_location_; | |
| 93 | |
| 94 // The delay between the user pressing the size button and the buttons | |
| 95 // adjacent to the size button morphing into buttons for snapping left and | |
| 96 // right. | |
| 97 int set_buttons_to_snap_mode_delay_ms_; | |
| 98 | |
| 99 base::OneShotTimer set_buttons_to_snap_mode_timer_; | |
| 100 | |
| 101 // Whether the buttons adjacent to the size button snap the window left and | |
| 102 // right. | |
| 103 bool in_snap_mode_; | |
| 104 | |
| 105 // The action to execute when the drag/click is ended. If | |
| 106 // |snap_type_| == SNAP_NONE, the size button's default action is run when the | |
| 107 // drag/click is ended. | |
| 108 SnapType snap_type_; | |
| 109 | |
| 110 // Displays a preview of how the window's bounds will change as a result of | |
| 111 // snapping the window left or right. The preview is only visible if the snap | |
| 112 // left or snap right button is pressed. | |
| 113 std::unique_ptr<PhantomWindowController> phantom_window_controller_; | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(FrameSizeButton); | |
| 116 }; | |
| 117 | |
| 118 } // namespace ash | |
| 119 | |
| 120 #endif // ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_SIZE_BUTTON_H_ | |
| OLD | NEW |