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

Side by Side Diff: Source/core/inspector/InspectorPageAgent.cpp

Issue 26929003: Add text autosizing override in the inspector. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add optional flag in protocol.json Created 7 years, 2 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
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/core/page/Settings.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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 namespace PageAgentState { 82 namespace PageAgentState {
83 static const char pageAgentEnabled[] = "pageAgentEnabled"; 83 static const char pageAgentEnabled[] = "pageAgentEnabled";
84 static const char pageAgentScriptExecutionDisabled[] = "pageAgentScriptExecution Disabled"; 84 static const char pageAgentScriptExecutionDisabled[] = "pageAgentScriptExecution Disabled";
85 static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvalua teOnLoad"; 85 static const char pageAgentScriptsToEvaluateOnLoad[] = "pageAgentScriptsToEvalua teOnLoad";
86 static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride "; 86 static const char pageAgentScreenWidthOverride[] = "pageAgentScreenWidthOverride ";
87 static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverri de"; 87 static const char pageAgentScreenHeightOverride[] = "pageAgentScreenHeightOverri de";
88 static const char pageAgentDeviceScaleFactorOverride[] = "pageAgentDeviceScaleFa ctorOverride"; 88 static const char pageAgentDeviceScaleFactorOverride[] = "pageAgentDeviceScaleFa ctorOverride";
89 static const char pageAgentFitWindow[] = "pageAgentFitWindow"; 89 static const char pageAgentFitWindow[] = "pageAgentFitWindow";
90 static const char pageAgentShowFPSCounter[] = "pageAgentShowFPSCounter"; 90 static const char pageAgentShowFPSCounter[] = "pageAgentShowFPSCounter";
91 static const char pageAgentTextAutosizingOverride[] = "pageAgentTextAutosizingOv erride";
91 static const char pageAgentContinuousPaintingEnabled[] = "pageAgentContinuousPai ntingEnabled"; 92 static const char pageAgentContinuousPaintingEnabled[] = "pageAgentContinuousPai ntingEnabled";
92 static const char pageAgentShowPaintRects[] = "pageAgentShowPaintRects"; 93 static const char pageAgentShowPaintRects[] = "pageAgentShowPaintRects";
93 static const char pageAgentShowDebugBorders[] = "pageAgentShowDebugBorders"; 94 static const char pageAgentShowDebugBorders[] = "pageAgentShowDebugBorders";
94 static const char pageAgentShowScrollBottleneckRects[] = "pageAgentShowScrollBot tleneckRects"; 95 static const char pageAgentShowScrollBottleneckRects[] = "pageAgentShowScrollBot tleneckRects";
95 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled"; 96 static const char touchEventEmulationEnabled[] = "touchEventEmulationEnabled";
96 static const char pageAgentEmulatedMedia[] = "pageAgentEmulatedMedia"; 97 static const char pageAgentEmulatedMedia[] = "pageAgentEmulatedMedia";
97 static const char showSizeOnResize[] = "showSizeOnResize"; 98 static const char showSizeOnResize[] = "showSizeOnResize";
98 static const char showGridOnResize[] = "showGridOnResize"; 99 static const char showGridOnResize[] = "showGridOnResize";
99 static const char forceCompositingMode[] = "forceCompositingMode"; 100 static const char forceCompositingMode[] = "forceCompositingMode";
100 } 101 }
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 setEmulatedMedia(0, emulatedMedia); 356 setEmulatedMedia(0, emulatedMedia);
356 bool continuousPaintingEnabled = m_state->getBoolean(PageAgentState::pag eAgentContinuousPaintingEnabled); 357 bool continuousPaintingEnabled = m_state->getBoolean(PageAgentState::pag eAgentContinuousPaintingEnabled);
357 setContinuousPaintingEnabled(0, continuousPaintingEnabled); 358 setContinuousPaintingEnabled(0, continuousPaintingEnabled);
358 bool showScrollBottleneckRects = m_state->getBoolean(PageAgentState::pag eAgentShowScrollBottleneckRects); 359 bool showScrollBottleneckRects = m_state->getBoolean(PageAgentState::pag eAgentShowScrollBottleneckRects);
359 setShowScrollBottleneckRects(0, showScrollBottleneckRects); 360 setShowScrollBottleneckRects(0, showScrollBottleneckRects);
360 361
361 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pag eAgentScreenWidthOverride)); 362 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pag eAgentScreenWidthOverride));
362 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pa geAgentScreenHeightOverride)); 363 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pa geAgentScreenHeightOverride));
363 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pag eAgentDeviceScaleFactorOverride); 364 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pag eAgentDeviceScaleFactorOverride);
364 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFit Window); 365 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFit Window);
365 updateViewMetrics(currentWidth, currentHeight, currentDeviceScaleFactor, currentFitWindow); 366 bool currentTextAutosizing = m_state->getBoolean(PageAgentState::pageAge ntTextAutosizingOverride);
367 updateViewMetrics(currentWidth, currentHeight, currentDeviceScaleFactor, currentFitWindow, currentTextAutosizing);
366 updateTouchEventEmulationInPage(m_state->getBoolean(PageAgentState::touc hEventEmulationEnabled)); 368 updateTouchEventEmulationInPage(m_state->getBoolean(PageAgentState::touc hEventEmulationEnabled));
367 } 369 }
368 } 370 }
369 371
370 void InspectorPageAgent::webViewResized(const IntSize& size) 372 void InspectorPageAgent::webViewResized(const IntSize& size)
371 { 373 {
372 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride)); 374 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride));
373 m_overlay->resize(currentWidth ? size : IntSize()); 375 m_overlay->resize(currentWidth ? size : IntSize());
374 } 376 }
375 377
(...skipping 15 matching lines...) Expand all
391 setShowPaintRects(0, false); 393 setShowPaintRects(0, false);
392 setShowDebugBorders(0, false); 394 setShowDebugBorders(0, false);
393 setShowFPSCounter(0, false); 395 setShowFPSCounter(0, false);
394 setEmulatedMedia(0, String()); 396 setEmulatedMedia(0, String());
395 setContinuousPaintingEnabled(0, false); 397 setContinuousPaintingEnabled(0, false);
396 setShowScrollBottleneckRects(0, false); 398 setShowScrollBottleneckRects(0, false);
397 setShowViewportSizeOnResize(0, false, 0); 399 setShowViewportSizeOnResize(0, false, 0);
398 if (m_didForceCompositingMode) 400 if (m_didForceCompositingMode)
399 setForceCompositingMode(0, false); 401 setForceCompositingMode(0, false);
400 402
401 if (!deviceMetricsChanged(0, 0, 1, false)) 403 if (!deviceMetricsChanged(0, 0, 1, false, false))
402 return; 404 return;
403 405
404 // When disabling the agent, reset the override values if necessary. 406 // When disabling the agent, reset the override values if necessary.
405 updateViewMetrics(0, 0, 1, false); 407 updateViewMetrics(0, 0, 1, false, false);
406 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0); 408 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, 0);
407 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0); 409 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, 0);
408 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, 1); 410 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, 1);
409 m_state->setBoolean(PageAgentState::pageAgentFitWindow, false); 411 m_state->setBoolean(PageAgentState::pageAgentFitWindow, false);
412 m_state->setBoolean(PageAgentState::pageAgentTextAutosizingOverride, false);
410 } 413 }
411 414
412 void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& s ource, String* identifier) 415 void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& s ource, String* identifier)
413 { 416 {
414 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad); 417 RefPtr<JSONObject> scripts = m_state->getObject(PageAgentState::pageAgentScr iptsToEvaluateOnLoad);
415 if (!scripts) { 418 if (!scripts) {
416 scripts = JSONObject::create(); 419 scripts = JSONObject::create();
417 m_state->setObject(PageAgentState::pageAgentScriptsToEvaluateOnLoad, scr ipts); 420 m_state->setObject(PageAgentState::pageAgentScriptsToEvaluateOnLoad, scr ipts);
418 } 421 }
419 // Assure we don't override existing ids -- m_lastScriptIdentifier could get out of sync WRT actual 422 // Assure we don't override existing ids -- m_lastScriptIdentifier could get out of sync WRT actual
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 return; 655 return;
653 656
654 Document* document = frame->document(); 657 Document* document = frame->document();
655 if (!document) { 658 if (!document) {
656 *errorString = "No Document instance to set HTML for"; 659 *errorString = "No Document instance to set HTML for";
657 return; 660 return;
658 } 661 }
659 DOMPatchSupport::patchDocument(*document, html); 662 DOMPatchSupport::patchDocument(*document, html);
660 } 663 }
661 664
662 void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, int width, int height, double deviceScaleFactor, bool fitWindow) 665 void InspectorPageAgent::setDeviceMetricsOverride(ErrorString* errorString, int width, int height, double deviceScaleFactor, bool fitWindow, const bool* optiona lTextAutosizing)
663 { 666 {
664 const static long maxDimension = 10000000; 667 const static long maxDimension = 10000000;
665 668
666 if (width < 0 || height < 0 || width > maxDimension || height > maxDimension ) { 669 if (width < 0 || height < 0 || width > maxDimension || height > maxDimension ) {
667 *errorString = "Width and height values must be positive, not greater th an " + String::number(maxDimension); 670 *errorString = "Width and height values must be positive, not greater th an " + String::number(maxDimension);
668 return; 671 return;
669 } 672 }
670 673
671 if (!width ^ !height) { 674 if (!width ^ !height) {
672 *errorString = "Both width and height must be either zero or non-zero at once"; 675 *errorString = "Both width and height must be either zero or non-zero at once";
673 return; 676 return;
674 } 677 }
675 678
676 if (deviceScaleFactor <= 0) { 679 if (deviceScaleFactor <= 0) {
677 *errorString = "deviceScaleFactor must be positive"; 680 *errorString = "deviceScaleFactor must be positive";
678 return; 681 return;
679 } 682 }
680 683
681 if (!deviceMetricsChanged(width, height, deviceScaleFactor, fitWindow)) 684 bool textAutosizing = optionalTextAutosizing ? *optionalTextAutosizing : fal se;
685
686 if (!deviceMetricsChanged(width, height, deviceScaleFactor, fitWindow, textA utosizing))
682 return; 687 return;
683 688
684 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width); 689 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width);
685 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height); 690 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height);
686 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, devic eScaleFactor); 691 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, devic eScaleFactor);
687 m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow); 692 m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow);
693 m_state->setBoolean(PageAgentState::pageAgentTextAutosizingOverride, textAut osizing);
688 694
689 updateViewMetrics(width, height, deviceScaleFactor, fitWindow); 695 updateViewMetrics(width, height, deviceScaleFactor, fitWindow, textAutosizin g);
690 } 696 }
691 697
692 bool InspectorPageAgent::deviceMetricsChanged(int width, int height, double devi ceScaleFactor, bool fitWindow) 698 bool InspectorPageAgent::deviceMetricsChanged(int width, int height, double devi ceScaleFactor, bool fitWindow, bool textAutosizing)
693 { 699 {
694 // These two always fit an int. 700 // These two always fit an int.
695 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride)); 701 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride));
696 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAg entScreenHeightOverride)); 702 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAg entScreenHeightOverride));
697 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pageAge ntDeviceScaleFactorOverride, 1); 703 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pageAge ntDeviceScaleFactorOverride, 1);
698 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWind ow); 704 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWind ow);
705 bool currentTextAutosizing = m_state->getBoolean(PageAgentState::pageAgentTe xtAutosizingOverride);
699 706
700 return width != currentWidth || height != currentHeight || deviceScaleFactor != currentDeviceScaleFactor || fitWindow != currentFitWindow; 707 return width != currentWidth || height != currentHeight || deviceScaleFactor != currentDeviceScaleFactor || fitWindow != currentFitWindow || textAutosizing != currentTextAutosizing;
701 } 708 }
702 709
703 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show) 710 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show)
704 { 711 {
705 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show); 712 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show);
706 m_client->setShowPaintRects(show); 713 m_client->setShowPaintRects(show);
707 714
708 if (!show && mainFrame() && mainFrame()->view()) 715 if (!show && mainFrame() && mainFrame()->view())
709 mainFrame()->view()->invalidate(); 716 mainFrame()->view()->invalidate();
710 } 717 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree( )->nextSibling()) { 1077 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree( )->nextSibling()) {
1071 if (!childrenArray) { 1078 if (!childrenArray) {
1072 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create(); 1079 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create();
1073 result->setChildFrames(childrenArray); 1080 result->setChildFrames(childrenArray);
1074 } 1081 }
1075 childrenArray->addItem(buildObjectForFrameTree(child)); 1082 childrenArray->addItem(buildObjectForFrameTree(child));
1076 } 1083 }
1077 return result; 1084 return result;
1078 } 1085 }
1079 1086
1080 void InspectorPageAgent::updateViewMetrics(int width, int height, double deviceS caleFactor, bool fitWindow) 1087 void InspectorPageAgent::updateViewMetrics(int width, int height, double deviceS caleFactor, bool fitWindow, bool textAutosizing)
1081 { 1088 {
1082 m_client->overrideDeviceMetrics(width, height, static_cast<float>(deviceScal eFactor), fitWindow); 1089 m_client->overrideDeviceMetrics(width, height, static_cast<float>(deviceScal eFactor), fitWindow);
1083 1090
1091 Settings& settings = m_page->settings();
1092 if (m_enabled && textAutosizing) {
1093 // FIXME(crbug.com/308800): overriding device metrics results in an inco rrect layout width.
1094 // This workaround can be removed once that bug is fixed.
1095 IntSize textAutosizingWindowSizeOverride = IntSize(width, height);
1096 textAutosizingWindowSizeOverride.scale((float)(1.0 / deviceScaleFactor)) ;
1097 settings.setTextAutosizingWindowSizeOverride(textAutosizingWindowSizeOve rride);
1098 }
1099
1084 Document* document = mainFrame()->document(); 1100 Document* document = mainFrame()->document();
1085 if (document) 1101 if (document)
1086 document->styleResolverChanged(RecalcStyleImmediately); 1102 document->styleResolverChanged(RecalcStyleImmediately);
1087 InspectorInstrumentation::mediaQueryResultChanged(document); 1103 InspectorInstrumentation::mediaQueryResultChanged(document);
1088 m_overlay->setOverride(InspectorOverlay::DeviceMetricsOverride, width && hei ght); 1104 m_overlay->setOverride(InspectorOverlay::DeviceMetricsOverride, width && hei ght);
1089 1105
1090 // FIXME: allow metrics override, fps counter and continuous painting at the same time: crbug.com/299837. 1106 // FIXME: allow metrics override, fps counter and continuous painting at the same time: crbug.com/299837.
1091 bool override = width && height; 1107 bool override = width && height;
1092 m_client->setShowFPSCounter(m_state->getBoolean(PageAgentState::pageAgentSho wFPSCounter) && !override); 1108 m_client->setShowFPSCounter(m_state->getBoolean(PageAgentState::pageAgentSho wFPSCounter) && !override);
1093 m_client->setContinuousPaintingEnabled(m_state->getBoolean(PageAgentState::p ageAgentContinuousPaintingEnabled) && !override); 1109 m_client->setContinuousPaintingEnabled(m_state->getBoolean(PageAgentState::p ageAgentContinuousPaintingEnabled) && !override);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1184 m_overlay->setOverride(InspectorOverlay::DeviceOrientationOverride, false); 1200 m_overlay->setOverride(InspectorOverlay::DeviceOrientationOverride, false);
1185 } 1201 }
1186 1202
1187 DeviceOrientationData* InspectorPageAgent::overrideDeviceOrientation(DeviceOrien tationData* deviceOrientation) 1203 DeviceOrientationData* InspectorPageAgent::overrideDeviceOrientation(DeviceOrien tationData* deviceOrientation)
1188 { 1204 {
1189 if (m_deviceOrientation) 1205 if (m_deviceOrientation)
1190 deviceOrientation = m_deviceOrientation.get(); 1206 deviceOrientation = m_deviceOrientation.get();
1191 return deviceOrientation; 1207 return deviceOrientation;
1192 } 1208 }
1193 1209
1210 bool InspectorPageAgent::overrideTextAutosizing(bool textAutosizing)
1211 {
1212 if (m_enabled)
1213 return m_state->getBoolean(PageAgentState::pageAgentTextAutosizingOverri de);
1214 return textAutosizing;
1215 }
1216
1194 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled) 1217 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled)
1195 { 1218 {
1196 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed) 1219 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed)
1197 return; 1220 return;
1198 updateTouchEventEmulationInPage(enabled); 1221 updateTouchEventEmulationInPage(enabled);
1199 } 1222 }
1200 1223
1201 void InspectorPageAgent::setEmulatedMedia(ErrorString*, const String& media) 1224 void InspectorPageAgent::setEmulatedMedia(ErrorString*, const String& media)
1202 { 1225 {
1203 String currentMedia = m_state->getString(PageAgentState::pageAgentEmulatedMe dia); 1226 String currentMedia = m_state->getString(PageAgentState::pageAgentEmulatedMe dia);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1285 }
1263 1286
1264 void InspectorPageAgent::setShowViewportSizeOnResize(ErrorString*, bool show, co nst bool* showGrid) 1287 void InspectorPageAgent::setShowViewportSizeOnResize(ErrorString*, bool show, co nst bool* showGrid)
1265 { 1288 {
1266 m_state->setBoolean(PageAgentState::showSizeOnResize, show); 1289 m_state->setBoolean(PageAgentState::showSizeOnResize, show);
1267 m_state->setBoolean(PageAgentState::showGridOnResize, showGrid && *showGrid) ; 1290 m_state->setBoolean(PageAgentState::showGridOnResize, showGrid && *showGrid) ;
1268 } 1291 }
1269 1292
1270 } // namespace WebCore 1293 } // namespace WebCore
1271 1294
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/core/page/Settings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698