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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 object = object->parent(); | 232 object = object->parent(); |
233 if (!object) | 233 if (!object) |
234 return 0; | 234 return 0; |
235 return toRenderBoxModelObject(object); | 235 return toRenderBoxModelObject(object); |
236 } | 236 } |
237 | 237 |
238 int PrintContext::pageNumberForElement(Element* element, const FloatSize& pageSi
zeInPixels) | 238 int PrintContext::pageNumberForElement(Element* element, const FloatSize& pageSi
zeInPixels) |
239 { | 239 { |
240 // Make sure the element is not freed during the layout. | 240 // Make sure the element is not freed during the layout. |
241 RefPtr<Element> elementRef(element); | 241 RefPtr<Element> elementRef(element); |
242 element->document()->updateLayout(); | 242 element->document().updateLayout(); |
243 | 243 |
244 RenderBoxModelObject* box = enclosingBoxModelObject(element->renderer()); | 244 RenderBoxModelObject* box = enclosingBoxModelObject(element->renderer()); |
245 if (!box) | 245 if (!box) |
246 return -1; | 246 return -1; |
247 | 247 |
248 Frame* frame = element->document()->frame(); | 248 Frame* frame = element->document().frame(); |
249 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); | 249 FloatRect pageRect(FloatPoint(0, 0), pageSizeInPixels); |
250 PrintContext printContext(frame); | 250 PrintContext printContext(frame); |
251 printContext.begin(pageRect.width(), pageRect.height()); | 251 printContext.begin(pageRect.width(), pageRect.height()); |
252 FloatSize scaledPageSize = pageSizeInPixels; | 252 FloatSize scaledPageSize = pageSizeInPixels; |
253 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); | 253 scaledPageSize.scale(frame->view()->contentsSize().width() / pageRect.width(
)); |
254 printContext.computePageRectsWithPageSize(scaledPageSize, false); | 254 printContext.computePageRectsWithPageSize(scaledPageSize, false); |
255 | 255 |
256 int top = box->pixelSnappedOffsetTop(); | 256 int top = box->pixelSnappedOffsetTop(); |
257 int left = box->pixelSnappedOffsetLeft(); | 257 int left = box->pixelSnappedOffsetLeft(); |
258 size_t pageNumber = 0; | 258 size_t pageNumber = 0; |
259 for (; pageNumber < printContext.pageCount(); pageNumber++) { | 259 for (; pageNumber < printContext.pageCount(); pageNumber++) { |
260 const IntRect& page = printContext.pageRect(pageNumber); | 260 const IntRect& page = printContext.pageRect(pageNumber); |
261 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) | 261 if (page.x() <= left && left < page.maxX() && page.y() <= top && top < p
age.maxY()) |
262 return pageNumber; | 262 return pageNumber; |
263 } | 263 } |
264 return -1; | 264 return -1; |
265 } | 265 } |
266 | 266 |
267 void PrintContext::collectLinkedDestinations(Node* node) | 267 void PrintContext::collectLinkedDestinations(Node* node) |
268 { | 268 { |
269 for (Node* i = node->firstChild(); i; i = i->nextSibling()) | 269 for (Node* i = node->firstChild(); i; i = i->nextSibling()) |
270 collectLinkedDestinations(i); | 270 collectLinkedDestinations(i); |
271 | 271 |
272 if (!node->isLink() || !node->isElementNode()) | 272 if (!node->isLink() || !node->isElementNode()) |
273 return; | 273 return; |
274 const AtomicString& href = toElement(node)->getAttribute(HTMLNames::hrefAttr
); | 274 const AtomicString& href = toElement(node)->getAttribute(HTMLNames::hrefAttr
); |
275 if (href.isNull()) | 275 if (href.isNull()) |
276 return; | 276 return; |
277 KURL url = node->document()->completeURL(href); | 277 KURL url = node->document().completeURL(href); |
278 if (!url.isValid()) | 278 if (!url.isValid()) |
279 return; | 279 return; |
280 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(url, node
->document()->baseURL())) { | 280 if (url.hasFragmentIdentifier() && equalIgnoringFragmentIdentifier(url, node
->document().baseURL())) { |
281 String name = url.fragmentIdentifier(); | 281 String name = url.fragmentIdentifier(); |
282 Element* element = node->document()->findAnchor(name); | 282 Element* element = node->document().findAnchor(name); |
283 if (element) | 283 if (element) |
284 m_linkedDestinations.set(name, element); | 284 m_linkedDestinations.set(name, element); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 void PrintContext::outputLinkedDestinations(GraphicsContext& graphicsContext, No
de* node, const IntRect& pageRect) | 288 void PrintContext::outputLinkedDestinations(GraphicsContext& graphicsContext, No
de* node, const IntRect& pageRect) |
289 { | 289 { |
290 if (!m_linkedDestinationsValid) { | 290 if (!m_linkedDestinationsValid) { |
291 collectLinkedDestinations(node); | 291 collectLinkedDestinations(node); |
292 m_linkedDestinationsValid = true; | 292 m_linkedDestinationsValid = true; |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 printContext.spoolPage(graphicsContext, pageIndex, pageWidth); | 402 printContext.spoolPage(graphicsContext, pageIndex, pageWidth); |
403 graphicsContext.restore(); | 403 graphicsContext.restore(); |
404 | 404 |
405 currentHeight += pageSizeInPixels.height() + 1; | 405 currentHeight += pageSizeInPixels.height() + 1; |
406 } | 406 } |
407 | 407 |
408 graphicsContext.restore(); | 408 graphicsContext.restore(); |
409 } | 409 } |
410 | 410 |
411 } | 411 } |
OLD | NEW |