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 2803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2837 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { | 2838 TEST_F(TextfieldTest, CursorBlinkRestartsOnInsertOrReplace) { |
2838 InitTextfield(); | 2839 InitTextfield(); |
2839 textfield_->SetText(ASCIIToUTF16("abc")); | 2840 textfield_->SetText(ASCIIToUTF16("abc")); |
2840 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2841 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2841 textfield_->SelectRange(gfx::Range(1, 2)); | 2842 textfield_->SelectRange(gfx::Range(1, 2)); |
2842 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); | 2843 EXPECT_FALSE(test_api_->IsCursorBlinkTimerRunning()); |
2843 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); | 2844 textfield_->InsertOrReplaceText(base::ASCIIToUTF16("foo")); |
2844 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); | 2845 EXPECT_TRUE(test_api_->IsCursorBlinkTimerRunning()); |
2845 } | 2846 } |
2846 | 2847 |
| 2848 #if defined(OS_CHROMEOS) |
| 2849 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2850 // shifted up when focused and restored when focus is lost. |
| 2851 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretInRect) { |
| 2852 InitTextfield(); |
| 2853 |
| 2854 // Enable new virtual keyboard behavior. |
| 2855 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2856 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2857 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2858 } |
| 2859 |
| 2860 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2861 int keyboard_height = 200; |
| 2862 gfx::Rect root_bounds = root_window->bounds(); |
| 2863 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2864 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2865 gfx::Rect keyboard_view_bounds = |
| 2866 gfx::Rect(0, root_bounds.height() - keyboard_height, root_bounds.width(), |
| 2867 keyboard_height); |
| 2868 |
| 2869 // Focus the window. |
| 2870 widget_->SetBounds(orig_widget_bounds); |
| 2871 input_method_->SetFocusedTextInputClient(textfield_); |
| 2872 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2873 |
| 2874 // Simulate virtual keyboard. |
| 2875 input_method_->SetCoveredBounds(keyboard_view_bounds); |
| 2876 |
| 2877 // Window should be shifted. |
| 2878 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2879 |
| 2880 // Change the focus. |
| 2881 input_method_->SetFocusedTextInputClient(nullptr); |
| 2882 |
| 2883 // Window should be restored. |
| 2884 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2885 } |
| 2886 #endif // defined(OS_CHROMEOS) |
| 2887 |
2847 class TextfieldTouchSelectionTest : public TextfieldTest { | 2888 class TextfieldTouchSelectionTest : public TextfieldTest { |
2848 protected: | 2889 protected: |
2849 // Simulates a complete tap. | 2890 // Simulates a complete tap. |
2850 void Tap(const gfx::Point& point) { | 2891 void Tap(const gfx::Point& point) { |
2851 GestureEventForTest begin( | 2892 GestureEventForTest begin( |
2852 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 2893 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
2853 textfield_->OnGestureEvent(&begin); | 2894 textfield_->OnGestureEvent(&begin); |
2854 | 2895 |
2855 GestureEventForTest tap_down( | 2896 GestureEventForTest tap_down( |
2856 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 2897 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3003 ui::AXNodeData node_data_protected; | 3044 ui::AXNodeData node_data_protected; |
3004 node_data_protected.state = 0; | 3045 node_data_protected.state = 0; |
3005 textfield_->GetAccessibleNodeData(&node_data_protected); | 3046 textfield_->GetAccessibleNodeData(&node_data_protected); |
3006 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); | 3047 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, node_data_protected.role); |
3007 EXPECT_EQ(ASCIIToUTF16("********"), | 3048 EXPECT_EQ(ASCIIToUTF16("********"), |
3008 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); | 3049 node_data_protected.GetString16Attribute(ui::AX_ATTR_VALUE)); |
3009 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 3050 EXPECT_TRUE(node_data_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
3010 } | 3051 } |
3011 | 3052 |
3012 } // namespace views | 3053 } // namespace views |
OLD | NEW |