| OLD | NEW |
| 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 dispatchEventsForPrintingOnAllFrames(); | 297 dispatchEventsForPrintingOnAllFrames(); |
| 298 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 298 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 299 return 0; | 299 return 0; |
| 300 | 300 |
| 301 frame()->view()->updateAllLifecyclePhasesExceptPaint(); | 301 frame()->view()->updateAllLifecyclePhasesExceptPaint(); |
| 302 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 302 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 303 return 0; | 303 return 0; |
| 304 | 304 |
| 305 // The page rect gets scaled and translated, so specify the entire | 305 // The page rect gets scaled and translated, so specify the entire |
| 306 // print content area here as the recording rect. | 306 // print content area here as the recording rect. |
| 307 IntRect printedPageRect(0, 0, m_printedPageHeight, m_printedPageWidth); | 307 IntRect bounds(0, 0, m_printedPageHeight, m_printedPageWidth); |
| 308 PaintRecordBuilder builder(printedPageRect, &canvas->getMetaData()); | 308 PaintRecordBuilder builder(bounds, &canvas->getMetaData()); |
| 309 builder.context().beginRecording(bounds); |
| 309 builder.context().setPrinting(true); | 310 builder.context().setPrinting(true); |
| 310 | 311 float scale = spoolPage(builder.context(), pageNumber, bounds); |
| 311 float scale = spoolPage(builder, pageNumber); | |
| 312 canvas->PlaybackPaintRecord(builder.endRecording()); | |
| 313 return scale; | 312 return scale; |
| 314 } | 313 } |
| 315 | 314 |
| 316 void spoolAllPagesWithBoundaries(WebCanvas* canvas, | 315 void spoolAllPagesWithBoundaries(WebCanvas* canvas, |
| 317 const FloatSize& pageSizeInPixels) { | 316 const FloatSize& pageSizeInPixels) { |
| 318 dispatchEventsForPrintingOnAllFrames(); | 317 dispatchEventsForPrintingOnAllFrames(); |
| 319 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 318 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 320 return; | 319 return; |
| 321 | 320 |
| 322 frame()->view()->updateAllLifecyclePhasesExceptPaint(); | 321 frame()->view()->updateAllLifecyclePhasesExceptPaint(); |
| 323 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) | 322 if (!frame()->document() || frame()->document()->layoutViewItem().isNull()) |
| 324 return; | 323 return; |
| 325 | 324 |
| 326 float pageHeight; | 325 float pageHeight; |
| 327 computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, | 326 computePageRects(FloatRect(FloatPoint(0, 0), pageSizeInPixels), 0, 0, 1, |
| 328 pageHeight); | 327 pageHeight); |
| 329 | 328 |
| 330 const float pageWidth = pageSizeInPixels.width(); | 329 const float pageWidth = pageSizeInPixels.width(); |
| 331 size_t numPages = pageRects().size(); | 330 size_t numPages = pageRects().size(); |
| 332 int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1; | 331 int totalHeight = numPages * (pageSizeInPixels.height() + 1) - 1; |
| 333 IntRect allPagesRect(0, 0, pageWidth, totalHeight); | 332 IntRect allPagesRect(0, 0, pageWidth, totalHeight); |
| 334 | 333 |
| 335 PaintRecordBuilder builder(allPagesRect, &canvas->getMetaData()); | 334 PaintRecordBuilder builder(allPagesRect, &canvas->getMetaData()); |
| 336 builder.context().setPrinting(true); | |
| 337 | |
| 338 { | 335 { |
| 339 GraphicsContext& context = builder.context(); | 336 GraphicsContext& context = builder.context(); |
| 340 DisplayItemCacheSkipper skipper(context); | 337 context.setPrinting(true); |
| 338 context.beginRecording(allPagesRect); |
| 341 | 339 |
| 342 // Fill the whole background by white. | 340 // Fill the whole background by white. |
| 343 { | 341 context.fillRect(FloatRect(0, 0, pageWidth, totalHeight), Color::white); |
| 344 DrawingRecorder backgroundRecorder( | |
| 345 context, builder, DisplayItem::kPrintedContentBackground, | |
| 346 allPagesRect); | |
| 347 context.fillRect(FloatRect(0, 0, pageWidth, totalHeight), Color::white); | |
| 348 } | |
| 349 | 342 |
| 350 int currentHeight = 0; | 343 int currentHeight = 0; |
| 351 for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) { | 344 for (size_t pageIndex = 0; pageIndex < numPages; pageIndex++) { |
| 352 // Draw a line for a page boundary if this isn't the first page. | 345 // Draw a line for a page boundary if this isn't the first page. |
| 353 if (pageIndex > 0) { | 346 if (pageIndex > 0) { |
| 354 DrawingRecorder lineBoundaryRecorder( | |
| 355 context, builder, DisplayItem::kPrintedContentLineBoundary, | |
| 356 allPagesRect); | |
| 357 context.save(); | 347 context.save(); |
| 358 context.setStrokeColor(Color(0, 0, 255)); | 348 context.setStrokeColor(Color(0, 0, 255)); |
| 359 context.setFillColor(Color(0, 0, 255)); | 349 context.setFillColor(Color(0, 0, 255)); |
| 360 context.drawLine(IntPoint(0, currentHeight), | 350 context.drawLine(IntPoint(0, currentHeight), |
| 361 IntPoint(pageWidth, currentHeight)); | 351 IntPoint(pageWidth, currentHeight)); |
| 362 context.restore(); | 352 context.restore(); |
| 363 } | 353 } |
| 364 | 354 |
| 365 AffineTransform transform; | 355 AffineTransform transform; |
| 366 transform.translate(0, currentHeight); | 356 transform.translate(0, currentHeight); |
| 367 #if OS(WIN) || OS(MACOSX) | 357 #if OS(WIN) || OS(MACOSX) |
| 368 // Account for the disabling of scaling in spoolPage. In the context | 358 // Account for the disabling of scaling in spoolPage. In the context |
| 369 // of spoolAllPagesWithBoundaries the scale HAS NOT been pre-applied. | 359 // of spoolAllPagesWithBoundaries the scale HAS NOT been pre-applied. |
| 370 float scale = getPageShrink(pageIndex); | 360 float scale = getPageShrink(pageIndex); |
| 371 transform.scale(scale, scale); | 361 transform.scale(scale, scale); |
| 372 #endif | 362 #endif |
| 373 TransformRecorder transformRecorder(context, builder, transform); | 363 context.save(); |
| 374 spoolPage(builder, pageIndex); | 364 context.concatCTM(transform); |
| 365 |
| 366 spoolPage(context, pageIndex, allPagesRect); |
| 367 |
| 368 context.restore(); |
| 375 | 369 |
| 376 currentHeight += pageSizeInPixels.height() + 1; | 370 currentHeight += pageSizeInPixels.height() + 1; |
| 377 } | 371 } |
| 372 canvas->PlaybackPaintRecord(context.endRecording()); |
| 378 } | 373 } |
| 379 canvas->PlaybackPaintRecord(builder.endRecording()); | |
| 380 } | 374 } |
| 381 | 375 |
| 382 protected: | 376 protected: |
| 383 // Spools the printed page, a subrect of frame(). Skip the scale step. | 377 // Spools the printed page, a subrect of frame(). Skip the scale step. |
| 384 // NativeTheme doesn't play well with scaling. Scaling is done browser side | 378 // NativeTheme doesn't play well with scaling. Scaling is done browser side |
| 385 // instead. Returns the scale to be applied. | 379 // instead. Returns the scale to be applied. |
| 386 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit | 380 // On Linux, we don't have the problem with NativeTheme, hence we let WebKit |
| 387 // do the scaling and ignore the return value. | 381 // do the scaling and ignore the return value. |
| 388 virtual float spoolPage(PaintRecordBuilder& builder, int pageNumber) { | 382 virtual float spoolPage(GraphicsContext& context, |
| 383 int pageNumber, |
| 384 const IntRect& bounds) { |
| 389 IntRect pageRect = m_pageRects[pageNumber]; | 385 IntRect pageRect = m_pageRects[pageNumber]; |
| 390 float scale = m_printedPageWidth / pageRect.width(); | 386 float scale = m_printedPageWidth / pageRect.width(); |
| 391 GraphicsContext& context = builder.context(); | |
| 392 | 387 |
| 393 AffineTransform transform; | 388 AffineTransform transform; |
| 394 #if OS(POSIX) && !OS(MACOSX) | 389 #if OS(POSIX) && !OS(MACOSX) |
| 395 transform.scale(scale); | 390 transform.scale(scale); |
| 396 #endif | 391 #endif |
| 397 transform.translate(static_cast<float>(-pageRect.x()), | 392 transform.translate(static_cast<float>(-pageRect.x()), |
| 398 static_cast<float>(-pageRect.y())); | 393 static_cast<float>(-pageRect.y())); |
| 399 TransformRecorder transformRecorder(context, builder, transform); | 394 context.save(); |
| 395 context.concatCTM(transform); |
| 396 context.clipRect(pageRect); |
| 400 | 397 |
| 401 ClipRecorder clipRecorder(context, builder, DisplayItem::kClipPrintedPage, | 398 PaintRecordBuilder builder(bounds, &context.canvas()->getMetaData()); |
| 402 pageRect); | |
| 403 | 399 |
| 404 frame()->view()->paintContents(context, GlobalPaintNormalPhase, pageRect); | 400 // The local sclope is so that the cache skipper is destroyed before |
| 401 // we call endRecording(). |
| 402 { |
| 403 DisplayItemCacheSkipper skipper(builder.context()); |
| 404 frame()->view()->paintContents(builder.context(), GlobalPaintNormalPhase, |
| 405 pageRect); |
| 405 | 406 |
| 406 { | |
| 407 DrawingRecorder lineBoundaryRecorder( | 407 DrawingRecorder lineBoundaryRecorder( |
| 408 context, builder, DisplayItem::kPrintedContentDestinationLocations, | 408 builder.context(), builder, |
| 409 pageRect); | 409 DisplayItem::kPrintedContentDestinationLocations, pageRect); |
| 410 outputLinkedDestinations(context, pageRect); | 410 outputLinkedDestinations(builder.context(), pageRect); |
| 411 } | 411 } |
| 412 context.drawRecord(builder.endRecording()); |
| 413 |
| 414 context.restore(); |
| 412 | 415 |
| 413 return scale; | 416 return scale; |
| 414 } | 417 } |
| 415 | 418 |
| 416 private: | 419 private: |
| 417 void dispatchEventsForPrintingOnAllFrames() { | 420 void dispatchEventsForPrintingOnAllFrames() { |
| 418 HeapVector<Member<Document>> documents; | 421 HeapVector<Member<Document>> documents; |
| 419 for (Frame* currentFrame = frame(); currentFrame; | 422 for (Frame* currentFrame = frame(); currentFrame; |
| 420 currentFrame = currentFrame->tree().traverseNext(frame())) { | 423 currentFrame = currentFrame->tree().traverseNext(frame())) { |
| 421 if (currentFrame->isLocalFrame()) | 424 if (currentFrame->isLocalFrame()) |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 | 473 |
| 471 void computePageRectsWithPageSize( | 474 void computePageRectsWithPageSize( |
| 472 const FloatSize& pageSizeInPixels) override { | 475 const FloatSize& pageSizeInPixels) override { |
| 473 NOTREACHED(); | 476 NOTREACHED(); |
| 474 } | 477 } |
| 475 | 478 |
| 476 protected: | 479 protected: |
| 477 // Spools the printed page, a subrect of frame(). Skip the scale step. | 480 // Spools the printed page, a subrect of frame(). Skip the scale step. |
| 478 // NativeTheme doesn't play well with scaling. Scaling is done browser side | 481 // NativeTheme doesn't play well with scaling. Scaling is done browser side |
| 479 // instead. Returns the scale to be applied. | 482 // instead. Returns the scale to be applied. |
| 480 float spoolPage(PaintRecordBuilder& builder, int pageNumber) override { | 483 float spoolPage(GraphicsContext& context, |
| 484 int pageNumber, |
| 485 const IntRect& bounds) override { |
| 481 IntRect pageRect = m_pageRects[pageNumber]; | 486 IntRect pageRect = m_pageRects[pageNumber]; |
| 482 m_plugin->printPage(pageNumber, builder.context(), pageRect); | 487 m_plugin->printPage(pageNumber, context, pageRect); |
| 483 | 488 |
| 484 return 1.0; | 489 return 1.0; |
| 485 } | 490 } |
| 486 | 491 |
| 487 private: | 492 private: |
| 488 // Set when printing. | 493 // Set when printing. |
| 489 Member<WebPluginContainerImpl> m_plugin; | 494 Member<WebPluginContainerImpl> m_plugin; |
| 490 WebPrintParams m_printParams; | 495 WebPrintParams m_printParams; |
| 491 }; | 496 }; |
| 492 | 497 |
| (...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2503 createMarkup(startPosition, endPosition, AnnotateForInterchange, | 2508 createMarkup(startPosition, endPosition, AnnotateForInterchange, |
| 2504 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); | 2509 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); |
| 2505 } else { | 2510 } else { |
| 2506 clipHtml = | 2511 clipHtml = |
| 2507 createMarkup(endPosition, startPosition, AnnotateForInterchange, | 2512 createMarkup(endPosition, startPosition, AnnotateForInterchange, |
| 2508 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); | 2513 ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); |
| 2509 } | 2514 } |
| 2510 } | 2515 } |
| 2511 | 2516 |
| 2512 } // namespace blink | 2517 } // namespace blink |
| OLD | NEW |