OLD | NEW |
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/frame/caption_buttons/frame_caption_button.h" | 5 #include "ash/frame/caption_buttons/frame_caption_button.h" |
6 | 6 |
7 #include "ui/base/resource/resource_bundle.h" | |
8 #include "ui/gfx/animation/slide_animation.h" | 7 #include "ui/gfx/animation/slide_animation.h" |
9 #include "ui/gfx/animation/throb_animation.h" | 8 #include "ui/gfx/animation/throb_animation.h" |
10 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/color_palette.h" |
| 11 #include "ui/gfx/paint_vector_icon.h" |
| 12 #include "ui/gfx/vector_icons_public.h" |
11 | 13 |
12 namespace ash { | 14 namespace ash { |
13 | 15 |
14 namespace { | 16 namespace { |
15 | 17 |
16 // The duration of the crossfade animation when swapping the button's images. | 18 // The duration of the crossfade animation when swapping the button's images. |
17 const int kSwapImagesAnimationDurationMs = 200; | 19 const int kSwapImagesAnimationDurationMs = 200; |
18 | 20 |
19 // The duration of the fade out animation of the old icon during a crossfade | 21 // The duration of the fade out animation of the old icon during a crossfade |
20 // animation as a ratio of |kSwapImagesAnimationDurationMs|. | 22 // animation as a ratio of |kSwapImagesAnimationDurationMs|. |
(...skipping 12 matching lines...) Expand all Loading... |
33 } // namespace | 35 } // namespace |
34 | 36 |
35 // static | 37 // static |
36 const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton"; | 38 const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton"; |
37 | 39 |
38 FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, | 40 FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, |
39 CaptionButtonIcon icon) | 41 CaptionButtonIcon icon) |
40 : CustomButton(listener), | 42 : CustomButton(listener), |
41 icon_(icon), | 43 icon_(icon), |
42 paint_as_active_(false), | 44 paint_as_active_(false), |
| 45 use_light_images_(false), |
43 alpha_(255), | 46 alpha_(255), |
44 icon_image_id_(-1), | 47 icon_image_id_(gfx::VectorIconId::VECTOR_ICON_NONE), |
45 swap_images_animation_(new gfx::SlideAnimation(this)) { | 48 swap_images_animation_(new gfx::SlideAnimation(this)) { |
46 swap_images_animation_->Reset(1); | 49 swap_images_animation_->Reset(1); |
47 | 50 |
48 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left | 51 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left |
49 // and snap right button icons should not be flipped. The other icons are | 52 // and snap right button icons should not be flipped. The other icons are |
50 // horizontally symmetrical. | 53 // horizontally symmetrical. |
51 } | 54 } |
52 | 55 |
53 FrameCaptionButton::~FrameCaptionButton() { | 56 FrameCaptionButton::~FrameCaptionButton() { |
54 } | 57 } |
55 | 58 |
56 void FrameCaptionButton::SetImage(CaptionButtonIcon icon, | 59 void FrameCaptionButton::SetImage(CaptionButtonIcon icon, |
57 Animate animate, | 60 Animate animate, |
58 int icon_image_id) { | 61 gfx::VectorIconId icon_image_id) { |
59 // The early return is dependant on |animate| because callers use SetImage() | 62 // The early return is dependent on |animate| because callers use SetImage() |
60 // with ANIMATE_NO to progress the crossfade animation to the end. | 63 // with ANIMATE_NO to progress the crossfade animation to the end. |
61 if (icon == icon_ && | 64 if (icon == icon_ && |
62 (animate == ANIMATE_YES || !swap_images_animation_->is_animating()) && | 65 (animate == ANIMATE_YES || !swap_images_animation_->is_animating()) && |
63 icon_image_id == icon_image_id_) { | 66 icon_image_id == icon_image_id_) { |
64 return; | 67 return; |
65 } | 68 } |
66 | 69 |
67 if (animate == ANIMATE_YES) | 70 if (animate == ANIMATE_YES) |
68 crossfade_icon_image_ = icon_image_; | 71 crossfade_icon_image_ = icon_image_; |
69 | 72 |
70 icon_ = icon; | 73 icon_ = icon; |
71 icon_image_id_ = icon_image_id; | 74 icon_image_id_ = icon_image_id; |
72 | 75 icon_image_ = gfx::CreateVectorIcon( |
73 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 76 icon_image_id, 12, |
74 icon_image_ = *rb.GetImageSkiaNamed(icon_image_id); | 77 use_light_images_ ? SK_ColorWHITE : gfx::kChromeIconGrey); |
75 | 78 |
76 if (animate == ANIMATE_YES) { | 79 if (animate == ANIMATE_YES) { |
77 swap_images_animation_->Reset(0); | 80 swap_images_animation_->Reset(0); |
78 swap_images_animation_->SetSlideDuration(kSwapImagesAnimationDurationMs); | 81 swap_images_animation_->SetSlideDuration(kSwapImagesAnimationDurationMs); |
79 swap_images_animation_->Show(); | 82 swap_images_animation_->Show(); |
80 } else { | 83 } else { |
81 swap_images_animation_->Reset(1); | 84 swap_images_animation_->Reset(1); |
82 } | 85 } |
83 PreferredSizeChanged(); | 86 PreferredSizeChanged(); |
84 SchedulePaint(); | 87 SchedulePaint(); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 182 |
180 SkPaint paint; | 183 SkPaint paint; |
181 paint.setAlpha(alpha); | 184 paint.setAlpha(alpha); |
182 canvas->DrawImageInt(to_center, | 185 canvas->DrawImageInt(to_center, |
183 (width() - to_center.width()) / 2, | 186 (width() - to_center.width()) / 2, |
184 (height() - to_center.height()) / 2, | 187 (height() - to_center.height()) / 2, |
185 paint); | 188 paint); |
186 } | 189 } |
187 | 190 |
188 } // namespace ash | 191 } // namespace ash |
OLD | NEW |