OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/views/controls/native/native_view_host.h" | 5 #include "ui/views/controls/native/native_view_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
9 #include "ui/views/accessibility/native_view_accessibility.h" | 9 #include "ui/views/accessibility/native_view_accessibility.h" |
10 #include "ui/views/controls/native/native_view_host_wrapper.h" | 10 #include "ui/views/controls/native/native_view_host_wrapper.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 const bool NativeViewHost::kRenderNativeControlFocus = true; | 26 const bool NativeViewHost::kRenderNativeControlFocus = true; |
27 #endif | 27 #endif |
28 | 28 |
29 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
30 // NativeViewHost, public: | 30 // NativeViewHost, public: |
31 | 31 |
32 NativeViewHost::NativeViewHost() | 32 NativeViewHost::NativeViewHost() |
33 : native_view_(NULL), | 33 : native_view_(NULL), |
34 fast_resize_(false), | 34 fast_resize_(false), |
35 fast_resize_at_last_layout_(false), | 35 fast_resize_at_last_layout_(false), |
| 36 fast_resize_gravity_(GRAVITY_NORTHWEST), |
36 focus_view_(NULL) { | 37 focus_view_(NULL) { |
37 } | 38 } |
38 | 39 |
39 NativeViewHost::~NativeViewHost() { | 40 NativeViewHost::~NativeViewHost() { |
40 } | 41 } |
41 | 42 |
42 void NativeViewHost::Attach(gfx::NativeView native_view) { | 43 void NativeViewHost::Attach(gfx::NativeView native_view) { |
43 DCHECK(native_view); | 44 DCHECK(native_view); |
44 DCHECK(!native_view_); | 45 DCHECK(!native_view_); |
45 native_view_ = native_view; | 46 native_view_ = native_view; |
46 // If set_focus_view() has not been invoked, this view is the one that should | 47 // If set_focus_view() has not been invoked, this view is the one that should |
47 // be seen as focused when the native view receives focus. | 48 // be seen as focused when the native view receives focus. |
48 if (!focus_view_) | 49 if (!focus_view_) |
49 focus_view_ = this; | 50 focus_view_ = this; |
50 native_wrapper_->NativeViewWillAttach(); | 51 native_wrapper_->AttachNativeView(); |
51 Widget::ReparentNativeView(native_view_, GetWidget()->GetNativeView()); | |
52 Layout(); | 52 Layout(); |
53 | 53 Widget* widget = Widget::GetWidgetForNativeView(native_view_); |
54 Widget* widget = Widget::GetWidgetForNativeView(native_view); | |
55 if (widget) | 54 if (widget) |
56 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, this); | 55 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, this); |
57 } | 56 } |
58 | 57 |
59 void NativeViewHost::Detach() { | 58 void NativeViewHost::Detach() { |
60 Detach(false); | 59 Detach(false); |
61 } | 60 } |
62 | 61 |
63 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { | 62 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { |
64 preferred_size_ = size; | 63 preferred_size_ = size; |
65 PreferredSizeChanged(); | 64 PreferredSizeChanged(); |
66 } | 65 } |
67 | 66 |
| 67 float NativeViewHost::GetWidthScaleFactor() const { |
| 68 switch (fast_resize_gravity_) { |
| 69 case GRAVITY_NORTHWEST: |
| 70 return 0.0; |
| 71 case GRAVITY_NORTH: |
| 72 return 0.5; |
| 73 case GRAVITY_NORTHEAST: |
| 74 return 1.0; |
| 75 case GRAVITY_EAST: |
| 76 return 1.0; |
| 77 case GRAVITY_SOUTHEAST: |
| 78 return 1.0; |
| 79 case GRAVITY_SOUTH: |
| 80 return 0.5; |
| 81 case GRAVITY_SOUTHWEST: |
| 82 return 0.0; |
| 83 case GRAVITY_WEST: |
| 84 return 0.0; |
| 85 case GRAVITY_CENTER: |
| 86 return 0.5; |
| 87 } |
| 88 NOTREACHED(); |
| 89 return 0.0; |
| 90 } |
| 91 |
| 92 float NativeViewHost::GetHeightScaleFactor() const { |
| 93 switch (fast_resize_gravity_) { |
| 94 case GRAVITY_NORTHWEST: |
| 95 return 0.0; |
| 96 case GRAVITY_NORTH: |
| 97 return 0.0; |
| 98 case GRAVITY_NORTHEAST: |
| 99 return 0.0; |
| 100 case GRAVITY_EAST: |
| 101 return 0.5; |
| 102 case GRAVITY_SOUTHEAST: |
| 103 return 1.0; |
| 104 case GRAVITY_SOUTH: |
| 105 return 1.0; |
| 106 case GRAVITY_SOUTHWEST: |
| 107 return 1.0; |
| 108 case GRAVITY_WEST: |
| 109 return 0.5; |
| 110 case GRAVITY_CENTER: |
| 111 return 0.5; |
| 112 } |
| 113 NOTREACHED(); |
| 114 return 0.0; |
| 115 } |
| 116 |
68 void NativeViewHost::NativeViewDestroyed() { | 117 void NativeViewHost::NativeViewDestroyed() { |
69 // Detach so we can clear our state and notify the native_wrapper_ to release | 118 // Detach so we can clear our state and notify the native_wrapper_ to release |
70 // ref on the native view. | 119 // ref on the native view. |
71 Detach(true); | 120 Detach(true); |
72 } | 121 } |
73 | 122 |
74 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
75 // NativeViewHost, View overrides: | 124 // NativeViewHost, View overrides: |
76 | 125 |
77 gfx::Size NativeViewHost::GetPreferredSize() { | 126 gfx::Size NativeViewHost::GetPreferredSize() { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 Widget::GetAllChildWidgets(native_view(), &widgets); | 270 Widget::GetAllChildWidgets(native_view(), &widgets); |
222 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { | 271 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { |
223 focus_manager->ViewRemoved((*i)->GetRootView()); | 272 focus_manager->ViewRemoved((*i)->GetRootView()); |
224 if (!focus_manager->GetFocusedView()) | 273 if (!focus_manager->GetFocusedView()) |
225 return; | 274 return; |
226 } | 275 } |
227 } | 276 } |
228 | 277 |
229 | 278 |
230 } // namespace views | 279 } // namespace views |
OLD | NEW |