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.
5 #ifndef UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_
6 #define UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/views/view.h"
15 class NativeViewHostTestBase;
18 class NativeViewHostWrapper;
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[];
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 {
30 // The NativeViewHost's class name.
31 static const char kViewClassName[];
34 ~NativeViewHost() override;
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.
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);
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.
49 // Sets a preferred size for the native view attached to this View.
50 void SetPreferredSize(const gfx::Size& size);
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_; }
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_;
66 // Accessor for |native_view_|.
67 gfx::NativeView native_view() const { return native_view_; }
69 void NativeViewDestroyed();
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;
81 bool GetNeedsNotificationWhenVisibleBoundsChange() const override;
82 void OnVisibleBoundsChanged() override;
83 void ViewHierarchyChanged(
84 const ViewHierarchyChangedDetails& details) override;
85 const char* GetClassName() const override;
88 friend class test::NativeViewHostTestBase;
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);
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.
99 // The attached native view. There is exactly one native_view_ attached.
100 gfx::NativeView native_view_;
102 // A platform-specific wrapper that does the OS-level manipulation of the
103 // attached gfx::NativeView.
104 scoped_ptr<NativeViewHostWrapper> native_wrapper_;
106 // The preferred size of this View
107 gfx::Size preferred_size_;
109 // True if the native view is being resized using the fast method described
110 // in the setter/accessor above.
113 // Value of |fast_resize_| during the last call to Layout.
114 bool fast_resize_at_last_layout_;
116 DISALLOW_COPY_AND_ASSIGN(NativeViewHost);
121 #endif // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_