| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/drop_shadow_label.h" | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "ui/gfx/canvas.h" | |
| 9 #include "ui/gfx/color_utils.h" | |
| 10 | |
| 11 using views::Label; | |
| 12 | |
| 13 namespace chromeos { | |
| 14 | |
| 15 static const int kDefaultDropShadowSize = 2; | |
| 16 | |
| 17 DropShadowLabel::DropShadowLabel() : drop_shadow_size_(kDefaultDropShadowSize) { | |
| 18 } | |
| 19 | |
| 20 void DropShadowLabel::SetDropShadowSize(int drop_shadow_size) { | |
| 21 if (drop_shadow_size != drop_shadow_size_) { | |
| 22 drop_shadow_size_ = drop_shadow_size; | |
| 23 invalidate_text_size(); | |
| 24 SchedulePaint(); | |
| 25 } | |
| 26 } | |
| 27 | |
| 28 void DropShadowLabel::PaintText(gfx::Canvas* canvas, | |
| 29 const string16& text, | |
| 30 const gfx::Rect& text_bounds, | |
| 31 int flags) { | |
| 32 SkColor text_color = enabled() ? enabled_color() : disabled_color(); | |
| 33 if (drop_shadow_size_ > 0) { | |
| 34 const float kShadowOpacity = 0.2; | |
| 35 const SkColor shadow_color = | |
| 36 SkColorSetA(SK_ColorBLACK, kShadowOpacity * SkColorGetA(text_color)); | |
| 37 for (int i = 0; i < drop_shadow_size_; i++) { | |
| 38 canvas->DrawStringInt(text, font(), shadow_color, | |
| 39 text_bounds.x() + i, text_bounds.y(), | |
| 40 text_bounds.width(), text_bounds.height(), flags); | |
| 41 canvas->DrawStringInt(text, font(), shadow_color, | |
| 42 text_bounds.x() + i, text_bounds.y() + i, | |
| 43 text_bounds.width(), text_bounds.height(), flags); | |
| 44 canvas->DrawStringInt(text, font(), shadow_color, | |
| 45 text_bounds.x(), text_bounds.y() + i, | |
| 46 text_bounds.width(), text_bounds.height(), flags); | |
| 47 } | |
| 48 } | |
| 49 | |
| 50 canvas->DrawStringInt(text, font(), text_color, text_bounds.x(), | |
| 51 text_bounds.y(), text_bounds.width(), text_bounds.height(), flags); | |
| 52 | |
| 53 if (HasFocus() || paint_as_focused()) { | |
| 54 gfx::Rect focus_bounds = text_bounds; | |
| 55 focus_bounds.Inset(-Label::kFocusBorderPadding, | |
| 56 -Label::kFocusBorderPadding); | |
| 57 canvas->DrawFocusRect(focus_bounds); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 gfx::Size DropShadowLabel::GetTextSize() const { | |
| 62 gfx::Size text_size = Label::GetTextSize(); | |
| 63 text_size.SetSize(text_size.width() + drop_shadow_size_, | |
| 64 text_size.height() + drop_shadow_size_); | |
| 65 return text_size; | |
| 66 } | |
| 67 | |
| 68 } // namespace chromeos | |
| OLD | NEW |