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