Commit 05a9d520 authored by Thomas Lukaszewicz's avatar Thomas Lukaszewicz Committed by Commit Bot

Views: Enable layer masking for ClientViews in dialogs and bubbles

This CL removes the flag gating layer masking for ClientViews of
dialogs and bubbles.

With this change dialogs and bubbles can use layer masking to
apply the appropriate clip to their ClientViews. Bubbles can opt into
layer masking by calling SetPaintClientToLayer(true).

The kEnableMDRoundedCornersOnDialogs flag continues to gate the
increased corner radius of bubbles and dialogs used in Chrome.

Bug: None
Change-Id: I4559ced170fa56b6b8974f4d9b2bd689668cbac9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490666
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824082}
parent 3603a293
......@@ -7,7 +7,6 @@
#include <utility>
#include "base/bind.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "ui/accessibility/ax_enums.mojom.h"
......@@ -26,7 +25,6 @@
#include "ui/views/layout/layout_provider.h"
#include "ui/views/metadata/metadata_impl_macros.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/views_features.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
......@@ -56,7 +54,8 @@ namespace {
//
// TODO(tluk): Fix all cases where bubble transparency is used and have bubble
// ClientViews always paint to a layer.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kPaintClientToLayer, true)
// TODO(tluk): Flip this to true for all bubbles.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kPaintClientToLayer, false)
// Override base functionality of Widget to give bubble dialogs access to the
// theme provider of the window they're anchored to.
......@@ -400,9 +399,7 @@ ClientView* BubbleDialogDelegate::CreateClientView(Widget* widget) {
// rounded corner clip we must paint the client view to a layer. This is
// necessary because layers do not respect the clip of a non-layer backed
// parent.
if (base::FeatureList::IsEnabled(
features::kEnableMDRoundedCornersOnDialogs) &&
GetProperty(kPaintClientToLayer)) {
if (GetProperty(kPaintClientToLayer)) {
client_view_->SetPaintToLayer();
client_view_->layer()->SetRoundedCornerRadius(
gfx::RoundedCornersF(GetCornerRadius()));
......
......@@ -14,7 +14,6 @@
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "ui/base/hit_test.h"
#include "ui/events/event_utils.h"
......@@ -30,7 +29,6 @@
#include "ui/views/test/test_widget_observer.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/test/widget_test.h"
#include "ui/views/views_features.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
......@@ -628,28 +626,14 @@ TEST_F(BubbleDialogDelegateViewTest, GetThemeProvider_FromAnchorWidget) {
anchor_widget->GetThemeProvider());
}
// Tests whether the BubbleDialogDelegateView will create a layer backed client
// view when prompted to do so.
class BubbleDialogDelegateClientLayerTest : public test::WidgetTest {
public:
BubbleDialogDelegateClientLayerTest() = default;
~BubbleDialogDelegateClientLayerTest() override = default;
void SetUp() override {
WidgetTest::SetUp();
scoped_feature_list_.InitWithFeatures(
{features::kEnableMDRoundedCornersOnDialogs}, {});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
TEST_F(BubbleDialogDelegateClientLayerTest, WithClientLayerTest) {
// Tests whether the BubbleDialogDelegateView will create a layer backed
// ClientView when SetPaintClientToLayer is set to true.
TEST_F(BubbleDialogDelegateViewTest, WithClientLayerTest) {
std::unique_ptr<Widget> anchor_widget =
CreateTestWidget(Widget::InitParams::TYPE_WINDOW);
auto bubble_delegate = std::make_unique<BubbleDialogDelegateView>(
nullptr, BubbleBorder::TOP_LEFT);
bubble_delegate->SetPaintClientToLayer(true);
bubble_delegate->set_parent_window(anchor_widget->GetNativeView());
WidgetAutoclosePtr bubble_widget(
......@@ -658,7 +642,9 @@ TEST_F(BubbleDialogDelegateClientLayerTest, WithClientLayerTest) {
EXPECT_NE(nullptr, bubble_widget->client_view()->layer());
}
TEST_F(BubbleDialogDelegateClientLayerTest, WithoutClientLayerTest) {
// Tests to ensure BubbleDialogDelegateView does not create a layer backed
// ClientView when SetPaintClientToLayer is set to false.
TEST_F(BubbleDialogDelegateViewTest, WithoutClientLayerTest) {
std::unique_ptr<Widget> anchor_widget =
CreateTestWidget(Widget::InitParams::TYPE_WINDOW);
auto bubble_delegate = std::make_unique<BubbleDialogDelegateView>(
......
......@@ -7,7 +7,6 @@
#include <algorithm>
#include <utility>
#include "base/feature_list.h"
#include "build/build_config.h"
#include "components/vector_icons/vector_icons.h"
#include "third_party/skia/include/core/SkPath.h"
......@@ -36,7 +35,6 @@
#include "ui/views/paint_info.h"
#include "ui/views/resources/grit/views_resources.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/views_features.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/views/window/client_view.h"
......@@ -198,12 +196,9 @@ bool BubbleFrameView::GetClientMask(const gfx::Size& size, SkPath* path) const {
// BubbleFrameView only returns a SkPath for the purpose of clipping the
// client view's corners so that it fits within the borders of its rounded
// frame. With MD rounded coners if a client view is painted to a layer the
// rounding is handled by the |SetRoundedCornerRadius()| layer API, so we
// return false here.
if (base::FeatureList::IsEnabled(
features::kEnableMDRoundedCornersOnDialogs) &&
GetWidget()->client_view()->layer()) {
// frame. If a client view is painted to a layer the rounding is handled by
// the |SetRoundedCornerRadius()| layer API, so we return false here.
if (GetWidget()->client_view()->layer()) {
return false;
}
......@@ -583,8 +578,6 @@ SkColor BubbleFrameView::GetBackgroundColor() const {
}
void BubbleFrameView::UpdateClientViewBackground() {
if (!base::FeatureList::IsEnabled(features::kEnableMDRoundedCornersOnDialogs))
return;
DCHECK(GetWidget());
DCHECK(GetWidget()->client_view());
......@@ -884,9 +877,10 @@ int BubbleFrameView::GetHeaderHeightForFrameWidth(int frame_width) const {
}
void BubbleFrameView::UpdateClientLayerCornerRadius() {
if (GetWidget() && GetWidget()->client_view()->layer() &&
base::FeatureList::IsEnabled(
features::kEnableMDRoundedCornersOnDialogs)) {
// If the ClientView is painted to a layer we need to apply the appropriate
// corner radius so that the ClientView and all its child layers are masked
// appropriately to fit within the BubbleFrameView.
if (GetWidget() && GetWidget()->client_view()->layer()) {
GetWidget()->client_view()->layer()->SetRoundedCornerRadius(
GetClientCornerRadii());
}
......
......@@ -65,6 +65,10 @@ bool InitializeVisuals() {
} // namespace
void ViewsTestBase::WidgetCloser::operator()(Widget* widget) const {
widget->CloseNow();
}
ViewsTestBase::ViewsTestBase(
std::unique_ptr<base::test::TaskEnvironment> task_environment)
: task_environment_(std::move(task_environment)) {}
......
......@@ -42,6 +42,13 @@ class ViewsTestBase : public PlatformTest {
kDesktop,
};
// This class can be used as a deleter for std::unique_ptr<Widget>
// to call function Widget::CloseNow automatically.
struct WidgetCloser {
void operator()(Widget* widget) const;
};
using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>;
// Constructs a ViewsTestBase with |traits| being forwarded to its
// TaskEnvironment. MainThreadType always defaults to UI and must not be
// specified.
......
......@@ -50,10 +50,6 @@ View* AnyViewWithClassName(Widget* widget, const std::string& classname) {
});
}
void WidgetTest::WidgetCloser::operator()(Widget* widget) const {
widget->CloseNow();
}
WidgetTest::WidgetTest() = default;
WidgetTest::WidgetTest(
......
......@@ -61,14 +61,6 @@ View* AnyViewWithClassName(Widget* widget, const std::string& classname);
class WidgetTest : public ViewsTestBase {
public:
// This class can be used as a deleter for std::unique_ptr<Widget>
// to call function Widget::CloseNow automatically.
struct WidgetCloser {
void operator()(Widget* widget) const;
};
using WidgetAutoclosePtr = std::unique_ptr<Widget, WidgetCloser>;
WidgetTest();
explicit WidgetTest(
std::unique_ptr<base::test::TaskEnvironment> task_environment);
......
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