Index: chrome/views/text_field.cc |
=================================================================== |
--- chrome/views/text_field.cc (revision 5301) |
+++ chrome/views/text_field.cc (working copy) |
@@ -11,6 +11,7 @@ |
#include <tom.h> // For ITextDocument, a COM interface to CRichEditCtrl |
#include <vsstyle.h> |
+#include "base/gfx/skia_utils.h" |
Finnur
2008/11/12 22:57:39
s is after n in the alphabet. :)
|
#include "base/gfx/native_theme.h" |
#include "base/scoped_clipboard_writer.h" |
#include "base/string_util.h" |
@@ -61,6 +62,8 @@ |
void SetEnabled(bool enabled); |
+ void SetBackgroundColor(COLORREF bg_color); |
+ |
// CWindowImpl |
BEGIN_MSG_MAP(Edit) |
MSG_WM_CHAR(OnChar) |
@@ -196,6 +199,8 @@ |
int ime_composition_start_; |
int ime_composition_length_; |
+ COLORREF bg_color_; |
+ |
DISALLOW_EVIL_CONSTRUCTORS(Edit); |
Finnur
2008/11/12 22:57:39
DISALLOW_COPY_AND_ASSIGN. Sorry, didn't mean to sh
|
}; |
@@ -242,7 +247,8 @@ |
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 @@ |
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 @@ |
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 @@ |
(!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 @@ |
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 @@ |
} |
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 @@ |
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::SetEnabled(bool enabled) { |
View::SetEnabled(enabled); |
- SetReadOnly(!enabled); |
edit_->SetEnabled(enabled); |
} |
@@ -1066,5 +1073,16 @@ |
return !win_util::IsNumPadDigit(e.GetCharacter(), e.IsExtendedKey()); |
} |
+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 |
- |