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" |
(...skipping 21 matching lines...) Expand all Loading... |
55 #endif | 56 #endif |
56 | 57 |
57 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | 58 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
58 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" | 59 #include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" |
59 #endif | 60 #endif |
60 | 61 |
61 #if defined(USE_X11) | 62 #if defined(USE_X11) |
62 #include "ui/events/event_utils.h" | 63 #include "ui/events/event_utils.h" |
63 #endif | 64 #endif |
64 | 65 |
| 66 #if defined(OS_CHROMEOS) |
| 67 #include "ui/wm/core/ime_util_chromeos.h" |
| 68 #endif |
| 69 |
65 using base::ASCIIToUTF16; | 70 using base::ASCIIToUTF16; |
66 using base::UTF8ToUTF16; | 71 using base::UTF8ToUTF16; |
67 using base::WideToUTF16; | 72 using base::WideToUTF16; |
68 | 73 |
69 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16) | 74 #define EXPECT_STR_EQ(ascii, utf16) EXPECT_EQ(ASCIIToUTF16(ascii), utf16) |
70 | 75 |
71 namespace { | 76 namespace { |
72 | 77 |
73 const base::char16 kHebrewLetterSamekh = 0x05E1; | 78 const base::char16 kHebrewLetterSamekh = 0x05E1; |
74 | 79 |
(...skipping 2871 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2946 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { | 2951 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { |
2947 InitTextfield(); | 2952 InitTextfield(); |
2948 textfield_->SetText(ASCIIToUTF16("abc")); | 2953 textfield_->SetText(ASCIIToUTF16("abc")); |
2949 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2954 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2950 textfield_->SelectRange(gfx::Range(1, 2)); | 2955 textfield_->SelectRange(gfx::Range(1, 2)); |
2951 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); | 2956 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); |
2952 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); | 2957 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); |
2953 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2958 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2954 } | 2959 } |
2955 | 2960 |
| 2961 #if defined(OS_CHROMEOS) |
| 2962 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2963 // shifted up when focused and restored when focus is lost. |
| 2964 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretNotInRect) { |
| 2965 InitTextfield(); |
| 2966 |
| 2967 // Enable new virtual keyboard behavior. |
| 2968 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2969 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2970 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2971 } |
| 2972 |
| 2973 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2974 int keyboard_height = 200; |
| 2975 gfx::Rect root_bounds = root_window->bounds(); |
| 2976 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2977 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2978 gfx::Rect keyboard_view_bounds = |
| 2979 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(), |
| 2980 keyboard_height); |
| 2981 |
| 2982 // Focus the window. |
| 2983 widget_->SetBounds(orig_widget_bounds); |
| 2984 input_method_->SetFocusedTextInputClient(textfield_); |
| 2985 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2986 |
| 2987 // Simulate virtual keyboard. |
| 2988 input_method_->SetOnScreenKeyboardBounds(keyboard_view_bounds); |
| 2989 |
| 2990 // Window should be shifted. |
| 2991 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2992 |
| 2993 // Detach the textfield from the IME |
| 2994 input_method_->DetachTextInputClient(textfield_); |
| 2995 wm::RestoreWindowBoundsOnClientFocusLost( |
| 2996 widget_->GetNativeView()->GetToplevelWindow()); |
| 2997 |
| 2998 // Window should be restored. |
| 2999 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 3000 } |
| 3001 #endif // defined(OS_CHROMEOS) |
| 3002 |
2956 class TextfieldTouchSelectionTest : public TextfieldTest { | 3003 class TextfieldTouchSelectionTest : public TextfieldTest { |
2957 protected: | 3004 protected: |
2958 // Simulates a complete tap. | 3005 // Simulates a complete tap. |
2959 void Tap(const gfx::Point& point) { | 3006 void Tap(const gfx::Point& point) { |
2960 GestureEventForTest begin( | 3007 GestureEventForTest begin( |
2961 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 3008 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
2962 textfield_->OnGestureEvent(&begin); | 3009 textfield_->OnGestureEvent(&begin); |
2963 | 3010 |
2964 GestureEventForTest tap_down( | 3011 GestureEventForTest tap_down( |
2965 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 3012 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(); | 3170 InitTextfield(); |
3124 | 3171 |
3125 textfield_->SetCursorEnabled(false); | 3172 textfield_->SetCursorEnabled(false); |
3126 EXPECT_FALSE(test_api_->IsCursorVisible()); | 3173 EXPECT_FALSE(test_api_->IsCursorVisible()); |
3127 | 3174 |
3128 textfield_->SetCursorEnabled(true); | 3175 textfield_->SetCursorEnabled(true); |
3129 EXPECT_TRUE(test_api_->IsCursorVisible()); | 3176 EXPECT_TRUE(test_api_->IsCursorVisible()); |
3130 } | 3177 } |
3131 | 3178 |
3132 } // namespace views | 3179 } // namespace views |
OLD | NEW |