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

Side by Side Diff: ash/shelf/shelf_button.cc

Issue 2033553003: Add MD ink drop ripple to shelf app items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased (after r398375) Created 4 years, 6 months 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/shelf/shelf_button.h" 5 #include "ash/shelf/shelf_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
(...skipping 10 matching lines...) Expand all
21 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
22 #include "ui/compositor/scoped_layer_animation_settings.h" 22 #include "ui/compositor/scoped_layer_animation_settings.h"
23 #include "ui/events/event_constants.h" 23 #include "ui/events/event_constants.h"
24 #include "ui/gfx/animation/animation_delegate.h" 24 #include "ui/gfx/animation/animation_delegate.h"
25 #include "ui/gfx/animation/throb_animation.h" 25 #include "ui/gfx/animation/throb_animation.h"
26 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/geometry/vector2d.h" 27 #include "ui/gfx/geometry/vector2d.h"
28 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
29 #include "ui/gfx/image/image_skia_operations.h" 29 #include "ui/gfx/image/image_skia_operations.h"
30 #include "ui/gfx/skbitmap_operations.h" 30 #include "ui/gfx/skbitmap_operations.h"
31 #include "ui/views/animation/square_ink_drop_ripple.h"
31 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
32 33
33 namespace { 34 namespace {
34 35
35 // Size of the bar. This is along the opposite axis of the shelf. For example, 36 // Size of the bar. This is along the opposite axis of the shelf. For example,
36 // if the shelf is aligned horizontally then this is the height of the bar. 37 // if the shelf is aligned horizontally then this is the height of the bar.
37 const int kBarSize = 3; 38 const int kBarSize = 3;
38 const int kIconSize = 32; 39 const int kIconSize = 32;
39 const int kIconPad = 5; 40 const int kIconPad = 5;
40 const int kIconPadVertical = 6; 41 const int kIconPadVertical = 6;
41 const int kAttentionThrobDurationMS = 800; 42 const int kAttentionThrobDurationMS = 800;
42 const int kMaxAnimationSeconds = 10; 43 const int kMaxAnimationSeconds = 10;
43 const int kIndicatorOffsetFromBottom = 2; 44 const int kIndicatorOffsetFromBottom = 2;
44 const int kIndicatorRadius = 2; 45 const int kIndicatorRadius = 2;
45 const SkColor kIndicatorColor = SK_ColorWHITE; 46 const SkColor kIndicatorColor = SK_ColorWHITE;
46 47
47 // Canvas scale to ensure that the activity indicator is not pixelated even at 48 // Canvas scale to ensure that the activity indicator is not pixelated even at
48 // the highest possible device scale factors. 49 // the highest possible device scale factors.
49 const int kIndicatorCanvasScale = 5; 50 const int kIndicatorCanvasScale = 5;
50 51
52 // Shelf item ripple constants.
53 const int kInkDropSmallSize = 48;
54 const int kInkDropLargeSize = 60;
55 const int kInkDropLargeCornerRadius = 4;
56 const SkColor kInkDropBaseColor = SK_ColorWHITE;
57
51 // Paints an activity indicator on |canvas| whose |size| is specified in DIP. 58 // Paints an activity indicator on |canvas| whose |size| is specified in DIP.
52 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) { 59 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) {
53 SkPaint paint; 60 SkPaint paint;
54 paint.setColor(kIndicatorColor); 61 paint.setColor(kIndicatorColor);
55 paint.setFlags(SkPaint::kAntiAlias_Flag); 62 paint.setFlags(SkPaint::kAntiAlias_Flag);
56 canvas->DrawCircle( 63 canvas->DrawCircle(
57 gfx::Point(size.width() / 2, 64 gfx::Point(size.width() / 2,
58 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius), 65 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius),
59 kIndicatorRadius, paint); 66 kIndicatorRadius, paint);
60 } 67 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 DISALLOW_COPY_AND_ASSIGN(BarView); 243 DISALLOW_COPY_AND_ASSIGN(BarView);
237 }; 244 };
238 245
239 //////////////////////////////////////////////////////////////////////////////// 246 ////////////////////////////////////////////////////////////////////////////////
240 // ShelfButton 247 // ShelfButton
241 248
242 // static 249 // static
243 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; 250 const char ShelfButton::kViewClassName[] = "ash/ShelfButton";
244 251
245 ShelfButton::ShelfButton(ShelfView* shelf_view) 252 ShelfButton::ShelfButton(ShelfView* shelf_view)
246 : CustomButton(shelf_view), 253 : CustomButton(nullptr),
247 shelf_view_(shelf_view), 254 shelf_view_(shelf_view),
248 icon_view_(new views::ImageView()), 255 icon_view_(new views::ImageView()),
249 bar_(new BarView(shelf_view->shelf())), 256 bar_(new BarView(shelf_view->shelf())),
250 state_(STATE_NORMAL), 257 state_(STATE_NORMAL),
251 destroyed_flag_(nullptr) { 258 destroyed_flag_(nullptr) {
252 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); 259 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY);
260 if (ash::MaterialDesignController::IsShelfMaterial()) {
261 SetHasInkDrop(true);
262 set_ink_drop_base_color(kInkDropBaseColor);
263 }
253 264
254 const gfx::ShadowValue kShadows[] = { 265 const gfx::ShadowValue kShadows[] = {
255 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), 266 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)),
256 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), 267 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)),
257 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), 268 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)),
258 }; 269 };
259 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); 270 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows));
260 271
261 // TODO: refactor the layers so each button doesn't require 2. 272 // TODO: refactor the layers so each button doesn't require 2.
262 icon_view_->SetPaintToLayer(true); 273 icon_view_->SetPaintToLayer(true);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 Layout(); 336 Layout();
326 if (state & STATE_ATTENTION) 337 if (state & STATE_ATTENTION)
327 bar_->ShowAttention(false); 338 bar_->ShowAttention(false);
328 } 339 }
329 } 340 }
330 341
331 gfx::Rect ShelfButton::GetIconBounds() const { 342 gfx::Rect ShelfButton::GetIconBounds() const {
332 return icon_view_->bounds(); 343 return icon_view_->bounds();
333 } 344 }
334 345
346 void ShelfButton::OnDragStarted() {
347 AnimateInkDrop(views::InkDropState::HIDDEN);
348 }
349
335 void ShelfButton::ShowContextMenu(const gfx::Point& p, 350 void ShelfButton::ShowContextMenu(const gfx::Point& p,
336 ui::MenuSourceType source_type) { 351 ui::MenuSourceType source_type) {
337 if (!context_menu_controller()) 352 if (!context_menu_controller())
338 return; 353 return;
339 354
340 bool destroyed = false; 355 bool destroyed = false;
341 destroyed_flag_ = &destroyed; 356 destroyed_flag_ = &destroyed;
342 357
343 CustomButton::ShowContextMenu(p, source_type); 358 CustomButton::ShowContextMenu(p, source_type);
344 359
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 case ui::ET_GESTURE_SCROLL_END: 489 case ui::ET_GESTURE_SCROLL_END:
475 case ui::ET_SCROLL_FLING_START: 490 case ui::ET_SCROLL_FLING_START:
476 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false); 491 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false);
477 event->SetHandled(); 492 event->SetHandled();
478 return; 493 return;
479 default: 494 default:
480 return CustomButton::OnGestureEvent(event); 495 return CustomButton::OnGestureEvent(event);
481 } 496 }
482 } 497 }
483 498
499 std::unique_ptr<views::InkDropRipple> ShelfButton::CreateInkDropRipple() const {
500 return base::WrapUnique(new views::SquareInkDropRipple(
501 gfx::Size(kInkDropLargeSize, kInkDropLargeSize),
502 kInkDropLargeCornerRadius,
503 gfx::Size(kInkDropSmallSize, kInkDropSmallSize),
504 kInkDropSmallCornerRadius, GetInkDropCenter(), GetInkDropBaseColor()));
505 }
506
507 bool ShelfButton::ShouldEnterPushedState(const ui::Event& event) {
508 if (shelf_view_->WillIgnoreEventOnButton(this, event))
509 return false;
510
511 return CustomButton::ShouldEnterPushedState(event);
512 }
513
514 bool ShelfButton::ShouldShowInkDropHighlight() const {
bruthig 2016/06/09 03:25:59 I can't remember what we discussed in person. Am
mohsen 2016/06/09 21:24:50 Yes. We don't want hover effect on shelf buttons.
bruthig 2016/06/10 15:25:19 Acknowledged.
515 return false;
516 }
517
518 void ShelfButton::NotifyClick(const ui::Event& event) {
519 CustomButton::NotifyClick(event);
520 shelf_view_->ButtonPressed(this, event, ink_drop());
521 }
522
484 void ShelfButton::UpdateState() { 523 void ShelfButton::UpdateState() {
485 UpdateBar(); 524 UpdateBar();
486 Shelf* shelf = shelf_view_->shelf(); 525 Shelf* shelf = shelf_view_->shelf();
487 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue( 526 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue(
488 views::ImageView::CENTER, views::ImageView::LEADING)); 527 views::ImageView::CENTER, views::ImageView::LEADING));
489 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue( 528 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue(
490 views::ImageView::LEADING, views::ImageView::CENTER)); 529 views::ImageView::LEADING, views::ImageView::CENTER));
491 SchedulePaint(); 530 SchedulePaint();
492 } 531 }
493 532
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 views::ImageView::TRAILING)); 568 views::ImageView::TRAILING));
530 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( 569 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
531 views::ImageView::TRAILING, views::ImageView::CENTER, 570 views::ImageView::TRAILING, views::ImageView::CENTER,
532 views::ImageView::CENTER)); 571 views::ImageView::CENTER));
533 bar_->SchedulePaint(); 572 bar_->SchedulePaint();
534 } 573 }
535 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 574 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
536 } 575 }
537 576
538 } // namespace ash 577 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698