| 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 "config.h" | 5 #include "config.h" |
| 6 #include "core/page/PrintContext.h" | 6 #include "core/page/PrintContext.h" |
| 7 | 7 |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/FrameHost.h" | 9 #include "core/frame/FrameHost.h" |
| 10 #include "core/frame/FrameView.h" | 10 #include "core/frame/FrameView.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 DrawPoint | 44 DrawPoint |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 struct Operation { | 47 struct Operation { |
| 48 OperationType type; | 48 OperationType type; |
| 49 SkRect rect; | 49 SkRect rect; |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 MockCanvas() : SkCanvas(kPageWidth, kPageHeight) { } | 52 MockCanvas() : SkCanvas(kPageWidth, kPageHeight) { } |
| 53 | 53 |
| 54 virtual void onDrawRect(const SkRect& rect, const SkPaint& paint) override | 54 void onDrawRect(const SkRect& rect, const SkPaint& paint) override |
| 55 { | 55 { |
| 56 if (!paint.getAnnotation()) | 56 if (!paint.getAnnotation()) |
| 57 return; | 57 return; |
| 58 Operation operation = { DrawRect, rect }; | 58 Operation operation = { DrawRect, rect }; |
| 59 getTotalMatrix().mapRect(&operation.rect); | 59 getTotalMatrix().mapRect(&operation.rect); |
| 60 m_recordedOperations.append(operation); | 60 m_recordedOperations.append(operation); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
const SkPaint& paint) override | 63 void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[], const S
kPaint& paint) override |
| 64 { | 64 { |
| 65 if (!paint.getAnnotation()) | 65 if (!paint.getAnnotation()) |
| 66 return; | 66 return; |
| 67 ASSERT_EQ(1u, count); // Only called from drawPoint(). | 67 ASSERT_EQ(1u, count); // Only called from drawPoint(). |
| 68 SkPoint point = getTotalMatrix().mapXY(pts[0].x(), pts[0].y()); | 68 SkPoint point = getTotalMatrix().mapXY(pts[0].x(), pts[0].y()); |
| 69 Operation operation = { DrawPoint, SkRect::MakeXYWH(point.x(), point.y()
, 0, 0) }; | 69 Operation operation = { DrawPoint, SkRect::MakeXYWH(point.x(), point.y()
, 0, 0) }; |
| 70 m_recordedOperations.append(operation); | 70 m_recordedOperations.append(operation); |
| 71 } | 71 } |
| 72 | 72 |
| 73 const Vector<Operation>& recordedOperations() const { return m_recordedOpera
tions; } | 73 const Vector<Operation>& recordedOperations() const { return m_recordedOpera
tions; } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 135 |
| 136 private: | 136 private: |
| 137 OwnPtr<DummyPageHolder> m_pageHolder; | 137 OwnPtr<DummyPageHolder> m_pageHolder; |
| 138 OwnPtrWillBePersistent<MockPrintContext> m_printContext; | 138 OwnPtrWillBePersistent<MockPrintContext> m_printContext; |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 class SingleChildFrameLoaderClient : public EmptyFrameLoaderClient { | 141 class SingleChildFrameLoaderClient : public EmptyFrameLoaderClient { |
| 142 public: | 142 public: |
| 143 SingleChildFrameLoaderClient() : m_child(nullptr) { } | 143 SingleChildFrameLoaderClient() : m_child(nullptr) { } |
| 144 | 144 |
| 145 virtual Frame* firstChild() const override { return m_child; } | 145 Frame* firstChild() const override { return m_child; } |
| 146 virtual Frame* lastChild() const override { return m_child; } | 146 Frame* lastChild() const override { return m_child; } |
| 147 | 147 |
| 148 void setChild(Frame* child) { m_child = child; } | 148 void setChild(Frame* child) { m_child = child; } |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 Frame* m_child; | 151 Frame* m_child; |
| 152 }; | 152 }; |
| 153 | 153 |
| 154 class FrameLoaderClientWithParent : public EmptyFrameLoaderClient { | 154 class FrameLoaderClientWithParent : public EmptyFrameLoaderClient { |
| 155 public: | 155 public: |
| 156 FrameLoaderClientWithParent(Frame* parent) : m_parent(parent) { } | 156 FrameLoaderClientWithParent(Frame* parent) : m_parent(parent) { } |
| 157 | 157 |
| 158 virtual Frame* parent() const override { return m_parent; } | 158 Frame* parent() const override { return m_parent; } |
| 159 | 159 |
| 160 private: | 160 private: |
| 161 Frame* m_parent; | 161 Frame* m_parent; |
| 162 }; | 162 }; |
| 163 | 163 |
| 164 class PrintContextFrameTest : public PrintContextTest { | 164 class PrintContextFrameTest : public PrintContextTest { |
| 165 public: | 165 public: |
| 166 PrintContextFrameTest() : PrintContextTest(adoptPtr(new SingleChildFrameLoad
erClient())) { } | 166 PrintContextFrameTest() : PrintContextTest(adoptPtr(new SingleChildFrameLoad
erClient())) { } |
| 167 }; | 167 }; |
| 168 | 168 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 188 // We should also check if the annotation is correct but Skia doesn't export | 188 // We should also check if the annotation is correct but Skia doesn't export |
| 189 // SkAnnotation API. | 189 // SkAnnotation API. |
| 190 } | 190 } |
| 191 | 191 |
| 192 class PrintContextTestWithSlimmingPaint : public PrintContextTest { | 192 class PrintContextTestWithSlimmingPaint : public PrintContextTest { |
| 193 public: | 193 public: |
| 194 PrintContextTestWithSlimmingPaint() | 194 PrintContextTestWithSlimmingPaint() |
| 195 : m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEn
abled()) { } | 195 : m_originalSlimmingPaintEnabled(RuntimeEnabledFeatures::slimmingPaintEn
abled()) { } |
| 196 | 196 |
| 197 protected: | 197 protected: |
| 198 virtual void SetUp() override | 198 void SetUp() override |
| 199 { | 199 { |
| 200 PrintContextTest::SetUp(); | 200 PrintContextTest::SetUp(); |
| 201 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); | 201 RuntimeEnabledFeatures::setSlimmingPaintEnabled(true); |
| 202 } | 202 } |
| 203 virtual void TearDown() override | 203 void TearDown() override |
| 204 { | 204 { |
| 205 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE
nabled); | 205 RuntimeEnabledFeatures::setSlimmingPaintEnabled(m_originalSlimmingPaintE
nabled); |
| 206 PrintContextTest::TearDown(); | 206 PrintContextTest::TearDown(); |
| 207 } | 207 } |
| 208 | 208 |
| 209 private: | 209 private: |
| 210 bool m_originalSlimmingPaintEnabled; | 210 bool m_originalSlimmingPaintEnabled; |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 TEST_F(PrintContextTest, LinkTarget) | 213 TEST_F(PrintContextTest, LinkTarget) |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); | 376 EXPECT_SKRECT_EQ(150, 160, 170, 180, operations[1].rect); |
| 377 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); | 377 EXPECT_EQ(MockCanvas::DrawRect, operations[2].type); |
| 378 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); | 378 EXPECT_SKRECT_EQ(250, 260, 270, 280, operations[2].rect); |
| 379 | 379 |
| 380 subframe->detach(FrameDetachType::Remove); | 380 subframe->detach(FrameDetachType::Remove); |
| 381 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); | 381 static_cast<SingleChildFrameLoaderClient*>(document().frame()->client())->se
tChild(nullptr); |
| 382 document().frame()->host()->decrementSubframeCount(); | 382 document().frame()->host()->decrementSubframeCount(); |
| 383 } | 383 } |
| 384 | 384 |
| 385 } // namespace blink | 385 } // namespace blink |
| OLD | NEW |