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

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

Powered by Google App Engine
This is Rietveld 408576698