initial import
[vuplus_webkit] / Source / WebCore / page / ChromeClient.h
1 /*
2  * Copyright (C) 2006, 2007, 2008, 2009 Apple, Inc. All rights reserved.
3  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef ChromeClient_h
22 #define ChromeClient_h
23
24 #include "AXObjectCache.h"
25 #include "ConsoleTypes.h"
26 #include "Cursor.h"
27 #include "FocusDirection.h"
28 #include "FrameLoader.h"
29 #include "GraphicsContext.h"
30 #include "HostWindow.h"
31 #include "PopupMenu.h"
32 #include "PopupMenuClient.h"
33 #include "ScrollTypes.h"
34 #include "SearchPopupMenu.h"
35 #include "WebCoreKeyboardUIMode.h"
36 #include <wtf/Forward.h>
37 #include <wtf/PassOwnPtr.h>
38 #include <wtf/UnusedParam.h>
39 #include <wtf/Vector.h>
40
41 #ifndef __OBJC__
42 class NSMenu;
43 class NSResponder;
44 #endif
45
46 namespace WebCore {
47
48     class AccessibilityObject;
49     class Element;
50     class FileChooser;
51     class FileIconLoader;
52     class FloatRect;
53     class Frame;
54     class Geolocation;
55     class GraphicsLayer;
56     class HitTestResult;
57     class IntRect;
58     class NavigationAction;
59     class Node;
60     class Page;
61     class PopupMenuClient;
62     class SecurityOrigin;
63     class GraphicsContext3D;
64     class Widget;
65
66     struct FrameLoadRequest;
67     struct ViewportArguments;
68     struct WindowFeatures;
69
70 #if USE(ACCELERATED_COMPOSITING)
71     class GraphicsLayer;
72 #endif
73
74 #if ENABLE(INPUT_COLOR)
75     class ColorChooser;
76 #endif
77
78 #if ENABLE(NOTIFICATIONS)
79     class NotificationPresenter;
80 #endif
81
82     class ChromeClient {
83     public:
84         virtual void chromeDestroyed() = 0;
85         
86         virtual void setWindowRect(const FloatRect&) = 0;
87         virtual FloatRect windowRect() = 0;
88         
89         virtual FloatRect pageRect() = 0;
90         
91         virtual void focus() = 0;
92         virtual void unfocus() = 0;
93
94         virtual bool canTakeFocus(FocusDirection) = 0;
95         virtual void takeFocus(FocusDirection) = 0;
96
97         virtual void focusedNodeChanged(Node*) = 0;
98         virtual void focusedFrameChanged(Frame*) = 0;
99
100         // The Frame pointer provides the ChromeClient with context about which
101         // Frame wants to create the new Page.  Also, the newly created window
102         // should not be shown to the user until the ChromeClient of the newly
103         // created Page has its show method called.
104         // The FrameLoadRequest parameter is only for ChromeClient to check if the
105         // request could be fulfilled.  The ChromeClient should not load the request.
106         virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) = 0;
107         virtual void show() = 0;
108
109         virtual bool canRunModal() = 0;
110         virtual void runModal() = 0;
111
112         virtual void setToolbarsVisible(bool) = 0;
113         virtual bool toolbarsVisible() = 0;
114         
115         virtual void setStatusbarVisible(bool) = 0;
116         virtual bool statusbarVisible() = 0;
117         
118         virtual void setScrollbarsVisible(bool) = 0;
119         virtual bool scrollbarsVisible() = 0;
120         
121         virtual void setMenubarVisible(bool) = 0;
122         virtual bool menubarVisible() = 0;
123
124         virtual void setResizable(bool) = 0;
125         
126         virtual void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String& sourceID) = 0;
127
128         virtual bool canRunBeforeUnloadConfirmPanel() = 0;
129         virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame) = 0;
130
131         virtual void closeWindowSoon() = 0;
132         
133         virtual void runJavaScriptAlert(Frame*, const String&) = 0;
134         virtual bool runJavaScriptConfirm(Frame*, const String&) = 0;
135         virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0;
136         virtual void setStatusbarText(const String&) = 0;
137         virtual bool shouldInterruptJavaScript() = 0;
138         virtual KeyboardUIMode keyboardUIMode() = 0;
139
140         virtual void* webView() const = 0;
141
142 #if ENABLE(REGISTER_PROTOCOL_HANDLER)
143         virtual void registerProtocolHandler(const String& scheme, const String& baseURL, const String& url, const String& title) = 0;
144 #endif
145
146         virtual IntRect windowResizerRect() const = 0;
147
148         // Methods used by HostWindow.
149         virtual void invalidateWindow(const IntRect&, bool) = 0;
150         virtual void invalidateContentsAndWindow(const IntRect&, bool) = 0;
151         virtual void invalidateContentsForSlowScroll(const IntRect&, bool) = 0;
152         virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0;
153 #if ENABLE(TILED_BACKING_STORE)
154         virtual void delegatedScrollRequested(const IntPoint&) = 0;
155 #endif
156         virtual IntPoint screenToWindow(const IntPoint&) const = 0;
157         virtual IntRect windowToScreen(const IntRect&) const = 0;
158         virtual PlatformPageClient platformPageClient() const = 0;
159         virtual void scrollbarsModeDidChange() const = 0;
160         virtual void setCursor(const Cursor&) = 0;
161         virtual void setCursorHiddenUntilMouseMoves(bool) = 0;
162 #if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
163         virtual void scheduleAnimation() = 0;
164 #endif
165         // End methods used by HostWindow.
166
167         virtual void dispatchViewportDataDidChange(const ViewportArguments&) const { }
168
169         virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0;
170         virtual void layoutUpdated(Frame*) const { }
171         virtual void scrollRectIntoView(const IntRect&) const { }; // Currently only Mac has a non empty implementation.
172        
173         virtual bool shouldMissingPluginMessageBeButton() const { return false; }
174         virtual void missingPluginButtonClicked(Element*) const { }
175         virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0;
176
177         virtual void setToolTip(const String&, TextDirection) = 0;
178
179         virtual void print(Frame*) = 0;
180         virtual bool shouldRubberBandInDirection(ScrollDirection) const = 0;
181
182 #if ENABLE(DATABASE)
183         virtual void exceededDatabaseQuota(Frame*, const String& databaseName) = 0;
184 #endif
185
186 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
187         // Callback invoked when the application cache fails to save a cache object
188         // because storing it would grow the database file past its defined maximum
189         // size or past the amount of free space on the device. 
190         // The chrome client would need to take some action such as evicting some
191         // old caches.
192         virtual void reachedMaxAppCacheSize(int64_t spaceNeeded) = 0;
193
194         // Callback invoked when the application cache origin quota is reached. This
195         // means that the resources attempting to be cached via the manifest are
196         // more than allowed on this origin. This callback allows the chrome client
197         // to take action, such as prompting the user to ask to increase the quota
198         // for this origin. The totalSpaceNeeded parameter is the total amount of
199         // storage, in bytes, needed to store the new cache along with all of the
200         // other existing caches for the origin that would not be replaced by
201         // the new cache.
202         virtual void reachedApplicationCacheOriginQuota(SecurityOrigin*, int64_t totalSpaceNeeded) = 0;
203 #endif
204
205 #if ENABLE(DASHBOARD_SUPPORT)
206         virtual void dashboardRegionsChanged();
207 #endif
208
209 #if ENABLE(NOTIFICATIONS)
210         virtual NotificationPresenter* notificationPresenter() const = 0;
211 #endif
212
213         virtual void populateVisitedLinks();
214
215         virtual FloatRect customHighlightRect(Node*, const AtomicString& type, const FloatRect& lineRect);
216         virtual void paintCustomHighlight(Node*, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
217             bool behindText, bool entireLine);
218             
219         virtual bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename);
220         virtual String generateReplacementFile(const String& path);
221
222         virtual bool paintCustomScrollbar(GraphicsContext*, const FloatRect&, ScrollbarControlSize, 
223                                           ScrollbarControlState, ScrollbarPart pressedPart, bool vertical,
224                                           float value, float proportion, ScrollbarControlPartMask);
225         virtual bool paintCustomScrollCorner(GraphicsContext*, const FloatRect&);
226
227         virtual bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&);
228
229         // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373
230         // For client-based geolocation, these two methods have moved to GeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061
231         // This can be either a synchronous or asynchronous call. The ChromeClient can display UI asking the user for permission
232         // to use Geolocation.
233         virtual void requestGeolocationPermissionForFrame(Frame*, Geolocation*) = 0;
234         virtual void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*) = 0;
235
236 #if ENABLE(INPUT_COLOR)
237         virtual void openColorChooser(ColorChooser*, const Color&) = 0;
238         virtual void cleanupColorChooser() = 0;
239         virtual void setSelectedColorInColorChooser(const Color&) = 0;
240 #endif
241
242         virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0;
243         // Asynchronous request to load an icon for specified filenames.
244         virtual void loadIconForFiles(const Vector<String>&, FileIconLoader*) = 0;
245
246 #if ENABLE(DIRECTORY_UPLOAD)
247         // Asychronous request to enumerate all files in a directory chosen by the user.
248         virtual void enumerateChosenDirectory(FileChooser*) = 0;
249 #endif
250
251         // Notification that the given form element has changed. This function
252         // will be called frequently, so handling should be very fast.
253         virtual void formStateDidChange(const Node*) = 0;
254         
255         virtual void elementDidFocus(const Node*) { };
256         virtual void elementDidBlur(const Node*) { };
257
258 #if USE(ACCELERATED_COMPOSITING)
259         // Pass 0 as the GraphicsLayer to detatch the root layer.
260         virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0;
261         // Sets a flag to specify that the next time content is drawn to the window,
262         // the changes appear on the screen in synchrony with updates to GraphicsLayers.
263         virtual void setNeedsOneShotDrawingSynchronization() = 0;
264         // Sets a flag to specify that the view needs to be updated, so we need
265         // to do an eager layout before the drawing.
266         virtual void scheduleCompositingLayerSync() = 0;
267         // Returns whether or not the client can render the composited layer,
268         // regardless of the settings.
269         virtual bool allowsAcceleratedCompositing() const { return true; }
270
271         enum CompositingTrigger {
272             ThreeDTransformTrigger = 1 << 0,
273             VideoTrigger = 1 << 1,
274             PluginTrigger = 1 << 2,
275             CanvasTrigger = 1 << 3,
276             AnimationTrigger = 1 << 4,
277             AllTriggers = 0xFFFFFFFF
278         };
279         typedef unsigned CompositingTriggerFlags;
280
281         // Returns a bitfield indicating conditions that can trigger the compositor.
282         virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); }
283 #endif
284
285         virtual bool supportsFullscreenForNode(const Node*) { return false; }
286         virtual void enterFullscreenForNode(Node*) { }
287         virtual void exitFullscreenForNode(Node*) { }
288         virtual bool requiresFullscreenForVideoPlayback() { return false; } 
289
290 #if ENABLE(FULLSCREEN_API)
291         virtual bool supportsFullScreenForElement(const Element*, bool) { return false; }
292         virtual void enterFullScreenForElement(Element*) { }
293         virtual void exitFullScreenForElement(Element*) { }
294         virtual void fullScreenRendererChanged(RenderBox*) { }
295         virtual void setRootFullScreenLayer(GraphicsLayer*) { }
296 #endif
297         
298 #if ENABLE(TILED_BACKING_STORE)
299         virtual IntRect visibleRectForTiledBackingStore() const { return IntRect(); }
300 #endif
301
302 #if PLATFORM(MAC)
303         virtual NSResponder *firstResponder() { return 0; }
304         virtual void makeFirstResponder(NSResponder *) { }
305         // Focuses on the containing view associated with this page.
306         virtual void makeFirstResponder() { }
307         virtual void willPopUpMenu(NSMenu *) { }
308 #endif
309
310 #if PLATFORM(WIN)
311         virtual void setLastSetCursorToCurrentCursor() = 0;
312 #endif
313
314 #if ENABLE(TOUCH_EVENTS)
315         virtual void needTouchEvents(bool) = 0;
316 #endif
317
318         virtual bool selectItemWritingDirectionIsNatural() = 0;
319         virtual bool selectItemAlignmentFollowsMenuWritingDirection() = 0;
320         virtual PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const = 0;
321         virtual PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const = 0;
322
323 #if ENABLE(CONTEXT_MENUS)
324         virtual void showContextMenu() = 0;
325 #endif
326
327         virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { }
328
329         virtual void didStartRubberBandForFrame(Frame*, const IntSize&) const { }
330         virtual void didCompleteRubberBandForFrame(Frame*, const IntSize&) const { }
331         virtual void didStartAnimatedScroll() const { }
332         virtual void didCompleteAnimatedScroll() const { }
333         
334         virtual void notifyScrollerThumbIsVisibleInRect(const IntRect&) { }
335
336         enum DialogType {
337             AlertDialog = 0,
338             ConfirmDialog = 1,
339             PromptDialog = 2,
340             HTMLDialog = 3
341         };
342         virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String& dialogMessage, FrameLoader::PageDismissalType) const { UNUSED_PARAM(dialogMessage); return true; }
343
344         virtual void numWheelEventHandlersChanged(unsigned) = 0;
345         
346     protected:
347         virtual ~ChromeClient() { }
348     };
349
350 }
351
352 #endif // ChromeClient_h