| 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 object = object->parent(); | 183 object = object->parent(); |
| 184 if (!object) | 184 if (!object) |
| 185 return nullptr; | 185 return nullptr; |
| 186 return toLayoutBoxModelObject(object); | 186 return toLayoutBoxModelObject(object); |
| 187 } | 187 } |
| 188 | 188 |
| 189 int PrintContext::pageNumberForElement(Element* element, const FloatSize& pageSi
zeInPixels) | 189 int PrintContext::pageNumberForElement(Element* element, const FloatSize& pageSi
zeInPixels) |
| 190 { | 190 { |
| 191 element->document().updateLayout(); | 191 element->document().updateLayout(); |
| 192 | 192 |
| 193 LocalFrame* frame = element->document().frame(); |
| 194 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); |
| 195 PrintContext printContext(frame); |
| 196 printContext.begin(pageRect.width(), pageRect.height()); |
| 197 |
| 193 LayoutBoxModelObject* box = enclosingBoxModelObject(element->layoutObject())
; | 198 LayoutBoxModelObject* box = enclosingBoxModelObject(element->layoutObject())
; |
| 194 if (!box) | 199 if (!box) |
| 195 return -1; | 200 return -1; |
| 196 | 201 |
| 197 LocalFrame* frame = element->document().frame(); | |
| 198 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); | |
| 199 PrintContext printContext(frame); | |
| 200 printContext.begin(pageRect.width(), pageRect.height()); | |
| 201 FloatSize scaledPageSize = pageSizeInPixels; | 202 FloatSize scaledPageSize = pageSizeInPixels; |
| 202 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); | 203 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); |
| 203 printContext.computePageRectsWithPageSize(scaledPageSize); | 204 printContext.computePageRectsWithPageSize(scaledPageSize); |
| 204 | 205 |
| 205 int top = box->pixelSnappedOffsetTop(); | 206 int top = box->pixelSnappedOffsetTop(); |
| 206 int left = box->pixelSnappedOffsetLeft(); | 207 int left = box->pixelSnappedOffsetLeft(); |
| 207 size_t pageNumber = 0; | 208 size_t pageNumber = 0; |
| 208 for (; pageNumber < printContext.pageCount(); pageNumber++) { | 209 for (; pageNumber < printContext.pageCount(); pageNumber++) { |
| 209 const IntRect& page = printContext.pageRect(pageNumber); | 210 const IntRect& page = printContext.pageRect(pageNumber); |
| 210 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) | 211 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return printContext.pageCount(); | 315 return printContext.pageCount(); |
| 315 } | 316 } |
| 316 | 317 |
| 317 DEFINE_TRACE(PrintContext) | 318 DEFINE_TRACE(PrintContext) |
| 318 { | 319 { |
| 319 visitor->trace(m_frame); | 320 visitor->trace(m_frame); |
| 320 visitor->trace(m_linkedDestinations); | 321 visitor->trace(m_linkedDestinations); |
| 321 } | 322 } |
| 322 | 323 |
| 323 } // namespace blink | 324 } // namespace blink |
| OLD | NEW |