OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ | 5 #ifndef UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ |
6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ | 6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #import "ui/accelerated_widget_mac/accelerated_widget_mac.h" | 15 #import "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
16 #include "ui/base/ime/input_method_delegate.h" | 16 #include "ui/base/ime/input_method_delegate.h" |
17 #include "ui/compositor/layer_owner.h" | 17 #include "ui/compositor/layer_owner.h" |
18 #import "ui/views/cocoa/bridged_native_widget_owner.h" | 18 #import "ui/views/cocoa/bridged_native_widget_owner.h" |
19 #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" | 19 #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" |
| 20 #import "ui/views/cocoa/cocoa_window_move_loop.h" |
20 #import "ui/views/focus/focus_manager.h" | 21 #import "ui/views/focus/focus_manager.h" |
21 #include "ui/views/views_export.h" | 22 #include "ui/views/views_export.h" |
22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
23 | 24 |
24 @class BridgedContentView; | 25 @class BridgedContentView; |
25 @class ViewsNSWindowDelegate; | 26 @class ViewsNSWindowDelegate; |
26 | 27 |
27 namespace ui { | 28 namespace ui { |
28 class InputMethod; | 29 class InputMethod; |
29 } | 30 } |
30 | 31 |
31 namespace views { | 32 namespace views { |
32 namespace test { | 33 namespace test { |
33 class BridgedNativeWidgetTestApi; | 34 class BridgedNativeWidgetTestApi; |
34 } | 35 } |
35 | 36 |
36 class CocoaMouseCapture; | 37 class CocoaMouseCapture; |
| 38 class CocoaWindowMoveLoop; |
37 class NativeWidgetMac; | 39 class NativeWidgetMac; |
38 class View; | 40 class View; |
39 | 41 |
40 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or | 42 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or |
41 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the | 43 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the |
42 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. | 44 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. |
43 class VIEWS_EXPORT BridgedNativeWidget | 45 class VIEWS_EXPORT BridgedNativeWidget |
44 : public ui::LayerDelegate, | 46 : public ui::LayerDelegate, |
45 public ui::LayerOwner, | 47 public ui::LayerOwner, |
46 public ui::internal::InputMethodDelegate, | 48 public ui::internal::InputMethodDelegate, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Sets the desired visibility of the window and updates the visibility of | 94 // Sets the desired visibility of the window and updates the visibility of |
93 // descendant windows where necessary. | 95 // descendant windows where necessary. |
94 void SetVisibilityState(WindowVisibilityState new_state); | 96 void SetVisibilityState(WindowVisibilityState new_state); |
95 | 97 |
96 // Acquiring mouse capture first steals capture from any existing | 98 // Acquiring mouse capture first steals capture from any existing |
97 // CocoaMouseCaptureDelegate, then captures all mouse events until released. | 99 // CocoaMouseCaptureDelegate, then captures all mouse events until released. |
98 void AcquireCapture(); | 100 void AcquireCapture(); |
99 void ReleaseCapture(); | 101 void ReleaseCapture(); |
100 bool HasCapture(); | 102 bool HasCapture(); |
101 | 103 |
| 104 // Start moving the window, pinned to the mouse cursor, and monitor events. |
| 105 // Return MOVE_LOOP_SUCCESSFUL on mouse up or MOVE_LOOP_CANCELED on escape. |
| 106 Widget::MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset); |
| 107 void EndMoveLoop(); |
| 108 bool IsRunMoveLoopActive() const; |
| 109 |
102 // See views::Widget. | 110 // See views::Widget. |
103 void SetNativeWindowProperty(const char* key, void* value); | 111 void SetNativeWindowProperty(const char* key, void* value); |
104 void* GetNativeWindowProperty(const char* key) const; | 112 void* GetNativeWindowProperty(const char* key) const; |
105 | 113 |
106 // Sets the cursor associated with the NSWindow. Retains |cursor|. | 114 // Sets the cursor associated with the NSWindow. Retains |cursor|. |
107 void SetCursor(NSCursor* cursor); | 115 void SetCursor(NSCursor* cursor); |
108 | 116 |
109 // Called internally by the NSWindowDelegate when the window is closing. | 117 // Called internally by the NSWindowDelegate when the window is closing. |
110 void OnWindowWillClose(); | 118 void OnWindowWillClose(); |
111 | 119 |
112 // Called by the NSWindowDelegate when a fullscreen operation begins. If | 120 // Called by the NSWindowDelegate when a fullscreen operation begins. If |
113 // |target_fullscreen_state| is true, the target state is fullscreen. | 121 // |target_fullscreen_state| is true, the target state is fullscreen. |
114 // Otherwise, a transition has begun to come out of fullscreen. | 122 // Otherwise, a transition has begun to come out of fullscreen. |
115 void OnFullscreenTransitionStart(bool target_fullscreen_state); | 123 void OnFullscreenTransitionStart(bool target_fullscreen_state); |
116 | 124 |
117 // Called when a fullscreen transition completes. If target_fullscreen_state() | 125 // Called when a fullscreen transition completes. If target_fullscreen_state() |
118 // does not match |actual_fullscreen_state|, a new transition will begin. | 126 // does not match |actual_fullscreen_state|, a new transition will begin. |
119 void OnFullscreenTransitionComplete(bool actual_fullscreen_state); | 127 void OnFullscreenTransitionComplete(bool actual_fullscreen_state); |
120 | 128 |
121 // Transition the window into or out of fullscreen. This will immediately | 129 // Transition the window into or out of fullscreen. This will immediately |
122 // invert the value of target_fullscreen_state(). | 130 // invert the value of target_fullscreen_state(). |
123 void ToggleDesiredFullscreenState(); | 131 void ToggleDesiredFullscreenState(); |
124 | 132 |
125 // Called by the NSWindowDelegate when the size of the window changes. | 133 // Called by the NSWindowDelegate when the size of the window changes. |
126 void OnSizeChanged(); | 134 void OnSizeChanged(); |
127 | 135 |
| 136 // Called once by the NSWindowDelegate when the position of the window has |
| 137 // changed. |
| 138 void OnPositionChanged(); |
| 139 |
128 // Called by the NSWindowDelegate when the visibility of the window may have | 140 // Called by the NSWindowDelegate when the visibility of the window may have |
129 // changed. For example, due to a (de)miniaturize operation, or the window | 141 // changed. For example, due to a (de)miniaturize operation, or the window |
130 // being reordered in (or out of) the screen list. | 142 // being reordered in (or out of) the screen list. |
131 void OnVisibilityChanged(); | 143 void OnVisibilityChanged(); |
132 | 144 |
133 // Explicitly set the visibility. This is called when Cocoa requests a draw, | 145 // Explicitly set the visibility. This is called when Cocoa requests a draw, |
134 // but hasn't updated the value of -[NSWindow isVisible] yet. | 146 // but hasn't updated the value of -[NSWindow isVisible] yet. |
135 void OnVisibilityChangedTo(bool new_visibility); | 147 void OnVisibilityChangedTo(bool new_visibility); |
136 | 148 |
137 // Called by the NSWindowDelegate on a scale factor or color space change. | 149 // Called by the NSWindowDelegate on a scale factor or color space change. |
(...skipping 11 matching lines...) Expand all Loading... |
149 // Called by NativeWidgetMac when the window size constraints change. | 161 // Called by NativeWidgetMac when the window size constraints change. |
150 void OnSizeConstraintsChanged(); | 162 void OnSizeConstraintsChanged(); |
151 | 163 |
152 // See widget.h for documentation. | 164 // See widget.h for documentation. |
153 ui::InputMethod* GetInputMethod(); | 165 ui::InputMethod* GetInputMethod(); |
154 | 166 |
155 // The restored bounds will be derived from the current NSWindow frame unless | 167 // The restored bounds will be derived from the current NSWindow frame unless |
156 // fullscreen or transitioning between fullscreen states. | 168 // fullscreen or transitioning between fullscreen states. |
157 gfx::Rect GetRestoredBounds() const; | 169 gfx::Rect GetRestoredBounds() const; |
158 | 170 |
| 171 // Returns the actual frame as the WindowServer sees it. |
| 172 NSRect WindowServerFrame() const; |
| 173 |
159 // Creates a ui::Compositor which becomes responsible for drawing the window. | 174 // Creates a ui::Compositor which becomes responsible for drawing the window. |
160 void CreateLayer(ui::LayerType layer_type, bool translucent); | 175 void CreateLayer(ui::LayerType layer_type, bool translucent); |
161 | 176 |
162 // Updates |associated_views_| on NativeViewHost::Attach()/Detach(). | 177 // Updates |associated_views_| on NativeViewHost::Attach()/Detach(). |
163 void SetAssociationForView(const views::View* view, NSView* native_view); | 178 void SetAssociationForView(const views::View* view, NSView* native_view); |
164 void ClearAssociationForView(const views::View* view); | 179 void ClearAssociationForView(const views::View* view); |
165 // Sorts child NSViews according to NativeViewHosts order in views hierarchy. | 180 // Sorts child NSViews according to NativeViewHosts order in views hierarchy. |
166 void ReorderChildViews(); | 181 void ReorderChildViews(); |
167 | 182 |
168 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } | 183 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } |
(...skipping 11 matching lines...) Expand all Loading... |
180 } | 195 } |
181 | 196 |
182 bool target_fullscreen_state() const { return target_fullscreen_state_; } | 197 bool target_fullscreen_state() const { return target_fullscreen_state_; } |
183 bool window_visible() { return window_visible_; } | 198 bool window_visible() { return window_visible_; } |
184 | 199 |
185 // Overridden from ui::internal::InputMethodDelegate: | 200 // Overridden from ui::internal::InputMethodDelegate: |
186 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override; | 201 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override; |
187 | 202 |
188 private: | 203 private: |
189 friend class test::BridgedNativeWidgetTestApi; | 204 friend class test::BridgedNativeWidgetTestApi; |
| 205 friend class CocoaWindowMoveLoop; |
190 | 206 |
191 // Closes all child windows. BridgedNativeWidget children will be destroyed. | 207 // Closes all child windows. BridgedNativeWidget children will be destroyed. |
192 void RemoveOrDestroyChildren(); | 208 void RemoveOrDestroyChildren(); |
193 | 209 |
194 // Notify descendants of a visibility change. | 210 // Notify descendants of a visibility change. |
195 void NotifyVisibilityChangeDown(); | 211 void NotifyVisibilityChangeDown(); |
196 | 212 |
197 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no | 213 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no |
198 // coordinate transformations are required from AppKit coordinates. | 214 // coordinate transformations are required from AppKit coordinates. |
199 gfx::Size GetClientAreaSize() const; | 215 gfx::Size GetClientAreaSize() const; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 gfx::Vector2d GetChildWindowOffset() const override; | 271 gfx::Vector2d GetChildWindowOffset() const override; |
256 bool IsVisibleParent() const override; | 272 bool IsVisibleParent() const override; |
257 void RemoveChildWindow(BridgedNativeWidget* child) override; | 273 void RemoveChildWindow(BridgedNativeWidget* child) override; |
258 | 274 |
259 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. | 275 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. |
260 base::scoped_nsobject<NSWindow> window_; | 276 base::scoped_nsobject<NSWindow> window_; |
261 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; | 277 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; |
262 base::scoped_nsobject<BridgedContentView> bridged_view_; | 278 base::scoped_nsobject<BridgedContentView> bridged_view_; |
263 std::unique_ptr<ui::InputMethod> input_method_; | 279 std::unique_ptr<ui::InputMethod> input_method_; |
264 std::unique_ptr<CocoaMouseCapture> mouse_capture_; | 280 std::unique_ptr<CocoaMouseCapture> mouse_capture_; |
| 281 std::unique_ptr<CocoaWindowMoveLoop> window_move_loop_; |
265 std::unique_ptr<TooltipManager> tooltip_manager_; | 282 std::unique_ptr<TooltipManager> tooltip_manager_; |
266 FocusManager* focus_manager_; // Weak. Owned by our Widget. | 283 FocusManager* focus_manager_; // Weak. Owned by our Widget. |
267 Widget::InitParams::Type widget_type_; | 284 Widget::InitParams::Type widget_type_; |
268 | 285 |
269 BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. | 286 BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. |
270 std::vector<BridgedNativeWidget*> child_windows_; | 287 std::vector<BridgedNativeWidget*> child_windows_; |
271 | 288 |
272 base::scoped_nsobject<NSView> compositor_superview_; | 289 base::scoped_nsobject<NSView> compositor_superview_; |
273 std::unique_ptr<ui::AcceleratedWidgetMac> compositor_widget_; | 290 std::unique_ptr<ui::AcceleratedWidgetMac> compositor_widget_; |
274 std::unique_ptr<ui::Compositor> compositor_; | 291 std::unique_ptr<ui::Compositor> compositor_; |
275 | 292 |
276 // Tracks the bounds when the window last started entering fullscreen. Used to | 293 // Tracks the bounds when the window last started entering fullscreen. Used to |
277 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it | 294 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it |
278 // has its own copy, but doesn't provide access to it). | 295 // has its own copy, but doesn't provide access to it). |
279 gfx::Rect bounds_before_fullscreen_; | 296 gfx::Rect bounds_before_fullscreen_; |
280 | 297 |
| 298 base::RunLoop* drag_run_loop_ = nullptr; |
| 299 |
281 // Whether this window wants to be fullscreen. If a fullscreen animation is in | 300 // Whether this window wants to be fullscreen. If a fullscreen animation is in |
282 // progress then it might not be actually fullscreen. | 301 // progress then it might not be actually fullscreen. |
283 bool target_fullscreen_state_; | 302 bool target_fullscreen_state_; |
284 | 303 |
285 // Whether this window is in a fullscreen transition, and the fullscreen state | 304 // Whether this window is in a fullscreen transition, and the fullscreen state |
286 // can not currently be changed. | 305 // can not currently be changed. |
287 bool in_fullscreen_transition_; | 306 bool in_fullscreen_transition_; |
288 | 307 |
289 // Stores the value last read from -[NSWindow isVisible], to detect visibility | 308 // Stores the value last read from -[NSWindow isVisible], to detect visibility |
290 // changes. | 309 // changes. |
291 bool window_visible_; | 310 bool window_visible_; |
292 | 311 |
293 // If true, the window is either visible, or wants to be visible but is | 312 // If true, the window is either visible, or wants to be visible but is |
294 // currently hidden due to having a hidden parent. | 313 // currently hidden due to having a hidden parent. |
295 bool wants_to_be_visible_; | 314 bool wants_to_be_visible_; |
296 | 315 |
297 // If true, the window has been made visible or changed shape and the window | 316 // If true, the window has been made visible or changed shape and the window |
298 // shadow needs to be invalidated when a frame is received for the new shape. | 317 // shadow needs to be invalidated when a frame is received for the new shape. |
299 bool invalidate_shadow_on_frame_swap_ = false; | 318 bool invalidate_shadow_on_frame_swap_ = false; |
300 | 319 |
301 AssociatedViews associated_views_; | 320 AssociatedViews associated_views_; |
302 | 321 |
303 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); | 322 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); |
304 }; | 323 }; |
305 | 324 |
306 } // namespace views | 325 } // namespace views |
307 | 326 |
308 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ | 327 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ |
OLD | NEW |