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 <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
7 #include <set> | 10 #include <set> |
8 #include <string> | 11 #include <string> |
9 #include <vector> | 12 #include <vector> |
10 | 13 |
11 #include "base/command_line.h" | 14 #include "base/command_line.h" |
12 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/macros.h" |
13 #include "base/pickle.h" | 17 #include "base/pickle.h" |
14 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
15 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "build/build_config.h" |
16 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
17 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
18 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 23 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
19 #include "ui/base/dragdrop/drag_drop_types.h" | 24 #include "ui/base/dragdrop/drag_drop_types.h" |
20 #include "ui/base/ime/input_method_base.h" | 25 #include "ui/base/ime/input_method_base.h" |
21 #include "ui/base/ime/input_method_delegate.h" | 26 #include "ui/base/ime/input_method_delegate.h" |
22 #include "ui/base/ime/input_method_factory.h" | 27 #include "ui/base/ime/input_method_factory.h" |
23 #include "ui/base/ime/text_input_client.h" | 28 #include "ui/base/ime/text_input_client.h" |
24 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
25 #include "ui/base/ui_base_switches_util.h" | 30 #include "ui/base/ui_base_switches_util.h" |
(...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 2120 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
2116 | 2121 |
2117 // Reset locale. | 2122 // Reset locale. |
2118 base::i18n::SetICUDefaultLocale(locale); | 2123 base::i18n::SetICUDefaultLocale(locale); |
2119 } | 2124 } |
2120 | 2125 |
2121 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { | 2126 TEST_F(TextfieldTest, GetCompositionCharacterBoundsTest) { |
2122 InitTextfield(); | 2127 InitTextfield(); |
2123 ui::CompositionText composition; | 2128 ui::CompositionText composition; |
2124 composition.text = UTF8ToUTF16("abc123"); | 2129 composition.text = UTF8ToUTF16("abc123"); |
2125 const uint32 char_count = static_cast<uint32>(composition.text.length()); | 2130 const uint32_t char_count = static_cast<uint32_t>(composition.text.length()); |
2126 ui::TextInputClient* client = textfield_; | 2131 ui::TextInputClient* client = textfield_; |
2127 | 2132 |
2128 // Compare the composition character bounds with surrounding cursor bounds. | 2133 // Compare the composition character bounds with surrounding cursor bounds. |
2129 for (uint32 i = 0; i < char_count; ++i) { | 2134 for (uint32_t i = 0; i < char_count; ++i) { |
2130 composition.selection = gfx::Range(i); | 2135 composition.selection = gfx::Range(i); |
2131 client->SetCompositionText(composition); | 2136 client->SetCompositionText(composition); |
2132 gfx::Point cursor_origin = GetCursorBounds().origin(); | 2137 gfx::Point cursor_origin = GetCursorBounds().origin(); |
2133 views::View::ConvertPointToScreen(textfield_, &cursor_origin); | 2138 views::View::ConvertPointToScreen(textfield_, &cursor_origin); |
2134 | 2139 |
2135 composition.selection = gfx::Range(i + 1); | 2140 composition.selection = gfx::Range(i + 1); |
2136 client->SetCompositionText(composition); | 2141 client->SetCompositionText(composition); |
2137 gfx::Point next_cursor_bottom_left = GetCursorBounds().bottom_left(); | 2142 gfx::Point next_cursor_bottom_left = GetCursorBounds().bottom_left(); |
2138 views::View::ConvertPointToScreen(textfield_, &next_cursor_bottom_left); | 2143 views::View::ConvertPointToScreen(textfield_, &next_cursor_bottom_left); |
2139 | 2144 |
(...skipping 28 matching lines...) Expand all Loading... |
2168 const size_t kUtf16CharsCount = arraysize(kUtf16Chars); | 2173 const size_t kUtf16CharsCount = arraysize(kUtf16Chars); |
2169 | 2174 |
2170 ui::CompositionText composition; | 2175 ui::CompositionText composition; |
2171 composition.text.assign(kUtf16Chars, kUtf16Chars + kUtf16CharsCount); | 2176 composition.text.assign(kUtf16Chars, kUtf16Chars + kUtf16CharsCount); |
2172 ui::TextInputClient* client = textfield_; | 2177 ui::TextInputClient* client = textfield_; |
2173 client->SetCompositionText(composition); | 2178 client->SetCompositionText(composition); |
2174 | 2179 |
2175 // Make sure GetCompositionCharacterBounds never fails for index. | 2180 // Make sure GetCompositionCharacterBounds never fails for index. |
2176 gfx::Rect rects[kUtf16CharsCount]; | 2181 gfx::Rect rects[kUtf16CharsCount]; |
2177 gfx::Rect prev_cursor = GetCursorBounds(); | 2182 gfx::Rect prev_cursor = GetCursorBounds(); |
2178 for (uint32 i = 0; i < kUtf16CharsCount; ++i) | 2183 for (uint32_t i = 0; i < kUtf16CharsCount; ++i) |
2179 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &rects[i])); | 2184 EXPECT_TRUE(client->GetCompositionCharacterBounds(i, &rects[i])); |
2180 | 2185 |
2181 // Here we might expect the following results but it actually depends on how | 2186 // Here we might expect the following results but it actually depends on how |
2182 // Uniscribe or HarfBuzz treats them with given font. | 2187 // Uniscribe or HarfBuzz treats them with given font. |
2183 // - rects[1] == rects[2] | 2188 // - rects[1] == rects[2] |
2184 // - rects[3] == rects[4] == rects[5] | 2189 // - rects[3] == rects[4] == rects[5] |
2185 // - rects[6] == rects[7] | 2190 // - rects[6] == rects[7] |
2186 } | 2191 } |
2187 | 2192 |
2188 // The word we select by double clicking should remain selected regardless of | 2193 // The word we select by double clicking should remain selected regardless of |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2565 | 2570 |
2566 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2571 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
2567 ui::AXViewState state_protected; | 2572 ui::AXViewState state_protected; |
2568 textfield_->GetAccessibleState(&state_protected); | 2573 textfield_->GetAccessibleState(&state_protected); |
2569 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2574 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
2570 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2575 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
2571 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2576 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
2572 } | 2577 } |
2573 | 2578 |
2574 } // namespace views | 2579 } // namespace views |
OLD | NEW |