OLD | NEW |
---|---|
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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, |
11 // we queue up all the mouse move and mouse up events. When the test tries to | 11 // we queue up all the mouse move and mouse up events. When the test tries to |
12 // start a drag (by calling EvenSendingController::DoDragDrop), we take the | 12 // start a drag (by calling EvenSendingController::DoDragDrop), we take the |
13 // events in the queue and replay them. | 13 // events in the queue and replay them. |
14 // The behavior of queuing events and replaying them can be disabled by a | 14 // The behavior of queuing events and replaying them can be disabled by a |
15 // layout test by setting eventSender.dragMode to false. | 15 // layout test by setting eventSender.dragMode to false. |
16 | 16 |
17 // TODO(darin): This is very wrong. We should not be including WebCore headers | 17 // TODO(darin): This is very wrong. We should not be including WebCore headers |
18 // directly like this!! | 18 // directly like this!! |
19 #include "config.h" | 19 #include "config.h" |
20 #include "KeyboardCodes.h" | 20 #include "KeyboardCodes.h" |
21 | 21 |
22 #undef LOG | 22 #undef LOG |
23 | 23 |
24 #include "webkit/tools/test_shell/event_sending_controller.h" | 24 #include "webkit/tools/test_shell/event_sending_controller.h" |
25 | 25 |
26 #include <queue> | 26 #include <queue> |
27 | 27 |
28 #include "base/compiler_specific.h" | 28 #include "base/compiler_specific.h" |
29 #include "base/file_path.h" | |
30 #include "base/file_util.h" | |
29 #include "base/logging.h" | 31 #include "base/logging.h" |
30 #include "base/message_loop.h" | 32 #include "base/message_loop.h" |
31 #include "base/string_util.h" | 33 #include "base/string_util.h" |
32 #include "base/time.h" | 34 #include "base/time.h" |
33 #include "webkit/api/public/WebDragData.h" | 35 #include "webkit/api/public/WebDragData.h" |
34 #include "webkit/api/public/WebPoint.h" | 36 #include "webkit/api/public/WebPoint.h" |
37 #include "webkit/api/public/WebString.h" | |
38 #include "webkit/glue/webkit_glue.h" | |
35 #include "webkit/glue/webview.h" | 39 #include "webkit/glue/webview.h" |
36 #include "webkit/tools/test_shell/test_shell.h" | 40 #include "webkit/tools/test_shell/test_shell.h" |
37 | 41 |
38 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
39 #include "webkit/api/public/win/WebInputEventFactory.h" | 43 #include "webkit/api/public/win/WebInputEventFactory.h" |
40 using WebKit::WebInputEventFactory; | 44 using WebKit::WebInputEventFactory; |
41 #endif | 45 #endif |
42 | 46 |
43 // TODO(mpcomplete): layout before each event? | 47 // TODO(mpcomplete): layout before each event? |
44 // TODO(mpcomplete): do we need modifiers for mouse events? | 48 // TODO(mpcomplete): do we need modifiers for mouse events? |
45 | 49 |
46 using base::Time; | 50 using base::Time; |
47 using base::TimeTicks; | 51 using base::TimeTicks; |
48 | 52 |
49 using WebKit::WebDragData; | 53 using WebKit::WebDragData; |
50 using WebKit::WebInputEvent; | 54 using WebKit::WebInputEvent; |
51 using WebKit::WebKeyboardEvent; | 55 using WebKit::WebKeyboardEvent; |
52 using WebKit::WebMouseEvent; | 56 using WebKit::WebMouseEvent; |
53 using WebKit::WebPoint; | 57 using WebKit::WebPoint; |
58 using WebKit::WebString; | |
54 | 59 |
55 TestShell* EventSendingController::shell_ = NULL; | 60 TestShell* EventSendingController::shell_ = NULL; |
56 gfx::Point EventSendingController::last_mouse_pos_; | 61 gfx::Point EventSendingController::last_mouse_pos_; |
57 WebMouseEvent::Button EventSendingController::pressed_button_ = | 62 WebMouseEvent::Button EventSendingController::pressed_button_ = |
58 WebMouseEvent::ButtonNone; | 63 WebMouseEvent::ButtonNone; |
59 | 64 |
60 int EventSendingController::last_button_number_ = -1; | 65 int EventSendingController::last_button_number_ = -1; |
61 | 66 |
62 namespace { | 67 namespace { |
63 | 68 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 &EventSendingController::enableDOMUIEventLogging); | 166 &EventSendingController::enableDOMUIEventLogging); |
162 BindMethod("fireKeyboardEventsToElement", | 167 BindMethod("fireKeyboardEventsToElement", |
163 &EventSendingController::fireKeyboardEventsToElement); | 168 &EventSendingController::fireKeyboardEventsToElement); |
164 BindMethod("clearKillRing", &EventSendingController::clearKillRing); | 169 BindMethod("clearKillRing", &EventSendingController::clearKillRing); |
165 BindMethod("textZoomIn", &EventSendingController::textZoomIn); | 170 BindMethod("textZoomIn", &EventSendingController::textZoomIn); |
166 BindMethod("textZoomOut", &EventSendingController::textZoomOut); | 171 BindMethod("textZoomOut", &EventSendingController::textZoomOut); |
167 BindMethod("zoomPageIn", &EventSendingController::zoomPageIn); | 172 BindMethod("zoomPageIn", &EventSendingController::zoomPageIn); |
168 BindMethod("zoomPageOut", &EventSendingController::zoomPageOut); | 173 BindMethod("zoomPageOut", &EventSendingController::zoomPageOut); |
169 BindMethod("scheduleAsynchronousClick", | 174 BindMethod("scheduleAsynchronousClick", |
170 &EventSendingController::scheduleAsynchronousClick); | 175 &EventSendingController::scheduleAsynchronousClick); |
176 BindMethod("beginDragWithFiles", | |
177 &EventSendingController::beginDragWithFiles); | |
171 | 178 |
172 // When set to true (the default value), we batch mouse move and mouse up | 179 // When set to true (the default value), we batch mouse move and mouse up |
173 // events so we can simulate drag & drop. | 180 // events so we can simulate drag & drop. |
174 BindProperty("dragMode", &dragMode); | 181 BindProperty("dragMode", &dragMode); |
175 #if defined(OS_WIN) | 182 #if defined(OS_WIN) |
176 BindProperty("WM_KEYDOWN", &wmKeyDown); | 183 BindProperty("WM_KEYDOWN", &wmKeyDown); |
177 BindProperty("WM_KEYUP", &wmKeyUp); | 184 BindProperty("WM_KEYUP", &wmKeyUp); |
178 BindProperty("WM_CHAR", &wmChar); | 185 BindProperty("WM_CHAR", &wmChar); |
179 BindProperty("WM_DEADCHAR", &wmDeadChar); | 186 BindProperty("WM_DEADCHAR", &wmDeadChar); |
180 BindProperty("WM_SYSKEYDOWN", &wmSysKeyDown); | 187 BindProperty("WM_SYSKEYDOWN", &wmSysKeyDown); |
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
590 result->SetNull(); | 597 result->SetNull(); |
591 | 598 |
592 MessageLoop::current()->PostTask(FROM_HERE, | 599 MessageLoop::current()->PostTask(FROM_HERE, |
593 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, | 600 method_factory_.NewRunnableMethod(&EventSendingController::mouseDown, |
594 args, static_cast<CppVariant*>(NULL))); | 601 args, static_cast<CppVariant*>(NULL))); |
595 MessageLoop::current()->PostTask(FROM_HERE, | 602 MessageLoop::current()->PostTask(FROM_HERE, |
596 method_factory_.NewRunnableMethod(&EventSendingController::mouseUp, | 603 method_factory_.NewRunnableMethod(&EventSendingController::mouseUp, |
597 args, static_cast<CppVariant*>(NULL))); | 604 args, static_cast<CppVariant*>(NULL))); |
598 } | 605 } |
599 | 606 |
607 void EventSendingController::beginDragWithFiles( | |
608 const CppArgumentList& args, CppVariant* result) { | |
609 result->SetNull(); | |
dglazkov
2009/09/03 02:51:40
I would put this at the end --not that it matters.
| |
610 | |
611 current_drag_data.initialize(); | |
612 std::vector<std::wstring> files = args[0].ToStringVector(); | |
613 for (size_t i = 0; i < files.size(); ++i) { | |
614 FilePath file_path = FilePath::FromWStringHack(files[i]); | |
615 file_util::AbsolutePath(&file_path); | |
616 current_drag_data.appendToFileNames( | |
617 webkit_glue::FilePathStringToWebString(file_path.value())); | |
618 } | |
619 | |
620 // Provide a drag source. | |
621 WebPoint client_point(last_mouse_pos_.x(), last_mouse_pos_.y()); | |
622 WebPoint screen_point(last_mouse_pos_.x(), last_mouse_pos_.y()); | |
623 webview()->DragTargetDragEnter(current_drag_data, 0, | |
624 client_point, screen_point); | |
625 | |
626 // dragMode saves events and then replays them later. We don't need/want that. | |
627 dragMode.Set(false); | |
628 | |
629 // Make the rest of eventSender think a drag is in progress. | |
630 pressed_button_ = WebMouseEvent::ButtonLeft; | |
631 } | |
632 | |
600 // | 633 // |
601 // Unimplemented stubs | 634 // Unimplemented stubs |
602 // | 635 // |
603 | 636 |
604 void EventSendingController::enableDOMUIEventLogging( | 637 void EventSendingController::enableDOMUIEventLogging( |
605 const CppArgumentList& args, CppVariant* result) { | 638 const CppArgumentList& args, CppVariant* result) { |
606 result->SetNull(); | 639 result->SetNull(); |
607 } | 640 } |
608 | 641 |
609 void EventSendingController::fireKeyboardEventsToElement( | 642 void EventSendingController::fireKeyboardEventsToElement( |
610 const CppArgumentList& args, CppVariant* result) { | 643 const CppArgumentList& args, CppVariant* result) { |
611 result->SetNull(); | 644 result->SetNull(); |
612 } | 645 } |
613 | 646 |
614 void EventSendingController::clearKillRing( | 647 void EventSendingController::clearKillRing( |
615 const CppArgumentList& args, CppVariant* result) { | 648 const CppArgumentList& args, CppVariant* result) { |
616 result->SetNull(); | 649 result->SetNull(); |
617 } | 650 } |
OLD | NEW |