Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / ash / frame / caption_buttons / alternate_frame_size_button.h
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.
4
5 #ifndef ASH_FRAME_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
7
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"
13
14 namespace views {
15 class Widget;
16 }
17
18 namespace ash {
19 class AlternateFrameSizeButtonDelegate;
20
21 namespace internal {
22 class PhantomWindowController;
23 }
24
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
28 //   respectively.
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 {
35  public:
36   AlternateFrameSizeButton(views::ButtonListener* listener,
37                            views::Widget* frame,
38                            AlternateFrameSizeButtonDelegate* delegate);
39
40   virtual ~AlternateFrameSizeButton();
41
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;
49
50   void set_delay_to_set_buttons_to_snap_mode(int delay_ms) {
51     set_buttons_to_snap_mode_delay_ms_ = delay_ms;
52   }
53
54  private:
55   // Starts |set_buttons_to_snap_mode_timer_|.
56   void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event);
57
58   // Animates the buttons adjacent to the size button to snap left and right.
59   void AnimateButtonsToSnapMode();
60
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);
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(
83       AlternateFrameSizeButtonDelegate::Animate animate);
84
85   // Widget that the size button acts on.
86   views::Widget* frame_;
87
88   // Not owned.
89   AlternateFrameSizeButtonDelegate* delegate_;
90
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_;
94
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_;
99
100   base::OneShotTimer<AlternateFrameSizeButton> set_buttons_to_snap_mode_timer_;
101
102   // Whether the buttons adjacent to the size button snap the window left and
103   // right.
104   bool in_snap_mode_;
105
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_;
110
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_;
115
116   DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButton);
117 };
118
119 }  // namespace ash
120
121 #endif  // ASH_FRAME_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_