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

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: address @varkha 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
« no previous file with comments | « 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"
13 #include "ash/shelf/shelf_constants.h"
12 #include "ash/shelf/shelf_view.h" 14 #include "ash/shelf/shelf_view.h"
13 #include "base/time/time.h" 15 #include "base/time/time.h"
14 #include "grit/ash_resources.h" 16 #include "grit/ash_resources.h"
15 #include "skia/ext/image_operations.h" 17 #include "skia/ext/image_operations.h"
18 #include "third_party/skia/include/core/SkPaint.h"
16 #include "ui/accessibility/ax_view_state.h" 19 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/base/resource/resource_bundle.h" 20 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h" 21 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 22 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/events/event_constants.h" 23 #include "ui/events/event_constants.h"
21 #include "ui/gfx/animation/animation_delegate.h" 24 #include "ui/gfx/animation/animation_delegate.h"
22 #include "ui/gfx/animation/throb_animation.h" 25 #include "ui/gfx/animation/throb_animation.h"
23 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/geometry/vector2d.h" 27 #include "ui/gfx/geometry/vector2d.h"
25 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/image/image_skia_operations.h" 29 #include "ui/gfx/image/image_skia_operations.h"
27 #include "ui/gfx/skbitmap_operations.h" 30 #include "ui/gfx/skbitmap_operations.h"
28 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
29 32
30 namespace { 33 namespace {
31 34
32 // Size of the bar. This is along the opposite axis of the shelf. For example, 35 // 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. 36 // if the shelf is aligned horizontally then this is the height of the bar.
34 const int kBarSize = 3; 37 const int kBarSize = 3;
35 const int kIconSize = 32; 38 const int kIconSize = 32;
36 const int kIconPad = 5; 39 const int kIconPad = 5;
37 const int kIconPadVertical = 6; 40 const int kIconPadVertical = 6;
38 const int kAttentionThrobDurationMS = 800; 41 const int kAttentionThrobDurationMS = 800;
39 const int kMaxAnimationSeconds = 10; 42 const int kMaxAnimationSeconds = 10;
43 const int kIndicatorOffsetFromBottom = 2;
44 const int kIndicatorRadius = 2;
45 const int kIndicatorColor = SK_ColorWHITE;
46
47 // Canvas scale to ensures that the activity indicator is not pixelated even at
varkha 2016/05/10 21:04:11 nit: s/ensures/ensure
yiyix 2016/05/13 22:24:11 Done.
48 // the highest possible device scale factors.
49 const int kIndicatorCanvasScale = 5;
40 50
41 // Simple AnimationDelegate that owns a single ThrobAnimation instance to 51 // Simple AnimationDelegate that owns a single ThrobAnimation instance to
42 // keep all Draw Attention animations in sync. 52 // keep all Draw Attention animations in sync.
43 class ShelfButtonAnimation : public gfx::AnimationDelegate { 53 class ShelfButtonAnimation : public gfx::AnimationDelegate {
44 public: 54 public:
45 class Observer { 55 class Observer {
46 public: 56 public:
47 virtual void AnimationProgressed() = 0; 57 virtual void AnimationProgressed() = 0;
48 58
49 protected: 59 protected:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 int bar_id = 0; 489 int bar_id = 0;
480 if (state_ & (STATE_ACTIVE)) 490 if (state_ & (STATE_ACTIVE))
481 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 491 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
482 else if (state_ & STATE_ATTENTION) 492 else if (state_ & STATE_ATTENTION)
483 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 493 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
484 else if (state_ & STATE_RUNNING) 494 else if (state_ & STATE_RUNNING)
485 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 495 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
486 496
487 if (bar_id != 0) { 497 if (bar_id != 0) {
488 Shelf* shelf = shelf_view_->shelf(); 498 Shelf* shelf = shelf_view_->shelf();
489 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 499 gfx::ImageSkia image;
490 gfx::ImageSkia image = *rb->GetImageNamed(bar_id).ToImageSkia(); 500 if (ash::MaterialDesignController::IsMaterial()) {
501 gfx::Size size(kShelfButtonSize, kShelfSize);
502 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */);
503 PaintIndicatorOnCanvas(&canvas, size);
504 image = gfx::ImageSkia(canvas.ExtractImageRep());
505 } else {
506 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
507 image = *rb->GetImageNamed(bar_id).ToImageSkia();
508 }
491 if (!shelf->IsHorizontalAlignment()) { 509 if (!shelf->IsHorizontalAlignment()) {
492 image = gfx::ImageSkiaOperations::CreateRotatedImage( 510 image = gfx::ImageSkiaOperations::CreateRotatedImage(
493 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT 511 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT
494 ? SkBitmapOperations::ROTATION_90_CW 512 ? SkBitmapOperations::ROTATION_90_CW
495 : SkBitmapOperations::ROTATION_270_CW); 513 : SkBitmapOperations::ROTATION_270_CW);
496 } 514 }
497 bar_->SetImage(image); 515 bar_->SetImage(image);
498 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( 516 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment(
499 views::ImageView::CENTER, views::ImageView::LEADING, 517 views::ImageView::CENTER, views::ImageView::LEADING,
500 views::ImageView::TRAILING)); 518 views::ImageView::TRAILING));
501 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( 519 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
502 views::ImageView::TRAILING, views::ImageView::CENTER, 520 views::ImageView::TRAILING, views::ImageView::CENTER,
503 views::ImageView::CENTER)); 521 views::ImageView::CENTER));
504 bar_->SchedulePaint(); 522 bar_->SchedulePaint();
505 } 523 }
506
507 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 524 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
508 } 525 }
509 526
527 void ShelfButton::PaintIndicatorOnCanvas(gfx::Canvas* canvas,
sky 2016/05/12 15:27:03 Make this a non-member function (see Effective C++
yiyix 2016/05/13 22:24:11 Done.
528 const gfx::Size& size) {
529 SkPaint paint;
530 paint.setColor(kIndicatorColor);
531 paint.setFlags(SkPaint::kAntiAlias_Flag);
532 canvas->DrawCircle(
533 gfx::Point(size.width() / 2,
534 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius),
535 kIndicatorRadius, paint);
536 }
537
510 } // namespace ash 538 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_button.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698