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> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/format_macros.h" | 15 #include "base/format_macros.h" |
16 #include "base/i18n/rtl.h" | 16 #include "base/i18n/rtl.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/pickle.h" | 18 #include "base/pickle.h" |
19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "ui/accessibility/ax_node_data.h" | 23 #include "ui/accessibility/ax_node_data.h" |
| 24 #include "ui/aura/window.h" |
24 #include "ui/base/clipboard/clipboard.h" | 25 #include "ui/base/clipboard/clipboard.h" |
25 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 26 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
26 #include "ui/base/dragdrop/drag_drop_types.h" | 27 #include "ui/base/dragdrop/drag_drop_types.h" |
27 #include "ui/base/ime/input_method_base.h" | 28 #include "ui/base/ime/input_method_base.h" |
28 #include "ui/base/ime/input_method_delegate.h" | 29 #include "ui/base/ime/input_method_delegate.h" |
29 #include "ui/base/ime/input_method_factory.h" | 30 #include "ui/base/ime/input_method_factory.h" |
30 #include "ui/base/ime/text_edit_commands.h" | 31 #include "ui/base/ime/text_edit_commands.h" |
31 #include "ui/base/ime/text_input_client.h" | 32 #include "ui/base/ime/text_input_client.h" |
32 #include "ui/base/ui_base_switches.h" | 33 #include "ui/base/ui_base_switches.h" |
33 #include "ui/base/ui_base_switches_util.h" | 34 #include "ui/base/ui_base_switches_util.h" |
34 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
35 #include "ui/events/event_processor.h" | 36 #include "ui/events/event_processor.h" |
36 #include "ui/events/event_utils.h" | 37 #include "ui/events/event_utils.h" |
37 #include "ui/events/keycodes/keyboard_codes.h" | 38 #include "ui/events/keycodes/keyboard_codes.h" |
38 #include "ui/events/test/event_generator.h" | 39 #include "ui/events/test/event_generator.h" |
39 #include "ui/events/test/keyboard_layout.h" | 40 #include "ui/events/test/keyboard_layout.h" |
40 #include "ui/gfx/render_text.h" | 41 #include "ui/gfx/render_text.h" |
41 #include "ui/strings/grit/ui_strings.h" | 42 #include "ui/strings/grit/ui_strings.h" |
42 #include "ui/views/controls/textfield/textfield_controller.h" | 43 #include "ui/views/controls/textfield/textfield_controller.h" |
43 #include "ui/views/controls/textfield/textfield_model.h" | 44 #include "ui/views/controls/textfield/textfield_model.h" |
44 #include "ui/views/controls/textfield/textfield_test_api.h" | 45 #include "ui/views/controls/textfield/textfield_test_api.h" |
45 #include "ui/views/focus/focus_manager.h" | 46 #include "ui/views/focus/focus_manager.h" |
46 #include "ui/views/style/platform_style.h" | 47 #include "ui/views/style/platform_style.h" |
47 #include "ui/views/test/test_views_delegate.h" | 48 #include "ui/views/test/test_views_delegate.h" |
48 #include "ui/views/test/views_test_base.h" | 49 #include "ui/views/test/views_test_base.h" |
49 #include "ui/views/test/widget_test.h" | 50 #include "ui/views/test/widget_test.h" |
50 #include "ui/views/widget/widget.h" | 51 #include "ui/views/widget/widget.h" |
| 52 #include "ui/wm/core/ime_util.h" |
51 #include "url/gurl.h" | 53 #include "url/gurl.h" |
52 | 54 |
53 #if defined(OS_WIN) | 55 #if defined(OS_WIN) |
54 #include "base/win/windows_version.h" | 56 #include "base/win/windows_version.h" |
55 #endif | 57 #endif |
56 | 58 |
57 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 59 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
58 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 60 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
59 #endif | 61 #endif |
60 | 62 |
(...skipping 2879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2940 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { | 2942 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { |
2941 InitTextfield(); | 2943 InitTextfield(); |
2942 textfield_->SetText(ASCIIToUTF16("abc")); | 2944 textfield_->SetText(ASCIIToUTF16("abc")); |
2943 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2945 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2944 textfield_->SelectRange(gfx::Range(1, 2)); | 2946 textfield_->SelectRange(gfx::Range(1, 2)); |
2945 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); | 2947 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); |
2946 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); | 2948 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); |
2947 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2949 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2948 } | 2950 } |
2949 | 2951 |
| 2952 #if defined(OS_CHROMEOS) |
| 2953 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2954 // shifted up when focused and restored when focus is lost. |
| 2955 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretNotInRect) { |
| 2956 InitTextfield(); |
| 2957 |
| 2958 // Enable new virtual keyboard behavior. |
| 2959 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2960 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2961 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2962 } |
| 2963 |
| 2964 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2965 int keyboard_height = 200; |
| 2966 gfx::Rect root_bounds = root_window->bounds(); |
| 2967 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2968 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2969 gfx::Rect keyboard_view_bounds = |
| 2970 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(), |
| 2971 keyboard_height); |
| 2972 |
| 2973 // Focus the window. |
| 2974 widget_->SetBounds(orig_widget_bounds); |
| 2975 input_method_->SetFocusedTextInputClient(textfield_); |
| 2976 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2977 |
| 2978 // Simulate virtual keyboard. |
| 2979 input_method_->SetOnScreenKeyboardBounds(keyboard_view_bounds); |
| 2980 |
| 2981 // Window should be shifted. |
| 2982 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2983 |
| 2984 // Detach the textfield from the IME |
| 2985 input_method_->DetachTextInputClient(textfield_); |
| 2986 wm::RestoreWindowBoundsOnClientFocusLost( |
| 2987 widget_->GetNativeView()->GetToplevelWindow()); |
| 2988 |
| 2989 // Window should be restored. |
| 2990 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2991 } |
| 2992 #endif // defined(OS_CHROMEOS) |
| 2993 |
2950 class TextfieldTouchSelectionTest : public TextfieldTest { | 2994 class TextfieldTouchSelectionTest : public TextfieldTest { |
2951 protected: | 2995 protected: |
2952 // Simulates a complete tap. | 2996 // Simulates a complete tap. |
2953 void Tap(const gfx::Point& point) { | 2997 void Tap(const gfx::Point& point) { |
2954 GestureEventForTest begin( | 2998 GestureEventForTest begin( |
2955 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 2999 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
2956 textfield_->OnGestureEvent(&begin); | 3000 textfield_->OnGestureEvent(&begin); |
2957 | 3001 |
2958 GestureEventForTest tap_down( | 3002 GestureEventForTest tap_down( |
2959 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 3003 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3117 InitTextfield(); | 3161 InitTextfield(); |
3118 | 3162 |
3119 textfield_->SetCursorEnabled(false); | 3163 textfield_->SetCursorEnabled(false); |
3120 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3164 EXPECT_FALSE(test_api_->IsCursorVisible()); |
3121 | 3165 |
3122 textfield_->SetCursorEnabled(true); | 3166 textfield_->SetCursorEnabled(true); |
3123 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3167 EXPECT_TRUE(test_api_->IsCursorVisible()); |
3124 } | 3168 } |
3125 | 3169 |
3126 } // namespace views | 3170 } // namespace views |
OLD | NEW |