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 "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 using blink::WebString; | 42 using blink::WebString; |
43 using blink::WebTouchEvent; | 43 using blink::WebTouchEvent; |
44 using blink::WebTouchPoint; | 44 using blink::WebTouchPoint; |
45 using blink::WebVector; | 45 using blink::WebVector; |
46 using blink::WebView; | 46 using blink::WebView; |
47 | 47 |
48 namespace test_runner { | 48 namespace test_runner { |
49 | 49 |
50 namespace { | 50 namespace { |
51 | 51 |
| 52 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
| 53 switch (button_code) { |
| 54 case -1: |
| 55 return WebMouseEvent::ButtonNone; |
| 56 case 0: |
| 57 return WebMouseEvent::ButtonLeft; |
| 58 case 1: |
| 59 return WebMouseEvent::ButtonMiddle; |
| 60 case 2: |
| 61 return WebMouseEvent::ButtonRight; |
| 62 } |
| 63 NOTREACHED(); |
| 64 return WebMouseEvent::ButtonNone; |
| 65 } |
| 66 |
| 67 int GetWebMouseEventModifierForButton(WebMouseEvent::Button button) { |
| 68 switch (button) { |
| 69 case WebMouseEvent::ButtonNone: |
| 70 return 0; |
| 71 case WebMouseEvent::ButtonLeft: |
| 72 return WebMouseEvent::LeftButtonDown; |
| 73 case WebMouseEvent::ButtonMiddle: |
| 74 return WebMouseEvent::MiddleButtonDown; |
| 75 case WebMouseEvent::ButtonRight: |
| 76 return WebMouseEvent::RightButtonDown; |
| 77 } |
| 78 NOTREACHED(); |
| 79 return 0; |
| 80 } |
| 81 |
52 void InitMouseEvent(WebInputEvent::Type t, | 82 void InitMouseEvent(WebInputEvent::Type t, |
53 WebMouseEvent::Button b, | 83 WebMouseEvent::Button b, |
54 const WebPoint& pos, | 84 const WebPoint& pos, |
55 double time_stamp, | 85 double time_stamp, |
56 int click_count, | 86 int click_count, |
57 int modifiers, | 87 int modifiers, |
58 WebMouseEvent* e) { | 88 WebMouseEvent* e) { |
59 e->type = t; | 89 e->type = t; |
60 e->button = b; | 90 e->button = b; |
61 e->modifiers = modifiers; | 91 e->modifiers = modifiers | GetWebMouseEventModifierForButton(b); |
62 e->x = pos.x; | 92 e->x = pos.x; |
63 e->y = pos.y; | 93 e->y = pos.y; |
64 e->globalX = pos.x; | 94 e->globalX = pos.x; |
65 e->globalY = pos.y; | 95 e->globalY = pos.y; |
66 e->timeStampSeconds = time_stamp; | 96 e->timeStampSeconds = time_stamp; |
67 e->clickCount = click_count; | 97 e->clickCount = click_count; |
68 } | 98 } |
69 | 99 |
70 int GetKeyModifier(const std::string& modifier_name) { | 100 int GetKeyModifier(const std::string& modifier_name) { |
71 const char* characters = modifier_name.c_str(); | 101 const char* characters = modifier_name.c_str(); |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 } | 280 } |
251 } | 281 } |
252 | 282 |
253 return strings; | 283 return strings; |
254 } | 284 } |
255 | 285 |
256 // How much we should scroll per event - the value here is chosen to match the | 286 // How much we should scroll per event - the value here is chosen to match the |
257 // WebKit impl and layout test results. | 287 // WebKit impl and layout test results. |
258 const float kScrollbarPixelsPerTick = 40.0f; | 288 const float kScrollbarPixelsPerTick = 40.0f; |
259 | 289 |
260 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | |
261 if (!button_code) | |
262 return WebMouseEvent::ButtonLeft; | |
263 if (button_code == 2) | |
264 return WebMouseEvent::ButtonRight; | |
265 return WebMouseEvent::ButtonMiddle; | |
266 } | |
267 | |
268 class MouseDownTask : public WebMethodTask<EventSender> { | 290 class MouseDownTask : public WebMethodTask<EventSender> { |
269 public: | 291 public: |
270 MouseDownTask(EventSender* obj, int button_number, int modifiers) | 292 MouseDownTask(EventSender* obj, int button_number, int modifiers) |
271 : WebMethodTask<EventSender>(obj), | 293 : WebMethodTask<EventSender>(obj), |
272 button_number_(button_number), | 294 button_number_(button_number), |
273 modifiers_(modifiers) {} | 295 modifiers_(modifiers) {} |
274 | 296 |
275 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); } | 297 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); } |
276 | 298 |
277 private: | 299 private: |
(...skipping 2243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2521 last_event_timestamp_ = event.timeStampSeconds; | 2543 last_event_timestamp_ = event.timeStampSeconds; |
2522 | 2544 |
2523 if (WebPagePopup* popup = view_->pagePopup()) { | 2545 if (WebPagePopup* popup = view_->pagePopup()) { |
2524 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2546 if (!WebInputEvent::isKeyboardEventType(event.type)) |
2525 return popup->handleInputEvent(event); | 2547 return popup->handleInputEvent(event); |
2526 } | 2548 } |
2527 return view_->handleInputEvent(event); | 2549 return view_->handleInputEvent(event); |
2528 } | 2550 } |
2529 | 2551 |
2530 } // namespace test_runner | 2552 } // namespace test_runner |
OLD | NEW |