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

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: resolve compilation errors 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/material_design/material_design_controller.cc ('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 SkColor kIndicatorColor = SK_ColorWHITE;
46
47 // Canvas scale to ensure that the activity indicator is not pixelated even at
48 // the highest possible device scale factors.
49 const int kIndicatorCanvasScale = 5;
50
51 // Paints an activity indicator on |canvas| whose |size| is specified in DIP.
52 void PaintIndicatorOnCanvas(gfx::Canvas* canvas, const gfx::Size& size) {
53 SkPaint paint;
54 paint.setColor(kIndicatorColor);
55 paint.setFlags(SkPaint::kAntiAlias_Flag);
56 canvas->DrawCircle(
57 gfx::Point(size.width() / 2,
58 size.height() - kIndicatorOffsetFromBottom - kIndicatorRadius),
59 kIndicatorRadius, paint);
60 }
40 61
41 // Simple AnimationDelegate that owns a single ThrobAnimation instance to 62 // Simple AnimationDelegate that owns a single ThrobAnimation instance to
42 // keep all Draw Attention animations in sync. 63 // keep all Draw Attention animations in sync.
43 class ShelfButtonAnimation : public gfx::AnimationDelegate { 64 class ShelfButtonAnimation : public gfx::AnimationDelegate {
44 public: 65 public:
45 class Observer { 66 class Observer {
46 public: 67 public:
47 virtual void AnimationProgressed() = 0; 68 virtual void AnimationProgressed() = 0;
48 69
49 protected: 70 protected:
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 int bar_id = 0; 500 int bar_id = 0;
480 if (state_ & (STATE_ACTIVE)) 501 if (state_ & (STATE_ACTIVE))
481 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 502 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
482 else if (state_ & STATE_ATTENTION) 503 else if (state_ & STATE_ATTENTION)
483 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 504 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
484 else if (state_ & STATE_RUNNING) 505 else if (state_ & STATE_RUNNING)
485 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 506 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
486 507
487 if (bar_id != 0) { 508 if (bar_id != 0) {
488 Shelf* shelf = shelf_view_->shelf(); 509 Shelf* shelf = shelf_view_->shelf();
489 ResourceBundle* rb = &ResourceBundle::GetSharedInstance(); 510 gfx::ImageSkia image;
490 gfx::ImageSkia image = *rb->GetImageNamed(bar_id).ToImageSkia(); 511 if (ash::MaterialDesignController::IsShelfMaterial()) {
512 gfx::Size size(kShelfButtonSize, kShelfSize);
513 gfx::Canvas canvas(size, kIndicatorCanvasScale, true /* is_opaque */);
514 PaintIndicatorOnCanvas(&canvas, size);
515 image = gfx::ImageSkia(canvas.ExtractImageRep());
516 } else {
517 ResourceBundle* rb = &ResourceBundle::GetSharedInstance();
518 image = *rb->GetImageNamed(bar_id).ToImageSkia();
519 }
491 if (!shelf->IsHorizontalAlignment()) { 520 if (!shelf->IsHorizontalAlignment()) {
492 image = gfx::ImageSkiaOperations::CreateRotatedImage( 521 image = gfx::ImageSkiaOperations::CreateRotatedImage(
493 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT 522 image, shelf->alignment() == wm::SHELF_ALIGNMENT_LEFT
494 ? SkBitmapOperations::ROTATION_90_CW 523 ? SkBitmapOperations::ROTATION_90_CW
495 : SkBitmapOperations::ROTATION_270_CW); 524 : SkBitmapOperations::ROTATION_270_CW);
496 } 525 }
497 bar_->SetImage(image); 526 bar_->SetImage(image);
498 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment( 527 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment(
499 views::ImageView::CENTER, views::ImageView::LEADING, 528 views::ImageView::CENTER, views::ImageView::LEADING,
500 views::ImageView::TRAILING)); 529 views::ImageView::TRAILING));
501 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment( 530 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
502 views::ImageView::TRAILING, views::ImageView::CENTER, 531 views::ImageView::TRAILING, views::ImageView::CENTER,
503 views::ImageView::CENTER)); 532 views::ImageView::CENTER));
504 bar_->SchedulePaint(); 533 bar_->SchedulePaint();
505 } 534 }
506
507 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 535 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
508 } 536 }
509 537
510 } // namespace ash 538 } // namespace ash
OLDNEW
« no previous file with comments | « ash/material_design/material_design_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698