summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authoraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-10 18:55:49 +0000
committeraltimofeev@chromium.org <altimofeev@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-10 18:55:49 +0000
commit8746f6d6d517e9bab21a7851cae4251a62c421f1 (patch)
treec96e6c2615f37bd13957da24043848a0bfb3ac14 /views
parent5c13b4a8978c92e8667d2e47914f9eb5e22af43c (diff)
downloadchromium_src-8746f6d6d517e9bab21a7851cae4251a62c421f1.zip
chromium_src-8746f6d6d517e9bab21a7851cae4251a62c421f1.tar.gz
chromium_src-8746f6d6d517e9bab21a7851cae4251a62c421f1.tar.bz2
Implements vertical margins setter for textfield.
After bug fix #r64550, changing horizontal margin doesn't change vertical margins. Unfortunately FindBar has used this bug, so explicit vertical setter was implemented to deal with this issue. BUG=chromium-os:8536 TEST=In chrome use 'ctrl+f' to invoke find bar. Notice that the border is inplace. Review URL: http://codereview.chromium.org/4246002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65686 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc28
-rw-r--r--views/controls/textfield/native_textfield_gtk.h3
-rw-r--r--views/controls/textfield/native_textfield_win.cc19
-rw-r--r--views/controls/textfield/native_textfield_win.h3
-rw-r--r--views/controls/textfield/native_textfield_wrapper.h7
-rw-r--r--views/controls/textfield/textfield.cc38
-rw-r--r--views/controls/textfield/textfield.h19
7 files changed, 106 insertions, 11 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 1c8126d..b52a50b 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -188,8 +188,8 @@ void NativeTextfieldGtk::UpdateBorder() {
gtk_container_set_border_width(GTK_CONTAINER(native_view()), 0);
// Use margin to match entry with no border
- SetHorizontalMargins(kTextViewBorderWidth / 2 + 1,
- kTextViewBorderWidth / 2 + 1);
+ textfield_->SetHorizontalMargins(kTextViewBorderWidth / 2 + 1,
+ kTextViewBorderWidth / 2 + 1);
}
} else {
if (!textfield_->draw_border())
@@ -291,9 +291,14 @@ gfx::Insets NativeTextfieldGtk::CalculateInsets() {
return insets;
}
-void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) {
+void NativeTextfieldGtk::UpdateHorizontalMargins() {
if (!native_view())
return;
+
+ int left, right;
+ if (!textfield_->GetHorizontalMargins(&left, &right))
+ return;
+
if (textfield_->IsMultiLine()) {
GtkTextView* text_view = GTK_TEXT_VIEW(native_view());
gtk_text_view_set_left_margin(text_view, left);
@@ -305,6 +310,23 @@ void NativeTextfieldGtk::SetHorizontalMargins(int left, int right) {
}
}
+void NativeTextfieldGtk::UpdateVerticalMargins() {
+ if (!native_view())
+ return;
+
+ int top, bottom;
+ if (!textfield_->GetVerticalMargins(&top, &bottom))
+ return;
+
+ if (!textfield_->IsMultiLine()) {
+ gfx::Insets insets = GetEntryInnerBorder(GTK_ENTRY(native_view()));
+ GtkBorder border = {insets.left(), insets.right(), top, bottom};
+ gtk_entry_set_inner_border(GTK_ENTRY(native_view()), &border);
+ } else {
+ NOTIMPLEMENTED();
+ }
+}
+
void NativeTextfieldGtk::SetFocus() {
Focus();
}
diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h
index 60d02de..707af3d 100644
--- a/views/controls/textfield/native_textfield_gtk.h
+++ b/views/controls/textfield/native_textfield_gtk.h
@@ -43,7 +43,8 @@ class NativeTextfieldGtk : public NativeControlGtk,
virtual void UpdateEnabled();
virtual bool IsPassword();
virtual gfx::Insets CalculateInsets();
- virtual void SetHorizontalMargins(int left, int right);
+ virtual void UpdateHorizontalMargins();
+ virtual void UpdateVerticalMargins();
virtual void SetFocus();
virtual View* GetView();
virtual gfx::NativeView GetTestingHandle() const;
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index 254c677..2109cb9 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -251,7 +251,11 @@ gfx::Insets NativeTextfieldWin::CalculateInsets() {
return gfx::Insets(3, 3, 3, 3);
}
-void NativeTextfieldWin::SetHorizontalMargins(int left, int right) {
+void NativeTextfieldWin::UpdateHorizontalMargins() {
+ int left, right;
+ if (!textfield_->GetHorizontalMargins(&left, &right))
+ return;
+
// SendMessage expects the two values to be packed into one using MAKELONG
// so we truncate to 16 bits if necessary.
SendMessage(m_hWnd, EM_SETMARGINS,
@@ -259,6 +263,19 @@ void NativeTextfieldWin::SetHorizontalMargins(int left, int right) {
MAKELONG(left & 0xFFFF, right & 0xFFFF));
}
+void NativeTextfieldWin::UpdateVerticalMargins() {
+ int top, bottom;
+ if (!textfield_->GetVerticalMargins(&top, &bottom))
+ return;
+
+ if (top == 0 && bottom == 0) {
+ // Do nothing, default margins are 0 already.
+ return;
+ }
+ // Non-zero margins case.
+ NOTIMPLEMENTED();
+}
+
void NativeTextfieldWin::SetFocus() {
// Focus the associated HWND.
//container_view_->Focus();
diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h
index 52504c1..b01b87e 100644
--- a/views/controls/textfield/native_textfield_win.h
+++ b/views/controls/textfield/native_textfield_win.h
@@ -60,7 +60,8 @@ class NativeTextfieldWin
virtual void UpdateIsPassword();
virtual void UpdateEnabled();
virtual gfx::Insets CalculateInsets();
- virtual void SetHorizontalMargins(int left, int right);
+ virtual void UpdateHorizontalMargins();
+ virtual void UpdateVerticalMargins();
virtual void SetFocus();
virtual View* GetView();
virtual gfx::NativeView GetTestingHandle() const;
diff --git a/views/controls/textfield/native_textfield_wrapper.h b/views/controls/textfield/native_textfield_wrapper.h
index afe1917..eb5245f 100644
--- a/views/controls/textfield/native_textfield_wrapper.h
+++ b/views/controls/textfield/native_textfield_wrapper.h
@@ -71,8 +71,11 @@ class NativeTextfieldWrapper {
// 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;
+ // Updates the horizontal margins for the native text field.
+ virtual void UpdateHorizontalMargins() = 0;
+
+ // Updates the vertical margins for the native text field.
+ virtual void UpdateVerticalMargins() = 0;
// Sets the focus to the text field.
virtual void SetFocus() = 0;
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index 32d4e39..81c74d2 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -48,7 +48,9 @@ Textfield::Textfield()
background_color_(SK_ColorWHITE),
use_default_background_color_(true),
num_lines_(1),
- initialized_(false) {
+ initialized_(false),
+ horizontal_margins_were_set_(false),
+ vertical_margins_were_set_(false) {
SetFocusable(true);
}
@@ -64,7 +66,9 @@ Textfield::Textfield(StyleFlags style)
background_color_(SK_ColorWHITE),
use_default_background_color_(true),
num_lines_(1),
- initialized_(false) {
+ initialized_(false),
+ horizontal_margins_were_set_(false),
+ vertical_margins_were_set_(false) {
SetFocusable(true);
}
@@ -167,8 +171,18 @@ void Textfield::SetFont(const gfx::Font& font) {
}
void Textfield::SetHorizontalMargins(int left, int right) {
+ margins_.Set(margins_.top(), left, margins_.bottom(), right);
+ horizontal_margins_were_set_ = true;
if (native_wrapper_)
- native_wrapper_->SetHorizontalMargins(left, right);
+ native_wrapper_->UpdateHorizontalMargins();
+ PreferredSizeChanged();
+}
+
+void Textfield::SetVerticalMargins(int top, int bottom) {
+ margins_.Set(top, margins_.left(), bottom, margins_.right());
+ vertical_margins_were_set_ = true;
+ if (native_wrapper_)
+ native_wrapper_->UpdateVerticalMargins();
PreferredSizeChanged();
}
@@ -187,6 +201,22 @@ void Textfield::RemoveBorder() {
native_wrapper_->UpdateBorder();
}
+bool Textfield::GetHorizontalMargins(int* left, int* right) {
+ if (!horizontal_margins_were_set_)
+ return false;
+ *left = margins_.left();
+ *right = margins_.right();
+ return true;
+}
+
+bool Textfield::GetVerticalMargins(int* top, int* bottom) {
+ if (!vertical_margins_were_set_)
+ return false;
+ *top = margins_.top();
+ *bottom = margins_.bottom();
+ return true;
+}
+
void Textfield::UpdateAllProperties() {
if (native_wrapper_) {
native_wrapper_->UpdateText();
@@ -197,6 +227,8 @@ void Textfield::UpdateAllProperties() {
native_wrapper_->UpdateEnabled();
native_wrapper_->UpdateBorder();
native_wrapper_->UpdateIsPassword();
+ native_wrapper_->UpdateHorizontalMargins();
+ native_wrapper_->UpdateVerticalMargins();
}
}
diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h
index 35c3932..d171eb5 100644
--- a/views/controls/textfield/textfield.h
+++ b/views/controls/textfield/textfield.h
@@ -177,6 +177,10 @@ class Textfield : public View {
// 32 bit number, so the left and right margins are effectively 16 bits.
void SetHorizontalMargins(int left, int right);
+ // Sets the top and bottom margins (in pixels) within the textfield.
+ // NOTE: in most cases height could be changed instead.
+ void SetVerticalMargins(int top, int bottom);
+
// Should only be called on a multi-line text field. Sets how many lines of
// text can be displayed at once by this text field.
void SetHeightInLines(int num_lines);
@@ -201,6 +205,14 @@ class Textfield : public View {
return text_to_display_when_empty_;
}
+ // Getter for the horizontal margins that were set. Returns false if
+ // horizontal margins weren't set.
+ bool GetHorizontalMargins(int* left, int* right);
+
+ // Getter for the vertical margins that were set. Returns false if vertical
+ // margins weren't set.
+ bool GetVerticalMargins(int* top, int* bottom);
+
// Updates all properties on the textfield. This is invoked internally.
// Users of Textfield never need to invoke this directly.
void UpdateAllProperties();
@@ -290,6 +302,13 @@ class Textfield : public View {
// NativeControlWin.
bool initialized_;
+ // Holds inner textfield margins.
+ gfx::Insets margins_;
+
+ // Holds whether margins were set.
+ bool horizontal_margins_were_set_;
+ bool vertical_margins_were_set_;
+
// Text to display when empty.
string16 text_to_display_when_empty_;