| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/browser/devtools/renderer_overrides_handler.h" | 5 #include "content/browser/devtools/renderer_overrides_handler.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/barrier_closure.h" | 10 #include "base/barrier_closure.h" |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 RegisterCommandHandler( | 167 RegisterCommandHandler( |
| 168 devtools::Page::queryUsageAndQuota::kName, | 168 devtools::Page::queryUsageAndQuota::kName, |
| 169 base::Bind( | 169 base::Bind( |
| 170 &RendererOverridesHandler::PageQueryUsageAndQuota, | 170 &RendererOverridesHandler::PageQueryUsageAndQuota, |
| 171 base::Unretained(this))); | 171 base::Unretained(this))); |
| 172 RegisterCommandHandler( | 172 RegisterCommandHandler( |
| 173 devtools::Page::setColorPickerEnabled::kName, | 173 devtools::Page::setColorPickerEnabled::kName, |
| 174 base::Bind( | 174 base::Bind( |
| 175 &RendererOverridesHandler::PageSetColorPickerEnabled, | 175 &RendererOverridesHandler::PageSetColorPickerEnabled, |
| 176 base::Unretained(this))); | 176 base::Unretained(this))); |
| 177 RegisterCommandHandler( | |
| 178 devtools::Input::emulateTouchFromMouseEvent::kName, | |
| 179 base::Bind( | |
| 180 &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, | |
| 181 base::Unretained(this))); | |
| 182 mouse_event_callback_ = base::Bind( | 177 mouse_event_callback_ = base::Bind( |
| 183 &RendererOverridesHandler::HandleMouseEvent, | 178 &RendererOverridesHandler::HandleMouseEvent, |
| 184 base::Unretained(this)); | 179 base::Unretained(this)); |
| 185 } | 180 } |
| 186 | 181 |
| 187 RendererOverridesHandler::~RendererOverridesHandler() {} | 182 RendererOverridesHandler::~RendererOverridesHandler() {} |
| 188 | 183 |
| 189 void RendererOverridesHandler::OnClientDetached() { | 184 void RendererOverridesHandler::OnClientDetached() { |
| 190 touch_emulation_enabled_ = false; | 185 touch_emulation_enabled_ = false; |
| 191 screencast_command_ = NULL; | 186 screencast_command_ = NULL; |
| (...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1182 kHotspotOffset * device_scale_factor); | 1177 kHotspotOffset * device_scale_factor); |
| 1183 #if defined(OS_WIN) | 1178 #if defined(OS_WIN) |
| 1184 cursor_info.external_handle = 0; | 1179 cursor_info.external_handle = 0; |
| 1185 #endif | 1180 #endif |
| 1186 | 1181 |
| 1187 cursor.InitFromCursorInfo(cursor_info); | 1182 cursor.InitFromCursorInfo(cursor_info); |
| 1188 DCHECK(host_); | 1183 DCHECK(host_); |
| 1189 host_->SetCursor(cursor); | 1184 host_->SetCursor(cursor); |
| 1190 } | 1185 } |
| 1191 | 1186 |
| 1192 // Input agent handlers ------------------------------------------------------ | |
| 1193 | |
| 1194 scoped_refptr<DevToolsProtocol::Response> | |
| 1195 RendererOverridesHandler::InputEmulateTouchFromMouseEvent( | |
| 1196 scoped_refptr<DevToolsProtocol::Command> command) { | |
| 1197 if (!screencast_command_.get()) | |
| 1198 return command->InternalErrorResponse("Screencast should be turned on"); | |
| 1199 | |
| 1200 base::DictionaryValue* params = command->params(); | |
| 1201 if (!params) | |
| 1202 return command->NoSuchMethodErrorResponse(); | |
| 1203 | |
| 1204 std::string type; | |
| 1205 if (!params->GetString( | |
| 1206 devtools::Input::emulateTouchFromMouseEvent::kParamType, | |
| 1207 &type)) { | |
| 1208 return command->InvalidParamResponse( | |
| 1209 devtools::Input::emulateTouchFromMouseEvent::kParamType); | |
| 1210 } | |
| 1211 | |
| 1212 blink::WebMouseWheelEvent wheel_event; | |
| 1213 blink::WebMouseEvent mouse_event; | |
| 1214 blink::WebMouseEvent* event = &mouse_event; | |
| 1215 | |
| 1216 if (type == | |
| 1217 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMousePressed) { | |
| 1218 event->type = WebInputEvent::MouseDown; | |
| 1219 } else if (type == | |
| 1220 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseReleased) { | |
| 1221 event->type = WebInputEvent::MouseUp; | |
| 1222 } else if (type == | |
| 1223 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseMoved) { | |
| 1224 event->type = WebInputEvent::MouseMove; | |
| 1225 } else if (type == | |
| 1226 devtools::Input::emulateTouchFromMouseEvent::Type::kEnumMouseWheel) { | |
| 1227 double deltaX = 0; | |
| 1228 double deltaY = 0; | |
| 1229 if (!params->GetDouble( | |
| 1230 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaX, | |
| 1231 &deltaX)) { | |
| 1232 return command->InvalidParamResponse( | |
| 1233 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaX); | |
| 1234 } | |
| 1235 if (!params->GetDouble( | |
| 1236 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaY, | |
| 1237 &deltaY)) { | |
| 1238 return command->InvalidParamResponse( | |
| 1239 devtools::Input::emulateTouchFromMouseEvent::kParamDeltaY); | |
| 1240 } | |
| 1241 wheel_event.deltaX = static_cast<float>(deltaX); | |
| 1242 wheel_event.deltaY = static_cast<float>(deltaY); | |
| 1243 event = &wheel_event; | |
| 1244 event->type = WebInputEvent::MouseWheel; | |
| 1245 } else { | |
| 1246 return command->InvalidParamResponse( | |
| 1247 devtools::Input::emulateTouchFromMouseEvent::kParamType); | |
| 1248 } | |
| 1249 | |
| 1250 int modifiers = 0; | |
| 1251 if (params->GetInteger( | |
| 1252 devtools::Input::emulateTouchFromMouseEvent::kParamModifiers, | |
| 1253 &modifiers)) { | |
| 1254 if (modifiers & 1) | |
| 1255 event->modifiers |= WebInputEvent::AltKey; | |
| 1256 if (modifiers & 2) | |
| 1257 event->modifiers |= WebInputEvent::ControlKey; | |
| 1258 if (modifiers & 4) | |
| 1259 event->modifiers |= WebInputEvent::MetaKey; | |
| 1260 if (modifiers & 8) | |
| 1261 event->modifiers |= WebInputEvent::ShiftKey; | |
| 1262 } | |
| 1263 | |
| 1264 params->GetDouble( | |
| 1265 devtools::Input::emulateTouchFromMouseEvent::kParamTimestamp, | |
| 1266 &event->timeStampSeconds); | |
| 1267 | |
| 1268 if (!params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamX, | |
| 1269 &event->x)) { | |
| 1270 return command->InvalidParamResponse( | |
| 1271 devtools::Input::emulateTouchFromMouseEvent::kParamX); | |
| 1272 } | |
| 1273 | |
| 1274 if (!params->GetInteger(devtools::Input::emulateTouchFromMouseEvent::kParamY, | |
| 1275 &event->y)) { | |
| 1276 return command->InvalidParamResponse( | |
| 1277 devtools::Input::emulateTouchFromMouseEvent::kParamY); | |
| 1278 } | |
| 1279 | |
| 1280 event->windowX = event->x; | |
| 1281 event->windowY = event->y; | |
| 1282 event->globalX = event->x; | |
| 1283 event->globalY = event->y; | |
| 1284 | |
| 1285 params->GetInteger( | |
| 1286 devtools::Input::emulateTouchFromMouseEvent::kParamClickCount, | |
| 1287 &event->clickCount); | |
| 1288 | |
| 1289 std::string button; | |
| 1290 if (!params->GetString( | |
| 1291 devtools::Input::emulateTouchFromMouseEvent::kParamButton, | |
| 1292 &button)) { | |
| 1293 return command->InvalidParamResponse( | |
| 1294 devtools::Input::emulateTouchFromMouseEvent::kParamButton); | |
| 1295 } | |
| 1296 | |
| 1297 if (button == "none") { | |
| 1298 event->button = WebMouseEvent::ButtonNone; | |
| 1299 } else if (button == "left") { | |
| 1300 event->button = WebMouseEvent::ButtonLeft; | |
| 1301 event->modifiers |= WebInputEvent::LeftButtonDown; | |
| 1302 } else if (button == "middle") { | |
| 1303 event->button = WebMouseEvent::ButtonMiddle; | |
| 1304 event->modifiers |= WebInputEvent::MiddleButtonDown; | |
| 1305 } else if (button == "right") { | |
| 1306 event->button = WebMouseEvent::ButtonRight; | |
| 1307 event->modifiers |= WebInputEvent::RightButtonDown; | |
| 1308 } else { | |
| 1309 return command->InvalidParamResponse( | |
| 1310 devtools::Input::emulateTouchFromMouseEvent::kParamButton); | |
| 1311 } | |
| 1312 | |
| 1313 if (!host_) | |
| 1314 return command->InternalErrorResponse("Could not connect to view"); | |
| 1315 | |
| 1316 if (event->type == WebInputEvent::MouseWheel) | |
| 1317 host_->ForwardWheelEvent(wheel_event); | |
| 1318 else | |
| 1319 host_->ForwardMouseEvent(mouse_event); | |
| 1320 return command->SuccessResponse(NULL); | |
| 1321 } | |
| 1322 | |
| 1323 void RendererOverridesHandler::UpdateTouchEventEmulationState() { | 1187 void RendererOverridesHandler::UpdateTouchEventEmulationState() { |
| 1324 if (!host_) | 1188 if (!host_) |
| 1325 return; | 1189 return; |
| 1326 bool enabled = touch_emulation_enabled_ || screencast_command_.get(); | 1190 bool enabled = touch_emulation_enabled_ || screencast_command_.get(); |
| 1327 host_->SetTouchEventEmulationEnabled(enabled); | 1191 host_->SetTouchEventEmulationEnabled(enabled); |
| 1328 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1192 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1329 WebContents::FromRenderViewHost(host_)); | 1193 WebContents::FromRenderViewHost(host_)); |
| 1330 if (web_contents) | 1194 if (web_contents) |
| 1331 web_contents->SetForceDisableOverscrollContent(enabled); | 1195 web_contents->SetForceDisableOverscrollContent(enabled); |
| 1332 } | 1196 } |
| 1333 | 1197 |
| 1334 } // namespace content | 1198 } // namespace content |
| OLD | NEW |