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