| 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, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "webkit/tools/test_shell/test_shell.h" | 28 #include "webkit/tools/test_shell/test_shell.h" |
| 29 | 29 |
| 30 // TODO(mpcomplete): layout before each event? | 30 // TODO(mpcomplete): layout before each event? |
| 31 // TODO(mpcomplete): do we need modifiers for mouse events? | 31 // TODO(mpcomplete): do we need modifiers for mouse events? |
| 32 | 32 |
| 33 TestShell* EventSendingController::shell_ = NULL; | 33 TestShell* EventSendingController::shell_ = NULL; |
| 34 gfx::Point EventSendingController::last_mouse_pos_; | 34 gfx::Point EventSendingController::last_mouse_pos_; |
| 35 WebMouseEvent::Button EventSendingController::pressed_button_ = | 35 WebMouseEvent::Button EventSendingController::pressed_button_ = |
| 36 WebMouseEvent::BUTTON_NONE; | 36 WebMouseEvent::BUTTON_NONE; |
| 37 | 37 |
| 38 int EventSendingController::last_button_number_ = -1; |
| 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 41 static scoped_refptr<IDataObject> drag_data_object; | 43 static scoped_refptr<IDataObject> drag_data_object; |
| 42 #elif defined(OS_MACOSX) | 44 #elif defined(OS_MACOSX) |
| 43 // Throughout this file, drag support is #ifdef-ed out. TODO(port): Add it in | 45 // Throughout this file, drag support is #ifdef-ed out. TODO(port): Add it in |
| 44 // for the Mac. | 46 // for the Mac. |
| 45 #endif | 47 #endif |
| 46 static bool replaying_saved_events = false; | 48 static bool replaying_saved_events = false; |
| 47 static std::queue<WebMouseEvent> mouse_event_queue; | 49 static std::queue<WebMouseEvent> mouse_event_queue; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 void EventSendingController::Reset() { | 144 void EventSendingController::Reset() { |
| 143 // The test should have finished a drag and the mouse button state. | 145 // The test should have finished a drag and the mouse button state. |
| 144 #if defined(OS_WIN) | 146 #if defined(OS_WIN) |
| 145 DCHECK(!drag_data_object); | 147 DCHECK(!drag_data_object); |
| 146 drag_data_object = NULL; | 148 drag_data_object = NULL; |
| 147 #endif | 149 #endif |
| 148 pressed_button_ = WebMouseEvent::BUTTON_NONE; | 150 pressed_button_ = WebMouseEvent::BUTTON_NONE; |
| 149 dragMode.Set(true); | 151 dragMode.Set(true); |
| 150 last_click_time_sec = 0; | 152 last_click_time_sec = 0; |
| 151 click_count = 0; | 153 click_count = 0; |
| 154 last_button_number_ = -1; |
| 152 } | 155 } |
| 153 | 156 |
| 154 /* static */ WebView* EventSendingController::webview() { | 157 /* static */ WebView* EventSendingController::webview() { |
| 155 return shell_->webView(); | 158 return shell_->webView(); |
| 156 } | 159 } |
| 157 | 160 |
| 158 #if defined(OS_WIN) | 161 #if defined(OS_WIN) |
| 159 /* static */ void EventSendingController::DoDragDrop(IDataObject* data_obj) { | 162 /* static */ void EventSendingController::DoDragDrop(IDataObject* data_obj) { |
| 160 drag_data_object = data_obj; | 163 drag_data_object = data_obj; |
| 161 | 164 |
| 162 DWORD effect = 0; | 165 DWORD effect = 0; |
| 163 POINTL screen_ptl = {0, 0}; | 166 POINTL screen_ptl = {0, 0}; |
| 164 TestWebViewDelegate* delegate = shell_->delegate(); | 167 TestWebViewDelegate* delegate = shell_->delegate(); |
| 165 delegate->drop_delegate()->DragEnter(drag_data_object, MK_LBUTTON, | 168 delegate->drop_delegate()->DragEnter(drag_data_object, MK_LBUTTON, |
| 166 screen_ptl, &effect); | 169 screen_ptl, &effect); |
| 167 | 170 |
| 168 // Finish processing events. | 171 // Finish processing events. |
| 169 ReplaySavedEvents(); | 172 ReplaySavedEvents(); |
| 170 } | 173 } |
| 171 #endif | 174 #endif |
| 172 | 175 |
| 173 // static | 176 WebMouseEvent::Button EventSendingController::GetButtonTypeFromButtonNumber( |
| 174 WebMouseEvent::Button EventSendingController::GetButtonTypeFromSingleArg( | 177 int button_code) { |
| 175 const CppArgumentList& args) { | 178 if (button_code == 0) |
| 176 if (args.size() > 0 && args[0].isNumber()) { | 179 return WebMouseEvent::BUTTON_LEFT; |
| 177 int button_code = args[0].ToInt32(); | 180 else if (button_code == 2) |
| 178 if (button_code == 1) | 181 return WebMouseEvent::BUTTON_RIGHT; |
| 179 return WebMouseEvent::BUTTON_MIDDLE; | 182 |
| 180 else if (button_code == 2) | 183 return WebMouseEvent::BUTTON_MIDDLE; |
| 181 return WebMouseEvent::BUTTON_RIGHT; | |
| 182 } | |
| 183 return WebMouseEvent::BUTTON_LEFT; | |
| 184 } | 184 } |
| 185 | 185 |
| 186 // static |
| 187 int EventSendingController::GetButtonNumberFromSingleArg( |
| 188 const CppArgumentList& args) { |
| 189 int button_code = 0; |
| 190 |
| 191 if (args.size() > 0 && args[0].isNumber()) { |
| 192 button_code = args[0].ToInt32(); |
| 193 } |
| 194 |
| 195 return button_code; |
| 196 } |
| 186 // | 197 // |
| 187 // Implemented javascript methods. | 198 // Implemented javascript methods. |
| 188 // | 199 // |
| 189 | 200 |
| 190 void EventSendingController::mouseDown( | 201 void EventSendingController::mouseDown( |
| 191 const CppArgumentList& args, CppVariant* result) { | 202 const CppArgumentList& args, CppVariant* result) { |
| 192 result->SetNull(); | 203 result->SetNull(); |
| 193 | 204 |
| 194 webview()->Layout(); | 205 webview()->Layout(); |
| 195 | 206 |
| 196 WebMouseEvent::Button button_type = GetButtonTypeFromSingleArg(args); | 207 int button_number = GetButtonNumberFromSingleArg(args); |
| 208 DCHECK(button_number != -1); |
| 197 | 209 |
| 198 if ((GetCurrentEventTimeSec() - last_click_time_sec >= kMultiClickTimeSec) || | 210 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( |
| 199 outside_multiclick_radius(last_mouse_pos_, last_click_pos)) { | 211 button_number); |
| 212 |
| 213 if ((GetCurrentEventTimeSec() - last_click_time_sec < kMultiClickTimeSec) && |
| 214 (!outside_multiclick_radius(last_mouse_pos_, last_click_pos)) && |
| 215 (button_number == last_button_number_)) { |
| 216 ++click_count; |
| 217 } else { |
| 200 click_count = 1; | 218 click_count = 1; |
| 201 } else { | |
| 202 ++click_count; | |
| 203 } | 219 } |
| 204 | 220 |
| 221 last_button_number_ = button_number; |
| 222 |
| 205 WebMouseEvent event; | 223 WebMouseEvent event; |
| 206 pressed_button_ = button_type; | 224 pressed_button_ = button_type; |
| 207 InitMouseEvent(WebInputEvent::MOUSE_DOWN, button_type, | 225 InitMouseEvent(WebInputEvent::MOUSE_DOWN, button_type, |
| 208 last_mouse_pos_, &event); | 226 last_mouse_pos_, &event); |
| 209 webview()->HandleInputEvent(&event); | 227 webview()->HandleInputEvent(&event); |
| 210 } | 228 } |
| 211 | 229 |
| 212 void EventSendingController::mouseUp( | 230 void EventSendingController::mouseUp( |
| 213 const CppArgumentList& args, CppVariant* result) { | 231 const CppArgumentList& args, CppVariant* result) { |
| 214 result->SetNull(); | 232 result->SetNull(); |
| 215 | 233 |
| 216 webview()->Layout(); | 234 webview()->Layout(); |
| 217 | 235 |
| 218 WebMouseEvent::Button button_type = GetButtonTypeFromSingleArg(args); | 236 int button_number = GetButtonNumberFromSingleArg(args); |
| 237 DCHECK(button_number != -1); |
| 238 |
| 239 WebMouseEvent::Button button_type = GetButtonTypeFromButtonNumber( |
| 240 button_number); |
| 241 |
| 242 last_button_number_ = button_number; |
| 219 | 243 |
| 220 WebMouseEvent event; | 244 WebMouseEvent event; |
| 221 InitMouseEvent(WebInputEvent::MOUSE_UP, button_type, | 245 InitMouseEvent(WebInputEvent::MOUSE_UP, button_type, |
| 222 last_mouse_pos_, &event); | 246 last_mouse_pos_, &event); |
| 223 if (drag_mode() && !replaying_saved_events) { | 247 if (drag_mode() && !replaying_saved_events) { |
| 224 mouse_event_queue.push(event); | 248 mouse_event_queue.push(event); |
| 225 ReplaySavedEvents(); | 249 ReplaySavedEvents(); |
| 226 } else { | 250 } else { |
| 227 DoMouseUp(event); | 251 DoMouseUp(event); |
| 228 } | 252 } |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 void EventSendingController::fireKeyboardEventsToElement( | 566 void EventSendingController::fireKeyboardEventsToElement( |
| 543 const CppArgumentList& args, CppVariant* result) { | 567 const CppArgumentList& args, CppVariant* result) { |
| 544 result->SetNull(); | 568 result->SetNull(); |
| 545 } | 569 } |
| 546 | 570 |
| 547 void EventSendingController::clearKillRing( | 571 void EventSendingController::clearKillRing( |
| 548 const CppArgumentList& args, CppVariant* result) { | 572 const CppArgumentList& args, CppVariant* result) { |
| 549 result->SetNull(); | 573 result->SetNull(); |
| 550 } | 574 } |
| 551 | 575 |
| OLD | NEW |