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

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

Issue 1932433002: Update activity indicator from a light bar to a point (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add MaterialDesignController and address comments Created 4 years, 7 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
« ash/shelf/shelf_button.h ('K') | « ash/shelf/shelf_button.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "ash/material_design/material_design_controller.h"
11 #include "ash/shelf/shelf.h" 12 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_view.h" 13 #include "ash/shelf/shelf_view.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "grit/ash_resources.h" 15 #include "grit/ash_resources.h"
15 #include "skia/ext/image_operations.h" 16 #include "skia/ext/image_operations.h"
17 #include "third_party/skia/include/core/SkPaint.h"
16 #include "ui/accessibility/ax_view_state.h" 18 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h" 20 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 21 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/events/event_constants.h" 22 #include "ui/events/event_constants.h"
21 #include "ui/gfx/animation/animation_delegate.h" 23 #include "ui/gfx/animation/animation_delegate.h"
22 #include "ui/gfx/animation/throb_animation.h" 24 #include "ui/gfx/animation/throb_animation.h"
23 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/geometry/vector2d.h" 26 #include "ui/gfx/geometry/vector2d.h"
25 #include "ui/gfx/image/image.h" 27 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/image/image_skia_operations.h" 28 #include "ui/gfx/image/image_skia_operations.h"
27 #include "ui/gfx/skbitmap_operations.h" 29 #include "ui/gfx/skbitmap_operations.h"
28 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
29 31
30 namespace { 32 namespace {
31 33
32 // Size of the bar. This is along the opposite axis of the shelf. For example, 34 // Size of the bar. This is along the opposite axis of the shelf. For example,
33 // if the shelf is aligned horizontally then this is the height of the bar. 35 // if the shelf is aligned horizontally then this is the height of the bar.
34 const int kBarSize = 3; 36 const int kBarSize = 3;
35 const int kIconSize = 32; 37 const int kIconSize = 32;
36 const int kIconPad = 5; 38 const int kIconPad = 5;
37 const int kIconPadVertical = 6; 39 const int kIconPadVertical = 6;
38 const int kAttentionThrobDurationMS = 800; 40 const int kAttentionThrobDurationMS = 800;
39 const int kMaxAnimationSeconds = 10; 41 const int kMaxAnimationSeconds = 10;
42 const int kShelfIconHeight = 48;
varkha 2016/05/02 18:13:58 Is this defined / dependent on a constant that is
yiyix 2016/05/03 18:55:34 You are right, this is defined in shelf_constants.
43 const int kShelfIconWidth = 48;
44 const int kIconInsideVertical = 3;
varkha 2016/05/02 18:13:59 nit: rename kIndicatorOffsetFromBottom.
yiyix 2016/05/03 18:55:34 Done.
45 const int kIndicatorRadius = 2;
46 const int kIndicatorColor = SK_ColorWHITE;
40 47
41 // Simple AnimationDelegate that owns a single ThrobAnimation instance to 48 // Simple AnimationDelegate that owns a single ThrobAnimation instance to
42 // keep all Draw Attention animations in sync. 49 // keep all Draw Attention animations in sync.
43 class ShelfButtonAnimation : public gfx::AnimationDelegate { 50 class ShelfButtonAnimation : public gfx::AnimationDelegate {
44 public: 51 public:
45 class Observer { 52 class Observer {
46 public: 53 public:
47 virtual void AnimationProgressed() = 0; 54 virtual void AnimationProgressed() = 0;
48 55
49 protected: 56 protected:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 int bar_id = 0; 486 int bar_id = 0;
480 if (state_ & (STATE_ACTIVE)) 487 if (state_ & (STATE_ACTIVE))
481 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 488 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
482 else if (state_ & STATE_ATTENTION) 489 else if (state_ & STATE_ATTENTION)
483 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 490 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
484 else if (state_ & STATE_RUNNING) 491 else if (state_ & STATE_RUNNING)
485 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 492 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
486 493
487 if (bar_id != 0) { 494 if (bar_id != 0) {
488 Shelf* shelf = shelf_view_->shelf(); 495 Shelf* shelf = shelf_view_->shelf();
489 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 496 gfx::ImageSkia image;
490 gfx::ImageSkia image = *rb->GetImageNamed(bar_id).ToImageSkia(); 497 if (MaterialDesignController::IsMaterial()) {
tdanderson 2016/05/02 17:58:35 varkha@, side comment: should we consider giving t
varkha 2016/05/02 18:13:58 Would using explicit namespace here help? I think
tdanderson 2016/05/02 18:19:55 Yes, though since there is no way to force all fut
yiyix 2016/05/03 18:55:34 I added ash for this cl.
498 gfx::Canvas canvas(gfx::Size(kShelfIconHeight, kShelfIconWidth),
499 kShelfIconHeight, true /* is_opaque */);
500 GetIndicatorImage(canvas);
501 image = gfx::ImageSkia(canvas.ExtractImageRep());
502
tdanderson 2016/05/02 17:58:35 nit: remove blank line
yiyix 2016/05/03 18:55:34 Done.
503 } else {
504 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
505 image = *rb->GetImageNamed(bar_id).ToImageSkia();
506 }
491 if (!shelf->IsHorizontalAlignment()) { 507 if (!shelf->IsHorizontalAlignment()) {
492 image = gfx::ImageSkiaOperations::CreateRotatedImage( 508 image = gfx::ImageSkiaOperations::CreateRotatedImage(
493 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT 509 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT
494 ? SkBitmapOperations::ROTATION_90_CW 510 ? SkBitmapOperations::ROTATION_90_CW
495 : SkBitmapOperations::ROTATION_270_CW); 511 : SkBitmapOperations::ROTATION_270_CW);
496 } 512 }
497 bar_->SetImage(image); 513 bar_->SetImage(image);
498 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( 514 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment(
499 views::ImageView::CENTER, views::ImageView::LEADING, 515 views::ImageView::CENTER, views::ImageView::LEADING,
500 views::ImageView::TRAILING)); 516 views::ImageView::TRAILING));
501 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( 517 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
502 views::ImageView::TRAILING, views::ImageView::CENTER, 518 views::ImageView::TRAILING, views::ImageView::CENTER,
503 views::ImageView::CENTER)); 519 views::ImageView::CENTER));
504 bar_->SchedulePaint(); 520 bar_->SchedulePaint();
505 } 521 }
506
507 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 522 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
508 } 523 }
509 524
525 void ShelfButton::GetIndicatorImage(gfx::Canvas& canvas) {
tdanderson 2016/05/02 17:58:35 nit: the Google C++ style guide states that refere
yiyix 2016/05/03 18:55:34 Since I am drawing a circle on this canvas, it is
526 SkPaint paint;
527 paint.setColor(kIndicatorColor);
528 int pad_vertical = kIconInsideVertical + kIndicatorRadius;
tdanderson 2016/05/02 17:58:35 extreme nit, possibly personal preference: declare
varkha 2016/05/02 18:13:58 nit: I would just remove the pad_vertical and inli
yiyix 2016/05/03 18:55:34 Done.
529 canvas.DrawCircle(
530 gfx::Point(kShelfIconWidth / 2, kShelfIconHeight - pad_vertical),
varkha 2016/05/02 18:13:59 Would it be safer to use canvas properties instead
yiyix 2016/05/03 18:55:34 Since it is harder to get these properties from ca
531 kIndicatorRadius, paint);
532 }
533
510 } // namespace ash 534 } // namespace ash
OLDNEW
« ash/shelf/shelf_button.h ('K') | « ash/shelf/shelf_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698