diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 23:09:40 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 23:09:40 +0000 |
commit | 099d3d24e38113a7a828c39f31b620bd28c11268 (patch) | |
tree | 38fad0bb5a9759fc460667a8e64dc86a1fe4d79a /chrome | |
parent | 58f2cdffde416d3e7d659a342358d26ed4a8b34f (diff) | |
download | chromium_src-099d3d24e38113a7a828c39f31b620bd28c11268.zip chromium_src-099d3d24e38113a7a828c39f31b620bd28c11268.tar.gz chromium_src-099d3d24e38113a7a828c39f31b620bd28c11268.tar.bz2 |
Fixes text field background when disabled/read-only to better match
how Windows looks. This also changes SetEnabled not to adjust
read_only_ state. That SetEnabled invoked SetReadOnly is just wrong,
the two don't have to be the same.
BUG=1218491
TEST=bring up the keyword editor and double click on one of the
default search engines, make sure the background of the text field
looks disabled.
Review URL: http://codereview.chromium.org/10662
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/views/text_field.cc | 54 | ||||
-rw-r--r-- | chrome/views/text_field.h | 13 |
2 files changed, 44 insertions, 23 deletions
diff --git a/chrome/views/text_field.cc b/chrome/views/text_field.cc index d45e875..3c64c3d 100644 --- a/chrome/views/text_field.cc +++ b/chrome/views/text_field.cc @@ -12,6 +12,7 @@ #include <vsstyle.h> #include "base/gfx/native_theme.h" +#include "base/gfx/skia_utils.h" #include "base/scoped_clipboard_writer.h" #include "base/string_util.h" #include "base/win_util.h" @@ -61,6 +62,8 @@ class TextField::Edit void SetEnabled(bool enabled); + void SetBackgroundColor(COLORREF bg_color); + // CWindowImpl BEGIN_MSG_MAP(Edit) MSG_WM_CHAR(OnChar) @@ -196,6 +199,8 @@ class TextField::Edit int ime_composition_start_; int ime_composition_length_; + COLORREF bg_color_; + DISALLOW_EVIL_CONSTRUCTORS(Edit); }; @@ -242,7 +247,8 @@ TextField::Edit::Edit(TextField* parent, bool draw_border) draw_border_(draw_border), ime_discard_composition_(false), ime_composition_start_(0), - ime_composition_length_(0) { + ime_composition_length_(0), + bg_color_(0) { if (!did_load_library_) did_load_library_ = !!LoadLibrary(L"riched20.dll"); @@ -341,6 +347,11 @@ void TextField::Edit::SetEnabled(bool enabled) { static_cast<WPARAM>(enabled), 0); } +void TextField::Edit::SetBackgroundColor(COLORREF bg_color) { + CRichEditCtrl::SetBackgroundColor(bg_color); + bg_color_ = bg_color; +} + bool TextField::Edit::IsCommandEnabled(int id) const { switch (id) { case IDS_UNDO: return !parent_->IsReadOnly() && !!CanUndo(); @@ -663,7 +674,9 @@ void TextField::Edit::OnNCPaint(HRGN region) { window_rect.right - content_insets_.right(), window_rect.bottom - content_insets_.bottom()); - FillRect(hdc, &window_rect, (HBRUSH) (COLOR_WINDOW+1)); + HBRUSH brush = CreateSolidBrush(bg_color_); + FillRect(hdc, &window_rect, brush); + DeleteObject(brush); int part; int state; @@ -697,7 +710,8 @@ void TextField::Edit::OnNCPaint(HRGN region) { (!parent_->IsEnabled() || parent_->IsReadOnly()) ? DFCS_INACTIVE : 0; NativeTheme::instance()->PaintTextField(hdc, part, state, classic_state, - &window_rect, NULL, false, true); + &window_rect, bg_color_, false, + true); // NOTE: I tried checking the transparent property of the theme and invoking // drawParentBackground, but it didn't seem to make a difference. @@ -898,8 +912,7 @@ void TextField::ViewHierarchyChanged(bool is_add, View* parent, View* child) { native_view_->Attach(*edit_); if (!text_.empty()) edit_->SetText(text_); - if (!use_default_background_color_) - SetBackgroundColor(background_color_); + UpdateEditBackgroundColor(); Layout(); } } else if (!is_add && edit_ && IsWindow(edit_->m_hWnd)) { @@ -968,13 +981,13 @@ bool TextField::IsMultiLine() const { } void TextField::SetReadOnly(bool read_only) { - if (edit_) + read_only_ = read_only; + if (edit_) { edit_->SetReadOnly(read_only); - else - read_only_ = read_only; + UpdateEditBackgroundColor(); + } } - void TextField::Focus() { ::SetFocus(native_view_->GetHWND()); } @@ -996,17 +1009,12 @@ HWND TextField::GetNativeComponent() { void TextField::SetBackgroundColor(SkColor color) { background_color_ = color; use_default_background_color_ = false; - if (edit_) { - edit_->SetBackgroundColor(RGB(SkColorGetR(color), - SkColorGetG(color), - SkColorGetB(color))); - } + UpdateEditBackgroundColor(); } void TextField::SetDefaultBackgroundColor() { use_default_background_color_ = true; - if (edit_) - edit_->SetBackgroundColor(); + UpdateEditBackgroundColor(); } void TextField::SetFont(const ChromeFont& font) { @@ -1045,7 +1053,6 @@ void TextField::RemoveBorder() { void TextField::SetEnabled(bool enabled) { View::SetEnabled(enabled); - SetReadOnly(!enabled); edit_->SetEnabled(enabled); } @@ -1066,5 +1073,16 @@ bool TextField::ShouldLookupAccelerators(const KeyEvent& e) { return !win_util::IsNumPadDigit(e.GetCharacter(), e.IsExtendedKey()); } -} // namespace views +void TextField::UpdateEditBackgroundColor() { + if (!edit_) + return; + COLORREF bg_color; + if (!use_default_background_color_) + bg_color = gfx::SkColorToCOLORREF(background_color_); + else + bg_color = GetSysColor(read_only_ ? COLOR_3DFACE : COLOR_WINDOW); + edit_->SetBackgroundColor(bg_color); +} + +} // namespace views diff --git a/chrome/views/text_field.h b/chrome/views/text_field.h index e69dd329..6d75e3b 100644 --- a/chrome/views/text_field.h +++ b/chrome/views/text_field.h @@ -5,8 +5,8 @@ // These classes define a text field widget that can be used in the views UI // toolkit. -#ifndef CHROME_VIEWS_TEXT_FIELD_H__ -#define CHROME_VIEWS_TEXT_FIELD_H__ +#ifndef CHROME_VIEWS_TEXT_FIELD_H_ +#define CHROME_VIEWS_TEXT_FIELD_H_ #include <string> @@ -136,6 +136,7 @@ class TextField : public View { void RemoveBorder(); // Disable the edit control. + // NOTE: this does NOT change the read only property. void SetEnabled(bool enabled); private: @@ -150,6 +151,9 @@ class TextField : public View { // Reset the text field native control. void ResetNativeControl(); + // Resets the background color of the edit. + void UpdateEditBackgroundColor(); + // This encapsulates the HWND of the native text field. HWNDView* native_view_; @@ -188,10 +192,9 @@ class TextField : public View { // Calculates the insets for the text field. void CalculateInsets(gfx::Insets* insets); - DISALLOW_EVIL_CONSTRUCTORS(TextField); + DISALLOW_COPY_AND_ASSIGN(TextField); }; } // namespace views -#endif // CHROME_VIEWS_TEXT_FIELD_H__ - +#endif // CHROME_VIEWS_TEXT_FIELD_H_ |