diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 22:54:17 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-06 22:54:17 +0000 |
commit | 7428d245ad019cc6d92098968e059416daecad8d (patch) | |
tree | 9344cd7da7ff666dfce84ed238482694c22060f1 /views/controls | |
parent | 90591f0a86c90b779c0bc1f62c13f5611f44c9ef (diff) | |
download | chromium_src-7428d245ad019cc6d92098968e059416daecad8d.zip chromium_src-7428d245ad019cc6d92098968e059416daecad8d.tar.gz chromium_src-7428d245ad019cc6d92098968e059416daecad8d.tar.bz2 |
Gets preferred size of views textfields on gtk to work. Also made
turning off border work.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/256080
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28172 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls')
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 44 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.h | 1 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.cc | 12 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.h | 1 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_wrapper.h | 7 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 17 | ||||
-rw-r--r-- | views/controls/textfield/textfield.h | 3 |
7 files changed, 66 insertions, 19 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 2a5aa15..0c72ca2 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -82,6 +82,9 @@ void NativeTextfieldGtk::ClearSelection() { void NativeTextfieldGtk::UpdateBorder() { if (!native_view()) return; + + if (!textfield_->draw_border()) + gtk_entry_set_has_frame(GTK_ENTRY(native_view()), false); } void NativeTextfieldGtk::UpdateTextColor() { @@ -126,6 +129,47 @@ void NativeTextfieldGtk::UpdateEnabled() { SetEnabled(textfield_->IsEnabled()); } +gfx::Insets NativeTextfieldGtk::CalculateInsets() { + if (!native_view()) + return gfx::Insets(); + + GtkWidget* widget = native_view(); + GtkEntry* entry = GTK_ENTRY(widget); + const GtkBorder* inner_border = gtk_entry_get_inner_border(entry); + int left = 0, right = 0, top = 0, bottom = 0; + if (!inner_border) + gtk_widget_style_get(widget, "inner-border", &inner_border, NULL); + + if (inner_border) { + left += inner_border->left; + right += inner_border->right; + top += inner_border->top; + bottom += inner_border->bottom; + } + + if (entry->has_frame) { + left += widget->style->xthickness; + right += widget->style->xthickness; + top += widget->style->ythickness; + bottom += widget->style->ythickness; + } + + gboolean interior_focus; + gint focus_width; + gtk_widget_style_get(widget, + "focus-line-width", &focus_width, + "interior-focus", &interior_focus, + NULL); + if (!interior_focus) { + left += focus_width; + right += focus_width; + top += focus_width; + bottom += focus_width; + } + + return gfx::Insets(top, left, bottom, right); +} + void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) { if (!native_view()) return; diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h index bbd0663..10cb7f2 100644 --- a/views/controls/textfield/native_textfield_gtk.h +++ b/views/controls/textfield/native_textfield_gtk.h @@ -32,6 +32,7 @@ class NativeTextfieldGtk : public NativeControlGtk, virtual void UpdateReadOnly(); virtual void UpdateFont(); virtual void UpdateEnabled(); + virtual gfx::Insets CalculateInsets(); virtual void SetHorizontalMargins(int left, int right); virtual void SetFocus(); virtual View* GetView(); diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 0b997ee..39abb10 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -205,6 +205,15 @@ void NativeTextfieldWin::UpdateEnabled() { SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0); } +gfx::Insets NativeTextfieldWin::CalculateInsets() { + // NOTE: One would think GetThemeMargins would return the insets we should + // use, but it doesn't. The margins returned by GetThemeMargins are always + // 0. + + // This appears to be the insets used by Windows. + return gfx::Insets(3, 3, 3, 3); +} + void NativeTextfieldWin::SetHorizontalMargins(int left, int right) { // SendMessage expects the two values to be packed into one using MAKELONG // so we truncate to 16 bits if necessary. @@ -587,7 +596,8 @@ void NativeTextfieldWin::OnMouseMove(UINT keys, const CPoint& point) { int NativeTextfieldWin::OnNCCalcSize(BOOL w_param, LPARAM l_param) { content_insets_.Set(0, 0, 0, 0); - textfield_->CalculateInsets(&content_insets_); + if (textfield_->draw_border()) + content_insets_ = CalculateInsets(); if (w_param) { NCCALCSIZE_PARAMS* nc_params = reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param); diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h index 270411d..6ba8165 100644 --- a/views/controls/textfield/native_textfield_win.h +++ b/views/controls/textfield/native_textfield_win.h @@ -53,6 +53,7 @@ class NativeTextfieldWin virtual void UpdateReadOnly(); virtual void UpdateFont(); virtual void UpdateEnabled(); + virtual gfx::Insets CalculateInsets(); virtual void SetHorizontalMargins(int left, int right); virtual void SetFocus(); virtual View* GetView(); diff --git a/views/controls/textfield/native_textfield_wrapper.h b/views/controls/textfield/native_textfield_wrapper.h index 14dea7f..0a30ca3 100644 --- a/views/controls/textfield/native_textfield_wrapper.h +++ b/views/controls/textfield/native_textfield_wrapper.h @@ -8,6 +8,10 @@ #include "base/string16.h" #include "base/gfx/native_widget_types.h" +namespace gfx { +class Insets; +} // namespace gfx + namespace views { class Textfield; @@ -60,6 +64,9 @@ class NativeTextfieldWrapper { // Updates the enabled state of the native text field. virtual void UpdateEnabled() = 0; + // Returns the insets for the text field. + virtual gfx::Insets CalculateInsets() = 0; + // Sets the horizontal margins for the native text field. virtual void SetHorizontalMargins(int left, int right) = 0; diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index bf12e42..f06eb3d 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -173,20 +173,6 @@ void Textfield::RemoveBorder() { } -void Textfield::CalculateInsets(gfx::Insets* insets) { - DCHECK(insets); - - if (!draw_border_) - return; - - // NOTE: One would think GetThemeMargins would return the insets we should - // use, but it doesn't. The margins returned by GetThemeMargins are always - // 0. - - // This appears to be the insets used by Windows. - insets->Set(3, 3, 3, 3); -} - void Textfield::SyncText() { if (native_wrapper_) text_ = native_wrapper_->GetText(); @@ -204,7 +190,8 @@ void Textfield::Layout() { gfx::Size Textfield::GetPreferredSize() { gfx::Insets insets; - CalculateInsets(&insets); + if (draw_border_ && native_wrapper_) + insets = native_wrapper_->CalculateInsets(); return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + insets.width(), num_lines_ * font_.height() + insets.height()); diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h index b1f5259..facfaca 100644 --- a/views/controls/textfield/textfield.h +++ b/views/controls/textfield/textfield.h @@ -181,9 +181,6 @@ class Textfield : public View { bool draw_border() const { return draw_border_; } void RemoveBorder(); - // Calculates the insets for the text field. - void CalculateInsets(gfx::Insets* insets); - // Invoked by the edit control when the value changes. This method set // the text_ member variable to the value contained in edit control. // This is important because the edit control can be replaced if it has |