OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ | 5 #ifndef UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ |
6 #define UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ | 6 #define UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "ui/gfx/native_widget_types.h" | 10 #include "ui/gfx/native_widget_types.h" |
11 #include "ui/views/view.h" | 11 #include "ui/views/view.h" |
12 | 12 |
13 namespace views { | 13 namespace views { |
14 | 14 |
15 class NativeViewHostAuraTest; | 15 class NativeViewHostAuraTest; |
16 class NativeViewHostWrapper; | 16 class NativeViewHostWrapper; |
17 | 17 |
18 | |
sky
2013/10/01 15:06:43
nit: remove newline.
rharrison
2013/10/02 19:02:50
Done.
| |
18 // If a NativeViewHost's native view is a Widget, this native window | 19 // 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 // property is set on the widget, pointing to the owning NativeViewHost. |
20 extern const char kWidgetNativeViewHostKey[]; | 21 extern const char kWidgetNativeViewHostKey[]; |
21 | 22 |
22 // A View type that hosts a gfx::NativeView. The bounds of the native view are | 23 // 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 // 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 // Under the hood, a platform-specific NativeViewHostWrapper implementation does |
25 // the platform-specific work of manipulating the underlying OS widget type. | 26 // the platform-specific work of manipulating the underlying OS widget type. |
26 class VIEWS_EXPORT NativeViewHost : public View { | 27 class VIEWS_EXPORT NativeViewHost : public View { |
27 public: | 28 public: |
28 // The NativeViewHost's class name. | 29 // The NativeViewHost's class name. |
29 static const char kViewClassName[]; | 30 static const char kViewClassName[]; |
30 | 31 |
31 // Should views render the focus when on native controls? | 32 // Should views render the focus when on native controls? |
32 static const bool kRenderNativeControlFocus; | 33 static const bool kRenderNativeControlFocus; |
33 | 34 |
34 NativeViewHost(); | 35 // When performing fast resizes the contents is not actually resized, but |
36 // instead the contents is positioned and clipped to give the impression of | |
37 // resizing. Gravity indicates the positioning of the content relative to the | |
38 // clipping. The default value, northwest, indicates that the top left corner | |
39 // of the clip and the content should align, so the bottom and right sides of | |
40 // the content will be clipped. For a value like south the bottom edges will | |
41 // align at their respective middles, thus the full vertical resize will be | |
42 // reflected on the top, but half of the horizontal resize will be reflected | |
43 // on the left and right sides. The following list is the gravity values and | |
44 // their alignment points for reference, coordinates relative to the | |
45 // respective system for the clip or contents: | |
46 // NorthWest (0, 0) | |
47 // North (width/2, 0) | |
48 // NorthEast (width, 0) | |
49 // East (width, height/2) | |
50 // SouthEast (width, height) | |
51 // South (width/2, height) | |
52 // SouthWest (0, height) | |
53 // West (0, height/2) | |
54 // Center (width/2, height/2) | |
55 enum Gravity { | |
56 GRAVITY_NORTHWEST, | |
57 GRAVITY_NORTH, | |
58 GRAVITY_NORTHEAST, | |
59 GRAVITY_EAST, | |
60 GRAVITY_SOUTHEAST, | |
61 GRAVITY_SOUTH, | |
62 GRAVITY_SOUTHWEST, | |
63 GRAVITY_WEST, | |
64 GRAVITY_CENTER, | |
65 }; | |
66 | |
67 NativeViewHost(); | |
35 virtual ~NativeViewHost(); | 68 virtual ~NativeViewHost(); |
36 | 69 |
37 // Attach a gfx::NativeView to this View. Its bounds will be kept in sync | 70 // Attach a gfx::NativeView to this View. Its bounds will be kept in sync |
38 // with the bounds of this View until Detach is called. | 71 // with the bounds of this View until Detach is called. |
39 // | 72 // |
40 // Because native views are positioned in the coordinates of their parent | 73 // Because native views are positioned in the coordinates of their parent |
41 // native view, this function should only be called after this View has been | 74 // native view, this function should only be called after this View has been |
42 // added to a View hierarchy hosted within a valid Widget. | 75 // added to a View hierarchy hosted within a valid Widget. |
43 void Attach(gfx::NativeView native_view); | 76 void Attach(gfx::NativeView native_view); |
44 | 77 |
(...skipping 22 matching lines...) Expand all Loading... | |
67 // and don't care about accuracy. Make sure you do a real resize at the | 100 // and don't care about accuracy. Make sure you do a real resize at the |
68 // end. USE WITH CAUTION. | 101 // end. USE WITH CAUTION. |
69 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } | 102 void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } |
70 bool fast_resize() const { return fast_resize_; } | 103 bool fast_resize() const { return fast_resize_; } |
71 | 104 |
72 // Value of fast_resize() the last time Layout() was invoked. | 105 // Value of fast_resize() the last time Layout() was invoked. |
73 bool fast_resize_at_last_layout() const { | 106 bool fast_resize_at_last_layout() const { |
74 return fast_resize_at_last_layout_; | 107 return fast_resize_at_last_layout_; |
75 } | 108 } |
76 | 109 |
110 // Gravity controls how the clip is positioned relative to the native | |
111 // view. The specifics of this are discussed in the comment above the related | |
112 // enum. This call only sets the value being used, but does not cause a | |
113 // re-layout, so ShowWidget, via Layout, must be called before the new gravity | |
114 // will have an effect. | |
115 void set_fast_resize_gravity(Gravity gravity) { | |
116 fast_resize_gravity_ = gravity; | |
117 } | |
118 Gravity fast_resize_gravity() const { | |
119 return fast_resize_gravity_; | |
120 } | |
121 | |
122 // Returns the appropriate, as in the comment above discussing gravity, | |
123 // scaling factor for the current gravity. | |
124 float GetWidthScaleFactor() const; | |
125 float GetHeightScaleFactor() const; | |
126 | |
77 // Accessor for |native_view_|. | 127 // Accessor for |native_view_|. |
78 gfx::NativeView native_view() const { return native_view_; } | 128 gfx::NativeView native_view() const { return native_view_; } |
79 | 129 |
80 void NativeViewDestroyed(); | 130 void NativeViewDestroyed(); |
81 | 131 |
82 // Overridden from View: | 132 // Overridden from View: |
83 virtual gfx::Size GetPreferredSize() OVERRIDE; | 133 virtual gfx::Size GetPreferredSize() OVERRIDE; |
84 virtual void Layout() OVERRIDE; | 134 virtual void Layout() OVERRIDE; |
85 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 135 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
86 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; | 136 virtual void VisibilityChanged(View* starting_from, bool is_visible) OVERRIDE; |
(...skipping 29 matching lines...) Expand all Loading... | |
116 // The preferred size of this View | 166 // The preferred size of this View |
117 gfx::Size preferred_size_; | 167 gfx::Size preferred_size_; |
118 | 168 |
119 // True if the native view is being resized using the fast method described | 169 // True if the native view is being resized using the fast method described |
120 // in the setter/accessor above. | 170 // in the setter/accessor above. |
121 bool fast_resize_; | 171 bool fast_resize_; |
122 | 172 |
123 // Value of |fast_resize_| during the last call to Layout. | 173 // Value of |fast_resize_| during the last call to Layout. |
124 bool fast_resize_at_last_layout_; | 174 bool fast_resize_at_last_layout_; |
125 | 175 |
176 // Gravity value to be used on the next call to ShowWidget. | |
177 Gravity fast_resize_gravity_; | |
178 | |
126 // The view that should be given focus when this NativeViewHost is focused. | 179 // The view that should be given focus when this NativeViewHost is focused. |
127 View* focus_view_; | 180 View* focus_view_; |
128 | 181 |
129 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); | 182 DISALLOW_COPY_AND_ASSIGN(NativeViewHost); |
130 }; | 183 }; |
131 | 184 |
132 } // namespace views | 185 } // namespace views |
133 | 186 |
134 #endif // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ | 187 #endif // UI_VIEWS_CONTROLS_NATIVE_NATIVE_VIEW_HOST_H_ |
OLD | NEW |