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

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: Address reviewer comments 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
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, bool textAutosizing )
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 if (!deviceMetricsChanged(width, height, deviceScaleFactor, fitWindow, textA utosizing))
682 return; 685 return;
683 686
684 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width); 687 m_state->setLong(PageAgentState::pageAgentScreenWidthOverride, width);
685 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height); 688 m_state->setLong(PageAgentState::pageAgentScreenHeightOverride, height);
686 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, devic eScaleFactor); 689 m_state->setDouble(PageAgentState::pageAgentDeviceScaleFactorOverride, devic eScaleFactor);
687 m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow); 690 m_state->setBoolean(PageAgentState::pageAgentFitWindow, fitWindow);
691 m_state->setBoolean(PageAgentState::pageAgentTextAutosizingOverride, textAut osizing);
688 692
689 updateViewMetrics(width, height, deviceScaleFactor, fitWindow); 693 updateViewMetrics(width, height, deviceScaleFactor, fitWindow, textAutosizin g);
690 } 694 }
691 695
692 bool InspectorPageAgent::deviceMetricsChanged(int width, int height, double devi ceScaleFactor, bool fitWindow) 696 bool InspectorPageAgent::deviceMetricsChanged(int width, int height, double devi ceScaleFactor, bool fitWindow, bool textAutosizing)
693 { 697 {
694 // These two always fit an int. 698 // These two always fit an int.
695 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride)); 699 int currentWidth = static_cast<int>(m_state->getLong(PageAgentState::pageAge ntScreenWidthOverride));
696 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAg entScreenHeightOverride)); 700 int currentHeight = static_cast<int>(m_state->getLong(PageAgentState::pageAg entScreenHeightOverride));
697 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pageAge ntDeviceScaleFactorOverride, 1); 701 double currentDeviceScaleFactor = m_state->getDouble(PageAgentState::pageAge ntDeviceScaleFactorOverride, 1);
698 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWind ow); 702 bool currentFitWindow = m_state->getBoolean(PageAgentState::pageAgentFitWind ow);
703 bool currentTextAutosizing = m_state->getBoolean(PageAgentState::pageAgentTe xtAutosizingOverride);
699 704
700 return width != currentWidth || height != currentHeight || deviceScaleFactor != currentDeviceScaleFactor || fitWindow != currentFitWindow; 705 return width != currentWidth || height != currentHeight || deviceScaleFactor != currentDeviceScaleFactor || fitWindow != currentFitWindow || textAutosizing != currentTextAutosizing;
701 } 706 }
702 707
703 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show) 708 void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show)
704 { 709 {
705 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show); 710 m_state->setBoolean(PageAgentState::pageAgentShowPaintRects, show);
706 m_client->setShowPaintRects(show); 711 m_client->setShowPaintRects(show);
707 712
708 if (!show && mainFrame() && mainFrame()->view()) 713 if (!show && mainFrame() && mainFrame()->view())
709 mainFrame()->view()->invalidate(); 714 mainFrame()->view()->invalidate();
710 } 715 }
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree( )->nextSibling()) { 1075 for (Frame* child = frame->tree()->firstChild(); child; child = child->tree( )->nextSibling()) {
1071 if (!childrenArray) { 1076 if (!childrenArray) {
1072 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create(); 1077 childrenArray = TypeBuilder::Array<TypeBuilder::Page::FrameResourceT ree>::create();
1073 result->setChildFrames(childrenArray); 1078 result->setChildFrames(childrenArray);
1074 } 1079 }
1075 childrenArray->addItem(buildObjectForFrameTree(child)); 1080 childrenArray->addItem(buildObjectForFrameTree(child));
1076 } 1081 }
1077 return result; 1082 return result;
1078 } 1083 }
1079 1084
1080 void InspectorPageAgent::updateViewMetrics(int width, int height, double deviceS caleFactor, bool fitWindow) 1085 void InspectorPageAgent::updateViewMetrics(int width, int height, double deviceS caleFactor, bool fitWindow, bool textAutosizing)
1081 { 1086 {
1082 m_client->overrideDeviceMetrics(width, height, static_cast<float>(deviceScal eFactor), fitWindow); 1087 m_client->overrideDeviceMetrics(width, height, static_cast<float>(deviceScal eFactor), fitWindow);
1083 1088
1089 Settings& settings = m_page->settings();
1090 if (m_enabled && textAutosizing) {
1091 // FIXME(crbug.com/308800): overriding device metrics results in an inco rrect layout width.
1092 // This workaround can be removed once that bug is fixed.
1093 IntSize textAutosizingWindowSizeOverride = IntSize(width, height);
1094 textAutosizingWindowSizeOverride.scale((float)(1.0 / deviceScaleFactor)) ;
1095 settings.setTextAutosizingWindowSizeOverride(textAutosizingWindowSizeOve rride);
1096 }
1097
1084 Document* document = mainFrame()->document(); 1098 Document* document = mainFrame()->document();
1085 if (document) 1099 if (document)
1086 document->styleResolverChanged(RecalcStyleImmediately); 1100 document->styleResolverChanged(RecalcStyleImmediately);
1087 InspectorInstrumentation::mediaQueryResultChanged(document); 1101 InspectorInstrumentation::mediaQueryResultChanged(document);
1088 m_overlay->setOverride(InspectorOverlay::DeviceMetricsOverride, width && hei ght); 1102 m_overlay->setOverride(InspectorOverlay::DeviceMetricsOverride, width && hei ght);
1089 1103
1090 // FIXME: allow metrics override, fps counter and continuous painting at the same time: crbug.com/299837. 1104 // FIXME: allow metrics override, fps counter and continuous painting at the same time: crbug.com/299837.
1091 bool override = width && height; 1105 bool override = width && height;
1092 m_client->setShowFPSCounter(m_state->getBoolean(PageAgentState::pageAgentSho wFPSCounter) && !override); 1106 m_client->setShowFPSCounter(m_state->getBoolean(PageAgentState::pageAgentSho wFPSCounter) && !override);
1093 m_client->setContinuousPaintingEnabled(m_state->getBoolean(PageAgentState::p ageAgentContinuousPaintingEnabled) && !override); 1107 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); 1198 m_overlay->setOverride(InspectorOverlay::DeviceOrientationOverride, false);
1185 } 1199 }
1186 1200
1187 DeviceOrientationData* InspectorPageAgent::overrideDeviceOrientation(DeviceOrien tationData* deviceOrientation) 1201 DeviceOrientationData* InspectorPageAgent::overrideDeviceOrientation(DeviceOrien tationData* deviceOrientation)
1188 { 1202 {
1189 if (m_deviceOrientation) 1203 if (m_deviceOrientation)
1190 deviceOrientation = m_deviceOrientation.get(); 1204 deviceOrientation = m_deviceOrientation.get();
1191 return deviceOrientation; 1205 return deviceOrientation;
1192 } 1206 }
1193 1207
1208 bool InspectorPageAgent::overrideTextAutosizing(bool textAutosizing)
1209 {
1210 if (m_enabled)
1211 return m_state->getBoolean(PageAgentState::pageAgentTextAutosizingOverri de);
skobes 2013/10/18 17:17:07 Does this handle the case where the inspector is e
pfeldman 2013/10/18 17:26:52 Yeah, I guess you are right. It should be if (m_en
pdr. 2013/10/18 18:46:09 Done.
1212 return textAutosizing;
1213 }
1214
1194 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled) 1215 void InspectorPageAgent::setTouchEmulationEnabled(ErrorString*, bool enabled)
1195 { 1216 {
1196 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed) 1217 if (m_state->getBoolean(PageAgentState::touchEventEmulationEnabled) == enabl ed)
1197 return; 1218 return;
1198 updateTouchEventEmulationInPage(enabled); 1219 updateTouchEventEmulationInPage(enabled);
1199 } 1220 }
1200 1221
1201 void InspectorPageAgent::setEmulatedMedia(ErrorString*, const String& media) 1222 void InspectorPageAgent::setEmulatedMedia(ErrorString*, const String& media)
1202 { 1223 {
1203 String currentMedia = m_state->getString(PageAgentState::pageAgentEmulatedMe dia); 1224 String currentMedia = m_state->getString(PageAgentState::pageAgentEmulatedMe dia);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1283 }
1263 1284
1264 void InspectorPageAgent::setShowViewportSizeOnResize(ErrorString*, bool show, co nst bool* showGrid) 1285 void InspectorPageAgent::setShowViewportSizeOnResize(ErrorString*, bool show, co nst bool* showGrid)
1265 { 1286 {
1266 m_state->setBoolean(PageAgentState::showSizeOnResize, show); 1287 m_state->setBoolean(PageAgentState::showSizeOnResize, show);
1267 m_state->setBoolean(PageAgentState::showGridOnResize, showGrid && *showGrid) ; 1288 m_state->setBoolean(PageAgentState::showGridOnResize, showGrid && *showGrid) ;
1268 } 1289 }
1269 1290
1270 } // namespace WebCore 1291 } // namespace WebCore
1271 1292
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698