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..16d505b672dab58702d182de6b480e6ca9931442 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,7 +16,12 @@ namespace views { |
NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
: host_(host), |
- installed_clip_(false) { |
+ installed_clip_(false), |
+ clipping_window_(NULL) { |
+ clipping_window_.SetTransparent(true); |
sky
2013/09/26 22:10:54
I suspect the ownership isn't right here. Create a
rharrison
2013/09/30 20:48:45
I have moved the ownership out of this class, so I
|
+ clipping_window_.Init(ui::LAYER_NOT_DRAWN); |
+ clipping_window_.layer()->set_name("NativeViewHostAuraClip"); |
+ clipping_window_.layer()->SetMasksToBounds(false); |
} |
NativeViewHostAura::~NativeViewHostAura() { |
@@ -33,11 +39,17 @@ void NativeViewHostAura::NativeViewWillAttach() { |
static_cast<View*>(host_)); |
} |
+void NativeViewHostAura::NativeViewAttached() { |
+ AddClippingWindow(); |
sky
2013/09/26 22:10:54
Replace this and NativeWillAttach with AttachNativ
rharrison
2013/09/30 20:48:45
Done.
|
+} |
+ |
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); |
} |
@@ -49,7 +61,8 @@ void NativeViewHostAura::AddedToWidget() { |
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 |
@@ -60,15 +73,31 @@ void NativeViewHostAura::AddedToWidget() { |
void NativeViewHostAura::RemovedFromWidget() { |
if (host_->native_view()) { |
host_->native_view()->Hide(); |
+ RemoveClippingWindow(); |
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); |
+ |
+ if (!installed_clip_) { |
+ orig_bounds_ = host_->native_view()->layer()->bounds(); |
+ } |
+ |
+ installed_clip_ = true; |
+ |
+ gfx::Rect layer_bounds = orig_bounds_; |
+ |
+ clipping_window_.layer()->SetMasksToBounds(true); |
+ gfx::Point clipping_orig = layer_bounds.origin(); |
+ |
+ clipping_window_.layer()->SetBounds(gfx::Rect(clipping_orig.x() + x, |
+ clipping_orig.y() + y, |
+ w, h)); |
+ layer_bounds.set_origin(gfx::Point(-x, -y)); |
+ host_->native_view()->layer()->SetBounds(layer_bounds); |
} |
bool NativeViewHostAura::HasInstalledClip() { |
@@ -76,12 +105,33 @@ bool NativeViewHostAura::HasInstalledClip() { |
} |
void NativeViewHostAura::UninstallClip() { |
+ if (installed_clip_ == false) |
+ return; |
+ |
+ clipping_window_.layer()->SetMasksToBounds(false); |
+ host_->native_view()->layer()->SetBounds(orig_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()) { |
+ UninstallClip(); |
+ gfx::Rect input_rect(x, y, w, h); |
+ gfx::Rect native_bounds = host_->native_view()->layer()->bounds(); |
+ gfx::Point new_native_origin = CalculateNewNativeViewOrigin(input_rect, |
+ native_bounds); |
+ host_->native_view()->SetBounds(gfx::Rect(new_native_origin.x(), |
+ new_native_origin.y(), |
+ native_bounds.width(), |
+ native_bounds.height())); |
+ |
+ gfx::Point clip_origin = CalculateClipOrigin(input_rect, native_bounds); |
+ InstallClip(clip_origin.x(), clip_origin.y(), w, h); |
+ } else { |
+ clipping_window_.SetBounds(gfx::Rect(x, y, w, h)); |
+ host_->native_view()->SetBounds(gfx::Rect(0, 0, w, h)); |
+ } |
host_->native_view()->Show(); |
} |
@@ -111,4 +161,50 @@ NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
return new NativeViewHostAura(host); |
} |
+gfx::Point NativeViewHostAura::CalculateNewNativeViewOrigin( |
+ const gfx::Rect& input_rect, |
+ const gfx::Rect& native_rect) const { |
+ int new_x = input_rect.origin().x() + |
+ gfx::ToRoundedInt(host_->GetWidthScaleFactor() * (input_rect.width() - |
+ native_rect.width())); |
+ int new_y = input_rect.origin().y() + |
+ gfx::ToRoundedInt(host_->GetHeightScaleFactor() * (input_rect.height() - |
+ native_rect.height())); |
+ return gfx::Point(new_x, new_y); |
+} |
+ |
+gfx::Point NativeViewHostAura::CalculateClipOrigin( |
+ 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() { |
+ aura::Window* widget_window = host_->GetWidget()->GetNativeView(); |
+ widget_window->AddChild(&clipping_window_); |
+ clipping_window_.AddChild(host_->native_view()); |
+ |
+ gfx::Rect bounds = host_->native_view()->bounds(); |
+ bounds.set_origin(gfx::Point(0,0)); |
+ host_->native_view()->SetBounds(bounds); |
+ |
+ clipping_window_.Show(); |
+ host_->Layout(); |
+} |
+ |
+void NativeViewHostAura::RemoveClippingWindow() { |
+ if (host_->native_view()->parent() == &clipping_window_) { |
+ clipping_window_.parent()->AddChild(host_->native_view()); |
+ clipping_window_.parent()->RemoveChild(&clipping_window_); |
+ host_->native_view()->SetBounds(clipping_window_.bounds()); |
+ clipping_window_.Hide(); |
+ } |
+} |
+ |
} // namespace views |