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

Side by Side Diff: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp

Issue 1931133002: Let SkPictureBuilder be DisplayItemClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromNode(LocalFrame* f rame, const WebNode& node) 264 WebPluginContainerImpl* WebLocalFrameImpl::pluginContainerFromNode(LocalFrame* f rame, const WebNode& node)
265 { 265 {
266 WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame); 266 WebPluginContainerImpl* pluginContainer = pluginContainerFromFrame(frame);
267 if (pluginContainer) 267 if (pluginContainer)
268 return pluginContainer; 268 return pluginContainer;
269 return toWebPluginContainerImpl(node.pluginContainer()); 269 return toWebPluginContainerImpl(node.pluginContainer());
270 } 270 }
271 271
272 // Simple class to override some of PrintContext behavior. Some of the methods 272 // Simple class to override some of PrintContext behavior. Some of the methods
273 // made virtual so that they can be overridden by ChromePluginPrintContext. 273 // made virtual so that they can be overridden by ChromePluginPrintContext.
274 class ChromePrintContext : public PrintContext, public DisplayItemClient { 274 class ChromePrintContext : public PrintContext {
275 WTF_MAKE_NONCOPYABLE(ChromePrintContext); 275 WTF_MAKE_NONCOPYABLE(ChromePrintContext);
276 public: 276 public:
277 ChromePrintContext(LocalFrame* frame) 277 ChromePrintContext(LocalFrame* frame)
278 : PrintContext(frame) 278 : PrintContext(frame)
279 , m_printedPageWidth(0) 279 , m_printedPageWidth(0)
280 { 280 {
281 } 281 }
282 282
283 ~ChromePrintContext() override {} 283 ~ChromePrintContext() override {}
284 284
(...skipping 17 matching lines...) Expand all
302 return 0; 302 return 0;
303 303
304 frame()->view()->updateAllLifecyclePhasesExceptPaint(); 304 frame()->view()->updateAllLifecyclePhasesExceptPaint();
305 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ()) 305 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ())
306 return 0; 306 return 0;
307 307
308 IntRect pageRect = m_pageRects[pageNumber]; 308 IntRect pageRect = m_pageRects[pageNumber];
309 SkPictureBuilder pictureBuilder(pageRect, &skia::GetMetaData(*canvas)); 309 SkPictureBuilder pictureBuilder(pageRect, &skia::GetMetaData(*canvas));
310 pictureBuilder.context().setPrinting(true); 310 pictureBuilder.context().setPrinting(true);
311 311
312 float scale = spoolPage(pictureBuilder.context(), pageNumber); 312 float scale = spoolPage(pictureBuilder, pageNumber);
313 pictureBuilder.endRecording()->playback(canvas); 313 pictureBuilder.endRecording()->playback(canvas);
314 return scale; 314 return scale;
315 } 315 }
316 316
317 void spoolAllPagesWithBoundaries(WebCanvas* canvas, const FloatSize& pageSiz eInPixels) 317 void spoolAllPagesWithBoundaries(WebCanvas* canvas, const FloatSize& pageSiz eInPixels)
318 { 318 {
319 dispatchEventsForPrintingOnAllFrames(); 319 dispatchEventsForPrintingOnAllFrames();
320 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ()) 320 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ())
321 return; 321 return;
322 322
323 frame()->view()->updateAllLifecyclePhasesExceptPaint(); 323 frame()->view()->updateAllLifecyclePhasesExceptPaint();
324 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ()) 324 if (!frame()->document() || frame()->document()->layoutViewItem().isNull ())
325 return; 325 return;
326 326
327 float pageHeight; 327 float pageHeight;
328 computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight); 328 computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, pageHeight);
329 329
330 const float pageWidth = pageSizeInPixels.width(); 330 const float pageWidth = pageSizeInPixels.width();
331 size_t numPages = pageRects().size(); 331 size_t numPages = pageRects().size();
332 int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1; 332 int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1;
333 IntRect allPagesRect(0, 0, pageWidth, totalHeight); 333 IntRect allPagesRect(0, 0, pageWidth, totalHeight);
334 334
335 SkPictureBuilder pictureBuilder(allPagesRect, &skia::GetMetaData(*canvas )); 335 SkPictureBuilder pictureBuilder(allPagesRect, &skia::GetMetaData(*canvas ));
336 pictureBuilder.context().setPrinting(true); 336 pictureBuilder.context().setPrinting(true);
337 337
338 GraphicsContext& context = pictureBuilder.context(); 338 GraphicsContext& context = pictureBuilder.context();
339 339
340 // Fill the whole background by white. 340 // Fill the whole background by white.
341 { 341 {
342 DrawingRecorder backgroundRecorder(context, *this, DisplayItem::Prin tedContentBackground, allPagesRect); 342 DrawingRecorder backgroundRecorder(context, pictureBuilder, DisplayI tem::PrintedContentBackground, allPagesRect);
343 context.fillRect(FloatRect(0, 0, pageWidth, totalHeight), Color::whi te); 343 context.fillRect(FloatRect(0, 0, pageWidth, totalHeight), Color::whi te);
344 } 344 }
345 345
346 int currentHeight = 0; 346 int currentHeight = 0;
347 for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) { 347 for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) {
348 ScopeRecorder scopeRecorder(context); 348 ScopeRecorder scopeRecorder(context);
349 // Draw a line for a page boundary if this isn't the first page. 349 // Draw a line for a page boundary if this isn't the first page.
350 if (pageIndex > 0) { 350 if (pageIndex > 0) {
351 DrawingRecorder lineBoundaryRecorder(context, *this, DisplayItem ::PrintedContentLineBoundary, allPagesRect); 351 DrawingRecorder lineBoundaryRecorder(context, pictureBuilder, Di splayItem::PrintedContentLineBoundary, allPagesRect);
352 context.save(); 352 context.save();
353 context.setStrokeColor(Color(0, 0, 255)); 353 context.setStrokeColor(Color(0, 0, 255));
354 context.setFillColor(Color(0, 0, 255)); 354 context.setFillColor(Color(0, 0, 255));
355 context.drawLine(IntPoint(0, currentHeight), IntPoint(pageWidth, currentHeight)); 355 context.drawLine(IntPoint(0, currentHeight), IntPoint(pageWidth, currentHeight));
356 context.restore(); 356 context.restore();
357 } 357 }
358 358
359 AffineTransform transform; 359 AffineTransform transform;
360 transform.translate(0, currentHeight); 360 transform.translate(0, currentHeight);
361 #if OS(WIN) || OS(MACOSX) 361 #if OS(WIN) || OS(MACOSX)
362 // Account for the disabling of scaling in spoolPage. In the context 362 // Account for the disabling of scaling in spoolPage. In the context
363 // of spoolAllPagesWithBoundaries the scale HAS NOT been pre-applied . 363 // of spoolAllPagesWithBoundaries the scale HAS NOT been pre-applied .
364 float scale = getPageShrink(pageIndex); 364 float scale = getPageShrink(pageIndex);
365 transform.scale(scale, scale); 365 transform.scale(scale, scale);
366 #endif 366 #endif
367 TransformRecorder transformRecorder(context, *this, transform); 367 TransformRecorder transformRecorder(context, pictureBuilder, transfo rm);
368 spoolPage(context, pageIndex); 368 spoolPage(pictureBuilder, pageIndex);
369 369
370 currentHeight += pageSizeInPixels.height() + 1; 370 currentHeight += pageSizeInPixels.height() + 1;
371 } 371 }
372 pictureBuilder.endRecording()->playback(canvas); 372 pictureBuilder.endRecording()->playback(canvas);
373 } 373 }
374 374
375 // DisplayItemClient methods
376 String debugName() const final { return "ChromePrintContext"; }
377 LayoutRect visualRect() const override { return LayoutRect(); }
378
379 protected: 375 protected:
380 // Spools the printed page, a subrect of frame(). Skip the scale step. 376 // Spools the printed page, a subrect of frame(). Skip the scale step.
381 // NativeTheme doesn't play well with scaling. Scaling is done browser side 377 // NativeTheme doesn't play well with scaling. Scaling is done browser side
382 // instead. Returns the scale to be applied. 378 // instead. Returns the scale to be applied.
383 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit 379 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit
384 // do the scaling and ignore the return value. 380 // do the scaling and ignore the return value.
385 virtual float spoolPage(GraphicsContext& context, int pageNumber) 381 virtual float spoolPage(SkPictureBuilder& pictureBuilder, int pageNumber)
386 { 382 {
387 IntRect pageRect = m_pageRects[pageNumber]; 383 IntRect pageRect = m_pageRects[pageNumber];
388 float scale = m_printedPageWidth / pageRect.width(); 384 float scale = m_printedPageWidth / pageRect.width();
385 GraphicsContext& context = pictureBuilder.context();
389 386
390 AffineTransform transform; 387 AffineTransform transform;
391 #if OS(POSIX) && !OS(MACOSX) 388 #if OS(POSIX) && !OS(MACOSX)
392 transform.scale(scale); 389 transform.scale(scale);
393 #endif 390 #endif
394 transform.translate(static_cast<float>(-pageRect.x()), static_cast<float >(-pageRect.y())); 391 transform.translate(static_cast<float>(-pageRect.x()), static_cast<float >(-pageRect.y()));
395 TransformRecorder transformRecorder(context, *this, transform); 392 TransformRecorder transformRecorder(context, pictureBuilder, transform);
396 393
397 ClipRecorder clipRecorder(context, *this, DisplayItem::ClipPrintedPage, LayoutRect(pageRect)); 394 ClipRecorder clipRecorder(context, pictureBuilder, DisplayItem::ClipPrin tedPage, LayoutRect(pageRect));
398 395
399 frame()->view()->paintContents(context, GlobalPaintNormalPhase, pageRect ); 396 frame()->view()->paintContents(context, GlobalPaintNormalPhase, pageRect );
400 397
401 { 398 {
402 DrawingRecorder lineBoundaryRecorder(context, *this, DisplayItem::Pr intedContentDestinationLocations, pageRect); 399 DrawingRecorder lineBoundaryRecorder(context, pictureBuilder, Displa yItem::PrintedContentDestinationLocations, pageRect);
403 outputLinkedDestinations(context, pageRect); 400 outputLinkedDestinations(context, pageRect);
404 } 401 }
405 402
406 return scale; 403 return scale;
407 } 404 }
408 405
409 private: 406 private:
410 void dispatchEventsForPrintingOnAllFrames() 407 void dispatchEventsForPrintingOnAllFrames()
411 { 408 {
412 HeapVector<Member<Document>> documents; 409 HeapVector<Member<Document>> documents;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 461
465 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels) overrid e 462 void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels) overrid e
466 { 463 {
467 NOTREACHED(); 464 NOTREACHED();
468 } 465 }
469 466
470 protected: 467 protected:
471 // Spools the printed page, a subrect of frame(). Skip the scale step. 468 // Spools the printed page, a subrect of frame(). Skip the scale step.
472 // NativeTheme doesn't play well with scaling. Scaling is done browser side 469 // NativeTheme doesn't play well with scaling. Scaling is done browser side
473 // instead. Returns the scale to be applied. 470 // instead. Returns the scale to be applied.
474 float spoolPage(GraphicsContext& context, int pageNumber) override 471 float spoolPage(SkPictureBuilder& pictureBuilder, int pageNumber) override
475 { 472 {
476 IntRect pageRect = m_pageRects[pageNumber]; 473 IntRect pageRect = m_pageRects[pageNumber];
477 m_plugin->printPage(pageNumber, context, pageRect); 474 m_plugin->printPage(pageNumber, pictureBuilder.context(), pageRect);
478 475
479 return 1.0; 476 return 1.0;
480 } 477 }
481 478
482 private: 479 private:
483 // Set when printing. 480 // Set when printing.
484 Member<WebPluginContainerImpl> m_plugin; 481 Member<WebPluginContainerImpl> m_plugin;
485 WebPrintParams m_printParams; 482 WebPrintParams m_printParams;
486 }; 483 };
487 484
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 return WebSandboxFlags::None; 2107 return WebSandboxFlags::None;
2111 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags( )); 2108 return static_cast<WebSandboxFlags>(frame()->loader().effectiveSandboxFlags( ));
2112 } 2109 }
2113 2110
2114 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags) 2111 void WebLocalFrameImpl::forceSandboxFlags(WebSandboxFlags flags)
2115 { 2112 {
2116 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags)); 2113 frame()->loader().forceSandboxFlags(static_cast<SandboxFlags>(flags));
2117 } 2114 }
2118 2115
2119 } // namespace blink 2116 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698