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

Unified Diff: third_party/WebKit/Source/web/WebFrameSerializer.cpp

Issue 2624953002: Set width and height attributes for <img> if image is loaded from srcset (Closed)
Patch Set: Fix another typo Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/WebFrameSerializer.cpp
diff --git a/third_party/WebKit/Source/web/WebFrameSerializer.cpp b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
index 401d4ea9df369e713cc8914fd9669e57c6e2bd28..9a266f1dce7545ba1fe7dfa7d3a26905d186d893 100644
--- a/third_party/WebKit/Source/web/WebFrameSerializer.cpp
+++ b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
@@ -40,6 +40,7 @@
#include "core/html/HTMLAllCollection.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/HTMLFrameOwnerElement.h"
+#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLTableElement.h"
#include "core/loader/DocumentLoader.h"
@@ -91,6 +92,11 @@ class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
Vector<Attribute> getCustomAttributes(const Element&) override;
private:
+ void getCustomAttributesForImageElement(const HTMLImageElement&,
+ Vector<Attribute>*);
+ void getCustomAttributesForFormControlElement(const Element&,
+ Vector<Attribute>*);
+
WebFrameSerializer::MHTMLPartsGenerationDelegate& m_webDelegate;
};
@@ -193,18 +199,65 @@ Vector<Attribute> MHTMLFrameSerializerDelegate::getCustomAttributes(
const Element& element) {
Vector<Attribute> attributes;
- // Disable all form elements in MTHML to tell the user that the form cannot be
- // worked on. MHTML is loaded in full sandboxing mode which disable the form
- // submission and script execution.
- if (element.isFormControlElement() &&
- !element.fastHasAttribute(HTMLNames::disabledAttr)) {
- Attribute disabledAttribute(HTMLNames::disabledAttr, "");
- attributes.push_back(disabledAttribute);
+ if (isHTMLImageElement(element)) {
+ getCustomAttributesForImageElement(toHTMLImageElement(element),
+ &attributes);
+ } else if (element.isFormControlElement()) {
+ getCustomAttributesForFormControlElement(element, &attributes);
}
return attributes;
}
+void MHTMLFrameSerializerDelegate::getCustomAttributesForImageElement(
+ const HTMLImageElement& element,
+ Vector<Attribute>* attributes) {
+ // Currently only the value of src is pulled into the archive and the srcset
+ // attribute is ignored (see shouldIgnoreAttribute() above). If the device
+ // has a higher DPR, a different image from srcset could be loaded instead.
+ // When this occurs, we should provide the rendering width and height for
+ // <img> element if not set.
+
+ // The image should be loaded and participate the layout.
+ ImageResourceContent* image = element.cachedImage();
+ if (!image || !image->hasImage() || image->errorOccurred() ||
+ !element.layoutObject()) {
+ return;
+ }
+
+ // The width and height attributes should not be set.
+ if (element.fastHasAttribute(HTMLNames::widthAttr) ||
+ element.fastHasAttribute(HTMLNames::heightAttr)) {
+ return;
+ }
+
+ // Check if different image is loaded. naturalWidth/naturalHeight will return
+ // the image size adjusted with current DPR.
+ if (((int)element.naturalWidth()) == image->getImage()->width() &&
+ ((int)element.naturalHeight()) == image->getImage()->height()) {
+ return;
+ }
+
+ Attribute widthAttribute(HTMLNames::widthAttr,
+ AtomicString::number(element.layoutBoxWidth()));
+ attributes->push_back(widthAttribute);
+ Attribute heightAttribute(HTMLNames::heightAttr,
+ AtomicString::number(element.layoutBoxHeight()));
+ attributes->push_back(heightAttribute);
+}
+
+void MHTMLFrameSerializerDelegate::getCustomAttributesForFormControlElement(
+ const Element& element,
+ Vector<Attribute>* attributes) {
+ // Disable all form elements in MTHML to tell the user that the form cannot be
+ // worked on. MHTML is loaded in full sandboxing mode which disable the form
+ // submission and script execution.
+ if (element.fastHasAttribute(HTMLNames::disabledAttr))
+ return;
+ Attribute disabledAttribute(HTMLNames::disabledAttr, "");
+ attributes->push_back(disabledAttribute);
+}
+
bool cacheControlNoStoreHeaderPresent(
const WebLocalFrameImpl& webLocalFrameImpl) {
const ResourceResponse& response =

Powered by Google App Engine
This is Rietveld 408576698