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_aura.h" | 5 #include "ui/views/controls/native/native_view_host_aura.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ui/aura/focus_manager.h" | 8 #include "ui/aura/focus_manager.h" |
| 9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
| 10 #include "ui/gfx/safe_integer_conversions.h" | |
| 10 #include "ui/views/controls/native/native_view_host.h" | 11 #include "ui/views/controls/native/native_view_host.h" |
| 11 #include "ui/views/view_constants_aura.h" | 12 #include "ui/views/view_constants_aura.h" |
| 12 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 | 16 |
| 16 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) | 17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
| 17 : host_(host), | 18 : host_(host), |
| 18 installed_clip_(false) { | 19 installed_clip_(false) { |
| 20 clipping_layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); | |
| 21 clipping_layer_->set_name("NativeViewHostAuraClip"); | |
| 22 clipping_layer_->SetMasksToBounds(true); | |
| 23 clipping_layer_->SetFillsBoundsOpaquely(false); | |
| 19 } | 24 } |
| 20 | 25 |
| 21 NativeViewHostAura::~NativeViewHostAura() { | 26 NativeViewHostAura::~NativeViewHostAura() { |
| 22 if (host_->native_view()) { | 27 if (host_->native_view()) { |
| 23 host_->native_view()->ClearProperty(views::kHostViewKey); | 28 host_->native_view()->ClearProperty(views::kHostViewKey); |
| 24 host_->native_view()->RemoveObserver(this); | 29 host_->native_view()->RemoveObserver(this); |
| 25 } | 30 } |
| 26 } | 31 } |
| 27 | 32 |
| 28 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 59 | 64 |
| 60 void NativeViewHostAura::RemovedFromWidget() { | 65 void NativeViewHostAura::RemovedFromWidget() { |
| 61 if (host_->native_view()) { | 66 if (host_->native_view()) { |
| 62 host_->native_view()->Hide(); | 67 host_->native_view()->Hide(); |
| 63 if (host_->native_view()->parent()) | 68 if (host_->native_view()->parent()) |
| 64 host_->native_view()->parent()->RemoveChild(host_->native_view()); | 69 host_->native_view()->parent()->RemoveChild(host_->native_view()); |
| 65 } | 70 } |
| 66 } | 71 } |
| 67 | 72 |
| 68 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { | 73 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { |
| 69 // Note that this does not pose a problem functionality wise - it might | 74 gfx::Rect input_rect(x, y, w, h); |
| 70 // however pose a speed degradation if not implemented. | 75 |
| 71 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; | 76 if (!installed_clip_) { |
| 77 host_->native_view()->layer()->parent()->Add(clipping_layer_.get()); | |
| 78 clipping_layer_->Add(host_->native_view()->layer()); | |
|
sky
2013/09/24 20:23:25
In general I don't like temporarily adding layers
sadrul
2013/09/25 21:27:23
The NativeView (aura::Window) attached to a Native
sky
2013/09/25 22:31:03
Good point. I like the clipping Window approach. T
rharrison
2013/09/26 20:36:48
Done.
| |
| 79 orig_bounds_ = host_->native_view()->layer()->bounds(); | |
| 80 } | |
| 81 | |
| 82 installed_clip_ = true; | |
| 83 | |
| 84 gfx::Rect layer_bounds = orig_bounds_; | |
| 85 | |
| 86 clipping_layer_->SetBounds(gfx::Rect(layer_bounds.origin().x() + x, | |
| 87 layer_bounds.origin().y() + y, | |
| 88 w, h)); | |
| 89 layer_bounds.set_origin(gfx::Point(-x, -y)); | |
| 90 host_->native_view()->layer()->SetBounds(layer_bounds); | |
| 72 } | 91 } |
| 73 | 92 |
| 74 bool NativeViewHostAura::HasInstalledClip() { | 93 bool NativeViewHostAura::HasInstalledClip() { |
| 75 return installed_clip_; | 94 return installed_clip_; |
| 76 } | 95 } |
| 77 | 96 |
| 78 void NativeViewHostAura::UninstallClip() { | 97 void NativeViewHostAura::UninstallClip() { |
| 98 if (installed_clip_ == false) | |
| 99 return; | |
| 100 | |
| 101 host_->native_view()->layer()->SetBounds(orig_bounds_); | |
| 102 | |
| 103 clipping_layer_->parent()->Add(host_->native_view()->layer()); | |
| 104 host_->native_view()->layer()->parent()->Remove(clipping_layer_.get()); | |
| 105 | |
| 79 installed_clip_ = false; | 106 installed_clip_ = false; |
| 80 } | 107 } |
| 81 | 108 |
| 82 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { | 109 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { |
| 83 // TODO: need to support fast resize. | 110 if (host_->fast_resize()) { |
| 84 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); | 111 UninstallClip(); |
| 112 gfx::Rect input_rect(x, y, w, h); | |
| 113 gfx::Rect native_bounds = host_->native_view()->layer()->bounds(); | |
| 114 gfx::Point new_native_origin = CalculateNewNativeViewOrigin(input_rect, | |
| 115 native_bounds); | |
| 116 host_->native_view()->SetBounds(gfx::Rect(new_native_origin.x(), | |
| 117 new_native_origin.y(), | |
| 118 native_bounds.width(), | |
| 119 native_bounds.height())); | |
| 120 | |
| 121 gfx::Point clip_origin = CalculateClipOrigin(input_rect, native_bounds); | |
| 122 InstallClip(clip_origin.x(), clip_origin.y(), w, h); | |
| 123 } else { | |
| 124 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); | |
| 125 } | |
| 85 host_->native_view()->Show(); | 126 host_->native_view()->Show(); |
| 86 } | 127 } |
| 87 | 128 |
| 88 void NativeViewHostAura::HideWidget() { | 129 void NativeViewHostAura::HideWidget() { |
| 89 host_->native_view()->Hide(); | 130 host_->native_view()->Hide(); |
| 90 } | 131 } |
| 91 | 132 |
| 92 void NativeViewHostAura::SetFocus() { | 133 void NativeViewHostAura::SetFocus() { |
| 93 aura::Window* window = host_->native_view(); | 134 aura::Window* window = host_->native_view(); |
| 94 aura::client::FocusClient* client = aura::client::GetFocusClient(window); | 135 aura::client::FocusClient* client = aura::client::GetFocusClient(window); |
| 95 if (client) | 136 if (client) |
| 96 client->FocusWindow(window); | 137 client->FocusWindow(window); |
| 97 } | 138 } |
| 98 | 139 |
| 99 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { | 140 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { |
| 100 return NULL; | 141 return NULL; |
| 101 } | 142 } |
| 102 | 143 |
| 103 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { | 144 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { |
| 104 DCHECK(window == host_->native_view()); | 145 DCHECK(window == host_->native_view()); |
| 105 host_->NativeViewDestroyed(); | 146 host_->NativeViewDestroyed(); |
| 106 } | 147 } |
| 107 | 148 |
| 108 // static | 149 // static |
| 109 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 150 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| 110 NativeViewHost* host) { | 151 NativeViewHost* host) { |
| 111 return new NativeViewHostAura(host); | 152 return new NativeViewHostAura(host); |
| 112 } | 153 } |
| 113 | 154 |
| 155 gfx::Point NativeViewHostAura::CalculateNewNativeViewOrigin( | |
| 156 gfx::Rect input_rect, | |
| 157 gfx::Rect native_rect) const { | |
| 158 int new_x = input_rect.origin().x() + | |
| 159 gfx::ToRoundedInt(GetWidthFactor() * (input_rect.width() - | |
| 160 native_rect.width())); | |
| 161 int new_y = input_rect.origin().y() + | |
| 162 gfx::ToRoundedInt(GetHeightFactor() * (input_rect.height() - | |
| 163 native_rect.height())); | |
| 164 return gfx::Point(new_x, new_y); | |
| 165 } | |
| 166 | |
| 167 gfx::Point NativeViewHostAura::CalculateClipOrigin( | |
| 168 gfx::Rect input_rect, | |
| 169 gfx::Rect native_rect) const { | |
| 170 int new_x = gfx::ToRoundedInt(GetWidthFactor() * (input_rect.width() - | |
| 171 native_rect.width())); | |
| 172 int new_y = gfx::ToRoundedInt(GetHeightFactor() * (input_rect.height() - | |
| 173 native_rect.height())); | |
| 174 return gfx::Point(new_x, new_y); | |
| 175 } | |
| 176 | |
| 177 float NativeViewHostAura::GetWidthFactor() const { | |
| 178 float ret_val; | |
| 179 switch (host_->fast_resize_gravity()) { | |
| 180 case FAST_RESIZE_GRAVITY_NORTHWEST: | |
| 181 ret_val = 0.0; | |
| 182 break; | |
| 183 case FAST_RESIZE_GRAVITY_NORTH: | |
| 184 ret_val = 0.5; | |
| 185 break; | |
| 186 case FAST_RESIZE_GRAVITY_NORTHEAST: | |
| 187 ret_val = 1.0; | |
| 188 break; | |
| 189 case FAST_RESIZE_GRAVITY_EAST: | |
| 190 ret_val = 1.0; | |
| 191 break; | |
| 192 case FAST_RESIZE_GRAVITY_SOUTHEAST: | |
| 193 ret_val = 1.0; | |
| 194 break; | |
| 195 case FAST_RESIZE_GRAVITY_SOUTH: | |
| 196 ret_val = 0.5; | |
| 197 break; | |
| 198 case FAST_RESIZE_GRAVITY_SOUTHWEST: | |
| 199 ret_val = 0.0; | |
| 200 break; | |
| 201 case FAST_RESIZE_GRAVITY_WEST: | |
| 202 ret_val = 0.0; | |
| 203 break; | |
| 204 case FAST_RESIZE_GRAVITY_CENTER: | |
| 205 ret_val = 0.5; | |
| 206 break; | |
| 207 default: | |
| 208 NOTREACHED(); | |
| 209 }; | |
|
sky
2013/09/24 20:23:25
nit: no ; (same on 245 below). Also, remove the de
rharrison
2013/09/26 20:36:48
Done.
| |
| 210 return ret_val; | |
| 211 } | |
| 212 | |
| 213 float NativeViewHostAura::GetHeightFactor() const { | |
| 214 float ret_val; | |
| 215 switch (host_->fast_resize_gravity()) { | |
| 216 case FAST_RESIZE_GRAVITY_NORTHWEST: | |
| 217 ret_val = 0.0; | |
| 218 break; | |
| 219 case FAST_RESIZE_GRAVITY_NORTH: | |
| 220 ret_val = 0.0; | |
| 221 break; | |
| 222 case FAST_RESIZE_GRAVITY_NORTHEAST: | |
| 223 ret_val = 0.0; | |
| 224 break; | |
| 225 case FAST_RESIZE_GRAVITY_EAST: | |
| 226 ret_val = 0.5; | |
| 227 break; | |
| 228 case FAST_RESIZE_GRAVITY_SOUTHEAST: | |
| 229 ret_val = 1.0; | |
| 230 break; | |
| 231 case FAST_RESIZE_GRAVITY_SOUTH: | |
| 232 ret_val = 1.0; | |
| 233 break; | |
| 234 case FAST_RESIZE_GRAVITY_SOUTHWEST: | |
| 235 ret_val = 1.0; | |
| 236 break; | |
| 237 case FAST_RESIZE_GRAVITY_WEST: | |
| 238 ret_val = 0.5; | |
| 239 break; | |
| 240 case FAST_RESIZE_GRAVITY_CENTER: | |
| 241 ret_val = 0.5; | |
| 242 break; | |
| 243 default: | |
| 244 NOTREACHED(); | |
| 245 }; | |
| 246 return ret_val; | |
| 247 } | |
| 248 | |
| 249 | |
| 114 } // namespace views | 250 } // namespace views |
| OLD | NEW |