Commit 9704fe05 authored by Alex Newcomer's avatar Alex Newcomer Committed by Commit Bot

cros: Remove the 1px BubbleBorder stroke for non default BubbleBorders

Whenever an elevation is set (and the BubbleBorder is no longer
default) remove the 1px border stroke.

This brings the touchable app context menus closer to spec.

Bug: 830929
Change-Id: Ia95af9088e2a7cb17b6195700b9cf73e1d0d9c86
Reviewed-on: https://chromium-review.googlesource.com/1008417
Commit-Queue: Alex Newcomer <newcomer@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550703}
parent 5ab90e02
...@@ -184,10 +184,9 @@ BubbleBorder::~BubbleBorder() {} ...@@ -184,10 +184,9 @@ BubbleBorder::~BubbleBorder() {}
// static // static
gfx::Insets BubbleBorder::GetBorderAndShadowInsets( gfx::Insets BubbleBorder::GetBorderAndShadowInsets(
base::Optional<int> elevation) { base::Optional<int> elevation) {
if (elevation.has_value()) { // Borders with custom shadow elevations do not draw the 1px border.
return -gfx::ShadowValue::GetMargin(GetShadowValues(elevation)) + if (elevation.has_value())
gfx::Insets(kBorderThicknessDip); return -gfx::ShadowValue::GetMargin(GetShadowValues(elevation));
}
constexpr gfx::Insets blur(kShadowBlur + kBorderThicknessDip); constexpr gfx::Insets blur(kShadowBlur + kBorderThicknessDip);
constexpr gfx::Insets offset(-kShadowVerticalOffset, 0, kShadowVerticalOffset, constexpr gfx::Insets offset(-kShadowVerticalOffset, 0, kShadowVerticalOffset,
...@@ -218,11 +217,14 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect, ...@@ -218,11 +217,14 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect,
// Apply the border part of the inset before calculating coordinates because // Apply the border part of the inset before calculating coordinates because
// the border should align with the anchor's border. For the purposes of // the border should align with the anchor's border. For the purposes of
// positioning, the border is rounded up to a dip, which may mean we have // positioning, the border is rounded up to a dip, which may mean we have
// misalignment in scale factors greater than 1. // misalignment in scale factors greater than 1. Borders with custom shadow
// elevations do not draw the 1px border.
// TODO(estade): when it becomes possible to provide px bounds instead of // TODO(estade): when it becomes possible to provide px bounds instead of
// dip bounds, fix this. // dip bounds, fix this.
const gfx::Insets border_insets = const gfx::Insets border_insets =
shadow_ == NO_ASSETS ? gfx::Insets() : gfx::Insets(kBorderThicknessDip); shadow_ == NO_ASSETS || md_shadow_elevation_.has_value()
? gfx::Insets()
: gfx::Insets(kBorderThicknessDip);
const gfx::Insets shadow_insets = GetInsets() - border_insets; const gfx::Insets shadow_insets = GetInsets() - border_insets;
contents_bounds.Inset(-border_insets); contents_bounds.Inset(-border_insets);
if (arrow_ == TOP_RIGHT) { if (arrow_ == TOP_RIGHT) {
......
...@@ -188,11 +188,14 @@ class VIEWS_EXPORT BubbleBorder : public Border { ...@@ -188,11 +188,14 @@ class VIEWS_EXPORT BubbleBorder : public Border {
void (cc::PaintCanvas::*draw)(const T&, const cc::PaintFlags&), void (cc::PaintCanvas::*draw)(const T&, const cc::PaintFlags&),
gfx::Canvas* canvas, gfx::Canvas* canvas,
base::Optional<int> shadow_elevation = base::nullopt) { base::Optional<int> shadow_elevation = base::nullopt) {
// Provide a 1 px border outside the bounds. // Borders with custom shadow elevations do not draw the 1px border.
const int kBorderStrokeThicknessPx = 1; if (!shadow_elevation.has_value()) {
const SkScalar one_pixel = // Provide a 1 px border outside the bounds.
SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); const int kBorderStrokeThicknessPx = 1;
rect.outset(one_pixel, one_pixel); const SkScalar one_pixel =
SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale());
rect.outset(one_pixel, one_pixel);
}
(canvas->sk_canvas()->*draw)(rect, (canvas->sk_canvas()->*draw)(rect,
GetBorderAndShadowFlags(shadow_elevation)); GetBorderAndShadowFlags(shadow_elevation));
......
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