Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: content/shell/renderer/test_runner/event_sender.cc

Issue 1152653004: Re-land: gin: Use V8 Maybe APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gin/arguments.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/shell/renderer/test_runner/event_sender.h" 5 #include "content/shell/renderer/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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 int GetKeyModifiers(const std::vector<std::string>& modifier_names) { 110 int GetKeyModifiers(const std::vector<std::string>& modifier_names) {
111 int modifiers = 0; 111 int modifiers = 0;
112 for (std::vector<std::string>::const_iterator it = modifier_names.begin(); 112 for (std::vector<std::string>::const_iterator it = modifier_names.begin();
113 it != modifier_names.end(); ++it) { 113 it != modifier_names.end(); ++it) {
114 modifiers |= GetKeyModifier(*it); 114 modifiers |= GetKeyModifier(*it);
115 } 115 }
116 return modifiers; 116 return modifiers;
117 } 117 }
118 118
119 int GetKeyModifiersFromV8(v8::Local<v8::Value> value) { 119 int GetKeyModifiersFromV8(v8::Isolate* isolate, v8::Local<v8::Value> value) {
120 std::vector<std::string> modifier_names; 120 std::vector<std::string> modifier_names;
121 if (value->IsString()) { 121 if (value->IsString()) {
122 modifier_names.push_back(gin::V8ToString(value)); 122 modifier_names.push_back(gin::V8ToString(value));
123 } else if (value->IsArray()) { 123 } else if (value->IsArray()) {
124 gin::Converter<std::vector<std::string> >::FromV8( 124 gin::Converter<std::vector<std::string> >::FromV8(
125 NULL, value, &modifier_names); 125 isolate, value, &modifier_names);
126 } 126 }
127 return GetKeyModifiers(modifier_names); 127 return GetKeyModifiers(modifier_names);
128 } 128 }
129 129
130 // Maximum distance (in space and time) for a mouse click to register as a 130 // Maximum distance (in space and time) for a mouse click to register as a
131 // double or triple click. 131 // double or triple click.
132 const double kMultipleClickTimeSec = 1; 132 const double kMultipleClickTimeSec = 1;
133 const int kMultipleClickRadiusPixels = 5; 133 const int kMultipleClickRadiusPixels = 5;
134 const char kSubMenuDepthIdentifier[] = "_"; 134 const char kSubMenuDepthIdentifier[] = "_";
135 const char kSubMenuIdentifier[] = " >"; 135 const char kSubMenuIdentifier[] = " >";
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 909
910 void EventSenderBindings::ScheduleAsynchronousClick(gin::Arguments* args) { 910 void EventSenderBindings::ScheduleAsynchronousClick(gin::Arguments* args) {
911 if (!sender_) 911 if (!sender_)
912 return; 912 return;
913 913
914 int button_number = 0; 914 int button_number = 0;
915 int modifiers = 0; 915 int modifiers = 0;
916 if (!args->PeekNext().IsEmpty()) { 916 if (!args->PeekNext().IsEmpty()) {
917 args->GetNext(&button_number); 917 args->GetNext(&button_number);
918 if (!args->PeekNext().IsEmpty()) 918 if (!args->PeekNext().IsEmpty())
919 modifiers = GetKeyModifiersFromV8(args->PeekNext()); 919 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
920 } 920 }
921 sender_->ScheduleAsynchronousClick(button_number, modifiers); 921 sender_->ScheduleAsynchronousClick(button_number, modifiers);
922 } 922 }
923 923
924 void EventSenderBindings::ScheduleAsynchronousKeyDown(gin::Arguments* args) { 924 void EventSenderBindings::ScheduleAsynchronousKeyDown(gin::Arguments* args) {
925 if (!sender_) 925 if (!sender_)
926 return; 926 return;
927 927
928 std::string code_str; 928 std::string code_str;
929 int modifiers = 0; 929 int modifiers = 0;
930 int location = DOMKeyLocationStandard; 930 int location = DOMKeyLocationStandard;
931 args->GetNext(&code_str); 931 args->GetNext(&code_str);
932 if (!args->PeekNext().IsEmpty()) { 932 if (!args->PeekNext().IsEmpty()) {
933 v8::Local<v8::Value> value; 933 v8::Local<v8::Value> value;
934 args->GetNext(&value); 934 args->GetNext(&value);
935 modifiers = GetKeyModifiersFromV8(value); 935 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
936 if (!args->PeekNext().IsEmpty()) 936 if (!args->PeekNext().IsEmpty())
937 args->GetNext(&location); 937 args->GetNext(&location);
938 } 938 }
939 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers, 939 sender_->ScheduleAsynchronousKeyDown(code_str, modifiers,
940 static_cast<KeyLocationCode>(location)); 940 static_cast<KeyLocationCode>(location));
941 } 941 }
942 942
943 void EventSenderBindings::MouseDown(gin::Arguments* args) { 943 void EventSenderBindings::MouseDown(gin::Arguments* args) {
944 if (!sender_) 944 if (!sender_)
945 return; 945 return;
946 946
947 int button_number = 0; 947 int button_number = 0;
948 int modifiers = 0; 948 int modifiers = 0;
949 if (!args->PeekNext().IsEmpty()) { 949 if (!args->PeekNext().IsEmpty()) {
950 args->GetNext(&button_number); 950 args->GetNext(&button_number);
951 if (!args->PeekNext().IsEmpty()) 951 if (!args->PeekNext().IsEmpty())
952 modifiers = GetKeyModifiersFromV8(args->PeekNext()); 952 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
953 } 953 }
954 sender_->MouseDown(button_number, modifiers); 954 sender_->MouseDown(button_number, modifiers);
955 } 955 }
956 956
957 void EventSenderBindings::MouseUp(gin::Arguments* args) { 957 void EventSenderBindings::MouseUp(gin::Arguments* args) {
958 if (!sender_) 958 if (!sender_)
959 return; 959 return;
960 960
961 int button_number = 0; 961 int button_number = 0;
962 int modifiers = 0; 962 int modifiers = 0;
963 if (!args->PeekNext().IsEmpty()) { 963 if (!args->PeekNext().IsEmpty()) {
964 args->GetNext(&button_number); 964 args->GetNext(&button_number);
965 if (!args->PeekNext().IsEmpty()) 965 if (!args->PeekNext().IsEmpty())
966 modifiers = GetKeyModifiersFromV8(args->PeekNext()); 966 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
967 } 967 }
968 sender_->MouseUp(button_number, modifiers); 968 sender_->MouseUp(button_number, modifiers);
969 } 969 }
970 970
971 void EventSenderBindings::KeyDown(gin::Arguments* args) { 971 void EventSenderBindings::KeyDown(gin::Arguments* args) {
972 if (!sender_) 972 if (!sender_)
973 return; 973 return;
974 974
975 std::string code_str; 975 std::string code_str;
976 int modifiers = 0; 976 int modifiers = 0;
977 int location = DOMKeyLocationStandard; 977 int location = DOMKeyLocationStandard;
978 args->GetNext(&code_str); 978 args->GetNext(&code_str);
979 if (!args->PeekNext().IsEmpty()) { 979 if (!args->PeekNext().IsEmpty()) {
980 v8::Local<v8::Value> value; 980 v8::Local<v8::Value> value;
981 args->GetNext(&value); 981 args->GetNext(&value);
982 modifiers = GetKeyModifiersFromV8(value); 982 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
983 if (!args->PeekNext().IsEmpty()) 983 if (!args->PeekNext().IsEmpty())
984 args->GetNext(&location); 984 args->GetNext(&location);
985 } 985 }
986 sender_->KeyDown(code_str, modifiers, static_cast<KeyLocationCode>(location)); 986 sender_->KeyDown(code_str, modifiers, static_cast<KeyLocationCode>(location));
987 } 987 }
988 988
989 bool EventSenderBindings::ForceLayoutOnEvents() const { 989 bool EventSenderBindings::ForceLayoutOnEvents() const {
990 if (sender_) 990 if (sender_)
991 return sender_->force_layout_on_events(); 991 return sender_->force_layout_on_events();
992 return false; 992 return false;
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 double x; 1901 double x;
1902 double y; 1902 double y;
1903 if (!args->GetNext(&x) || !args->GetNext(&y)) { 1903 if (!args->GetNext(&x) || !args->GetNext(&y)) {
1904 args->ThrowError(); 1904 args->ThrowError();
1905 return; 1905 return;
1906 } 1906 }
1907 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); 1907 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y));
1908 1908
1909 int modifiers = 0; 1909 int modifiers = 0;
1910 if (!args->PeekNext().IsEmpty()) 1910 if (!args->PeekNext().IsEmpty())
1911 modifiers = GetKeyModifiersFromV8(args->PeekNext()); 1911 modifiers = GetKeyModifiersFromV8(args->isolate(), args->PeekNext());
1912 1912
1913 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && 1913 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft &&
1914 !replaying_saved_events_) { 1914 !replaying_saved_events_) {
1915 SavedEvent saved_event; 1915 SavedEvent saved_event;
1916 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; 1916 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE;
1917 saved_event.pos = mouse_pos; 1917 saved_event.pos = mouse_pos;
1918 saved_event.modifiers = modifiers; 1918 saved_event.modifiers = modifiers;
1919 mouse_event_queue_.push_back(saved_event); 1919 mouse_event_queue_.push_back(saved_event);
1920 } else { 1920 } else {
1921 WebMouseEvent event; 1921 WebMouseEvent event;
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 bool has_precise_scrolling_deltas = false; 2380 bool has_precise_scrolling_deltas = false;
2381 int modifiers = 0; 2381 int modifiers = 0;
2382 bool can_scroll = true; 2382 bool can_scroll = true;
2383 if (!args->PeekNext().IsEmpty()) { 2383 if (!args->PeekNext().IsEmpty()) {
2384 args->GetNext(&paged); 2384 args->GetNext(&paged);
2385 if (!args->PeekNext().IsEmpty()) { 2385 if (!args->PeekNext().IsEmpty()) {
2386 args->GetNext(&has_precise_scrolling_deltas); 2386 args->GetNext(&has_precise_scrolling_deltas);
2387 if (!args->PeekNext().IsEmpty()) { 2387 if (!args->PeekNext().IsEmpty()) {
2388 v8::Local<v8::Value> value; 2388 v8::Local<v8::Value> value;
2389 args->GetNext(&value); 2389 args->GetNext(&value);
2390 modifiers = GetKeyModifiersFromV8(value); 2390 modifiers = GetKeyModifiersFromV8(args->isolate(), value);
2391 if (!args->PeekNext().IsEmpty()) 2391 if (!args->PeekNext().IsEmpty())
2392 args->GetNext(&can_scroll); 2392 args->GetNext(&can_scroll);
2393 } 2393 }
2394 } 2394 }
2395 } 2395 }
2396 2396
2397 InitMouseEvent(WebInputEvent::MouseWheel, 2397 InitMouseEvent(WebInputEvent::MouseWheel,
2398 pressed_button_, 2398 pressed_button_,
2399 last_mouse_pos_, 2399 last_mouse_pos_,
2400 GetCurrentEventTimeSec(), 2400 GetCurrentEventTimeSec(),
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
2517 2517
2518 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) { 2518 bool EventSender::HandleInputEventOnViewOrPopup(const WebInputEvent& event) {
2519 if (WebPagePopup* popup = view_->pagePopup()) { 2519 if (WebPagePopup* popup = view_->pagePopup()) {
2520 if (!WebInputEvent::isKeyboardEventType(event.type)) 2520 if (!WebInputEvent::isKeyboardEventType(event.type))
2521 return popup->handleInputEvent(event); 2521 return popup->handleInputEvent(event);
2522 } 2522 }
2523 return view_->handleInputEvent(event); 2523 return view_->handleInputEvent(event);
2524 } 2524 }
2525 2525
2526 } // namespace content 2526 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | gin/arguments.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698