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

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: another rebase 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
« no previous file with comments | « Source/web/WebDevToolsAgentImpl.h ('k') | public/web/WebDevToolsAgentClient.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 /* 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 // FIXME: This workaround is required for touch emulation on Mac, where
306 // compositor-side pinch handling is not enabled. See http://crbug.com/13800 3.
307 bool isPinch = inputEvent.type == WebInputEvent::GesturePinchBegin || inputE vent.type == WebInputEvent::GesturePinchUpdate || inputEvent.type == WebInputEve nt::GesturePinchEnd;
308 if (isPinch && m_touchEventEmulationEnabled && m_emulateViewportEnabled) {
309 FrameView* frameView = page->mainFrame()->view();
310 PlatformGestureEventBuilder gestureEvent(frameView, *static_cast<const W ebGestureEvent*>(&inputEvent));
311 float pageScaleFactor = page->pageScaleFactor();
312 if (gestureEvent.type() == PlatformEvent::GesturePinchBegin) {
313 m_lastPinchAnchorCss = adoptPtr(new WebCore::IntPoint(frameView->scr ollPosition() + gestureEvent.position()));
314 m_lastPinchAnchorDip = adoptPtr(new WebCore::IntPoint(gestureEvent.p osition()));
315 m_lastPinchAnchorDip->scale(pageScaleFactor, pageScaleFactor);
316 }
317 if (gestureEvent.type() == PlatformEvent::GesturePinchUpdate && m_lastPi nchAnchorCss) {
318 float newPageScaleFactor = pageScaleFactor * gestureEvent.scale();
319 WebCore::IntPoint anchorCss(*m_lastPinchAnchorDip.get());
320 anchorCss.scale(1.f / newPageScaleFactor, 1.f / newPageScaleFactor);
321 m_webViewImpl->setPageScaleFactor(newPageScaleFactor);
322 m_webViewImpl->setMainFrameScrollOffset(*m_lastPinchAnchorCss.get() - toIntSize(anchorCss));
323 }
324 if (gestureEvent.type() == PlatformEvent::GesturePinchEnd) {
325 m_lastPinchAnchorCss.clear();
326 m_lastPinchAnchorDip.clear();
327 }
328 return true;
329 }
330
301 InspectorController* ic = inspectorController(); 331 InspectorController* ic = inspectorController();
302 if (!ic) 332 if (!ic)
303 return false; 333 return false;
304 334
305 if (WebInputEvent::isGestureEventType(inputEvent.type) && inputEvent.type == WebInputEvent::GestureTap) { 335 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). 336 // 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)); 337 PlatformGestureEvent gestureEvent = PlatformGestureEventBuilder(page->ma inFrame()->view(), *static_cast<const WebGestureEvent*>(&inputEvent));
308 return ic->handleGestureEvent(page->mainFrame(), gestureEvent); 338 return ic->handleGestureEvent(page->mainFrame(), gestureEvent);
309 } 339 }
310 if (WebInputEvent::isMouseEventType(inputEvent.type) && inputEvent.type != W ebInputEvent::MouseEnter) { 340 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; 375 WebDeviceEmulationParams params;
346 params.screenPosition = emulateViewport ? WebDeviceEmulationParams::Mobi le : WebDeviceEmulationParams::Desktop; 376 params.screenPosition = emulateViewport ? WebDeviceEmulationParams::Mobi le : WebDeviceEmulationParams::Desktop;
347 params.deviceScaleFactor = deviceScaleFactor; 377 params.deviceScaleFactor = deviceScaleFactor;
348 params.viewSize = WebSize(width, height); 378 params.viewSize = WebSize(width, height);
349 params.fitToView = fitWindow; 379 params.fitToView = fitWindow;
350 params.viewInsets = WebSize(10, 10); 380 params.viewInsets = WebSize(10, 10);
351 m_client->enableDeviceEmulation(params); 381 m_client->enableDeviceEmulation(params);
352 } 382 }
353 } 383 }
354 384
385 void WebDevToolsAgentImpl::setTouchEventEmulationEnabled(bool enabled)
386 {
387 if (m_touchEventEmulationEnabled == enabled)
388 return;
389
390 if (!m_touchEventEmulationEnabled) {
391 m_originalTouchEnabled = RuntimeEnabledFeatures::touchEnabled();
392 if (m_webViewImpl->page())
393 m_originalDeviceSupportsMouse = m_webViewImpl->page()->settings().de viceSupportsMouse();
394 }
395 RuntimeEnabledFeatures::setTouchEnabled(enabled ? true : m_originalTouchEnab led);
396 if (m_webViewImpl->page())
397 m_webViewImpl->page()->settings().setDeviceSupportsMouse(enabled ? false : m_originalDeviceSupportsMouse);
398 m_client->setTouchEventEmulationEnabled(enabled, m_emulateViewportEnabled);
399 m_touchEventEmulationEnabled = enabled;
400 m_webViewImpl->mainFrameImpl()->frame()->view()->layout();
401 }
402
355 void WebDevToolsAgentImpl::enableViewportEmulation() 403 void WebDevToolsAgentImpl::enableViewportEmulation()
356 { 404 {
357 if (m_emulateViewportEnabled) 405 if (m_emulateViewportEnabled)
358 return; 406 return;
359 m_emulateViewportEnabled = true; 407 m_emulateViewportEnabled = true;
360 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab led(); 408 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScrollbarsEnab led();
361 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); 409 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
362 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled(); 410 m_originalViewportEnabled = RuntimeEnabledFeatures::cssViewportEnabled();
363 RuntimeEnabledFeatures::setCSSViewportEnabled(true); 411 RuntimeEnabledFeatures::setCSSViewportEnabled(true);
364 m_webViewImpl->settings()->setViewportEnabled(true); 412 m_webViewImpl->settings()->setViewportEnabled(true);
365 m_webViewImpl->settings()->setViewportMetaEnabled(true); 413 m_webViewImpl->settings()->setViewportMetaEnabled(true);
366 m_webViewImpl->settings()->setShrinksViewportContentToFit(true); 414 m_webViewImpl->settings()->setShrinksViewportContentToFit(true);
367 m_webViewImpl->setIgnoreViewportTagScaleLimits(true); 415 m_webViewImpl->setIgnoreViewportTagScaleLimits(true);
368 m_webViewImpl->setPageScaleFactorLimits(-1, -1); 416 m_webViewImpl->setPageScaleFactorLimits(-1, -1);
369 m_webViewImpl->setZoomFactorOverride(1); 417 m_webViewImpl->setZoomFactorOverride(1);
418 // FIXME: with touch and viewport emulation enabled, we may want to disable overscroll navigation.
419 if (m_touchEventEmulationEnabled)
420 m_client->setTouchEventEmulationEnabled(m_touchEventEmulationEnabled, m_ emulateViewportEnabled);
370 } 421 }
371 422
372 void WebDevToolsAgentImpl::disableViewportEmulation() 423 void WebDevToolsAgentImpl::disableViewportEmulation()
373 { 424 {
374 if (!m_emulateViewportEnabled) 425 if (!m_emulateViewportEnabled)
375 return; 426 return;
376 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_isOverlayScrollbarsEna bled); 427 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_isOverlayScrollbarsEna bled);
377 RuntimeEnabledFeatures::setCSSViewportEnabled(m_originalViewportEnabled); 428 RuntimeEnabledFeatures::setCSSViewportEnabled(m_originalViewportEnabled);
378 m_webViewImpl->settings()->setViewportEnabled(false); 429 m_webViewImpl->settings()->setViewportEnabled(false);
379 m_webViewImpl->settings()->setViewportMetaEnabled(false); 430 m_webViewImpl->settings()->setViewportMetaEnabled(false);
380 m_webViewImpl->settings()->setShrinksViewportContentToFit(false); 431 m_webViewImpl->settings()->setShrinksViewportContentToFit(false);
381 m_webViewImpl->setIgnoreViewportTagScaleLimits(false); 432 m_webViewImpl->setIgnoreViewportTagScaleLimits(false);
382 m_webViewImpl->setPageScaleFactorLimits(1, 1); 433 m_webViewImpl->setPageScaleFactorLimits(1, 1);
383 m_webViewImpl->setZoomFactorOverride(0); 434 m_webViewImpl->setZoomFactorOverride(0);
384 m_emulateViewportEnabled = false; 435 m_emulateViewportEnabled = false;
436 if (m_touchEventEmulationEnabled)
437 m_client->setTouchEventEmulationEnabled(m_touchEventEmulationEnabled, m_ emulateViewportEnabled);
385 } 438 }
386 439
387 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set) 440 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set)
388 { 441 {
389 class CountingVisitor : public WebDevToolsAgentClient::AllocatedObjectVisito r { 442 class CountingVisitor : public WebDevToolsAgentClient::AllocatedObjectVisito r {
390 public: 443 public:
391 CountingVisitor() : m_totalObjectsCount(0) 444 CountingVisitor() : m_totalObjectsCount(0)
392 { 445 {
393 } 446 }
394 447
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_startCmd) 721 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_startCmd)
669 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_stopCmd); 722 || commandName == InspectorBackendDispatcher::commandName(InspectorBacke ndDispatcher::kProfiler_stopCmd);
670 } 723 }
671 724
672 void WebDevToolsAgent::processPendingMessages() 725 void WebDevToolsAgent::processPendingMessages()
673 { 726 {
674 PageScriptDebugServer::shared().runPendingTasks(); 727 PageScriptDebugServer::shared().runPendingTasks();
675 } 728 }
676 729
677 } // namespace blink 730 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebDevToolsAgentImpl.h ('k') | public/web/WebDevToolsAgentClient.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698