OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/textfield/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/i18n/rtl.h" |
12 #include "base/pickle.h" | 13 #include "base/pickle.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
15 #include "ui/accessibility/ax_view_state.h" | 16 #include "ui/accessibility/ax_view_state.h" |
16 #include "ui/base/clipboard/clipboard.h" | 17 #include "ui/base/clipboard/clipboard.h" |
17 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 18 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
18 #include "ui/base/dragdrop/drag_drop_types.h" | 19 #include "ui/base/dragdrop/drag_drop_types.h" |
19 #include "ui/base/ime/input_method_base.h" | 20 #include "ui/base/ime/input_method_base.h" |
20 #include "ui/base/ime/input_method_delegate.h" | 21 #include "ui/base/ime/input_method_delegate.h" |
21 #include "ui/base/ime/input_method_factory.h" | 22 #include "ui/base/ime/input_method_factory.h" |
22 #include "ui/base/ime/text_input_client.h" | 23 #include "ui/base/ime/text_input_client.h" |
23 #include "ui/base/l10n/l10n_util.h" | |
24 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
25 #include "ui/base/ui_base_switches_util.h" | 25 #include "ui/base/ui_base_switches_util.h" |
26 #include "ui/events/event.h" | 26 #include "ui/events/event.h" |
27 #include "ui/events/event_processor.h" | 27 #include "ui/events/event_processor.h" |
28 #include "ui/events/event_utils.h" | 28 #include "ui/events/event_utils.h" |
29 #include "ui/events/keycodes/keyboard_codes.h" | 29 #include "ui/events/keycodes/keyboard_codes.h" |
30 #include "ui/gfx/render_text.h" | 30 #include "ui/gfx/render_text.h" |
31 #include "ui/strings/grit/ui_strings.h" | 31 #include "ui/strings/grit/ui_strings.h" |
32 #include "ui/views/controls/textfield/textfield_controller.h" | 32 #include "ui/views/controls/textfield/textfield_controller.h" |
33 #include "ui/views/controls/textfield/textfield_model.h" | 33 #include "ui/views/controls/textfield/textfield_model.h" |
(...skipping 1855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1889 EXPECT_LT(prev_x, x); | 1889 EXPECT_LT(prev_x, x); |
1890 prev_x = x; | 1890 prev_x = x; |
1891 | 1891 |
1892 SendKeyEvent('b'); | 1892 SendKeyEvent('b'); |
1893 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); | 1893 EXPECT_EQ(WideToUTF16(L"\x05E1\x5E2" L"ab"), textfield_->text()); |
1894 x = GetCursorBounds().x(); | 1894 x = GetCursorBounds().x(); |
1895 EXPECT_LT(prev_x, x); | 1895 EXPECT_LT(prev_x, x); |
1896 } | 1896 } |
1897 | 1897 |
1898 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { | 1898 TEST_F(TextfieldTest, TextCursorDisplayInRTLTest) { |
1899 std::string locale = l10n_util::GetApplicationLocale(""); | 1899 std::string locale = base::i18n::GetConfiguredLocale(); |
1900 base::i18n::SetICUDefaultLocale("he"); | 1900 base::i18n::SetICUDefaultLocale("he"); |
1901 | 1901 |
1902 InitTextfield(); | 1902 InitTextfield(); |
1903 // LTR-RTL string in RTL context. | 1903 // LTR-RTL string in RTL context. |
1904 SendKeyEvent('a'); | 1904 SendKeyEvent('a'); |
1905 EXPECT_STR_EQ("a", textfield_->text()); | 1905 EXPECT_STR_EQ("a", textfield_->text()); |
1906 int x = GetCursorBounds().x(); | 1906 int x = GetCursorBounds().x(); |
1907 EXPECT_EQ(GetDisplayRect().right() - 1, x); | 1907 EXPECT_EQ(GetDisplayRect().right() - 1, x); |
1908 int prev_x = x; | 1908 int prev_x = x; |
1909 | 1909 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2036 MouseClick(bound, 10); | 2036 MouseClick(bound, 10); |
2037 EXPECT_EQ(bound, GetCursorBounds()); | 2037 EXPECT_EQ(bound, GetCursorBounds()); |
2038 | 2038 |
2039 SendEndEvent(shift); | 2039 SendEndEvent(shift); |
2040 bound = GetCursorBounds(); | 2040 bound = GetCursorBounds(); |
2041 MouseClick(bound, -10); | 2041 MouseClick(bound, -10); |
2042 EXPECT_EQ(bound, GetCursorBounds()); | 2042 EXPECT_EQ(bound, GetCursorBounds()); |
2043 } | 2043 } |
2044 | 2044 |
2045 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { | 2045 TEST_F(TextfieldTest, HitOutsideTextAreaInRTLTest) { |
2046 std::string locale = l10n_util::GetApplicationLocale(""); | 2046 std::string locale = base::i18n::GetConfiguredLocale(); |
2047 base::i18n::SetICUDefaultLocale("he"); | 2047 base::i18n::SetICUDefaultLocale("he"); |
2048 | 2048 |
2049 InitTextfield(); | 2049 InitTextfield(); |
2050 | 2050 |
2051 // RTL-LTR string in RTL context. | 2051 // RTL-LTR string in RTL context. |
2052 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); | 2052 textfield_->SetText(WideToUTF16(L"\x05E1\x5E2" L"ab")); |
2053 const bool shift = false; | 2053 const bool shift = false; |
2054 SendHomeEvent(shift); | 2054 SendHomeEvent(shift); |
2055 gfx::Rect bound = GetCursorBounds(); | 2055 gfx::Rect bound = GetCursorBounds(); |
2056 MouseClick(bound, 10); | 2056 MouseClick(bound, 10); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2099 for (int i = 0; i < 500; ++i) | 2099 for (int i = 0; i < 500; ++i) |
2100 SendKeyEvent(kHebrewLetterSamekh); | 2100 SendKeyEvent(kHebrewLetterSamekh); |
2101 SendKeyEvent('a'); | 2101 SendKeyEvent('a'); |
2102 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 2102 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
2103 | 2103 |
2104 MouseClick(GetCursorBounds(), -1); | 2104 MouseClick(GetCursorBounds(), -1); |
2105 EXPECT_EQ(501U, textfield_->GetCursorPosition()); | 2105 EXPECT_EQ(501U, textfield_->GetCursorPosition()); |
2106 } | 2106 } |
2107 | 2107 |
2108 TEST_F(TextfieldTest, OverflowInRTLTest) { | 2108 TEST_F(TextfieldTest, OverflowInRTLTest) { |
2109 std::string locale = l10n_util::GetApplicationLocale(""); | 2109 std::string locale = base::i18n::GetConfiguredLocale(); |
2110 base::i18n::SetICUDefaultLocale("he"); | 2110 base::i18n::SetICUDefaultLocale("he"); |
2111 | 2111 |
2112 InitTextfield(); | 2112 InitTextfield(); |
2113 | 2113 |
2114 base::string16 str; | 2114 base::string16 str; |
2115 for (int i = 0; i < 500; ++i) | 2115 for (int i = 0; i < 500; ++i) |
2116 SendKeyEvent('a'); | 2116 SendKeyEvent('a'); |
2117 SendKeyEvent(kHebrewLetterSamekh); | 2117 SendKeyEvent(kHebrewLetterSamekh); |
2118 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); | 2118 EXPECT_TRUE(GetDisplayRect().Contains(GetCursorBounds())); |
2119 | 2119 |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2583 | 2583 |
2584 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2584 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
2585 ui::AXViewState state_protected; | 2585 ui::AXViewState state_protected; |
2586 textfield_->GetAccessibleState(&state_protected); | 2586 textfield_->GetAccessibleState(&state_protected); |
2587 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2587 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
2588 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2588 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
2589 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2589 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
2590 } | 2590 } |
2591 | 2591 |
2592 } // namespace views | 2592 } // namespace views |
OLD | NEW |