2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
32 #include "AffineTransform.h"
33 #include "FloatRect.h"
35 #include "EditorClient.h"
36 #include "FrameLoader.h"
37 #include "FrameLoadRequest.h"
38 #include "FramePrivate.h"
39 #include "FrameView.h"
40 #include "HTMLIFrameElement.h"
41 #include "HTMLNames.h"
42 #include "HTMLTableCellElement.h"
43 #include "KeyboardEvent.h"
44 #include "NP_jsobject.h"
45 #include "NotImplemented.h"
48 #include "PluginDatabase.h"
49 #include "PluginView.h"
50 #include "RegularExpression.h"
51 #include "RenderFrame.h"
52 #include "RenderTableCell.h"
53 #include "RenderView.h"
54 #include "ResourceHandle.h"
55 #include "TextResourceDecoder.h"
56 #include "kjs_proxy.h"
57 #include "kjs_window.h"
58 #include "npruntime_impl.h"
59 #include "runtime_root.h"
60 #include "GraphicsContext.h"
64 using namespace KJS::Bindings;
68 using namespace HTMLNames;
70 void Frame::clearPlatformScriptObjects()
74 KJS::Bindings::Instance* Frame::createScriptInstanceForWidget(Widget* widget)
76 // FIXME: Ideally we'd have an isPluginView() here but we can't add that to the open source tree right now.
77 if (widget->isFrameView())
80 return static_cast<PluginView*>(widget)->bindingInstance();
83 void computePageRectsForFrame(Frame* frame, const IntRect& printRect, float headerHeight, float footerHeight, float userScaleFactor,Vector<IntRect>& pages, int& outPageHeight)
90 if (!frame->document() || !frame->view() || !frame->document()->renderer())
93 RenderView* root = static_cast<RenderView *>(frame->document()->renderer());
96 LOG_ERROR("document to be printed has no renderer");
100 if (userScaleFactor <= 0) {
101 LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor);
105 float ratio = static_cast<float>(printRect.height()) / static_cast<float>(printRect.width());
107 float pageWidth = static_cast<float>(root->docWidth());
108 float pageHeight = pageWidth * ratio;
109 outPageHeight = static_cast<int>(pageHeight); // this is the height of the page adjusted by margins
110 pageHeight -= (headerHeight + footerHeight);
112 if (pageHeight <= 0) {
113 LOG_ERROR("pageHeight has bad value %.2f", pageHeight);
117 float currPageHeight = pageHeight / userScaleFactor;
118 float docHeight = root->layer()->height();
119 float docWidth = root->layer()->width();
120 float currPageWidth = pageWidth / userScaleFactor;
123 // always return at least one page, since empty files should print a blank page
124 float printedPagesHeight = 0.0f;
126 float proposedBottom = min(docHeight, printedPagesHeight + pageHeight);
127 frame->adjustPageHeight(&proposedBottom, printedPagesHeight, proposedBottom, printedPagesHeight);
128 currPageHeight = max(1.0f, proposedBottom - printedPagesHeight);
130 pages.append(IntRect(0, printedPagesHeight, currPageWidth, currPageHeight));
131 printedPagesHeight += currPageHeight;
132 } while (printedPagesHeight < docHeight);
135 DragImageRef Frame::dragImageForSelection()
137 if (selectionController()->isRange())
138 return imageFromSelection(this, false);
143 } // namespace WebCore