• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
6 #define UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
7 
8 #import <Cocoa/Cocoa.h>
9 
10 #import "base/mac/scoped_nsobject.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/views/ime/input_method_delegate.h"
13 #include "ui/views/views_export.h"
14 
15 @class BridgedContentView;
16 
17 namespace ui {
18 class InputMethod;
19 }
20 
21 namespace views {
22 
23 class InputMethod;
24 class View;
25 
26 // A bridge to an NSWindow managed by an instance of NativeWidgetMac or
27 // DesktopNativeWidgetMac. Serves as a helper class to bridge requests from the
28 // NativeWidgetMac to the Cocoa window. Behaves a bit like an aura::Window.
29 class VIEWS_EXPORT BridgedNativeWidget : public internal::InputMethodDelegate {
30 
31  public:
32   BridgedNativeWidget();
33   virtual ~BridgedNativeWidget();
34 
35   // Initialize the bridge, "retains" ownership of |window|.
36   void Init(base::scoped_nsobject<NSWindow> window);
37 
38   // Set or clears the views::View bridged by the content view. This does NOT
39   // take ownership of |view|.
40   void SetRootView(views::View* view);
41 
42   // See widget.h for documentation.
43   InputMethod* CreateInputMethod();
44   ui::InputMethod* GetHostInputMethod();
45 
ns_view()46   BridgedContentView* ns_view() { return bridged_view_; }
ns_window()47   NSWindow* ns_window() { return window_; }
48 
49   // Overridden from internal::InputMethodDelegate:
50   virtual void DispatchKeyEventPostIME(const ui::KeyEvent& key) OVERRIDE;
51 
52  private:
53   base::scoped_nsobject<NSWindow> window_;
54   base::scoped_nsobject<BridgedContentView> bridged_view_;
55   scoped_ptr<ui::InputMethod> input_method_;
56 
57   DISALLOW_COPY_AND_ASSIGN(BridgedNativeWidget);
58 };
59 
60 }  // namespace views
61 
62 #endif  // UI_VIEWS_COCOA_BRIDGED_NATIVE_WIDGET_H_
63