Bug 960822 - Limit the Shrink-To-Fit scaling for documents with a text-ish content type so that the content is still visible with extremely long lines. r=dholbert
authorMats Palmgren <matspal@gmail.com>
Tue, 04 Feb 2014 02:12:13 +0000
changeset 183891 53489b3e14f154401cd62ea6e9f5c66d4ae24d50
parent 183890 0b8fdcee7a26e0ea75e2dff4b8960d093e0d0ece
child 183892 c66ebc9414790067d63b0dfbc7263ecf8d9fa650
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs960822
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 960822 - Limit the Shrink-To-Fit scaling for documents with a text-ish content type so that the content is still visible with extremely long lines. r=dholbert
layout/printing/nsPrintEngine.cpp
layout/reftests/printing/960822-ref.html
layout/reftests/printing/960822.html
layout/reftests/printing/reftest.list
modules/libpref/src/init/all.js
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2028,16 +2028,32 @@ nsPrintEngine::UpdateSelectionAndShrinkP
   // we must first locate the "pageContent" frame
   // Then we walk the frame tree and look for the "xmost" frame
   // this is the frame where the right-hand side of the frame extends
   // the furthest
   if (mPrt->mShrinkToFit && aDocumentIsTopLevel) {
     nsIPageSequenceFrame* pageSequence = aPO->mPresShell->GetPageSequenceFrame();
     NS_ENSURE_STATE(pageSequence);
     pageSequence->GetSTFPercent(aPO->mShrinkRatio);
+    // Limit the shrink-to-fit scaling for some text-ish type of documents.
+    nsAutoString contentType;
+    aPO->mPresShell->GetDocument()->GetContentType(contentType);
+    bool applyLimit = contentType.EqualsLiteral("application/xhtml+xml");
+    if (contentType.Length() > 5) {
+      contentType.Truncate(5);
+    }
+    applyLimit = applyLimit || contentType.EqualsLiteral("text/");
+    if (applyLimit) {
+      int32_t limitPercent = 
+        Preferences::GetInt("print.shrink-to-fit.scale-limit-percent", 20);
+      limitPercent = std::max(0, limitPercent);
+      limitPercent = std::min(100, limitPercent);
+      float minShrinkRatio = float(limitPercent) / 100;
+      aPO->mShrinkRatio = std::max(aPO->mShrinkRatio, minShrinkRatio);
+    }
   }
   return NS_OK;
 }
 
 bool
 nsPrintEngine::DoSetPixelScale()
 {
   // This is an Optimization
new file mode 100644
--- /dev/null
+++ b/layout/reftests/printing/960822-ref.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html class="reftest-print">
+<head><meta charset="utf-8"></head>
+<body>
+<div style="width:100in; border:solid blue;">line</div>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/printing/960822.html
@@ -0,0 +1,7 @@
+<!DOCTYPE html>
+<html class="reftest-print">
+<head><meta charset="utf-8"></head>
+<body>
+<div style="width:30in; border:solid blue;">line</div>
+</body>
+</html>
--- a/layout/reftests/printing/reftest.list
+++ b/layout/reftests/printing/reftest.list
@@ -21,10 +21,14 @@
 == 626395-2d.html 626395-2-ref.html
 == 652178-1.html 652178-1-ref.html
 == 115199-1.html 115199-1-ref.html
 == 115199-2a.html 115199-2-ref.html
 == 115199-2b.html 115199-2-ref.html
 == 652178-1.html 652178-1-ref2.html
 fuzzy-if(cocoaWidget,1,5000) fuzzy-if(/^Windows\x20NT\x206\.1/.test(http.oscpu),255,100) == 745025-1.html 745025-1-ref.html
 == 820496-1.html 820496-1-ref.html
+
+# NOTE: These tests don't yet rigorously test what they're
+# trying to test (shrink-to-fit behavior), due to bug 967311.
+== 960822.html 960822-ref.html
 == 966419-1.html 966419-1-ref.html
 == 966419-2.html 966419-2-ref.html
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -166,16 +166,19 @@ pref("browser.chrome.toolbar_tips",     
 // 0 = Pictures Only, 1 = Text Only, 2 = Pictures and Text
 pref("browser.chrome.toolbar_style",        2);
 // max image size for which it is placed in the tab icon for tabbrowser.
 // if 0, no images are used for tab icons for image documents.
 pref("browser.chrome.image_icons.max_size", 1024);
 
 pref("browser.triple_click_selects_paragraph", true);
 
+// Print/Preview Shrink-To-Fit won't shrink below 20% for text-ish documents.
+pref("print.shrink-to-fit.scale-limit-percent", 20);
+
 // Media cache size in kilobytes
 pref("media.cache_size", 512000);
 
 // Master HTML5 media volume scale.
 pref("media.volume_scale", "1.0");
 
 // Timeout for wakelock release
 pref("media.wakelock_timeout", 2000);