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..4fda2bfb106552ac55b9c64a7f77792eb52b7193 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" |
| @@ -15,29 +16,40 @@ namespace views { |
| NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
| : host_(host), |
| - installed_clip_(false) { |
| + installed_clip_(false), |
| + clipping_window_(NULL) { |
| + clipping_window_.SetTransparent(true); |
| + clipping_window_.Init(ui::LAYER_NOT_DRAWN); |
| + clipping_window_.set_owned_by_parent(false); |
| + clipping_window_.layer()->set_name("NativeViewHostAuraClip"); |
| + clipping_window_.layer()->SetMasksToBounds(false); |
| } |
| NativeViewHostAura::~NativeViewHostAura() { |
| if (host_->native_view()) { |
| host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->RemoveObserver(this); |
| + RemoveClippingWindow(); |
| } |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| // NativeViewHostAura, NativeViewHostWrapper implementation: |
| -void NativeViewHostAura::NativeViewWillAttach() { |
| +void NativeViewHostAura::AttachNativeView() { |
| host_->native_view()->AddObserver(this); |
| host_->native_view()->SetProperty(views::kHostViewKey, |
| static_cast<View*>(host_)); |
| + |
| + AddClippingWindow(); |
| } |
| void NativeViewHostAura::NativeViewDetaching(bool destroyed) { |
| + RemoveClippingWindow(); |
| if (!destroyed) { |
| host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->RemoveObserver(this); |
| host_->native_view()->Hide(); |
| + |
| if (host_->native_view()->parent()) |
| Widget::ReparentNativeView(host_->native_view(), NULL); |
| } |
| @@ -47,9 +59,10 @@ void NativeViewHostAura::AddedToWidget() { |
| if (!host_->native_view()) |
| return; |
| - aura::Window* widget_window = host_->GetWidget()->GetNativeView(); |
| - if (host_->native_view()->parent() != widget_window) |
| - widget_window->AddChild(host_->native_view()); |
| + if (host_->native_view()->parent() != |
| + host_->GetWidget()->GetNativeView()) |
|
sky
2013/10/02 20:49:00
nit: I think you can fit this on one line.
rharrison
2013/10/09 17:42:20
Done.
|
| + AddClippingWindow(); |
| + |
| if (host_->IsDrawn()) |
| host_->native_view()->Show(); |
| else |
| @@ -60,15 +73,31 @@ void NativeViewHostAura::AddedToWidget() { |
| void NativeViewHostAura::RemovedFromWidget() { |
| if (host_->native_view()) { |
| host_->native_view()->Hide(); |
| + RemoveClippingWindow(); |
|
sky
2013/10/02 20:49:00
Why do you need anything more than removing the cl
rharrison
2013/10/09 17:42:20
If we do that then the native will still be attach
sky
2013/10/09 20:21:37
You're right. My question should be, can we just r
|
| if (host_->native_view()->parent()) |
| host_->native_view()->parent()->RemoveChild(host_->native_view()); |
| } |
| } |
| 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); |
|
xiyuan
2013/10/02 20:47:29
nit: seems not used.
rharrison
2013/10/09 17:42:20
Done.
|
| + |
| + if (!installed_clip_) { |
|
sky
2013/10/02 20:49:00
nit: no {}
rharrison
2013/10/09 17:42:20
Done.
|
| + orig_bounds_ = clipping_window_.layer()->bounds(); |
|
xiyuan
2013/10/02 20:47:29
What if InstallClip is called while it has a clip?
rharrison
2013/10/09 17:42:20
Done.
|
| + } |
| + |
| + installed_clip_ = true; |
| + |
| + gfx::Rect clipping_bounds(x, y, w, h); |
| + clipping_window_.layer()->SetMasksToBounds(true); |
| + clipping_window_.layer()->SetBounds(clipping_bounds); |
|
xiyuan
2013/10/02 20:47:29
host_ calls InstallClip with (x,y) in its own coor
rharrison
2013/10/09 17:42:20
You are correct, I have fixed this.
|
| + |
| + gfx::Rect native_bounds = host_->native_view()->layer()->bounds(); |
| + |
| + gfx::Point native_origin = CalculateNativeViewOrigin(clipping_bounds, |
| + native_bounds); |
| + native_bounds.set_origin(native_origin); |
| + host_->native_view()->layer()->SetBounds(native_bounds); |
| } |
| bool NativeViewHostAura::HasInstalledClip() { |
| @@ -76,12 +105,26 @@ bool NativeViewHostAura::HasInstalledClip() { |
| } |
| void NativeViewHostAura::UninstallClip() { |
| + if (installed_clip_ == false) |
| + return; |
| + |
| + clipping_window_.layer()->SetMasksToBounds(false); |
| + clipping_window_.layer()->SetBounds(orig_bounds_); |
|
sky
2013/10/02 20:49:00
ShowWidget is invoked right after this. Can you wa
rharrison
2013/10/09 17:42:20
I think you meant InstallClip maybe? I want to avo
sky
2013/10/09 20:21:37
Isn't there already this dependency though? Native
|
| + gfx::Rect layer_bounds = orig_bounds_; |
| + layer_bounds.set_origin(gfx::Point(0,0)); |
| + host_->native_view()->layer()->SetBounds(layer_bounds); |
| + |
| 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()) { |
|
xiyuan
2013/10/02 20:47:29
Is it possible to make it work for non fast resize
rharrison
2013/10/09 17:42:20
The fast v. non-fast resize paths have semantic/fu
|
| + UninstallClip(); |
| + InstallClip(x, y, w, h); |
|
xiyuan
2013/10/02 20:47:29
ShowWidget's (x,y) is in host_->GetWidget()'s coor
rharrison
2013/10/09 17:42:20
I agree, Done.
|
| + } else { |
| + clipping_window_.SetBounds(gfx::Rect(x, y, w, h)); |
| + host_->native_view()->SetBounds(gfx::Rect(0, 0, w, h)); |
| + } |
| host_->native_view()->Show(); |
| } |
| @@ -101,8 +144,9 @@ gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { |
| } |
| void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { |
| - DCHECK(window == host_->native_view()); |
| - host_->NativeViewDestroyed(); |
| + if (window == host_->native_view()) |
|
sky
2013/10/02 20:49:00
Why the if and not the DCHECK? This only adds one
rharrison
2013/10/09 17:42:20
Done.
|
| + host_->NativeViewDestroyed(); |
| + |
| } |
| // static |
| @@ -111,4 +155,48 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| return new NativeViewHostAura(host); |
| } |
| +gfx::Point NativeViewHostAura::CalculateNativeViewOrigin( |
| + const gfx::Rect& input_rect, |
| + const gfx::Rect& native_rect) const { |
| + int new_x = gfx::ToRoundedInt(host_->GetWidthScaleFactor() * |
| + (input_rect.width() - |
| + native_rect.width())); |
| + int new_y = gfx::ToRoundedInt(host_->GetHeightScaleFactor() * |
| + (input_rect.height() - |
| + native_rect.height())); |
| + return gfx::Point(new_x, new_y); |
| +} |
| + |
| +void NativeViewHostAura::AddClippingWindow() { |
| + gfx::Rect bounds = host_->native_view()->bounds(); |
| + |
| + if (host_->GetWidget()->GetNativeView()) |
| + Widget::ReparentNativeView(&clipping_window_, |
| + host_->GetWidget()->GetNativeView()); |
| + Widget::ReparentNativeView(host_->native_view(), |
| + &clipping_window_); |
| + |
| + clipping_window_.SetBounds(bounds); |
| + bounds.set_origin(gfx::Point(0,0)); |
| + host_->native_view()->SetBounds(bounds); |
| + |
| + clipping_window_.Show(); |
| +} |
| + |
| +void NativeViewHostAura::RemoveClippingWindow() { |
| + if (host_->native_view()->parent() == &clipping_window_) { |
| + if (host_->GetWidget()->GetNativeView()) { |
| + Widget::ReparentNativeView(host_->native_view(), |
| + host_->GetWidget()->GetNativeView()); |
| + } else { |
| + clipping_window_.RemoveChild(host_->native_view()); |
| + } |
| + |
| + clipping_window_.Hide(); |
| + host_->native_view()->SetBounds(clipping_window_.bounds()); |
| + if (clipping_window_.parent()) |
| + clipping_window_.parent()->RemoveChild(&clipping_window_); |
| + } |
| +} |
| + |
| } // namespace views |