Commit 2073de75 authored by msw@chromium.org's avatar msw@chromium.org

Refactor views::Label and gfx::RenderText shadow functions.

This is mechanical cleanup in preparation for a Label rewrite.
Use simple gfx::ShadowValues setter functions everywhere.
Remove a forbidden static FontList instance.

BUG=240037
TEST=No appearance changes for views text shadows.
R=sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278101 0039d316-1c4b-4281-b951-d872f2087c98
parent 20ed87f8
...@@ -13,17 +13,12 @@ ...@@ -13,17 +13,12 @@
namespace ash { namespace ash {
void SetupLabelForTray(views::Label* label) { void SetupLabelForTray(views::Label* label) {
// Making label_font static to avoid the time penalty of Derive for all but label->SetFontList(gfx::FontList().Derive(1, gfx::Font::BOLD));
// the first call.
static const gfx::FontList label_font_list(
gfx::FontList().Derive(1, gfx::Font::BOLD));
label->SetFontList(label_font_list);
label->SetAutoColorReadabilityEnabled(false); label->SetAutoColorReadabilityEnabled(false);
label->SetEnabledColor(SK_ColorWHITE); label->SetEnabledColor(SK_ColorWHITE);
label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), label->set_shadows(gfx::ShadowValues(1,
SkColorSetARGB(64, 0, 0, 0)); gfx::ShadowValue(gfx::Point(0, 1), 0, SkColorSetARGB(64, 0, 0, 0))));
label->SetShadowOffset(0, 1);
} }
void SetTrayImageItemBorder(views::View* tray_view, void SetTrayImageItemBorder(views::View* tray_view,
......
...@@ -352,9 +352,8 @@ TouchHudDebug::TouchHudDebug(aura::Window* initial_root) ...@@ -352,9 +352,8 @@ TouchHudDebug::TouchHudDebug(aura::Window* initial_root)
for (int i = 0; i < kMaxTouchPoints; ++i) { for (int i = 0; i < kMaxTouchPoints; ++i) {
touch_labels_[i] = new views::Label; touch_labels_[i] = new views::Label;
touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); touch_labels_[i]->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
touch_labels_[i]->SetShadowColors(SK_ColorWHITE, touch_labels_[i]->set_shadows(gfx::ShadowValues(1,
SK_ColorWHITE); gfx::ShadowValue(gfx::Point(1, 1), 0, SK_ColorWHITE)));
touch_labels_[i]->SetShadowOffset(1, 1);
label_container_->AddChildView(touch_labels_[i]); label_container_->AddChildView(touch_labels_[i]);
} }
label_container_->SetX(0); label_container_->SetX(0);
......
...@@ -89,9 +89,8 @@ views::Widget* CreateWindowLabel(aura::Window* root_window, ...@@ -89,9 +89,8 @@ views::Widget* CreateWindowLabel(aura::Window* root_window,
views::Label* label = new views::Label; views::Label* label = new views::Label;
label->SetEnabledColor(kLabelColor); label->SetEnabledColor(kLabelColor);
label->SetBackgroundColor(kLabelBackground); label->SetBackgroundColor(kLabelBackground);
label->SetShadowColors(kLabelShadow, kLabelShadow); label->set_shadows(gfx::ShadowValues(1, gfx::ShadowValue(
label->SetShadowOffset(0, kVerticalShadowOffset); gfx::Point(0, kVerticalShadowOffset), kShadowBlur, kLabelShadow)));
label->set_shadow_blur(kShadowBlur);
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont)); label->SetFontList(bundle.GetFontList(ui::ResourceBundle::BoldFont));
label->SetText(title); label->SetText(title);
......
...@@ -240,7 +240,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text, ...@@ -240,7 +240,7 @@ void Canvas::DrawStringRectWithShadows(const base::string16& text,
#endif #endif
scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetTextShadows(shadows); render_text->set_shadows(shadows);
if (flags & MULTI_LINE) { if (flags & MULTI_LINE) {
WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS; WordWrapBehavior wrap_behavior = IGNORE_LONG_WORDS;
......
...@@ -762,7 +762,7 @@ void RenderText::Draw(Canvas* canvas) { ...@@ -762,7 +762,7 @@ void RenderText::Draw(Canvas* canvas) {
if (clip_to_display_rect()) { if (clip_to_display_rect()) {
Rect clip_rect(display_rect()); Rect clip_rect(display_rect());
clip_rect.Inset(ShadowValue::GetMargin(text_shadows_)); clip_rect.Inset(ShadowValue::GetMargin(shadows_));
canvas->Save(); canvas->Save();
canvas->ClipRect(clip_rect); canvas->ClipRect(clip_rect);
...@@ -873,10 +873,6 @@ SelectionModel RenderText::GetSelectionModelForSelectionStart() { ...@@ -873,10 +873,6 @@ SelectionModel RenderText::GetSelectionModelForSelectionStart() {
sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD); sel.is_reversed() ? CURSOR_BACKWARD : CURSOR_FORWARD);
} }
void RenderText::SetTextShadows(const ShadowValues& shadows) {
text_shadows_ = shadows;
}
RenderText::RenderText() RenderText::RenderText()
: horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT), : horizontal_alignment_(base::i18n::IsRTL() ? ALIGN_RIGHT : ALIGN_LEFT),
directionality_mode_(DIRECTIONALITY_FROM_TEXT), directionality_mode_(DIRECTIONALITY_FROM_TEXT),
...@@ -1110,7 +1106,7 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { ...@@ -1110,7 +1106,7 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) {
} }
void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) { void RenderText::ApplyTextShadows(internal::SkiaTextRenderer* renderer) {
skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(text_shadows_); skia::RefPtr<SkDrawLooper> looper = CreateShadowDrawLooper(shadows_);
renderer->SetDrawLooper(looper.get()); renderer->SetDrawLooper(looper.get());
} }
......
...@@ -343,9 +343,8 @@ class GFX_EXPORT RenderText { ...@@ -343,9 +343,8 @@ class GFX_EXPORT RenderText {
VisualCursorDirection GetVisualDirectionOfLogicalEnd(); VisualCursorDirection GetVisualDirectionOfLogicalEnd();
// Returns the size required to display the current string (which is the // Returns the size required to display the current string (which is the
// wrapped size in multiline mode). Note that this returns the raw size of the // wrapped size in multiline mode). The returned size does not include space
// string, which does not include the cursor or the margin area of text // reserved for the cursor or the offset text shadows.
// shadows.
virtual Size GetStringSize() = 0; virtual Size GetStringSize() = 0;
// This is same as GetStringSize except that fractional size is returned. // This is same as GetStringSize except that fractional size is returned.
...@@ -408,7 +407,7 @@ class GFX_EXPORT RenderText { ...@@ -408,7 +407,7 @@ class GFX_EXPORT RenderText {
SelectionModel GetSelectionModelForSelectionStart(); SelectionModel GetSelectionModelForSelectionStart();
// Sets shadows to drawn with text. // Sets shadows to drawn with text.
void SetTextShadows(const ShadowValues& shadows); void set_shadows(const ShadowValues& shadows) { shadows_ = shadows; }
typedef std::pair<Font, Range> FontSpan; typedef std::pair<Font, Range> FontSpan;
// For testing purposes, returns which fonts were chosen for which parts of // For testing purposes, returns which fonts were chosen for which parts of
...@@ -694,7 +693,7 @@ class GFX_EXPORT RenderText { ...@@ -694,7 +693,7 @@ class GFX_EXPORT RenderText {
bool cached_bounds_and_offset_valid_; bool cached_bounds_and_offset_valid_;
// Text shadows to be drawn. // Text shadows to be drawn.
ShadowValues text_shadows_; ShadowValues shadows_;
// A list of valid layout text line break positions. // A list of valid layout text line break positions.
BreakList<size_t> line_breaks_; BreakList<size_t> line_breaks_;
......
...@@ -43,8 +43,8 @@ void BlueButton::ResetColorsFromNativeTheme() { ...@@ -43,8 +43,8 @@ void BlueButton::ResetColorsFromNativeTheme() {
GetSystemColor(ui::NativeTheme::kColorId_BlueButtonDisabledColor)); GetSystemColor(ui::NativeTheme::kColorId_BlueButtonDisabledColor));
// TODO(estade): this is not great on system themes. // TODO(estade): this is not great on system themes.
label()->SetShadowColors(kBlueButtonShadowColor, kBlueButtonShadowColor); label()->set_shadows(gfx::ShadowValues(1,
label()->SetShadowOffset(0, 1); gfx::ShadowValue(gfx::Point(0, 1), 0, kBlueButtonShadowColor)));
} }
} }
......
...@@ -320,7 +320,7 @@ void LabelButton::ResetColorsFromNativeTheme() { ...@@ -320,7 +320,7 @@ void LabelButton::ResetColorsFromNativeTheme() {
label_->SetBackgroundColor(SK_ColorBLACK); label_->SetBackgroundColor(SK_ColorBLACK);
label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK)); label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
label_->SetAutoColorReadabilityEnabled(true); label_->SetAutoColorReadabilityEnabled(true);
label_->ClearEmbellishing(); label_->set_shadows(gfx::ShadowValues());
} else if (style() == STYLE_BUTTON) { } else if (style() == STYLE_BUTTON) {
// TODO(erg): This is disabled on desktop linux because of the binary asset // TODO(erg): This is disabled on desktop linux because of the binary asset
// confusion. These details should either be pushed into ui::NativeThemeWin // confusion. These details should either be pushed into ui::NativeThemeWin
...@@ -332,8 +332,8 @@ void LabelButton::ResetColorsFromNativeTheme() { ...@@ -332,8 +332,8 @@ void LabelButton::ResetColorsFromNativeTheme() {
label_->SetBackgroundColor(theme->GetSystemColor( label_->SetBackgroundColor(theme->GetSystemColor(
ui::NativeTheme::kColorId_ButtonBackgroundColor)); ui::NativeTheme::kColorId_ButtonBackgroundColor));
label_->SetAutoColorReadabilityEnabled(false); label_->SetAutoColorReadabilityEnabled(false);
label_->SetShadowColors(kStyleButtonShadowColor, kStyleButtonShadowColor); label_->set_shadows(gfx::ShadowValues(1,
label_->SetShadowOffset(0, 1); gfx::ShadowValue(gfx::Point(0, 1), 0, kStyleButtonShadowColor)));
#endif #endif
label_->set_background(NULL); label_->set_background(NULL);
} else { } else {
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/insets.h" #include "ui/gfx/insets.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/text_elider.h" #include "ui/gfx/text_elider.h"
#include "ui/gfx/text_utils.h" #include "ui/gfx/text_utils.h"
#include "ui/gfx/utf16_indexing.h" #include "ui/gfx/utf16_indexing.h"
...@@ -105,20 +104,6 @@ void Label::SetBackgroundColor(SkColor color) { ...@@ -105,20 +104,6 @@ void Label::SetBackgroundColor(SkColor color) {
RecalculateColors(); RecalculateColors();
} }
void Label::SetShadowColors(SkColor enabled_color, SkColor disabled_color) {
enabled_shadow_color_ = enabled_color;
disabled_shadow_color_ = disabled_color;
has_shadow_ = true;
}
void Label::SetShadowOffset(int x, int y) {
shadow_offset_.SetPoint(x, y);
}
void Label::ClearEmbellishing() {
has_shadow_ = false;
}
void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) { void Label::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
// If the UI layout is right-to-left, flip the alignment direction. // If the UI layout is right-to-left, flip the alignment direction.
if (base::i18n::IsRTL() && if (base::i18n::IsRTL() &&
...@@ -334,13 +319,8 @@ void Label::PaintText(gfx::Canvas* canvas, ...@@ -334,13 +319,8 @@ void Label::PaintText(gfx::Canvas* canvas,
if (elide_behavior_ == gfx::FADE_TAIL) { if (elide_behavior_ == gfx::FADE_TAIL) {
canvas->DrawFadedString(text, font_list_, color, text_bounds, flags); canvas->DrawFadedString(text, font_list_, color, text_bounds, flags);
} else { } else {
gfx::ShadowValues shadows;
if (has_shadow_) {
shadows.push_back(gfx::ShadowValue(shadow_offset_, shadow_blur_,
enabled() ? enabled_shadow_color_ : disabled_shadow_color_));
}
canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds, canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds,
line_height_, flags, shadows); line_height_, flags, shadows_);
if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) { if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) {
canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_, canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_,
...@@ -413,11 +393,6 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) { ...@@ -413,11 +393,6 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
elide_behavior_ = gfx::ELIDE_TAIL; elide_behavior_ = gfx::ELIDE_TAIL;
collapse_when_hidden_ = false; collapse_when_hidden_ = false;
directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI; directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
enabled_shadow_color_ = 0;
disabled_shadow_color_ = 0;
shadow_offset_.SetPoint(1, 1);
has_shadow_ = false;
shadow_blur_ = 0;
halo_color_ = SK_ColorTRANSPARENT; halo_color_ = SK_ColorTRANSPARENT;
cached_heights_.resize(kCachedSizeLimit); cached_heights_.resize(kCachedSizeLimit);
ResetCachedSize(); ResetCachedSize();
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/shadow_value.h"
#include "ui/gfx/text_constants.h" #include "ui/gfx/text_constants.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -58,17 +59,8 @@ class VIEWS_EXPORT Label : public View { ...@@ -58,17 +59,8 @@ class VIEWS_EXPORT Label : public View {
void SetBackgroundColor(SkColor color); void SetBackgroundColor(SkColor color);
SkColor background_color() const { return background_color_; } SkColor background_color() const { return background_color_; }
// Enables a drop shadow underneath the text. // Set drop shadows underneath the text.
void SetShadowColors(SkColor enabled_color, SkColor disabled_color); void set_shadows(const gfx::ShadowValues& shadows) { shadows_ = shadows; }
// Sets the drop shadow's offset from the text.
void SetShadowOffset(int x, int y);
// Sets the shadow blur. Default is zero.
void set_shadow_blur(double shadow_blur) { shadow_blur_ = shadow_blur; }
// Disables shadows.
void ClearEmbellishing();
// Set the color of a halo on the painted text (use transparent for none). // 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; } void set_halo_color(SkColor halo_color) { halo_color_ = halo_color; }
...@@ -241,19 +233,7 @@ class VIEWS_EXPORT Label : public View { ...@@ -241,19 +233,7 @@ class VIEWS_EXPORT Label : public View {
// Controls whether the directionality is auto-detected based on first strong // Controls whether the directionality is auto-detected based on first strong
// directionality character or is determined by the application UI's locale. // directionality character or is determined by the application UI's locale.
gfx::DirectionalityMode directionality_mode_; gfx::DirectionalityMode directionality_mode_;
gfx::ShadowValues shadows_;
// Colors for shadow.
SkColor enabled_shadow_color_;
SkColor disabled_shadow_color_;
// Space between text and shadow.
gfx::Point shadow_offset_;
// Should a shadow be drawn behind the text?
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. // The halo color drawn around the text if it is not transparent.
SkColor halo_color_; SkColor halo_color_;
......
...@@ -64,8 +64,8 @@ void LabelExample::CreateExampleView(View* container) { ...@@ -64,8 +64,8 @@ void LabelExample::CreateExampleView(View* container) {
label = new Label(ASCIIToUTF16("A Courier-18 label with a halo and 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->set_shadows(gfx::ShadowValues(1,
label->SetShadowOffset(2, 2); gfx::ShadowValue(gfx::Point(2, 2), 0, SK_ColorGRAY)));
label->set_halo_color(SK_ColorGREEN); label->set_halo_color(SK_ColorGREEN);
container->AddChildView(label); container->AddChildView(label);
......
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