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 // Sets the color to paint the background during a resize that involves a
62 // clip. This is white by default.
63 void set_resize_background_color(SkColor resize_background_color
) {
64 resize_background_color_
= resize_background_color
;
67 // Value of fast_resize() the last time Layout() was invoked.
68 bool fast_resize_at_last_layout() const {
69 return fast_resize_at_last_layout_
;
72 // Accessor for |native_view_|.
73 gfx::NativeView
native_view() const { return native_view_
; }
75 void NativeViewDestroyed();
77 // Overridden from View:
78 gfx::Size
GetPreferredSize() const override
;
79 void Layout() override
;
80 void OnPaint(gfx::Canvas
* canvas
) override
;
81 void VisibilityChanged(View
* starting_from
, bool is_visible
) override
;
82 void OnFocus() override
;
83 gfx::NativeViewAccessible
GetNativeViewAccessible() override
;
84 gfx::NativeCursor
GetCursor(const ui::MouseEvent
& event
) override
;
87 bool GetNeedsNotificationWhenVisibleBoundsChange() const override
;
88 void OnVisibleBoundsChanged() override
;
89 void ViewHierarchyChanged(
90 const ViewHierarchyChangedDetails
& details
) override
;
91 const char* GetClassName() const override
;
94 friend class test::NativeViewHostTestBase
;
96 // Detach the native view. |destroyed| is true if the native view is
97 // detached because it's being destroyed, or false otherwise.
98 void Detach(bool destroyed
);
100 // Invokes ViewRemoved() on the FocusManager for all the child Widgets of our
101 // NativeView. This is used when detaching to ensure the FocusManager doesn't
102 // have a reference to a View that is no longer reachable.
105 // The attached native view. There is exactly one native_view_ attached.
106 gfx::NativeView native_view_
;
108 // A platform-specific wrapper that does the OS-level manipulation of the
109 // attached gfx::NativeView.
110 scoped_ptr
<NativeViewHostWrapper
> native_wrapper_
;
112 // The preferred size of this View
113 gfx::Size preferred_size_
;
115 // True if the native view is being resized using the fast method described
116 // in the setter/accessor above.
119 // Value of |fast_resize_| during the last call to Layout.
120 bool fast_resize_at_last_layout_
;
122 // Color to paint in the background while resizing.
123 SkColor resize_background_color_
;
125 DISALLOW_COPY_AND_ASSIGN(NativeViewHost
);
130 #endif // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_