| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/drop_shadow_label.h" | 5 #include "chrome/browser/chromeos/drop_shadow_label.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
| 9 #include "ui/gfx/color_utils.h" | 9 #include "ui/gfx/color_utils.h" |
| 10 | 10 |
| 11 using views::Label; | 11 using views::Label; |
| 12 | 12 |
| 13 namespace chromeos { | 13 namespace chromeos { |
| 14 | 14 |
| 15 static const int kDefaultDropShadowSize = 2; | 15 static const int kDefaultDropShadowSize = 2; |
| 16 | 16 |
| 17 // Default color is black. | 17 DropShadowLabel::DropShadowLabel() : drop_shadow_size_(kDefaultDropShadowSize) { |
| 18 static const SkColor kDefaultColor = 0x000000; | |
| 19 | |
| 20 static const float kShadowOpacity = 0.2; | |
| 21 | |
| 22 DropShadowLabel::DropShadowLabel() : Label() { | |
| 23 Init(); | |
| 24 } | |
| 25 | |
| 26 void DropShadowLabel::Init() { | |
| 27 drop_shadow_size_ = kDefaultDropShadowSize; | |
| 28 } | 18 } |
| 29 | 19 |
| 30 void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) { | 20 void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) { |
| 31 if (drop_shadow_size != drop_shadow_size_) { | 21 if (drop_shadow_size != drop_shadow_size_) { |
| 32 drop_shadow_size_ = drop_shadow_size; | 22 drop_shadow_size_ = drop_shadow_size; |
| 33 invalidate_text_size(); | 23 invalidate_text_size(); |
| 34 SchedulePaint(); | 24 SchedulePaint(); |
| 35 } | 25 } |
| 36 } | 26 } |
| 37 | 27 |
| 38 void DropShadowLabel::PaintText(gfx::Canvas* canvas, | 28 void DropShadowLabel::PaintText(gfx::Canvas* canvas, |
| 39 const string16& text, | 29 const string16& text, |
| 40 const gfx::Rect& text_bounds, | 30 const gfx::Rect& text_bounds, |
| 41 int flags) { | 31 int flags) { |
| 32 SkColor text_color = IsEnabled() ? enabled_color() : disabled_color(); |
| 42 if (drop_shadow_size_ > 0) { | 33 if (drop_shadow_size_ > 0) { |
| 43 SkColor color = SkColorSetARGB(kShadowOpacity * SkColorGetA(GetColor()), | 34 const float kShadowOpacity = 0.2; |
| 44 SkColorGetR(kDefaultColor), | 35 const SkColor shadow_color = |
| 45 SkColorGetG(kDefaultColor), | 36 SkColorSetA(SK_ColorBLACK, kShadowOpacity * SkColorGetA(text_color)); |
| 46 SkColorGetB(kDefaultColor)); | |
| 47 for (int i = 0; i < drop_shadow_size_; i++) { | 37 for (int i = 0; i < drop_shadow_size_; i++) { |
| 48 canvas->DrawStringInt(text, font(), color, | 38 canvas->DrawStringInt(text, font(), shadow_color, |
| 49 text_bounds.x() + i, text_bounds.y(), | 39 text_bounds.x() + i, text_bounds.y(), |
| 50 text_bounds.width(), text_bounds.height(), flags); | 40 text_bounds.width(), text_bounds.height(), flags); |
| 51 canvas->DrawStringInt(text, font(), color, | 41 canvas->DrawStringInt(text, font(), shadow_color, |
| 52 text_bounds.x() + i, text_bounds.y() + i, | 42 text_bounds.x() + i, text_bounds.y() + i, |
| 53 text_bounds.width(), text_bounds.height(), flags); | 43 text_bounds.width(), text_bounds.height(), flags); |
| 54 canvas->DrawStringInt(text, font(), color, | 44 canvas->DrawStringInt(text, font(), shadow_color, |
| 55 text_bounds.x(), text_bounds.y() + i, | 45 text_bounds.x(), text_bounds.y() + i, |
| 56 text_bounds.width(), text_bounds.height(), flags); | 46 text_bounds.width(), text_bounds.height(), flags); |
| 57 } | 47 } |
| 58 } | 48 } |
| 59 | 49 |
| 60 canvas->DrawStringInt(text, font(), GetColor(), | 50 canvas->DrawStringInt(text, font(), text_color, text_bounds.x(), |
| 61 text_bounds.x(), text_bounds.y(), | 51 text_bounds.y(), text_bounds.width(), text_bounds.height(), flags); |
| 62 text_bounds.width(), text_bounds.height(), flags); | |
| 63 | 52 |
| 64 if (HasFocus() || paint_as_focused()) { | 53 if (HasFocus() || paint_as_focused()) { |
| 65 gfx::Rect focus_bounds = text_bounds; | 54 gfx::Rect focus_bounds = text_bounds; |
| 66 focus_bounds.Inset(-Label::kFocusBorderPadding, | 55 focus_bounds.Inset(-Label::kFocusBorderPadding, |
| 67 -Label::kFocusBorderPadding); | 56 -Label::kFocusBorderPadding); |
| 68 canvas->DrawFocusRect(focus_bounds.x(), focus_bounds.y(), | 57 canvas->DrawFocusRect(focus_bounds.x(), focus_bounds.y(), |
| 69 focus_bounds.width(), focus_bounds.height()); | 58 focus_bounds.width(), focus_bounds.height()); |
| 70 } | 59 } |
| 71 } | 60 } |
| 72 | 61 |
| 73 gfx::Size DropShadowLabel::GetTextSize() const { | 62 gfx::Size DropShadowLabel::GetTextSize() const { |
| 74 gfx::Size text_size = Label::GetTextSize(); | 63 gfx::Size text_size = Label::GetTextSize(); |
| 75 text_size.SetSize(text_size.width() + drop_shadow_size_, | 64 text_size.SetSize(text_size.width() + drop_shadow_size_, |
| 76 text_size.height() + drop_shadow_size_); | 65 text_size.height() + drop_shadow_size_); |
| 77 return text_size; | 66 return text_size; |
| 78 } | 67 } |
| 79 | 68 |
| 80 } // namespace chromeos | 69 } // namespace chromeos |
| OLD | NEW |