- add sources.
[platform/framework/web/crosswalk.git] / src / ui / views / controls / native / native_view_host.h
1 // Copyright (c) 2011 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_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_
6 #define UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_
7
8 #include <string>
9
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/view.h"
12
13 namespace views {
14
15 class NativeViewHostAuraTest;
16 class NativeViewHostWrapper;
17
18 // If a NativeViewHost's native view is a Widget, this native window
19 // property is set on the widget, pointing to the owning NativeViewHost.
20 extern const char kWidgetNativeViewHostKey[];
21
22 // A View type that hosts a gfx::NativeView. The bounds of the native view are
23 // kept in sync with the bounds of this view as it is moved and sized.
24 // Under the hood, a platform-specific NativeViewHostWrapper implementation does
25 // the platform-specific work of manipulating the underlying OS widget type.
26 class VIEWS_EXPORT NativeViewHost : public View {
27  public:
28   // The NativeViewHost's class name.
29   static const char kViewClassName[];
30
31   // Should views render the focus when on native controls?
32   static const bool kRenderNativeControlFocus;
33
34   NativeViewHost();
35   virtual ~NativeViewHost();
36
37   // Attach a gfx::NativeView to this View. Its bounds will be kept in sync
38   // with the bounds of this View until Detach is called.
39   //
40   // Because native views are positioned in the coordinates of their parent
41   // native view, this function should only be called after this View has been
42   // added to a View hierarchy hosted within a valid Widget.
43   void Attach(gfx::NativeView native_view);
44
45   // Detach the attached native view. Its bounds and visibility will no
46   // longer be manipulated by this View. The native view may be destroyed and
47   // detached before calling this function, and this has no effect in that case.
48   void Detach();
49
50   // Sets a preferred size for the native view attached to this View.
51   void SetPreferredSize(const gfx::Size& size);
52
53   // A NativeViewHost has an associated focus View so that the focus of the
54   // native control and of the View are kept in sync. In simple cases where the
55   // NativeViewHost directly wraps a native window as is, the associated view
56   // is this View. In other cases where the NativeViewHost is part of another
57   // view (such as TextField), the actual View is not the NativeViewHost and
58   // this method must be called to set that.
59   // This method must be called before Attach().
60   void set_focus_view(View* view) { focus_view_ = view; }
61   View* focus_view() { return focus_view_; }
62
63   // Fast resizing will move the native view and clip its visible region, this
64   // will result in white areas and will not resize the content (so scrollbars
65   // will be all wrong and content will flow offscreen). Only use this
66   // when you're doing extremely quick, high-framerate vertical resizes
67   // and don't care about accuracy. Make sure you do a real resize at the
68   // end. USE WITH CAUTION.
69   void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; }
70   bool fast_resize() const { return fast_resize_; }
71
72   // Value of fast_resize() the last time Layout() was invoked.
73   bool fast_resize_at_last_layout() const {
74     return fast_resize_at_last_layout_;
75   }
76
77   // Accessor for |native_view_|.
78   gfx::NativeView native_view() const { return native_view_; }
79
80   void NativeViewDestroyed();
81
82   // Overridden from View:
83   virtual gfx::Size GetPreferredSize() OVERRIDE;
84   virtual void Layout() OVERRIDE;
85   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
86   virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE;
87   virtual void OnFocus() OVERRIDE;
88   virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
89
90  protected:
91   virtual bool NeedsNotificationWhenVisibleBoundsChange() const OVERRIDE;
92   virtual void OnVisibleBoundsChanged() OVERRIDE;
93   virtual void ViewHierarchyChanged(
94       const ViewHierarchyChangedDetails& details) OVERRIDE;
95   virtual const char* GetClassName() const OVERRIDE;
96
97  private:
98   friend class NativeViewHostAuraTest;
99
100   // Detach the native view. |destroyed| is true if the native view is
101   // detached because it's being destroyed, or false otherwise.
102   void Detach(bool destroyed);
103
104   // Invokes ViewRemoved() on the FocusManager for all the child Widgets of our
105   // NativeView. This is used when detaching to ensure the FocusManager doesn't
106   // have a reference to a View that is no longer reachable.
107   void ClearFocus();
108
109   // The attached native view. There is exactly one native_view_ attached.
110   gfx::NativeView native_view_;
111
112   // A platform-specific wrapper that does the OS-level manipulation of the
113   // attached gfx::NativeView.
114   scoped_ptr<NativeViewHostWrapper> native_wrapper_;
115
116   // The preferred size of this View
117   gfx::Size preferred_size_;
118
119   // True if the native view is being resized using the fast method described
120   // in the setter/accessor above.
121   bool fast_resize_;
122
123   // Value of |fast_resize_| during the last call to Layout.
124   bool fast_resize_at_last_layout_;
125
126   // The view that should be given focus when this NativeViewHost is focused.
127   View* focus_view_;
128
129   DISALLOW_COPY_AND_ASSIGN(NativeViewHost);
130 };
131
132 }  // namespace views
133
134 #endif  // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_