Bug 1348208 part 3 - Add a pref to force showing broken image placeoholder. r?dbaron draft
authorXidorn Quan <me@upsuper.org>
Mon, 20 Mar 2017 11:28:37 +1100
changeset 501343 ff4aa66d039712fcefcaa8a1afca7af2306f4b29
parent 501342 5d65fc37426552d5701133a753e012396e980611
child 549837 b13a69957a4450e2e26d226c32df07a68c5eca4f
push id49935
push userxquan@mozilla.com
push dateMon, 20 Mar 2017 00:42:21 +0000
reviewersdbaron
bugs1348208
milestone55.0a1
Bug 1348208 part 3 - Add a pref to force showing broken image placeoholder. r?dbaron MozReview-Commit-ID: 5pvhf0c1Sbs
layout/generic/nsImageFrame.cpp
layout/generic/nsImageFrame.h
modules/libpref/init/all.js
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -451,26 +451,33 @@ nsImageFrame::ShouldCreateImageFrameFor(
                HaveSpecifiedSize(aStyleContext->StylePosition()))) {
     // Image is fine; do the image frame thing
     return true;
   }
 
   // Check if we want to use a placeholder box with an icon or just
   // let the presShell make us into inline text.  Decide as follows:
   //
+  //  - if our "force show broken placeholder" pref is set, force the
+  //    icon, else:
   //  - if our "do not show placeholders" pref is set, skip the icon
   //  - else:
   //  - if there is a src attribute, there is no alt attribute,
   //    and this is not an <object> (which could not possibly have
   //    such an attribute), show an icon.
   //  - if QuirksMode, and the IMG has a size show an icon.
   //  - otherwise, skip the icon
 
-  if (gIconLoad && gIconLoad->mPrefForceInlineAltText) {
-    return false;
+  if (gIconLoad) {
+    if (gIconLoad->mPrefForceShowBrokenPlaceholder) {
+      return true;
+    }
+    if (gIconLoad->mPrefForceInlineAltText) {
+      return false;
+    }
   }
   if (aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::src) &&
       !aElement->HasAttr(kNameSpaceID_None, nsGkAtoms::alt) &&
       !aElement->IsHTMLElement(nsGkAtoms::object) &&
       !aElement->IsHTMLElement(nsGkAtoms::input)) {
     // Use a sized box if we have no alt text.  This means no alt attribute
     // and the node is not an object or an input (since those always have alt
     // text).
@@ -2291,16 +2298,17 @@ nsresult nsImageFrame::LoadIcons(nsPresC
 
 NS_IMPL_ISUPPORTS(nsImageFrame::IconLoad, nsIObserver,
                   imgINotificationObserver)
 
 static const char* kIconLoadPrefs[] = {
   "browser.display.force_inline_alttext",
   "browser.display.show_image_placeholders",
   "browser.display.show_loading_image_placeholder",
+  "browser.display.force_show_broken_image_placeholder",
   nullptr
 };
 
 nsImageFrame::IconLoad::IconLoad()
 {
   // register observers
   Preferences::AddStrongObservers(this, kIconLoadPrefs);
   GetPrefs();
@@ -2346,16 +2354,19 @@ void nsImageFrame::IconLoad::GetPrefs()
   mPrefForceInlineAltText =
     Preferences::GetBool("browser.display.force_inline_alttext");
 
   mPrefShowPlaceholders =
     Preferences::GetBool("browser.display.show_image_placeholders", true);
 
   mPrefShowLoadingPlaceholder =
     Preferences::GetBool("browser.display.show_loading_image_placeholder", true);
+
+  mPrefForceShowBrokenPlaceholder =
+    Preferences::GetBool("browser.display.force_show_broken_image_placeholder");
 }
 
 NS_IMETHODIMP
 nsImageFrame::IconLoad::Notify(imgIRequest* aRequest,
                                int32_t aType,
                                const nsIntRect* aData)
 {
   MOZ_ASSERT(aRequest);
--- a/layout/generic/nsImageFrame.h
+++ b/layout/generic/nsImageFrame.h
@@ -387,16 +387,17 @@ private:
 
 
   public:
     RefPtr<imgRequestProxy> mLoadingImage;
     RefPtr<imgRequestProxy> mBrokenImage;
     bool             mPrefForceInlineAltText;
     bool             mPrefShowPlaceholders;
     bool             mPrefShowLoadingPlaceholder;
+    bool             mPrefForceShowBrokenPlaceholder;
   };
   
 public:
   static IconLoad* gIconLoad; // singleton pattern: one LoadIcons instance is used
   
   friend class nsDisplayImage;
 };
 
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -236,16 +236,20 @@ pref("browser.display.foreground_color",
 pref("browser.display.background_color",    "#FFFFFF");
 pref("browser.display.force_inline_alttext", false); // true = force ALT text for missing images to be layed out inline
 // 0 = no external leading,
 // 1 = use external leading only when font provides,
 // 2 = add extra leading both internal leading and external leading are zero
 pref("browser.display.normal_lineheight_calc_control", 2);
 // enable showing image placeholders while image is loading or when image is broken
 pref("browser.display.show_image_placeholders", true);
+// Force showing image placeholders when image is broken.
+// This requires browser.display.show_image_placeholders to work, and it
+// overrides browser.display.force_inline_alttext.
+pref("browser.display.force_show_broken_image_placeholder", false);
 // if browser.display.show_image_placeholders is true then this controls whether the loading image placeholder and border is shown or not
 pref("browser.display.show_loading_image_placeholder", false);
 // min font device pixel size at which to turn on high quality
 pref("browser.display.auto_quality_min_font_size", 20);
 pref("browser.anchor_color",                "#0000EE");
 pref("browser.active_color",                "#EE0000");
 pref("browser.visited_color",               "#551A8B");
 pref("browser.underline_anchors",           true);