| 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..f370a5c587915eae884226a4073aa4571ef238cd 100644
|
| --- a/ui/views/controls/native/native_view_host_aura.cc
|
| +++ b/ui/views/controls/native/native_view_host_aura.cc
|
| @@ -5,6 +5,7 @@
|
| #include "ui/views/controls/native/native_view_host_aura.h"
|
|
|
| #include "base/logging.h"
|
| +#include "ui/aura/client/aura_constants.h"
|
| #include "ui/aura/client/focus_client.h"
|
| #include "ui/aura/window.h"
|
| #include "ui/base/cursor/cursor.h"
|
| @@ -16,31 +17,43 @@ namespace views {
|
|
|
| NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
|
| : host_(host),
|
| - installed_clip_(false) {
|
| + clipping_window_(NULL) {
|
| + clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN);
|
| + clipping_window_.set_owned_by_parent(false);
|
| + clipping_window_.SetName("NativeViewHostAuraClip");
|
| + clipping_window_.layer()->SetMasksToBounds(true);
|
| + clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_));
|
| }
|
|
|
| NativeViewHostAura::~NativeViewHostAura() {
|
| if (host_->native_view()) {
|
| - host_->native_view()->ClearProperty(views::kHostViewKey);
|
| host_->native_view()->RemoveObserver(this);
|
| + host_->native_view()->ClearProperty(views::kHostViewKey);
|
| + host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
|
| + clipping_window_.ClearProperty(views::kHostViewKey);
|
| + 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) {
|
| + RemoveClippingWindow();
|
| if (!destroyed) {
|
| - host_->native_view()->ClearProperty(views::kHostViewKey);
|
| host_->native_view()->RemoveObserver(this);
|
| + host_->native_view()->ClearProperty(views::kHostViewKey);
|
| + host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
|
| host_->native_view()->Hide();
|
| if (host_->native_view()->parent())
|
| - Widget::ReparentNativeView(host_->native_view(), NULL);
|
| + host_->native_view()->parent()->RemoveChild(host_->native_view());
|
| }
|
| }
|
|
|
| @@ -48,9 +61,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,28 +72,42 @@ void NativeViewHostAura::AddedToWidget() {
|
| void NativeViewHostAura::RemovedFromWidget() {
|
| if (host_->native_view()) {
|
| host_->native_view()->Hide();
|
| + host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
|
| 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.";
|
| + clip_rect_.reset(
|
| + new gfx::Rect(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h))));
|
| }
|
|
|
| bool NativeViewHostAura::HasInstalledClip() {
|
| - return installed_clip_;
|
| + return clip_rect_;
|
| }
|
|
|
| void NativeViewHostAura::UninstallClip() {
|
| - installed_clip_ = false;
|
| + clip_rect_.reset();
|
| }
|
|
|
| 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));
|
| + int width = w;
|
| + int height = h;
|
| + if (host_->fast_resize()) {
|
| + gfx::Point origin(x, y);
|
| + views::View::ConvertPointFromWidget(host_, &origin);
|
| + InstallClip(origin.x(), origin.y(), w, h);
|
| + width = host_->native_view()->bounds().width();
|
| + height = host_->native_view()->bounds().height();
|
| + }
|
| + clipping_window_.SetBounds(clip_rect_ ? *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(), width, height));
|
| host_->native_view()->Show();
|
| }
|
|
|
| @@ -118,4 +143,40 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
|
| return new NativeViewHostAura(host);
|
| }
|
|
|
| +void NativeViewHostAura::AddClippingWindow() {
|
| + RemoveClippingWindow();
|
| +
|
| + gfx::Rect bounds = host_->native_view()->bounds();
|
| + if (host_->GetWidget()->GetNativeView()) {
|
| + Widget::ReparentNativeView(&clipping_window_,
|
| + host_->GetWidget()->GetNativeView());
|
| + }
|
| + host_->native_view()->SetProperty(aura::client::kHostWindowKey,
|
| + 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())
|
| + host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
|
| +
|
| + 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
|
|
|