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 |
11 #import "base/mac/scoped_nsobject.h" | 11 #import "base/mac/scoped_nsobject.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "ui/compositor/layer_owner.h" | 13 #include "ui/compositor/layer_owner.h" |
14 #import "ui/accelerated_widget_mac/accelerated_widget_mac.h" | 14 #import "ui/accelerated_widget_mac/accelerated_widget_mac.h" |
| 15 #import "ui/views/cocoa/bridged_native_widget_owner.h" |
15 #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" | 16 #import "ui/views/cocoa/cocoa_mouse_capture_delegate.h" |
16 #import "ui/views/focus/focus_manager.h" | 17 #import "ui/views/focus/focus_manager.h" |
17 #include "ui/views/ime/input_method_delegate.h" | 18 #include "ui/views/ime/input_method_delegate.h" |
18 #include "ui/views/views_export.h" | 19 #include "ui/views/views_export.h" |
19 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
20 | 21 |
21 @class BridgedContentView; | 22 @class BridgedContentView; |
22 @class ViewsNSWindowDelegate; | 23 @class ViewsNSWindowDelegate; |
23 | 24 |
24 namespace ui { | 25 namespace ui { |
25 class InputMethod; | 26 class InputMethod; |
26 } | 27 } |
27 | 28 |
28 namespace views { | 29 namespace views { |
29 | 30 |
30 class CocoaMouseCapture; | 31 class CocoaMouseCapture; |
31 class InputMethod; | 32 class InputMethod; |
32 class NativeWidgetMac; | 33 class NativeWidgetMac; |
33 class View; | 34 class View; |
34 | 35 |
35 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or | 36 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or |
36 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the | 37 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the |
37 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. | 38 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. |
38 class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate, | 39 class VIEWS_EXPORT BridgedNativeWidget : public ui::LayerDelegate, |
39 public ui::LayerOwner, | 40 public ui::LayerOwner, |
40 public internal::InputMethodDelegate, | 41 public internal::InputMethodDelegate, |
41 public CocoaMouseCaptureDelegate, | 42 public CocoaMouseCaptureDelegate, |
42 public FocusChangeListener, | 43 public FocusChangeListener, |
43 public ui::AcceleratedWidgetMacNSView { | 44 public ui::AcceleratedWidgetMacNSView, |
| 45 public BridgedNativeWidgetOwner { |
44 public: | 46 public: |
45 // Ways of changing the visibility of the bridged NSWindow. | 47 // Ways of changing the visibility of the bridged NSWindow. |
46 enum WindowVisibilityState { | 48 enum WindowVisibilityState { |
47 HIDE_WINDOW, // Hides with -[NSWindow orderOut:]. | 49 HIDE_WINDOW, // Hides with -[NSWindow orderOut:]. |
48 SHOW_AND_ACTIVATE_WINDOW, // Shows with -[NSWindow makeKeyAndOrderFront:]. | 50 SHOW_AND_ACTIVATE_WINDOW, // Shows with -[NSWindow makeKeyAndOrderFront:]. |
49 SHOW_INACTIVE, // Shows with -[NSWindow orderWindow:..]. Orders | 51 SHOW_INACTIVE, // Shows with -[NSWindow orderWindow:..]. Orders |
50 // the window above its parent if it has one. | 52 // the window above its parent if it has one. |
51 }; | 53 }; |
52 | 54 |
53 // Return the size that |window| will take for the given client area |size|, | 55 // Return the size that |window| will take for the given client area |size|, |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Creates a ui::Compositor which becomes responsible for drawing the window. | 146 // Creates a ui::Compositor which becomes responsible for drawing the window. |
145 void CreateLayer(ui::LayerType layer_type, bool translucent); | 147 void CreateLayer(ui::LayerType layer_type, bool translucent); |
146 | 148 |
147 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } | 149 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } |
148 BridgedContentView* ns_view() { return bridged_view_; } | 150 BridgedContentView* ns_view() { return bridged_view_; } |
149 NSWindow* ns_window() { return window_; } | 151 NSWindow* ns_window() { return window_; } |
150 | 152 |
151 // The parent widget specified in Widget::InitParams::parent. If non-null, the | 153 // The parent widget specified in Widget::InitParams::parent. If non-null, the |
152 // parent will close children before the parent closes, and children will be | 154 // parent will close children before the parent closes, and children will be |
153 // raised above their parent when window z-order changes. | 155 // raised above their parent when window z-order changes. |
154 BridgedNativeWidget* parent() { return parent_; } | 156 BridgedNativeWidgetOwner* parent() { return parent_; } |
155 const std::vector<BridgedNativeWidget*>& child_windows() { | 157 const std::vector<BridgedNativeWidget*>& child_windows() { |
156 return child_windows_; | 158 return child_windows_; |
157 } | 159 } |
158 | 160 |
159 bool target_fullscreen_state() const { return target_fullscreen_state_; } | 161 bool target_fullscreen_state() const { return target_fullscreen_state_; } |
160 bool window_visible() { return window_visible_; } | 162 bool window_visible() { return window_visible_; } |
161 | 163 |
162 // Overridden from internal::InputMethodDelegate: | 164 // Overridden from internal::InputMethodDelegate: |
163 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; | 165 void DispatchKeyEventPostIME(const ui::KeyEvent& key) override; |
164 | 166 |
165 private: | 167 private: |
166 // Closes all child windows. BridgedNativeWidget children will be destroyed. | 168 // Closes all child windows. BridgedNativeWidget children will be destroyed. |
167 void RemoveOrDestroyChildren(); | 169 void RemoveOrDestroyChildren(); |
168 | 170 |
169 // Remove the given |child| from |child_windows_|. | |
170 void RemoveChildWindow(BridgedNativeWidget* child); | |
171 | |
172 // Notify descendants of a visibility change. | 171 // Notify descendants of a visibility change. |
173 void NotifyVisibilityChangeDown(); | 172 void NotifyVisibilityChangeDown(); |
174 | 173 |
175 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no | 174 // Essentially NativeWidgetMac::GetClientAreaBoundsInScreen().size(), but no |
176 // coordinate transformations are required from AppKit coordinates. | 175 // coordinate transformations are required from AppKit coordinates. |
177 gfx::Size GetClientAreaSize() const; | 176 gfx::Size GetClientAreaSize() const; |
178 | 177 |
179 // Creates an owned ui::Compositor. For consistency, these functions reflect | 178 // Creates an owned ui::Compositor. For consistency, these functions reflect |
180 // those in aura::WindowTreeHost. | 179 // those in aura::WindowTreeHost. |
181 void CreateCompositor(); | 180 void CreateCompositor(); |
(...skipping 28 matching lines...) Expand all Loading... |
210 void OnDeviceScaleFactorChanged(float device_scale_factor) override; | 209 void OnDeviceScaleFactorChanged(float device_scale_factor) override; |
211 base::Closure PrepareForLayerBoundsChange() override; | 210 base::Closure PrepareForLayerBoundsChange() override; |
212 | 211 |
213 // Overridden from ui::AcceleratedWidgetMac: | 212 // Overridden from ui::AcceleratedWidgetMac: |
214 NSView* AcceleratedWidgetGetNSView() const override; | 213 NSView* AcceleratedWidgetGetNSView() const override; |
215 bool AcceleratedWidgetShouldIgnoreBackpressure() const override; | 214 bool AcceleratedWidgetShouldIgnoreBackpressure() const override; |
216 void AcceleratedWidgetSwapCompleted( | 215 void AcceleratedWidgetSwapCompleted( |
217 const std::vector<ui::LatencyInfo>& latency_info) override; | 216 const std::vector<ui::LatencyInfo>& latency_info) override; |
218 void AcceleratedWidgetHitError() override; | 217 void AcceleratedWidgetHitError() override; |
219 | 218 |
| 219 // Overridden from BridgedNativeWidgetOwner: |
| 220 NSWindow* GetNSWindow() override; |
| 221 gfx::Vector2d ChildWindowOffset() override; |
| 222 bool IsVisibleParent() override; |
| 223 void RemoveChildWindow(BridgedNativeWidget* child) override; |
| 224 |
220 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. | 225 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. |
221 base::scoped_nsobject<NSWindow> window_; | 226 base::scoped_nsobject<NSWindow> window_; |
222 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; | 227 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; |
223 base::scoped_nsobject<BridgedContentView> bridged_view_; | 228 base::scoped_nsobject<BridgedContentView> bridged_view_; |
224 scoped_ptr<ui::InputMethod> input_method_; | 229 scoped_ptr<ui::InputMethod> input_method_; |
225 scoped_ptr<CocoaMouseCapture> mouse_capture_; | 230 scoped_ptr<CocoaMouseCapture> mouse_capture_; |
226 FocusManager* focus_manager_; // Weak. Owned by our Widget. | 231 FocusManager* focus_manager_; // Weak. Owned by our Widget. |
227 Widget::InitParams::Type widget_type_; | 232 Widget::InitParams::Type widget_type_; |
228 | 233 |
229 BridgedNativeWidget* parent_; // Weak. If non-null, owns this. | 234 BridgedNativeWidgetOwner* parent_; // Weak. If non-null, owns this. |
230 std::vector<BridgedNativeWidget*> child_windows_; | 235 std::vector<BridgedNativeWidget*> child_windows_; |
231 | 236 |
232 base::scoped_nsobject<NSView> compositor_superview_; | 237 base::scoped_nsobject<NSView> compositor_superview_; |
233 scoped_ptr<ui::AcceleratedWidgetMac> compositor_widget_; | 238 scoped_ptr<ui::AcceleratedWidgetMac> compositor_widget_; |
234 scoped_ptr<ui::Compositor> compositor_; | 239 scoped_ptr<ui::Compositor> compositor_; |
235 | 240 |
236 // Tracks the bounds when the window last started entering fullscreen. Used to | 241 // Tracks the bounds when the window last started entering fullscreen. Used to |
237 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it | 242 // provide an answer for GetRestoredBounds(), but not ever sent to Cocoa (it |
238 // has its own copy, but doesn't provide access to it). | 243 // has its own copy, but doesn't provide access to it). |
239 gfx::Rect bounds_before_fullscreen_; | 244 gfx::Rect bounds_before_fullscreen_; |
(...skipping 13 matching lines...) Expand all Loading... |
253 // If true, the window is either visible, or wants to be visible but is | 258 // If true, the window is either visible, or wants to be visible but is |
254 // currently hidden due to having a hidden parent. | 259 // currently hidden due to having a hidden parent. |
255 bool wants_to_be_visible_; | 260 bool wants_to_be_visible_; |
256 | 261 |
257 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); | 262 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); |
258 }; | 263 }; |
259 | 264 |
260 } // namespace views | 265 } // namespace views |
261 | 266 |
262 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ | 267 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ |
OLD | NEW |