Not reviewed, gdk build fix.
[WebKit-https.git] / WebCore / platform / gdk / FrameGdk.cpp
1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
3  * Copyright (C) 2006 Michael Emmel mike.emmel@gmail.com 
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
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.
14  *
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. 
26  */
27
28 #include "config.h"
29 #include "FrameGdk.h"
30
31 #include "CString.h"
32 #include "Document.h"
33 #include "DocumentLoader.h"
34 #include "EventHandler.h"
35 #include "FrameLoader.h"
36 #include "FrameLoaderClientGdk.h"
37 #include "FramePrivate.h"
38 #include "FrameView.h"
39 #include "GraphicsContext.h"
40 #include "HitTestRequest.h"
41 #include "HitTestResult.h"
42 #include "KeyboardCodes.h"
43 #include "NotImplemented.h"
44 #include "Page.h"
45 #include "PlatformKeyboardEvent.h"
46 #include "PlatformMouseEvent.h"
47 #include "PlatformString.h"
48 #include "PlatformWheelEvent.h"
49 #include "RenderObject.h"
50 #include "RenderTreeAsText.h"
51 #include "ResourceHandle.h"
52 #include "ResourceResponse.h"
53 #include "SelectionController.h"
54 #include "Settings.h"
55 #include "TypingCommand.h"
56
57 #include <gdk/gdk.h>
58 #include <gtk/gtk.h>
59
60 // This function loads resources from WebKit
61 // This does not belong here and I'm not sure where
62 // it should go
63 // I don't know what the plans or design is
64 // for none code resources
65 Vector<char> loadResourceIntoArray(const char* resourceName)
66 {
67     Vector<char> resource;
68     //if (strcmp(resourceName,"missingImage") == 0) {
69     //}
70     return resource;
71 }
72
73 namespace WebCore {
74
75 FrameGdk::FrameGdk(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClientGdk* frameLoader)
76     : Frame(page, ownerElement, frameLoader)
77 {
78     m_exitAfterLoading = false;
79     m_dumpRenderTreeAfterLoading = false;
80
81     Settings* settings = page->settings();
82     settings->setLoadsImagesAutomatically(true);
83     settings->setMinimumFontSize(5);
84     settings->setMinimumLogicalFontSize(5);
85     settings->setShouldPrintBackgrounds(true);
86     settings->setJavaScriptEnabled(true);
87
88     settings->setDefaultFixedFontSize(14);
89     settings->setDefaultFontSize(14);
90     settings->setSerifFontFamily("Times New Roman");
91     settings->setSansSerifFontFamily("Arial");
92     settings->setFixedFontFamily("Courier");
93     settings->setStandardFontFamily("Arial");
94
95     frameLoader->setFrame(this);
96 }
97
98 FrameGdk::~FrameGdk()
99 {
100     loader()->cancelAndClear();
101 }
102
103 void FrameGdk::onDidFinishLoad()
104 {
105     if (dumpRenderTreeAfterLoading())
106         dumpRenderTree();
107     if (exitAfterLoading())
108         gtk_main_quit();  // FIXME: a bit drastic?
109 }
110
111 void FrameGdk::dumpRenderTree() const
112 {
113     if (view()->needsLayout())
114         view()->layout();
115     
116     String txt = externalRepresentation(renderer());
117     CString utf8Str = txt.utf8();
118     const char *utf8 = utf8Str.data();
119     if (utf8)
120         printf("%s\n", utf8);
121     else
122         printf("FrameGdk::dumpRenderTree() no data\n");
123 }
124
125 bool FrameGdk::keyPress(const PlatformKeyboardEvent& keyEvent)
126 {
127     if (!eventHandler())
128         return false;
129
130     return eventHandler()->keyEvent(keyEvent);
131 }
132
133 void FrameGdk::handleGdkEvent(GdkEvent* event)
134 {
135     switch (event->type) {
136
137         case GDK_EXPOSE: {
138             GdkRectangle clip;
139             gdk_region_get_clipbox(event->expose.region, &clip);
140             gdk_window_begin_paint_region(event->any.window, event->expose.region);
141             cairo_t* cr = gdk_cairo_create(event->any.window);
142             GraphicsContext ctx(cr);
143             if (renderer()) {
144                 if (view()->needsLayout())
145                     view()->layout();
146                 IntRect rect(clip.x, clip.y, clip.width, clip.height);
147                 paint(&ctx, rect);
148             }
149             cairo_destroy(cr);
150             gdk_window_end_paint(event->any.window);
151             break;
152         }
153
154         case GDK_CONFIGURE: {
155             view()->updateGeometry(event->configure.width, event->configure.height);
156             forceLayout();
157             break;
158         }
159
160         case GDK_SCROLL: {
161             PlatformWheelEvent wheelEvent(event);
162             view()->wheelEvent(wheelEvent);
163             if (wheelEvent.isAccepted())
164                 return;
165
166             HitTestRequest hitTestRequest(true, true);
167             HitTestResult hitTestResult(wheelEvent.pos());
168             renderer()->layer()->hitTest(hitTestRequest, hitTestResult);
169             Node* node = hitTestResult.innerNode();
170             if (!node)
171                 return;
172             /*
173              * FIXME: Does this belong here?
174              * Default to scrolling the page
175              * not sure why its null
176              * broke anyway when its not null
177              * doScroll(renderer(), wheelEvent.deltaX(), wheelEvent.deltaY());
178              */
179             break;
180         }
181         case GDK_DRAG_ENTER:
182         case GDK_DRAG_LEAVE:
183         case GDK_DRAG_MOTION:
184         case GDK_DRAG_STATUS:
185         case GDK_DROP_START:
186         case GDK_DROP_FINISHED: {
187             //bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
188             //void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
189             //bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
190             break;
191         }
192         case GDK_MOTION_NOTIFY:
193             eventHandler()->handleMouseMoveEvent(PlatformMouseEvent(event));
194             break;
195         case GDK_BUTTON_PRESS:
196         case GDK_2BUTTON_PRESS:
197         case GDK_3BUTTON_PRESS:
198             eventHandler()->handleMousePressEvent(PlatformMouseEvent(event));
199             break;
200         case GDK_BUTTON_RELEASE:
201             eventHandler()->handleMouseReleaseEvent(PlatformMouseEvent(event));
202             break;
203         case GDK_KEY_PRESS:
204         case GDK_KEY_RELEASE: {
205             PlatformKeyboardEvent keyEvent(event);
206             keyPress(keyEvent);
207         }
208         default:
209             break;
210     }
211 }
212
213 void Frame::print() 
214 {
215     notImplemented();
216 }
217
218 void Frame::issueTransposeCommand()
219 {
220     notImplemented();
221 }
222
223 void Frame::cleanupPlatformScriptObjects()
224 {
225     notImplemented();
226 }
227
228 DragImageRef Frame::dragImageForSelection() 
229 {
230     notImplemented();
231     return 0;
232 }
233
234 void Frame::dashboardRegionsChanged()
235 {
236     notImplemented();
237 }
238
239 }