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