blob: 04892b89c3cad999a1045b680ff3c7da90dd7d0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_
#define ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_
#include "ash/ash_export.h"
#include "base/memory/scoped_ptr.h"
#include "base/timer.h"
#include "ui/views/controls/button/image_button.h"
namespace views {
class NonClientFrameView;
}
namespace ash {
namespace internal {
class PhantomWindowController;
class SnapSizer;
}
// Button used for the maximize control on the frame. Handles snapping logic.
class ASH_EXPORT FrameMaximizeButton : public views::ImageButton {
public:
FrameMaximizeButton(views::ButtonListener* listener,
views::NonClientFrameView* frame);
virtual ~FrameMaximizeButton();
// ImageButton overrides:
virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
virtual bool OnMouseDragged(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseReleased(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseCaptureLost() OVERRIDE;
// Sets is_left_right_enabled_ and updates tooltip.
void SetIsLeftRightEnabled(bool e);
void set_is_maximize_enabled(bool e) { is_maximize_enabled_ = e; }
protected:
// ImageButton overrides:
virtual SkBitmap GetImageToPaint() OVERRIDE;
private:
class EscapeEventFilter;
// Where to snap to.
enum SnapType {
SNAP_LEFT,
SNAP_RIGHT,
SNAP_MAXIMIZE,
SNAP_MINIMIZE,
SNAP_RESTORE,
SNAP_NONE
};
// Cancels snap behavior.
void Cancel();
// Installs/uninstalls an EventFilter to track when escape is pressed.
void InstallEventFilter();
void UninstallEventFilter();
// Updates the snap position from the current location. This is invoked by
// |update_timer_|.
void UpdateSnapFromCursorScreenPoint();
// Updates |snap_type_| based on a mouse drag.
void UpdateSnap(const gfx::Point& location);
// Returns true if maximizing is allowed.
bool AllowMaximize() const;
// Returns the type of snap based on the specified location.
SnapType SnapTypeForLocation(const gfx::Point& location) const;
// Returns the bounds of the resulting window for the specified type.
gfx::Rect BoundsForType(SnapType type) const;
// Converts location to screen coordinates and returns it. These are the
// coordinates used by the SnapSizer.
gfx::Point LocationForSnapSizer(const gfx::Point& location) const;
// Snaps the window to the current snap position.
void Snap();
// Frame that the maximize button acts on.
views::NonClientFrameView* frame_;
// Renders the snap position.
scoped_ptr<internal::PhantomWindowController> phantom_window_;
// Is snapping enabled? Set on press so that in drag we know whether we
// should show the snap locations.
bool is_snap_enabled_;
// Selectively enable/disable button functionality.
bool is_left_right_enabled_;
bool is_maximize_enabled_;
// Did the user drag far enough to trigger snapping?
bool exceeded_drag_threshold_;
// Location of the press.
gfx::Point press_location_;
// Current snap type.
SnapType snap_type_;
scoped_ptr<internal::SnapSizer> snap_sizer_;
scoped_ptr<EscapeEventFilter> escape_event_filter_;
base::OneShotTimer<FrameMaximizeButton> update_timer_;
DISALLOW_COPY_AND_ASSIGN(FrameMaximizeButton);
};
} // namespace ash
#endif // ASH_WM_WORKSPACE_FRAME_MAXIMIZE_BUTTON_H_
|