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 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2873 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { | 2874 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { |
2874 InitTextfield(); | 2875 InitTextfield(); |
2875 textfield_->SetText(ASCIIToUTF16("abc")); | 2876 textfield_->SetText(ASCIIToUTF16("abc")); |
2876 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2877 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2877 textfield_->SelectRange(gfx::Range(1, 2)); | 2878 textfield_->SelectRange(gfx::Range(1, 2)); |
2878 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); | 2879 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); |
2879 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); | 2880 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); |
2880 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2881 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2881 } | 2882 } |
2882 | 2883 |
| 2884 #if defined(OS_CHROMEOS) |
| 2885 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2886 // shifted up when focused and restored when focus is lost. |
| 2887 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretInRect) { |
| 2888 InitTextfield(); |
| 2889 |
| 2890 // Enable new virtual keyboard behavior. |
| 2891 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2892 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2893 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2894 } |
| 2895 |
| 2896 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2897 int keyboard_height = 200; |
| 2898 gfx::Rect root_bounds = root_window->bounds(); |
| 2899 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2900 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2901 gfx::Rect keyboard_view_bounds = |
| 2902 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(), |
| 2903 keyboard_height); |
| 2904 |
| 2905 // Focus the window. |
| 2906 widget_->SetBounds(orig_widget_bounds); |
| 2907 input_method_->SetFocusedTextInputClient(textfield_); |
| 2908 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2909 |
| 2910 // Simulate virtual keyboard. |
| 2911 input_method_->SetOnScreenKeyboardBounds(keyboard_view_bounds); |
| 2912 |
| 2913 // Window should be shifted. |
| 2914 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2915 |
| 2916 // Change the focus. |
| 2917 input_method_->SetFocusedTextInputClient(nullptr); |
| 2918 |
| 2919 // Window should be restored. |
| 2920 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2921 } |
| 2922 #endif // defined(OS_CHROMEOS) |
| 2923 |
2883 class TextfieldTouchSelectionTest : public TextfieldTest { | 2924 class TextfieldTouchSelectionTest : public TextfieldTest { |
2884 protected: | 2925 protected: |
2885 // Simulates a complete tap. | 2926 // Simulates a complete tap. |
2886 void Tap(const gfx::Point& point) { | 2927 void Tap(const gfx::Point& point) { |
2887 GestureEventForTest begin( | 2928 GestureEventForTest begin( |
2888 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 2929 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
2889 textfield_->OnGestureEvent(&begin); | 2930 textfield_->OnGestureEvent(&begin); |
2890 | 2931 |
2891 GestureEventForTest tap_down( | 2932 GestureEventForTest tap_down( |
2892 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 2933 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3039 ui::AXNodeData node_data_protected; | 3080 ui::AXNodeData node_data_protected; |
3040 node_data_protected.state = 0; | 3081 node_data_protected.state = 0; |
3041 textfield_->GetAccessibleNodeData(&node_data_protected); | 3082 textfield_->GetAccessibleNodeData(&node_data_protected); |
3042 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3083 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
3043 EXPECT_EQ(ASCIIToUTF16("********"), | 3084 EXPECT_EQ(ASCIIToUTF16("********"), |
3044 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3085 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
3045 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3086 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
3046 } | 3087 } |
3047 | 3088 |
3048 } // namespace views | 3089 } // namespace views |
OLD | NEW |