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 49bf733bbe2ae06567f1b9d148db2255b743ab85..0a3346334a1f91a187f7557bbd8fa00cccda90ea 100644 |
| --- a/ui/views/controls/native/native_view_host_aura.cc |
| +++ b/ui/views/controls/native/native_view_host_aura.cc |
| @@ -16,41 +16,48 @@ namespace views { |
| NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
| : host_(host), |
| - installed_clip_(false) { |
| + installed_clip_(false), |
| + clipping_window_(NULL) { |
| + clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| + clipping_window_.set_owned_by_parent(false); |
| + clipping_window_.layer()->set_name("NativeViewHostAuraClip"); |
| + clipping_window_.layer()->SetMasksToBounds(true); |
| } |
| NativeViewHostAura::~NativeViewHostAura() { |
| if (host_->native_view()) { |
| host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->RemoveObserver(this); |
| + if (host_->native_view()->parent() == &clipping_window_) |
| + clipping_window_.RemoveChild(host_->native_view()); |
| } |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| // 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) { |
| if (!destroyed) { |
| - host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->RemoveObserver(this); |
| + host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->Hide(); |
| if (host_->native_view()->parent()) |
| Widget::ReparentNativeView(host_->native_view(), NULL); |
| } |
| + RemoveClippingWindow(); |
| } |
| 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()); |
| + AddClippingWindow(); |
| if (host_->IsDrawn()) |
| host_->native_view()->Show(); |
| else |
| @@ -63,13 +70,13 @@ void NativeViewHostAura::RemovedFromWidget() { |
| host_->native_view()->Hide(); |
| if (host_->native_view()->parent()) |
| host_->native_view()->parent()->RemoveChild(host_->native_view()); |
| + RemoveClippingWindow(); |
| } |
| } |
| 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."; |
| + installed_clip_ = true; |
|
sky
2014/06/10 16:11:06
Is it possible to nuke installed_clip_ and use cli
calamity
2014/06/11 09:50:26
Done.
|
| + clip_rect_ = host_->ConvertRectToWidget(gfx::Rect(x, y, w, h)); |
| } |
| bool NativeViewHostAura::HasInstalledClip() { |
| @@ -81,8 +88,15 @@ void NativeViewHostAura::UninstallClip() { |
| } |
| 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()) |
| + InstallClip(x, y, w, h); |
|
sky
2014/06/10 16:11:06
Doesn't InstallClip expect coordinates in the view
calamity
2014/06/11 09:50:26
Hmm. Yeah. I think that this is actually completel
|
| + |
| + clipping_window_.SetBounds(installed_clip_ ? clip_rect_ |
| + : gfx::Rect(x, y, w, h)); |
| + |
| + gfx::Point clip_offset = clipping_window_.bounds().origin(); |
| + host_->native_view()->SetBounds( |
| + gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), w, h)); |
| host_->native_view()->Show(); |
| } |
| @@ -118,4 +132,35 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| return new NativeViewHostAura(host); |
| } |
| +void NativeViewHostAura::AddClippingWindow() { |
| + RemoveClippingWindow(); |
| + clipping_window_.AddChild(host_->native_view()); |
| + |
| + gfx::Rect bounds = host_->native_view()->bounds(); |
| + if (host_->GetWidget()->GetNativeView()) { |
| + Widget::ReparentNativeView(&clipping_window_, |
| + host_->GetWidget()->GetNativeView()); |
| + } |
| + |
| + 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()); |
| + } |
| + host_->native_view()->SetBounds(clipping_window_.bounds()); |
| + } |
| + clipping_window_.Hide(); |
| + if (clipping_window_.parent()) |
| + clipping_window_.parent()->RemoveChild(&clipping_window_); |
| +} |
| + |
| } // namespace views |