Commit 16725934 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Views: Update NativeViewHost to use the rounded corners fast path

Currently NativeViewHost applies a masking path to the NativeView's
layer to achieve the rounded corners effect. Tbis CL updates the API
to use gfx::RoundedCornersF and uses the rounded corners layer fast
path for Aura platforms.

Bug: None
Change-Id: I038d7b01f315e930cd2577d1c6b4f5dc7f6ca5c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2371309Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801472}
parent 8608405b
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/bubble/bubble_frame_view.h" #include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/native/native_view_host.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
...@@ -69,7 +70,7 @@ void ExtensionPopup::AddedToWidget() { ...@@ -69,7 +70,7 @@ void ExtensionPopup::AddedToWidget() {
BubbleDialogDelegateView::AddedToWidget(); BubbleDialogDelegateView::AddedToWidget();
const int radius = GetBubbleFrameView()->corner_radius(); const int radius = GetBubbleFrameView()->corner_radius();
const bool contents_has_rounded_corners = const bool contents_has_rounded_corners =
extension_view_->holder()->SetCornerRadius(radius); extension_view_->holder()->SetCornerRadii(gfx::RoundedCornersF(radius));
SetBorder(views::CreateEmptyBorder( SetBorder(views::CreateEmptyBorder(
gfx::Insets(contents_has_rounded_corners ? 0 : radius, 0))); gfx::Insets(contents_has_rounded_corners ? 0 : radius, 0)));
} }
......
...@@ -57,10 +57,8 @@ void NativeViewHost::SetParentAccessible(gfx::NativeViewAccessible accessible) { ...@@ -57,10 +57,8 @@ void NativeViewHost::SetParentAccessible(gfx::NativeViewAccessible accessible) {
native_wrapper_->SetParentAccessible(accessible); native_wrapper_->SetParentAccessible(accessible);
} }
bool NativeViewHost::SetCornerRadius(int corner_radius) { bool NativeViewHost::SetCornerRadii(const gfx::RoundedCornersF& corner_radii) {
return SetCustomMask(views::Painter::CreatePaintedLayer( return native_wrapper_->SetCornerRadii(corner_radii);
views::Painter::CreateSolidRoundRectPainter(SK_ColorBLACK,
corner_radius)));
} }
bool NativeViewHost::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) { bool NativeViewHost::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) {
......
...@@ -12,6 +12,10 @@ ...@@ -12,6 +12,10 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace gfx {
class RoundedCornersF;
}
namespace views { namespace views {
namespace test { namespace test {
class NativeViewHostTestBase; class NativeViewHostTestBase;
...@@ -47,14 +51,16 @@ class VIEWS_EXPORT NativeViewHost : public View { ...@@ -47,14 +51,16 @@ class VIEWS_EXPORT NativeViewHost : public View {
// detached before calling this function, and this has no effect in that case. // detached before calling this function, and this has no effect in that case.
void Detach(); void Detach();
// Sets the corner radius for clipping gfx::NativeView. Returns true on // Sets the corner radii for clipping gfx::NativeView. Returns true on success
// success or false if the platform doesn't support the operation. // or false if the platform doesn't support the operation. This method calls
// This method calls SetCustomMask internally. // SetCustomMask internally.
bool SetCornerRadius(int corner_radius); bool SetCornerRadii(const gfx::RoundedCornersF& corner_radii);
// Sets the custom layer mask for clipping gfx::NativeView. Returns true on // Sets the custom layer mask for clipping gfx::NativeView. Returns true on
// success or false if the platform doesn't support the operation. // success or false if the platform doesn't support the operation.
// NB: This does not interact nicely with fast_resize. // NB: This does not interact nicely with fast_resize.
// TODO(tluk): This is currently only being used to apply rounded corners in
// ash code. Migrate existing use to SetCornerRadii().
bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask); bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask);
// Sets the height of the top region where the gfx::NativeView shouldn't be // Sets the height of the top region where the gfx::NativeView shouldn't be
......
...@@ -102,6 +102,7 @@ void NativeViewHostAura::AttachNativeView() { ...@@ -102,6 +102,7 @@ void NativeViewHostAura::AttachNativeView() {
original_transform_changed_ = false; original_transform_changed_ = false;
AddClippingWindow(); AddClippingWindow();
InstallMask(); InstallMask();
ApplyRoundedCorners();
} }
void NativeViewHostAura::SetParentAccessible( void NativeViewHostAura::SetParentAccessible(
...@@ -160,6 +161,13 @@ void NativeViewHostAura::RemovedFromWidget() { ...@@ -160,6 +161,13 @@ void NativeViewHostAura::RemovedFromWidget() {
} }
} }
bool NativeViewHostAura::SetCornerRadii(
const gfx::RoundedCornersF& corner_radii) {
corner_radii_ = corner_radii;
ApplyRoundedCorners();
return true;
}
bool NativeViewHostAura::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) { bool NativeViewHostAura::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) {
UninstallMask(); UninstallMask();
mask_ = std::move(mask); mask_ = std::move(mask);
...@@ -327,6 +335,17 @@ void NativeViewHostAura::RemoveClippingWindow() { ...@@ -327,6 +335,17 @@ void NativeViewHostAura::RemoveClippingWindow() {
clipping_window_->parent()->RemoveChild(clipping_window_.get()); clipping_window_->parent()->RemoveChild(clipping_window_.get());
} }
void NativeViewHostAura::ApplyRoundedCorners() {
if (!host_->native_view())
return;
ui::Layer* layer = host_->native_view()->layer();
if (layer->rounded_corner_radii() != corner_radii_) {
layer->SetRoundedCornerRadius(corner_radii_);
layer->SetIsFastRoundedCorner(true);
}
}
void NativeViewHostAura::InstallMask() { void NativeViewHostAura::InstallMask() {
if (!mask_) if (!mask_)
return; return;
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/macros.h" #include "base/macros.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/geometry/rounded_corners_f.h"
#include "ui/gfx/transform.h" #include "ui/gfx/transform.h"
#include "ui/views/controls/native/native_view_host_wrapper.h" #include "ui/views/controls/native/native_view_host_wrapper.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -35,6 +36,7 @@ class NativeViewHostAura : public NativeViewHostWrapper, ...@@ -35,6 +36,7 @@ class NativeViewHostAura : public NativeViewHostWrapper,
void NativeViewDetaching(bool destroyed) override; void NativeViewDetaching(bool destroyed) override;
void AddedToWidget() override; void AddedToWidget() override;
void RemovedFromWidget() override; void RemovedFromWidget() override;
bool SetCornerRadii(const gfx::RoundedCornersF& corner_radii) override;
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;
...@@ -73,6 +75,9 @@ class NativeViewHostAura : public NativeViewHostWrapper, ...@@ -73,6 +75,9 @@ class NativeViewHostAura : public NativeViewHostWrapper,
// undoes it. // undoes it.
void RemoveClippingWindow(); void RemoveClippingWindow();
// Sets or updates the |corner_radii_| on the native view's layer.
void ApplyRoundedCorners();
// Sets or updates the mask layer on the native view's layer. // Sets or updates the mask layer on the native view's layer.
void InstallMask(); void InstallMask();
...@@ -96,6 +101,9 @@ class NativeViewHostAura : public NativeViewHostWrapper, ...@@ -96,6 +101,9 @@ class NativeViewHostAura : public NativeViewHostWrapper,
// 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_;
// Holds the corner_radii to be applied.
gfx::RoundedCornersF corner_radii_;
// Set when AttachNativeView() is called. This is the original transform of // Set when AttachNativeView() is called. This is the original transform of
// the NativeView's layer. The NativeView's layer may be modified to scale // the NativeView's layer. The NativeView's layer may be modified to scale
// when ShowWidget() is called with a native view size not equal to the // when ShowWidget() is called with a native view size not equal to the
......
...@@ -18,6 +18,10 @@ class LayerOwner; ...@@ -18,6 +18,10 @@ class LayerOwner;
class ViewsHostableView; class ViewsHostableView;
} // namespace ui } // namespace ui
namespace gfx {
class RoundedCornersF;
} // namespace gfx
namespace views { namespace views {
class NativeWidgetMacNSWindowHost; class NativeWidgetMacNSWindowHost;
...@@ -41,6 +45,7 @@ class NativeViewHostMac : public NativeViewHostWrapper, ...@@ -41,6 +45,7 @@ class NativeViewHostMac : public NativeViewHostWrapper,
void NativeViewDetaching(bool destroyed) override; void NativeViewDetaching(bool destroyed) override;
void AddedToWidget() override; void AddedToWidget() override;
void RemovedFromWidget() override; void RemovedFromWidget() override;
bool SetCornerRadii(const gfx::RoundedCornersF& corner_radii) override;
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;
......
...@@ -153,6 +153,12 @@ void NativeViewHostMac::RemovedFromWidget() { ...@@ -153,6 +153,12 @@ void NativeViewHostMac::RemovedFromWidget() {
NativeViewDetaching(false); NativeViewDetaching(false);
} }
bool NativeViewHostMac::SetCornerRadii(
const gfx::RoundedCornersF& corner_radii) {
NOTIMPLEMENTED();
return false;
}
bool NativeViewHostMac::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) { bool NativeViewHostMac::SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
return false; return false;
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace gfx {
class RoundedCornersF;
}
namespace ui { namespace ui {
class LayerOwner; class LayerOwner;
} }
...@@ -44,6 +48,11 @@ class NativeViewHostWrapper { ...@@ -44,6 +48,11 @@ class NativeViewHostWrapper {
// rooted at a valid Widget. // rooted at a valid Widget.
virtual void RemovedFromWidget() = 0; virtual void RemovedFromWidget() = 0;
// Clips the corners of the gfx::NativeView to the |corner_radii| specififed.
// Returns true on success or false if the platform doesn't support the
// operation.
virtual bool SetCornerRadii(const gfx::RoundedCornersF& corner_radii) = 0;
// Sets the custom mask for clipping gfx::NativeView. Returns true on // Sets the custom mask for clipping gfx::NativeView. Returns true on
// success or false if the platform doesn't support the operation. // success or false if the platform doesn't support the operation.
virtual bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) = 0; virtual bool SetCustomMask(std::unique_ptr<ui::LayerOwner> mask) = 0;
......
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