diff options
-rw-r--r-- | chrome/browser/views/about_chrome_view.cc | 13 | ||||
-rw-r--r-- | chrome/browser/views/bookmark_bubble_view.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/first_run_view.cc | 1 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.cc | 13 | ||||
-rw-r--r-- | chrome/browser/views/info_bubble.h | 4 | ||||
-rw-r--r-- | chrome/browser/views/infobars/infobars.cc | 4 | ||||
-rw-r--r-- | chrome/browser/views/location_bar_view.cc | 2 | ||||
-rw-r--r-- | views/background.cc | 31 | ||||
-rw-r--r-- | views/background.h | 10 | ||||
-rw-r--r-- | views/controls/label.cc | 18 | ||||
-rw-r--r-- | views/controls/label.h | 4 | ||||
-rw-r--r-- | views/controls/link.cc | 62 | ||||
-rw-r--r-- | views/controls/link.h | 6 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 11 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.h | 1 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.cc | 11 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.h | 1 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_wrapper.h | 3 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 19 | ||||
-rw-r--r-- | views/controls/textfield/textfield.h | 21 |
20 files changed, 198 insertions, 49 deletions
diff --git a/chrome/browser/views/about_chrome_view.cc b/chrome/browser/views/about_chrome_view.cc index 6b2ba40..fc18064 100644 --- a/chrome/browser/views/about_chrome_view.cc +++ b/chrome/browser/views/about_chrome_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -166,6 +166,7 @@ void AboutChromeView::Init() { l10n_util::GetString(IDS_PRODUCT_NAME)); about_title_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(18, BOLD_FONTTYPE)); + about_title_label_->SetColor(SK_ColorBLACK); AddChildView(about_title_label_); // This is a text field so people can copy the version number from the dialog. @@ -173,6 +174,7 @@ void AboutChromeView::Init() { version_label_->SetText(current_version_); version_label_->SetReadOnly(true); version_label_->RemoveBorder(); + version_label_->SetTextColor(SK_ColorBLACK); version_label_->SetBackgroundColor(SK_ColorWHITE); version_label_->SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::BaseFont).DeriveFont(0, BOLD_FONTTYPE)); @@ -493,6 +495,13 @@ void AboutChromeView::DrawTextStartingFrom(gfx::Canvas* canvas, const gfx::Rect& bounds, const gfx::Font& font, bool ltr_within_rtl) { +#if defined(OS_WIN) + const SkColor text_color = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); +#else + // TODO(beng): source from theme provider. + const SkColor text_color = SkColor_BLACK; +#endif + // Iterate through line breaking opportunities (which in English would be // spaces and such. This tells us where to wrap. WordIterator iter(text, WordIterator::BREAK_LINE); @@ -537,7 +546,7 @@ void AboutChromeView::DrawTextStartingFrom(gfx::Canvas* canvas, int y = position->height() + bounds.y(); // Draw the text on the screen (mirrored, if RTL run). - canvas->DrawStringInt(word, font, SK_ColorBLACK, x, y, w, h, flags); + canvas->DrawStringInt(word, font, text_color, x, y, w, h, flags); if (word.size() > 0 && word[word.size() - 1] == L'\x0a') { // When we come across '\n', we move to the beginning of the next line. diff --git a/chrome/browser/views/bookmark_bubble_view.cc b/chrome/browser/views/bookmark_bubble_view.cc index 6a48deb..c85052f 100644 --- a/chrome/browser/views/bookmark_bubble_view.cc +++ b/chrome/browser/views/bookmark_bubble_view.cc @@ -5,6 +5,7 @@ #include "chrome/browser/views/bookmark_bubble_view.h" #include "app/gfx/canvas.h" +#include "app/gfx/color_utils.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "base/keyboard_codes.h" @@ -33,9 +34,6 @@ using views::Link; using views::NativeButton; using views::View; -// Color of the title. -static const SkColor kTitleColor = SkColorSetRGB(6, 45, 117); - // Padding between "Title:" and the actual title. static const int kTitlePadding = 4; @@ -226,9 +224,15 @@ BookmarkBubbleView::BookmarkBubbleView(InfoBubbleDelegate* delegate, } void BookmarkBubbleView::Init() { - if (!kCloseImage) { + static SkColor kTitleColor; + static bool initialized = false; + if (!initialized) { + kTitleColor = color_utils::GetReadableColor(SkColorSetRGB(6, 45, 117), + InfoBubble::kBackgroundColor); kCloseImage = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_INFO_BUBBLE_CLOSE); + + initialized = true; } remove_link_ = new Link(l10n_util::GetString( diff --git a/chrome/browser/views/first_run_view.cc b/chrome/browser/views/first_run_view.cc index 334213c..d29c567 100644 --- a/chrome/browser/views/first_run_view.cc +++ b/chrome/browser/views/first_run_view.cc @@ -56,6 +56,7 @@ void FirstRunView::SetupControls() { default_browser_->SetChecked(true); welcome_label_ = new Label(l10n_util::GetString(IDS_FIRSTRUN_DLG_TEXT)); + welcome_label_->SetColor(SK_ColorBLACK); welcome_label_->SetMultiLine(true); welcome_label_->SetHorizontalAlignment(Label::ALIGN_LEFT); welcome_label_->SizeToFit(0); diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc index 92dd6f7..40244ef 100644 --- a/chrome/browser/views/info_bubble.cc +++ b/chrome/browser/views/info_bubble.cc @@ -14,18 +14,15 @@ #include "views/widget/root_view.h" #include "views/window/window.h" -namespace { - // Background color of the bubble. #if defined(OS_WIN) -const SkColor kBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); +const SkColor InfoBubble::kBackgroundColor = + color_utils::GetSysSkColor(COLOR_WINDOW); #else // TODO(beng): source from theme provider. -const SkColor kBackgroundColor = SK_ColorWHITE; +const SkColor InfoBubble::kBackgroundColor = SK_ColorWHITE; #endif -} - // BorderContents ------------------------------------------------------------- // This is used to paint the border of the InfoBubble. Windows uses this via @@ -75,7 +72,7 @@ void BorderContents::InitAndGetBounds( // Set the border. BubbleBorder* bubble_border = new BubbleBorder; set_border(bubble_border); - bubble_border->set_background_color(kBackgroundColor); + bubble_border->set_background_color(InfoBubble::kBackgroundColor); // Give the contents a margin. gfx::Size local_contents_size(contents_size); @@ -128,7 +125,7 @@ void BorderContents::Paint(gfx::Canvas* canvas) { SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kFill_Style); - paint.setColor(kBackgroundColor); + paint.setColor(InfoBubble::kBackgroundColor); gfx::Path path; gfx::Rect bounds(GetLocalBounds(false)); SkRect rect; diff --git a/chrome/browser/views/info_bubble.h b/chrome/browser/views/info_bubble.h index 2d4a0f2..fc5f671 100644 --- a/chrome/browser/views/info_bubble.h +++ b/chrome/browser/views/info_bubble.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -101,6 +101,8 @@ class InfoBubble : public views::WidgetGtk { // Overridden from WidgetWin: virtual void Close(); + static const SkColor kBackgroundColor; + protected: InfoBubble(); virtual ~InfoBubble() {} diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index c2fc041..be4e0ed 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -270,6 +270,7 @@ AlertInfoBar::AlertInfoBar(AlertInfoBarDelegate* delegate) label_ = new views::Label( delegate->GetMessageText(), ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::MediumFont)); + label_->SetColor(SK_ColorBLACK); label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label_); @@ -332,6 +333,8 @@ LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) ResourceBundle& rb = ResourceBundle::GetSharedInstance(); label_1_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); label_2_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); + label_1_->SetColor(SK_ColorBLACK); + label_2_->SetColor(SK_ColorBLACK); label_1_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); label_2_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); AddChildView(label_1_); @@ -342,6 +345,7 @@ LinkInfoBar::LinkInfoBar(LinkInfoBarDelegate* delegate) link_->SetFont(rb.GetFont(ResourceBundle::MediumFont)); link_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); link_->SetController(this); + link_->MakeReadableOverBackgroundColor(background()->get_color()); AddChildView(link_); } diff --git a/chrome/browser/views/location_bar_view.cc b/chrome/browser/views/location_bar_view.cc index 0e3e104..e5ba8f6 100644 --- a/chrome/browser/views/location_bar_view.cc +++ b/chrome/browser/views/location_bar_view.cc @@ -768,6 +768,8 @@ LocationBarView::SelectedKeywordView::SelectedKeywordView(Profile* profile) partial_label_.set_border( views::Border::CreateEmptyBorder(kTopInset, kLeftInset, kBottomInset, kRightInset)); + full_label_.SetColor(SK_ColorBLACK); + partial_label_.SetColor(SK_ColorBLACK); } LocationBarView::SelectedKeywordView::~SelectedKeywordView() { diff --git a/views/background.cc b/views/background.cc index 5206349..333b011 100644 --- a/views/background.cc +++ b/views/background.cc @@ -1,10 +1,11 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "views/background.h" #include "app/gfx/canvas.h" +#include "app/gfx/color_utils.h" #include "base/logging.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkPaint.h" @@ -17,21 +18,18 @@ namespace views { // background in a solid color. class SolidBackground : public Background { public: - explicit SolidBackground(const SkColor& color) : - color_(color) { - SetNativeControlColor(color_); + explicit SolidBackground(const SkColor& color) { + SetNativeControlColor(color); } void Paint(gfx::Canvas* canvas, View* view) const { // Fill the background. Note that we don't constrain to the bounds as // canvas is already clipped for us. - canvas->drawColor(color_); + canvas->drawColor(get_color()); } private: - const SkColor color_; - - DISALLOW_EVIL_CONSTRUCTORS(SolidBackground); + DISALLOW_COPY_AND_ASSIGN(SolidBackground); }; class BackgroundPainter : public Background { @@ -56,12 +54,13 @@ class BackgroundPainter : public Background { bool owns_painter_; Painter* painter_; - DISALLOW_EVIL_CONSTRUCTORS(BackgroundPainter); + DISALLOW_COPY_AND_ASSIGN(BackgroundPainter); }; Background::Background() + : color_(SK_ColorWHITE) #if defined(OS_WIN) - : native_control_brush_(NULL) + , native_control_brush_(NULL) #endif { } @@ -73,6 +72,7 @@ Background::~Background() { } void Background::SetNativeControlColor(SkColor color) { + color_ = color; #if defined(OS_WIN) DeleteObject(native_control_brush_); native_control_brush_ = CreateSolidBrush(skia::SkColorToCOLORREF(color)); @@ -93,13 +93,10 @@ Background* Background::CreateStandardPanelBackground() { //static Background* Background::CreateVerticalGradientBackground( const SkColor& color1, const SkColor& color2) { - Background *background = - CreateBackgroundPainter(true, Painter::CreateVerticalGradient(color1, - color2)); - background->SetNativeControlColor( // 50% blend of colors 1 & 2 - SkColorSetRGB((SkColorGetR(color1) + SkColorGetR(color2)) / 2, - (SkColorGetG(color1) + SkColorGetG(color2)) / 2, - (SkColorGetB(color1) + SkColorGetB(color2)) / 2)); + Background* background = CreateBackgroundPainter( + true, Painter::CreateVerticalGradient(color1, color2)); + background->SetNativeControlColor( + color_utils::AlphaBlend(color1, color2, 128)); return background; } diff --git a/views/background.h b/views/background.h index 1453749..a5215e4 100644 --- a/views/background.h +++ b/views/background.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -73,6 +73,12 @@ class Background { // controls. Unfortunately alpha=0 is not an option. void SetNativeControlColor(SkColor color); + // Returns the "background color". This is equivalent to the color set in + // SetNativeControlColor(). For solid backgrounds, this is the color; for + // gradient backgrounds, it's the midpoint of the gradient; for painter + // backgrounds, this is not useful (returns a default color). + SkColor get_color() const { return color_; } + #if defined(OS_WIN) // TODO(port): Make GetNativeControlBrush portable (currently uses HBRUSH). @@ -81,10 +87,12 @@ class Background { #endif // defined(OS_WIN) private: + SkColor color_; #if defined(OS_WIN) // TODO(port): Create portable replacement for HBRUSH. HBRUSH native_control_brush_; #endif // defined(OS_WIN) + DISALLOW_COPY_AND_ASSIGN(Background); }; diff --git a/views/controls/label.cc b/views/controls/label.cc index 8bda393..6e9a360 100644 --- a/views/controls/label.cc +++ b/views/controls/label.cc @@ -7,6 +7,7 @@ #include <math.h> #include "app/gfx/canvas.h" +#include "app/gfx/color_utils.h" #include "app/gfx/font.h" #include "app/gfx/insets.h" #include "app/gfx/text_elider.h" @@ -20,9 +21,8 @@ namespace views { // static const char Label::kViewClassName[] = "views/Label"; +SkColor Label::kEnabledColor, Label::kDisabledColor; -static const SkColor kEnabledColor = SK_ColorBLACK; -static const SkColor kDisabledColor = SkColorSetRGB(161, 161, 146); static const int kFocusBorderPadding = 1; Label::Label() { @@ -38,6 +38,20 @@ Label::Label(const std::wstring& text, const gfx::Font& font) { } void Label::Init(const std::wstring& text, const gfx::Font& font) { + static bool initialized = false; + if (!initialized) { +#if defined(OS_WIN) + kEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); +#else + // TODO(beng): source from theme provider. + kEnabledColor = SK_ColorBLACK; + kDisabledColor = SK_ColorGRAY; +#endif + + initialized = true; + } + contains_mouse_ = false; font_ = font; text_size_valid_ = false; diff --git a/views/controls/label.h b/views/controls/label.h index 9a5526a..19d921d 100644 --- a/views/controls/label.h +++ b/views/controls/label.h @@ -224,6 +224,10 @@ class Label : public View { int ComputeMultiLineFlags(); gfx::Size GetTextSize(); void Init(const std::wstring& text, const gfx::Font& font); + + // The colors to use for enabled and disabled labels. + static SkColor kEnabledColor, kDisabledColor; + std::wstring text_; GURL url_; gfx::Font font_; diff --git a/views/controls/link.cc b/views/controls/link.cc index c9bd256..f2887e0 100644 --- a/views/controls/link.cc +++ b/views/controls/link.cc @@ -8,44 +8,75 @@ #include <gdk/gdk.h> #endif +#include "app/gfx/color_utils.h" #include "app/gfx/font.h" #include "base/logging.h" #include "views/event.h" +namespace { + +void GetColors(const SkColor* background_color, // NULL means "use default" + SkColor* highlighted_color, + SkColor* disabled_color, + SkColor* normal_color) { + static SkColor kHighlightedColor, kDisabledColor, kNormalColor; + static bool initialized = false; + if (!initialized) { +#if defined(OS_WIN) + kHighlightedColor = color_utils::GetReadableColor( + SkColorSetRGB(200, 0, 0), color_utils::GetSysSkColor(COLOR_WINDOW)); + kDisabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); + kNormalColor = color_utils::GetSysSkColor(COLOR_HOTLIGHT); +#else + // TODO(beng): source from theme provider. + kHighlightedColor = SK_ColorRED; + kDisabledColor = SK_ColorBLACK; + kNormalColor = SkColorSetRGB(0, 51, 153); +#endif + + initialized = true; + } + + if (background_color) { + *highlighted_color = color_utils::GetReadableColor(kHighlightedColor, + *background_color); + *disabled_color = color_utils::GetReadableColor(kDisabledColor, + *background_color); + *normal_color = color_utils::GetReadableColor(kNormalColor, + *background_color); + } else { + *highlighted_color = kHighlightedColor; + *disabled_color = kDisabledColor; + *normal_color = kNormalColor; + } +} + +} + namespace views { #if defined(OS_WIN) static HCURSOR g_hand_cursor = NULL; #endif -// Default colors used for links. -static const SkColor kHighlightedColor = SkColorSetRGB(255, 0x00, 0x00); -static const SkColor kNormalColor = SkColorSetRGB(0, 51, 153); -static const SkColor kDisabledColor = SkColorSetRGB(0, 0, 0); - const char Link::kViewClassName[] = "views/Link"; Link::Link() : Label(L""), controller_(NULL), - highlighted_(false), - highlighted_color_(kHighlightedColor), - disabled_color_(kDisabledColor), - normal_color_(kNormalColor) { + highlighted_(false) { Init(); SetFocusable(true); } Link::Link(const std::wstring& title) : Label(title), controller_(NULL), - highlighted_(false), - highlighted_color_(kHighlightedColor), - disabled_color_(kDisabledColor), - normal_color_(kNormalColor) { + highlighted_(false) { Init(); SetFocusable(true); } void Link::Init() { + GetColors(NULL, &highlighted_color_, &disabled_color_, &normal_color_); SetColor(normal_color_); ValidateStyle(); } @@ -167,6 +198,11 @@ void Link::SetNormalColor(const SkColor& color) { ValidateStyle(); } +void Link::MakeReadableOverBackgroundColor(const SkColor& color) { + GetColors(&color, &highlighted_color_, &disabled_color_, &normal_color_); + ValidateStyle(); +} + void Link::SetHighlighted(bool f) { if (f != highlighted_) { highlighted_ = f; diff --git a/views/controls/link.h b/views/controls/link.h index 30b2bdb7..bf5039b 100644 --- a/views/controls/link.h +++ b/views/controls/link.h @@ -61,10 +61,14 @@ class Link : public Label { void SetDisabledColor(const SkColor& color); void SetNormalColor(const SkColor& color); + // If you'll be displaying the link over some non-system background color, + // call this with the relevant color and the link will auto-set its colors to + // be readable. + void MakeReadableOverBackgroundColor(const SkColor& color); + static const char kViewClassName[]; private: - // A highlighted link is clicked. void SetHighlighted(bool f); diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index ef7a67d..2a5aa15 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -84,6 +84,17 @@ void NativeTextfieldGtk::UpdateBorder() { return; } +void NativeTextfieldGtk::UpdateTextColor() { + if (textfield_->use_default_text_color()) { + // Passing NULL as the color undoes the effect of previous calls to + // gtk_widget_modify_text. + gtk_widget_modify_text(native_view(), GTK_STATE_NORMAL, NULL); + return; + } + GdkColor gdk_color = skia::SkColorToGdkColor(textfield_->text_color()); + gtk_widget_modify_text(native_view(), GTK_STATE_NORMAL, &gdk_color); +} + void NativeTextfieldGtk::UpdateBackgroundColor() { if (textfield_->use_default_background_color()) { // Passing NULL as the color undoes the effect of previous calls to diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h index ef2f4fe..bbd0663 100644 --- a/views/controls/textfield/native_textfield_gtk.h +++ b/views/controls/textfield/native_textfield_gtk.h @@ -27,6 +27,7 @@ class NativeTextfieldGtk : public NativeControlGtk, virtual void SelectAll(); virtual void ClearSelection(); virtual void UpdateBorder(); + virtual void UpdateTextColor(); virtual void UpdateBackgroundColor(); virtual void UpdateReadOnly(); virtual void UpdateFont(); diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 15d6bd9..1872492 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -170,6 +170,15 @@ void NativeTextfieldWin::UpdateBorder() { SWP_NOOWNERZORDER | SWP_NOSIZE); } +void NativeTextfieldWin::UpdateTextColor() { + CHARFORMAT cf = {0}; + cf.dwMask = CFM_COLOR; + cf.crTextColor = textfield_->use_default_text_color() ? + GetSysColor(textfield_->read_only() ? COLOR_GRAYTEXT : COLOR_WINDOWTEXT) : + skia::SkColorToCOLORREF(textfield_->text_color()); + CRichEditCtrl::SetDefaultCharFormat(cf); +} + void NativeTextfieldWin::UpdateBackgroundColor() { if (!textfield_->use_default_background_color()) { bg_color_ = skia::SkColorToCOLORREF(textfield_->background_color()); @@ -187,6 +196,8 @@ void NativeTextfieldWin::UpdateReadOnly() { void NativeTextfieldWin::UpdateFont() { SendMessage(m_hWnd, WM_SETFONT, reinterpret_cast<WPARAM>(textfield_->font().hfont()), TRUE); + // Setting the font blows away any text color we've set, so reset it. + UpdateTextColor(); } void NativeTextfieldWin::UpdateEnabled() { diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h index e1e51d7..270411d 100644 --- a/views/controls/textfield/native_textfield_win.h +++ b/views/controls/textfield/native_textfield_win.h @@ -48,6 +48,7 @@ class NativeTextfieldWin virtual void SelectAll(); virtual void ClearSelection(); virtual void UpdateBorder(); + virtual void UpdateTextColor(); virtual void UpdateBackgroundColor(); virtual void UpdateReadOnly(); virtual void UpdateFont(); diff --git a/views/controls/textfield/native_textfield_wrapper.h b/views/controls/textfield/native_textfield_wrapper.h index f11fc33a..14dea7f 100644 --- a/views/controls/textfield/native_textfield_wrapper.h +++ b/views/controls/textfield/native_textfield_wrapper.h @@ -45,6 +45,9 @@ class NativeTextfieldWrapper { // by the Textfield. virtual void UpdateBorder() = 0; + // Updates the text color used when painting the native text field. + virtual void UpdateTextColor() = 0; + // Updates the background color used when painting the native text field. virtual void UpdateBackgroundColor() = 0; diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index 05fb018..c467831 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -39,7 +39,9 @@ Textfield::Textfield() read_only_(false), default_width_in_chars_(0), draw_border_(true), + text_color_(SK_ColorBLACK), background_color_(SK_ColorWHITE), + use_default_text_color_(true), use_default_background_color_(true), num_lines_(1), initialized_(false) { @@ -53,7 +55,9 @@ Textfield::Textfield(StyleFlags style) read_only_(false), default_width_in_chars_(0), draw_border_(true), + text_color_(SK_ColorBLACK), background_color_(SK_ColorWHITE), + use_default_text_color_(true), use_default_background_color_(true), num_lines_(1), initialized_(false) { @@ -75,6 +79,7 @@ void Textfield::SetReadOnly(bool read_only) { read_only_ = read_only; if (native_wrapper_) { native_wrapper_->UpdateReadOnly(); + native_wrapper_->UpdateTextColor(); native_wrapper_->UpdateBackgroundColor(); } } @@ -115,6 +120,19 @@ void Textfield::ClearSelection() const { native_wrapper_->ClearSelection(); } +void Textfield::SetTextColor(SkColor color) { + text_color_ = color; + use_default_text_color_ = false; + if (native_wrapper_) + native_wrapper_->UpdateTextColor(); +} + +void Textfield::UseDefaultTextColor() { + use_default_text_color_ = true; + if (native_wrapper_) + native_wrapper_->UpdateTextColor(); +} + void Textfield::SetBackgroundColor(SkColor color) { background_color_ = color; use_default_background_color_ = false; @@ -244,6 +262,7 @@ void Textfield::ViewHierarchyChanged(bool is_add, View* parent, View* child) { // TODO(beng): Move this initialization to NativeTextfieldWin once it // subclasses NativeControlWin. native_wrapper_->UpdateText(); + native_wrapper_->UpdateTextColor(); native_wrapper_->UpdateBackgroundColor(); native_wrapper_->UpdateReadOnly(); native_wrapper_->UpdateFont(); diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h index 7bc5f68..b1f5259 100644 --- a/views/controls/textfield/textfield.h +++ b/views/controls/textfield/textfield.h @@ -135,6 +135,18 @@ class Textfield : public View { // Accessor for |style_|. StyleFlags style() const { return style_; } + // Gets/Sets the text color to be used when painting the Textfield. + // Call |UseDefaultTextColor| to return to the system default colors. + SkColor text_color() const { return text_color_; } + void SetTextColor(SkColor color); + + // Gets/Sets whether the default text color should be used when painting the + // Textfield. + bool use_default_text_color() const { + return use_default_text_color_; + } + void UseDefaultTextColor(); + // Gets/Sets the background color to be used when painting the Textfield. // Call |UseDefaultBackgroundColor| to return to the system default colors. SkColor background_color() const { return background_color_; } @@ -227,6 +239,15 @@ class Textfield : public View { // Whether the border is drawn. bool draw_border_; + // The text color to be used when painting the Textfield, provided + // |use_default_text_color_| is set to false. + SkColor text_color_; + + // When true, the system text color for Textfields is used when painting this + // Textfield. When false, the value of |text_color_| determines the + // Textfield's text color. + bool use_default_text_color_; + // The background color to be used when painting the Textfield, provided // |use_default_background_color_| is set to false. SkColor background_color_; |