Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: ash/common/system/tray/tray_background_view.cc

Issue 2510603003: Add ink drop ripple to status tray (Closed)
Patch Set: Addressed review comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ash/common/material_design/material_design_controller.h" 7 #include "ash/common/material_design/material_design_controller.h"
8 #include "ash/common/shelf/shelf_constants.h" 8 #include "ash/common/shelf/shelf_constants.h"
9 #include "ash/common/shelf/wm_shelf.h" 9 #include "ash/common/shelf/wm_shelf.h"
10 #include "ash/common/shelf/wm_shelf_util.h" 10 #include "ash/common/shelf/wm_shelf_util.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 // When becoming visible delay the animation so that StatusAreaWidgetDelegate 50 // When becoming visible delay the animation so that StatusAreaWidgetDelegate
51 // can animate sibling views out of the position to be occuped by the 51 // can animate sibling views out of the position to be occuped by the
52 // TrayBackgroundView. 52 // TrayBackgroundView.
53 const int kShowAnimationDelayMs = 100; 53 const int kShowAnimationDelayMs = 100;
54 54
55 // Additional padding used to adjust the user-visible size of status tray 55 // Additional padding used to adjust the user-visible size of status tray
56 // and overview button dark background. 56 // and overview button dark background.
57 const int kBackgroundAdjustPadding = 3; 57 const int kBackgroundAdjustPadding = 3;
58 58
59 const gfx::Rect GetBackgroundBounds(const gfx::Rect& local_bounds, 59 // Switches left and right insets if RTL mode is active.
60 ash::ShelfAlignment shelf_alignment) { 60 void MirrorInsetsIfNecessary(gfx::Insets* insets) {
61 if (base::i18n::IsRTL()) {
62 insets->Set(insets->top(), insets->right(), insets->bottom(),
63 insets->left());
64 }
65 }
66
67 // Returns background insets relative to the contents bounds of the view and
68 // mirrored if RTL mode is active.
69 gfx::Insets GetMirroredBackgroundInsets(ash::ShelfAlignment shelf_alignment) {
70 gfx::Insets insets;
61 if (IsHorizontalAlignment(shelf_alignment)) { 71 if (IsHorizontalAlignment(shelf_alignment)) {
62 return gfx::Rect(local_bounds.x() + ash::kHitRegionPadding, 72 insets.Set(0, ash::kHitRegionPadding, 0,
63 local_bounds.y(), 73 ash::kHitRegionPadding + ash::kSeparatorWidth);
64 local_bounds.width() - ash::kHitRegionPadding - 74 } else {
65 ash::kHitRegionPadding - ash::kSeparatorWidth, 75 insets.Set(ash::kHitRegionPadding, 0,
66 local_bounds.height()); 76 ash::kHitRegionPadding + ash::kSeparatorWidth, 0);
67 } 77 }
68 return gfx::Rect(local_bounds.x(), local_bounds.y() + ash::kHitRegionPadding, 78 MirrorInsetsIfNecessary(&insets);
69 local_bounds.width(), 79 return insets;
70 local_bounds.height() - ash::kHitRegionPadding -
71 ash::kHitRegionPadding - ash::kSeparatorWidth);
72 } 80 }
81
73 } // namespace 82 } // namespace
74 83
75 using views::TrayBubbleView; 84 using views::TrayBubbleView;
76 85
77 namespace ash { 86 namespace ash {
78 87
79 // static 88 // static
80 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; 89 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
81 90
82 // Used to track when the anchor widget changes position on screen so that the 91 // 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
120 129
121 void set_alpha(int alpha) { alpha_ = alpha; } 130 void set_alpha(int alpha) { alpha_ = alpha; }
122 131
123 private: 132 private:
124 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } 133 WmShelf* GetShelf() const { return tray_background_view_->shelf(); }
125 134
126 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { 135 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const {
127 SkPaint background_paint; 136 SkPaint background_paint;
128 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 137 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
129 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); 138 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_));
130 gfx::Rect local_bounds = view->GetLocalBounds(); 139 gfx::Insets insets =
131 gfx::Rect bounds = 140 GetMirroredBackgroundInsets(GetShelf()->GetAlignment());
132 GetBackgroundBounds(local_bounds, GetShelf()->GetAlignment()); 141 gfx::Rect bounds = view->GetLocalBounds();
142 bounds.Inset(insets);
133 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); 143 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint);
134 144
135 if (draws_active_ && tray_background_view_->is_active()) { 145 if (draws_active_ && tray_background_view_->is_active()) {
136 SkPaint highlight_paint; 146 SkPaint highlight_paint;
137 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); 147 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
138 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); 148 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
139 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); 149 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint);
140 } 150 }
141 } 151 }
142 152
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { 387 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
378 // Return focus to the login view. See crbug.com/120500. 388 // Return focus to the login view. See crbug.com/120500.
379 views::View* v = GetNextFocusableView(); 389 views::View* v = GetNextFocusableView();
380 if (v) 390 if (v)
381 v->AboutToRequestFocusFromTabTraversal(reverse); 391 v->AboutToRequestFocusFromTabTraversal(reverse);
382 } 392 }
383 393
384 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() 394 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple()
385 const { 395 const {
386 return base::MakeUnique<views::FloodFillInkDropRipple>( 396 return base::MakeUnique<views::FloodFillInkDropRipple>(
387 GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), 397 GetBackgroundBounds(), GetInkDropCenterBasedOnLastEvent(),
388 GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), 398 GetInkDropBaseColor(), ink_drop_visible_opacity());
389 ink_drop_visible_opacity());
390 } 399 }
391 400
392 std::unique_ptr<views::InkDropHighlight> 401 std::unique_ptr<views::InkDropHighlight>
393 TrayBackgroundView::CreateInkDropHighlight() const { 402 TrayBackgroundView::CreateInkDropHighlight() const {
394 gfx::Rect bounds = GetBackgroundBounds(GetContentsBounds(), shelf_alignment_); 403 gfx::Rect bounds = GetBackgroundBounds();
395 std::unique_ptr<views::InkDropHighlight> highlight( 404 std::unique_ptr<views::InkDropHighlight> highlight(
396 new views::InkDropHighlight(bounds.size(), 0, 405 new views::InkDropHighlight(bounds.size(), 0,
397 gfx::RectF(bounds).CenterPoint(), 406 gfx::RectF(bounds).CenterPoint(),
398 GetInkDropBaseColor())); 407 GetInkDropBaseColor()));
399 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); 408 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity);
400 return highlight; 409 return highlight;
401 } 410 }
402 411
403 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { 412 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
404 // If there is no ink drop, show "touch feedback". 413 // If there is no ink drop, show "touch feedback".
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 anchor_insets.top(), 528 anchor_insets.top(),
520 kBigShadowArrowInteriorThickness - tray_bg_insets.left(), 529 kBigShadowArrowInteriorThickness - tray_bg_insets.left(),
521 anchor_insets.bottom(), 530 anchor_insets.bottom(),
522 kBigShadowArrowInteriorThickness - tray_bg_insets.right()); 531 kBigShadowArrowInteriorThickness - tray_bg_insets.right());
523 } 532 }
524 } 533 }
525 534
526 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() 535 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask()
527 const { 536 const {
528 return base::MakeUnique<views::RoundRectInkDropMask>( 537 return base::MakeUnique<views::RoundRectInkDropMask>(
529 size(), GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), 538 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius);
530 kTrayRoundedBorderRadius);
531 } 539 }
532 540
533 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { 541 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) {
534 if (is_active_) 542 if (is_active_)
535 return false; 543 return false;
536 544
537 return ActionableView::ShouldEnterPushedState(event); 545 return ActionableView::ShouldEnterPushedState(event);
538 } 546 }
539 547
540 bool TrayBackgroundView::PerformAction(const ui::Event& event) { 548 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 paint.setColor(kSeparatorColor); 588 paint.setColor(kSeparatorColor);
581 paint.setAntiAlias(true); 589 paint.setAntiAlias(true);
582 590
583 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) 591 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
584 : gfx::Rect(y, x, height, width); 592 : gfx::Rect(y, x, height, width);
585 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); 593 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
586 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), 594 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
587 rect.bottom_right(), paint); 595 rect.bottom_right(), paint);
588 } 596 }
589 597
598 gfx::Insets TrayBackgroundView::GetBackgroundInsets() const {
599 gfx::Insets insets = GetMirroredBackgroundInsets(shelf_alignment_);
600 // Convert insets from contents bounds coordinates to local bounds
601 // coordinates.
602 gfx::Insets local_contents_insets =
603 GetLocalBounds().InsetsFrom(GetContentsBounds());
604 MirrorInsetsIfNecessary(&local_contents_insets);
605 insets += local_contents_insets;
606 return insets;
607 }
608
609 gfx::Rect TrayBackgroundView::GetBackgroundBounds() const {
610 gfx::Insets insets = GetBackgroundInsets();
611 gfx::Rect bounds = GetLocalBounds();
612 bounds.Inset(insets);
613 // Currently, we don't handle view resize. To compensate for that, enlarge the
614 // bounds by two tray icons so that ripple looks good even if two more icons
615 // are added when ripple is active. Note that ink drop mask handles resize
616 // correctly, so the extra ripple would be clipped.
617 // TODO(mohsen): Remove this extra size when resize is handled properly (see
618 // https://crbug.com/666175).
619 const int icon_size =
620 kTrayIconSize + 2 * GetTrayConstant(TRAY_IMAGE_ITEM_PADDING);
621 bounds.set_width(bounds.width() + 2 * icon_size);
622 bounds.set_height(bounds.height() + 2 * icon_size);
623 return bounds;
624 }
625
590 } // namespace ash 626 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698