Skip to content

Commit e49b255

Browse files
Mike WassermanCommit Bot
Mike Wasserman
authored and
Commit Bot
committedFeb 7, 2019
Fix the system tray bubble placement.
The system tray bubble's shadow should not overlap the shelf. This regressed in https://chromium-review.googlesource.com/c/1386432 Add a flag to apply shadow insets before calculating coordinates. This should restore the previous behavior for tray bubbles. Bug: 919645 Test: Tray/volume/etc. bubbles placed correctly for all shelf positions. Change-Id: I3592e73fc67b32dead470e25e14e450fadc08aba Reviewed-on: https://chromium-review.googlesource.com/c/1457434 Commit-Queue: Manu Cornet <[email protected]> Reviewed-by: Manu Cornet <[email protected]> Reviewed-by: Tetsui Ohkubo <[email protected]> Cr-Commit-Position: refs/heads/master@{#629917}
1 parent 04bc411 commit e49b255

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed
 

‎ash/system/tray/tray_bubble_view.cc

+1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ TrayBubbleView::TrayBubbleView(const InitParams& init_params)
217217
bubble_border_->set_use_theme_background_color(!init_params.bg_color);
218218
if (init_params.corner_radius)
219219
bubble_border_->SetCornerRadius(init_params.corner_radius.value());
220+
bubble_border_->set_avoid_shadow_overlap(true);
220221
set_parent_window(params_.parent_window);
221222
SetCanActivate(false);
222223
set_notify_enter_exit_on_child(true);

‎ui/views/bubble/bubble_border.cc

+11-6
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,23 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect,
9191
// In MD, there are no arrows, so positioning logic is significantly simpler.
9292
if (has_arrow(arrow_)) {
9393
gfx::Rect contents_bounds(contents_size);
94-
// Apply the border part of the inset before calculating coordinates because
95-
// the border should align with the anchor's border. For the purposes of
96-
// positioning, the border is rounded up to a dip, which may mean we have
97-
// misalignment in scale factors greater than 1. Borders with custom shadow
98-
// elevations do not draw the 1px border.
94+
// Always apply the border part of the inset before calculating coordinates,
95+
// that ensures the bubble's border is aligned with the anchor's border.
96+
// For the purposes of positioning, the border is rounded up to a dip, which
97+
// may cause misalignment in scale factors greater than 1.
9998
// TODO(estade): when it becomes possible to provide px bounds instead of
10099
// dip bounds, fix this.
100+
// Borders with custom shadow elevations do not draw the 1px border.
101101
const gfx::Insets border_insets =
102102
shadow_ == NO_ASSETS || md_shadow_elevation_.has_value()
103103
? gfx::Insets()
104104
: gfx::Insets(kBorderThicknessDip);
105105
const gfx::Insets shadow_insets = GetInsets() - border_insets;
106106
contents_bounds.Inset(-border_insets);
107+
// If |avoid_shadow_overlap_| is true, the shadow part of the inset is also
108+
// applied now, to ensure that the shadow itself doesn't overlap the anchor.
109+
if (avoid_shadow_overlap_)
110+
contents_bounds.Inset(-shadow_insets);
107111
switch (arrow_) {
108112
case TOP_LEFT:
109113
contents_bounds += anchor_rect.bottom_left() - contents_bounds.origin();
@@ -156,7 +160,8 @@ gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& anchor_rect,
156160
// used to position the bubble origin according to |anchor_rect|.
157161
DCHECK((shadow_ != NO_ASSETS && shadow_ != NO_SHADOW) ||
158162
shadow_insets.IsEmpty());
159-
contents_bounds.Inset(-shadow_insets);
163+
if (!avoid_shadow_overlap_)
164+
contents_bounds.Inset(-shadow_insets);
160165
// |arrow_offset_| is used to adjust bubbles that would normally be
161166
// partially offscreen.
162167
if (is_arrow_on_horizontal(arrow_))

‎ui/views/bubble/bubble_border.h

+4
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class VIEWS_EXPORT BubbleBorder : public Border {
182182
md_shadow_color_ = shadow_color;
183183
}
184184

185+
// Set a flag to avoid the bubble's shadow overlapping the anchor.
186+
void set_avoid_shadow_overlap(bool value) { avoid_shadow_overlap_ = value; }
187+
185188
// Get the desired widget bounds (in screen coordinates) given the anchor rect
186189
// and bubble content size; calculated from shadow and arrow image dimensions.
187190
virtual gfx::Rect GetBounds(const gfx::Rect& anchor_rect,
@@ -245,6 +248,7 @@ class VIEWS_EXPORT BubbleBorder : public Border {
245248
SkColor md_shadow_color_ = SK_ColorBLACK;
246249
SkColor background_color_;
247250
bool use_theme_background_color_;
251+
bool avoid_shadow_overlap_ = false;
248252

249253
DISALLOW_COPY_AND_ASSIGN(BubbleBorder);
250254
};

0 commit comments

Comments
 (0)
Please sign in to comment.