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

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

Issue 23187005: [DevTools] Use device metrics emulation implemented in content. (Closed) Base URL: svn://svn.chromium.org/blink/trunk/
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "WebDevToolsAgentImpl.h" 32 #include "WebDevToolsAgentImpl.h"
33 33
34 #include "InspectorBackendDispatcher.h" 34 #include "InspectorBackendDispatcher.h"
35 #include "InspectorFrontend.h" 35 #include "InspectorFrontend.h"
36 #include "InspectorProtocolVersion.h" 36 #include "InspectorProtocolVersion.h"
37 #include "RuntimeEnabledFeatures.h"
37 #include "WebDataSource.h" 38 #include "WebDataSource.h"
38 #include "WebDevToolsAgentClient.h" 39 #include "WebDevToolsAgentClient.h"
39 #include "WebFrameImpl.h" 40 #include "WebFrameImpl.h"
40 #include "WebInputEventConversion.h" 41 #include "WebInputEventConversion.h"
41 #include "WebMemoryUsageInfo.h" 42 #include "WebMemoryUsageInfo.h"
43 #include "WebSettings.h"
42 #include "WebViewClient.h" 44 #include "WebViewClient.h"
43 #include "WebViewImpl.h" 45 #include "WebViewImpl.h"
44 #include "bindings/v8/PageScriptDebugServer.h" 46 #include "bindings/v8/PageScriptDebugServer.h"
45 #include "bindings/v8/ScriptController.h" 47 #include "bindings/v8/ScriptController.h"
46 #include "bindings/v8/V8Binding.h" 48 #include "bindings/v8/V8Binding.h"
47 #include "bindings/v8/V8Utilities.h" 49 #include "bindings/v8/V8Utilities.h"
48 #include "core/dom/ExceptionCode.h" 50 #include "core/dom/ExceptionCode.h"
49 #include "core/fetch/MemoryCache.h" 51 #include "core/fetch/MemoryCache.h"
50 #include "core/inspector/InjectedScriptHost.h" 52 #include "core/inspector/InjectedScriptHost.h"
51 #include "core/inspector/InspectorController.h" 53 #include "core/inspector/InspectorController.h"
52 #include "core/page/Frame.h" 54 #include "core/page/Frame.h"
53 #include "core/page/FrameView.h" 55 #include "core/page/FrameView.h"
54 #include "core/page/Page.h" 56 #include "core/page/Page.h"
55 #include "core/page/PageGroup.h" 57 #include "core/page/PageGroup.h"
58 #include "core/page/Settings.h"
56 #include "core/platform/JSONValues.h" 59 #include "core/platform/JSONValues.h"
57 #include "core/platform/graphics/GraphicsContext.h" 60 #include "core/platform/graphics/GraphicsContext.h"
58 #include "core/platform/network/ResourceError.h" 61 #include "core/platform/network/ResourceError.h"
59 #include "core/platform/network/ResourceRequest.h" 62 #include "core/platform/network/ResourceRequest.h"
60 #include "core/platform/network/ResourceResponse.h" 63 #include "core/platform/network/ResourceResponse.h"
61 #include "core/rendering/RenderView.h" 64 #include "core/rendering/RenderView.h"
62 #include "public/platform/Platform.h" 65 #include "public/platform/Platform.h"
63 #include "public/platform/WebRect.h" 66 #include "public/platform/WebRect.h"
64 #include "public/platform/WebString.h" 67 #include "public/platform/WebString.h"
65 #include "public/platform/WebURL.h" 68 #include "public/platform/WebURL.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 virtual void run() 183 virtual void run()
181 { 184 {
182 if (WebDevToolsAgent* webagent = m_descriptor->agent()) 185 if (WebDevToolsAgent* webagent = m_descriptor->agent())
183 webagent->dispatchOnInspectorBackend(m_descriptor->message()); 186 webagent->dispatchOnInspectorBackend(m_descriptor->message());
184 } 187 }
185 188
186 private: 189 private:
187 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor; 190 OwnPtr<WebDevToolsAgent::MessageDescriptor> m_descriptor;
188 }; 191 };
189 192
193 // FIXME: remove DeviceMetricsSupport.
pfeldman 2013/09/19 12:46:05 Do it right away.
190 class DeviceMetricsSupport { 194 class DeviceMetricsSupport {
191 public: 195 public:
192 DeviceMetricsSupport(WebViewImpl* webView) 196 DeviceMetricsSupport(WebViewImpl* webView)
193 : m_webView(webView) 197 : m_webView(webView)
194 , m_fitWindow(false) 198 , m_fitWindow(false)
195 , m_originalZoomFactor(0) 199 , m_originalZoomFactor(0)
196 { 200 {
197 } 201 }
198 202
199 ~DeviceMetricsSupport() 203 ~DeviceMetricsSupport()
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 double m_originalZoomFactor; 355 double m_originalZoomFactor;
352 }; 356 };
353 357
354 WebDevToolsAgentImpl::WebDevToolsAgentImpl( 358 WebDevToolsAgentImpl::WebDevToolsAgentImpl(
355 WebViewImpl* webViewImpl, 359 WebViewImpl* webViewImpl,
356 WebDevToolsAgentClient* client) 360 WebDevToolsAgentClient* client)
357 : m_hostId(client->hostIdentifier()) 361 : m_hostId(client->hostIdentifier())
358 , m_client(client) 362 , m_client(client)
359 , m_webViewImpl(webViewImpl) 363 , m_webViewImpl(webViewImpl)
360 , m_attached(false) 364 , m_attached(false)
365 , m_deviceMetricsEnabled(false)
pfeldman 2013/09/19 12:46:05 You need to initialize all booleans here.
dgozman 2013/09/19 13:59:38 Done.
361 { 366 {
362 ASSERT(m_hostId > 0); 367 ASSERT(m_hostId > 0);
363 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client); 368 ClientMessageLoopAdapter::ensureClientMessageLoopCreated(m_client);
364 } 369 }
365 370
366 WebDevToolsAgentImpl::~WebDevToolsAgentImpl() 371 WebDevToolsAgentImpl::~WebDevToolsAgentImpl()
367 { 372 {
368 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl); 373 ClientMessageLoopAdapter::inspectedViewClosed(m_webViewImpl);
369 if (m_attached) 374 if (m_attached)
370 WebKit::Platform::current()->currentThread()->removeTaskObserver(this); 375 WebKit::Platform::current()->currentThread()->removeTaskObserver(this);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 446 }
442 447
443 void WebDevToolsAgentImpl::mainFrameViewCreated(WebFrameImpl* webFrame) 448 void WebDevToolsAgentImpl::mainFrameViewCreated(WebFrameImpl* webFrame)
444 { 449 {
445 if (m_metricsSupport) 450 if (m_metricsSupport)
446 m_metricsSupport->applySizeOverrideIfNecessary(); 451 m_metricsSupport->applySizeOverrideIfNecessary();
447 } 452 }
448 453
449 bool WebDevToolsAgentImpl::metricsOverridden() 454 bool WebDevToolsAgentImpl::metricsOverridden()
450 { 455 {
451 return !!m_metricsSupport; 456 // FIXME: cleanup usages of this function and remove it.
pfeldman 2013/09/19 12:46:05 ditto
457 return false;
452 } 458 }
453 459
454 void WebDevToolsAgentImpl::webViewResized(const WebSize& size) 460 void WebDevToolsAgentImpl::webViewResized(const WebSize& size)
455 { 461 {
456 if (m_metricsSupport) 462 if (m_metricsSupport)
457 m_metricsSupport->webViewResized(); 463 m_metricsSupport->webViewResized();
458 if (InspectorController* ic = inspectorController()) 464 if (InspectorController* ic = inspectorController())
459 ic->webViewResized(m_metricsSupport ? IntSize(size.width, size.height) : IntSize()); 465 ic->webViewResized(m_metricsSupport ? IntSize(size.width, size.height) : IntSize());
460 } 466 }
461 467
(...skipping 18 matching lines...) Expand all
480 } 486 }
481 if (WebInputEvent::isTouchEventType(inputEvent.type)) { 487 if (WebInputEvent::isTouchEventType(inputEvent.type)) {
482 PlatformTouchEvent touchEvent = PlatformTouchEventBuilder(page->mainFram e()->view(), *static_cast<const WebTouchEvent*>(&inputEvent)); 488 PlatformTouchEvent touchEvent = PlatformTouchEventBuilder(page->mainFram e()->view(), *static_cast<const WebTouchEvent*>(&inputEvent));
483 return ic->handleTouchEvent(page->mainFrame(), touchEvent); 489 return ic->handleTouchEvent(page->mainFrame(), touchEvent);
484 } 490 }
485 return false; 491 return false;
486 } 492 }
487 493
488 void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fo ntScaleFactor, bool fitWindow) 494 void WebDevToolsAgentImpl::overrideDeviceMetrics(int width, int height, float fo ntScaleFactor, bool fitWindow)
489 { 495 {
496 // FIXME: enable viewport after UI problems with pageScaleFactor will be fix ed.
497 bool enableViewport = false;
498
499 bool needReload = false;
490 if (!width && !height) { 500 if (!width && !height) {
491 if (m_metricsSupport) 501 if (m_deviceMetricsEnabled) {
492 m_metricsSupport.clear(); 502 needReload = true;
493 if (InspectorController* ic = inspectorController()) 503 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(m_isOverlayScrol lbarsEnabled);
494 ic->webViewResized(IntSize()); 504 if (enableViewport) {
495 return; 505 RuntimeEnabledFeatures::setCSSViewportEnabled(m_isCSSViewportEna bled);
506 m_webViewImpl->enableFixedLayoutMode(false);
507 m_webViewImpl->settings()->setViewportEnabled(false);
508 m_webViewImpl->page()->settings().setTextAutosizingEnabled(false );
509 m_webViewImpl->setIgnoreViewportTagScaleLimits(false);
510 m_webViewImpl->setPageScaleFactorLimits(1.f, 1.f);
apavlov 2013/09/19 12:47:57 Is the float literal notation really required here
dgozman 2013/09/19 13:59:38 Done.
511 }
512 m_webViewImpl->client()->emulateDevice(false /* enabled */, IntSize( ), IntRect(), 1.0f, false);
513 }
514 m_deviceMetricsEnabled = false;
515 } else {
516 if (!m_deviceMetricsEnabled) {
517 needReload = true;
518
519 m_isOverlayScrollbarsEnabled = RuntimeEnabledFeatures::overlayScroll barsEnabled();
520 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
521
522 if (enableViewport) {
523 m_isCSSViewportEnabled = RuntimeEnabledFeatures::cssViewportEnab led();
524 RuntimeEnabledFeatures::setCSSViewportEnabled(true);
525 // FIXME: save and restore next two values.
apavlov 2013/09/19 12:47:57 Guess this comment should note that this should be
dgozman 2013/09/19 13:59:38 Nice catch! Thanks.
526 m_webViewImpl->enableFixedLayoutMode(true);
527 m_webViewImpl->settings()->setViewportEnabled(true);
528 m_webViewImpl->page()->settings().setTextAutosizingEnabled(true) ;
apavlov 2013/09/19 12:47:57 This one is dubious. Text autosizing should be ena
dgozman 2013/09/19 13:59:38 Safari, Firefox and IE has this functionality. Add
529 m_webViewImpl->setIgnoreViewportTagScaleLimits(fontScaleFactor > 1.f);
530 m_webViewImpl->setPageScaleFactorLimits(-1.f, -1.f);
531 }
532 }
533 if (enableViewport)
534 m_webViewImpl->page()->settings().setTextAutosizingFontScaleFactor(f ontScaleFactor);
535
536 m_webViewImpl->client()->emulateDevice(true /* enabled */, IntSize(width , height), IntRect(0, 0, width, height), 2.0f, fitWindow);
537 m_deviceMetricsEnabled = true;
496 } 538 }
539 if (needReload && m_webViewImpl->mainFrameImpl())
540 m_webViewImpl->mainFrameImpl()->reload(false /* ignoreCache */);
541 }
497 542
498 if (!m_metricsSupport) 543 void WebDevToolsAgentImpl::setDeviceEmulationScales(bool enabled, float deviceSc aleFactor, float rootLayerScale)
499 m_metricsSupport = adoptPtr(new DeviceMetricsSupport(m_webViewImpl)); 544 {
500 545 m_webViewImpl->setDeviceEmulationScales(enabled, deviceScaleFactor, rootLaye rScale);
501 m_metricsSupport->setDeviceMetrics(width, height, fontScaleFactor, fitWindow );
502 if (InspectorController* ic = inspectorController()) {
503 WebSize size = m_webViewImpl->size();
504 ic->webViewResized(IntSize(size.width, size.height));
505 }
506 } 546 }
507 547
508 void WebDevToolsAgentImpl::autoZoomPageToFitWidth() 548 void WebDevToolsAgentImpl::autoZoomPageToFitWidth()
509 { 549 {
510 if (m_metricsSupport) 550 if (m_metricsSupport)
511 m_metricsSupport->autoZoomPageToFitWidthOnNavigation(m_webViewImpl->main FrameImpl()->frame()); 551 m_metricsSupport->autoZoomPageToFitWidthOnNavigation(m_webViewImpl->main FrameImpl()->frame());
512 } 552 }
513 553
514 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set) 554 void WebDevToolsAgentImpl::getAllocatedObjects(HashSet<const void*>& set)
515 { 555 {
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack endDispatcher::kProfiler_getCPUProfileCmd] 796 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack endDispatcher::kProfiler_getCPUProfileCmd]
757 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack endDispatcher::kHeapProfiler_getHeapSnapshotCmd]; 797 || commandName == InspectorBackendDispatcher::commandNames[InspectorBack endDispatcher::kHeapProfiler_getHeapSnapshotCmd];
758 } 798 }
759 799
760 void WebDevToolsAgent::processPendingMessages() 800 void WebDevToolsAgent::processPendingMessages()
761 { 801 {
762 PageScriptDebugServer::shared().runPendingTasks(); 802 PageScriptDebugServer::shared().runPendingTasks();
763 } 803 }
764 804
765 } // namespace WebKit 805 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698