OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> | 2 * Copyright (C) 2007 Alp Toker <alp@atoker.com> |
3 * Copyright (C) 2007 Apple Inc. | 3 * Copyright (C) 2007 Apple Inc. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #include "core/page/PrintContext.h" | 21 #include "core/page/PrintContext.h" |
22 | 22 |
23 #include "core/frame/FrameView.h" | 23 #include "core/frame/FrameView.h" |
24 #include "core/frame/LocalFrame.h" | 24 #include "core/frame/LocalFrame.h" |
25 #include "core/layout/LayoutView.h" | 25 #include "core/layout/LayoutView.h" |
| 26 #include "core/layout/api/LayoutViewItem.h" |
26 #include "platform/graphics/GraphicsContext.h" | 27 #include "platform/graphics/GraphicsContext.h" |
27 | 28 |
28 namespace blink { | 29 namespace blink { |
29 | 30 |
30 // By shrinking to a width of 75% (1.333f) we will render the correct physical | 31 // By shrinking to a width of 75% (1.333f) we will render the correct physical |
31 // dimensions in paged media (i.e. cm, pt,). The shrinkage used | 32 // dimensions in paged media (i.e. cm, pt,). The shrinkage used |
32 // to be 80% (1.25f) to match other browsers - they have since moved on. | 33 // to be 80% (1.25f) to match other browsers - they have since moved on. |
33 // Wide pages will be scaled down more than this. | 34 // Wide pages will be scaled down more than this. |
34 const float printingMinimumShrinkFactor = 1.333f; | 35 const float printingMinimumShrinkFactor = 1.333f; |
35 | 36 |
(...skipping 15 matching lines...) Expand all Loading... |
51 { | 52 { |
52 if (m_isPrinting) | 53 if (m_isPrinting) |
53 end(); | 54 end(); |
54 } | 55 } |
55 | 56 |
56 void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
ht, float footerHeight, float userScaleFactor, float& outPageHeight) | 57 void PrintContext::computePageRects(const FloatRect& printRect, float headerHeig
ht, float footerHeight, float userScaleFactor, float& outPageHeight) |
57 { | 58 { |
58 m_pageRects.clear(); | 59 m_pageRects.clear(); |
59 outPageHeight = 0; | 60 outPageHeight = 0; |
60 | 61 |
61 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->layout
View()) | 62 if (!m_frame->document() || !m_frame->view() || m_frame->document()->layoutV
iewItem().isNull()) |
62 return; | 63 return; |
63 | 64 |
64 if (userScaleFactor <= 0) { | 65 if (userScaleFactor <= 0) { |
65 DLOG(ERROR) << "userScaleFactor has bad value " << userScaleFactor; | 66 DLOG(ERROR) << "userScaleFactor has bad value " << userScaleFactor; |
66 return; | 67 return; |
67 } | 68 } |
68 | 69 |
69 LayoutView* view = m_frame->document()->layoutView(); | 70 LayoutViewItem view = m_frame->document()->layoutViewItem(); |
70 const IntRect& documentRect = view->documentRect(); | 71 const IntRect& documentRect = view.documentRect(); |
71 FloatSize pageSize = m_frame->resizePageRectsKeepingRatio(FloatSize(printRec
t.width(), printRect.height()), FloatSize(documentRect.width(), documentRect.hei
ght())); | 72 FloatSize pageSize = m_frame->resizePageRectsKeepingRatio(FloatSize(printRec
t.width(), printRect.height()), FloatSize(documentRect.width(), documentRect.hei
ght())); |
72 float pageWidth = pageSize.width(); | 73 float pageWidth = pageSize.width(); |
73 float pageHeight = pageSize.height(); | 74 float pageHeight = pageSize.height(); |
74 | 75 |
75 outPageHeight = pageHeight; // this is the height of the page adjusted by ma
rgins | 76 outPageHeight = pageHeight; // this is the height of the page adjusted by ma
rgins |
76 pageHeight -= headerHeight + footerHeight; | 77 pageHeight -= headerHeight + footerHeight; |
77 | 78 |
78 if (pageHeight <= 0) { | 79 if (pageHeight <= 0) { |
79 DLOG(ERROR) << "pageHeight has bad value " << pageHeight; | 80 DLOG(ERROR) << "pageHeight has bad value " << pageHeight; |
80 return; | 81 return; |
81 } | 82 } |
82 | 83 |
83 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor,
pageHeight / userScaleFactor)); | 84 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor,
pageHeight / userScaleFactor)); |
84 } | 85 } |
85 | 86 |
86 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixel
s) | 87 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixel
s) |
87 { | 88 { |
88 m_pageRects.clear(); | 89 m_pageRects.clear(); |
89 computePageRectsWithPageSizeInternal(pageSizeInPixels); | 90 computePageRectsWithPageSizeInternal(pageSizeInPixels); |
90 } | 91 } |
91 | 92 |
92 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
eInPixels) | 93 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
eInPixels) |
93 { | 94 { |
94 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->layout
View()) | 95 if (!m_frame->document() || !m_frame->view() || m_frame->document()->layoutV
iewItem().isNull()) |
95 return; | 96 return; |
96 | 97 |
97 LayoutView* view = m_frame->document()->layoutView(); | 98 LayoutViewItem view = m_frame->document()->layoutViewItem(); |
98 | 99 |
99 IntRect docRect = view->documentRect(); | 100 IntRect docRect = view.documentRect(); |
100 | 101 |
101 int pageWidth = pageSizeInPixels.width(); | 102 int pageWidth = pageSizeInPixels.width(); |
102 // We scaled with floating point arithmetic and need to ensure results like
13329.99 | 103 // We scaled with floating point arithmetic and need to ensure results like
13329.99 |
103 // are treated as 13330 so that we don't mistakenly assign an extra page for
the | 104 // are treated as 13330 so that we don't mistakenly assign an extra page for
the |
104 // stray pixel. | 105 // stray pixel. |
105 int pageHeight = pageSizeInPixels.height() + LayoutUnit::epsilon(); | 106 int pageHeight = pageSizeInPixels.height() + LayoutUnit::epsilon(); |
106 | 107 |
107 bool isHorizontal = view->style()->isHorizontalWritingMode(); | 108 bool isHorizontal = view.style()->isHorizontalWritingMode(); |
108 | 109 |
109 int docLogicalHeight = isHorizontal ? docRect.height() : docRect.width(); | 110 int docLogicalHeight = isHorizontal ? docRect.height() : docRect.width(); |
110 int pageLogicalHeight = isHorizontal ? pageHeight : pageWidth; | 111 int pageLogicalHeight = isHorizontal ? pageHeight : pageWidth; |
111 int pageLogicalWidth = isHorizontal ? pageWidth : pageHeight; | 112 int pageLogicalWidth = isHorizontal ? pageWidth : pageHeight; |
112 | 113 |
113 int inlineDirectionStart; | 114 int inlineDirectionStart; |
114 int inlineDirectionEnd; | 115 int inlineDirectionEnd; |
115 int blockDirectionStart; | 116 int blockDirectionStart; |
116 int blockDirectionEnd; | 117 int blockDirectionEnd; |
117 if (isHorizontal) { | 118 if (isHorizontal) { |
118 if (view->style()->isFlippedBlocksWritingMode()) { | 119 if (view.style()->isFlippedBlocksWritingMode()) { |
119 blockDirectionStart = docRect.maxY(); | 120 blockDirectionStart = docRect.maxY(); |
120 blockDirectionEnd = docRect.y(); | 121 blockDirectionEnd = docRect.y(); |
121 } else { | 122 } else { |
122 blockDirectionStart = docRect.y(); | 123 blockDirectionStart = docRect.y(); |
123 blockDirectionEnd = docRect.maxY(); | 124 blockDirectionEnd = docRect.maxY(); |
124 } | 125 } |
125 inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect
.x() : docRect.maxX(); | 126 inlineDirectionStart = view.style()->isLeftToRightDirection() ? docRect.
x() : docRect.maxX(); |
126 inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.m
axX() : docRect.x(); | 127 inlineDirectionEnd = view.style()->isLeftToRightDirection() ? docRect.ma
xX() : docRect.x(); |
127 } else { | 128 } else { |
128 if (view->style()->isFlippedBlocksWritingMode()) { | 129 if (view.style()->isFlippedBlocksWritingMode()) { |
129 blockDirectionStart = docRect.maxX(); | 130 blockDirectionStart = docRect.maxX(); |
130 blockDirectionEnd = docRect.x(); | 131 blockDirectionEnd = docRect.x(); |
131 } else { | 132 } else { |
132 blockDirectionStart = docRect.x(); | 133 blockDirectionStart = docRect.x(); |
133 blockDirectionEnd = docRect.maxX(); | 134 blockDirectionEnd = docRect.maxX(); |
134 } | 135 } |
135 inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect
.y() : docRect.maxY(); | 136 inlineDirectionStart = view.style()->isLeftToRightDirection() ? docRect.
y() : docRect.maxY(); |
136 inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.m
axY() : docRect.y(); | 137 inlineDirectionEnd = view.style()->isLeftToRightDirection() ? docRect.ma
xY() : docRect.y(); |
137 } | 138 } |
138 | 139 |
139 unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight); | 140 unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight); |
140 for (unsigned i = 0; i < pageCount; ++i) { | 141 for (unsigned i = 0; i < pageCount; ++i) { |
141 int pageLogicalTop = blockDirectionEnd > blockDirectionStart ? | 142 int pageLogicalTop = blockDirectionEnd > blockDirectionStart ? |
142 blockDirectionStart + i * pageLogicalHeight : | 143 blockDirectionStart + i * pageLogicalHeight : |
143 blockDirectionStart - (i + 1) * pageLogicalHeight; | 144 blockDirectionStart - (i + 1) * pageLogicalHeight; |
144 | 145 |
145 int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? inline
DirectionStart : inlineDirectionStart - pageLogicalWidth; | 146 int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? inline
DirectionStart : inlineDirectionStart - pageLogicalWidth; |
146 IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, page
LogicalHeight); | 147 IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, page
LogicalHeight); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 return printContext.pageCount(); | 314 return printContext.pageCount(); |
314 } | 315 } |
315 | 316 |
316 DEFINE_TRACE(PrintContext) | 317 DEFINE_TRACE(PrintContext) |
317 { | 318 { |
318 visitor->trace(m_frame); | 319 visitor->trace(m_frame); |
319 visitor->trace(m_linkedDestinations); | 320 visitor->trace(m_linkedDestinations); |
320 } | 321 } |
321 | 322 |
322 } // namespace blink | 323 } // namespace blink |
OLD | NEW |