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 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #import "ui/views/focus/focus_manager.h" |
12 #include "ui/views/ime/input_method_delegate.h" | 13 #include "ui/views/ime/input_method_delegate.h" |
13 #include "ui/views/views_export.h" | 14 #include "ui/views/views_export.h" |
14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
15 | 16 |
16 @class BridgedContentView; | 17 @class BridgedContentView; |
17 @class ViewsNSWindowDelegate; | 18 @class ViewsNSWindowDelegate; |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 class InputMethod; | 21 class InputMethod; |
21 } | 22 } |
22 | 23 |
23 namespace views { | 24 namespace views { |
24 | 25 |
25 class InputMethod; | 26 class InputMethod; |
26 class NativeWidgetMac; | 27 class NativeWidgetMac; |
27 class View; | 28 class View; |
28 | 29 |
29 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or | 30 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or |
30 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the | 31 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the |
31 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. | 32 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window. |
32 class VIEWS_EXPORT BridgedNativeWidget : public internal::InputMethodDelegate { | 33 class VIEWS_EXPORT BridgedNativeWidget : public internal::InputMethodDelegate, |
| 34 public FocusChangeListener { |
33 public: | 35 public: |
34 // Creates one side of the bridge. |parent| must not be NULL. | 36 // Creates one side of the bridge. |parent| must not be NULL. |
35 explicit BridgedNativeWidget(NativeWidgetMac* parent); | 37 explicit BridgedNativeWidget(NativeWidgetMac* parent); |
36 virtual ~BridgedNativeWidget(); | 38 virtual ~BridgedNativeWidget(); |
37 | 39 |
38 // Initialize the bridge, "retains" ownership of |window|. | 40 // Initialize the bridge, "retains" ownership of |window|. |
39 void Init(base::scoped_nsobject<NSWindow> window, | 41 void Init(base::scoped_nsobject<NSWindow> window, |
40 const Widget::InitParams& params); | 42 const Widget::InitParams& params); |
41 | 43 |
| 44 // Sets or clears the focus manager to use for tracking focused views. |
| 45 // This does NOT take ownership of |focus_manager|. |
| 46 void SetFocusManager(FocusManager* focus_manager); |
| 47 |
42 // Set or clears the views::View bridged by the content view. This does NOT | 48 // Set or clears the views::View bridged by the content view. This does NOT |
43 // take ownership of |view|. | 49 // take ownership of |view|. |
44 void SetRootView(views::View* view); | 50 void SetRootView(views::View* view); |
45 | 51 |
46 // Called internally by the NSWindowDelegate when the window is closing. | 52 // Called internally by the NSWindowDelegate when the window is closing. |
47 void OnWindowWillClose(); | 53 void OnWindowWillClose(); |
48 | 54 |
49 // See widget.h for documentation. | 55 // See widget.h for documentation. |
50 InputMethod* CreateInputMethod(); | 56 InputMethod* CreateInputMethod(); |
51 ui::InputMethod* GetHostInputMethod(); | 57 ui::InputMethod* GetHostInputMethod(); |
52 | 58 |
53 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } | 59 NativeWidgetMac* native_widget_mac() { return native_widget_mac_; } |
54 BridgedContentView* ns_view() { return bridged_view_; } | 60 BridgedContentView* ns_view() { return bridged_view_; } |
55 NSWindow* ns_window() { return window_; } | 61 NSWindow* ns_window() { return window_; } |
56 | 62 |
57 // Overridden from internal::InputMethodDelegate: | 63 // Overridden from internal::InputMethodDelegate: |
58 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; | 64 virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE; |
59 | 65 |
60 private: | 66 private: |
61 // Closes all child windows. BridgedNativeWidget children will be destroyed. | 67 // Closes all child windows. BridgedNativeWidget children will be destroyed. |
62 void RemoveOrDestroyChildren(); | 68 void RemoveOrDestroyChildren(); |
63 | 69 |
64 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. | 70 views::NativeWidgetMac* native_widget_mac_; // Weak. Owns this. |
65 base::scoped_nsobject<NSWindow> window_; | 71 base::scoped_nsobject<NSWindow> window_; |
66 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; | 72 base::scoped_nsobject<ViewsNSWindowDelegate> window_delegate_; |
67 base::scoped_nsobject<BridgedContentView> bridged_view_; | 73 base::scoped_nsobject<BridgedContentView> bridged_view_; |
68 scoped_ptr<ui::InputMethod> input_method_; | 74 scoped_ptr<ui::InputMethod> input_method_; |
| 75 FocusManager* focus_manager_; // Weak. Owned by our Widget. |
| 76 |
| 77 // Overridden from FocusChangeListener: |
| 78 virtual void OnWillChangeFocus(View* focused_before, |
| 79 View* focused_now) OVERRIDE; |
| 80 virtual void OnDidChangeFocus(View* focused_before, |
| 81 View* focused_now) OVERRIDE; |
69 | 82 |
70 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); | 83 DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget); |
71 }; | 84 }; |
72 | 85 |
73 } // namespace views | 86 } // namespace views |
74 | 87 |
75 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ | 88 #endif // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_ |
OLD | NEW |