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