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 2885 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2946 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { | 2948 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { |
2947 InitTextfield(); | 2949 InitTextfield(); |
2948 textfield_->SetText(ASCIIToUTF16("abc")); | 2950 textfield_->SetText(ASCIIToUTF16("abc")); |
2949 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2951 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2950 textfield_->SelectRange(gfx::Range(1, 2)); | 2952 textfield_->SelectRange(gfx::Range(1, 2)); |
2951 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); | 2953 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); |
2952 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); | 2954 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); |
2953 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2955 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2954 } | 2956 } |
2955 | 2957 |
| 2958 #if defined(OS_CHROMEOS) |
| 2959 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2960 // shifted up when focused and restored when focus is lost. |
| 2961 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretNotInRect) { |
| 2962 InitTextfield(); |
| 2963 |
| 2964 // Enable new virtual keyboard behavior. |
| 2965 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2966 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2967 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2968 } |
| 2969 |
| 2970 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2971 int keyboard_height = 200; |
| 2972 gfx::Rect root_bounds = root_window->bounds(); |
| 2973 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2974 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2975 gfx::Rect keyboard_view_bounds = |
| 2976 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(), |
| 2977 keyboard_height); |
| 2978 |
| 2979 // Focus the window. |
| 2980 widget_->SetBounds(orig_widget_bounds); |
| 2981 input_method_->SetFocusedTextInputClient(textfield_); |
| 2982 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2983 |
| 2984 // Simulate virtual keyboard. |
| 2985 input_method_->SetOnScreenKeyboardBounds(keyboard_view_bounds); |
| 2986 |
| 2987 // Window should be shifted. |
| 2988 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2989 |
| 2990 // Detach the textfield from the IME |
| 2991 input_method_->DetachTextInputClient(textfield_); |
| 2992 wm::RestoreWindowBoundsOnClientFocusLost( |
| 2993 widget_->GetNativeView()->GetToplevelWindow()); |
| 2994 |
| 2995 // Window should be restored. |
| 2996 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2997 } |
| 2998 #endif // defined(OS_CHROMEOS) |
| 2999 |
2956 class TextfieldTouchSelectionTest : public TextfieldTest { | 3000 class TextfieldTouchSelectionTest : public TextfieldTest { |
2957 protected: | 3001 protected: |
2958 // Simulates a complete tap. | 3002 // Simulates a complete tap. |
2959 void Tap(const gfx::Point& point) { | 3003 void Tap(const gfx::Point& point) { |
2960 GestureEventForTest begin( | 3004 GestureEventForTest begin( |
2961 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 3005 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
2962 textfield_->OnGestureEvent(&begin); | 3006 textfield_->OnGestureEvent(&begin); |
2963 | 3007 |
2964 GestureEventForTest tap_down( | 3008 GestureEventForTest tap_down( |
2965 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 3009 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3123 InitTextfield(); | 3167 InitTextfield(); |
3124 | 3168 |
3125 textfield_->SetCursorEnabled(false); | 3169 textfield_->SetCursorEnabled(false); |
3126 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3170 EXPECT_FALSE(test_api_->IsCursorVisible()); |
3127 | 3171 |
3128 textfield_->SetCursorEnabled(true); | 3172 textfield_->SetCursorEnabled(true); |
3129 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3173 EXPECT_TRUE(test_api_->IsCursorVisible()); |
3130 } | 3174 } |
3131 | 3175 |
3132 } // namespace views | 3176 } // namespace views |
OLD | NEW |