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"
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
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
{
32 FrameSizeButton(views::ButtonListener
* listener
,
34 FrameSizeButtonDelegate
* delegate
);
36 virtual ~FrameSizeButton();
38 // views::CustomButton overrides:
39 virtual bool OnMousePressed(const ui::MouseEvent
& event
) OVERRIDE
;
40 virtual bool OnMouseDragged(const ui::MouseEvent
& event
) OVERRIDE
;
41 virtual void OnMouseReleased(const ui::MouseEvent
& event
) OVERRIDE
;
42 virtual void OnMouseCaptureLost() OVERRIDE
;
43 virtual void OnMouseMoved(const ui::MouseEvent
& event
) OVERRIDE
;
44 virtual 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
;
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
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_
;
89 FrameSizeButtonDelegate
* delegate_
;
91 // Location of the event which started |set_buttons_to_snap_mode_timer_| in
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
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
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.
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
);
121 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_SIZE_BUTTON_H_