Commit 2d6063d5 authored by msw@chromium.org's avatar msw@chromium.org

Remove Label::PaintText overrides.

This is simple cleanup in preparation for a Label rewrite.
These overrides were supplying an extra gfx::Canvas flag.
Instead, add an explicit label flag for NO_SUBPIXEL_RENDERING.
Update some callers and the unit test.

TODO(followup): Update more Label::SetBackgroundColor callers.

BUG=240037
TEST=No exit warning or sticky keys label rendering changes.
R=sky@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278213 0039d316-1c4b-4281-b951-d872f2087c98
parent 5a93fe87
...@@ -38,27 +38,6 @@ const int kWindowCornerRadius = 2; ...@@ -38,27 +38,6 @@ const int kWindowCornerRadius = 2;
const int kHorizontalMarginAroundText = 100; const int kHorizontalMarginAroundText = 100;
const int kVerticalMarginAroundText = 100; const int kVerticalMarginAroundText = 100;
class ExitWarningLabel : public views::Label {
public:
ExitWarningLabel() {}
virtual ~ExitWarningLabel() {}
private:
virtual void PaintText(gfx::Canvas* canvas,
const base::string16& text,
const gfx::Rect& text_bounds,
int flags) OVERRIDE {
// Turn off subpixel rendering.
views::Label::PaintText(canvas,
text,
text_bounds,
flags | gfx::Canvas::NO_SUBPIXEL_RENDERING);
}
DISALLOW_COPY_AND_ASSIGN(ExitWarningLabel);
};
class ExitWarningWidgetDelegateView : public views::WidgetDelegateView { class ExitWarningWidgetDelegateView : public views::WidgetDelegateView {
public: public:
ExitWarningWidgetDelegateView() : text_width_(0), width_(0), height_(0) { ExitWarningWidgetDelegateView() : text_width_(0), width_(0), height_(0) {
...@@ -77,13 +56,14 @@ class ExitWarningWidgetDelegateView : public views::WidgetDelegateView { ...@@ -77,13 +56,14 @@ class ExitWarningWidgetDelegateView : public views::WidgetDelegateView {
text_width_ = gfx::GetStringWidth(text_, font_list); text_width_ = gfx::GetStringWidth(text_, font_list);
width_ = text_width_ + kHorizontalMarginAroundText; width_ = text_width_ + kHorizontalMarginAroundText;
height_ = font_list.GetHeight() + kVerticalMarginAroundText; height_ = font_list.GetHeight() + kVerticalMarginAroundText;
views::Label* label = new ExitWarningLabel; views::Label* label = new views::Label();
label->SetText(text_); label->SetText(text_);
label->SetHorizontalAlignment(gfx::ALIGN_CENTER); label->SetHorizontalAlignment(gfx::ALIGN_CENTER);
label->SetFontList(font_list); label->SetFontList(font_list);
label->SetEnabledColor(kTextColor); label->SetEnabledColor(kTextColor);
label->SetDisabledColor(kTextColor); label->SetDisabledColor(kTextColor);
label->SetAutoColorReadabilityEnabled(false); label->SetAutoColorReadabilityEnabled(false);
label->set_subpixel_rendering_enabled(false);
AddChildView(label); AddChildView(label);
SetLayoutManager(new views::FillLayout); SetLayoutManager(new views::FillLayout);
} }
......
...@@ -54,12 +54,6 @@ class StickyKeyOverlayLabel : public views::Label { ...@@ -54,12 +54,6 @@ class StickyKeyOverlayLabel : public views::Label {
void SetKeyState(StickyKeyState state); void SetKeyState(StickyKeyState state);
private: private:
// views::Label overrides:
virtual void PaintText(gfx::Canvas* canvas,
const base::string16& text,
const gfx::Rect& text_bounds,
int flags) OVERRIDE;
StickyKeyState state_; StickyKeyState state_;
DISALLOW_COPY_AND_ASSIGN(StickyKeyOverlayLabel); DISALLOW_COPY_AND_ASSIGN(StickyKeyOverlayLabel);
...@@ -76,6 +70,7 @@ StickyKeyOverlayLabel::StickyKeyOverlayLabel(const std::string& key_name) ...@@ -76,6 +70,7 @@ StickyKeyOverlayLabel::StickyKeyOverlayLabel(const std::string& key_name)
SetFocusable(false); SetFocusable(false);
SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); SetEnabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF));
SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF)); SetDisabledColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF));
set_subpixel_rendering_enabled(false);
} }
StickyKeyOverlayLabel::~StickyKeyOverlayLabel() { StickyKeyOverlayLabel::~StickyKeyOverlayLabel() {
...@@ -104,19 +99,8 @@ void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) { ...@@ -104,19 +99,8 @@ void StickyKeyOverlayLabel::SetKeyState(StickyKeyState state) {
SetFontList(font_list().DeriveWithStyle(style)); SetFontList(font_list().DeriveWithStyle(style));
} }
void StickyKeyOverlayLabel::PaintText(gfx::Canvas* canvas,
const base::string16& text,
const gfx::Rect& text_bounds,
int flags) {
views::Label::PaintText(canvas,
text,
text_bounds,
flags | gfx::Canvas::NO_SUBPIXEL_RENDERING);
}
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
// StickyKeyOverlayLabel // StickyKeysOverlayView
class StickyKeysOverlayView : public views::WidgetDelegateView { class StickyKeysOverlayView : public views::WidgetDelegateView {
public: public:
StickyKeysOverlayView(); StickyKeysOverlayView();
......
...@@ -141,9 +141,7 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame, ...@@ -141,9 +141,7 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
gfx::FontList(BrowserFrame::GetTitleFontList())); gfx::FontList(BrowserFrame::GetTitleFontList()));
window_title_->SetVisible(browser_view->ShouldShowWindowTitle()); window_title_->SetVisible(browser_view->ShouldShowWindowTitle());
window_title_->SetEnabledColor(SK_ColorWHITE); window_title_->SetEnabledColor(SK_ColorWHITE);
// TODO(msw): Use a transparent background color as a workaround to use the window_title_->set_subpixel_rendering_enabled(false);
// gfx::Canvas::NO_SUBPIXEL_RENDERING flag and avoid some visual artifacts.
window_title_->SetBackgroundColor(0x00000000);
window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
window_title_->set_id(VIEW_ID_WINDOW_TITLE); window_title_->set_id(VIEW_ID_WINDOW_TITLE);
AddChildView(window_title_); AddChildView(window_title_);
......
...@@ -207,7 +207,7 @@ class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase { ...@@ -207,7 +207,7 @@ class OpaqueBrowserFrameViewLayoutTest : public views::ViewsTestBase {
window_title_ = new views::Label(delegate_->GetWindowTitle()); window_title_ = new views::Label(delegate_->GetWindowTitle());
window_title_->SetVisible(delegate_->ShouldShowWindowTitle()); window_title_->SetVisible(delegate_->ShouldShowWindowTitle());
window_title_->SetEnabledColor(SK_ColorWHITE); window_title_->SetEnabledColor(SK_ColorWHITE);
window_title_->SetBackgroundColor(0x00000000); window_title_->set_subpixel_rendering_enabled(false);
window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
window_title_->set_id(VIEW_ID_WINDOW_TITLE); window_title_->set_id(VIEW_ID_WINDOW_TITLE);
root_view_->AddChildView(window_title_); root_view_->AddChildView(window_title_);
......
...@@ -383,6 +383,7 @@ void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) { ...@@ -383,6 +383,7 @@ void Label::OnNativeThemeChanged(const ui::NativeTheme* theme) {
void Label::Init(const base::string16& text, const gfx::FontList& font_list) { void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
font_list_ = font_list; font_list_ = font_list;
enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; enabled_color_set_ = disabled_color_set_ = background_color_set_ = false;
subpixel_rendering_enabled_ = true;
auto_color_readability_ = true; auto_color_readability_ = true;
UpdateColorsFromTheme(ui::NativeTheme::instance()); UpdateColorsFromTheme(ui::NativeTheme::instance());
horizontal_alignment_ = gfx::ALIGN_CENTER; horizontal_alignment_ = gfx::ALIGN_CENTER;
...@@ -439,7 +440,7 @@ int Label::ComputeDrawStringFlags() const { ...@@ -439,7 +440,7 @@ int Label::ComputeDrawStringFlags() const {
int flags = 0; int flags = 0;
// We can't use subpixel rendering if the background is non-opaque. // We can't use subpixel rendering if the background is non-opaque.
if (SkColorGetA(background_color_) != 0xFF) if (SkColorGetA(background_color_) != 0xFF || !subpixel_rendering_enabled_)
flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING; flags |= gfx::Canvas::NO_SUBPIXEL_RENDERING;
if (directionality_mode_ == gfx::DIRECTIONALITY_FORCE_LTR) { if (directionality_mode_ == gfx::DIRECTIONALITY_FORCE_LTR) {
......
...@@ -62,6 +62,12 @@ class VIEWS_EXPORT Label : public View { ...@@ -62,6 +62,12 @@ class VIEWS_EXPORT Label : public View {
// Set drop shadows underneath the text. // Set drop shadows underneath the text.
void set_shadows(const gfx::ShadowValues& shadows) { shadows_ = shadows; } void set_shadows(const gfx::ShadowValues& shadows) { shadows_ = shadows; }
// Sets whether subpixel rendering is used; the default is true, but this
// feature also requires an opaque background color.
void set_subpixel_rendering_enabled(bool subpixel_rendering_enabled) {
subpixel_rendering_enabled_ = subpixel_rendering_enabled;
}
// 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; }
...@@ -218,6 +224,7 @@ class VIEWS_EXPORT Label : public View { ...@@ -218,6 +224,7 @@ class VIEWS_EXPORT Label : public View {
bool disabled_color_set_; bool disabled_color_set_;
bool background_color_set_; bool background_color_set_;
bool subpixel_rendering_enabled_;
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_;
......
...@@ -862,18 +862,19 @@ TEST(LabelTest, DrawMultiLineStringInRTL) { ...@@ -862,18 +862,19 @@ TEST(LabelTest, DrawMultiLineStringInRTL) {
base::i18n::SetICUDefaultLocale(locale); base::i18n::SetICUDefaultLocale(locale);
} }
// Check that we disable subpixel rendering when a transparent background is // Ensure the subpixel rendering flag and background color alpha are respected.
// being used.
TEST(LabelTest, DisableSubpixelRendering) { TEST(LabelTest, DisableSubpixelRendering) {
Label label; Label label;
label.SetBackgroundColor(SK_ColorWHITE); label.SetBackgroundColor(SK_ColorWHITE);
EXPECT_EQ( const int flag = gfx::Canvas::NO_SUBPIXEL_RENDERING;
0, label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING); EXPECT_EQ(0, label.ComputeDrawStringFlags() & flag);
label.set_subpixel_rendering_enabled(false);
EXPECT_EQ(flag, label.ComputeDrawStringFlags() & flag);
label.set_subpixel_rendering_enabled(true);
EXPECT_EQ(0, label.ComputeDrawStringFlags() & flag);
// Text cannot be drawn with subpixel rendering on transparent backgrounds.
label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255)); label.SetBackgroundColor(SkColorSetARGB(64, 255, 255, 255));
EXPECT_EQ( EXPECT_EQ(flag, label.ComputeDrawStringFlags() & flag);
gfx::Canvas::NO_SUBPIXEL_RENDERING,
label.ComputeDrawStringFlags() & gfx::Canvas::NO_SUBPIXEL_RENDERING);
} }
// Check that labels support GetTooltipHandlerForPoint. // Check that labels support GetTooltipHandlerForPoint.
......
...@@ -992,8 +992,8 @@ void Textfield::WriteDragDataForView(View* sender, ...@@ -992,8 +992,8 @@ void Textfield::WriteDragDataForView(View* sender,
const base::string16& selected_text(GetSelectedText()); const base::string16& selected_text(GetSelectedText());
data->SetString(selected_text); data->SetString(selected_text);
Label label(selected_text, GetFontList()); Label label(selected_text, GetFontList());
const SkColor background = GetBackgroundColor(); label.SetBackgroundColor(GetBackgroundColor());
label.SetBackgroundColor(SkColorSetA(background, SK_AlphaTRANSPARENT)); label.set_subpixel_rendering_enabled(false);
gfx::Size size(label.GetPreferredSize()); gfx::Size size(label.GetPreferredSize());
gfx::NativeView native_view = GetWidget()->GetNativeView(); gfx::NativeView native_view = GetWidget()->GetNativeView();
gfx::Display display = gfx::Screen::GetScreenFor(native_view)-> gfx::Display display = gfx::Screen::GetScreenFor(native_view)->
...@@ -1005,7 +1005,7 @@ void Textfield::WriteDragDataForView(View* sender, ...@@ -1005,7 +1005,7 @@ void Textfield::WriteDragDataForView(View* sender,
label.SetEnabledColor(GetTextColor()); label.SetEnabledColor(GetTextColor());
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
// Desktop Linux Aura does not yet support transparency in drag images. // Desktop Linux Aura does not yet support transparency in drag images.
canvas->DrawColor(background); canvas->DrawColor(GetBackgroundColor());
#endif #endif
label.Paint(canvas.get(), views::CullSet()); label.Paint(canvas.get(), views::CullSet());
const gfx::Vector2d kOffset(-15, 0); const gfx::Vector2d kOffset(-15, 0);
......
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