Chromium Code Reviews| Index: ui/views/controls/native/native_view_host_aura.cc |
| diff --git a/ui/views/controls/native/native_view_host_aura.cc b/ui/views/controls/native/native_view_host_aura.cc |
| index 444f5803e687830df18efb39ca68f2bf5f51a3b0..398fd86f4571a8b258411e54b222362dd1cc2c39 100644 |
| --- a/ui/views/controls/native/native_view_host_aura.cc |
| +++ b/ui/views/controls/native/native_view_host_aura.cc |
| @@ -7,6 +7,7 @@ |
| #include "base/logging.h" |
| #include "ui/aura/focus_manager.h" |
| #include "ui/aura/window.h" |
| +#include "ui/gfx/safe_integer_conversions.h" |
| #include "ui/views/controls/native/native_view_host.h" |
| #include "ui/views/view_constants_aura.h" |
| #include "ui/views/widget/widget.h" |
| @@ -16,6 +17,10 @@ namespace views { |
| NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
| : host_(host), |
| installed_clip_(false) { |
| + clipping_layer_.reset(new ui::Layer(ui::LAYER_NOT_DRAWN)); |
| + clipping_layer_->set_name("NativeViewHostAuraClip"); |
| + clipping_layer_->SetMasksToBounds(true); |
| + clipping_layer_->SetFillsBoundsOpaquely(false); |
| } |
| NativeViewHostAura::~NativeViewHostAura() { |
| @@ -66,9 +71,23 @@ void NativeViewHostAura::RemovedFromWidget() { |
| } |
| void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { |
| - // Note that this does not pose a problem functionality wise - it might |
| - // however pose a speed degradation if not implemented. |
| - LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; |
| + gfx::Rect input_rect(x, y, w, h); |
| + |
| + if (!installed_clip_) { |
| + host_->native_view()->layer()->parent()->Add(clipping_layer_.get()); |
| + 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.
|
| + orig_bounds_ = host_->native_view()->layer()->bounds(); |
| + } |
| + |
| + installed_clip_ = true; |
| + |
| + gfx::Rect layer_bounds = orig_bounds_; |
| + |
| + clipping_layer_->SetBounds(gfx::Rect(layer_bounds.origin().x() + x, |
| + layer_bounds.origin().y() + y, |
| + w, h)); |
| + layer_bounds.set_origin(gfx::Point(-x, -y)); |
| + host_->native_view()->layer()->SetBounds(layer_bounds); |
| } |
| bool NativeViewHostAura::HasInstalledClip() { |
| @@ -76,12 +95,34 @@ bool NativeViewHostAura::HasInstalledClip() { |
| } |
| void NativeViewHostAura::UninstallClip() { |
| + if (installed_clip_ == false) |
| + return; |
| + |
| + host_->native_view()->layer()->SetBounds(orig_bounds_); |
| + |
| + clipping_layer_->parent()->Add(host_->native_view()->layer()); |
| + host_->native_view()->layer()->parent()->Remove(clipping_layer_.get()); |
| + |
| installed_clip_ = false; |
| } |
| void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { |
| - // TODO: need to support fast resize. |
| - host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); |
| + if (host_->fast_resize()) { |
| + UninstallClip(); |
| + gfx::Rect input_rect(x, y, w, h); |
| + gfx::Rect native_bounds = host_->native_view()->layer()->bounds(); |
| + gfx::Point new_native_origin = CalculateNewNativeViewOrigin(input_rect, |
| + native_bounds); |
| + host_->native_view()->SetBounds(gfx::Rect(new_native_origin.x(), |
| + new_native_origin.y(), |
| + native_bounds.width(), |
| + native_bounds.height())); |
| + |
| + gfx::Point clip_origin = CalculateClipOrigin(input_rect, native_bounds); |
| + InstallClip(clip_origin.x(), clip_origin.y(), w, h); |
| + } else { |
| + host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); |
| + } |
| host_->native_view()->Show(); |
| } |
| @@ -111,4 +152,99 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| return new NativeViewHostAura(host); |
| } |
| +gfx::Point NativeViewHostAura::CalculateNewNativeViewOrigin( |
| + gfx::Rect input_rect, |
| + gfx::Rect native_rect) const { |
| + int new_x = input_rect.origin().x() + |
| + gfx::ToRoundedInt(GetWidthFactor() * (input_rect.width() - |
| + native_rect.width())); |
| + int new_y = input_rect.origin().y() + |
| + gfx::ToRoundedInt(GetHeightFactor() * (input_rect.height() - |
| + native_rect.height())); |
| + return gfx::Point(new_x, new_y); |
| +} |
| + |
| +gfx::Point NativeViewHostAura::CalculateClipOrigin( |
| + gfx::Rect input_rect, |
| + gfx::Rect native_rect) const { |
| + int new_x = gfx::ToRoundedInt(GetWidthFactor() * (input_rect.width() - |
| + native_rect.width())); |
| + int new_y = gfx::ToRoundedInt(GetHeightFactor() * (input_rect.height() - |
| + native_rect.height())); |
| + return gfx::Point(new_x, new_y); |
| +} |
| + |
| +float NativeViewHostAura::GetWidthFactor() const { |
| + float ret_val; |
| + switch (host_->fast_resize_gravity()) { |
| + case FAST_RESIZE_GRAVITY_NORTHWEST: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_NORTH: |
| + ret_val = 0.5; |
| + break; |
| + case FAST_RESIZE_GRAVITY_NORTHEAST: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_EAST: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTHEAST: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTH: |
| + ret_val = 0.5; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTHWEST: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_WEST: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_CENTER: |
| + ret_val = 0.5; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + }; |
|
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.
|
| + return ret_val; |
| +} |
| + |
| +float NativeViewHostAura::GetHeightFactor() const { |
| + float ret_val; |
| + switch (host_->fast_resize_gravity()) { |
| + case FAST_RESIZE_GRAVITY_NORTHWEST: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_NORTH: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_NORTHEAST: |
| + ret_val = 0.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_EAST: |
| + ret_val = 0.5; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTHEAST: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTH: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_SOUTHWEST: |
| + ret_val = 1.0; |
| + break; |
| + case FAST_RESIZE_GRAVITY_WEST: |
| + ret_val = 0.5; |
| + break; |
| + case FAST_RESIZE_GRAVITY_CENTER: |
| + ret_val = 0.5; |
| + break; |
| + default: |
| + NOTREACHED(); |
| + }; |
| + return ret_val; |
| +} |
| + |
| + |
| } // namespace views |