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

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

Issue 2656713002: Merge to M57: Remove popup overlay from MHTML when requested (Closed)
Patch Set: 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
« no previous file with comments | « content/test/data/popup.html ('k') | third_party/WebKit/Source/web/tests/WebFrameSerializerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35eb6932a45b196860d9f55cc6fa197103a71265..4434b29d0ebf1950f76066c6237085b0a8142cc8 100644
--- a/third_party/WebKit/Source/web/WebFrameSerializer.cpp
+++ b/third_party/WebKit/Source/web/WebFrameSerializer.cpp
@@ -43,6 +43,7 @@
#include "core/html/HTMLImageElement.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/HTMLTableElement.h"
+#include "core/layout/LayoutBox.h"
#include "core/loader/DocumentLoader.h"
#include "platform/Histogram.h"
#include "platform/SerializedResource.h"
@@ -77,6 +78,8 @@ namespace blink {
namespace {
+const int kPopupOverlayZIndexThreshold = 50;
+
class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
WTF_MAKE_NONCOPYABLE(MHTMLFrameSerializerDelegate);
@@ -92,6 +95,8 @@ class MHTMLFrameSerializerDelegate final : public FrameSerializer::Delegate {
Vector<Attribute> getCustomAttributes(const Element&) override;
private:
+ bool shouldIgnoreHiddenElement(const Element&);
+ bool shouldIgnorePopupOverlayElement(const Element&);
void getCustomAttributesForImageElement(const HTMLImageElement&,
Vector<Attribute>*);
void getCustomAttributesForFormControlElement(const Element&,
@@ -105,6 +110,17 @@ MHTMLFrameSerializerDelegate::MHTMLFrameSerializerDelegate(
: m_webDelegate(webDelegate) {}
bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) {
+ if (shouldIgnoreHiddenElement(element))
+ return true;
+ if (m_webDelegate.removePopupOverlay() &&
+ shouldIgnorePopupOverlayElement(element)) {
+ return true;
+ }
+ return false;
+}
+
+bool MHTMLFrameSerializerDelegate::shouldIgnoreHiddenElement(
+ const Element& element) {
// Do not include elements that are are set to hidden without affecting layout
// by the page. For those elements that are hidden by default, they will not
// be excluded:
@@ -122,6 +138,28 @@ bool MHTMLFrameSerializerDelegate::shouldIgnoreElement(const Element& element) {
return parent && !isHTMLHeadElement(parent);
}
+bool MHTMLFrameSerializerDelegate::shouldIgnorePopupOverlayElement(
+ const Element& element) {
+ // The element should be visible.
+ LayoutBox* box = element.layoutBox();
+ if (!box)
+ return false;
+
+ // The bounding box of the element should contain center point of the
+ // viewport.
+ LocalDOMWindow* window = element.document().domWindow();
+ DCHECK(window);
+ LayoutPoint centerPoint(window->innerWidth() / 2, window->innerHeight() / 2);
+ if (!box->frameRect().contains(centerPoint))
+ return false;
+
+ // The z-index should be greater than the threshold.
+ if (box->style()->zIndex() < kPopupOverlayZIndexThreshold)
+ return false;
+
+ return true;
+}
+
bool MHTMLFrameSerializerDelegate::shouldIgnoreAttribute(
const Element& element,
const Attribute& attribute) {
« no previous file with comments | « content/test/data/popup.html ('k') | third_party/WebKit/Source/web/tests/WebFrameSerializerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698