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" | 7 #include "ui/base/resource/resource_bundle.h" |
8 #include "ui/compositor/layer.h" | |
9 #include "ui/gfx/animation/slide_animation.h" | 8 #include "ui/gfx/animation/slide_animation.h" |
10 #include "ui/gfx/animation/throb_animation.h" | 9 #include "ui/gfx/animation/throb_animation.h" |
11 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
12 #include "ui/views/widget/widget.h" | |
13 | 11 |
14 namespace ash { | 12 namespace ash { |
15 | 13 |
16 namespace { | 14 namespace { |
17 | 15 |
18 // The duration of the crossfade animation when swapping the button's images. | 16 // The duration of the crossfade animation when swapping the button's images. |
19 const int kSwapImagesAnimationDurationMs = 200; | 17 const int kSwapImagesAnimationDurationMs = 200; |
20 | 18 |
21 // The duration of the fade out animation of the old icon during a crossfade | 19 // The duration of the fade out animation of the old icon during a crossfade |
22 // animation as a ratio of |kSwapImagesAnimationDurationMs|. | 20 // animation as a ratio of |kSwapImagesAnimationDurationMs|. |
23 const float kFadeOutRatio = 0.5f; | 21 const float kFadeOutRatio = 0.5f; |
24 | 22 |
25 } // namespace | 23 } // namespace |
26 | 24 |
27 // static | 25 // static |
28 const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton"; | 26 const char FrameCaptionButton::kViewClassName[] = "FrameCaptionButton"; |
29 | 27 |
30 FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, | 28 FrameCaptionButton::FrameCaptionButton(views::ButtonListener* listener, |
31 CaptionButtonIcon icon) | 29 CaptionButtonIcon icon) |
32 : CustomButton(listener), | 30 : CustomButton(listener), |
33 icon_(icon), | 31 icon_(icon), |
34 paint_as_active_(false), | 32 paint_as_active_(false), |
35 icon_image_id_(-1), | 33 icon_image_id_(-1), |
36 inactive_icon_image_id_(-1), | 34 inactive_icon_image_id_(-1), |
37 hovered_background_image_id_(-1), | 35 hovered_background_image_id_(-1), |
38 pressed_background_image_id_(-1), | 36 pressed_background_image_id_(-1), |
39 swap_images_animation_(new gfx::SlideAnimation(this)) { | 37 swap_images_animation_(new gfx::SlideAnimation(this)) { |
40 swap_images_animation_->Reset(1); | 38 swap_images_animation_->Reset(1); |
41 | 39 |
42 SetPaintToLayer(true); | |
43 SetFillsBoundsOpaquely(false); | |
44 set_layer_owner_delegate(this); | |
45 | |
46 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left | 40 // Do not flip the gfx::Canvas passed to the OnPaint() method. The snap left |
47 // and snap right button icons should not be flipped. The other icons are | 41 // and snap right button icons should not be flipped. The other icons are |
48 // horizontally symmetrical. | 42 // horizontally symmetrical. |
49 } | 43 } |
50 | 44 |
51 FrameCaptionButton::~FrameCaptionButton() { | 45 FrameCaptionButton::~FrameCaptionButton() { |
52 } | 46 } |
53 | 47 |
54 void FrameCaptionButton::SetImages(CaptionButtonIcon icon, | 48 void FrameCaptionButton::SetImages(CaptionButtonIcon icon, |
55 Animate animate, | 49 Animate animate, |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 const gfx::ImageSkia& to_center, | 167 const gfx::ImageSkia& to_center, |
174 int alpha) { | 168 int alpha) { |
175 SkPaint paint; | 169 SkPaint paint; |
176 paint.setAlpha(alpha); | 170 paint.setAlpha(alpha); |
177 canvas->DrawImageInt(to_center, | 171 canvas->DrawImageInt(to_center, |
178 (width() - to_center.width()) / 2, | 172 (width() - to_center.width()) / 2, |
179 (height() - to_center.height()) / 2, | 173 (height() - to_center.height()) / 2, |
180 paint); | 174 paint); |
181 } | 175 } |
182 | 176 |
183 void FrameCaptionButton::OnLayerRecreated(ui::Layer* old_layer, | |
184 ui::Layer* new_layer) { | |
185 GetWidget()->UpdateRootLayers(); | |
186 } | |
187 | |
188 } // namespace ash | 177 } // namespace ash |
OLD | NEW |