Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/common/system/tray/tray_background_view.h" | 5 #include "ash/common/system/tray/tray_background_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 // When becoming visible delay the animation so that StatusAreaWidgetDelegate | 52 // When becoming visible delay the animation so that StatusAreaWidgetDelegate |
| 53 // can animate sibling views out of the position to be occuped by the | 53 // can animate sibling views out of the position to be occuped by the |
| 54 // TrayBackgroundView. | 54 // TrayBackgroundView. |
| 55 const int kShowAnimationDelayMs = 100; | 55 const int kShowAnimationDelayMs = 100; |
| 56 | 56 |
| 57 // Additional padding used to adjust the user-visible size of status tray | 57 // Additional padding used to adjust the user-visible size of status tray |
| 58 // and overview button dark background. | 58 // and overview button dark background. |
| 59 const int kBackgroundAdjustPadding = 3; | 59 const int kBackgroundAdjustPadding = 3; |
| 60 | 60 |
| 61 const gfx::Rect GetBackgroundBounds(const gfx::Rect& local_bounds, | 61 // Switches left and right insets if RTL mode is active. |
|
tdanderson
2016/11/17 23:55:21
Thank you for making sure this works well in RTL!
| |
| 62 ash::ShelfAlignment shelf_alignment) { | 62 void MirrorInsetsIfNecessary(gfx::Insets* insets) { |
| 63 if (base::i18n::IsRTL()) { | |
| 64 insets->Set(insets->top(), insets->right(), insets->bottom(), | |
| 65 insets->left()); | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 // Returns background insets relative to the contents bounds of the view and | |
| 70 // mirrored if RTL mode is active. | |
| 71 gfx::Insets GetMirroredBackgroundInsets(ash::ShelfAlignment shelf_alignment) { | |
| 72 gfx::Insets insets; | |
| 63 if (IsHorizontalAlignment(shelf_alignment)) { | 73 if (IsHorizontalAlignment(shelf_alignment)) { |
| 64 return gfx::Rect(local_bounds.x() + ash::kHitRegionPadding, | 74 insets.Set(0, ash::kHitRegionPadding, 0, |
| 65 local_bounds.y(), | 75 ash::kHitRegionPadding + ash::kSeparatorWidth); |
| 66 local_bounds.width() - ash::kHitRegionPadding - | 76 } else { |
| 67 ash::kHitRegionPadding - ash::kSeparatorWidth, | 77 insets.Set(ash::kHitRegionPadding, 0, |
| 68 local_bounds.height()); | 78 ash::kHitRegionPadding + ash::kSeparatorWidth, 0); |
| 69 } | 79 } |
| 70 return gfx::Rect(local_bounds.x(), local_bounds.y() + ash::kHitRegionPadding, | 80 MirrorInsetsIfNecessary(&insets); |
| 71 local_bounds.width(), | 81 return insets; |
| 72 local_bounds.height() - ash::kHitRegionPadding - | |
| 73 ash::kHitRegionPadding - ash::kSeparatorWidth); | |
| 74 } | 82 } |
| 83 | |
| 75 } // namespace | 84 } // namespace |
| 76 | 85 |
| 77 using views::TrayBubbleView; | 86 using views::TrayBubbleView; |
| 78 | 87 |
| 79 namespace ash { | 88 namespace ash { |
| 80 | 89 |
| 81 // static | 90 // static |
| 82 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; | 91 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; |
| 83 | 92 |
| 84 // Used to track when the anchor widget changes position on screen so that the | 93 // Used to track when the anchor widget changes position on screen so that the |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 | 131 |
| 123 void set_alpha(int alpha) { alpha_ = alpha; } | 132 void set_alpha(int alpha) { alpha_ = alpha; } |
| 124 | 133 |
| 125 private: | 134 private: |
| 126 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } | 135 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } |
| 127 | 136 |
| 128 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { | 137 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { |
| 129 SkPaint background_paint; | 138 SkPaint background_paint; |
| 130 background_paint.setFlags(SkPaint::kAntiAlias_Flag); | 139 background_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 131 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); | 140 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); |
| 132 gfx::Rect local_bounds = view->GetLocalBounds(); | 141 gfx::Insets insets = |
| 133 gfx::Rect bounds = | 142 GetMirroredBackgroundInsets(GetShelf()->GetAlignment()); |
| 134 GetBackgroundBounds(local_bounds, GetShelf()->GetAlignment()); | 143 gfx::Rect bounds = view->GetLocalBounds(); |
| 144 bounds.Inset(insets); | |
| 135 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); | 145 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); |
| 136 | 146 |
| 137 if (draws_active_ && tray_background_view_->is_active()) { | 147 if (draws_active_ && tray_background_view_->is_active()) { |
| 138 SkPaint highlight_paint; | 148 SkPaint highlight_paint; |
| 139 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); | 149 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 140 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); | 150 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); |
| 141 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); | 151 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); |
| 142 } | 152 } |
| 143 } | 153 } |
| 144 | 154 |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 380 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { | 390 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 381 // Return focus to the login view. See crbug.com/120500. | 391 // Return focus to the login view. See crbug.com/120500. |
| 382 views::View* v = GetNextFocusableView(); | 392 views::View* v = GetNextFocusableView(); |
| 383 if (v) | 393 if (v) |
| 384 v->AboutToRequestFocusFromTabTraversal(reverse); | 394 v->AboutToRequestFocusFromTabTraversal(reverse); |
| 385 } | 395 } |
| 386 | 396 |
| 387 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() | 397 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() |
| 388 const { | 398 const { |
| 389 return base::MakeUnique<views::FloodFillInkDropRipple>( | 399 return base::MakeUnique<views::FloodFillInkDropRipple>( |
| 390 GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), | 400 GetInkDropBounds(), GetInkDropCenterBasedOnLastEvent(), |
| 391 GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), | 401 GetInkDropBaseColor(), ink_drop_visible_opacity()); |
| 392 ink_drop_visible_opacity()); | |
| 393 } | 402 } |
| 394 | 403 |
| 395 std::unique_ptr<views::InkDropHighlight> | 404 std::unique_ptr<views::InkDropHighlight> |
| 396 TrayBackgroundView::CreateInkDropHighlight() const { | 405 TrayBackgroundView::CreateInkDropHighlight() const { |
| 397 gfx::Rect bounds = GetBackgroundBounds(GetContentsBounds(), shelf_alignment_); | 406 gfx::Rect bounds = GetInkDropBounds(); |
| 398 std::unique_ptr<views::InkDropHighlight> highlight( | 407 std::unique_ptr<views::InkDropHighlight> highlight( |
| 399 new views::InkDropHighlight(bounds.size(), 0, | 408 new views::InkDropHighlight(bounds.size(), 0, |
| 400 gfx::RectF(bounds).CenterPoint(), | 409 gfx::RectF(bounds).CenterPoint(), |
| 401 GetInkDropBaseColor())); | 410 GetInkDropBaseColor())); |
| 402 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); | 411 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); |
| 403 return highlight; | 412 return highlight; |
| 404 } | 413 } |
| 405 | 414 |
| 406 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { | 415 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { |
| 407 // If there is no ink drop, show "touch feedback". | 416 // If there is no ink drop, show "touch feedback". |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 anchor_insets.top(), | 531 anchor_insets.top(), |
| 523 kBigShadowArrowInteriorThickness - tray_bg_insets.left(), | 532 kBigShadowArrowInteriorThickness - tray_bg_insets.left(), |
| 524 anchor_insets.bottom(), | 533 anchor_insets.bottom(), |
| 525 kBigShadowArrowInteriorThickness - tray_bg_insets.right()); | 534 kBigShadowArrowInteriorThickness - tray_bg_insets.right()); |
| 526 } | 535 } |
| 527 } | 536 } |
| 528 | 537 |
| 529 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() | 538 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() |
| 530 const { | 539 const { |
| 531 return base::MakeUnique<views::RoundRectInkDropMask>( | 540 return base::MakeUnique<views::RoundRectInkDropMask>( |
| 532 size(), GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), | 541 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius); |
| 533 kTrayRoundedBorderRadius); | |
| 534 } | 542 } |
| 535 | 543 |
| 536 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { | 544 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { |
| 537 if (is_active_) | 545 if (is_active_) |
| 538 return false; | 546 return false; |
| 539 | 547 |
| 540 return ActionableView::ShouldEnterPushedState(event); | 548 return ActionableView::ShouldEnterPushedState(event); |
| 541 } | 549 } |
| 542 | 550 |
| 543 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 551 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 paint.setColor(kSeparatorColor); | 591 paint.setColor(kSeparatorColor); |
| 584 paint.setAntiAlias(true); | 592 paint.setAntiAlias(true); |
| 585 | 593 |
| 586 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) | 594 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) |
| 587 : gfx::Rect(y, x, height, width); | 595 : gfx::Rect(y, x, height, width); |
| 588 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); | 596 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); |
| 589 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), | 597 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), |
| 590 rect.bottom_right(), paint); | 598 rect.bottom_right(), paint); |
| 591 } | 599 } |
| 592 | 600 |
| 601 gfx::Insets TrayBackgroundView::GetBackgroundInsets() const { | |
| 602 gfx::Insets insets = GetMirroredBackgroundInsets(shelf_alignment_); | |
| 603 // Convert insets from contents bounds coordinates to local bounds | |
| 604 // coordinates. | |
|
tdanderson
2016/11/17 23:55:21
Please adjust whitespace as discussed.
How about
mohsen
2016/11/18 05:20:56
Done.
| |
| 605 gfx::Insets local_contents_insets = | |
| 606 GetLocalBounds().InsetsFrom(GetContentsBounds()); | |
| 607 MirrorInsetsIfNecessary(&local_contents_insets); | |
| 608 insets += local_contents_insets; | |
| 609 return insets; | |
| 610 } | |
| 611 | |
| 612 gfx::Rect TrayBackgroundView::GetInkDropBounds() const { | |
| 613 gfx::Insets insets = GetBackgroundInsets(); | |
| 614 gfx::Rect bounds = GetLocalBounds(); | |
| 615 bounds.Inset(insets); | |
| 616 // Currently, we don't handle view resize. To compensate for that, enlarge the | |
| 617 // bounds by two tray icons so that ripple looks good even if two more icons | |
| 618 // are added when ripple is active. Note that ink drop mask handles resize | |
| 619 // correctly, so the extra ripple would be clipped. | |
| 620 // TODO(mohsen): Remove this extra size when resize is handled properly (see | |
| 621 // https://crbug.com/666175). | |
|
tdanderson
2016/11/17 23:55:21
Thanks for the informative comment, TODO, and bug.
| |
| 622 const int icon_size = | |
| 623 kTrayIconSize + 2 * GetTrayConstant(TRAY_IMAGE_ITEM_PADDING); | |
| 624 bounds.set_width(bounds.width() + 2 * icon_size); | |
| 625 bounds.set_height(bounds.height() + 2 * icon_size); | |
| 626 return bounds; | |
| 627 } | |
| 628 | |
| 593 } // namespace ash | 629 } // namespace ash |
| OLD | NEW |