summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc2
-rw-r--r--chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc4
-rw-r--r--chrome/browser/ui/views/edit_search_engine_dialog.cc2
-rw-r--r--chrome/browser/ui/views/find_bar_view.cc6
-rw-r--r--chrome/browser/ui/views/login_view.cc2
-rw-r--r--chrome/browser/ui/views/omnibox/omnibox_view_views.cc5
-rw-r--r--ui/gfx/render_text.cc14
-rw-r--r--ui/gfx/render_text.h10
-rw-r--r--ui/gfx/render_text_unittest.cc33
-rw-r--r--ui/views/controls/message_box_view.cc2
-rw-r--r--ui/views/controls/textfield/native_textfield_views.cc12
-rw-r--r--ui/views/controls/textfield/native_textfield_views.h2
-rw-r--r--ui/views/controls/textfield/native_textfield_views_unittest.cc12
-rw-r--r--ui/views/controls/textfield/native_textfield_win.cc23
-rw-r--r--ui/views/controls/textfield/native_textfield_win.h2
-rw-r--r--ui/views/controls/textfield/native_textfield_wrapper.h7
-rw-r--r--ui/views/controls/textfield/textfield.cc6
-rw-r--r--ui/views/controls/textfield/textfield.h6
-rw-r--r--ui/views/controls/textfield/textfield_views_model.cc6
-rw-r--r--ui/views/controls/textfield/textfield_views_model.h6
-rw-r--r--ui/views/controls/textfield/textfield_views_model_unittest.cc29
-rw-r--r--ui/views/controls/tree/tree_view_views.cc2
-rw-r--r--ui/views/view_unittest.cc22
23 files changed, 130 insertions, 85 deletions
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc
index 14244a5..6cf4125 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bubble_view.cc
@@ -87,7 +87,7 @@ void BookmarkBubbleView::ShowBubble(views::View* anchor_view,
views::BubbleDelegateView::CreateBubble(bookmark_bubble_);
bookmark_bubble_->Show();
// Select the entire title textfield contents when the bubble is first shown.
- bookmark_bubble_->title_tf_->SelectAll();
+ bookmark_bubble_->title_tf_->SelectAll(true);
GURL url_ptr(url);
content::NotificationService::current()->Notify(
diff --git a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
index 752ef35..5e8605c 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_editor_view.cc
@@ -120,7 +120,7 @@ bool BookmarkEditorView::Accept() {
if (!IsDialogButtonEnabled(ui::DIALOG_BUTTON_OK)) {
if (details_.GetNodeType() != BookmarkNode::FOLDER) {
// The url is invalid, focus the url field.
- url_tf_->SelectAll();
+ url_tf_->SelectAll(true);
url_tf_->RequestFocus();
}
return false;
@@ -259,7 +259,7 @@ void BookmarkEditorView::Show(gfx::NativeWindow parent_window) {
ExpandAndSelect();
GetWidget()->Show();
// Select all the text in the name Textfield.
- title_tf_->SelectAll();
+ title_tf_->SelectAll(true);
// Give focus to the name Textfield.
title_tf_->RequestFocus();
}
diff --git a/chrome/browser/ui/views/edit_search_engine_dialog.cc b/chrome/browser/ui/views/edit_search_engine_dialog.cc
index 8960dc7..a5d97d1 100644
--- a/chrome/browser/ui/views/edit_search_engine_dialog.cc
+++ b/chrome/browser/ui/views/edit_search_engine_dialog.cc
@@ -62,7 +62,7 @@ void EditSearchEngineDialog::Show(gfx::NativeWindow parent,
views::Widget::CreateWindowWithParent(contents, parent);
contents->GetWidget()->Show();
contents->GetDialogClientView()->UpdateDialogButtons();
- contents->title_tf_->SelectAll();
+ contents->title_tf_->SelectAll(true);
contents->title_tf_->RequestFocus();
}
diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc
index f113822..25dce06 100644
--- a/chrome/browser/ui/views/find_bar_view.cc
+++ b/chrome/browser/ui/views/find_bar_view.cc
@@ -186,7 +186,7 @@ void FindBarView::UpdateForResult(const FindNotificationDetails& result,
// update the text only when the IME is not composing text.
if (find_text_->text() != find_text && !find_text_->IsIMEComposing()) {
find_text_->SetText(find_text);
- find_text_->SelectAll();
+ find_text_->SelectAll(true);
}
if (find_text.empty() || !have_valid_range) {
@@ -220,7 +220,7 @@ void FindBarView::ClearMatchCount() {
void FindBarView::SetFocusAndSelection(bool select_all) {
find_text_->RequestFocus();
if (select_all && !find_text_->text().empty())
- find_text_->SelectAll();
+ find_text_->SelectAll(true);
}
///////////////////////////////////////////////////////////////////////////////
@@ -478,7 +478,7 @@ void FindBarView::SearchTextfieldView::RequestFocus() {
if (HasFocus())
return;
views::View::RequestFocus();
- SelectAll();
+ SelectAll(true);
}
FindBarHost* FindBarView::find_bar_host() const {
diff --git a/chrome/browser/ui/views/login_view.cc b/chrome/browser/ui/views/login_view.cc
index bba2c2d..62e5b0a 100644
--- a/chrome/browser/ui/views/login_view.cc
+++ b/chrome/browser/ui/views/login_view.cc
@@ -107,6 +107,6 @@ void LoginView::OnAutofillDataAvailable(const string16& username,
if (username_field_->text().empty()) {
username_field_->SetText(username);
password_field_->SetText(password);
- username_field_->SelectAll();
+ username_field_->SelectAll(true);
}
}
diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
index 9b810c5..1d5595b 100644
--- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
+++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc
@@ -614,10 +614,7 @@ void OmniboxViewViews::GetSelectionBounds(string16::size_type* start,
}
void OmniboxViewViews::SelectAll(bool reversed) {
- if (reversed)
- textfield_->SelectRange(ui::Range(GetTextLength(), 0));
- else
- textfield_->SelectRange(ui::Range(0, GetTextLength()));
+ textfield_->SelectAll(reversed);
}
void OmniboxViewViews::RevertAll() {
diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc
index cd9b505..85dc029 100644
--- a/ui/gfx/render_text.cc
+++ b/ui/gfx/render_text.cc
@@ -521,18 +521,16 @@ void RenderText::ClearSelection() {
selection_model_.caret_affinity()));
}
-void RenderText::SelectAll() {
- SelectionModel all;
- if (GetTextDirection() == base::i18n::LEFT_TO_RIGHT)
- all = SelectionModel(ui::Range(0, text().length()), CURSOR_FORWARD);
- else
- all = SelectionModel(ui::Range(text().length(), 0), CURSOR_BACKWARD);
- SetSelectionModel(all);
+void RenderText::SelectAll(bool reversed) {
+ const size_t length = text().length();
+ const ui::Range all = reversed ? ui::Range(length, 0) : ui::Range(0, length);
+ const bool success = SelectRange(all);
+ DCHECK(success);
}
void RenderText::SelectWord() {
if (obscured_) {
- SelectAll();
+ SelectAll(false);
return;
}
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
index 0f8ca50..a6265b0 100644
--- a/ui/gfx/render_text.h
+++ b/ui/gfx/render_text.h
@@ -226,9 +226,15 @@ class UI_EXPORT RenderText {
// Returns true if the local point is over selected text.
bool IsPointInSelection(const Point& point);
- // Selects no text, all text, or the word at the current cursor position.
+ // Selects no text, keeping the current cursor position and caret affinity.
void ClearSelection();
- void SelectAll();
+
+ // Select the entire text range. If |reversed| is true, the range will end at
+ // the logical beginning of the text; this generally shows the leading portion
+ // of text that overflows its display area.
+ void SelectAll(bool reversed);
+
+ // Selects the word at the current cursor position.
void SelectWord();
const ui::Range& GetCompositionRange() const;
diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc
index 46a3a78..a8ca541 100644
--- a/ui/gfx/render_text_unittest.cc
+++ b/ui/gfx/render_text_unittest.cc
@@ -727,7 +727,38 @@ TEST_F(RenderTextTest, EdgeSelectionModels) {
}
}
-TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
+TEST_F(RenderTextTest, SelectAll) {
+ const wchar_t* const cases[] = {
+ L"abc",
+ L"a"L"\x5d0\x5d1",
+ L"a"L"\x5d1"L"b",
+ L"\x5d0\x5d1\x5d2",
+ L"\x5d0\x5d1"L"a",
+ L"\x5d0"L"a"L"\x5d1",
+ };
+
+ // Ensure that SelectAll respects the |reversed| argument regardless of
+ // application locale and text content directionality.
+ scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
+ const SelectionModel expected_reversed(ui::Range(3, 0), CURSOR_FORWARD);
+ const SelectionModel expected_forwards(ui::Range(0, 3), CURSOR_BACKWARD);
+ const bool was_rtl = base::i18n::IsRTL();
+
+ for (size_t i = 0; i < 2; ++i) {
+ SetRTL(!base::i18n::IsRTL());
+ for (size_t j = 0; j < ARRAYSIZE_UNSAFE(cases); j++) {
+ render_text->SetText(WideToUTF16(cases[j]));
+ render_text->SelectAll(false);
+ EXPECT_EQ(render_text->selection_model(), expected_forwards);
+ render_text->SelectAll(true);
+ EXPECT_EQ(render_text->selection_model(), expected_reversed);
+ }
+ }
+
+ EXPECT_EQ(was_rtl, base::i18n::IsRTL());
+}
+
+ TEST_F(RenderTextTest, MoveCursorLeftRightWithSelection) {
scoped_ptr<RenderText> render_text(RenderText::CreateInstance());
render_text->SetText(WideToUTF16(L"abc\x05d0\x05d1\x05d2"));
// Left arrow on select ranging (6, 4).
diff --git a/ui/views/controls/message_box_view.cc b/ui/views/controls/message_box_view.cc
index 23151f1..960b316 100644
--- a/ui/views/controls/message_box_view.cc
+++ b/ui/views/controls/message_box_view.cc
@@ -125,7 +125,7 @@ void MessageBoxView::ViewHierarchyChanged(bool is_add,
View* child) {
if (child == this && is_add) {
if (prompt_field_)
- prompt_field_->SelectAll();
+ prompt_field_->SelectAll(true);
GetWidget()->NotifyAccessibilityEvent(
this, ui::AccessibilityTypes::EVENT_ALERT, true);
diff --git a/ui/views/controls/textfield/native_textfield_views.cc b/ui/views/controls/textfield/native_textfield_views.cc
index 80e785a..beb1437 100644
--- a/ui/views/controls/textfield/native_textfield_views.cc
+++ b/ui/views/controls/textfield/native_textfield_views.cc
@@ -159,7 +159,7 @@ ui::GestureStatus NativeTextfieldViews::OnGestureEvent(
OnAfterUserAction();
return ui::GESTURE_STATUS_CONSUMED;
case ui::ET_GESTURE_DOUBLE_TAP:
- SelectAll();
+ SelectAll(false);
return ui::GESTURE_STATUS_CONSUMED;
case ui::ET_GESTURE_SCROLL_UPDATE:
OnBeforeUserAction();
@@ -370,9 +370,9 @@ string16 NativeTextfieldViews::GetSelectedText() const {
return model_->GetSelectedText();
}
-void NativeTextfieldViews::SelectAll() {
+void NativeTextfieldViews::SelectAll(bool reversed) {
OnBeforeUserAction();
- model_->SelectAll();
+ model_->SelectAll(reversed);
OnCaretBoundsChanged();
SchedulePaint();
OnAfterUserAction();
@@ -618,7 +618,7 @@ void NativeTextfieldViews::ExecuteCommand(int command_id) {
text_changed = model_->Delete();
break;
case IDS_APP_SELECT_ALL:
- SelectAll();
+ SelectAll(false);
break;
default:
textfield_->GetController()->ExecuteCommand(command_id);
@@ -927,7 +927,7 @@ bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) {
break;
case ui::VKEY_A:
if (control) {
- model_->SelectAll();
+ model_->SelectAll(false);
cursor_changed = true;
}
break;
@@ -1177,7 +1177,7 @@ void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) {
OnCaretBoundsChanged();
break;
case 2:
- model_->SelectAll();
+ model_->SelectAll(false);
OnCaretBoundsChanged();
break;
default:
diff --git a/ui/views/controls/textfield/native_textfield_views.h b/ui/views/controls/textfield/native_textfield_views.h
index f5ea868..9142c5a 100644
--- a/ui/views/controls/textfield/native_textfield_views.h
+++ b/ui/views/controls/textfield/native_textfield_views.h
@@ -94,7 +94,7 @@ class VIEWS_EXPORT NativeTextfieldViews : public TouchSelectionClientView,
virtual void UpdateText() OVERRIDE;
virtual void AppendText(const string16& text) OVERRIDE;
virtual string16 GetSelectedText() const OVERRIDE;
- virtual void SelectAll() OVERRIDE;
+ virtual void SelectAll(bool reversed) OVERRIDE;
virtual void ClearSelection() OVERRIDE;
virtual void UpdateBorder() OVERRIDE;
virtual void UpdateTextColor() OVERRIDE;
diff --git a/ui/views/controls/textfield/native_textfield_views_unittest.cc b/ui/views/controls/textfield/native_textfield_views_unittest.cc
index b299e37..de5bc3a 100644
--- a/ui/views/controls/textfield/native_textfield_views_unittest.cc
+++ b/ui/views/controls/textfield/native_textfield_views_unittest.cc
@@ -352,7 +352,7 @@ TEST_F(NativeTextfieldViewsTest, ModelChangesTest) {
EXPECT_TRUE(last_contents_.empty());
EXPECT_EQ(string16(), textfield_->GetSelectedText());
- textfield_->SelectAll();
+ textfield_->SelectAll(false);
EXPECT_STR_EQ("this is a test", textfield_->GetSelectedText());
EXPECT_TRUE(last_contents_.empty());
}
@@ -523,7 +523,7 @@ TEST_F(NativeTextfieldViewsTest, InsertionDeletionTest) {
EXPECT_STR_EQ("this is ", textfield_->text());
// Select all and replace with "k".
- textfield_->SelectAll();
+ textfield_->SelectAll(false);
SendKeyEvent(ui::VKEY_K);
EXPECT_STR_EQ("k", textfield_->text());
@@ -573,7 +573,7 @@ TEST_F(NativeTextfieldViewsTest, PasswordTest) {
EXPECT_TRUE(last_contents_.empty());
// Cut and copy should be disabled in the context menu.
- model_->SelectAll();
+ model_->SelectAll(false);
EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_CUT));
EXPECT_FALSE(IsCommandIdEnabled(IDS_APP_COPY));
@@ -756,7 +756,7 @@ TEST_F(NativeTextfieldViewsTest, ContextMenuDisplayTest) {
EXPECT_TRUE(GetContextMenuModel());
VerifyTextfieldContextMenuContents(false, GetContextMenuModel());
- textfield_->SelectAll();
+ textfield_->SelectAll(false);
VerifyTextfieldContextMenuContents(true, GetContextMenuModel());
}
@@ -1075,7 +1075,7 @@ TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) {
EXPECT_EQ(5U, textfield_->GetCursorPosition());
EXPECT_STR_EQ("two ", textfield_->GetSelectedText());
- textfield_->SelectAll();
+ textfield_->SelectAll(false);
EXPECT_STR_EQ(" one two three ", textfield_->GetSelectedText());
// CUT&PASTE does not work, but COPY works
@@ -1099,7 +1099,7 @@ TEST_F(NativeTextfieldViewsTest, ReadOnlyTest) {
EXPECT_STR_EQ(" four five six ", textfield_->text());
EXPECT_TRUE(textfield_->GetSelectedText().empty());
- textfield_->SelectAll();
+ textfield_->SelectAll(false);
EXPECT_STR_EQ(" four five six ", textfield_->GetSelectedText());
// Text field is unmodifiable and selection shouldn't change.
diff --git a/ui/views/controls/textfield/native_textfield_win.cc b/ui/views/controls/textfield/native_textfield_win.cc
index ec98132..5372cbc 100644
--- a/ui/views/controls/textfield/native_textfield_win.cc
+++ b/ui/views/controls/textfield/native_textfield_win.cc
@@ -219,10 +219,11 @@ string16 NativeTextfieldWin::GetSelectedText() const {
return str;
}
-void NativeTextfieldWin::SelectAll() {
- // Select from the end to the front so that the first part of the text is
- // always visible.
- SetSel(GetTextLength(), 0);
+void NativeTextfieldWin::SelectAll(bool reversed) {
+ if (reversed)
+ SetSel(GetTextLength(), 0);
+ else
+ SetSel(0, GetTextLength());
}
void NativeTextfieldWin::ClearSelection() {
@@ -449,12 +450,12 @@ void NativeTextfieldWin::ExecuteCommand(int command_id) {
ScopedFreeze freeze(this, GetTextObjectModel());
OnBeforePossibleChange();
switch (command_id) {
- case IDS_APP_UNDO: Undo(); break;
- case IDS_APP_CUT: Cut(); break;
- case IDS_APP_COPY: Copy(); break;
- case IDS_APP_PASTE: Paste(); break;
- case IDS_APP_SELECT_ALL: SelectAll(); break;
- default: NOTREACHED(); break;
+ case IDS_APP_UNDO: Undo(); break;
+ case IDS_APP_CUT: Cut(); break;
+ case IDS_APP_COPY: Copy(); break;
+ case IDS_APP_PASTE: Paste(); break;
+ case IDS_APP_SELECT_ALL: SelectAll(false); break;
+ default: NOTREACHED(); break;
}
OnAfterPossibleChange(true);
}
@@ -1095,7 +1096,7 @@ void NativeTextfieldWin::OnAfterPossibleChange(bool should_redraw_text) {
string16 text(GetText());
ScopedSuspendUndo suspend_undo(GetTextObjectModel());
- SelectAll();
+ SelectAll(true);
ReplaceSel(reinterpret_cast<LPCTSTR>(text.c_str()), true);
SetSel(original_sel);
}
diff --git a/ui/views/controls/textfield/native_textfield_win.h b/ui/views/controls/textfield/native_textfield_win.h
index dfebcdb..b7591bd 100644
--- a/ui/views/controls/textfield/native_textfield_win.h
+++ b/ui/views/controls/textfield/native_textfield_win.h
@@ -69,7 +69,7 @@ class NativeTextfieldWin
virtual void UpdateText() OVERRIDE;
virtual void AppendText(const string16& text) OVERRIDE;
virtual string16 GetSelectedText() const OVERRIDE;
- virtual void SelectAll() OVERRIDE;
+ virtual void SelectAll(bool reversed) OVERRIDE;
virtual void ClearSelection() OVERRIDE;
virtual void UpdateBorder() OVERRIDE;
virtual void UpdateTextColor() OVERRIDE;
diff --git a/ui/views/controls/textfield/native_textfield_wrapper.h b/ui/views/controls/textfield/native_textfield_wrapper.h
index 43aed03..06d972f3 100644
--- a/ui/views/controls/textfield/native_textfield_wrapper.h
+++ b/ui/views/controls/textfield/native_textfield_wrapper.h
@@ -47,9 +47,10 @@ class VIEWS_EXPORT NativeTextfieldWrapper {
// Gets the text that is selected in the wrapped native text field.
virtual string16 GetSelectedText() const = 0;
- // Selects all the text in the edit. Use this in place of SetSelAll() to
- // avoid selecting the "phantom newline" at the end of the edit.
- virtual void SelectAll() = 0;
+ // Select the entire text range. If |reversed| is true, the range will end at
+ // the logical beginning of the text; this generally shows the leading portion
+ // of text that overflows its display area.
+ virtual void SelectAll(bool reversed) = 0;
// Clears the selection within the edit field and sets the caret to the end.
virtual void ClearSelection() = 0;
diff --git a/ui/views/controls/textfield/textfield.cc b/ui/views/controls/textfield/textfield.cc
index 8b3a254..a34be2d 100644
--- a/ui/views/controls/textfield/textfield.cc
+++ b/ui/views/controls/textfield/textfield.cc
@@ -159,9 +159,9 @@ void Textfield::AppendText(const string16& text) {
native_wrapper_->AppendText(text);
}
-void Textfield::SelectAll() {
+void Textfield::SelectAll(bool reversed) {
if (native_wrapper_)
- native_wrapper_->SelectAll();
+ native_wrapper_->SelectAll(reversed);
}
string16 Textfield::GetSelectedText() const {
@@ -370,7 +370,7 @@ gfx::Size Textfield::GetPreferredSize() {
}
void Textfield::AboutToRequestFocusFromTabTraversal(bool reverse) {
- SelectAll();
+ SelectAll(false);
}
bool Textfield::SkipDefaultKeyEventProcessing(const KeyEvent& e) {
diff --git a/ui/views/controls/textfield/textfield.h b/ui/views/controls/textfield/textfield.h
index 39bc4a0..224169b 100644
--- a/ui/views/controls/textfield/textfield.h
+++ b/ui/views/controls/textfield/textfield.h
@@ -88,8 +88,10 @@ class VIEWS_EXPORT Textfield : public View {
// Returns the text that is currently selected.
string16 GetSelectedText() const;
- // Causes the edit field to be fully selected.
- void SelectAll();
+ // Select the entire text range. If |reversed| is true, the range will end at
+ // the logical beginning of the text; this generally shows the leading portion
+ // of text that overflows its display area.
+ void SelectAll(bool reversed);
// Clears the selection within the edit field and sets the caret to the end.
void ClearSelection() const;
diff --git a/ui/views/controls/textfield/textfield_views_model.cc b/ui/views/controls/textfield/textfield_views_model.cc
index f052df9..372fcf1 100644
--- a/ui/views/controls/textfield/textfield_views_model.cc
+++ b/ui/views/controls/textfield/textfield_views_model.cc
@@ -317,7 +317,7 @@ bool TextfieldViewsModel::SetText(const string16& text) {
size_t old_cursor = GetCursorPosition();
// SetText moves the cursor to the end.
size_t new_cursor = text.length();
- SelectAll();
+ SelectAll(false);
// If there is a composition text, don't merge with previous edit.
// Otherwise, force merge the edits.
ExecuteAndRecordReplace(
@@ -439,10 +439,10 @@ void TextfieldViewsModel::SelectSelectionModel(const gfx::SelectionModel& sel) {
render_text_->MoveCursorTo(sel);
}
-void TextfieldViewsModel::SelectAll() {
+void TextfieldViewsModel::SelectAll(bool reversed) {
if (HasCompositionText())
ConfirmCompositionText();
- render_text_->SelectAll();
+ render_text_->SelectAll(reversed);
}
void TextfieldViewsModel::SelectWord() {
diff --git a/ui/views/controls/textfield/textfield_views_model.h b/ui/views/controls/textfield/textfield_views_model.h
index 94bf984..8268595 100644
--- a/ui/views/controls/textfield/textfield_views_model.h
+++ b/ui/views/controls/textfield/textfield_views_model.h
@@ -151,9 +151,11 @@ class VIEWS_EXPORT TextfieldViewsModel {
// render_text_'s selection model is set to |sel|.
void SelectSelectionModel(const gfx::SelectionModel& sel);
- // Selects all text.
+ // Select the entire text range. If |reversed| is true, the range will end at
+ // the logical beginning of the text; this generally shows the leading portion
+ // of text that overflows its display area.
// The current composition text will be confirmed.
- void SelectAll();
+ void SelectAll(bool reversed);
// Selects the word at which the cursor is currently positioned.
// The current composition text will be confirmed.
diff --git a/ui/views/controls/textfield/textfield_views_model_unittest.cc b/ui/views/controls/textfield/textfield_views_model_unittest.cc
index 7140436..376f7d4 100644
--- a/ui/views/controls/textfield/textfield_views_model_unittest.cc
+++ b/ui/views/controls/textfield/textfield_views_model_unittest.cc
@@ -276,13 +276,20 @@ TEST_F(TextfieldViewsModelTest, Selection) {
EXPECT_STR_EQ("ELLO", model.GetSelectedText());
model.ClearSelection();
EXPECT_EQ(string16(), model.GetSelectedText());
- model.SelectAll();
+
+ // SelectAll(false) selects towards the end.
+ model.SelectAll(false);
EXPECT_STR_EQ("HELLO", model.GetSelectedText());
- // SelectAll should select towards the end.
gfx::SelectionModel sel;
model.GetSelectionModel(&sel);
EXPECT_EQ(ui::Range(0, 5), sel.selection());
+ // SelectAll(true) selects towards the beginning.
+ model.SelectAll(true);
+ EXPECT_STR_EQ("HELLO", model.GetSelectedText());
+ model.GetSelectionModel(&sel);
+ EXPECT_EQ(ui::Range(5, 0), sel.selection());
+
// Select and move cursor
model.SelectRange(ui::Range(1U, 3U));
EXPECT_STR_EQ("EL", model.GetSelectedText());
@@ -293,10 +300,10 @@ TEST_F(TextfieldViewsModelTest, Selection) {
EXPECT_EQ(3U, model.GetCursorPosition());
// Select all and move cursor
- model.SelectAll();
+ model.SelectAll(false);
model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_LEFT, false);
EXPECT_EQ(0U, model.GetCursorPosition());
- model.SelectAll();
+ model.SelectAll(false);
model.MoveCursor(gfx::CHARACTER_BREAK, gfx::CURSOR_RIGHT, false);
EXPECT_EQ(5U, model.GetCursorPosition());
}
@@ -337,7 +344,7 @@ TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) {
model.ClearSelection();
EXPECT_EQ(string16(), model.GetSelectedText());
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_EQ(WideToUTF16(L"abc\x05E9\x05BC\x05C1\x05B8\x05E0\x05B8"L"def"),
model.GetSelectedText());
#endif
@@ -380,7 +387,7 @@ TEST_F(TextfieldViewsModelTest, Selection_BidiWithNonSpacingMarks) {
model.ClearSelection();
EXPECT_EQ(string16(), model.GetSelectedText());
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_EQ(WideToUTF16(L"a\x05E9"L"b"), model.GetSelectedText());
}
@@ -468,7 +475,7 @@ TEST_F(TextfieldViewsModelTest, SetText) {
EXPECT_STR_EQ("GOODBYE", model.GetText());
// SetText move the cursor to the end of the new text.
EXPECT_EQ(7U, model.GetCursorPosition());
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_STR_EQ("GOODBYE", model.GetSelectedText());
model.MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, false);
EXPECT_EQ(7U, model.GetCursorPosition());
@@ -515,7 +522,7 @@ TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) {
// Cut on obscured (password) text should do nothing.
model.render_text()->SetObscured(true);
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_FALSE(model.Cut());
clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
EXPECT_EQ(initial_clipboard_text, clipboard_text);
@@ -523,7 +530,7 @@ TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) {
EXPECT_STR_EQ("HELLO WORLD", model.GetSelectedText());
// Copy on obscured text should do nothing.
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_FALSE(model.Copy());
clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
EXPECT_EQ(initial_clipboard_text, clipboard_text);
@@ -542,7 +549,7 @@ TEST_F(TextfieldViewsModelTest, MAYBE_Clipboard) {
// Copy with non-empty selection.
model.Append(ASCIIToUTF16("HELLO WORLD"));
- model.SelectAll();
+ model.SelectAll(false);
model.Copy();
clipboard->ReadText(ui::Clipboard::BUFFER_STANDARD, &clipboard_text);
EXPECT_STR_EQ("HELLO HELLO WORLD", clipboard_text);
@@ -975,7 +982,7 @@ TEST_F(TextfieldViewsModelTest, CompositionTextTest) {
EXPECT_STR_EQ("678", model.GetText());
model.SetCompositionText(composition);
- model.SelectAll();
+ model.SelectAll(false);
EXPECT_TRUE(composition_text_confirmed_or_cleared_);
composition_text_confirmed_or_cleared_ = false;
EXPECT_STR_EQ("678", model.GetText());
diff --git a/ui/views/controls/tree/tree_view_views.cc b/ui/views/controls/tree/tree_view_views.cc
index b13080e..c97bb41 100644
--- a/ui/views/controls/tree/tree_view_views.cc
+++ b/ui/views/controls/tree/tree_view_views.cc
@@ -143,7 +143,7 @@ void TreeView::StartEditing(TreeModelNode* node) {
LayoutEditor();
SchedulePaintForNode(selected_node_);
editor_->RequestFocus();
- editor_->SelectAll();
+ editor_->SelectAll(false);
// Listen for focus changes so that we can cancel editing.
focus_manager_ = GetFocusManager();
diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc
index 1ccd2dc..4fd87b3 100644
--- a/ui/views/view_unittest.cc
+++ b/ui/views/view_unittest.cc
@@ -1044,7 +1044,7 @@ TEST_F(ViewTest, Textfield) {
// Test selection related methods.
textfield->SetText(kText);
EXPECT_EQ(kEmptyString, textfield->GetSelectedText());
- textfield->SelectAll();
+ textfield->SelectAll(false);
EXPECT_EQ(kText, textfield->text());
textfield->ClearSelection();
EXPECT_EQ(kEmptyString, textfield->GetSelectedText());
@@ -1085,7 +1085,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
// Test cut.
//
ASSERT_TRUE(normal->GetTestingHandle());
- normal->SelectAll();
+ normal->SelectAll(false);
::SendMessage(normal->GetTestingHandle(), WM_CUT, 0, 0);
string16 result;
@@ -1094,7 +1094,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
normal->SetText(kNormalText); // Let's revert to the original content.
ASSERT_TRUE(read_only->GetTestingHandle());
- read_only->SelectAll();
+ read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
@@ -1102,7 +1102,7 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
EXPECT_EQ(kNormalText, result);
ASSERT_TRUE(password->GetTestingHandle());
- password->SelectAll();
+ password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_CUT, 0, 0);
result.clear();
clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
@@ -1115,19 +1115,19 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
// Let's start with read_only as the clipboard already contains the content
// of normal.
- read_only->SelectAll();
+ read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kReadOnlyText, result);
- normal->SelectAll();
+ normal->SelectAll(false);
::SendMessage(normal->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
EXPECT_EQ(kNormalText, result);
- password->SelectAll();
+ password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_COPY, 0, 0);
result.clear();
clipboard.ReadText(ui::Clipboard::BUFFER_STANDARD, &result);
@@ -1143,22 +1143,22 @@ TEST_F(ViewTest, TextfieldCutCopyPaste) {
// WM_KEYDOWN messages that we are not simulating here.
// Attempting to copy kNormalText in a read-only text-field should fail.
- read_only->SelectAll();
+ read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_KEYDOWN, 0, 0);
wchar_t buffer[1024] = { 0 };
::GetWindowText(read_only->GetTestingHandle(), buffer, 1024);
EXPECT_EQ(kReadOnlyText, string16(buffer));
- password->SelectAll();
+ password->SelectAll(false);
::SendMessage(password->GetTestingHandle(), WM_PASTE, 0, 0);
::GetWindowText(password->GetTestingHandle(), buffer, 1024);
EXPECT_EQ(kNormalText, string16(buffer));
// Copy from read_only so the string we are pasting is not the same as the
// current one.
- read_only->SelectAll();
+ read_only->SelectAll(false);
::SendMessage(read_only->GetTestingHandle(), WM_COPY, 0, 0);
- normal->SelectAll();
+ normal->SelectAll(false);
::SendMessage(normal->GetTestingHandle(), WM_PASTE, 0, 0);
::GetWindowText(normal->GetTestingHandle(), buffer, 1024);
EXPECT_EQ(kReadOnlyText, string16(buffer));