diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 22:04:17 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-10 22:04:17 +0000 |
commit | 7f98defa88b14435de270c5e0cc4419c4dba68b9 (patch) | |
tree | 1a22ba756263b83ebb3ea1470cde0514bd48e445 /ui | |
parent | 56e691305912ef4fb469c9d0004fc697c3b9a88c (diff) | |
download | chromium_src-7f98defa88b14435de270c5e0cc4419c4dba68b9.zip chromium_src-7f98defa88b14435de270c5e0cc4419c4dba68b9.tar.gz chromium_src-7f98defa88b14435de270c5e0cc4419c4dba68b9.tar.bz2 |
Use native theme colors for textfields; etc.
Make LocationBarView::GetColor use NativeTheme colors.
(except the CrOS transparent Omnibox background color)
Add NativeTheme read-only textfield color/background IDs.
Cache a set of Windows system colors in NativeThemeWin.
Update cached colors via gfx::SysColorChangeListener impl.
Init colors in NativeTextfieldViews, not TextfieldViewsModel.
Refactor Textfield and NativeTextfieldViews color code.
Nix frivolous AutocompleteTextfield::PaintChildren OVERRIDE.
Nix Textfield cursor color settings and visibility kludge.
(replace with proper cursor enabled accessors for views)
TODO(followup): Fix related existing issues (not affected here):
(existing textfields don't update with system color changes)
(bubbles seem to cache the system colors at startup...)
BUG=134766
TEST=Views textfields are created with the current system colors.
R=sky@chromium.org,varunjain@chromium.org,samarth@chromium.org
TBR=marja@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11421204
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@172142 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/sys_color_change_listener.h | 2 | ||||
-rw-r--r-- | ui/native_theme/native_theme.cc | 2 | ||||
-rw-r--r-- | ui/native_theme/native_theme.h | 4 | ||||
-rw-r--r-- | ui/native_theme/native_theme_aura.cc | 6 | ||||
-rw-r--r-- | ui/native_theme/native_theme_win.cc | 71 | ||||
-rw-r--r-- | ui/native_theme/native_theme_win.h | 18 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views.cc | 69 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_views.h | 6 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_win.cc | 29 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_win.h | 3 | ||||
-rw-r--r-- | ui/views/controls/textfield/native_textfield_wrapper.h | 7 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield.cc | 37 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield.h | 36 | ||||
-rw-r--r-- | ui/views/controls/textfield/textfield_views_model.cc | 11 |
14 files changed, 156 insertions, 145 deletions
diff --git a/ui/gfx/sys_color_change_listener.h b/ui/gfx/sys_color_change_listener.h index 522e377..2d19663 100644 --- a/ui/gfx/sys_color_change_listener.h +++ b/ui/gfx/sys_color_change_listener.h @@ -18,7 +18,7 @@ namespace gfx { UI_EXPORT bool IsInvertedColorScheme(); // Interface for classes that want to listen to system color changes. -class SysColorChangeListener { +class UI_EXPORT SysColorChangeListener { public: virtual void OnSysColorChange() = 0; diff --git a/ui/native_theme/native_theme.cc b/ui/native_theme/native_theme.cc index 6bc7a93..b36c914 100644 --- a/ui/native_theme/native_theme.cc +++ b/ui/native_theme/native_theme.cc @@ -34,4 +34,6 @@ NativeTheme::NativeTheme() track_color_(0xd3d3d3) { } +NativeTheme::~NativeTheme() {} + } // namespace ui diff --git a/ui/native_theme/native_theme.h b/ui/native_theme/native_theme.h index ed3ed35..3ee74a2 100644 --- a/ui/native_theme/native_theme.h +++ b/ui/native_theme/native_theme.h @@ -243,6 +243,8 @@ class NATIVE_THEME_EXPORT NativeTheme { // Textfield kColorId_TextfieldDefaultColor, kColorId_TextfieldDefaultBackground, + kColorId_TextfieldReadOnlyColor, + kColorId_TextfieldReadOnlyBackground, kColorId_TextfieldSelectionColor, kColorId_TextfieldSelectionBackgroundFocused, kColorId_TextfieldSelectionBackgroundUnfocused, @@ -263,7 +265,7 @@ class NATIVE_THEME_EXPORT NativeTheme { protected: NativeTheme(); - virtual ~NativeTheme() {} + virtual ~NativeTheme(); unsigned int thumb_inactive_color_; unsigned int thumb_active_color_; diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc index 0b5f6b0..8cfdb31 100644 --- a/ui/native_theme/native_theme_aura.cc +++ b/ui/native_theme/native_theme_aura.cc @@ -43,6 +43,8 @@ const SkColor kLabelBackgroundColor = SK_ColorWHITE; // Textfield: const SkColor kTextfieldDefaultColor = SK_ColorBLACK; const SkColor kTextfieldDefaultBackground = SK_ColorWHITE; +const SkColor kTextfieldReadOnlyColor = SK_ColorDKGRAY; +const SkColor kTextfieldReadOnlyBackground = SK_ColorWHITE; const SkColor kTextfieldSelectionBackgroundFocused = SkColorSetARGB(0x54, 0x60, 0xA8, 0xEB); const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; @@ -127,6 +129,10 @@ SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { return kTextfieldDefaultColor; case kColorId_TextfieldDefaultBackground: return kTextfieldDefaultBackground; + case kColorId_TextfieldReadOnlyColor: + return kTextfieldReadOnlyColor; + case kColorId_TextfieldReadOnlyBackground: + return kTextfieldReadOnlyBackground; case kColorId_TextfieldSelectionColor: return kTextfieldSelectionColor; case kColorId_TextfieldSelectionBackgroundFocused: diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc index 7ede675..e4065a7 100644 --- a/ui/native_theme/native_theme_win.cc +++ b/ui/native_theme/native_theme_win.cc @@ -49,26 +49,24 @@ const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); -// Label: -const SkColor kLabelEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); -const SkColor kLabelDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); -const SkColor kLabelBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); // Textfield: -const SkColor kTextfieldDefaultColor = SK_ColorBLACK; -const SkColor kTextfieldDefaultBackground = SK_ColorWHITE; -const SkColor kTextfieldSelectionColor = SK_ColorWHITE; -const SkColor kTextfieldSelectionBackgroundFocused = - SkColorSetRGB(0x1D, 0x90, 0xFF); const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; -SkColor WinColorToSkColor(COLORREF color) { - return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); -} +// Windows system color IDs cached and updated by the native theme. +const int kSystemColors[] = { + COLOR_3DFACE, + COLOR_GRAYTEXT, + COLOR_HIGHLIGHT, + COLOR_HIGHLIGHTTEXT, + COLOR_SCROLLBAR, + COLOR_WINDOW, + COLOR_WINDOWTEXT, +}; void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. - SkColor face = skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)); - SkColor highlight = skia::COLORREFToSkColor(GetSysColor(COLOR_3DHILIGHT)); + const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); + const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); SkColor buffer[] = { face, highlight, highlight, face }; // Confusing bit: we first create a temporary bitmap with our desired pattern, // then copy it to another bitmap. The temporary bitmap doesn't take @@ -154,7 +152,7 @@ SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, int default_sys_color) const { SkColor color; if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) - color = skia::COLORREFToSkColor(GetSysColor(default_sys_color)); + color = color_utils::GetSysSkColor(default_sys_color); return color; } @@ -306,7 +304,8 @@ NativeThemeWin::NativeThemeWin() close_theme_(NULL), set_theme_properties_(NULL), is_theme_active_(NULL), - get_theme_int_(NULL) { + get_theme_int_(NULL), + ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)) { if (theme_dll_) { draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>( GetProcAddress(theme_dll_, "DrawThemeBackground")); @@ -330,6 +329,9 @@ NativeThemeWin::NativeThemeWin() GetProcAddress(theme_dll_, "GetThemeInt")); } memset(theme_handles_, 0, sizeof(theme_handles_)); + + // Initialize the cached system colors. + UpdateSystemColors(); } NativeThemeWin::~NativeThemeWin() { @@ -341,6 +343,17 @@ NativeThemeWin::~NativeThemeWin() { } } +void NativeThemeWin::OnSysColorChange() { + UpdateSystemColors(); +} + +void NativeThemeWin::UpdateSystemColors() { + for (int i = 0; i < arraysize(kSystemColors); ++i) { + system_colors_[kSystemColors[i]] = + color_utils::GetSysSkColor(kSystemColors[i]); + } +} + void NativeThemeWin::PaintDirect(SkCanvas* canvas, Part part, State state, @@ -441,7 +454,7 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { case kColorId_DialogBackground: // TODO(benrg): Should this use the new Windows theme functions? The old // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE). - return WinColorToSkColor(GetSysColor(COLOR_3DFACE)); + return system_colors_[COLOR_3DFACE]; // FocusableBorder case kColorId_FocusedBorderColor: @@ -473,21 +486,25 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { // Label case kColorId_LabelEnabledColor: - return kLabelEnabledColor; + return system_colors_[COLOR_WINDOWTEXT]; case kColorId_LabelDisabledColor: - return kLabelDisabledColor; + return system_colors_[COLOR_GRAYTEXT]; case kColorId_LabelBackgroundColor: - return kLabelBackgroundColor; + return system_colors_[COLOR_WINDOW]; // Textfield case kColorId_TextfieldDefaultColor: - return kTextfieldDefaultColor; + return system_colors_[COLOR_WINDOWTEXT]; case kColorId_TextfieldDefaultBackground: - return kTextfieldDefaultBackground; + return system_colors_[COLOR_WINDOW]; + case kColorId_TextfieldReadOnlyColor: + return system_colors_[COLOR_GRAYTEXT]; + case kColorId_TextfieldReadOnlyBackground: + return system_colors_[COLOR_3DFACE]; case kColorId_TextfieldSelectionColor: - return kTextfieldSelectionColor; + return system_colors_[COLOR_HIGHLIGHTTEXT]; case kColorId_TextfieldSelectionBackgroundFocused: - return kTextfieldSelectionBackgroundFocused; + return system_colors_[COLOR_HIGHLIGHT]; case kColorId_TextfieldSelectionBackgroundUnfocused: return kTextfieldSelectionBackgroundUnfocused; @@ -1143,10 +1160,8 @@ HRESULT NativeThemeWin::PaintScrollbarTrack( return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); // Draw it manually. - const DWORD colorScrollbar = GetSysColor(COLOR_SCROLLBAR); - const DWORD color3DFace = GetSysColor(COLOR_3DFACE); - if ((colorScrollbar != color3DFace) && - (colorScrollbar != GetSysColor(COLOR_WINDOW))) { + if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && + (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); } else { SkPaint paint; diff --git a/ui/native_theme/native_theme_win.h b/ui/native_theme/native_theme_win.h index 1e83d15..d4bdea7 100644 --- a/ui/native_theme/native_theme_win.h +++ b/ui/native_theme/native_theme_win.h @@ -11,6 +11,8 @@ // For more information on visual style parts and states, see: // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/userex/topics/partsandstates.asp +#include <map> + #include <windows.h> #include <uxtheme.h> @@ -18,6 +20,7 @@ #include "base/compiler_specific.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/gfx/size.h" +#include "ui/gfx/sys_color_change_listener.h" #include "ui/native_theme/native_theme.h" class SkCanvas; @@ -30,7 +33,8 @@ namespace ui { // of several PaintXXX methods to an API, inherited from the NativeTheme base // class, that consists of a single Paint() method with a argument to indicate // what kind of part to paint. -class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme { +class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme, + public gfx::SysColorChangeListener { public: enum ThemeName { BUTTON, @@ -96,7 +100,7 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme { bool fill_content_area, bool draw_edges) const; - // NativeTheme Implementation: + // NativeTheme implementation: virtual gfx::Size GetPartSize(Part part, State state, const ExtraParams& extra) const OVERRIDE; @@ -111,6 +115,12 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme { NativeThemeWin(); ~NativeThemeWin(); + // gfx::SysColorChangeListener implementation: + virtual void OnSysColorChange() OVERRIDE; + + // Update the locally cached set of system colors. + void UpdateSystemColors(); + // Paint directly to canvas' HDC. void PaintDirect(SkCanvas* canvas, Part part, @@ -332,6 +342,10 @@ class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme { // A cache of open theme handles. mutable HANDLE theme_handles_[LAST]; + // The system color change listener and the updated cache of system colors. + gfx::ScopedSysColorChangeListener color_change_listener_; + mutable std::map<int, SkColor> system_colors_; + DISALLOW_COPY_AND_ASSIGN(NativeThemeWin); }; diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc index 8fc0fc5..da216a9 100644 --- a/ui/views/controls/textfield/native_textfield_views.cc +++ b/ui/views/controls/textfield/native_textfield_views.cc @@ -47,9 +47,6 @@ namespace { -// Text color for read only. -const SkColor kReadonlyTextColor = SK_ColorDKGRAY; - // Default "system" color for text cursor. const SkColor kDefaultCursorColor = SK_ColorBLACK; @@ -82,12 +79,8 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) #else GetRenderText()->SetFont(textfield_->font()); #endif - // Set the default text style. - gfx::StyleRange default_style; - default_style.foreground = textfield_->text_color(); - GetRenderText()->set_default_style(default_style); - GetRenderText()->ApplyDefaultStyle(); + UpdateColorsFromTheme(GetNativeTheme()); set_context_menu_controller(this); set_drag_controller(this); } @@ -292,15 +285,7 @@ void NativeTextfieldViews::OnBlur() { } void NativeTextfieldViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { - gfx::RenderText* render_text = GetRenderText(); - render_text->set_selection_color( - theme->GetSystemColor(ui::NativeTheme::kColorId_TextfieldSelectionColor)); - render_text->set_selection_background_focused_color( - theme->GetSystemColor( - ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); - render_text->set_selection_background_unfocused_color( - theme->GetSystemColor( - ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); + UpdateColorsFromTheme(theme); } void NativeTextfieldViews::SelectRect(const gfx::Point& start, @@ -442,29 +427,21 @@ void NativeTextfieldViews::UpdateBorder() { } void NativeTextfieldViews::UpdateTextColor() { + gfx::StyleRange default_style(GetRenderText()->default_style()); + default_style.foreground = textfield_->GetTextColor(); + GetRenderText()->set_default_style(default_style); + GetRenderText()->ApplyDefaultStyle(); SchedulePaint(); } void NativeTextfieldViews::UpdateBackgroundColor() { - // TODO(oshima): Background has to match the border's shape. - set_background( - Background::CreateSolidBackground(textfield_->background_color())); - SchedulePaint(); -} - -void NativeTextfieldViews::UpdateCursorColor() { + const SkColor color = textfield_->GetBackgroundColor(); + set_background(Background::CreateSolidBackground(color)); + GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); SchedulePaint(); } void NativeTextfieldViews::UpdateReadOnly() { - // Update the default text style. - gfx::StyleRange default_style(GetRenderText()->default_style()); - default_style.foreground = textfield_->read_only() ? kReadonlyTextColor : - textfield_->text_color(); - GetRenderText()->set_default_style(default_style); - GetRenderText()->ApplyDefaultStyle(); - - SchedulePaint(); OnTextInputTypeChanged(); } @@ -559,6 +536,14 @@ size_t NativeTextfieldViews::GetCursorPosition() const { return model_->GetCursorPosition(); } +bool NativeTextfieldViews::GetCursorEnabled() const { + return GetRenderText()->cursor_enabled(); +} + +void NativeTextfieldViews::SetCursorEnabled(bool enabled) { + GetRenderText()->SetCursorEnabled(enabled); +} + bool NativeTextfieldViews::HandleKeyPressed(const ui::KeyEvent& e) { TextfieldController* controller = textfield_->GetController(); bool handled = false; @@ -932,6 +917,19 @@ string16 NativeTextfieldViews::GetTextForDisplay(const string16& text) { base::i18n::ToLower(text) : text; } +void NativeTextfieldViews::UpdateColorsFromTheme(const ui::NativeTheme* theme) { + UpdateTextColor(); + UpdateBackgroundColor(); + gfx::RenderText* render_text = GetRenderText(); + render_text->set_cursor_color(kDefaultCursorColor); + render_text->set_selection_color(theme->GetSystemColor( + ui::NativeTheme::kColorId_TextfieldSelectionColor)); + render_text->set_selection_background_focused_color(theme->GetSystemColor( + ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); + render_text->set_selection_background_unfocused_color(theme->GetSystemColor( + ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); +} + void NativeTextfieldViews::UpdateCursor() { is_cursor_visible_ = !is_cursor_visible_; RepaintCursor(); @@ -951,15 +949,8 @@ void NativeTextfieldViews::RepaintCursor() { void NativeTextfieldViews::PaintTextAndCursor(gfx::Canvas* canvas) { TRACE_EVENT0("views", "NativeTextfieldViews::PaintTextAndCursor"); canvas->Save(); - GetRenderText()->set_background_is_transparent( - !textfield_->use_default_background_color() && - SkColorGetA(textfield_->background_color()) != 0xFF); GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || (is_cursor_visible_ && !model_->HasSelection())); - GetRenderText()->set_cursor_color( - textfield_->use_default_cursor_color() ? - kDefaultCursorColor : - textfield_->cursor_color()); // Draw the text, cursor, and selection. GetRenderText()->Draw(canvas); diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h index 822bab8..104f881 100644 --- a/ui/views/controls/textfield/native_textfield_views.h +++ b/ui/views/controls/textfield/native_textfield_views.h @@ -106,7 +106,6 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView, virtual void UpdateBorder() OVERRIDE; virtual void UpdateTextColor() OVERRIDE; virtual void UpdateBackgroundColor() OVERRIDE; - virtual void UpdateCursorColor() OVERRIDE; virtual void UpdateReadOnly() OVERRIDE; virtual void UpdateFont() OVERRIDE; virtual void UpdateIsObscured() OVERRIDE; @@ -123,6 +122,8 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView, virtual void GetSelectionModel(gfx::SelectionModel* sel) const OVERRIDE; virtual void SelectSelectionModel(const gfx::SelectionModel& sel) OVERRIDE; virtual size_t GetCursorPosition() const OVERRIDE; + virtual bool GetCursorEnabled() const OVERRIDE; + virtual void SetCursorEnabled(bool enabled) OVERRIDE; virtual bool HandleKeyPressed(const ui::KeyEvent& e) OVERRIDE; virtual bool HandleKeyReleased(const ui::KeyEvent& e) OVERRIDE; virtual void HandleFocus() OVERRIDE; @@ -191,6 +192,9 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView, // |textfield_| has STYLE_LOWERCASE style. string16 GetTextForDisplay(const string16& text); + // Updates any colors that have not been explicitly set from the theme. + void UpdateColorsFromTheme(const ui::NativeTheme* theme); + // A callback function to periodically update the cursor state. void UpdateCursor(); diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc index 916b19d..7566baf 100644 --- a/ui/views/controls/textfield/native_textfield_win.cc +++ b/ui/views/controls/textfield/native_textfield_win.cc @@ -249,25 +249,13 @@ void NativeTextfieldWin::UpdateBorder() { 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()); + cf.crTextColor = skia::SkColorToCOLORREF(textfield_->GetTextColor()); CRichEditCtrl::SetDefaultCharFormat(cf); } void NativeTextfieldWin::UpdateBackgroundColor() { - if (!textfield_->use_default_background_color()) { - bg_color_ = skia::SkColorToCOLORREF(textfield_->background_color()); - } else { - bg_color_ = GetSysColor(textfield_->read_only() ? COLOR_3DFACE - : COLOR_WINDOW); - } - CRichEditCtrl::SetBackgroundColor(bg_color_); -} - -void NativeTextfieldWin::UpdateCursorColor() { - if (!textfield_->use_default_cursor_color()) - NOTIMPLEMENTED(); + CRichEditCtrl::SetBackgroundColor( + skia::SkColorToCOLORREF(textfield_->GetBackgroundColor())); } void NativeTextfieldWin::UpdateReadOnly() { @@ -387,6 +375,17 @@ size_t NativeTextfieldWin::GetCursorPosition() const { return 0U; } +bool NativeTextfieldWin::GetCursorEnabled() const { + // TODO(msw): Implement. + NOTIMPLEMENTED(); + return true; +} + +void NativeTextfieldWin::SetCursorEnabled(bool enabled) { + // TODO(msw): Implement. + NOTIMPLEMENTED(); +} + bool NativeTextfieldWin::HandleKeyPressed(const ui::KeyEvent& event) { return false; } diff --git a/ui/views/controls/textfield/native_textfield_win.h b/ui/views/controls/textfield/native_textfield_win.h index fda34dd..d9b205f 100644 --- a/ui/views/controls/textfield/native_textfield_win.h +++ b/ui/views/controls/textfield/native_textfield_win.h @@ -77,7 +77,6 @@ class NativeTextfieldWin virtual void UpdateBorder() OVERRIDE; virtual void UpdateTextColor() OVERRIDE; virtual void UpdateBackgroundColor() OVERRIDE; - virtual void UpdateCursorColor() OVERRIDE; virtual void UpdateReadOnly() OVERRIDE; virtual void UpdateFont() OVERRIDE; virtual void UpdateIsObscured() OVERRIDE; @@ -94,6 +93,8 @@ class NativeTextfieldWin virtual void GetSelectionModel(gfx::SelectionModel* sel) const OVERRIDE; virtual void SelectSelectionModel(const gfx::SelectionModel& sel) OVERRIDE; virtual size_t GetCursorPosition() const OVERRIDE; + virtual bool GetCursorEnabled() const OVERRIDE; + virtual void SetCursorEnabled(bool enabled) OVERRIDE; virtual bool HandleKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool HandleKeyReleased(const ui::KeyEvent& event) OVERRIDE; virtual void HandleFocus() OVERRIDE; diff --git a/ui/views/controls/textfield/native_textfield_wrapper.h b/ui/views/controls/textfield/native_textfield_wrapper.h index f5a6c5d..aaaaa15 100644 --- a/ui/views/controls/textfield/native_textfield_wrapper.h +++ b/ui/views/controls/textfield/native_textfield_wrapper.h @@ -72,9 +72,6 @@ class VIEWS_EXPORT NativeTextfieldWrapper { // Updates the background color used when painting the native text field. virtual void UpdateBackgroundColor() = 0; - // Updates the cursor color used when painting the native text field. - virtual void UpdateCursorColor() = 0; - // Updates the read-only state of the native text field. virtual void UpdateReadOnly() = 0; @@ -124,6 +121,10 @@ class VIEWS_EXPORT NativeTextfieldWrapper { // Returns the currnet cursor position. virtual size_t GetCursorPosition() const = 0; + // Get or set whether or not the cursor is enabled. + virtual bool GetCursorEnabled() const = 0; + virtual void SetCursorEnabled(bool enabled) = 0; + // Following methods are to forward key/focus related events to the // views wrapper so that TextfieldViews can handle key inputs without // having focus. diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc index 88f9766..d353101 100644 --- a/ui/views/controls/textfield/textfield.cc +++ b/ui/views/controls/textfield/textfield.cc @@ -17,6 +17,7 @@ #include "ui/base/ui_base_switches.h" #include "ui/gfx/insets.h" #include "ui/gfx/selection_model.h" +#include "ui/native_theme/native_theme.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/controls/textfield/native_textfield_views.h" #include "ui/views/controls/textfield/native_textfield_wrapper.h" @@ -65,8 +66,6 @@ Textfield::Textfield() use_default_text_color_(true), background_color_(SK_ColorWHITE), use_default_background_color_(true), - cursor_color_(SK_ColorBLACK), - use_default_cursor_color_(true), initialized_(false), horizontal_margins_were_set_(false), vertical_margins_were_set_(false), @@ -86,8 +85,6 @@ Textfield::Textfield(StyleFlags style) use_default_text_color_(true), background_color_(SK_ColorWHITE), use_default_background_color_(true), - cursor_color_(SK_ColorBLACK), - use_default_cursor_color_(true), initialized_(false), horizontal_margins_were_set_(false), vertical_margins_were_set_(false), @@ -116,7 +113,6 @@ void Textfield::SetReadOnly(bool read_only) { native_wrapper_->UpdateReadOnly(); native_wrapper_->UpdateTextColor(); native_wrapper_->UpdateBackgroundColor(); - native_wrapper_->UpdateCursorColor(); } } @@ -197,6 +193,15 @@ bool Textfield::HasSelection() const { return !range.is_empty(); } +SkColor Textfield::GetTextColor() const { + if (!use_default_text_color_) + return text_color_; + + return GetNativeTheme()->GetSystemColor(read_only() ? + ui::NativeTheme::kColorId_TextfieldReadOnlyColor : + ui::NativeTheme::kColorId_TextfieldDefaultColor); +} + void Textfield::SetTextColor(SkColor color) { text_color_ = color; use_default_text_color_ = false; @@ -210,6 +215,15 @@ void Textfield::UseDefaultTextColor() { native_wrapper_->UpdateTextColor(); } +SkColor Textfield::GetBackgroundColor() const { + if (!use_default_background_color_) + return background_color_; + + return GetNativeTheme()->GetSystemColor(read_only() ? + ui::NativeTheme::kColorId_TextfieldReadOnlyBackground : + ui::NativeTheme::kColorId_TextfieldDefaultBackground); +} + void Textfield::SetBackgroundColor(SkColor color) { background_color_ = color; use_default_background_color_ = false; @@ -223,17 +237,13 @@ void Textfield::UseDefaultBackgroundColor() { native_wrapper_->UpdateBackgroundColor(); } -void Textfield::SetCursorColor(SkColor color) { - cursor_color_ = color; - use_default_cursor_color_ = false; - if (native_wrapper_) - native_wrapper_->UpdateCursorColor(); +bool Textfield::GetCursorEnabled() const { + return native_wrapper_ && native_wrapper_->GetCursorEnabled(); } -void Textfield::UseDefaultCursorColor() { - use_default_cursor_color_ = true; +void Textfield::SetCursorEnabled(bool enabled) { if (native_wrapper_) - native_wrapper_->UpdateCursorColor(); + native_wrapper_->SetCursorEnabled(enabled); } void Textfield::SetFont(const gfx::Font& font) { @@ -289,7 +299,6 @@ void Textfield::UpdateAllProperties() { native_wrapper_->UpdateText(); native_wrapper_->UpdateTextColor(); native_wrapper_->UpdateBackgroundColor(); - native_wrapper_->UpdateCursorColor(); native_wrapper_->UpdateReadOnly(); native_wrapper_->UpdateFont(); native_wrapper_->UpdateEnabled(); diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h index 880c13d..1831073 100644 --- a/ui/views/controls/textfield/textfield.h +++ b/ui/views/controls/textfield/textfield.h @@ -108,36 +108,20 @@ class VIEWS_EXPORT Textfield : public View { 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_; } + // Call |UseDefaultTextColor| to restore the default system color. + SkColor GetTextColor() const; 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_; } + // Call |UseDefaultBackgroundColor| to restore the default system color. + SkColor GetBackgroundColor() const; void SetBackgroundColor(SkColor color); - - // Gets/Sets whether the default background color should be used when painting - // the Textfield. - bool use_default_background_color() const { - return use_default_background_color_; - } void UseDefaultBackgroundColor(); - // Gets/Sets the color to be used for the cursor. - SkColor cursor_color() const { return cursor_color_; } - void SetCursorColor(SkColor color); - - // Gets/Sets whether we use the system's default color for the cursor. - bool use_default_cursor_color() const { return use_default_cursor_color_; } - void UseDefaultCursorColor(); + // Gets/Sets whether or not the cursor is enabled. + bool GetCursorEnabled() const; + void SetCursorEnabled(bool enabled); // Gets/Sets the font used when rendering the text within the Textfield. const gfx::Font& font() const { return font_; } @@ -303,12 +287,6 @@ class VIEWS_EXPORT Textfield : public View { // Should we use the system background color instead of |background_color_|? bool use_default_background_color_; - // Cursor color. Only used if |use_default_cursor_color_| is false. - SkColor cursor_color_; - - // Should we use the system cursor color instead of |cursor_color_|? - bool use_default_cursor_color_; - // TODO(beng): remove this once NativeTextfieldWin subclasses // NativeControlWin. bool initialized_; diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc index c779927..8ed8ba0 100644 --- a/ui/views/controls/textfield/textfield_views_model.cc +++ b/ui/views/controls/textfield/textfield_views_model.cc @@ -18,7 +18,6 @@ #include "ui/gfx/font.h" #include "ui/gfx/render_text.h" #include "ui/gfx/text_constants.h" -#include "ui/native_theme/native_theme.h" #include "ui/views/controls/textfield/textfield.h" namespace views { @@ -284,16 +283,6 @@ TextfieldViewsModel::TextfieldViewsModel(Delegate* delegate) : delegate_(delegate), render_text_(gfx::RenderText::CreateInstance()), current_edit_(edit_history_.end()) { - const ui::NativeTheme* theme = ui::NativeTheme::instance(); - render_text_->set_selection_color( - theme->GetSystemColor( - ui::NativeTheme::kColorId_TextfieldSelectionColor)); - render_text_->set_selection_background_focused_color( - theme->GetSystemColor( - ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)); - render_text_->set_selection_background_unfocused_color( - theme->GetSystemColor( - ui::NativeTheme::kColorId_TextfieldSelectionBackgroundUnfocused)); } TextfieldViewsModel::~TextfieldViewsModel() { |