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

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 antialias flag to draw circle 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"
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;
40 46
41 // Simple AnimationDelegate that owns a single ThrobAnimation instance to 47 // Simple AnimationDelegate that owns a single ThrobAnimation instance to
42 // keep all Draw Attention animations in sync. 48 // keep all Draw Attention animations in sync.
43 class ShelfButtonAnimation : public gfx::AnimationDelegate { 49 class ShelfButtonAnimation : public gfx::AnimationDelegate {
44 public: 50 public:
45 class Observer { 51 class Observer {
46 public: 52 public:
47 virtual void AnimationProgressed() = 0; 53 virtual void AnimationProgressed() = 0;
48 54
49 protected: 55 protected:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 int bar_id = 0; 485 int bar_id = 0;
480 if (state_ & (STATE_ACTIVE)) 486 if (state_ & (STATE_ACTIVE))
481 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 487 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
482 else if (state_ & STATE_ATTENTION) 488 else if (state_ & STATE_ATTENTION)
483 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 489 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
484 else if (state_ & STATE_RUNNING) 490 else if (state_ & STATE_RUNNING)
485 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 491 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
486 492
487 if (bar_id != 0) { 493 if (bar_id != 0) {
488 Shelf* shelf = shelf_view_->shelf(); 494 Shelf* shelf = shelf_view_->shelf();
489 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 495 gfx::ImageSkia image;
490 gfx::ImageSkia image = *rb->GetImageNamed(bar_id).ToImageSkia(); 496 if (ash::MaterialDesignController::IsMaterial()) {
497 gfx::Size size = gfx::Size(kShelfButtonSize, kShelfSize);
varkha 2016/05/05 14:40:56 nit: Simpler: gfx::Size size(kShelfButtonSize, kSh
yiyix 2016/05/10 19:30:00 Done.
498 // Chrome os is most common to run with 100% or 200% scale as default
varkha 2016/05/05 14:40:56 nit: s/Chrome os/Chrome OS
yiyix 2016/05/10 19:30:00 Done.
499 // setting, and users can zoom in to 200%. So image scale needs to be at
500 // least 4.
varkha 2016/05/05 14:40:56 I suggest moving the scale to be a constant in ano
yiyix 2016/05/10 19:30:00 I like your comment much more. It explains the pur
501 gfx::Canvas canvas(size, 5 /* image scale*/, true /* is_opaque */);
502 PaintIndicatorOnCanvas(&canvas, size);
503 image = gfx::ImageSkia(canvas.ExtractImageRep());
504 } else {
505 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
506 image = *rb->GetImageNamed(bar_id).ToImageSkia();
507 }
491 if (!shelf->IsHorizontalAlignment()) { 508 if (!shelf->IsHorizontalAlignment()) {
492 image = gfx::ImageSkiaOperations::CreateRotatedImage( 509 image = gfx::ImageSkiaOperations::CreateRotatedImage(
493 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT 510 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT
494 ? SkBitmapOperations::ROTATION_90_CW 511 ? SkBitmapOperations::ROTATION_90_CW
495 : SkBitmapOperations::ROTATION_270_CW); 512 : SkBitmapOperations::ROTATION_270_CW);
496 } 513 }
497 bar_->SetImage(image); 514 bar_->SetImage(image);
498 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( 515 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment(
499 views::ImageView::CENTER, views::ImageView::LEADING, 516 views::ImageView::CENTER, views::ImageView::LEADING,
500 views::ImageView::TRAILING)); 517 views::ImageView::TRAILING));
501 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( 518 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
502 views::ImageView::TRAILING, views::ImageView::CENTER, 519 views::ImageView::TRAILING, views::ImageView::CENTER,
503 views::ImageView::CENTER)); 520 views::ImageView::CENTER));
504 bar_->SchedulePaint(); 521 bar_->SchedulePaint();
505 } 522 }
506
507 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 523 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
508 } 524 }
509 525
526 void ShelfButton::PaintIndicatorOnCanvas(gfx::Canvas* canvas,
527 const gfx::Size& size) {
528 SkPaint paint;
529 paint.setColor(kIndicatorColor);
530 paint.setFlags(SkPaint::kAntiAlias_Flag);
531 canvas->DrawCircle(
532 gfx::Point(size.width() / 2,
533 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius),
534 kIndicatorRadius, paint);
535 }
536
510 } // namespace ash 537 } // 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