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..04af837354d943db8e9e8775c581b59091d6e7e4 100644 |
| --- a/ui/views/controls/native/native_view_host_aura.cc |
| +++ b/ui/views/controls/native/native_view_host_aura.cc |
| @@ -15,32 +15,42 @@ |
| namespace views { |
| NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
| - : host_(host), |
| - installed_clip_(false) { |
| + : host_(host), installed_clip_(false), clipping_window_(NULL) { |
|
sky
2014/06/05 15:49:01
nit: one param per line.
calamity
2014/06/06 08:13:44
Done.
|
| + 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(false); |
| } |
| NativeViewHostAura::~NativeViewHostAura() { |
| if (host_->native_view()) { |
| host_->native_view()->ClearProperty(views::kHostViewKey); |
| host_->native_view()->RemoveObserver(this); |
| + RemoveClippingWindow(); |
|
sky
2014/06/05 15:49:01
Are you sure this is necessary here? In particular
calamity
2014/06/06 08:13:44
Removing this crashes NativeViewHostAuraTest.HostV
sky
2014/06/06 15:53:57
What does the trace look like?
calamity
2014/06/10 08:48:46
Evidently we need to remove the native view from t
|
| } |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| // 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) { |
| + RemoveClippingWindow(); |
| 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); |
| + } else { |
| + clipping_window_.Hide(); |
|
sky
2014/06/05 15:49:01
Why is this in an else? Shouldn't you always do it
calamity
2014/06/06 08:13:44
RemoveClippingView actually takes care of this. Fi
|
| + if (clipping_window_.parent()) |
| + clipping_window_.parent()->RemoveChild(&clipping_window_); |
| } |
| } |
| @@ -48,9 +58,7 @@ 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 |
| @@ -61,15 +69,16 @@ void NativeViewHostAura::AddedToWidget() { |
| void NativeViewHostAura::RemovedFromWidget() { |
| if (host_->native_view()) { |
| host_->native_view()->Hide(); |
| + RemoveClippingWindow(); |
|
sky
2014/06/05 15:49:01
Seems weird to reparent the native_view to the wid
calamity
2014/06/06 08:13:44
Switched the order. RemoveClippingWindow() won't 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."; |
| + installed_clip_ = true; |
| + clipping_window_.SetBounds(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h))); |
| + clipping_window_.layer()->SetMasksToBounds(true); |
|
sky
2014/06/05 15:49:01
Can't you always set mask to bounds true?
calamity
2014/06/06 08:13:44
It's set to false so that the native view can draw
sky
2014/06/06 15:53:57
Isn't the only time the size of the clipping_windo
calamity
2014/06/10 08:48:46
Oops, this comment was outdated. Yeah. Since I set
|
| } |
| bool NativeViewHostAura::HasInstalledClip() { |
| @@ -77,13 +86,22 @@ bool NativeViewHostAura::HasInstalledClip() { |
| } |
| void NativeViewHostAura::UninstallClip() { |
| + if (installed_clip_ == false) |
| + return; |
| + |
| installed_clip_ = false; |
| + clipping_window_.layer()->SetMasksToBounds(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)); |
| - host_->native_view()->Show(); |
| + if (host_->fast_resize()) { |
| + InstallClip(x, y, w, h); |
| + } else { |
| + 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(); |
| + } |
| } |
| void NativeViewHostAura::HideWidget() { |
| @@ -118,4 +136,34 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
| return new NativeViewHostAura(host); |
| } |
| +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()); |
| + } |
| + host_->native_view()->SetBounds(clipping_window_.bounds()); |
| + } |
| + clipping_window_.Hide(); |
| + if (clipping_window_.parent()) |
| + clipping_window_.parent()->RemoveChild(&clipping_window_); |
| +} |
| + |
| } // namespace views |