2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
3 * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include "RenderObject.h"
32 #include "RenderWidget.h"
33 #include "RenderLayer.h"
36 #include "DOMWindow.h"
37 #include "DOMImplementation.h"
38 #include "BrowserExtensionGdk.h"
42 #include "FramePrivate.h"
43 #include "GraphicsContext.h"
44 #include "HTMLDocument.h"
45 #include "ResourceLoader.h"
46 #include "PlatformMouseEvent.h"
47 #include "PlatformKeyboardEvent.h"
48 #include "PlatformWheelEvent.h"
49 #include "MouseEventWithHitTestResults.h"
50 #include "SelectionController.h"
51 #include "TypingCommand.h"
52 #include "SSLKeyGenerator.h"
53 #include "KeyboardCodes.h"
57 // This function loads resources from WebKit
58 // This does not belong here and I'm not sure where
60 // I don't know what the plans or design is
61 // for none code resources
62 Vector<char> loadResourceIntoArray(const char* resourceName)
64 Vector<char> resource;
65 //if (strcmp(resourceName,"missingImage") == 0) {
72 static void doScroll(const RenderObject* r, bool isHorizontal, int multiplier)
74 // FIXME: The scrolling done here should be done in the default handlers
75 // of the elements rather than here in the part.
79 //broken since it calls scroll on scrollbars
80 //and we have none now
81 //r->scroll(direction, ScrollByWheel, multiplier);
84 int x = r->layer()->scrollXOffset();
85 int y = r->layer()->scrollYOffset();
90 r->layer()->scrollToOffset(x, y, true, true);
93 bool FrameView::isFrameView() const
98 FrameGdk::FrameGdk(GdkDrawable* gdkdrawable)
99 : Frame(new Page, 0), m_drawable(gdkdrawable)
101 d->m_extension = new BrowserExtensionGdk(this);
102 Settings* settings = new Settings;
103 settings->setAutoLoadImages(true);
104 settings->setMinFontSize(5);
105 settings->setMinLogicalFontSize(5);
106 settings->setShouldPrintBackgrounds(true);
108 settings->setMediumFixedFontSize(14);
109 settings->setMediumFontSize(14);
110 settings->setSerifFontName("Times New Roman");
111 settings->setSansSerifFontName("Arial");
112 settings->setFixedFontName("Courier");
113 settings->setStdFontName("Arial");
114 setSettings(settings);
115 page()->setMainFrame(this);
116 FrameView* view = new FrameView(this);
118 IntRect geom = frameGeometry();
119 view->resize(geom.width(), geom.height());
120 view->ScrollView::setDrawable(gdkdrawable);
123 FrameGdk::FrameGdk(Page* page, Element* element)
124 : Frame(page,element)
126 d->m_extension = new BrowserExtensionGdk(this);
127 Settings* settings = new Settings;
128 settings->setAutoLoadImages(true);
129 setSettings(settings);
132 FrameGdk::~FrameGdk()
136 bool FrameGdk::openURL(const KURL& url)
140 ResourceLoader* job = new ResourceLoader(this, "GET", url);
141 job->start(document()->docLoader());
145 void FrameGdk::submitForm(const ResourceRequest&)
149 void FrameGdk::urlSelected(const ResourceRequest& request)
151 //need to potentially updateLocationBar(str.ascii()); or notify sys of new url mybe event or callback
152 const KURL url = request.url();
153 printf("------------------> LOADING NEW URL %s \n", url.url().ascii());
156 ResourceLoader* job = new ResourceLoader(this, "GET", url);
157 job->start(document()->docLoader());
160 String FrameGdk::userAgent() const
162 return "Mozilla/5.0 (PC; U; Intel; Linux; en) AppleWebKit/420+ (KHTML, like Gecko)";
165 void FrameGdk::runJavaScriptAlert(String const& message)
169 bool FrameGdk::runJavaScriptConfirm(String const& message)
174 void FrameGdk::setTitle(const String &title)
178 void FrameGdk::handleGdkEvent(GdkEvent* event)
180 switch (event->type) {
183 gdk_region_get_clipbox(event->expose.region, &clip);
184 gdk_window_begin_paint_region (event->any.window, event->expose.region);
185 cairo_t* cr = gdk_cairo_create (event->any.window);
186 GraphicsContext* ctx = new GraphicsContext(cr);
187 paint(ctx, IntRect(clip.x, clip.y, clip.width, clip.height));
189 gdk_window_end_paint (event->any.window);
193 PlatformWheelEvent wheelEvent(event);
194 view()->handleWheelEvent(wheelEvent);
195 if (wheelEvent.isAccepted()) {
198 RenderObject::NodeInfo nodeInfo(true, true);
199 renderer()->layer()->hitTest(nodeInfo, wheelEvent.pos());
200 Node* node = nodeInfo.innerNode();
203 //Default to scrolling the page
204 //not sure why its null
205 //broke anyway when its not null
206 doScroll(renderer(), wheelEvent.isHorizontal(), wheelEvent.delta());
211 case GDK_DRAG_MOTION:
212 case GDK_DRAG_STATUS:
214 case GDK_DROP_FINISHED: {
215 //bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
216 //void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
217 //bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
220 case GDK_MOTION_NOTIFY:
221 view()->handleMouseMoveEvent(event);
223 case GDK_BUTTON_PRESS:
224 case GDK_2BUTTON_PRESS:
225 case GDK_3BUTTON_PRESS:
226 view()->handleMousePressEvent(event);
228 case GDK_BUTTON_RELEASE:
229 view()->handleMouseReleaseEvent(event);
232 case GDK_KEY_RELEASE: {
233 PlatformKeyboardEvent kevent(event);
234 bool handled = false;
235 if (!kevent.isKeyUp()) {
236 Node* start = selectionController()->start().node();
237 if (start && start->isContentEditable()) {
238 switch(kevent.WindowsKeyCode()) {
240 TypingCommand::deleteKeyPressed(document());
243 TypingCommand::forwardDeleteKeyPressed(document());
246 selectionController()->modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity);
249 selectionController()->modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity);
252 selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, ParagraphGranularity);
255 selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, ParagraphGranularity);
258 TypingCommand::insertText(document(), kevent.text(), false);
264 switch (kevent.WindowsKeyCode()) {
266 doScroll(renderer(), true, -120);
269 doScroll(renderer(), true, 120);
272 doScroll(renderer(), false, -120);
278 //return SB_PAGEDOWN;
281 doScroll(renderer(), false, 120);
284 renderer()->layer()->scrollToOffset(0, 0, true, true);
285 doScroll(renderer(), false, 120);
288 renderer()->layer()->scrollToOffset(0,
289 renderer()->height(), true, true);
292 if (kevent.shiftKey())
293 doScroll(renderer(), false, -120);
295 doScroll(renderer(), false, 120);
307 void FrameGdk::receivedData(ResourceLoader* job, const char* data, int length)
312 void FrameGdk::receivedAllData(ResourceLoader* job, PlatformData data)
317 void FrameGdk::setFrameGeometry(const IntRect &r)
319 if (!m_drawable || !GDK_IS_WINDOW(m_drawable))
321 GdkWindow* window = GDK_WINDOW(m_drawable);
322 gdk_window_move_resize(window, r.x(), r.y(), r.width(), r.height());
325 IntRect FrameGdk::frameGeometry() const
327 gint x, y, width, height, depth;
331 if (!GDK_IS_WINDOW(m_drawable)) {
332 gdk_drawable_get_size(m_drawable, &width, &height);
333 return IntRect(0, 0, width, height);
336 GdkWindow* window = GDK_WINDOW(m_drawable);
337 gdk_window_get_geometry(window, &x, &y, &width, &height, &depth);
338 return IntRect(x, y, width, height);
341 bool FrameGdk::passWheelEventToChildWidget(Node* node)
345 RenderObject* renderer = node->renderer();
346 if (!renderer || !renderer->isWidget())
348 Widget* widget = static_cast<RenderWidget*>(renderer)->widget();
354 bool FrameGdk::passSubframeEventToSubframe(MouseEventWithHitTestResults& mev, Frame*)
356 if (mev.targetNode() == 0)