| 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_view_state.h" | 23 #include "ui/accessibility/ax_view_state.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 2743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 // The controller assumes ownership of the textfield. | 2778 // The controller assumes ownership of the textfield. |
| 2778 TextfieldDestroyerController controller(textfield_); | 2779 TextfieldDestroyerController controller(textfield_); |
| 2779 EXPECT_TRUE(controller.target()); | 2780 EXPECT_TRUE(controller.target()); |
| 2780 | 2781 |
| 2781 // Send a key to trigger OnKeyEvent(). | 2782 // Send a key to trigger OnKeyEvent(). |
| 2782 SendKeyEvent(ui::VKEY_RETURN); | 2783 SendKeyEvent(ui::VKEY_RETURN); |
| 2783 | 2784 |
| 2784 EXPECT_FALSE(controller.target()); | 2785 EXPECT_FALSE(controller.target()); |
| 2785 } | 2786 } |
| 2786 | 2787 |
| 2788 // Check that when accessibility virtual keyboard is enabled, windows are |
| 2789 // shifted up when focused and restored when focus is lost. |
| 2790 TEST_F(TextfieldTest, VirtualKeyboardFocusEnsureCaretInRect) { |
| 2791 InitTextfield(); |
| 2792 |
| 2793 // Enable new virtual keyboard behavior. |
| 2794 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 2795 if (!command_line->HasSwitch(::switches::kUseNewVirtualKeyboardBehavior)) { |
| 2796 command_line->AppendSwitch(::switches::kUseNewVirtualKeyboardBehavior); |
| 2797 } |
| 2798 |
| 2799 aura::Window* root_window = widget_->GetNativeView()->GetRootWindow(); |
| 2800 int keyboard_height = 200; |
| 2801 gfx::Rect root_bounds = root_window->bounds(); |
| 2802 gfx::Rect root_bounds_with_keyboard = gfx::Rect( |
| 2803 root_bounds.origin(), |
| 2804 gfx::Size(root_bounds.width(), root_bounds.height() - keyboard_height)); |
| 2805 gfx::Rect orig_widget_bounds = gfx::Rect(0, 300, 400, 200); |
| 2806 gfx::Rect shifted_widget_bounds = gfx::Rect(0, 200, 400, 200); |
| 2807 |
| 2808 // Focus the window. |
| 2809 widget_->SetBounds(orig_widget_bounds); |
| 2810 input_method_->SetFocusedTextInputClient(textfield_); |
| 2811 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2812 |
| 2813 // Simulate virtual keyboard. |
| 2814 input_method_->SetAvailableBounds(root_bounds_with_keyboard); |
| 2815 |
| 2816 // Window should be shifted. |
| 2817 EXPECT_EQ(widget_->GetNativeView()->bounds(), shifted_widget_bounds); |
| 2818 |
| 2819 // Change the focus. |
| 2820 input_method_->SetFocusedTextInputClient(nullptr); |
| 2821 |
| 2822 // Window should be restored. |
| 2823 EXPECT_EQ(widget_->GetNativeView()->bounds(), orig_widget_bounds); |
| 2824 } |
| 2825 |
| 2787 class TextfieldTouchSelectionTest : public TextfieldTest { | 2826 class TextfieldTouchSelectionTest : public TextfieldTest { |
| 2788 protected: | 2827 protected: |
| 2789 // Simulates a complete tap. | 2828 // Simulates a complete tap. |
| 2790 void Tap(const gfx::Point& point) { | 2829 void Tap(const gfx::Point& point) { |
| 2791 GestureEventForTest begin( | 2830 GestureEventForTest begin( |
| 2792 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); | 2831 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_BEGIN)); |
| 2793 textfield_->OnGestureEvent(&begin); | 2832 textfield_->OnGestureEvent(&begin); |
| 2794 | 2833 |
| 2795 GestureEventForTest tap_down( | 2834 GestureEventForTest tap_down( |
| 2796 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); | 2835 point.x(), point.y(), ui::GestureEventDetails(ui::ET_GESTURE_TAP_DOWN)); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2939 | 2978 |
| 2940 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); | 2979 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD); |
| 2941 ui::AXViewState state_protected; | 2980 ui::AXViewState state_protected; |
| 2942 textfield_->GetAccessibleState(&state_protected); | 2981 textfield_->GetAccessibleState(&state_protected); |
| 2943 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); | 2982 EXPECT_EQ(ui::AX_ROLE_TEXT_FIELD, state_protected.role); |
| 2944 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); | 2983 EXPECT_EQ(ASCIIToUTF16("********"), state_protected.value); |
| 2945 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); | 2984 EXPECT_TRUE(state_protected.HasStateFlag(ui::AX_STATE_PROTECTED)); |
| 2946 } | 2985 } |
| 2947 | 2986 |
| 2948 } // namespace views | 2987 } // namespace views |
| OLD | NEW |