Commit 34a49bd7 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Round corners of ARC++ notifications during scroll

We have to set insets to ARC++ notification mask so that visible rect
should have appropriate rounded corners during scroll.
Ideally this can be fixed by changing layer ordering of NativeViewHost,
but it's not going to happen soon.

TEST=manual
BUG=866777

Change-Id: Ic4a2dc3c7f56051937dd02ae34fa0ab3bb290c08
Reviewed-on: https://chromium-review.googlesource.com/1215507Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590216}
parent ce4fa1f7
...@@ -346,7 +346,7 @@ void ArcNotificationContentView::UpdateCornerRadius(int top_radius, ...@@ -346,7 +346,7 @@ void ArcNotificationContentView::UpdateCornerRadius(int top_radius,
bottom_radius_ = bottom_radius; bottom_radius_ = bottom_radius;
if (GetWidget()) if (GetWidget())
InstallMask(); UpdateMask();
} }
void ArcNotificationContentView::OnSlideChanged() { void ArcNotificationContentView::OnSlideChanged() {
...@@ -484,7 +484,7 @@ void ArcNotificationContentView::AttachSurface() { ...@@ -484,7 +484,7 @@ void ArcNotificationContentView::AttachSurface() {
// (Re-)create the floating buttons after |surface_| is attached to a widget. // (Re-)create the floating buttons after |surface_| is attached to a widget.
MaybeCreateFloatingControlButtons(); MaybeCreateFloatingControlButtons();
InstallMask(); UpdateMask();
} }
void ArcNotificationContentView::ShowCopiedSurface() { void ArcNotificationContentView::ShowCopiedSurface() {
...@@ -522,18 +522,28 @@ void ArcNotificationContentView::HideCopiedSurface() { ...@@ -522,18 +522,28 @@ void ArcNotificationContentView::HideCopiedSurface() {
// Re-install the mask since the custom mask is unset by // Re-install the mask since the custom mask is unset by
// |::wm::RecreateLayers()| in |ShowCopiedSurface()| method. // |::wm::RecreateLayers()| in |ShowCopiedSurface()| method.
InstallMask(); UpdateMask();
} }
void ArcNotificationContentView::InstallMask() { void ArcNotificationContentView::UpdateMask() {
if (top_radius_ == 0 && bottom_radius_ == 0) { if (top_radius_ == 0 && bottom_radius_ == 0) {
SetCustomMask(nullptr); SetCustomMask(nullptr);
mask_insets_.reset();
return; return;
} }
SetCustomMask(views::Painter::CreatePaintedLayer( gfx::Insets new_insets = GetContentsBounds().InsetsFrom(GetVisibleBounds());
if (mask_insets_ == new_insets)
return;
mask_insets_ = new_insets;
auto mask_painter =
std::make_unique<message_center::NotificationBackgroundPainter>( std::make_unique<message_center::NotificationBackgroundPainter>(
top_radius_, bottom_radius_))); top_radius_, bottom_radius_);
// Set insets to round visible notification corners. https://crbug.com/866777
mask_painter->set_insets(new_insets);
SetCustomMask(views::Painter::CreatePaintedLayer(std::move(mask_painter)));
} }
void ArcNotificationContentView::AddedToWidget() { void ArcNotificationContentView::AddedToWidget() {
...@@ -595,6 +605,9 @@ void ArcNotificationContentView::Layout() { ...@@ -595,6 +605,9 @@ void ArcNotificationContentView::Layout() {
// |views::NativeViewHostAura::ShowWidget()| and |aura::Window::Show()| // |views::NativeViewHostAura::ShowWidget()| and |aura::Window::Show()|
// which has DCHECK the opacity of the window. // which has DCHECK the opacity of the window.
views::NativeViewHost::Layout(); views::NativeViewHost::Layout();
// Reinstall mask to update rounded mask insets. Set null mask unless radius
// is set.
UpdateMask();
// Scale notification surface if necessary. // Scale notification surface if necessary.
gfx::Transform transform; gfx::Transform transform;
......
...@@ -90,7 +90,7 @@ class ArcNotificationContentView ...@@ -90,7 +90,7 @@ class ArcNotificationContentView
void HideCopiedSurface(); void HideCopiedSurface();
// Generates a mask using |top_radius_| and |bottom_radius_| and installs it. // Generates a mask using |top_radius_| and |bottom_radius_| and installs it.
void InstallMask(); void UpdateMask();
// views::NativeViewHost // views::NativeViewHost
void ViewHierarchyChanged( void ViewHierarchyChanged(
...@@ -175,10 +175,13 @@ class ArcNotificationContentView ...@@ -175,10 +175,13 @@ class ArcNotificationContentView
base::string16 accessible_name_; base::string16 accessible_name_;
// Radiuses of rounded corners. These values are used in InstallMask(). // Radiuses of rounded corners. These values are used in UpdateMask().
int top_radius_ = 0; int top_radius_ = 0;
int bottom_radius_ = 0; int bottom_radius_ = 0;
// Current insets of mask layer.
base::Optional<gfx::Insets> mask_insets_;
std::unique_ptr<ui::LayerTreeOwner> surface_copy_; std::unique_ptr<ui::LayerTreeOwner> surface_copy_;
std::unique_ptr<ui::LayerOwner> surface_copy_mask_; std::unique_ptr<ui::LayerOwner> surface_copy_mask_;
......
...@@ -31,7 +31,9 @@ void NotificationBackgroundPainter::Paint(gfx::Canvas* canvas, ...@@ -31,7 +31,9 @@ void NotificationBackgroundPainter::Paint(gfx::Canvas* canvas,
SkScalar radii[8] = {top_radius_, top_radius_, top_radius_, SkScalar radii[8] = {top_radius_, top_radius_, top_radius_,
top_radius_, bottom_radius_, bottom_radius_, top_radius_, bottom_radius_, bottom_radius_,
bottom_radius_, bottom_radius_}; bottom_radius_, bottom_radius_};
path.addRoundRect(gfx::RectToSkRect(gfx::Rect(size)), radii); gfx::Rect rect(size);
rect.Inset(insets_);
path.addRoundRect(gfx::RectToSkRect(rect), radii);
cc::PaintFlags flags; cc::PaintFlags flags;
flags.setAntiAlias(true); flags.setAntiAlias(true);
......
...@@ -26,11 +26,15 @@ class MESSAGE_CENTER_EXPORT NotificationBackgroundPainter ...@@ -26,11 +26,15 @@ class MESSAGE_CENTER_EXPORT NotificationBackgroundPainter
gfx::Size GetMinimumSize() const override; gfx::Size GetMinimumSize() const override;
void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; void Paint(gfx::Canvas* canvas, const gfx::Size& size) override;
void set_insets(const gfx::Insets& insets) { insets_ = insets; }
private: private:
const SkScalar top_radius_; const SkScalar top_radius_;
const SkScalar bottom_radius_; const SkScalar bottom_radius_;
const SkColor color_; const SkColor color_;
gfx::Insets insets_;
DISALLOW_COPY_AND_ASSIGN(NotificationBackgroundPainter); DISALLOW_COPY_AND_ASSIGN(NotificationBackgroundPainter);
}; };
......
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