Commit 0ee09a04 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

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: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649355}
parent 8204d68f
......@@ -97,24 +97,7 @@ void NativeViewHost::Layout() {
if (!native_view_ || !native_wrapper_.get())
return;
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) {
if (IsDrawn() && !bounds().IsEmpty()) {
// Since widgets know nothing about the View hierarchy (they are direct
// children of the Widget that hosts our View hierarchy) they need to be
// positioned in the coordinate system of the Widget, not the current
......@@ -130,7 +113,6 @@ void NativeViewHost::Layout() {
} else {
native_wrapper_->HideWidget();
}
fast_resize_at_last_layout_ = visible && fast_resize_;
}
void NativeViewHost::OnPaint(gfx::Canvas* canvas) {
......
......@@ -86,11 +86,6 @@ class VIEWS_EXPORT NativeViewHost : public View {
void set_fast_resize(bool fast_resize) { fast_resize_ = 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_; }
void NativeViewDestroyed();
......@@ -138,9 +133,6 @@ class VIEWS_EXPORT NativeViewHost : public View {
// in the setter/accessor above.
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);
};
......
......@@ -183,21 +183,12 @@ void NativeViewHostAura::SetHitTestTopInset(int top_inset) {
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 {
return top_inset_;
}
bool NativeViewHostAura::HasInstalledClip() {
return !!clip_rect_;
}
void NativeViewHostAura::UninstallClip() {
clip_rect_.reset();
return clip_rect_.has_value();
}
void NativeViewHostAura::ShowWidget(int x,
......@@ -207,12 +198,11 @@ void NativeViewHostAura::ShowWidget(int x,
int native_w,
int native_h) {
if (host_->fast_resize()) {
gfx::Point origin(x, y);
views::View::ConvertPointFromWidget(host_, &origin);
InstallClip(origin.x(), origin.y(), w, h);
clip_rect_ = gfx::Rect(x, y, w, h);
native_w = host_->native_view()->bounds().width();
native_h = host_->native_view()->bounds().height();
} else {
clip_rect_.reset();
gfx::Transform transform = original_transform_;
if (w > 0 && h > 0 && native_w > 0 && native_h > 0) {
transform.Scale(static_cast<SkMScalar>(w) / native_w,
......@@ -225,7 +215,7 @@ void NativeViewHostAura::ShowWidget(int x,
}
}
clipping_window_->SetBounds(clip_rect_ ? *clip_rect_ : gfx::Rect(x, y, w, h));
clipping_window_->SetBounds(clip_rect_.value_or(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(), native_w, native_h));
......@@ -234,6 +224,7 @@ void NativeViewHostAura::ShowWidget(int x,
}
void NativeViewHostAura::HideWidget() {
clip_rect_.reset();
host_->native_view()->Hide();
clipping_window_->Hide();
}
......
......@@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/optional.h"
#include "ui/aura/window_observer.h"
#include "ui/compositor/layer_owner.h"
#include "ui/gfx/transform.h"
......@@ -36,9 +37,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override;
void SetHitTestTopInset(int top_inset) override;
int GetHitTestTopInset() const override;
void InstallClip(int x, int y, int w, int h) override;
bool HasInstalledClip() override;
void UninstallClip() override;
void ShowWidget(int x, int y, int w, int h, int native_w, int native_h)
override;
void HideWidget() override;
......@@ -89,7 +88,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
// clipping to occur. This is positioned in the coordinate space of
// host_->GetWidget().
std::unique_ptr<aura::Window> clipping_window_;
std::unique_ptr<gfx::Rect> clip_rect_;
base::Optional<gfx::Rect> clip_rect_;
// This mask exists for the sake of SetCornerRadius().
std::unique_ptr<ui::LayerOwner> mask_;
......
......@@ -278,48 +278,6 @@ TEST_F(NativeViewHostAuraTest, BoundsWhileScaling) {
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
// a regression test for http://crbug.com/389261.
TEST_F(NativeViewHostAuraTest, ParentAfterDetach) {
......
......@@ -42,9 +42,7 @@ class NativeViewHostMac : public NativeViewHostWrapper,
bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) override;
void SetHitTestTopInset(int top_inset) override;
int GetHitTestTopInset() const override;
void InstallClip(int x, int y, int w, int h) override;
bool HasInstalledClip() override;
void UninstallClip() override;
void ShowWidget(int x, int y, int w, int h, int native_w, int native_h)
override;
void HideWidget() override;
......
......@@ -169,18 +169,10 @@ int NativeViewHostMac::GetHitTestTopInset() const {
return 0;
}
void NativeViewHostMac::InstallClip(int x, int y, int w, int h) {
NOTIMPLEMENTED();
}
bool NativeViewHostMac::HasInstalledClip() {
return false;
}
void NativeViewHostMac::UninstallClip() {
NOTIMPLEMENTED();
}
void NativeViewHostMac::ShowWidget(int x,
int y,
int w,
......
......@@ -51,20 +51,10 @@ class NativeViewHostWrapper {
virtual void SetHitTestTopInset(int top_inset) = 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.
// A clip is only installed during fast-resize.
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
// 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
......
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