| 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, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 float pageHeight = pageSize.height(); | 74 float pageHeight = pageSize.height(); |
| 75 | 75 |
| 76 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 |
| 77 pageHeight -= headerHeight + footerHeight; | 77 pageHeight -= headerHeight + footerHeight; |
| 78 | 78 |
| 79 if (pageHeight <= 0) { | 79 if (pageHeight <= 0) { |
| 80 WTF_LOG_ERROR("pageHeight has bad value %.2f", pageHeight); | 80 WTF_LOG_ERROR("pageHeight has bad value %.2f", pageHeight); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 | 83 |
| 84 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor,
pageHeight / userScaleFactor), false); | 84 computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor,
pageHeight / userScaleFactor)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixel
s, bool allowHorizontalTiling) | 87 void PrintContext::computePageRectsWithPageSize(const FloatSize& pageSizeInPixel
s) |
| 88 { | 88 { |
| 89 m_pageRects.clear(); | 89 m_pageRects.clear(); |
| 90 computePageRectsWithPageSizeInternal(pageSizeInPixels, allowHorizontalTiling
); | 90 computePageRectsWithPageSizeInternal(pageSizeInPixels); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
eInPixels, bool allowInlineDirectionTiling) | 93 void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSiz
eInPixels) |
| 94 { | 94 { |
| 95 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->layout
View()) | 95 if (!m_frame->document() || !m_frame->view() || !m_frame->document()->layout
View()) |
| 96 return; | 96 return; |
| 97 | 97 |
| 98 LayoutView* view = m_frame->document()->layoutView(); | 98 LayoutView* view = m_frame->document()->layoutView(); |
| 99 | 99 |
| 100 IntRect docRect = view->documentRect(); | 100 IntRect docRect = view->documentRect(); |
| 101 | 101 |
| 102 int pageWidth = pageSizeInPixels.width(); | 102 int pageWidth = pageSizeInPixels.width(); |
| 103 int pageHeight = pageSizeInPixels.height(); | 103 int pageHeight = pageSizeInPixels.height(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 132 } | 132 } |
| 133 inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect
.y() : docRect.maxY(); | 133 inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect
.y() : docRect.maxY(); |
| 134 inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.m
axY() : docRect.y(); | 134 inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.m
axY() : docRect.y(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight); | 137 unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight); |
| 138 for (unsigned i = 0; i < pageCount; ++i) { | 138 for (unsigned i = 0; i < pageCount; ++i) { |
| 139 int pageLogicalTop = blockDirectionEnd > blockDirectionStart ? | 139 int pageLogicalTop = blockDirectionEnd > blockDirectionStart ? |
| 140 blockDirectionStart + i * pageLogicalHeight : | 140 blockDirectionStart + i * pageLogicalHeight : |
| 141 blockDirectionStart - (i + 1) * pageLogicalHeigh
t; | 141 blockDirectionStart - (i + 1) * pageLogicalHeigh
t; |
| 142 if (allowInlineDirectionTiling) { | 142 |
| 143 for (int currentInlinePosition = inlineDirectionStart; | 143 int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? inline
DirectionStart : inlineDirectionStart - pageLogicalWidth; |
| 144 inlineDirectionEnd > inlineDirectionStart ? currentInlinePositi
on < inlineDirectionEnd : currentInlinePosition > inlineDirectionEnd; | 144 IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, page
LogicalHeight); |
| 145 currentInlinePosition += (inlineDirectionEnd > inlineDirectionS
tart ? pageLogicalWidth : -pageLogicalWidth)) { | 145 if (!isHorizontal) |
| 146 int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart
? currentInlinePosition : currentInlinePosition - pageLogicalWidth; | 146 pageRect = pageRect.transposedRect(); |
| 147 IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWid
th, pageLogicalHeight); | 147 m_pageRects.append(pageRect); |
| 148 if (!isHorizontal) | 148 |
| 149 pageRect = pageRect.transposedRect(); | |
| 150 m_pageRects.append(pageRect); | |
| 151 } | |
| 152 } else { | |
| 153 int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? in
lineDirectionStart : inlineDirectionStart - pageLogicalWidth; | |
| 154 IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth,
pageLogicalHeight); | |
| 155 if (!isHorizontal) | |
| 156 pageRect = pageRect.transposedRect(); | |
| 157 m_pageRects.append(pageRect); | |
| 158 } | |
| 159 } | 149 } |
| 160 } | 150 } |
| 161 | 151 |
| 162 void PrintContext::begin(float width, float height) | 152 void PrintContext::begin(float width, float height) |
| 163 { | 153 { |
| 164 // This function can be called multiple times to adjust printing parameters
without going back to screen mode. | 154 // This function can be called multiple times to adjust printing parameters
without going back to screen mode. |
| 165 m_isPrinting = true; | 155 m_isPrinting = true; |
| 166 | 156 |
| 167 FloatSize originalPageSize = FloatSize(width, height); | 157 FloatSize originalPageSize = FloatSize(width, height); |
| 168 FloatSize minLayoutSize = m_frame->resizePageRectsKeepingRatio(originalPageS
ize, FloatSize(width * printingMinimumShrinkFactor, height * printingMinimumShri
nkFactor)); | 158 FloatSize minLayoutSize = m_frame->resizePageRectsKeepingRatio(originalPageS
ize, FloatSize(width * printingMinimumShrinkFactor, height * printingMinimumShri
nkFactor)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 LayoutBoxModelObject* box = enclosingBoxModelObject(element->layoutObject())
; | 190 LayoutBoxModelObject* box = enclosingBoxModelObject(element->layoutObject())
; |
| 201 if (!box) | 191 if (!box) |
| 202 return -1; | 192 return -1; |
| 203 | 193 |
| 204 LocalFrame* frame = element->document().frame(); | 194 LocalFrame* frame = element->document().frame(); |
| 205 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); | 195 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); |
| 206 PrintContext printContext(frame); | 196 PrintContext printContext(frame); |
| 207 printContext.begin(pageRect.width(), pageRect.height()); | 197 printContext.begin(pageRect.width(), pageRect.height()); |
| 208 FloatSize scaledPageSize = pageSizeInPixels; | 198 FloatSize scaledPageSize = pageSizeInPixels; |
| 209 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); | 199 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); |
| 210 printContext.computePageRectsWithPageSize(scaledPageSize, false); | 200 printContext.computePageRectsWithPageSize(scaledPageSize); |
| 211 | 201 |
| 212 int top = box->pixelSnappedOffsetTop(); | 202 int top = box->pixelSnappedOffsetTop(); |
| 213 int left = box->pixelSnappedOffsetLeft(); | 203 int left = box->pixelSnappedOffsetLeft(); |
| 214 size_t pageNumber = 0; | 204 size_t pageNumber = 0; |
| 215 for (; pageNumber < printContext.pageCount(); pageNumber++) { | 205 for (; pageNumber < printContext.pageCount(); pageNumber++) { |
| 216 const IntRect& page = printContext.pageRect(pageNumber); | 206 const IntRect& page = printContext.pageRect(pageNumber); |
| 217 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) | 207 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) |
| 218 return pageNumber; | 208 return pageNumber; |
| 219 } | 209 } |
| 220 return -1; | 210 return -1; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 int PrintContext::numberOfPages(LocalFrame* frame, const FloatSize& pageSizeInPi
xels) | 328 int PrintContext::numberOfPages(LocalFrame* frame, const FloatSize& pageSizeInPi
xels) |
| 339 { | 329 { |
| 340 frame->document()->updateLayout(); | 330 frame->document()->updateLayout(); |
| 341 | 331 |
| 342 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); | 332 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); |
| 343 PrintContext printContext(frame); | 333 PrintContext printContext(frame); |
| 344 printContext.begin(pageRect.width(), pageRect.height()); | 334 printContext.begin(pageRect.width(), pageRect.height()); |
| 345 // Account for shrink-to-fit. | 335 // Account for shrink-to-fit. |
| 346 FloatSize scaledPageSize = pageSizeInPixels; | 336 FloatSize scaledPageSize = pageSizeInPixels; |
| 347 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); | 337 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); |
| 348 printContext.computePageRectsWithPageSize(scaledPageSize, false); | 338 printContext.computePageRectsWithPageSize(scaledPageSize); |
| 349 return printContext.pageCount(); | 339 return printContext.pageCount(); |
| 350 } | 340 } |
| 351 | 341 |
| 352 DEFINE_TRACE(PrintContext) | 342 DEFINE_TRACE(PrintContext) |
| 353 { | 343 { |
| 354 #if ENABLE(OILPAN) | 344 #if ENABLE(OILPAN) |
| 355 visitor->trace(m_frame); | 345 visitor->trace(m_frame); |
| 356 visitor->trace(m_linkDestinations); | 346 visitor->trace(m_linkDestinations); |
| 357 visitor->trace(m_linkedDestinations); | 347 visitor->trace(m_linkedDestinations); |
| 358 #endif | 348 #endif |
| 359 } | 349 } |
| 360 | 350 |
| 361 } | 351 } |
| OLD | NEW |