Commit 53bd2e82 authored by David Black's avatar David Black Committed by Commit Bot

Revert "views: removal of dead code in NativeViewHost"

This reverts commit 0ee09a04.

Reason for revert: Regresses Assistant UI.

Original change's description:
> views: removal of dead code in NativeViewHost
>
> NativeViewHost has code to deal with being clipped by an ancestor. This logic
> dates back to when we used NativeViewHost more often, and in particular when
> NativeViewHost was contained in a ScrollView. AFAIK we no longer have this
> scenario, so, this removes the unnecessary logic.
>
> BUG=none
> TEST=covered by tests
>
> Change-Id: I7b1a9ba047bd7c4abab68f9fe49c651bf50209d2
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1560130
> Commit-Queue: Scott Violet <sky@chromium.org>
> Reviewed-by: Michael Wasserman <msw@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#649355}

TBR=sky@chromium.org,msw@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: b:130305523
Change-Id: Ib0b5dba24bb4e376f3cdad11d19d59e318fd1b2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1563031Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: David Black <dmblack@google.com>
Cr-Commit-Position: refs/heads/master@{#649775}
parent d452f0b5
...@@ -97,7 +97,24 @@ void NativeViewHost::Layout() { ...@@ -97,7 +97,24 @@ void NativeViewHost::Layout() {
if (!native_view_ || !native_wrapper_.get()) if (!native_view_ || !native_wrapper_.get())
return; return;
if (IsDrawn() && !bounds().IsEmpty()) { gfx::Rect vis_bounds = GetVisibleBounds();
bool visible = !vis_bounds.IsEmpty();
if (visible && !fast_resize_) {
if (vis_bounds.size() != size()) {
// Only a portion of the Widget is really visible.
int x = vis_bounds.x();
int y = vis_bounds.y();
native_wrapper_->InstallClip(x, y, vis_bounds.width(),
vis_bounds.height());
} else if (native_wrapper_->HasInstalledClip()) {
// The whole widget is visible but we installed a clip on the widget,
// uninstall it.
native_wrapper_->UninstallClip();
}
}
if (visible) {
// Since widgets know nothing about the View hierarchy (they are direct // Since widgets know nothing about the View hierarchy (they are direct
// children of the Widget that hosts our View hierarchy) they need to be // children of the Widget that hosts our View hierarchy) they need to be
// positioned in the coordinate system of the Widget, not the current // positioned in the coordinate system of the Widget, not the current
...@@ -113,6 +130,7 @@ void NativeViewHost::Layout() { ...@@ -113,6 +130,7 @@ void NativeViewHost::Layout() {
} else { } else {
native_wrapper_->HideWidget(); native_wrapper_->HideWidget();
} }
fast_resize_at_last_layout_ = visible && fast_resize_;
} }
void NativeViewHost::OnPaint(gfx::Canvas* canvas) { void NativeViewHost::OnPaint(gfx::Canvas* canvas) {
......
...@@ -86,6 +86,11 @@ class VIEWS_EXPORT NativeViewHost : public View { ...@@ -86,6 +86,11 @@ class VIEWS_EXPORT NativeViewHost : public View {
void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; } void set_fast_resize(bool fast_resize) { fast_resize_ = fast_resize; }
bool fast_resize() const { return fast_resize_; } bool fast_resize() const { return fast_resize_; }
// Value of fast_resize() the last time Layout() was invoked.
bool fast_resize_at_last_layout() const {
return fast_resize_at_last_layout_;
}
gfx::NativeView native_view() const { return native_view_; } gfx::NativeView native_view() const { return native_view_; }
void NativeViewDestroyed(); void NativeViewDestroyed();
...@@ -133,6 +138,9 @@ class VIEWS_EXPORT NativeViewHost : public View { ...@@ -133,6 +138,9 @@ class VIEWS_EXPORT NativeViewHost : public View {
// in the setter/accessor above. // in the setter/accessor above.
bool fast_resize_ = false; bool fast_resize_ = false;
// Value of |fast_resize_| during the last call to Layout.
bool fast_resize_at_last_layout_ = false;
DISALLOW_COPY_AND_ASSIGN(NativeViewHost); DISALLOW_COPY_AND_ASSIGN(NativeViewHost);
}; };
......
...@@ -183,12 +183,21 @@ void NativeViewHostAura::SetHitTestTopInset(int top_inset) { ...@@ -183,12 +183,21 @@ void NativeViewHostAura::SetHitTestTopInset(int top_inset) {
UpdateInsets(); UpdateInsets();
} }
void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
clip_rect_ = std::make_unique<gfx::Rect>(
host_->ConvertRectToWidget(gfx::Rect(x, y, w, h)));
}
int NativeViewHostAura::GetHitTestTopInset() const { int NativeViewHostAura::GetHitTestTopInset() const {
return top_inset_; return top_inset_;
} }
bool NativeViewHostAura::HasInstalledClip() { bool NativeViewHostAura::HasInstalledClip() {
return clip_rect_.has_value(); return !!clip_rect_;
}
void NativeViewHostAura::UninstallClip() {
clip_rect_.reset();
} }
void NativeViewHostAura::ShowWidget(int x, void NativeViewHostAura::ShowWidget(int x,
...@@ -198,11 +207,12 @@ void NativeViewHostAura::ShowWidget(int x, ...@@ -198,11 +207,12 @@ void NativeViewHostAura::ShowWidget(int x,
int native_w, int native_w,
int native_h) { int native_h) {
if (host_->fast_resize()) { if (host_->fast_resize()) {
clip_rect_ = gfx::Rect(x, y, w, h); gfx::Point origin(x, y);
views::View::ConvertPointFromWidget(host_, &origin);
InstallClip(origin.x(), origin.y(), w, h);
native_w = host_->native_view()->bounds().width(); native_w = host_->native_view()->bounds().width();
native_h = host_->native_view()->bounds().height(); native_h = host_->native_view()->bounds().height();
} else { } else {
clip_rect_.reset();
gfx::Transform transform = original_transform_; gfx::Transform transform = original_transform_;
if (w > 0 && h > 0 && native_w > 0 && native_h > 0) { if (w > 0 && h > 0 && native_w > 0 && native_h > 0) {
transform.Scale(static_cast<SkMScalar>(w) / native_w, transform.Scale(static_cast<SkMScalar>(w) / native_w,
...@@ -215,7 +225,7 @@ void NativeViewHostAura::ShowWidget(int x, ...@@ -215,7 +225,7 @@ void NativeViewHostAura::ShowWidget(int x,
} }
} }
clipping_window_->SetBounds(clip_rect_.value_or(gfx::Rect(x, y, w, h))); clipping_window_->SetBounds(clip_rect_ ? *clip_rect_ : gfx::Rect(x, y, w, h));
gfx::Point clip_offset = clipping_window_->bounds().origin(); gfx::Point clip_offset = clipping_window_->bounds().origin();
host_->native_view()->SetBounds( host_->native_view()->SetBounds(
gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), native_w, native_h)); gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), native_w, native_h));
...@@ -224,7 +234,6 @@ void NativeViewHostAura::ShowWidget(int x, ...@@ -224,7 +234,6 @@ void NativeViewHostAura::ShowWidget(int x,
} }
void NativeViewHostAura::HideWidget() { void NativeViewHostAura::HideWidget() {
clip_rect_.reset();
host_->native_view()->Hide(); host_->native_view()->Hide();
clipping_window_->Hide(); clipping_window_->Hide();
} }
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h"
#include "ui/aura/window_observer.h" #include "ui/aura/window_observer.h"
#include "ui/compositor/layer_owner.h" #include "ui/compositor/layer_owner.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
...@@ -37,7 +36,9 @@ class NativeViewHostAura : public NativeViewHostWrapper, ...@@ -37,7 +36,9 @@ class NativeViewHostAura : public NativeViewHostWrapper,
bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override; bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override;
void SetHitTestTopInset(int top_inset) override; void SetHitTestTopInset(int top_inset) override;
int GetHitTestTopInset() const override; int GetHitTestTopInset() const override;
void InstallClip(int x, int y, int w, int h) override;
bool HasInstalledClip() override; bool HasInstalledClip() override;
void UninstallClip() override;
void ShowWidget(int x, int y, int w, int h, int native_w, int native_h) void ShowWidget(int x, int y, int w, int h, int native_w, int native_h)
override; override;
void HideWidget() override; void HideWidget() override;
...@@ -88,7 +89,7 @@ class NativeViewHostAura : public NativeViewHostWrapper, ...@@ -88,7 +89,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
// clipping to occur. This is positioned in the coordinate space of // clipping to occur. This is positioned in the coordinate space of
// host_->GetWidget(). // host_->GetWidget().
std::unique_ptr<aura::Window> clipping_window_; std::unique_ptr<aura::Window> clipping_window_;
base::Optional<gfx::Rect> clip_rect_; std::unique_ptr<gfx::Rect> clip_rect_;
// This mask exists for the sake of SetCornerRadius(). // This mask exists for the sake of SetCornerRadius().
std::unique_ptr<ui::LayerOwner> mask_; std::unique_ptr<ui::LayerOwner> mask_;
......
...@@ -278,6 +278,48 @@ TEST_F(NativeViewHostAuraTest, BoundsWhileScaling) { ...@@ -278,6 +278,48 @@ TEST_F(NativeViewHostAuraTest, BoundsWhileScaling) {
DestroyHost(); DestroyHost();
} }
// Test installing and uninstalling a clip.
TEST_F(NativeViewHostAuraTest, InstallClip) {
CreateHost();
toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100));
// Without a clip, the clipping window should always be positioned at the
// requested coordinates with the native view positioned at the origin of the
// clipping window.
native_host()->ShowWidget(10, 20, 100, 100, 100, 100);
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
host()->native_view()->bounds().ToString());
EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(),
clipping_window()->bounds().ToString());
// Clip to the bottom right quarter of the native view.
native_host()->InstallClip(60, 70, 50, 50);
native_host()->ShowWidget(10, 20, 100, 100, 100, 100);
EXPECT_EQ(gfx::Rect(-50, -50, 100, 100).ToString(),
host()->native_view()->bounds().ToString());
EXPECT_EQ(gfx::Rect(60, 70, 50, 50).ToString(),
clipping_window()->bounds().ToString());
// Clip to the center of the native view.
native_host()->InstallClip(35, 45, 50, 50);
native_host()->ShowWidget(10, 20, 100, 100, 100, 100);
EXPECT_EQ(gfx::Rect(-25, -25, 100, 100).ToString(),
host()->native_view()->bounds().ToString());
EXPECT_EQ(gfx::Rect(35, 45, 50, 50).ToString(),
clipping_window()->bounds().ToString());
// Uninstalling the clip should make the clipping window match the native view
// again.
native_host()->UninstallClip();
native_host()->ShowWidget(10, 20, 100, 100, 100, 100);
EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(),
host()->native_view()->bounds().ToString());
EXPECT_EQ(gfx::Rect(10, 20, 100, 100).ToString(),
clipping_window()->bounds().ToString());
DestroyHost();
}
// Ensure native view is parented to the root window after detaching. This is // Ensure native view is parented to the root window after detaching. This is
// a regression test for http://crbug.com/389261. // a regression test for http://crbug.com/389261.
TEST_F(NativeViewHostAuraTest, ParentAfterDetach) { TEST_F(NativeViewHostAuraTest, ParentAfterDetach) {
......
...@@ -42,7 +42,9 @@ class NativeViewHostMac : public NativeViewHostWrapper, ...@@ -42,7 +42,9 @@ class NativeViewHostMac : public NativeViewHostWrapper,
bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override; bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override;
void SetHitTestTopInset(int top_inset) override; void SetHitTestTopInset(int top_inset) override;
int GetHitTestTopInset() const override; int GetHitTestTopInset() const override;
void InstallClip(int x, int y, int w, int h) override;
bool HasInstalledClip() override; bool HasInstalledClip() override;
void UninstallClip() override;
void ShowWidget(int x, int y, int w, int h, int native_w, int native_h) void ShowWidget(int x, int y, int w, int h, int native_w, int native_h)
override; override;
void HideWidget() override; void HideWidget() override;
......
...@@ -169,10 +169,18 @@ int NativeViewHostMac::GetHitTestTopInset() const { ...@@ -169,10 +169,18 @@ int NativeViewHostMac::GetHitTestTopInset() const {
return 0; return 0;
} }
void NativeViewHostMac::InstallClip(int x, int y, int w, int h) {
NOTIMPLEMENTED();
}
bool NativeViewHostMac::HasInstalledClip() { bool NativeViewHostMac::HasInstalledClip() {
return false; return false;
} }
void NativeViewHostMac::UninstallClip() {
NOTIMPLEMENTED();
}
void NativeViewHostMac::ShowWidget(int x, void NativeViewHostMac::ShowWidget(int x,
int y, int y,
int w, int w,
......
...@@ -51,10 +51,20 @@ class NativeViewHostWrapper { ...@@ -51,10 +51,20 @@ class NativeViewHostWrapper {
virtual void SetHitTestTopInset(int top_inset) = 0; virtual void SetHitTestTopInset(int top_inset) = 0;
virtual int GetHitTestTopInset() const = 0; virtual int GetHitTestTopInset() const = 0;
// Installs a clip on the gfx::NativeView. These values are in the coordinate
// space of the Widget, so if this method is called from ShowWidget
// then the values need to be translated.
virtual void InstallClip(int x, int y, int w, int h) = 0;
// Whether or not a clip has been installed on the wrapped gfx::NativeView. // Whether or not a clip has been installed on the wrapped gfx::NativeView.
// A clip is only installed during fast-resize.
virtual bool HasInstalledClip() = 0; virtual bool HasInstalledClip() = 0;
// Removes the clip installed on the gfx::NativeView by way of InstallClip. A
// following call to ShowWidget should occur after calling this method to
// position the gfx::NativeView correctly, since the clipping process may have
// adjusted its position.
virtual void UninstallClip() = 0;
// Shows the gfx::NativeView within the specified region (relative to the // Shows the gfx::NativeView within the specified region (relative to the
// parent native view) and with the given native size. The content will // parent native view) and with the given native size. The content will
// appear scaled if the |native_w| or |native_h| are different from |w| or // appear scaled if the |native_w| or |native_h| are different from |w| or
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment