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

Side by Side Diff: Source/web/WebDevToolsAgentImpl.cpp

Issue 145003002: [DevTools] Switch from blink-based to content-based touch emulation. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010-2011 Google Inc. All rights reserved. 2 * Copyright (C) 2010-2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "WebSettings.h" 44 #include "WebSettings.h"
45 #include "WebViewClient.h" 45 #include "WebViewClient.h"
46 #include "WebViewImpl.h" 46 #include "WebViewImpl.h"
47 #include "bindings/v8/PageScriptDebugServer.h" 47 #include "bindings/v8/PageScriptDebugServer.h"
48 #include "bindings/v8/ScriptController.h" 48 #include "bindings/v8/ScriptController.h"
49 #include "bindings/v8/V8Binding.h" 49 #include "bindings/v8/V8Binding.h"
50 #include "core/dom/ExceptionCode.h" 50 #include "core/dom/ExceptionCode.h"
51 #include "core/fetch/MemoryCache.h" 51 #include "core/fetch/MemoryCache.h"
52 #include "core/frame/FrameView.h" 52 #include "core/frame/FrameView.h"
53 #include "core/frame/LocalFrame.h" 53 #include "core/frame/LocalFrame.h"
54 #include "core/frame/Settings.h"
54 #include "core/inspector/InjectedScriptHost.h" 55 #include "core/inspector/InjectedScriptHost.h"
55 #include "core/inspector/InspectorController.h" 56 #include "core/inspector/InspectorController.h"
56 #include "core/page/Page.h" 57 #include "core/page/Page.h"
57 #include "core/rendering/RenderView.h" 58 #include "core/rendering/RenderView.h"
58 #include "platform/JSONValues.h" 59 #include "platform/JSONValues.h"
59 #include "platform/graphics/GraphicsContext.h" 60 #include "platform/graphics/GraphicsContext.h"
60 #include "platform/network/ResourceError.h" 61 #include "platform/network/ResourceError.h"
61 #include "platform/network/ResourceRequest.h" 62 #include "platform/network/ResourceRequest.h"
62 #include "platform/network/ResourceResponse.h" 63 #include "platform/network/ResourceResponse.h"
63 #include "public/platform/Platform.h" 64 #include "public/platform/Platform.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 WebDevToolsAgentClient* client) 199 WebDevToolsAgentClient* client)
199 : m_hostId(client->hostIdentifier()) 200 : m_hostId(client->hostIdentifier())
200 , m_client(client) 201 , m_client(client)
201 , m_webViewImpl(webViewImpl) 202 , m_webViewImpl(webViewImpl)
202 , m_attached(false) 203 , m_attached(false)
203 , m_generatingEvent(false) 204 , m_generatingEvent(false)
204 , m_deviceMetricsEnabled(false) 205 , m_deviceMetricsEnabled(false)
205 , m_emulateViewportEnabled(false) 206 , m_emulateViewportEnabled(false)
206 , m_originalViewportEnabled(false) 207 , m_originalViewportEnabled(false)
207 , m_isOverlayScrollbarsEnabled(false) 208 , m_isOverlayScrollbarsEnabled(false)
209 , m_touchEventEmulationEnabled(false)
210 , m_originalTouchEnabled(false)
211 , m_originalDeviceSupportsMouse(false)
208 { 212 {
209 ASSERT(m_hostId > 0); 213 ASSERT(m_hostId > 0);
210 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client); 214 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client);
211 } 215 }
212 216
213 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() 217 WebDevToolsAgentImpl::~WebDevToolsAgentImpl()
214 { 218 {
215 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); 219 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl);
216 if (m_attached) 220 if (m_attached)
217 blink::Platform::current()->currentThread()->removeTaskObserver(this); 221 blink::Platform::current()->currentThread()->removeTaskObserver(this);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 { 295 {
292 if (InspectorController* ic = inspectorController()) 296 if (InspectorController* ic = inspectorController())
293 ic->webViewResized(IntSize()); 297 ic->webViewResized(IntSize());
294 } 298 }
295 299
296 bool WebDevToolsAgentImpl::handleInputEvent(WebCore::Page* page, const WebInputE vent& inputEvent) 300 bool WebDevToolsAgentImpl::handleInputEvent(WebCore::Page* page, const WebInputE vent& inputEvent)
297 { 301 {
298 if (!m_attached && !m_generatingEvent) 302 if (!m_attached && !m_generatingEvent)
299 return false; 303 return false;
300 304
305 if (WebInputEvent::isGestureEventType(inputEvent.type) && m_touchEventEmulat ionEnabled) {
306 FrameView* frameView = page->mainFrame()->view();
pfeldman 2014/04/07 17:32:59 Why are these gestures handled here?
pfeldman 2014/04/07 17:52:50 Please add fixme and a link to a bug.
dgozman 2014/04/08 16:51:48 Done.
307 PlatformGestureEventBuilder gestureEvent(frameView, *static_cast<const W ebGestureEvent*>(&inputEvent));
308 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate) {
309 IntPoint offset = gestureEvent.position();
310 float oldPageScaleFactor = page->pageScaleFactor();
311 float newPageScaleFactor = oldPageScaleFactor * gestureEvent.scale() ;
312 float offsetScale = 1 - oldPageScaleFactor / newPageScaleFactor;
313 offset.scale(offsetScale, offsetScale);
314 m_webViewImpl->setPageScaleFactor(newPageScaleFactor, offset + frame View->scrollPosition());
315 }
316 if (gestureEvent.type() == PlatformEvent::GesturePinchBegin
317 || gestureEvent.type() == PlatformEvent::GesturePinchUpdate
318 || gestureEvent.type() == PlatformEvent::GesturePinchEnd)
319 return true;
320 }
321
301 InspectorController* ic = inspectorController(); 322 InspectorController* ic = inspectorController();
302 if (!ic) 323 if (!ic)
303 return false; 324 return false;
304 325
305 if (WebInputEvent::isGestureEventType(inputEvent.type) && inputEvent.type == WebInputEvent::GestureTap) { 326 if (WebInputEvent::isGestureEventType(inputEvent.type) && inputEvent.type == WebInputEvent::GestureTap) {
306 // Only let GestureTab in (we only need it and we know PlatformGestureEv entBuilder supports it). 327 // Only let GestureTab in (we only need it and we know PlatformGestureEv entBuilder supports it).
307 PlatformGestureEvent gestureEvent = PlatformGestureEventBuilder(page->ma inFrame()->view(), *static_cast<const WebGestureEvent*>(&inputEvent)); 328 PlatformGestureEvent gestureEvent = PlatformGestureEventBuilder(page->ma inFrame()->view(), *static_cast<const WebGestureEvent*>(&inputEvent));
308 return ic->handleGestureEvent(page->mainFrame(), gestureEvent); 329 return ic->handleGestureEvent(page->mainFrame(), gestureEvent);
309 } 330 }
310 if (WebInputEvent::isMouseEventType(inputEvent.type) && inputEvent.type != W ebInputEvent::MouseEnter) { 331 if (WebInputEvent::isMouseEventType(inputEvent.type) && inputEvent.type != W ebInputEvent::MouseEnter) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 WebDeviceEmulationParams params; 366 WebDeviceEmulationParams params;
346 params.screenPosition = emulateViewport ? WebDeviceEmulationParams::Mobi le : WebDeviceEmulationParams::Desktop; 367 params.screenPosition = emulateViewport ? WebDeviceEmulationParams::Mobi le : WebDeviceEmulationParams::Desktop;
347 params.deviceScaleFactor = deviceScaleFactor; 368 params.deviceScaleFactor = deviceScaleFactor;
348 params.viewSize = WebSize(width, height); 369 params.viewSize = WebSize(width, height);
349 params.fitToView = fitWindow; 370 params.fitToView = fitWindow;
350 params.viewInsets = WebSize(10, 10); 371 params.viewInsets = WebSize(10, 10);
351 m_client->enableDeviceEmulation(params); 372 m_client->enableDeviceEmulation(params);
352 } 373 }
353 } 374 }
354 375
376 void WebDevToolsAgentImpl::setTouchEventEmulationEnabled(bool enabled)
377 {
378 if (m_touchEventEmulationEnabled == enabled)
379 return;
380
381 if (!m_touchEventEmulationEnabled) {
382 m_originalTouchEnabled = RuntimeEnabledFeatures::touchEnabled();
383 if (m_webViewImpl->page())
384 m_originalDeviceSupportsMouse = m_webViewImpl->page()->settings().de viceSupportsMouse();
385 }
386 RuntimeEnabledFeatures::setTouchEnabled(enabled ? true : m_originalTouchEnab led);
387 if (m_webViewImpl->page())
388 m_webViewImpl->page()->settings().setDeviceSupportsMouse(enabled ? false : m_originalDeviceSupportsMouse);
389 m_client->setTouchEventEmulationEnabled(enabled);
390 m_touchEventEmulationEnabled = enabled;
391 }
392
355 void WebDevToolsAgentImpl::enableViewportEmulation() 393 void WebDevToolsAgentImpl::enableViewportEmulation()
356 { 394 {
357 if (m_emulateViewportEnabled) 395 if (m_emulateViewportEnabled)
358 return; 396 return;
359 m_emulateViewportEnabled = true; 397 m_emulateViewportEnabled = true;
360 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab led(); 398 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab led();
361 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); 399 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
362 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled(); 400 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled();
363 RuntimeEnabledFeatures::setCSSViewportEnabled(true); 401 RuntimeEnabledFeatures::setCSSViewportEnabled(true);
364 m_webViewImpl->settings()->setViewportEnabled(true); 402 m_webViewImpl->settings()->setViewportEnabled(true);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_startCmd) 704 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_startCmd)
667 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_stopCmd); 705 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_stopCmd);
668 } 706 }
669 707
670 void WebDevToolsAgent::processPendingMessages() 708 void WebDevToolsAgent::processPendingMessages()
671 { 709 {
672 PageScriptDebugServer::shared().runPendingTasks(); 710 PageScriptDebugServer::shared().runPendingTasks();
673 } 711 }
674 712
675 } // namespace blink 713 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698