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" |
(...skipping 24 matching lines...) Expand all Loading... |
35 // added to a View hierarchy hosted within a valid Widget. | 35 // added to a View hierarchy hosted within a valid Widget. |
36 void Attach(gfx::NativeView native_view); | 36 void Attach(gfx::NativeView native_view); |
37 | 37 |
38 // Detach the attached window handle. Its bounds and visibility will no longer | 38 // Detach the attached window handle. Its bounds and visibility will no longer |
39 // be manipulated by this View. | 39 // be manipulated by this View. |
40 void Detach(); | 40 void Detach(); |
41 | 41 |
42 // Sets a preferred size for the native view attached to this View. | 42 // Sets a preferred size for the native view attached to this View. |
43 void SetPreferredSize(const gfx::Size& size); | 43 void SetPreferredSize(const gfx::Size& size); |
44 | 44 |
45 // A NativeViewHost must keep the focused view in the focus manager and the | 45 // A NativeViewHost has an associated focus View so that the focus of the |
46 // native focus with in sync . There are 2 aspects to this: | 46 // native control and of the View are kept in sync. In simple cases where the |
47 // - when the native view receives focus, the focus manager must be notified | 47 // NativeViewHost directly wraps a native window as is, the associated view |
48 // that the associated view is now the focused view. | 48 // is this View. In other cases where the NativeViewHost is part of another |
49 // In simple cases where the NativeViewHost directly wraps a native window | 49 // view (such as TextField), the actual View is not the NativeViewHost and |
50 // as is, the associated view is this NativeViewHost. In other cases where | 50 // this method must be called to set that. |
51 // the NativeViewHost is part of another view (such as for the TextField | 51 // This method must be called before Attach(). |
52 // class), the actual View is not the NativeViewHost and set_focus_view() | |
53 // must be called to set the associated view before Attach() is called. | |
54 // - when the view is focused (by calling View::RequestFocus()), it must focus | |
55 // the appropriate native view. In simple cases where the native view does | |
56 // not have children or is the native view that should really get the focus, | |
57 // this works without doing anything. In case where the native view that | |
58 // should get the focus is not the native view passed to Attach(), then | |
59 // the appropriate native view should be specified to | |
60 // set_focus_native_view() before Attach() is called. | |
61 void set_focus_view(View* view) { focus_view_ = view; } | 52 void set_focus_view(View* view) { focus_view_ = view; } |
62 void set_focus_native_view(gfx::NativeView native_view) { | 53 View* focus_view() { return focus_view_; } |
63 focus_native_view_ = native_view; | |
64 } | |
65 gfx::NativeView focus_native_view() const { return focus_native_view_; } | |
66 | 54 |
67 // Fast resizing will move the native view and clip its visible region, this | 55 // Fast resizing will move the native view and clip its visible region, this |
68 // will result in white areas and will not resize the content (so scrollbars | 56 // will result in white areas and will not resize the content (so scrollbars |
69 // will be all wrong and content will flow offscreen). Only use this | 57 // will be all wrong and content will flow offscreen). Only use this |
70 // when you're doing extremely quick, high-framerate vertical resizes | 58 // when you're doing extremely quick, high-framerate vertical resizes |
71 // and don't care about accuracy. Make sure you do a real resize at the | 59 // and don't care about accuracy. Make sure you do a real resize at the |
72 // end. USE WITH CAUTION. | 60 // end. USE WITH CAUTION. |
73 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } | 61 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } |
74 bool fast_resize() const { return fast_resize_; } | 62 bool fast_resize() const { return fast_resize_; } |
75 | 63 |
76 // Accessor for |native_view_|. | 64 // Accessor for |native_view_|. |
77 gfx::NativeView native_view() const { return native_view_; } | 65 gfx::NativeView native_view() const { return native_view_; } |
78 | 66 |
79 // Called by the NativeViewHostWrapper to notify that the |focus_native_view_| | |
80 // got focus. | |
81 void GotNativeFocus(); | |
82 | |
83 void NativeViewDestroyed(); | 67 void NativeViewDestroyed(); |
84 | 68 |
85 // Overridden from View: | 69 // Overridden from View: |
86 virtual gfx::Size GetPreferredSize(); | 70 virtual gfx::Size GetPreferredSize(); |
87 virtual void Layout(); | 71 virtual void Layout(); |
88 virtual void Paint(gfx::Canvas* canvas); | 72 virtual void Paint(gfx::Canvas* canvas); |
89 virtual void VisibilityChanged(View* starting_from, bool is_visible); | 73 virtual void VisibilityChanged(View* starting_from, bool is_visible); |
90 virtual void Focus(); | 74 virtual void Focus(); |
91 | 75 |
92 protected: | 76 protected: |
(...skipping 12 matching lines...) Expand all Loading... |
105 // The preferred size of this View | 89 // The preferred size of this View |
106 gfx::Size preferred_size_; | 90 gfx::Size preferred_size_; |
107 | 91 |
108 // True if the native view is being resized using the fast method described | 92 // True if the native view is being resized using the fast method described |
109 // in the setter/accessor above. | 93 // in the setter/accessor above. |
110 bool fast_resize_; | 94 bool fast_resize_; |
111 | 95 |
112 // 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. |
113 View* focus_view_; | 97 View* focus_view_; |
114 | 98 |
115 // The native view that should get the focus when this View gets focused. | |
116 gfx::NativeView focus_native_view_; | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); | 99 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); |
119 }; | 100 }; |
120 | 101 |
121 } // namespace views | 102 } // namespace views |
122 | 103 |
123 #endif // VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ | 104 #endif // VIEWS_CONTROLS_NATIVE_VIEW_HOST_H_ |
OLD | NEW |