Chromium Code Reviews| 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_->NativeViewWillAttach(); |
| 51 Widget::ReparentNativeView(native_view_, GetWidget()->GetNativeView()); | 52 Widget::ReparentNativeView(native_view_, GetWidget()->GetNativeView()); |
| 52 Layout(); | 53 Layout(); |
| 53 | 54 |
| 54 Widget* widget = Widget::GetWidgetForNativeView(native_view); | 55 Widget* widget = Widget::GetWidgetForNativeView(native_view); |
| 55 if (widget) | 56 if (widget) |
| 56 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, this); | 57 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, this); |
| 58 native_wrapper_->NativeViewAttached(); | |
| 57 } | 59 } |
| 58 | 60 |
| 59 void NativeViewHost::Detach() { | 61 void NativeViewHost::Detach() { |
| 60 Detach(false); | 62 Detach(false); |
| 61 } | 63 } |
| 62 | 64 |
| 63 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { | 65 void NativeViewHost::SetPreferredSize(const gfx::Size& size) { |
| 64 preferred_size_ = size; | 66 preferred_size_ = size; |
| 65 PreferredSizeChanged(); | 67 PreferredSizeChanged(); |
| 66 } | 68 } |
| 67 | 69 |
| 70 float NativeViewHost::GetWidthScaleFactor() const { | |
| 71 float ret_val = 0.0; | |
| 72 switch (fast_resize_gravity_) { | |
| 73 case GRAVITY_NORTHWEST: | |
| 74 ret_val = 0.0; | |
|
sky
2013/09/26 22:10:54
There is no point in assigning to ret_val, break,
rharrison
2013/09/30 20:48:45
Done.
| |
| 75 break; | |
| 76 case GRAVITY_NORTH: | |
| 77 ret_val = 0.5; | |
| 78 break; | |
| 79 case GRAVITY_NORTHEAST: | |
| 80 ret_val = 1.0; | |
| 81 break; | |
| 82 case GRAVITY_EAST: | |
| 83 ret_val = 1.0; | |
| 84 break; | |
| 85 case GRAVITY_SOUTHEAST: | |
| 86 ret_val = 1.0; | |
| 87 break; | |
| 88 case GRAVITY_SOUTH: | |
| 89 ret_val = 0.5; | |
| 90 break; | |
| 91 case GRAVITY_SOUTHWEST: | |
| 92 ret_val = 0.0; | |
| 93 break; | |
| 94 case GRAVITY_WEST: | |
| 95 ret_val = 0.0; | |
| 96 break; | |
| 97 case GRAVITY_CENTER: | |
| 98 ret_val = 0.5; | |
| 99 break; | |
| 100 } | |
| 101 return ret_val; | |
| 102 } | |
| 103 | |
| 104 float NativeViewHost::GetHeightScaleFactor() const { | |
| 105 float ret_val = 0.0; | |
| 106 switch (fast_resize_gravity_) { | |
| 107 case GRAVITY_NORTHWEST: | |
| 108 ret_val = 0.0; | |
| 109 break; | |
| 110 case GRAVITY_NORTH: | |
| 111 ret_val = 0.0; | |
| 112 break; | |
| 113 case GRAVITY_NORTHEAST: | |
| 114 ret_val = 0.0; | |
| 115 break; | |
| 116 case GRAVITY_EAST: | |
| 117 ret_val = 0.5; | |
| 118 break; | |
| 119 case GRAVITY_SOUTHEAST: | |
| 120 ret_val = 1.0; | |
| 121 break; | |
| 122 case GRAVITY_SOUTH: | |
| 123 ret_val = 1.0; | |
| 124 break; | |
| 125 case GRAVITY_SOUTHWEST: | |
| 126 ret_val = 1.0; | |
| 127 break; | |
| 128 case GRAVITY_WEST: | |
| 129 ret_val = 0.5; | |
| 130 break; | |
| 131 case GRAVITY_CENTER: | |
| 132 ret_val = 0.5; | |
| 133 break; | |
| 134 } | |
| 135 return ret_val; | |
| 136 } | |
| 137 | |
| 68 void NativeViewHost::NativeViewDestroyed() { | 138 void NativeViewHost::NativeViewDestroyed() { |
| 69 // Detach so we can clear our state and notify the native_wrapper_ to release | 139 // Detach so we can clear our state and notify the native_wrapper_ to release |
| 70 // ref on the native view. | 140 // ref on the native view. |
| 71 Detach(true); | 141 Detach(true); |
| 72 } | 142 } |
| 73 | 143 |
| 74 //////////////////////////////////////////////////////////////////////////////// | 144 //////////////////////////////////////////////////////////////////////////////// |
| 75 // NativeViewHost, View overrides: | 145 // NativeViewHost, View overrides: |
| 76 | 146 |
| 77 gfx::Size NativeViewHost::GetPreferredSize() { | 147 gfx::Size NativeViewHost::GetPreferredSize() { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 Widget::GetAllChildWidgets(native_view(), &widgets); | 291 Widget::GetAllChildWidgets(native_view(), &widgets); |
| 222 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { | 292 for (Widget::Widgets::iterator i = widgets.begin(); i != widgets.end(); ++i) { |
| 223 focus_manager->ViewRemoved((*i)->GetRootView()); | 293 focus_manager->ViewRemoved((*i)->GetRootView()); |
| 224 if (!focus_manager->GetFocusedView()) | 294 if (!focus_manager->GetFocusedView()) |
| 225 return; | 295 return; |
| 226 } | 296 } |
| 227 } | 297 } |
| 228 | 298 |
| 229 | 299 |
| 230 } // namespace views | 300 } // namespace views |
| OLD | NEW |