Commit 0ae7afd7 authored by msw@chromium.org's avatar msw@chromium.org

Add support for painting halos on Views Labels.

Needed for converting some TextButtons to LabelButtons.
(eg. new avatar button, bookmark buttons on drag)

BUG=155363
TEST=Label example shows a halo'ed label.
R=sky@chromium.org

Review URL: https://codereview.chromium.org/308083011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@274848 0039d316-1c4b-4281-b951-d872f2087c98
parent 28301aff
...@@ -323,12 +323,18 @@ void Label::PaintText(gfx::Canvas* canvas, ...@@ -323,12 +323,18 @@ void Label::PaintText(gfx::Canvas* canvas,
const gfx::Rect& text_bounds, const gfx::Rect& text_bounds,
int flags) { int flags) {
gfx::ShadowValues shadows; gfx::ShadowValues shadows;
if (has_shadow_) if (has_shadow_) {
shadows.push_back(gfx::ShadowValue(shadow_offset_, shadow_blur_, shadows.push_back(gfx::ShadowValue(shadow_offset_, shadow_blur_,
enabled() ? enabled_shadow_color_ : disabled_shadow_color_)); enabled() ? enabled_shadow_color_ : disabled_shadow_color_));
canvas->DrawStringRectWithShadows(text, font_list_, }
enabled() ? actual_enabled_color_ : actual_disabled_color_, SkColor color = enabled() ? actual_enabled_color_ : actual_disabled_color_;
text_bounds, line_height_, flags, shadows); canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds,
line_height_, flags, shadows);
if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) {
canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_,
text_bounds, flags);
}
if (HasFocus()) { if (HasFocus()) {
gfx::Rect focus_bounds = text_bounds; gfx::Rect focus_bounds = text_bounds;
...@@ -400,6 +406,7 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) { ...@@ -400,6 +406,7 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
shadow_offset_.SetPoint(1, 1); shadow_offset_.SetPoint(1, 1);
has_shadow_ = false; has_shadow_ = false;
shadow_blur_ = 0; shadow_blur_ = 0;
halo_color_ = SK_ColorTRANSPARENT;
cached_heights_.resize(kCachedSizeLimit); cached_heights_.resize(kCachedSizeLimit);
ResetCachedSize(); ResetCachedSize();
......
...@@ -100,6 +100,9 @@ class VIEWS_EXPORT Label : public View { ...@@ -100,6 +100,9 @@ class VIEWS_EXPORT Label : public View {
// Disables shadows. // Disables shadows.
void ClearEmbellishing(); void ClearEmbellishing();
// Set the color of a halo on the painted text (use transparent for none).
void set_halo_color(SkColor halo_color) { halo_color_ = halo_color; }
// Sets horizontal alignment. If the locale is RTL, and the directionality // Sets horizontal alignment. If the locale is RTL, and the directionality
// mode is USE_UI_DIRECTIONALITY, the alignment is flipped around. // mode is USE_UI_DIRECTIONALITY, the alignment is flipped around.
// //
...@@ -270,8 +273,6 @@ class VIEWS_EXPORT Label : public View { ...@@ -270,8 +273,6 @@ class VIEWS_EXPORT Label : public View {
bool auto_color_readability_; bool auto_color_readability_;
mutable gfx::Size text_size_; mutable gfx::Size text_size_;
mutable bool text_size_valid_; mutable bool text_size_valid_;
// Indicates the level of shadow blurring. Default is zero.
double shadow_blur_;
int line_height_; int line_height_;
bool is_multi_line_; bool is_multi_line_;
bool is_obscured_; bool is_obscured_;
...@@ -296,6 +297,12 @@ class VIEWS_EXPORT Label : public View { ...@@ -296,6 +297,12 @@ class VIEWS_EXPORT Label : public View {
// Should a shadow be drawn behind the text? // Should a shadow be drawn behind the text?
bool has_shadow_; bool has_shadow_;
// Indicates the level of shadow blurring. Default is zero.
double shadow_blur_;
// The halo color drawn around the text if it is not transparent.
SkColor halo_color_;
// The cached heights to avoid recalculation in GetHeightForWidth(). // The cached heights to avoid recalculation in GetHeightForWidth().
mutable std::vector<gfx::Size> cached_heights_; mutable std::vector<gfx::Size> cached_heights_;
mutable int cached_heights_cursor_; mutable int cached_heights_cursor_;
......
...@@ -68,10 +68,11 @@ void LabelExample::CreateExampleView(View* container) { ...@@ -68,10 +68,11 @@ void LabelExample::CreateExampleView(View* container) {
label->SetEnabledColor(SK_ColorBLUE); label->SetEnabledColor(SK_ColorBLUE);
container->AddChildView(label); container->AddChildView(label);
label = new Label(ASCIIToUTF16("A Courier-18 label with a shadow.")); label = new Label(ASCIIToUTF16("A Courier-18 label with a halo and shadow."));
label->SetFontList(gfx::FontList("Courier, 18px")); label->SetFontList(gfx::FontList("Courier, 18px"));
label->SetShadowColors(SK_ColorGRAY, SK_ColorLTGRAY); label->SetShadowColors(SK_ColorGRAY, SK_ColorLTGRAY);
label->SetShadowOffset(1, 1); label->SetShadowOffset(2, 2);
label->set_halo_color(SK_ColorGREEN);
container->AddChildView(label); container->AddChildView(label);
label = new PreferredSizeLabel(); label = new PreferredSizeLabel();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment