OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/base/event.h" | 23 #include "ui/base/event.h" |
24 #include "ui/base/ime/text_input_client.h" | 24 #include "ui/base/ime/text_input_client.h" |
25 #include "ui/base/keycodes/keyboard_codes.h" | 25 #include "ui/base/keycodes/keyboard_codes.h" |
26 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
27 #include "ui/base/ui_base_switches.h" | 27 #include "ui/base/ui_base_switches.h" |
28 #include "ui/gfx/render_text.h" | 28 #include "ui/gfx/render_text.h" |
29 #include "ui/views/controls/textfield/native_textfield_views.h" | 29 #include "ui/views/controls/textfield/native_textfield_views.h" |
30 #include "ui/views/controls/textfield/textfield.h" | 30 #include "ui/views/controls/textfield/textfield.h" |
31 #include "ui/views/controls/textfield/textfield_controller.h" | 31 #include "ui/views/controls/textfield/textfield_controller.h" |
32 #include "ui/views/controls/textfield/textfield_views_model.h" | 32 #include "ui/views/controls/textfield/textfield_views_model.h" |
33 #include "ui/views/events/event.h" | |
34 #include "ui/views/focus/focus_manager.h" | 33 #include "ui/views/focus/focus_manager.h" |
35 #include "ui/views/ime/mock_input_method.h" | 34 #include "ui/views/ime/mock_input_method.h" |
36 #include "ui/views/test/test_views_delegate.h" | 35 #include "ui/views/test/test_views_delegate.h" |
37 #include "ui/views/test/views_test_base.h" | 36 #include "ui/views/test/views_test_base.h" |
38 #include "ui/views/views_delegate.h" | 37 #include "ui/views/views_delegate.h" |
39 #include "ui/views/widget/native_widget_private.h" | 38 #include "ui/views/widget/native_widget_private.h" |
40 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 EXPECT_EQ(0, formats); | 855 EXPECT_EQ(0, formats); |
857 EXPECT_TRUE(custom_formats.empty()); | 856 EXPECT_TRUE(custom_formats.empty()); |
858 EXPECT_FALSE(textfield_view_->CanDrop(data)); | 857 EXPECT_FALSE(textfield_view_->CanDrop(data)); |
859 textfield_->SetReadOnly(false); | 858 textfield_->SetReadOnly(false); |
860 | 859 |
861 // Ensure that enabled and editable textfields do accept drops. | 860 // Ensure that enabled and editable textfields do accept drops. |
862 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 861 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); |
863 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 862 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
864 EXPECT_TRUE(custom_formats.empty()); | 863 EXPECT_TRUE(custom_formats.empty()); |
865 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 864 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
866 DropTargetEvent drop(data, GetCursorPositionX(6), 0, | 865 gfx::Point drop_point(GetCursorPositionX(6), 0); |
| 866 ui::DropTargetEvent drop(data, drop_point, drop_point, |
867 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); | 867 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE); |
868 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, | 868 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_MOVE, |
869 textfield_view_->OnDragUpdated(drop)); | 869 textfield_view_->OnDragUpdated(drop)); |
870 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop)); | 870 EXPECT_EQ(ui::DragDropTypes::DRAG_COPY, textfield_view_->OnPerformDrop(drop)); |
871 EXPECT_STR_EQ("hello string world", textfield_->text()); | 871 EXPECT_STR_EQ("hello string world", textfield_->text()); |
872 | 872 |
873 // Ensure that textfields do not accept non-OSExchangeData::STRING types. | 873 // Ensure that textfields do not accept non-OSExchangeData::STRING types. |
874 ui::OSExchangeData bad_data; | 874 ui::OSExchangeData bad_data; |
875 bad_data.SetFilename(FilePath(FILE_PATH_LITERAL("x"))); | 875 bad_data.SetFilename(FilePath(FILE_PATH_LITERAL("x"))); |
876 #if defined(OS_WIN) | 876 #if defined(OS_WIN) |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 957 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
958 EXPECT_TRUE(data.GetString(&string)); | 958 EXPECT_TRUE(data.GetString(&string)); |
959 EXPECT_EQ(textfield_->GetSelectedText(), string); | 959 EXPECT_EQ(textfield_->GetSelectedText(), string); |
960 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 960 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); |
961 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 961 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
962 EXPECT_TRUE(custom_formats.empty()); | 962 EXPECT_TRUE(custom_formats.empty()); |
963 | 963 |
964 // Drop "ello" after "w". | 964 // Drop "ello" after "w". |
965 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); | 965 const gfx::Point kDropPoint(GetCursorPositionX(7), 0); |
966 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 966 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
967 DropTargetEvent drop_a(data, kDropPoint.x(), 0, operations); | 967 ui::DropTargetEvent drop_a(data, kDropPoint, kDropPoint, operations); |
968 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 968 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, |
969 textfield_view_->OnDragUpdated(drop_a)); | 969 textfield_view_->OnDragUpdated(drop_a)); |
970 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 970 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, |
971 textfield_view_->OnPerformDrop(drop_a)); | 971 textfield_view_->OnPerformDrop(drop_a)); |
972 EXPECT_STR_EQ("h welloorld", textfield_->text()); | 972 EXPECT_STR_EQ("h welloorld", textfield_->text()); |
973 textfield_view_->OnDragDone(); | 973 textfield_view_->OnDragDone(); |
974 | 974 |
975 // Undo/Redo the drag&drop change. | 975 // Undo/Redo the drag&drop change. |
976 SendKeyEvent(ui::VKEY_Z, false, true); | 976 SendKeyEvent(ui::VKEY_Z, false, true); |
977 EXPECT_STR_EQ("hello world", textfield_->text()); | 977 EXPECT_STR_EQ("hello world", textfield_->text()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 operations); | 1011 operations); |
1012 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); | 1012 textfield_view_->WriteDragDataForView(NULL, click_a.location(), &data); |
1013 EXPECT_TRUE(data.GetString(&string)); | 1013 EXPECT_TRUE(data.GetString(&string)); |
1014 EXPECT_EQ(textfield_->GetSelectedText(), string); | 1014 EXPECT_EQ(textfield_->GetSelectedText(), string); |
1015 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); | 1015 EXPECT_TRUE(textfield_view_->GetDropFormats(&formats, &custom_formats)); |
1016 EXPECT_EQ(ui::OSExchangeData::STRING, formats); | 1016 EXPECT_EQ(ui::OSExchangeData::STRING, formats); |
1017 EXPECT_TRUE(custom_formats.empty()); | 1017 EXPECT_TRUE(custom_formats.empty()); |
1018 | 1018 |
1019 // Drop " worl" after "h". | 1019 // Drop " worl" after "h". |
1020 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1020 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
1021 DropTargetEvent drop_a(data, GetCursorPositionX(1), 0, operations); | 1021 gfx::Point drop_point(GetCursorPositionX(1), 0); |
| 1022 ui::DropTargetEvent drop_a(data, drop_point, drop_point, operations); |
1022 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 1023 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, |
1023 textfield_view_->OnDragUpdated(drop_a)); | 1024 textfield_view_->OnDragUpdated(drop_a)); |
1024 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, | 1025 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, |
1025 textfield_view_->OnPerformDrop(drop_a)); | 1026 textfield_view_->OnPerformDrop(drop_a)); |
1026 EXPECT_STR_EQ("h worlellod", textfield_->text()); | 1027 EXPECT_STR_EQ("h worlellod", textfield_->text()); |
1027 textfield_view_->OnDragDone(); | 1028 textfield_view_->OnDragDone(); |
1028 | 1029 |
1029 // Undo/Redo the drag&drop change. | 1030 // Undo/Redo the drag&drop change. |
1030 SendKeyEvent(ui::VKEY_Z, false, true); | 1031 SendKeyEvent(ui::VKEY_Z, false, true); |
1031 EXPECT_STR_EQ("hello world", textfield_->text()); | 1032 EXPECT_STR_EQ("hello world", textfield_->text()); |
(...skipping 16 matching lines...) Expand all Loading... |
1048 // Start dragging "worl". | 1049 // Start dragging "worl". |
1049 textfield_->SelectRange(ui::Range(6, 10)); | 1050 textfield_->SelectRange(ui::Range(6, 10)); |
1050 gfx::Point point(GetCursorPositionX(8), 0); | 1051 gfx::Point point(GetCursorPositionX(8), 0); |
1051 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, | 1052 ui::MouseEvent click(ui::ET_MOUSE_PRESSED, point, point, |
1052 ui::EF_LEFT_MOUSE_BUTTON); | 1053 ui::EF_LEFT_MOUSE_BUTTON); |
1053 textfield_view_->OnMousePressed(click); | 1054 textfield_view_->OnMousePressed(click); |
1054 ui::OSExchangeData data; | 1055 ui::OSExchangeData data; |
1055 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); | 1056 textfield_view_->WriteDragDataForView(NULL, click.location(), &data); |
1056 EXPECT_TRUE(textfield_view_->CanDrop(data)); | 1057 EXPECT_TRUE(textfield_view_->CanDrop(data)); |
1057 // Drag the text over somewhere valid, outside the current selection. | 1058 // Drag the text over somewhere valid, outside the current selection. |
1058 DropTargetEvent drop(data, GetCursorPositionX(2), 0, | 1059 gfx::Point drop_point(GetCursorPositionX(2), 0); |
1059 ui::DragDropTypes::DRAG_MOVE); | 1060 ui::DropTargetEvent drop(data, drop_point, drop_point, |
| 1061 ui::DragDropTypes::DRAG_MOVE); |
1060 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); | 1062 EXPECT_EQ(ui::DragDropTypes::DRAG_MOVE, textfield_view_->OnDragUpdated(drop)); |
1061 // "Cancel" the drag, via move and release over the selection, and OnDragDone. | 1063 // "Cancel" the drag, via move and release over the selection, and OnDragDone. |
1062 gfx::Point drag_point(GetCursorPositionX(9), 0); | 1064 gfx::Point drag_point(GetCursorPositionX(9), 0); |
1063 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, | 1065 ui::MouseEvent drag(ui::ET_MOUSE_DRAGGED, drag_point, drag_point, |
1064 ui::EF_LEFT_MOUSE_BUTTON); | 1066 ui::EF_LEFT_MOUSE_BUTTON); |
1065 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, | 1067 ui::MouseEvent release(ui::ET_MOUSE_RELEASED, drag_point, drag_point, |
1066 ui::EF_LEFT_MOUSE_BUTTON); | 1068 ui::EF_LEFT_MOUSE_BUTTON); |
1067 textfield_view_->OnMouseDragged(drag); | 1069 textfield_view_->OnMouseDragged(drag); |
1068 textfield_view_->OnMouseReleased(release); | 1070 textfield_view_->OnMouseReleased(release); |
1069 textfield_view_->OnDragDone(); | 1071 textfield_view_->OnDragDone(); |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1676 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; | 1678 EXPECT_EQ(char_rect[i], actual_rect) << " i=" << i; |
1677 } | 1679 } |
1678 | 1680 |
1679 // Return false if the index is out of range. | 1681 // Return false if the index is out of range. |
1680 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); | 1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count, &rect)); |
1681 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); | 1683 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 1, &rect)); |
1682 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); | 1684 EXPECT_FALSE(client->GetCompositionCharacterBounds(char_count + 100, &rect)); |
1683 } | 1685 } |
1684 | 1686 |
1685 } // namespace views | 1687 } // namespace views |
OLD | NEW |