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

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

Issue 2510603003: Add ink drop ripple to status tray (Closed)
Patch Set: 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 // Returns background insets relative to the contents bounds of the view.
60 ash::ShelfAlignment shelf_alignment) { 60 gfx::Insets GetBackgroundInsets(ash::ShelfAlignment shelf_alignment) {
61 if (IsHorizontalAlignment(shelf_alignment)) { 61 if (IsHorizontalAlignment(shelf_alignment)) {
62 return gfx::Rect(local_bounds.x() + ash::kHitRegionPadding, 62 return gfx::Insets(0, ash::kHitRegionPadding, 0,
63 local_bounds.y(), 63 ash::kHitRegionPadding + ash::kSeparatorWidth);
64 local_bounds.width() - ash::kHitRegionPadding -
65 ash::kHitRegionPadding - ash::kSeparatorWidth,
66 local_bounds.height());
67 } 64 }
68 return gfx::Rect(local_bounds.x(), local_bounds.y() + ash::kHitRegionPadding, 65 return gfx::Insets(ash::kHitRegionPadding, 0,
69 local_bounds.width(), 66 ash::kHitRegionPadding + ash::kSeparatorWidth, 0);
70 local_bounds.height() - ash::kHitRegionPadding -
71 ash::kHitRegionPadding - ash::kSeparatorWidth);
72 } 67 }
68
73 } // namespace 69 } // namespace
74 70
75 using views::TrayBubbleView; 71 using views::TrayBubbleView;
76 72
77 namespace ash { 73 namespace ash {
78 74
79 // static 75 // static
80 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView"; 76 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
81 77
82 // Used to track when the anchor widget changes position on screen so that the 78 // 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 116
121 void set_alpha(int alpha) { alpha_ = alpha; } 117 void set_alpha(int alpha) { alpha_ = alpha; }
122 118
123 private: 119 private:
124 WmShelf* GetShelf() const { return tray_background_view_->shelf(); } 120 WmShelf* GetShelf() const { return tray_background_view_->shelf(); }
125 121
126 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const { 122 void PaintMaterial(gfx::Canvas* canvas, views::View* view) const {
127 SkPaint background_paint; 123 SkPaint background_paint;
128 background_paint.setFlags(SkPaint::kAntiAlias_Flag); 124 background_paint.setFlags(SkPaint::kAntiAlias_Flag);
129 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_)); 125 background_paint.setColor(SkColorSetA(kShelfBaseColor, alpha_));
130 gfx::Rect local_bounds = view->GetLocalBounds(); 126 gfx::Insets insets = GetBackgroundInsets(GetShelf()->GetAlignment());
131 gfx::Rect bounds = 127 gfx::Rect bounds = view->GetLocalBounds();
132 GetBackgroundBounds(local_bounds, GetShelf()->GetAlignment()); 128 bounds.Inset(insets);
133 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint); 129 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, background_paint);
134 130
135 if (draws_active_ && tray_background_view_->is_active()) { 131 if (draws_active_ && tray_background_view_->is_active()) {
136 SkPaint highlight_paint; 132 SkPaint highlight_paint;
137 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag); 133 highlight_paint.setFlags(SkPaint::kAntiAlias_Flag);
138 highlight_paint.setColor(kShelfButtonActivatedHighlightColor); 134 highlight_paint.setColor(kShelfButtonActivatedHighlightColor);
139 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint); 135 canvas->DrawRoundRect(bounds, kTrayRoundedBorderRadius, highlight_paint);
140 } 136 }
141 } 137 }
142 138
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { 373 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
378 // Return focus to the login view. See crbug.com/120500. 374 // Return focus to the login view. See crbug.com/120500.
379 views::View* v = GetNextFocusableView(); 375 views::View* v = GetNextFocusableView();
380 if (v) 376 if (v)
381 v->AboutToRequestFocusFromTabTraversal(reverse); 377 v->AboutToRequestFocusFromTabTraversal(reverse);
382 } 378 }
383 379
384 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple() 380 std::unique_ptr<views::InkDropRipple> TrayBackgroundView::CreateInkDropRipple()
385 const { 381 const {
386 return base::MakeUnique<views::FloodFillInkDropRipple>( 382 return base::MakeUnique<views::FloodFillInkDropRipple>(
387 GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), 383 GetBackgroundBounds(), GetInkDropCenterBasedOnLastEvent(),
388 GetInkDropCenterBasedOnLastEvent(), GetInkDropBaseColor(), 384 GetInkDropBaseColor(), ink_drop_visible_opacity());
389 ink_drop_visible_opacity());
390 } 385 }
391 386
392 std::unique_ptr<views::InkDropHighlight> 387 std::unique_ptr<views::InkDropHighlight>
393 TrayBackgroundView::CreateInkDropHighlight() const { 388 TrayBackgroundView::CreateInkDropHighlight() const {
394 gfx::Rect bounds = GetBackgroundBounds(GetContentsBounds(), shelf_alignment_); 389 gfx::Rect bounds = GetBackgroundBounds();
395 std::unique_ptr<views::InkDropHighlight> highlight( 390 std::unique_ptr<views::InkDropHighlight> highlight(
396 new views::InkDropHighlight(bounds.size(), 0, 391 new views::InkDropHighlight(bounds.size(), 0,
397 gfx::RectF(bounds).CenterPoint(), 392 gfx::RectF(bounds).CenterPoint(),
398 GetInkDropBaseColor())); 393 GetInkDropBaseColor()));
399 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity); 394 highlight->set_visible_opacity(kTrayPopupInkDropHighlightOpacity);
400 return highlight; 395 return highlight;
401 } 396 }
402 397
403 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) { 398 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
404 // If there is no ink drop, show "touch feedback". 399 // If there is no ink drop, show "touch feedback".
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 anchor_insets.right()); 511 anchor_insets.right());
517 } else { 512 } else {
518 return gfx::Insets( 513 return gfx::Insets(
519 anchor_insets.top(), 514 anchor_insets.top(),
520 kBigShadowArrowInteriorThickness - tray_bg_insets.left(), 515 kBigShadowArrowInteriorThickness - tray_bg_insets.left(),
521 anchor_insets.bottom(), 516 anchor_insets.bottom(),
522 kBigShadowArrowInteriorThickness - tray_bg_insets.right()); 517 kBigShadowArrowInteriorThickness - tray_bg_insets.right());
523 } 518 }
524 } 519 }
525 520
521 gfx::Insets TrayBackgroundView::GetBackgroundInsets() const {
522 gfx::Insets insets = ::GetBackgroundInsets(shelf_alignment_);
523 // Convert insets from contents bounds coordinates to local bounds
524 // coordinates.
525 insets += GetLocalBounds().InsetsFrom(GetContentsBounds());
526 return insets;
527 }
528
526 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask() 529 std::unique_ptr<views::InkDropMask> TrayBackgroundView::CreateInkDropMask()
527 const { 530 const {
528 return base::MakeUnique<views::RoundRectInkDropMask>( 531 return base::MakeUnique<views::RoundRectInkDropMask>(
529 size(), GetBackgroundBounds(GetContentsBounds(), shelf_alignment_), 532 size(), GetBackgroundInsets(), kTrayRoundedBorderRadius);
530 kTrayRoundedBorderRadius);
531 } 533 }
532 534
533 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) { 535 bool TrayBackgroundView::ShouldEnterPushedState(const ui::Event& event) {
534 if (is_active_) 536 if (is_active_)
535 return false; 537 return false;
536 538
537 return ActionableView::ShouldEnterPushedState(event); 539 return ActionableView::ShouldEnterPushedState(event);
538 } 540 }
539 541
540 bool TrayBackgroundView::PerformAction(const ui::Event& event) { 542 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 paint.setColor(kSeparatorColor); 582 paint.setColor(kSeparatorColor);
581 paint.setAntiAlias(true); 583 paint.setAntiAlias(true);
582 584
583 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height) 585 const gfx::Rect bounds = horizontal_shelf ? gfx::Rect(x, y, width, height)
584 : gfx::Rect(y, x, height, width); 586 : gfx::Rect(y, x, height, width);
585 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale)); 587 gfx::RectF rect(gfx::ScaleRect(gfx::RectF(bounds), scale));
586 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(), 588 canvas->DrawLine(horizontal_shelf ? rect.top_right() : rect.bottom_left(),
587 rect.bottom_right(), paint); 589 rect.bottom_right(), paint);
588 } 590 }
589 591
592 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
593 gfx::Insets insets = GetBackgroundInsets();
594 gfx::Rect bounds = GetLocalBounds();
595 bounds.Inset(insets);
596 // Currently, we don't handle view resize. To compensate for that, enlarge the
597 // bounds by two tray icons so that ripple looks good even if two more icons
598 // are added when ripple is active. Note that ink drop mask handles resize
599 // correctly, so the extra ripple would be clipped.
600 // TODO(mohsen): Remove this extra width when resize is handled properly (see
601 // https://crbug.com/666175).
602 const int icon_size =
603 kTrayIconSize + 2 * GetTrayConstant(TRAY_IMAGE_ITEM_PADDING);
604 bounds.set_width(bounds.width() + 2 * icon_size);
605 bounds.set_x(GetMirroredXForRect(bounds));
606 return bounds;
607 }
608
590 } // namespace ash 609 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698