Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: ui/views/cocoa/bridged_native_widget.h

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract CocoaWindowMoveLoop, fix review issues. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <vector> 10 #include <vector>
11 11
12 #import "base/mac/scoped_nsobject.h" 12 #import "base/mac/scoped_nsobject.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 // Sets the desired visibility of the window and updates the visibility of 91 // Sets the desired visibility of the window and updates the visibility of
90 // descendant windows where necessary. 92 // descendant windows where necessary.
91 void SetVisibilityState(WindowVisibilityState new_state); 93 void SetVisibilityState(WindowVisibilityState new_state);
92 94
93 // Acquiring mouse capture first steals capture from any existing 95 // Acquiring mouse capture first steals capture from any existing
94 // CocoaMouseCaptureDelegate, then captures all mouse events until released. 96 // CocoaMouseCaptureDelegate, then captures all mouse events until released.
95 void AcquireCapture(); 97 void AcquireCapture();
96 void ReleaseCapture(); 98 void ReleaseCapture();
97 bool HasCapture(); 99 bool HasCapture();
98 100
101 // Start moving the window, pinned to the mouse cursor, and monitor events.
102 // Return MOVE_LOOP_SUCCESSFUL on mouse up or MOVE_LOOP_CANCELED on escape.
103 Widget::MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset);
104 void EndMoveLoop();
105 bool IsRunMoveLoopActive() const;
106
99 // See views::Widget. 107 // See views::Widget.
100 void SetNativeWindowProperty(const char* key, void* value); 108 void SetNativeWindowProperty(const char* key, void* value);
101 void* GetNativeWindowProperty(const char* key) const; 109 void* GetNativeWindowProperty(const char* key) const;
102 110
103 // Sets the cursor associated with the NSWindow. Retains |cursor|. 111 // Sets the cursor associated with the NSWindow. Retains |cursor|.
104 void SetCursor(NSCursor* cursor); 112 void SetCursor(NSCursor* cursor);
105 113
106 // Called internally by the NSWindowDelegate when the window is closing. 114 // Called internally by the NSWindowDelegate when the window is closing.
107 void OnWindowWillClose(); 115 void OnWindowWillClose();
108 116
109 // Called by the NSWindowDelegate when a fullscreen operation begins. If 117 // Called by the NSWindowDelegate when a fullscreen operation begins. If
110 // |target_fullscreen_state| is true, the target state is fullscreen. 118 // |target_fullscreen_state| is true, the target state is fullscreen.
111 // Otherwise, a transition has begun to come out of fullscreen. 119 // Otherwise, a transition has begun to come out of fullscreen.
112 void OnFullscreenTransitionStart(bool target_fullscreen_state); 120 void OnFullscreenTransitionStart(bool target_fullscreen_state);
113 121
114 // Called when a fullscreen transition completes. If target_fullscreen_state() 122 // Called when a fullscreen transition completes. If target_fullscreen_state()
115 // does not match |actual_fullscreen_state|, a new transition will begin. 123 // does not match |actual_fullscreen_state|, a new transition will begin.
116 void OnFullscreenTransitionComplete(bool actual_fullscreen_state); 124 void OnFullscreenTransitionComplete(bool actual_fullscreen_state);
117 125
118 // Transition the window into or out of fullscreen. This will immediately 126 // Transition the window into or out of fullscreen. This will immediately
119 // invert the value of target_fullscreen_state(). 127 // invert the value of target_fullscreen_state().
120 void ToggleDesiredFullscreenState(); 128 void ToggleDesiredFullscreenState();
121 129
122 // Called by the NSWindowDelegate when the size of the window changes. 130 // Called by the NSWindowDelegate when the size of the window changes.
123 void OnSizeChanged(); 131 void OnSizeChanged();
124 132
133 // Called once by the NSWindowDelegate when the position of the window has
134 // changed. Called for each mouse event during RunMoveLoop().
135 void OnPositionChanged();
136
125 // Called by the NSWindowDelegate when the visibility of the window may have 137 // Called by the NSWindowDelegate when the visibility of the window may have
126 // changed. For example, due to a (de)miniaturize operation, or the window 138 // changed. For example, due to a (de)miniaturize operation, or the window
127 // being reordered in (or out of) the screen list. 139 // being reordered in (or out of) the screen list.
128 void OnVisibilityChanged(); 140 void OnVisibilityChanged();
129 141
130 // Explicitly set the visibility. This is called when Cocoa requests a draw, 142 // Explicitly set the visibility. This is called when Cocoa requests a draw,
131 // but hasn't updated the value of -[NSWindow isVisible] yet. 143 // but hasn't updated the value of -[NSWindow isVisible] yet.
132 void OnVisibilityChangedTo(bool new_visibility); 144 void OnVisibilityChangedTo(bool new_visibility);
133 145
134 // Called by the NSWindowDelegate on a scale factor or color space change. 146 // Called by the NSWindowDelegate on a scale factor or color space change.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 const std::vector<BridgedNativeWidget*>& child_windows() { 181 const std::vector<BridgedNativeWidget*>& child_windows() {
170 return child_windows_; 182 return child_windows_;
171 } 183 }
172 184
173 bool target_fullscreen_state() const { return target_fullscreen_state_; } 185 bool target_fullscreen_state() const { return target_fullscreen_state_; }
174 bool window_visible() { return window_visible_; } 186 bool window_visible() { return window_visible_; }
175 187
176 // Overridden from ui::internal::InputMethodDelegate: 188 // Overridden from ui::internal::InputMethodDelegate:
177 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override; 189 ui::EventDispatchDetails DispatchKeyEventPostIME(ui::KeyEvent* key) override;
178 190
191 static void IgnoreNextMouseDownForDraggableRegions();
192
179 private: 193 private:
180 friend class test::BridgedNativeWidgetTestApi; 194 friend class test::BridgedNativeWidgetTestApi;
195 friend class CocoaWindowMoveLoop;
181 196
182 // Closes all child windows. BridgedNativeWidget children will be destroyed. 197 // Closes all child windows. BridgedNativeWidget children will be destroyed.
183 void RemoveOrDestroyChildren(); 198 void RemoveOrDestroyChildren();
184 199
185 // Notify descendants of a visibility change. 200 // Notify descendants of a visibility change.
186 void NotifyVisibilityChangeDown(); 201 void NotifyVisibilityChangeDown();
187 202
188 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no 203 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no
189 // coordinate transformations are required from AppKit coordinates. 204 // coordinate transformations are required from AppKit coordinates.
190 gfx::Size GetClientAreaSize() const; 205 gfx::Size GetClientAreaSize() const;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 gfx::Vector2d GetChildWindowOffset() const override; 261 gfx::Vector2d GetChildWindowOffset() const override;
247 bool IsVisibleParent() const override; 262 bool IsVisibleParent() const override;
248 void RemoveChildWindow(BridgedNativeWidget* child) override; 263 void RemoveChildWindow(BridgedNativeWidget* child) override;
249 264
250 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. 265 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this.
251 base::scoped_nsobject<NSWindow> window_; 266 base::scoped_nsobject<NSWindow> window_;
252 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; 267 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_;
253 base::scoped_nsobject<BridgedContentView> bridged_view_; 268 base::scoped_nsobject<BridgedContentView> bridged_view_;
254 scoped_ptr<ui::InputMethod> input_method_; 269 scoped_ptr<ui::InputMethod> input_method_;
255 scoped_ptr<CocoaMouseCapture> mouse_capture_; 270 scoped_ptr<CocoaMouseCapture> mouse_capture_;
271 scoped_ptr<CocoaWindowMoveLoop> window_move_loop_;
256 scoped_ptr<TooltipManager> tooltip_manager_; 272 scoped_ptr<TooltipManager> tooltip_manager_;
257 FocusManager* focus_manager_; // Weak. Owned by our Widget. 273 FocusManager* focus_manager_; // Weak. Owned by our Widget.
258 Widget::InitParams::Type widget_type_; 274 Widget::InitParams::Type widget_type_;
259 275
260 BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. 276 BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this.
261 std::vector<BridgedNativeWidget*> child_windows_; 277 std::vector<BridgedNativeWidget*> child_windows_;
262 278
263 base::scoped_nsobject<NSView> compositor_superview_; 279 base::scoped_nsobject<NSView> compositor_superview_;
264 scoped_ptr<ui::AcceleratedWidgetMac> compositor_widget_; 280 scoped_ptr<ui::AcceleratedWidgetMac> compositor_widget_;
265 scoped_ptr<ui::Compositor> compositor_; 281 scoped_ptr<ui::Compositor> compositor_;
266 282
267 // Tracks the bounds when the window last started entering fullscreen. Used to 283 // Tracks the bounds when the window last started entering fullscreen. Used to
268 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it 284 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it
269 // has its own copy, but doesn't provide access to it). 285 // has its own copy, but doesn't provide access to it).
270 gfx::Rect bounds_before_fullscreen_; 286 gfx::Rect bounds_before_fullscreen_;
271 287
288 base::RunLoop* drag_run_loop_ = nullptr;
289
272 // Whether this window wants to be fullscreen. If a fullscreen animation is in 290 // Whether this window wants to be fullscreen. If a fullscreen animation is in
273 // progress then it might not be actually fullscreen. 291 // progress then it might not be actually fullscreen.
274 bool target_fullscreen_state_; 292 bool target_fullscreen_state_;
275 293
276 // Whether this window is in a fullscreen transition, and the fullscreen state 294 // Whether this window is in a fullscreen transition, and the fullscreen state
277 // can not currently be changed. 295 // can not currently be changed.
278 bool in_fullscreen_transition_; 296 bool in_fullscreen_transition_;
279 297
280 // Stores the value last read from -[NSWindow isVisible], to detect visibility 298 // Stores the value last read from -[NSWindow isVisible], to detect visibility
281 // changes. 299 // changes.
282 bool window_visible_; 300 bool window_visible_;
283 301
284 // If true, the window is either visible, or wants to be visible but is 302 // If true, the window is either visible, or wants to be visible but is
285 // currently hidden due to having a hidden parent. 303 // currently hidden due to having a hidden parent.
286 bool wants_to_be_visible_; 304 bool wants_to_be_visible_;
287 305
288 // If true, the window has been made visible or changed shape and the window 306 // If true, the window has been made visible or changed shape and the window
289 // shadow needs to be invalidated when a frame is received for the new shape. 307 // shadow needs to be invalidated when a frame is received for the new shape.
290 bool invalidate_shadow_on_frame_swap_ = false; 308 bool invalidate_shadow_on_frame_swap_ = false;
291 309
292 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); 310 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget);
293 }; 311 };
294 312
295 } // namespace views 313 } // namespace views
296 314
297 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ 315 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698