Chromium Code Reviews| Index: ash/common/system/tray/tray_background_view.cc |
| diff --git a/ash/common/system/tray/tray_background_view.cc b/ash/common/system/tray/tray_background_view.cc |
| index 0a0b41ec9839557e1df511169291a552860e33a4..31672a0d2c75ec970ab55afa4c53019829aae491 100644 |
| --- a/ash/common/system/tray/tray_background_view.cc |
| +++ b/ash/common/system/tray/tray_background_view.cc |
| @@ -56,20 +56,16 @@ const int kShowAnimationDelayMs = 100; |
| // and overview button dark background. |
| const int kBackgroundAdjustPadding = 3; |
| -const gfx::Rect GetBackgroundBounds(const gfx::Rect& local_bounds, |
| - ash::ShelfAlignment shelf_alignment) { |
| +// Returns background insets relative to the contents bounds of the view. |
| +gfx::Insets GetBackgroundInsets(ash::ShelfAlignment shelf_alignment) { |
| if (IsHorizontalAlignment(shelf_alignment)) { |
| - return gfx::Rect(local_bounds.x() + ash::kHitRegionPadding, |
| - local_bounds.y(), |
| - local_bounds.width() - ash::kHitRegionPadding - |
| - ash::kHitRegionPadding - ash::kSeparatorWidth, |
| - local_bounds.height()); |
| + return gfx::Insets(0, ash::kHitRegionPadding, 0, |
| + ash::kHitRegionPadding + ash::kSeparatorWidth); |
| } |
| - return gfx::Rect(local_bounds.x(), local_bounds.y() + ash::kHitRegionPadding, |
| - local_bounds.width(), |
| - local_bounds.height() - ash::kHitRegionPadding - |
| - ash::kHitRegionPadding - ash::kSeparatorWidth); |
| + return gfx::Insets(ash::kHitRegionPadding, 0, |
| + ash::kHitRegionPadding + ash::kSeparatorWidth, 0); |
| } |
| + |
| } // namespace |
| using views::TrayBubbleView; |
| @@ -127,9 +123,9 @@ class TrayBackground : public views::Background { |
| SkPaint background_paint; |
| background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| - gfx::Rect local_bounds = view->GetLocalBounds(); |
| - gfx::Rect bounds = |
| - GetBackgroundBounds(local_bounds, GetShelf()->GetAlignment()); |
| + gfx::Insets insets = GetBackgroundInsets(GetShelf()->GetAlignment()); |
| + gfx::Rect bounds = view->GetLocalBounds(); |
| + bounds.Inset(insets); |
| canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); |
| if (draws_active_ && tray_background_view_->is_active()) { |
| @@ -384,14 +380,13 @@ void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() |
| const { |
| return base::MakeUnique<views::FloodFillInkDropRipple>( |
| - GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), |
| - GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), |
| - ink_drop_visible_opacity()); |
| + GetBackgroundBounds(), GetInkDropCenterBasedOnLastEvent(), |
| + GetInkDropBaseColor(), ink_drop_visible_opacity()); |
| } |
| std::unique_ptr<views::InkDropHighlight> |
| TrayBackgroundView::CreateInkDropHighlight() const { |
| - gfx::Rect bounds = GetBackgroundBounds(GetContentsBounds(), shelf_alignment_); |
| + gfx::Rect bounds = GetBackgroundBounds(); |
| std::unique_ptr<views::InkDropHighlight> highlight( |
| new views::InkDropHighlight(bounds.size(), 0, |
| gfx::RectF(bounds).CenterPoint(), |
| @@ -523,11 +518,18 @@ gfx::Insets TrayBackgroundView::GetBubbleAnchorInsets() const { |
| } |
| } |
| +gfx::Insets TrayBackgroundView::GetBackgroundInsets() const { |
| + gfx::Insets insets = ::GetBackgroundInsets(shelf_alignment_); |
| + // Convert insets from contents bounds coordinates to local bounds |
| + // coordinates. |
| + insets += GetLocalBounds().InsetsFrom(GetContentsBounds()); |
| + return insets; |
| +} |
| + |
| std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() |
| const { |
| return base::MakeUnique<views::RoundRectInkDropMask>( |
| - size(), GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), |
| - kTrayRoundedBorderRadius); |
| + size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); |
| } |
| bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { |
| @@ -587,4 +589,21 @@ void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) { |
| rect.bottom_right(), paint); |
| } |
| +gfx::Rect TrayBackgroundView::GetBackgroundBounds() const { |
|
bruthig
2016/11/17 06:31:20
GetBackgroundBounds() doesn't seem accurate here.
mohsen
2016/11/17 20:10:12
With the new changes maybe it is more accurate now
|
| + gfx::Insets insets = GetBackgroundInsets(); |
| + gfx::Rect bounds = GetLocalBounds(); |
| + bounds.Inset(insets); |
| + // Currently, we don't handle view resize. To compensate for that, enlarge the |
| + // bounds by two tray icons so that ripple looks good even if two more icons |
| + // are added when ripple is active. Note that ink drop mask handles resize |
| + // correctly, so the extra ripple would be clipped. |
| + // TODO(mohsen): Remove this extra width when resize is handled properly (see |
| + // https://crbug.com/666175). |
| + const int icon_size = |
| + kTrayIconSize + 2 * GetTrayConstant(TRAY_IMAGE_ITEM_PADDING); |
| + bounds.set_width(bounds.width() + 2 * icon_size); |
| + bounds.set_x(GetMirroredXForRect(bounds)); |
| + return bounds; |
| +} |
| + |
| } // namespace ash |