| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/page/PrintContext.h" | 5 #include "core/page/PrintContext.h" |
| 6 | 6 |
| 7 #include "core/dom/Document.h" | 7 #include "core/dom/Document.h" |
| 8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
| 9 #include "core/html/HTMLElement.h" | 9 #include "core/html/HTMLElement.h" |
| 10 #include "core/layout/LayoutTestHelper.h" | 10 #include "core/layout/LayoutTestHelper.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 class MockPrintContext : public PrintContext { | 29 class MockPrintContext : public PrintContext { |
| 30 public: | 30 public: |
| 31 MockPrintContext(LocalFrame* frame) : PrintContext(frame) {} | 31 MockPrintContext(LocalFrame* frame) : PrintContext(frame) {} |
| 32 | 32 |
| 33 void outputLinkedDestinations(GraphicsContext& context, | 33 void outputLinkedDestinations(GraphicsContext& context, |
| 34 const IntRect& pageRect) { | 34 const IntRect& pageRect) { |
| 35 PrintContext::outputLinkedDestinations(context, pageRect); | 35 PrintContext::outputLinkedDestinations(context, pageRect); |
| 36 } | 36 } |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 class MockCanvas : public SkCanvas { | 39 class MockCanvas : public PaintCanvas { |
| 40 public: | 40 public: |
| 41 enum OperationType { DrawRect, DrawPoint }; | 41 enum OperationType { DrawRect, DrawPoint }; |
| 42 | 42 |
| 43 struct Operation { | 43 struct Operation { |
| 44 OperationType type; | 44 OperationType type; |
| 45 SkRect rect; | 45 SkRect rect; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 MockCanvas() : SkCanvas(kPageWidth, kPageHeight) {} | 48 MockCanvas() : PaintCanvas(kPageWidth, kPageHeight) {} |
| 49 | 49 |
| 50 void onDrawAnnotation(const SkRect& rect, | 50 void onDrawAnnotation(const SkRect& rect, |
| 51 const char key[], | 51 const char key[], |
| 52 SkData* value) override { | 52 SkData* value) override { |
| 53 if (rect.width() == 0 && rect.height() == 0) { | 53 if (rect.width() == 0 && rect.height() == 0) { |
| 54 SkPoint point = getTotalMatrix().mapXY(rect.x(), rect.y()); | 54 SkPoint point = getTotalMatrix().mapXY(rect.x(), rect.y()); |
| 55 Operation operation = {DrawPoint, | 55 Operation operation = {DrawPoint, |
| 56 SkRect::MakeXYWH(point.x(), point.y(), 0, 0)}; | 56 SkRect::MakeXYWH(point.x(), point.y(), 0, 0)}; |
| 57 m_recordedOperations.push_back(operation); | 57 m_recordedOperations.push_back(operation); |
| 58 } else { | 58 } else { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 80 m_printContext = new MockPrintContext(document().frame()); | 80 m_printContext = new MockPrintContext(document().frame()); |
| 81 } | 81 } |
| 82 | 82 |
| 83 MockPrintContext& printContext() { return *m_printContext.get(); } | 83 MockPrintContext& printContext() { return *m_printContext.get(); } |
| 84 | 84 |
| 85 void setBodyInnerHTML(String bodyContent) { | 85 void setBodyInnerHTML(String bodyContent) { |
| 86 document().body()->setAttribute(HTMLNames::styleAttr, "margin: 0"); | 86 document().body()->setAttribute(HTMLNames::styleAttr, "margin: 0"); |
| 87 document().body()->setInnerHTML(bodyContent); | 87 document().body()->setInnerHTML(bodyContent); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void printSinglePage(SkCanvas& canvas) { | 90 void printSinglePage(PaintCanvas& canvas) { |
| 91 IntRect pageRect(0, 0, kPageWidth, kPageHeight); | 91 IntRect pageRect(0, 0, kPageWidth, kPageHeight); |
| 92 printContext().begin(pageRect.width(), pageRect.height()); | 92 printContext().begin(pageRect.width(), pageRect.height()); |
| 93 document().view()->updateAllLifecyclePhases(); | 93 document().view()->updateAllLifecyclePhases(); |
| 94 SkPictureBuilder pictureBuilder(pageRect); | 94 SkPictureBuilder pictureBuilder(pageRect); |
| 95 GraphicsContext& context = pictureBuilder.context(); | 95 GraphicsContext& context = pictureBuilder.context(); |
| 96 context.setPrinting(true); | 96 context.setPrinting(true); |
| 97 document().view()->paintContents(context, GlobalPaintPrinting, pageRect); | 97 document().view()->paintContents(context, GlobalPaintPrinting, pageRect); |
| 98 { | 98 { |
| 99 DrawingRecorder recorder(context, *document().layoutView(), | 99 DrawingRecorder recorder(context, *document().layoutView(), |
| 100 DisplayItem::kPrintedContentDestinationLocations, | 100 DisplayItem::kPrintedContentDestinationLocations, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); | 350 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); |
| 351 EXPECT_SKRECT_EQ(50, 60, 70, 80, | 351 EXPECT_SKRECT_EQ(50, 60, 70, 80, |
| 352 operations[0].rect); // FIXME: the rect should be clipped. | 352 operations[0].rect); // FIXME: the rect should be clipped. |
| 353 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); | 353 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); |
| 354 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); | 354 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); |
| 355 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); | 355 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); |
| 356 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); | 356 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); |
| 357 } | 357 } |
| 358 | 358 |
| 359 } // namespace blink | 359 } // namespace blink |
| OLD | NEW |