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 NativeViewHostAuraTest
;
16 class NativeViewHostWrapper
;
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
[];
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
{
28 // The NativeViewHost's class name.
29 static const char kViewClassName
[];
32 virtual ~NativeViewHost();
34 // Attach a gfx::NativeView to this View. Its bounds will be kept in sync
35 // with the bounds of this View until Detach is called.
37 // Because native views are positioned in the coordinates of their parent
38 // native view, this function should only be called after this View has been
39 // added to a View hierarchy hosted within a valid Widget.
40 void Attach(gfx::NativeView native_view
);
42 // Detach the attached native view. Its bounds and visibility will no
43 // longer be manipulated by this View. The native view may be destroyed and
44 // detached before calling this function, and this has no effect in that case.
47 // Sets a preferred size for the native view attached to this View.
48 void SetPreferredSize(const gfx::Size
& size
);
50 // A NativeViewHost has an associated focus View so that the focus of the
51 // native control and of the View are kept in sync. In simple cases where the
52 // NativeViewHost directly wraps a native window as is, the associated view
53 // is this View. In other cases where the NativeViewHost is part of another
54 // view (such as TextField), the actual View is not the NativeViewHost and
55 // this method must be called to set that.
56 // This method must be called before Attach().
57 void set_focus_view(View
* view
) { focus_view_
= view
; }
58 View
* focus_view() { return focus_view_
; }
60 // Fast resizing will move the native view and clip its visible region, this
61 // will result in white areas and will not resize the content (so scrollbars
62 // will be all wrong and content will flow offscreen). Only use this
63 // when you're doing extremely quick, high-framerate vertical resizes
64 // and don't care about accuracy. Make sure you do a real resize at the
65 // end. USE WITH CAUTION.
66 void set_fast_resize(bool fast_resize
) { fast_resize_
= fast_resize
; }
67 bool fast_resize() const { return fast_resize_
; }
69 // Value of fast_resize() the last time Layout() was invoked.
70 bool fast_resize_at_last_layout() const {
71 return fast_resize_at_last_layout_
;
74 // Accessor for |native_view_|.
75 gfx::NativeView
native_view() const { return native_view_
; }
77 void NativeViewDestroyed();
79 // Overridden from View:
80 virtual gfx::Size
GetPreferredSize() const OVERRIDE
;
81 virtual void Layout() OVERRIDE
;
82 virtual void OnPaint(gfx::Canvas
* canvas
) OVERRIDE
;
83 virtual void VisibilityChanged(View
* starting_from
, bool is_visible
) OVERRIDE
;
84 virtual void OnFocus() OVERRIDE
;
85 virtual gfx::NativeViewAccessible
GetNativeViewAccessible() OVERRIDE
;
86 virtual gfx::NativeCursor
GetCursor(const ui::MouseEvent
& event
) OVERRIDE
;
89 virtual bool NeedsNotificationWhenVisibleBoundsChange() const OVERRIDE
;
90 virtual void OnVisibleBoundsChanged() OVERRIDE
;
91 virtual void ViewHierarchyChanged(
92 const ViewHierarchyChangedDetails
& details
) OVERRIDE
;
93 virtual const char* GetClassName() const OVERRIDE
;
96 friend class NativeViewHostAuraTest
;
98 // Detach the native view. |destroyed| is true if the native view is
99 // detached because it's being destroyed, or false otherwise.
100 void Detach(bool destroyed
);
102 // Invokes ViewRemoved() on the FocusManager for all the child Widgets of our
103 // NativeView. This is used when detaching to ensure the FocusManager doesn't
104 // have a reference to a View that is no longer reachable.
107 // The attached native view. There is exactly one native_view_ attached.
108 gfx::NativeView native_view_
;
110 // A platform-specific wrapper that does the OS-level manipulation of the
111 // attached gfx::NativeView.
112 scoped_ptr
<NativeViewHostWrapper
> native_wrapper_
;
114 // The preferred size of this View
115 gfx::Size preferred_size_
;
117 // True if the native view is being resized using the fast method described
118 // in the setter/accessor above.
121 // Value of |fast_resize_| during the last call to Layout.
122 bool fast_resize_at_last_layout_
;
124 // The view that should be given focus when this NativeViewHost is focused.
127 DISALLOW_COPY_AND_ASSIGN(NativeViewHost
);
132 #endif // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_