summaryrefslogtreecommitdiffstats
path: root/dom/html/ImageDocument.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-08-20 13:11:56 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-08-20 13:31:38 +0200
commitb5ee49d85ae054c0176248c1c4f5b84b57afcb1f (patch)
tree2eb441c87ff39bb79e51219ef3e3adbc3a268de4 /dom/html/ImageDocument.cpp
parent134fdc7ec46c242baf924db8e3fea9f360d21e73 (diff)
downloadUXP-b5ee49d85ae054c0176248c1c4f5b84b57afcb1f.tar
UXP-b5ee49d85ae054c0176248c1c4f5b84b57afcb1f.tar.gz
UXP-b5ee49d85ae054c0176248c1c4f5b84b57afcb1f.tar.lz
UXP-b5ee49d85ae054c0176248c1c4f5b84b57afcb1f.tar.xz
UXP-b5ee49d85ae054c0176248c1c4f5b84b57afcb1f.zip
Re-implement custom background color of standalone images.
This resolves #717. Note: this does not affect other applications because the platform default is to use the "darknoise" background image for standalone image, which effectively overrides a bg color.
Diffstat (limited to 'dom/html/ImageDocument.cpp')
-rw-r--r--dom/html/ImageDocument.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp
index 200bb5d46..f83a804be 100644
--- a/dom/html/ImageDocument.cpp
+++ b/dom/html/ImageDocument.cpp
@@ -40,12 +40,14 @@
#include "nsThreadUtils.h"
#include "nsIScrollableFrame.h"
#include "nsContentUtils.h"
+#include "nsCSSParser.h" // for CSS colors on the background
#include "mozilla/dom/Element.h"
#include "mozilla/Preferences.h"
#include <algorithm>
#define AUTOMATIC_IMAGE_RESIZING_PREF "browser.enable_automatic_image_resizing"
#define CLICK_IMAGE_RESIZING_PREF "browser.enable_click_image_resizing"
+#define STANDALONE_IMAGE_BACKGROUND_COLOR_PREF "browser.display.standalone_images.background_color"
//XXX A hack needed for Firefox's site specific zoom.
#define SITE_SPECIFIC_ZOOM "browser.zoom.siteSpecific"
@@ -170,6 +172,8 @@ ImageDocument::Init()
mClickResizingEnabled = Preferences::GetBool(CLICK_IMAGE_RESIZING_PREF);
mShouldResize = mResizeImageByDefault;
mFirstResize = true;
+
+ mBackgroundColor = Preferences::GetString(STANDALONE_IMAGE_BACKGROUND_COLOR_PREF);
return NS_OK;
}
@@ -682,9 +686,22 @@ ImageDocument::CreateSyntheticDocument()
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::src, srcString, false);
mImageContent->SetAttr(kNameSpaceID_None, nsGkAtoms::alt, srcString, false);
+ // Implement mechanism for custom background color from pref.
+ if (!mBackgroundColor.IsEmpty()) {
+ nsCSSValue color;
+ nsCSSParser parser;
+ if (parser.ParseColorString(mBackgroundColor, nullptr, 0, color)) {
+ nsAutoString styleAttr(NS_LITERAL_STRING("background-color: "));
+ styleAttr.Append(mBackgroundColor);
+ body->SetAttr(kNameSpaceID_None, nsGkAtoms::style, styleAttr, false);
+ }
+ }
+
body->AppendChildTo(mImageContent, false);
imageLoader->SetLoadingEnabled(true);
+ UpdateTitleAndCharset();
+
return NS_OK;
}