diff options
author | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 04:44:55 +0000 |
---|---|---|
committer | msw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-13 04:44:55 +0000 |
commit | f5f0c2acc32a94ba0035bb316aa6b66d212bf3cf (patch) | |
tree | 5c6e7928ca754c123cfa82d21778427536f4326c /ui/gfx/render_text_unittest.cc | |
parent | 24cddd42154b07c6559846b2159a88a3feabb5d5 (diff) | |
download | chromium_src-f5f0c2acc32a94ba0035bb316aa6b66d212bf3cf.zip chromium_src-f5f0c2acc32a94ba0035bb316aa6b66d212bf3cf.tar.gz chromium_src-f5f0c2acc32a94ba0035bb316aa6b66d212bf3cf.tar.bz2 |
Add and specify Views::Textfield::SelectAll |reversed| flag, etc.
SelectAll should be consistent and explicit with range reversal.
This dictates if leading or trailing text is shown when textfields overflow.
Currently, NativeTextfield[Win|Views]::SelectAll behavior is implicit and differs.
(Windows native reverses the selection, while ChromeOS/Views doesn't)
Revise SelectAll in RenderText, NativeTextfieldWin, and OmniboxViewViews.
Add the |reversed| parameter and plumbing to related interfaces/functions.
Add/update RenderTextTest.SelectAll and TextfieldViewsModelTest.Selection.
Specify explicit reversal behavior in all the following cases:
1) Use reversed selection (changes ChromeOS/Views behavior) in:
a) BookmarkBubbleView::ShowBubble (focus on bookmark title when shown).
b) BookmarkEditorView::Accept (focus on invalid bookmark URL on "Save").
c) BookmarkEditorView::Show (focus on bookmark title when shown).
d) FindBarView::UpdateForResult (find bar matches are found/iterated).
e) FindBarView::SetFocusAndSelection (find bar shown, etc.).
f) FindBarView::SearchTextfieldView::RequestFocus (click find bar parts, etc.).
g) EditSearchEngineDialog::Show (focus on search engine title when shown).
h) LoginView::OnAutofillDataAvailable (HTTP/FTP auth window shown).
i) MessageBoxView::ViewHierarchyChanged (JS dialog with text input shown).
2) Use forward selection (changes Windows native behavior) in:
a) NativeTextfieldWin::ExecuteCommand (textfield context menu "Select All").
(note: the Omnibox context menu "Select All" already uses forward selection)
b) Textfield::AboutToRequestFocusFromTabTraversal (focus via tab-traversal).
(note1: THIS IS CONTENTIOUS! Though OmniBoxViewWin is unaffected)
(note2: OmniboxViewViews should be fixed later as per crbug.com/134701#c9)
c) TreeView::StartEditing (editing tree view nodes ex/ collected cookies).
d) NativeTextfieldViewsTest.* and ViewTest.* (changes inconsequential to tests)
3) Formally specify existing implicit behavior (no behavioral change):
a) NativeTextfieldWin::OnAfterPossibleChange (temporary selection is reversed).
b) NativeTextfieldViews::OnGestureEvent (double tap is forwards).
c) NativeTextfieldViews::ExecuteCommand (context menu "Select All" is forwards).
d) NativeTextfieldViews::HandleKeyEvent (CTRL-A is forwards).
e) NativeTextfieldViews::HandleMousePressEvent (triple-click is forwards).
f) TextfieldViewsModel::SetText (temporary selection is forwards).
g) TextfieldViewsModelTest.* is mostly forwards, |Selection| tests reversed.
TBR=ben@chromium.org
BUG=134762
TEST=New RenderTextTest.SelectAll, updated TextfieldViewsModelTest.Selection, other unit tests, manual.
Review URL: https://chromiumcodereview.appspot.com/10693160
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146520 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/render_text_unittest.cc')
-rw-r--r-- | ui/gfx/render_text_unittest.cc | 33 |
1 files changed, 32 insertions, 1 deletions
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). |