1 // Copyright 2013 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_ALTERNATE_FRAME_SIZE_BUTTON_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
8 #include "ash/ash_export.h"
9 #include "ash/frame/caption_buttons/alternate_frame_size_button_delegate.h"
10 #include "ash/frame/caption_buttons/frame_caption_button.h"
11 #include "ash/wm/workspace/snap_types.h"
12 #include "base/timer/timer.h"
19 class AlternateFrameSizeButtonDelegate;
22 class PhantomWindowController;
25 // The maximize/restore button when using the alternate button style.
26 // When the mouse is pressed over the size button or the size button is touched:
27 // - The minimize and close buttons are set to snap left and snap right
29 // - The size button stays pressed while the mouse is over the buttons to snap
30 // left and to snap right. The button underneath the mouse is hovered.
31 // When the drag terminates, the action for the button underneath the mouse
32 // is executed. For the sake of simplicity, the size button is the event
33 // handler for a click starting on the size button and the entire drag.
34 class ASH_EXPORT AlternateFrameSizeButton : public FrameCaptionButton {
36 AlternateFrameSizeButton(views::ButtonListener* listener,
38 AlternateFrameSizeButtonDelegate* delegate);
40 virtual ~AlternateFrameSizeButton();
42 // views::CustomButton overrides:
43 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
44 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
45 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
46 virtual void OnMouseCaptureLost() OVERRIDE;
47 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
48 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
50 void set_delay_to_set_buttons_to_snap_mode(int delay_ms) {
51 set_buttons_to_snap_mode_delay_ms_ = delay_ms;
55 // Starts |set_buttons_to_snap_mode_timer_|.
56 void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event);
58 // Animates the buttons adjacent to the size button to snap left and right.
59 void AnimateButtonsToSnapMode();
61 // Sets the buttons adjacent to the size button to snap left and right.
62 // Passing in ANIMATE_NO progresses the animation (if any) to the end.
63 void SetButtonsToSnapMode(
64 AlternateFrameSizeButtonDelegate::Animate animate);
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);
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;
75 // Snaps |frame_| according to |snap_type_|. Returns true if |frame_| was
77 bool CommitSnap(const ui::LocatedEvent& event);
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(
83 AlternateFrameSizeButtonDelegate::Animate animate);
85 // Widget that the size button acts on.
86 views::Widget* frame_;
89 AlternateFrameSizeButtonDelegate* 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<AlternateFrameSizeButton> 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<internal::PhantomWindowController> phantom_window_controller_;
116 DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButton);
121 #endif // ASH_FRAME_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_