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