diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 16:49:26 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-25 16:49:26 +0000 |
commit | 28065f66296d0d012aa5b02c147f4f77ef8a771e (patch) | |
tree | 9fc2567cd9a4edaf09a322e2465b8540787c118c /views/controls/textfield | |
parent | 120e1f1b2728ae5d1d4fed21bddb3533b921fdba (diff) | |
download | chromium_src-28065f66296d0d012aa5b02c147f4f77ef8a771e.zip chromium_src-28065f66296d0d012aa5b02c147f4f77ef8a771e.tar.gz chromium_src-28065f66296d0d012aa5b02c147f4f77ef8a771e.tar.bz2 |
Use the system WINDOWTEXT color for labels, instead of black. Also use the system WINDOW color for InfoBubbles, not white. Several places are made to explicitly use black labels where that's correct or respecting system colors is a non-trivial fix (bugs filed for most).
Also, apparently I didn't get all my cleanup changes in the last patch, oops.
BUG=92,21027
TEST=Set theme to high-contrast black on white, check that most pieces of chrome UI have readable text
Review URL: http://codereview.chromium.org/237005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27196 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/textfield')
-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 |
7 files changed, 67 insertions, 0 deletions
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_; |