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/gfx/animation/slide_animation.h" | 8 #include "ui/gfx/animation/slide_animation.h" |
9 #include "ui/gfx/animation/throb_animation.h" | 9 #include "ui/gfx/animation/throb_animation.h" |
10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 gfx::Size FrameCaptionButton::GetPreferredSize() const { | 103 gfx::Size FrameCaptionButton::GetPreferredSize() const { |
104 return hovered_background_image_.isNull() ? | 104 return hovered_background_image_.isNull() ? |
105 gfx::Size() : hovered_background_image_.size(); | 105 gfx::Size() : hovered_background_image_.size(); |
106 } | 106 } |
107 | 107 |
108 const char* FrameCaptionButton::GetClassName() const { | 108 const char* FrameCaptionButton::GetClassName() const { |
109 return kViewClassName; | 109 return kViewClassName; |
110 } | 110 } |
111 | 111 |
112 void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) { | 112 void FrameCaptionButton::OnPaint(gfx::Canvas* canvas) { |
113 if (hover_animation_->is_animating() || state() == STATE_HOVERED) { | 113 if (hover_animation().is_animating() || state() == STATE_HOVERED) { |
114 int hovered_background_alpha = hover_animation_->is_animating() ? | 114 int hovered_background_alpha = |
115 hover_animation_->CurrentValueBetween(0, 255) : 255; | 115 hover_animation().is_animating() |
| 116 ? hover_animation().CurrentValueBetween(0, 255) |
| 117 : 255; |
116 SkPaint paint; | 118 SkPaint paint; |
117 paint.setAlpha(hovered_background_alpha); | 119 paint.setAlpha(hovered_background_alpha); |
118 canvas->DrawImageInt(hovered_background_image_, 0, 0, paint); | 120 canvas->DrawImageInt(hovered_background_image_, 0, 0, paint); |
119 } else if (state() == STATE_PRESSED) { | 121 } else if (state() == STATE_PRESSED) { |
120 canvas->DrawImageInt(pressed_background_image_, 0, 0); | 122 canvas->DrawImageInt(pressed_background_image_, 0, 0); |
121 } | 123 } |
122 | 124 |
123 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); | 125 int icon_alpha = swap_images_animation_->CurrentValueBetween(0, 255); |
124 int crossfade_icon_alpha = 0; | 126 int crossfade_icon_alpha = 0; |
125 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) | 127 if (icon_alpha < static_cast<int>(kFadeOutRatio * 255)) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 168 } |
167 CustomButton::OnGestureEvent(event); | 169 CustomButton::OnGestureEvent(event); |
168 } | 170 } |
169 | 171 |
170 void FrameCaptionButton::PaintCentered(gfx::Canvas* canvas, | 172 void FrameCaptionButton::PaintCentered(gfx::Canvas* canvas, |
171 const gfx::ImageSkia& to_center, | 173 const gfx::ImageSkia& to_center, |
172 int alpha) { | 174 int alpha) { |
173 if (!paint_as_active_) { | 175 if (!paint_as_active_) { |
174 // Paint icons as active when they are hovered over or pressed. | 176 // Paint icons as active when they are hovered over or pressed. |
175 double inactive_alpha = kInactiveIconAlpha; | 177 double inactive_alpha = kInactiveIconAlpha; |
176 if (hover_animation_->is_animating()) { | 178 if (hover_animation().is_animating()) { |
177 inactive_alpha = | 179 inactive_alpha = |
178 hover_animation_->CurrentValueBetween(inactive_alpha, 1.0f); | 180 hover_animation().CurrentValueBetween(inactive_alpha, 1.0f); |
179 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { | 181 } else if (state() == STATE_PRESSED || state() == STATE_HOVERED) { |
180 inactive_alpha = 1.0f; | 182 inactive_alpha = 1.0f; |
181 } | 183 } |
182 alpha *= inactive_alpha; | 184 alpha *= inactive_alpha; |
183 } | 185 } |
184 | 186 |
185 SkPaint paint; | 187 SkPaint paint; |
186 paint.setAlpha(alpha); | 188 paint.setAlpha(alpha); |
187 canvas->DrawImageInt(to_center, | 189 canvas->DrawImageInt(to_center, |
188 (width() - to_center.width()) / 2, | 190 (width() - to_center.width()) / 2, |
189 (height() - to_center.height()) / 2, | 191 (height() - to_center.height()) / 2, |
190 paint); | 192 paint); |
191 } | 193 } |
192 | 194 |
193 } // namespace ash | 195 } // namespace ash |
OLD | NEW |