| 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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 286 } |
| 257 } | 287 } |
| 258 | 288 |
| 259 return strings; | 289 return strings; |
| 260 } | 290 } |
| 261 | 291 |
| 262 // How much we should scroll per event - the value here is chosen to match the | 292 // How much we should scroll per event - the value here is chosen to match the |
| 263 // WebKit impl and layout test results. | 293 // WebKit impl and layout test results. |
| 264 const float kScrollbarPixelsPerTick = 40.0f; | 294 const float kScrollbarPixelsPerTick = 40.0f; |
| 265 | 295 |
| 266 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | |
| 267 if (!button_code) | |
| 268 return WebMouseEvent::ButtonLeft; | |
| 269 if (button_code == 2) | |
| 270 return WebMouseEvent::ButtonRight; | |
| 271 return WebMouseEvent::ButtonMiddle; | |
| 272 } | |
| 273 | |
| 274 class MouseDownTask : public WebMethodTask<EventSender> { | 296 class MouseDownTask : public WebMethodTask<EventSender> { |
| 275 public: | 297 public: |
| 276 MouseDownTask(EventSender* obj, int button_number, int modifiers) | 298 MouseDownTask(EventSender* obj, int button_number, int modifiers) |
| 277 : WebMethodTask<EventSender>(obj), | 299 : WebMethodTask<EventSender>(obj), |
| 278 button_number_(button_number), | 300 button_number_(button_number), |
| 279 modifiers_(modifiers) {} | 301 modifiers_(modifiers) {} |
| 280 | 302 |
| 281 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); } | 303 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); } |
| 282 | 304 |
| 283 private: | 305 private: |
| (...skipping 2247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2531 last_event_timestamp_ = event.timeStampSeconds; | 2553 last_event_timestamp_ = event.timeStampSeconds; |
| 2532 | 2554 |
| 2533 if (WebPagePopup* popup = view_->pagePopup()) { | 2555 if (WebPagePopup* popup = view_->pagePopup()) { |
| 2534 if (!WebInputEvent::isKeyboardEventType(event.type)) | 2556 if (!WebInputEvent::isKeyboardEventType(event.type)) |
| 2535 return popup->handleInputEvent(event); | 2557 return popup->handleInputEvent(event); |
| 2536 } | 2558 } |
| 2537 return view_->handleInputEvent(event); | 2559 return view_->handleInputEvent(event); |
| 2538 } | 2560 } |
| 2539 | 2561 |
| 2540 } // namespace test_runner | 2562 } // namespace test_runner |
| OLD | NEW |