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. 4 5 #ifndef ASH_WM_WM_EVENT_H_ 6 #define ASH_WM_WM_EVENT_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/wm/window_state.h" 10 #include "base/macros.h" 11 #include "base/time/time.h" 12 #include "ui/display/display.h" 13 #include "ui/display/display_observer.h" 14 #include "ui/gfx/geometry/rect.h" 15 16 namespace ash { 17 18 // WMEventType defines a set of operations that can change the 19 // window's state type and bounds. 20 enum WMEventType { 21 // Following events are the request to become corresponding state. 22 // Note that this does not mean the window will be in corresponding 23 // state and the request may not be fullfilled. 24 25 // NORMAL is used as a restore operation with a few exceptions. 26 WM_EVENT_NORMAL = 0, 27 WM_EVENT_MAXIMIZE, 28 WM_EVENT_MINIMIZE, 29 WM_EVENT_FULLSCREEN, 30 WM_EVENT_SNAP_LEFT, 31 WM_EVENT_SNAP_RIGHT, 32 33 // A window is requested to be the given bounds. The request may or 34 // may not be fulfilled depending on the requested bounds and window's 35 // state. This will not change the window state type. 36 WM_EVENT_SET_BOUNDS, 37 38 // Following events are compond events which may lead to different 39 // states depending on the current state. 40 41 // A user requested to toggle maximized state by double clicking window 42 // header. 43 WM_EVENT_TOGGLE_MAXIMIZE_CAPTION, 44 45 // A user requested to toggle maximized state using shortcut. 46 WM_EVENT_TOGGLE_MAXIMIZE, 47 48 // A user requested to toggle vertical maximize by double clicking 49 // top/bottom edge. 50 WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE, 51 52 // A user requested to toggle horizontal maximize by double clicking 53 // left/right edge. 54 WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE, 55 56 // A user requested to toggle fullscreen state. 57 WM_EVENT_TOGGLE_FULLSCREEN, 58 59 // A user requested a cycle of snap left. 60 // The way this event is processed is the current window state is used as 61 // the starting state. Assuming normal window start state; if the window can 62 // be snapped left, snap it; otherwise progress to next state. If the 63 // window can be restored; and this isn't the entry condition restore it; 64 // otherwise apply the bounce animation to the window. 65 WM_EVENT_CYCLE_SNAP_LEFT, 66 67 // A user requested a cycle of snap right. 68 // See decription of WM_EVENT_CYCLE_SNAP_LEFT. 69 WM_EVENT_CYCLE_SNAP_RIGHT, 70 71 // A user requested to center a window. 72 WM_EVENT_CENTER, 73 74 // TODO(oshima): Investigate if this can be removed from ash. 75 // Widget requested to show in inactive state. 76 WM_EVENT_SHOW_INACTIVE, 77 78 // Following events are generated when the workspace envrionment has changed. 79 // The window's state type will not be changed by these events. 80 81 // The window is added to the workspace, either as a new window, due to 82 // display disconnection or dragging. 83 WM_EVENT_ADDED_TO_WORKSPACE, 84 85 // Bounds of the display has changed. 86 WM_EVENT_DISPLAY_BOUNDS_CHANGED, 87 88 // Bounds of the work area has changed. This will not occur when the work 89 // area has changed as a result of DISPLAY_BOUNDS_CHANGED. 90 WM_EVENT_WORKAREA_BOUNDS_CHANGED, 91 92 // A user requested to pin a window. 93 WM_EVENT_PIN, 94 95 // A user requested to pip a window. 96 WM_EVENT_PIP, 97 98 // A user requested to pin a window for a trusted application. This is similar 99 // WM_EVENT_PIN but does not allow user to exit the mode by shortcut key. 100 WM_EVENT_TRUSTED_PIN, 101 102 // A system ui area has changed. Currently, this includes the virtual 103 // keyboard and the message center. A change can be a change in visibility 104 // or bounds. 105 // TODO(oshima): Consider consolidating this into 106 // WM_EVENT_WORKAREA_BOUNDS_CHANGED 107 WM_EVENT_SYSTEM_UI_AREA_CHANGED, 108 }; 109 110 class SetBoundsWMEvent; 111 class DisplayMetricsChangedWMEvent; 112 113 class ASH_EXPORT WMEvent { 114 public: 115 explicit WMEvent(WMEventType type); 116 virtual ~WMEvent(); 117 type()118 WMEventType type() const { return type_; } 119 120 // Predicates to test the type of event. 121 122 // Event that notifies that workspace has changed. (its size, being 123 // added/moved to another workspace, 124 // e.g. WM_EVENT_ADDED_TO_WORKSPACE). 125 bool IsWorkspaceEvent() const; 126 127 // True if the event will result in another event. For example 128 // TOGGLE_FULLSCREEN sends WM_EVENT_FULLSCREEN or WM_EVENT_NORMAL 129 // depending on the current state. 130 bool IsCompoundEvent() const; 131 132 // WM_EVENT_PIN or WM_EVENT_TRUSTD_PIN. 133 bool IsPinEvent() const; 134 135 // True If the event requurests bounds change, e.g. SET_BOUNDS 136 bool IsBoundsEvent() const; 137 138 // True if the event requests the window state transition, 139 // e.g. WM_EVENT_MAXIMIZED. 140 bool IsTransitionEvent() const; 141 142 // Utility methods to downcast to specific WMEvent types. 143 const DisplayMetricsChangedWMEvent* AsDisplayMetricsChangedWMEvent() const; 144 145 private: 146 WMEventType type_; 147 DISALLOW_COPY_AND_ASSIGN(WMEvent); 148 }; 149 150 // An WMEvent to request new bounds for the window. 151 class ASH_EXPORT SetBoundsWMEvent : public WMEvent { 152 public: 153 SetBoundsWMEvent( 154 const gfx::Rect& requested_bounds, 155 bool animate = false, 156 base::TimeDelta duration = WindowState::kBoundsChangeSlideDuration); 157 SetBoundsWMEvent(const gfx::Rect& requested_bounds, int64_t display_id); 158 ~SetBoundsWMEvent() override; 159 requested_bounds()160 const gfx::Rect& requested_bounds() const { return requested_bounds_; } 161 animate()162 bool animate() const { return animate_; } 163 duration()164 base::TimeDelta duration() const { return duration_; } 165 display_id()166 int64_t display_id() const { return display_id_; } 167 168 private: 169 const gfx::Rect requested_bounds_; 170 const int64_t display_id_ = display::kInvalidDisplayId; 171 const bool animate_; 172 const base::TimeDelta duration_; 173 174 DISALLOW_COPY_AND_ASSIGN(SetBoundsWMEvent); 175 }; 176 177 // A WMEvent sent when display metrics have changed. 178 // TODO(oshima): Consolidate with WM_EVENT_WORKAREA_BOUNDS_CHANGED. 179 class ASH_EXPORT DisplayMetricsChangedWMEvent : public WMEvent { 180 public: 181 explicit DisplayMetricsChangedWMEvent(int display_metrics); 182 ~DisplayMetricsChangedWMEvent() override; 183 primary_changed()184 bool primary_changed() const { 185 return changed_metrics_ & display::DisplayObserver::DISPLAY_METRIC_PRIMARY; 186 } 187 changed_metrics()188 uint32_t changed_metrics() const { return changed_metrics_; } 189 190 private: 191 const uint32_t changed_metrics_; 192 193 DISALLOW_COPY_AND_ASSIGN(DisplayMetricsChangedWMEvent); 194 }; 195 196 } // namespace ash 197 198 #endif // ASH_WM_WM_EVENT_H_ 199