Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: ui/views/controls/native/native_view_host_aura.cc

Issue 317823002: Implement NativeViewHostAura::InstallClip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add more tests Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..bdc508dc07e931790e4c268d423069f41531862f 100644
--- a/ui/views/controls/native/native_view_host_aura.cc
+++ b/ui/views/controls/native/native_view_host_aura.cc
@@ -16,31 +16,40 @@ 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);
}
NativeViewHostAura::~NativeViewHostAura() {
if (host_->native_view()) {
- host_->native_view()->ClearProperty(views::kHostViewKey);
host_->native_view()->RemoveObserver(this);
+ host_->native_view()->ClearProperty(views::kHostViewKey);
+ 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()->Hide();
if (host_->native_view()->parent())
- Widget::ReparentNativeView(host_->native_view(), NULL);
+ host_->native_view()->parent()->RemoveChild(host_->native_view());
}
}
@@ -48,9 +57,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
@@ -63,26 +70,39 @@ 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.";
+ 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 +138,38 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
return new NativeViewHostAura(host);
}
+void NativeViewHostAura::AddClippingWindow() {
+ RemoveClippingWindow();
+ clipping_window_.SetProperty(views::kHostViewKey,
sky 2014/06/16 17:11:03 Can't you set this in the constructor once and not
calamity 2014/06/17 05:01:12 Done.
+ static_cast<View*>(host_));
+
+ 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_.ClearProperty(views::kHostViewKey);
+ clipping_window_.Hide();
+ if (clipping_window_.parent())
+ clipping_window_.parent()->RemoveChild(&clipping_window_);
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698