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

Unified Diff: third_party/WebKit/Source/core/frame/FrameView.cpp

Issue 2672983003: Implements PrintBrowser mode. (Closed)
Patch Set: Add tests and respond to comments Created 3 years, 10 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/core/frame/FrameView.cpp
diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp
index 93a42bb40dca6076bc944a1ef652c21933171a5a..9252537a4ebd49852dc2926b1c55e37de2a90175 100644
--- a/third_party/WebKit/Source/core/frame/FrameView.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -90,6 +90,7 @@
#include "core/page/FocusController.h"
#include "core/page/FrameTree.h"
#include "core/page/Page.h"
+#include "core/page/PrintContext.h"
#include "core/page/scrolling/RootScrollerUtil.h"
#include "core/page/scrolling/ScrollingCoordinator.h"
#include "core/page/scrolling/TopDocumentRootScrollerController.h"
@@ -145,6 +146,10 @@
namespace blink {
+// A4 Portrait dimensions in pixels
+const int kA4PortraitPageWidth = 595;
+const int kA4PortraitPageHeight = 842;
+
using namespace HTMLNames;
// The maximum number of updateWidgets iterations that should be done before
@@ -234,6 +239,7 @@ DEFINE_TRACE(FrameView) {
visitor->trace(m_scrollAnchor);
visitor->trace(m_anchoringAdjustmentQueue);
visitor->trace(m_scrollbarManager);
+ visitor->trace(m_printContext);
Widget::trace(visitor);
ScrollableArea::trace(visitor);
}
@@ -2886,6 +2892,36 @@ void FrameView::notifyResizeObservers() {
DCHECK(!layoutView()->needsLayout());
}
+void FrameView::dispatchEventsForPrintingOnAllFrames() {
+ DCHECK(m_frame->isMainFrame());
+ for (Frame* currentFrame = m_frame; currentFrame;
+ currentFrame = currentFrame->tree().traverseNext(m_frame)) {
+ if (currentFrame->isLocalFrame())
+ toLocalFrame(currentFrame)->document()->dispatchEventsForPrinting();
+ }
+}
+
+void FrameView::setupPrintContext() {
+ if (!m_frame->document()->printing()) {
mstensho (USE GERRIT) 2017/02/08 14:32:29 Could consider an early return here; i.e.: if (
gozzard 2017/02/09 04:17:25 Done.
+ if (!m_printContext)
+ m_printContext = new PrintContext(m_frame);
+ if (m_frame->settings())
+ m_frame->settings()->setShouldPrintBackgrounds(true);
+ FloatRect pageRect(0, 0, kA4PortraitPageWidth, kA4PortraitPageHeight);
+ m_printContext->begin(pageRect.width(), pageRect.height());
+ float height;
+ m_printContext->computePageRects(pageRect, 0, 0, 1.0, height);
+ dispatchEventsForPrintingOnAllFrames();
pdr. 2017/02/08 06:34:08 Could you use forAllNonThrottledFrameViews for thi
gozzard 2017/02/09 04:17:25 dispatchEventsForPrinting() ultimately informs som
+ }
pdr. 2017/02/08 06:34:08 I think this approach can fail to dispatch print e
gozzard 2017/02/09 04:17:25 This appears to be the case. However, I believe th
+}
+
+void FrameView::clearPrintContext() {
+ if (m_printContext) {
mstensho (USE GERRIT) 2017/02/08 14:32:29 Might even consider an early return on !m_printCon
gozzard 2017/02/09 04:17:26 Done.
+ m_printContext->end();
+ m_printContext.clear();
+ }
+}
+
// TODO(leviw): We don't assert lifecycle information from documents in child
// PluginViews.
void FrameView::updateLifecyclePhasesInternal(
@@ -2918,6 +2954,12 @@ void FrameView::updateLifecyclePhasesInternal(
return;
}
+ if (RuntimeEnabledFeatures::printBrowserEnabled()) {
+ setupPrintContext();
+ } else {
+ clearPrintContext();
+ }
mstensho (USE GERRIT) 2017/02/08 14:32:29 No need for the curly braces.
gozzard 2017/02/09 04:17:25 Done.
+
updateStyleAndLayoutIfNeededRecursive();
DCHECK(lifecycle().state() >= DocumentLifecycle::LayoutClean);
@@ -2990,7 +3032,8 @@ void FrameView::updateLifecyclePhasesInternal(
DocumentAnimations::updateAnimations(layoutView()->document());
if (targetState == DocumentLifecycle::PaintClean) {
- if (!m_frame->document()->printing())
+ if (!m_frame->document()->printing() ||
+ RuntimeEnabledFeatures::printBrowserEnabled())
paintTree();
if (RuntimeEnabledFeatures::slimmingPaintV2Enabled())
@@ -3082,6 +3125,8 @@ void FrameView::paintTree() {
if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
if (layoutView()->layer()->needsRepaint()) {
GraphicsContext graphicsContext(*m_paintController);
+ if (RuntimeEnabledFeatures::printBrowserEnabled())
+ graphicsContext.setPrinting(true);
paint(graphicsContext, CullRect(LayoutRect::infiniteIntRect()));
m_paintController->commitNewDisplayItems(LayoutSize());
notifyPaint(*m_paintController);
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameView.h ('k') | third_party/WebKit/Source/core/paint/ObjectPaintInvalidator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698