OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // This file contains the definition for EventSendingController. | 5 // This file contains the definition for EventSendingController. |
6 // | 6 // |
7 // Some notes about drag and drop handling: | 7 // Some notes about drag and drop handling: |
8 // Windows drag and drop goes through a system call to DoDragDrop. At that | 8 // Windows drag and drop goes through a system call to DoDragDrop. At that |
9 // point, program control is given to Windows which then periodically makes | 9 // point, program control is given to Windows which then periodically makes |
10 // callbacks into the webview. This won't work for layout tests, so instead, | 10 // callbacks into the webview. This won't work for layout tests, so instead, |
(...skipping 17 matching lines...) Expand all Loading... | |
28 #include "base/time.h" | 28 #include "base/time.h" |
29 #include "base/string_number_conversions.h" | 29 #include "base/string_number_conversions.h" |
30 #include "base/string_util.h" | 30 #include "base/string_util.h" |
31 #include "base/utf_string_conversions.h" | 31 #include "base/utf_string_conversions.h" |
32 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" | 32 #include "third_party/WebKit/WebKit/chromium/public/WebDragData.h" |
33 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" | 33 #include "third_party/WebKit/WebKit/chromium/public/WebDragOperation.h" |
34 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" | 34 #include "third_party/WebKit/WebKit/chromium/public/WebPoint.h" |
35 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | 35 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" |
36 #include "third_party/WebKit/WebKit/chromium/public/WebTouchPoint.h" | 36 #include "third_party/WebKit/WebKit/chromium/public/WebTouchPoint.h" |
37 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" | 37 #include "third_party/WebKit/WebKit/chromium/public/WebView.h" |
38 #include "third_party/WebKit/WebKit/chromium/public/WebBindings.h" | |
38 #include "webkit/glue/webkit_glue.h" | 39 #include "webkit/glue/webkit_glue.h" |
39 #include "webkit/tools/test_shell/test_shell.h" | 40 #include "webkit/tools/test_shell/test_shell.h" |
40 #include "webkit/tools/test_shell/test_webview_delegate.h" | 41 #include "webkit/tools/test_shell/test_webview_delegate.h" |
41 | 42 |
42 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
43 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" | 44 #include "third_party/WebKit/WebKit/chromium/public/win/WebInputEventFactory.h" |
44 using WebKit::WebInputEventFactory; | 45 using WebKit::WebInputEventFactory; |
45 #endif | 46 #endif |
46 | 47 |
47 // TODO(mpcomplete): layout before each event? | 48 // TODO(mpcomplete): layout before each event? |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 break; | 764 break; |
764 } | 765 } |
765 default: | 766 default: |
766 NOTREACHED(); | 767 NOTREACHED(); |
767 } | 768 } |
768 } | 769 } |
769 | 770 |
770 replaying_saved_events = false; | 771 replaying_saved_events = false; |
771 } | 772 } |
772 | 773 |
774 // Because actual context menu is implemented by the browser side, | |
775 // this function does only what LayoutTests are expecting: | |
776 // - Many test checks the count of items. So returning non-zero value | |
777 // makes sense. | |
778 // - Some test compares the count before and after some action. So | |
779 // changing the count based on flags also makes sense. This function | |
780 // is doing such for some flags. | |
781 // - Some test even checks actual string content. So providing it | |
782 // would be also helpful. | |
783 static std::vector<WebString> | |
784 MakeMenuItemStringsFor(const WebKit::WebContextMenuData* context_menu, | |
785 MockSpellCheck* spellcheck) | |
786 { | |
tkent
2010/11/18 01:38:47
"{" should be put at the last of the previous line
gmorrita
2010/11/18 03:33:38
Done.
| |
787 // These constants are based on Safari's context menu because tests | |
788 // are made for it. | |
789 static const char* kNonEditableMenuStrings[] = { | |
790 "Back", "Reload Page", "Open in Dashbaord", "<separator>", "View Source", | |
tkent
2010/11/18 01:38:47
We usually use +4 spaces for line break in an expr
gmorrita
2010/11/18 03:33:38
Done.
| |
791 "Save Page As", "Print Page", "Inspect Element", 0 }; | |
792 static const char* kEditableMenuStrings[] = { | |
793 "Cut", "Copy", "<separator>", "Paste", "Spelling and Grammar", | |
794 "Substitutions, Transformations", "Font", "Speech", "Paragraph Direction", | |
795 "<separator>", 0 }; | |
796 | |
797 // This is possible because mouse events are cancelleable. | |
798 if (!context_menu) | |
799 return std::vector<WebString>(); | |
800 | |
801 std::vector<WebString> strings; | |
802 | |
803 if (context_menu->isEditable) { | |
804 for (const char** item = kEditableMenuStrings; *item; ++item) | |
805 strings.push_back(WebString::fromUTF8(*item)); | |
806 std::vector<string16> suggestions; | |
807 spellcheck->FillSuggestions(context_menu->misspelledWord, &suggestions); | |
808 for (size_t i = 0; i < suggestions.size(); ++i) | |
809 strings.push_back(WebString(suggestions[i])); | |
810 } else { | |
811 for (const char** item = kNonEditableMenuStrings; *item; ++item) | |
812 strings.push_back(WebString::fromUTF8(*item)); | |
813 } | |
814 | |
815 return strings; | |
816 } | |
817 | |
773 void EventSendingController::contextClick( | 818 void EventSendingController::contextClick( |
774 const CppArgumentList& args, CppVariant* result) { | 819 const CppArgumentList& args, CppVariant* result) { |
775 result->SetNull(); | 820 result->SetNull(); |
776 | 821 |
777 webview()->layout(); | 822 webview()->layout(); |
778 | 823 |
824 // Clears last context menu data because we need to know if the | |
825 // context menu be requested after following mouse events. | |
826 shell_->delegate()->ClearContextMenuData(); | |
827 | |
779 UpdateClickCountForButton(WebMouseEvent::ButtonRight); | 828 UpdateClickCountForButton(WebMouseEvent::ButtonRight); |
780 | 829 |
781 // Generate right mouse down and up. | 830 // Generate right mouse down and up. |
782 | 831 |
783 WebMouseEvent event; | 832 WebMouseEvent event; |
784 pressed_button_ = WebMouseEvent::ButtonRight; | 833 pressed_button_ = WebMouseEvent::ButtonRight; |
785 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight, | 834 InitMouseEvent(WebInputEvent::MouseDown, WebMouseEvent::ButtonRight, |
786 last_mouse_pos_, &event); | 835 last_mouse_pos_, &event); |
787 webview()->handleInputEvent(event); | 836 webview()->handleInputEvent(event); |
788 | 837 |
789 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight, | 838 InitMouseEvent(WebInputEvent::MouseUp, WebMouseEvent::ButtonRight, |
790 last_mouse_pos_, &event); | 839 last_mouse_pos_, &event); |
791 webview()->handleInputEvent(event); | 840 webview()->handleInputEvent(event); |
792 | 841 |
793 pressed_button_ = WebMouseEvent::ButtonNone; | 842 pressed_button_ = WebMouseEvent::ButtonNone; |
843 | |
844 result->Set(WebKit::WebBindings::makeStringArray( | |
845 MakeMenuItemStringsFor( | |
846 shell_->delegate()->last_context_menu_data(), | |
847 shell_->delegate()->mock_spellcheck()))); | |
848 | |
794 } | 849 } |
795 | 850 |
796 void EventSendingController::scheduleAsynchronousClick( | 851 void EventSendingController::scheduleAsynchronousClick( |
797 const CppArgumentList& args, CppVariant* result) { | 852 const CppArgumentList& args, CppVariant* result) { |
798 result->SetNull(); | 853 result->SetNull(); |
799 | 854 |
800 MessageLoop::current()->PostTask(FROM_HERE, | 855 MessageLoop::current()->PostTask(FROM_HERE, |
801 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, | 856 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, |
802 args, static_cast<CppVariant*>(NULL))); | 857 args, static_cast<CppVariant*>(NULL))); |
803 MessageLoop::current()->PostTask(FROM_HERE, | 858 MessageLoop::current()->PostTask(FROM_HERE, |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1017 | 1072 |
1018 void EventSendingController::fireKeyboardEventsToElement( | 1073 void EventSendingController::fireKeyboardEventsToElement( |
1019 const CppArgumentList& args, CppVariant* result) { | 1074 const CppArgumentList& args, CppVariant* result) { |
1020 result->SetNull(); | 1075 result->SetNull(); |
1021 } | 1076 } |
1022 | 1077 |
1023 void EventSendingController::clearKillRing( | 1078 void EventSendingController::clearKillRing( |
1024 const CppArgumentList& args, CppVariant* result) { | 1079 const CppArgumentList& args, CppVariant* result) { |
1025 result->SetNull(); | 1080 result->SetNull(); |
1026 } | 1081 } |
OLD | NEW |