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

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

Issue 2672983003: Implements PrintBrowser mode. (Closed)
Patch Set: Rebase 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 94b9738bcba2e46c73347ca92297c95115a7e7f8..62fef414a6f1da0f9bd3973152b15031c08db376 100644
--- a/third_party/WebKit/Source/core/frame/FrameView.cpp
+++ b/third_party/WebKit/Source/core/frame/FrameView.cpp
@@ -92,6 +92,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"
@@ -147,6 +148,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
@@ -236,6 +241,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())
+ return;
+ 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();
+}
+
+void FrameView::clearPrintContext() {
+ if (!m_printContext)
+ return;
+ 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,11 @@ void FrameView::updateLifecyclePhasesInternal(
return;
}
+ if (RuntimeEnabledFeatures::printBrowserEnabled())
+ setupPrintContext();
+ else
+ clearPrintContext();
+
updateStyleAndLayoutIfNeededRecursive();
DCHECK(lifecycle().state() >= DocumentLifecycle::LayoutClean);
@@ -2990,7 +3031,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())
@@ -3083,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