| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 class MockPrintContext : public PrintContext { | 30 class MockPrintContext : public PrintContext { |
| 31 public: | 31 public: |
| 32 MockPrintContext(LocalFrame* frame) : PrintContext(frame) {} | 32 MockPrintContext(LocalFrame* frame) : PrintContext(frame) {} |
| 33 | 33 |
| 34 void outputLinkedDestinations(GraphicsContext& context, | 34 void outputLinkedDestinations(GraphicsContext& context, |
| 35 const IntRect& pageRect) { | 35 const IntRect& pageRect) { |
| 36 PrintContext::outputLinkedDestinations(context, pageRect); | 36 PrintContext::outputLinkedDestinations(context, pageRect); |
| 37 } | 37 } |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 class MockCanvas : public PaintCanvas { | 40 class MockCanvas : public SkCanvas { |
| 41 public: | 41 public: |
| 42 enum OperationType { DrawRect, DrawPoint }; | 42 enum OperationType { DrawRect, DrawPoint }; |
| 43 | 43 |
| 44 struct Operation { | 44 struct Operation { |
| 45 OperationType type; | 45 OperationType type; |
| 46 SkRect rect; | 46 SkRect rect; |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 MockCanvas() : PaintCanvas(kPageWidth, kPageHeight) {} | 49 MockCanvas() : SkCanvas(kPageWidth, kPageHeight) {} |
| 50 | 50 |
| 51 void onDrawAnnotation(const SkRect& rect, | 51 void onDrawAnnotation(const SkRect& rect, |
| 52 const char key[], | 52 const char key[], |
| 53 SkData* value) override { | 53 SkData* value) override { |
| 54 if (rect.width() == 0 && rect.height() == 0) { | 54 if (rect.width() == 0 && rect.height() == 0) { |
| 55 SkPoint point = getTotalMatrix().mapXY(rect.x(), rect.y()); | 55 SkPoint point = getTotalMatrix().mapXY(rect.x(), rect.y()); |
| 56 Operation operation = {DrawPoint, | 56 Operation operation = {DrawPoint, |
| 57 SkRect::MakeXYWH(point.x(), point.y(), 0, 0)}; | 57 SkRect::MakeXYWH(point.x(), point.y(), 0, 0)}; |
| 58 m_recordedOperations.push_back(operation); | 58 m_recordedOperations.push_back(operation); |
| 59 } else { | 59 } else { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 81 m_printContext = new MockPrintContext(document().frame()); | 81 m_printContext = new MockPrintContext(document().frame()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 MockPrintContext& printContext() { return *m_printContext.get(); } | 84 MockPrintContext& printContext() { return *m_printContext.get(); } |
| 85 | 85 |
| 86 void setBodyInnerHTML(String bodyContent) { | 86 void setBodyInnerHTML(String bodyContent) { |
| 87 document().body()->setAttribute(HTMLNames::styleAttr, "margin: 0"); | 87 document().body()->setAttribute(HTMLNames::styleAttr, "margin: 0"); |
| 88 document().body()->setInnerHTML(bodyContent); | 88 document().body()->setInnerHTML(bodyContent); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void printSinglePage(PaintCanvas& canvas) { | 91 void printSinglePage(MockCanvas& canvas) { |
| 92 IntRect pageRect(0, 0, kPageWidth, kPageHeight); | 92 IntRect pageRect(0, 0, kPageWidth, kPageHeight); |
| 93 printContext().begin(pageRect.width(), pageRect.height()); | 93 printContext().begin(pageRect.width(), pageRect.height()); |
| 94 document().view()->updateAllLifecyclePhases(); | 94 document().view()->updateAllLifecyclePhases(); |
| 95 PaintRecordBuilder builder(pageRect); | 95 PaintRecordBuilder builder(pageRect); |
| 96 GraphicsContext& context = builder.context(); | 96 GraphicsContext& context = builder.context(); |
| 97 context.setPrinting(true); | 97 context.setPrinting(true); |
| 98 document().view()->paintContents(context, GlobalPaintPrinting, pageRect); | 98 document().view()->paintContents(context, GlobalPaintPrinting, pageRect); |
| 99 { | 99 { |
| 100 DrawingRecorder recorder(context, *document().layoutView(), | 100 DrawingRecorder recorder(context, *document().layoutView(), |
| 101 DisplayItem::kPrintedContentDestinationLocations, | 101 DisplayItem::kPrintedContentDestinationLocations, |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); | 351 EXPECT_EQ(MockCanvas::DrawRect, operations[0].type); |
| 352 EXPECT_SKRECT_EQ(50, 60, 70, 80, | 352 EXPECT_SKRECT_EQ(50, 60, 70, 80, |
| 353 operations[0].rect); // FIXME: the rect should be clipped. | 353 operations[0].rect); // FIXME: the rect should be clipped. |
| 354 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); | 354 EXPECT_EQ(MockCanvas::DrawRect, operations[1].type); |
| 355 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); | 355 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); |
| 356 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); | 356 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); |
| 357 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); | 357 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); |
| 358 } | 358 } |
| 359 | 359 |
| 360 } // namespace blink | 360 } // namespace blink |
| OLD | NEW |