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