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

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 <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
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.
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
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
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
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
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
604 // |insets| are relative to contents bounds. Change them to be relative to
605 // local bounds.
606 gfx::Insets local_contents_insets =
607 GetLocalBounds().InsetsFrom(GetContentsBounds());
608 MirrorInsetsIfNecessary(&local_contents_insets);
609 insets += local_contents_insets;
610
611 return insets;
612 }
613
614 gfx::Rect TrayBackgroundView::GetInkDropBounds() const {
615 gfx::Insets insets = GetBackgroundInsets();
616 gfx::Rect bounds = GetLocalBounds();
617 bounds.Inset(insets);
618 // Currently, we don't handle view resize. To compensate for that, enlarge the
619 // bounds by two tray icons so that ripple looks good even if two more icons
620 // are added when ripple is active. Note that ink drop mask handles resize
621 // correctly, so the extra ripple would be clipped.
622 // TODO(mohsen): Remove this extra size when resize is handled properly (see
623 // https://crbug.com/666175).
624 const int icon_size =
625 kTrayIconSize + 2 * GetTrayConstant(TRAY_IMAGE_ITEM_PADDING);
626 bounds.set_width(bounds.width() + 2 * icon_size);
627 bounds.set_height(bounds.height() + 2 * icon_size);
628 return bounds;
629 }
630
593 } // namespace ash 631 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/tray_background_view.h ('k') | ash/common/system/tray/tray_popup_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698