• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
6 #define ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
7 
8 #include "ash/ash_export.h"
9 #include "ash/wm/caption_buttons/alternate_frame_size_button_delegate.h"
10 #include "ash/wm/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 // The maximize/restore button when using the alternate button style.
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 pressed button is updated during the drag to reflect the button
26 //   underneath the mouse cursor. (The size button is potentially unpressed).
27 // When the drag terminates, the action for the pressed button is executed.
28 // For the sake of simplicity, the size button is the event handler for a click
29 // starting on the size button and the entire drag (including when the size
30 // button is unpressed).
31 class ASH_EXPORT AlternateFrameSizeButton : public FrameCaptionButton {
32  public:
33   AlternateFrameSizeButton(views::ButtonListener* listener,
34                            views::Widget* frame,
35                            AlternateFrameSizeButtonDelegate* delegate);
36 
37   virtual ~AlternateFrameSizeButton();
38 
39   // views::CustomButton overrides:
40   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
41   virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
42   virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
43   virtual void OnMouseCaptureLost() OVERRIDE;
44   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
45 
set_delay_to_set_buttons_to_snap_mode(int delay_ms)46   void set_delay_to_set_buttons_to_snap_mode(int delay_ms) {
47     set_buttons_to_snap_mode_delay_ms_ = delay_ms;
48   }
49 
50  private:
51   // Starts |set_buttons_to_snap_mode_timer_|.
52   void StartSetButtonsToSnapModeTimer(const ui::LocatedEvent& event);
53 
54   // Sets the buttons adjacent to the size button to snap left and right.
55   void SetButtonsToSnapMode();
56 
57   // Updates the pressed button based on |event_location|.
58   void UpdatePressedButton(const ui::LocatedEvent& event);
59 
60   // Snaps |frame_| according to |snap_type_|. Returns true if |frame_| was
61   // snapped.
62   bool CommitSnap(const ui::LocatedEvent& event);
63 
64   // Sets the buttons adjacent to the size button to minimize and close again.
65   // Clears any state set while snapping was enabled. |animate| indicates
66   // whether the buttons should animate back to their original icons.
67   void SetButtonsToNormalMode(
68       AlternateFrameSizeButtonDelegate::Animate animate);
69 
70   // Widget that the size button acts on.
71   views::Widget* frame_;
72 
73   // Not owned.
74   AlternateFrameSizeButtonDelegate* delegate_;
75 
76   // Location of the event which started |set_buttons_to_snap_mode_timer_| in
77   // view coordinates.
78   gfx::Point set_buttons_to_snap_mode_timer_event_location_;
79 
80   // The delay between the user pressing the size button and the buttons
81   // adjacent to the size button morphing into buttons for snapping left and
82   // right.
83   int set_buttons_to_snap_mode_delay_ms_;
84 
85   base::OneShotTimer<AlternateFrameSizeButton> set_buttons_to_snap_mode_timer_;
86 
87   // Whether the buttons adjacent to the size button snap the window left and
88   // right.
89   bool in_snap_mode_;
90 
91   // The action of the currently pressed button. If |snap_type_| == SNAP_NONE,
92   // the size button's default action is run when clicked.
93   SnapType snap_type_;
94 
95   DISALLOW_COPY_AND_ASSIGN(AlternateFrameSizeButton);
96 };
97 
98 }  // namespace ash
99 
100 #endif  // ASH_WM_CAPTION_BUTTONS_ALTERNATE_FRAME_SIZE_BUTTON_H_
101