OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ | 5 #ifndef VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ |
6 #define VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ | 6 #define VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "views/view.h" | 10 #include "views/view.h" |
11 | 11 |
12 #include "base/gfx/native_widget_types.h" | 12 #include "base/gfx/native_widget_types.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 // Base class for embedding native widgets in a view. | 16 class NativeViewHostWrapper; |
| 17 |
| 18 // A View type that hosts a gfx::NativeView. The bounds of the native view are |
| 19 // kept in sync with the bounds of this view as it is moved and sized. |
| 20 // Under the hood, a platform-specific NativeViewHostWrapper implementation does |
| 21 // the platform-specific work of manipulating the underlying OS widget type. |
17 class NativeViewHost : public View { | 22 class NativeViewHost : public View { |
18 public: | 23 public: |
| 24 // The NativeViewHost's class name. |
| 25 static const char kViewClassName[]; |
| 26 |
19 NativeViewHost(); | 27 NativeViewHost(); |
20 virtual ~NativeViewHost(); | 28 virtual ~NativeViewHost(); |
21 | 29 |
| 30 // Attach a gfx::NativeView to this View. Its bounds will be kept in sync |
| 31 // with the bounds of this View until Detach is called. |
| 32 // |
| 33 // Because native views are positioned in the coordinates of their parent |
| 34 // native view, this function should only be called after this View has been |
| 35 // added to a View hierarchy hosted within a valid Widget. |
| 36 void Attach(gfx::NativeView native_view); |
| 37 |
| 38 // Detach the attached window handle. Its bounds and visibility will no longer |
| 39 // be manipulated by this View. |
| 40 void Detach(); |
| 41 |
| 42 // Sets a preferred size for the native view attached to this View. |
22 void SetPreferredSize(const gfx::Size& size); | 43 void SetPreferredSize(const gfx::Size& size); |
23 virtual gfx::Size GetPreferredSize(); | |
24 | |
25 // Overriden to invoke Layout. | |
26 virtual void VisibilityChanged(View* starting_from, bool is_visible); | |
27 | |
28 // Invokes any of InstallClip, UninstallClip, ShowWidget or HideWidget | |
29 // depending upon what portion of the widget is view in the parent. | |
30 virtual void Layout(); | |
31 | 44 |
32 // A NativeViewHost has an associated focus View so that the focus of the | 45 // A NativeViewHost has an associated focus View so that the focus of the |
33 // native control and of the View are kept in sync. In simple cases where the | 46 // native control and of the View are kept in sync. In simple cases where the |
34 // NativeViewHost directly wraps a native window as is, the associated view | 47 // NativeViewHost directly wraps a native window as is, the associated view |
35 // is this View. In other cases where the NativeViewHost is part of another | 48 // is this View. In other cases where the NativeViewHost is part of another |
36 // view (such as TextField), the actual View is not the NativeViewHost and | 49 // view (such as TextField), the actual View is not the NativeViewHost and |
37 // this method must be called to set that. | 50 // this method must be called to set that. |
38 // This method must be called before Attach(). | 51 // This method must be called before Attach(). |
39 void SetAssociatedFocusView(View* view) { focus_view_ = view; } | 52 void set_focus_view(View* view) { focus_view_ = view; } |
40 View* associated_focus_view() { return focus_view_; } | 53 View* focus_view() { return focus_view_; } |
41 | 54 |
| 55 // Fast resizing will move the native view and clip its visible region, this |
| 56 // will result in white areas and will not resize the content (so scrollbars |
| 57 // will be all wrong and content will flow offscreen). Only use this |
| 58 // when you're doing extremely quick, high-framerate vertical resizes |
| 59 // and don't care about accuracy. Make sure you do a real resize at the |
| 60 // end. USE WITH CAUTION. |
42 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } | 61 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } |
43 bool fast_resize() const { return fast_resize_; } | 62 bool fast_resize() const { return fast_resize_; } |
44 | 63 |
45 // The embedded native view. | 64 // Accessor for |native_view_|. |
46 gfx::NativeView native_view() const { return native_view_; } | 65 gfx::NativeView native_view() const { return native_view_; } |
47 | 66 |
| 67 void NativeViewDestroyed(); |
| 68 |
| 69 // Overridden from View: |
| 70 virtual gfx::Size GetPreferredSize(); |
| 71 virtual void Layout(); |
| 72 virtual void Paint(gfx::Canvas* canvas); |
| 73 virtual void VisibilityChanged(View* starting_from, bool is_visible); |
| 74 |
48 protected: | 75 protected: |
49 // Notification that our visible bounds relative to the root has changed. | |
50 // Invokes Layout to make sure the widget is positioned correctly. | |
51 virtual void VisibleBoundsInRootChanged(); | 76 virtual void VisibleBoundsInRootChanged(); |
52 | 77 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
53 // Sets the native view. Subclasses will typically invoke Layout after setting | 78 virtual std::string GetClassName() const; |
54 // the widget. | 79 virtual void Focus(); |
55 void set_native_view(gfx::NativeView widget) { native_view_ = widget; } | |
56 | |
57 // Installs a clip on the native widget. | |
58 virtual void InstallClip(int x, int y, int w, int h) = 0; | |
59 | |
60 // Removes the clip installed on the native widget by way of InstallClip. | |
61 virtual void UninstallClip() = 0; | |
62 | |
63 // Shows the widget at the specified position (relative to the parent widget). | |
64 virtual void ShowWidget(int x, int y, int w, int h) = 0; | |
65 | |
66 // Hides the widget. NOTE: this may be invoked when the widget is already | |
67 // hidden. | |
68 virtual void HideWidget() = 0; | |
69 | |
70 void set_installed_clip(bool installed_clip) { | |
71 installed_clip_ = installed_clip; | |
72 } | |
73 bool installed_clip() const { return installed_clip_; } | |
74 | 80 |
75 private: | 81 private: |
| 82 // The attached native view. |
76 gfx::NativeView native_view_; | 83 gfx::NativeView native_view_; |
77 | 84 |
| 85 // A platform-specific wrapper that does the OS-level manipulation of the |
| 86 // attached gfx::NativeView. |
| 87 NativeViewHostWrapper* native_wrapper_; |
| 88 |
78 // The preferred size of this View | 89 // The preferred size of this View |
79 gfx::Size preferred_size_; | 90 gfx::Size preferred_size_; |
80 | 91 |
81 // Have we installed a region on the HWND used to clip to only the visible | 92 // True if the native view is being resized using the fast method described |
82 // portion of the HWND? | 93 // in the setter/accessor above. |
83 bool installed_clip_; | |
84 | |
85 // Fast resizing will move the hwnd and clip its window region, this will | |
86 // result in white areas and will not resize the content (so scrollbars | |
87 // will be all wrong and content will flow offscreen). Only use this | |
88 // when you're doing extremely quick, high-framerate vertical resizes | |
89 // and don't care about accuracy. Make sure you do a real resize at the | |
90 // end. USE WITH CAUTION. | |
91 bool fast_resize_; | 94 bool fast_resize_; |
92 | 95 |
93 // The view that should be given focus when this NativeViewHost is focused. | 96 // The view that should be given focus when this NativeViewHost is focused. |
94 View* focus_view_; | 97 View* focus_view_; |
95 | 98 |
96 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); | 99 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); |
97 }; | 100 }; |
98 | 101 |
99 } // namespace views | 102 } // namespace views |
100 | 103 |
101 #endif // VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ | 104 #endif // VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ |
OLD | NEW |