Commit d3ea545c authored by David Black's avatar David Black Committed by Commit Bot

Fix failure to clip web contents.

The layer to which our web contents is drawn is not masked by the layer
which applies corner clipping logic in Assistant UI.

To fix this, I've added a distinct clipping layer mask that enforces
our desired corner radius.

See bug for before/after.

Bug: b:113903157
Change-Id: If19ff4d6836cedf8b8ec6d0e9fef5616d5392b1d
Reviewed-on: https://chromium-review.googlesource.com/1205195
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#588969}
parent 94fe9bff
......@@ -33,7 +33,6 @@ namespace {
// Appearance.
constexpr SkColor kBackgroundColor = SK_ColorWHITE;
constexpr int kCornerRadiusDip = 20;
constexpr int kMiniUiCornerRadiusDip = 24;
constexpr int kMarginBottomDip = 8;
......
......@@ -15,6 +15,7 @@ class FontList;
namespace ash {
// Appearance.
constexpr int kCornerRadiusDip = 20;
constexpr int kMaxHeightDip = 640;
constexpr int kPaddingDip = 14;
constexpr int kPreferredWidthDip = 640;
......
......@@ -12,7 +12,10 @@
#include "ash/public/interfaces/web_contents_manager.mojom.h"
#include "base/callback.h"
#include "base/unguessable_token.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/painter.h"
namespace ash {
......@@ -47,6 +50,13 @@ void AssistantWebView::ChildPreferredSizeChanged(views::View* child) {
SchedulePaint();
}
void AssistantWebView::OnViewBoundsChanged(views::View* view) {
DCHECK_EQ(content_view_, view);
// The mask layer should always match the bounds of the content view.
content_view_mask_->layer()->SetBounds(content_view_->GetLocalBounds());
}
void AssistantWebView::InitLayout() {
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical));
......@@ -56,6 +66,13 @@ void AssistantWebView::InitLayout() {
caption_bar_->set_delegate(this);
caption_bar_->SetButtonVisible(CaptionButtonId::kMinimize, false);
AddChildView(caption_bar_);
// Content mask.
// This is used to enforce corner radius on the contents' layer.
content_view_mask_ = views::Painter::CreatePaintedLayer(
views::Painter::CreateSolidRoundRectPainter(SK_ColorBLACK,
kCornerRadiusDip));
content_view_mask_->layer()->SetFillsBoundsOpaquely(false);
}
bool AssistantWebView::OnCaptionButtonPressed(CaptionButtonId id) {
......@@ -121,6 +138,14 @@ void AssistantWebView::OnWebContentsReady(
if (app_list::AnswerCardContentsRegistry::Get()) {
content_view_ = app_list::AnswerCardContentsRegistry::Get()->GetView(
embed_token.value());
content_view_->AddObserver(this);
// Apply our layer mask which enforces corner radius.
app_list::AnswerCardContentsRegistry::Get()
->GetNativeView(embed_token.value())
->layer()
->SetMaskLayer(content_view_mask_->layer());
AddChildView(content_view_);
}
......
......@@ -12,6 +12,7 @@
#include "base/macros.h"
#include "base/optional.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"
namespace base {
class UnguessableToken;
......@@ -26,6 +27,7 @@ class AssistantController;
// for window level controls and a WebView/ServerRemoteViewHost for embedding
// web contents.
class AssistantWebView : public views::View,
public views::ViewObserver,
public AssistantControllerObserver,
public CaptionBarDelegate {
public:
......@@ -37,6 +39,9 @@ class AssistantWebView : public views::View,
int GetHeightForWidth(int width) const override;
void ChildPreferredSizeChanged(views::View* child) override;
// views::ViewObserver:
void OnViewBoundsChanged(views::View* view) override;
// CaptionBarDelegate:
bool OnCaptionButtonPressed(CaptionButtonId id) override;
......@@ -59,6 +64,12 @@ class AssistantWebView : public views::View,
// view is owned by the WebContentsManager.
views::View* content_view_;
// Our contents are drawn to a layer that is not masked by our widget's layer.
// This causes our contents to ignore the corner radius that we have set on
// the widget. To address this, we apply a separate layer mask to the
// contents' layer enforcing our desired corner radius.
std::unique_ptr<ui::LayerOwner> content_view_mask_;
// Uniquely identifies web contents owned by WebContentsManager.
base::Optional<base::UnguessableToken> web_contents_id_token_;
......
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