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