| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #if USE(JSC) | |
| 28 #include "runtime.h" | |
| 29 #elif USE(V8) | |
| 30 #include "npruntime_priv.h" | |
| 31 #endif | |
| 32 #include "FrameWin.h" | |
| 33 | |
| 34 #include "AffineTransform.h" | |
| 35 #include "FloatRect.h" | |
| 36 #include "Document.h" | |
| 37 #include "FramePrivate.h" | |
| 38 #include "RenderView.h" | |
| 39 #include "Settings.h" | |
| 40 | |
| 41 using std::min; | |
| 42 | |
| 43 namespace WebCore { | |
| 44 | |
| 45 void computePageRectsForFrame(Frame* frame, const IntRect& printRect, float head
erHeight, float footerHeight, float userScaleFactor, Vector<IntRect>& pages, int
& outPageHeight) | |
| 46 { | |
| 47 ASSERT(frame); | |
| 48 | |
| 49 pages.clear(); | |
| 50 outPageHeight = 0; | |
| 51 | |
| 52 if (!frame->document() || !frame->view() || !frame->document()->renderer()) | |
| 53 return; | |
| 54 | |
| 55 RenderView* root = static_cast<RenderView*>(frame->document()->renderer()); | |
| 56 | |
| 57 if (!root) { | |
| 58 LOG_ERROR("document to be printed has no renderer"); | |
| 59 return; | |
| 60 } | |
| 61 | |
| 62 if (userScaleFactor <= 0) { | |
| 63 LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); | |
| 64 return; | |
| 65 } | |
| 66 | |
| 67 float ratio = static_cast<float>(printRect.height()) / static_cast<float>(pr
intRect.width()); | |
| 68 | |
| 69 float pageWidth = static_cast<float>(root->docWidth()); | |
| 70 float pageHeight = pageWidth * ratio; | |
| 71 outPageHeight = static_cast<int>(pageHeight); // this is the height of the
page adjusted by margins | |
| 72 pageHeight -= (headerHeight + footerHeight); | |
| 73 | |
| 74 if (pageHeight <= 0) { | |
| 75 LOG_ERROR("pageHeight has bad value %.2f", pageHeight); | |
| 76 return; | |
| 77 } | |
| 78 | |
| 79 float currPageHeight = pageHeight / userScaleFactor; | |
| 80 float docHeight = root->layer()->height(); | |
| 81 float docWidth = root->layer()->width(); | |
| 82 float currPageWidth = pageWidth / userScaleFactor; | |
| 83 | |
| 84 | |
| 85 // always return at least one page, since empty files should print a blank p
age | |
| 86 float printedPagesHeight = 0.0f; | |
| 87 do { | |
| 88 float proposedBottom = min(docHeight, printedPagesHeight + pageHeight); | |
| 89 frame->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBot
tom, printedPagesHeight); | |
| 90 currPageHeight = max(1.0f, proposedBottom - printedPagesHeight); | |
| 91 | |
| 92 pages.append(IntRect(0, printedPagesHeight, currPageWidth, currPageHeigh
t)); | |
| 93 printedPagesHeight += currPageHeight; | |
| 94 } while (printedPagesHeight < docHeight); | |
| 95 } | |
| 96 | |
| 97 DragImageRef Frame::dragImageForSelection() | |
| 98 { | |
| 99 if (selection()->isRange()) | |
| 100 return 0; // TODO(pkasting): http://b/119669 Implement me! | |
| 101 | |
| 102 return 0; | |
| 103 } | |
| 104 | |
| 105 } // namespace WebCore | |
| OLD | NEW |