diff options
author | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-03 20:50:48 +0000 |
---|---|---|
committer | saintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-03 20:50:48 +0000 |
commit | 692c3d039e3661eac95a305970abbba6e7a6322e (patch) | |
tree | f1e84caa27463cc06d2b1010fe5433b100d4822b /views | |
parent | 82ab1fa1c57b693cca4823a146bae44da08a15f1 (diff) | |
download | chromium_src-692c3d039e3661eac95a305970abbba6e7a6322e.zip chromium_src-692c3d039e3661eac95a305970abbba6e7a6322e.tar.gz chromium_src-692c3d039e3661eac95a305970abbba6e7a6322e.tar.bz2 |
Remove unused multiline attribute in textfield. Need to be pushed only *after* http://codereview.chromium.org/6975062/ has landed
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7027014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/textfield/native_textfield_gtk.cc | 168 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_views.cc | 2 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_views.h | 2 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_win.cc | 16 | ||||
-rw-r--r-- | views/controls/textfield/textfield.cc | 15 | ||||
-rw-r--r-- | views/controls/textfield/textfield.h | 16 |
6 files changed, 38 insertions, 181 deletions
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc index 9116696..8160891 100644 --- a/views/controls/textfield/native_textfield_gtk.cc +++ b/views/controls/textfield/native_textfield_gtk.cc @@ -34,8 +34,6 @@ const int kTextViewBorderWidth = 4; NativeTextfieldGtk::NativeTextfieldGtk(Textfield* textfield) : textfield_(textfield), paste_clipboard_requested_(false) { - if (textfield_->IsMultiLine() && textfield_->IsPassword()) - NOTIMPLEMENTED(); // We don't support multiline password yet. // Make |textfield| the focused view, so that when we get focused the focus // manager sees |textfield| as the focused view (since we are just a wrapper // view). @@ -74,50 +72,20 @@ gfx::Insets NativeTextfieldGtk::GetTextViewInnerBorder(GtkTextView* text_view) { // NativeTextfieldGtk, NativeTextfieldWrapper implementation: string16 NativeTextfieldGtk::GetText() const { - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - GtkTextIter start; - GtkTextIter end; - gtk_text_buffer_get_bounds(text_buffer, &start, &end); - - return UTF8ToUTF16(gtk_text_iter_get_visible_text(&start, &end)); - } else { - return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(native_view()))); - } + return UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(native_view()))); } void NativeTextfieldGtk::UpdateText() { if (!native_view()) return; - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - std::string utf8 = UTF16ToUTF8(textfield_->text()); - gtk_text_buffer_set_text(text_buffer, utf8.c_str(), utf8.length()); - } else { - gtk_entry_set_text(GTK_ENTRY(native_view()), + gtk_entry_set_text(GTK_ENTRY(native_view()), UTF16ToUTF8(textfield_->text()).c_str()); - } } void NativeTextfieldGtk::AppendText(const string16& text) { if (!native_view()) return; - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - GtkTextIter end; - gtk_text_buffer_get_end_iter(text_buffer, &end); - - std::string utf8 = UTF16ToUTF8(text); - gtk_text_buffer_insert(text_buffer, &end, utf8.c_str(), utf8.length()); - } else { - gtk_entry_append_text(GTK_ENTRY(native_view()), UTF16ToUTF8(text).c_str()); - } + gtk_entry_append_text(GTK_ENTRY(native_view()), UTF16ToUTF8(text).c_str()); } string16 NativeTextfieldGtk::GetSelectedText() const { @@ -126,28 +94,15 @@ string16 NativeTextfieldGtk::GetSelectedText() const { string16 result; - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - GtkTextIter start; - GtkTextIter end; - if (gtk_text_buffer_get_selection_bounds(text_buffer, &start, &end)) { - gchar* selected_text = gtk_text_iter_get_visible_text(&start, &end); - if (selected_text) - UTF8ToUTF16(selected_text, strlen(selected_text), &result); - } - } else { - gint start_pos; - gint end_pos; - if (!gtk_editable_get_selection_bounds(GTK_EDITABLE(native_view()), + gint start_pos; + gint end_pos; + if (!gtk_editable_get_selection_bounds(GTK_EDITABLE(native_view()), &start_pos, &end_pos)) - return result; // No selection. + return result; // No selection. - UTF8ToUTF16(gtk_editable_get_chars(GTK_EDITABLE(native_view()), - start_pos, end_pos), - end_pos - start_pos, &result); - } + UTF8ToUTF16(gtk_editable_get_chars(GTK_EDITABLE(native_view()), + start_pos, end_pos), + end_pos - start_pos, &result); return result; } @@ -155,52 +110,22 @@ string16 NativeTextfieldGtk::GetSelectedText() const { void NativeTextfieldGtk::SelectAll() { if (!native_view()) return; - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - GtkTextIter start; - GtkTextIter end; - gtk_text_buffer_get_bounds(text_buffer, &start, &end); - gtk_text_buffer_select_range(text_buffer, &start, &end); - } else { - // -1 as the end position selects to the end of the text. - gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, -1); - } + // -1 as the end position selects to the end of the text. + gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, -1); } void NativeTextfieldGtk::ClearSelection() { if (!native_view()) return; - if (textfield_->IsMultiLine()) { - GtkTextBuffer* text_buffer = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(native_view())); - - GtkTextMark* insert_mark = gtk_text_buffer_get_insert(text_buffer); - GtkTextIter insert; - gtk_text_buffer_get_iter_at_mark(text_buffer, &insert, insert_mark); - gtk_text_buffer_select_range(text_buffer, &insert, &insert); - } else { - gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, 0); - } + gtk_editable_select_region(GTK_EDITABLE(native_view()), 0, 0); } void NativeTextfieldGtk::UpdateBorder() { if (!native_view()) return; - if (textfield_->IsMultiLine()) { - if (!textfield_->draw_border()) { - gtk_container_set_border_width(GTK_CONTAINER(native_view()), 0); - - // Use margin to match entry with no border - textfield_->SetHorizontalMargins(kTextViewBorderWidth / 2 + 1, - kTextViewBorderWidth / 2 + 1); - } - } else { - if (!textfield_->draw_border()) - gtk_entry_set_has_frame(GTK_ENTRY(native_view()), false); - } + if (!textfield_->draw_border()) + gtk_entry_set_has_frame(GTK_ENTRY(native_view()), false); } void NativeTextfieldGtk::UpdateTextColor() { @@ -228,14 +153,8 @@ void NativeTextfieldGtk::UpdateBackgroundColor() { void NativeTextfieldGtk::UpdateReadOnly() { if (!native_view()) return; - - if (textfield_->IsMultiLine()) { - gtk_text_view_set_editable(GTK_TEXT_VIEW(native_view()), - !textfield_->read_only()); - } else { - gtk_editable_set_editable(GTK_EDITABLE(native_view()), - !textfield_->read_only()); - } + gtk_editable_set_editable(GTK_EDITABLE(native_view()), + !textfield_->read_only()); } void NativeTextfieldGtk::UpdateFont() { @@ -249,10 +168,7 @@ void NativeTextfieldGtk::UpdateFont() { void NativeTextfieldGtk::UpdateIsPassword() { if (!native_view()) return; - if (!textfield_->IsMultiLine()) { - gtk_entry_set_visibility(GTK_ENTRY(native_view()), - !textfield_->IsPassword()); - } + gtk_entry_set_visibility(GTK_ENTRY(native_view()), !textfield_->IsPassword()); } void NativeTextfieldGtk::UpdateEnabled() { @@ -268,17 +184,13 @@ gfx::Insets NativeTextfieldGtk::CalculateInsets() { GtkWidget* widget = native_view(); gfx::Insets insets; - if (textfield_->IsMultiLine()) { - insets += GetTextViewInnerBorder(GTK_TEXT_VIEW(widget)); - } else { - GtkEntry* entry = GTK_ENTRY(widget); - insets += GetEntryInnerBorder(entry); - if (entry->has_frame) { - insets += gfx::Insets(widget->style->ythickness, + GtkEntry* entry = GTK_ENTRY(widget); + insets += GetEntryInnerBorder(entry); + if (entry->has_frame) { + insets += gfx::Insets(widget->style->ythickness, widget->style->xthickness, widget->style->ythickness, widget->style->xthickness); - } } gboolean interior_focus; @@ -301,15 +213,9 @@ void NativeTextfieldGtk::UpdateHorizontalMargins() { 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); - gtk_text_view_set_right_margin(text_view, right); - } else { - gfx::Insets insets = GetEntryInnerBorder(GTK_ENTRY(native_view())); - GtkBorder border = {left, right, insets.top(), insets.bottom()}; - gtk_entry_set_inner_border(GTK_ENTRY(native_view()), &border); - } + gfx::Insets insets = GetEntryInnerBorder(GTK_ENTRY(native_view())); + GtkBorder border = {left, right, insets.top(), insets.bottom()}; + gtk_entry_set_inner_border(GTK_ENTRY(native_view()), &border); } void NativeTextfieldGtk::UpdateVerticalMargins() { @@ -320,13 +226,9 @@ void NativeTextfieldGtk::UpdateVerticalMargins() { 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(); - } + 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); } bool NativeTextfieldGtk::SetFocus() { @@ -486,19 +388,9 @@ void NativeTextfieldGtk::OnPasteClipboard(GtkWidget* widget) { // NativeTextfieldGtk, NativeControlGtk overrides: void NativeTextfieldGtk::CreateNativeControl() { - if (textfield_->IsMultiLine()) { - NativeControlCreated(gtk_views_textview_new(this)); - if (textfield_->draw_border()) - gtk_container_set_border_width(GTK_CONTAINER(native_view()), - kTextViewBorderWidth); - - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(native_view()), - GTK_WRAP_WORD_CHAR); - } else { - NativeControlCreated(gtk_views_entry_new(this)); - gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), + NativeControlCreated(gtk_views_entry_new(this)); + gtk_entry_set_invisible_char(GTK_ENTRY(native_view()), static_cast<gunichar>(kPasswordChar)); - } textfield_->UpdateAllProperties(); } diff --git a/views/controls/textfield/native_textfield_views.cc b/views/controls/textfield/native_textfield_views.cc index 27d4cf4..2d7b615 100644 --- a/views/controls/textfield/native_textfield_views.cc +++ b/views/controls/textfield/native_textfield_views.cc @@ -75,8 +75,6 @@ NativeTextfieldViews::NativeTextfieldViews(Textfield* parent) last_click_location_(0, 0) { set_border(text_border_); - // Multiline is not supported. - DCHECK_NE(parent->style(), Textfield::STYLE_MULTILINE); // Lowercase is not supported. DCHECK_NE(parent->style(), Textfield::STYLE_LOWERCASE); diff --git a/views/controls/textfield/native_textfield_views.h b/views/controls/textfield/native_textfield_views.h index 19c10f7..54c13fb 100644 --- a/views/controls/textfield/native_textfield_views.h +++ b/views/controls/textfield/native_textfield_views.h @@ -36,8 +36,6 @@ class Menu2; // * BIDI/Complex script. // * Support surrogate pair, or maybe we should just use UTF32 internally. // * X selection (only if we want to support). -// * STYLE_MULTILINE, STYLE_LOWERCASE text. (These are not used in -// chromeos, so we may not need them) // Once completed, this will replace Textfield, NativeTextfieldWin and // NativeTextfieldGtk. class NativeTextfieldViews : public View, diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index d7d27e750..df352b7 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -99,17 +99,13 @@ NativeTextfieldWin::NativeTextfieldWin(Textfield* textfield) if (!did_load_library_) did_load_library_ = !!LoadLibrary(L"riched20.dll"); - DWORD style = kDefaultEditStyle; + DWORD style = kDefaultEditStyle | ES_AUTOHSCROLL; if (textfield_->style() & Textfield::STYLE_PASSWORD) style |= ES_PASSWORD; if (textfield_->read_only()) style |= ES_READONLY; - if (textfield_->style() & Textfield::STYLE_MULTILINE) - style |= ES_MULTILINE | ES_WANTRETURN | ES_AUTOVSCROLL; - else - style |= ES_AUTOHSCROLL; // Make sure we apply RTL related extended window styles if necessary. DWORD ex_style = l10n_util::GetExtendedStyles(); @@ -634,13 +630,11 @@ void NativeTextfieldWin::OnKeyDown(TCHAR key, UINT repeat_count, UINT flags) { // in this function even with a WM_SYSKEYDOWN handler. switch (key) { + + // Ignore Return case VK_RETURN: - // If we are multi-line, we want to let returns through so they start a - // new line. - if (textfield_->IsMultiLine()) - break; - else - return; + return; + // Hijacking Editing Commands // // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc index c2bc128..6f2edd5 100644 --- a/views/controls/textfield/textfield.cc +++ b/views/controls/textfield/textfield.cc @@ -51,7 +51,6 @@ Textfield::Textfield() use_default_text_color_(true), background_color_(SK_ColorWHITE), use_default_background_color_(true), - num_lines_(1), initialized_(false), horizontal_margins_were_set_(false), vertical_margins_were_set_(false) { @@ -69,7 +68,6 @@ Textfield::Textfield(StyleFlags style) use_default_text_color_(true), background_color_(SK_ColorWHITE), use_default_background_color_(true), - num_lines_(1), initialized_(false), horizontal_margins_were_set_(false), vertical_margins_were_set_(false) { @@ -109,10 +107,6 @@ void Textfield::SetPassword(bool password) { native_wrapper_->UpdateIsPassword(); } -bool Textfield::IsMultiLine() const { - return !!(style_ & STYLE_MULTILINE); -} - void Textfield::SetText(const string16& text) { text_ = text; if (native_wrapper_) @@ -197,12 +191,6 @@ void Textfield::SetVerticalMargins(int top, int bottom) { PreferredSizeChanged(); } -void Textfield::SetHeightInLines(int num_lines) { - DCHECK(IsMultiLine()); - num_lines_ = num_lines; - PreferredSizeChanged(); -} - void Textfield::RemoveBorder() { if (!draw_border_) return; @@ -313,8 +301,7 @@ gfx::Size Textfield::GetPreferredSize() { if (draw_border_ && native_wrapper_) insets = native_wrapper_->CalculateInsets(); return gfx::Size(font_.GetExpectedTextWidth(default_width_in_chars_) + - insets.width(), - num_lines_ * font_.GetHeight() + insets.height()); + insets.width(), font_.GetHeight() + insets.height()); } bool Textfield::IsFocusable() const { diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h index e80a622..3965050 100644 --- a/views/controls/textfield/textfield.h +++ b/views/controls/textfield/textfield.h @@ -50,8 +50,7 @@ class Textfield : public View { enum StyleFlags { STYLE_DEFAULT = 0, STYLE_PASSWORD = 1 << 0, - STYLE_MULTILINE = 1 << 1, - STYLE_LOWERCASE = 1 << 2 + STYLE_LOWERCASE = 1 << 1 }; Textfield(); @@ -70,11 +69,7 @@ class Textfield : public View { bool IsPassword() const; void SetPassword(bool password); - // Whether the text field is multi-line or not, must be set when the text - // field is created, using StyleFlags. - bool IsMultiLine() const; - - // Gets the text currently displayed in the Textfield. + // Gets/Sets the text currently displayed in the Textfield. const string16& text() const { return text_; } // Sets the text currently displayed in the Textfield. This doesn't @@ -138,10 +133,6 @@ class Textfield : public View { // 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); - // Sets the default width of the text control. See default_width_in_chars_. void set_default_width_in_chars(int default_width) { default_width_in_chars_ = default_width; @@ -294,9 +285,6 @@ class Textfield : public View { // Textfield's background color. bool use_default_background_color_; - // The number of lines of text this Textfield displays at once. - int num_lines_; - // TODO(beng): remove this once NativeTextfieldWin subclasses // NativeControlWin. bool initialized_; |