1 /* 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple, Inc. All rights reserved. 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 4 * Copyright (C) 2012 Samsung Electronics. All rights reserved. 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Library General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Library General Public License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; see the file COPYING.LIB. If not, write to 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef ChromeClient_h 23 #define ChromeClient_h 24 25 #include "core/accessibility/AXObjectCache.h" 26 #include "core/inspector/ConsoleAPITypes.h" 27 #include "core/loader/FrameLoader.h" 28 #include "core/loader/NavigationPolicy.h" 29 #include "core/page/ConsoleTypes.h" 30 #include "core/page/FocusDirection.h" 31 #include "core/platform/Cursor.h" 32 #include "core/platform/HostWindow.h" 33 #include "core/platform/PopupMenu.h" 34 #include "core/platform/PopupMenuClient.h" 35 #include "core/platform/ScrollTypes.h" 36 #include "core/platform/graphics/GraphicsContext.h" 37 #include "core/rendering/RenderEmbeddedObject.h" 38 #include "modules/webdatabase/DatabaseDetails.h" 39 #include "wtf/Forward.h" 40 #include "wtf/PassOwnPtr.h" 41 #include "wtf/UnusedParam.h" 42 #include "wtf/Vector.h" 43 44 45 #ifndef __OBJC__ 46 class NSMenu; 47 class NSResponder; 48 #endif 49 50 namespace WebCore { 51 52 class AccessibilityObject; 53 class ColorChooser; 54 class ColorChooserClient; 55 class DateTimeChooser; 56 class DateTimeChooserClient; 57 class Element; 58 class FileChooser; 59 class FloatRect; 60 class Frame; 61 class Geolocation; 62 class GraphicsContext3D; 63 class GraphicsLayer; 64 class GraphicsLayerFactory; 65 class HitTestResult; 66 class HTMLInputElement; 67 class IntRect; 68 class NavigationAction; 69 class Node; 70 class Page; 71 class PagePopup; 72 class PagePopupClient; 73 class PagePopupDriver; 74 class PopupContainer; 75 class PopupMenuClient; 76 class SecurityOrigin; 77 class Widget; 78 79 struct DateTimeChooserParameters; 80 struct FrameLoadRequest; 81 struct GraphicsDeviceAdapter; 82 struct ViewportArguments; 83 struct WindowFeatures; 84 85 class ChromeClient { 86 public: 87 virtual void chromeDestroyed() = 0; 88 89 virtual void setWindowRect(const FloatRect&) = 0; 90 virtual FloatRect windowRect() = 0; 91 92 virtual FloatRect pageRect() = 0; 93 94 virtual void focus() = 0; 95 virtual void unfocus() = 0; 96 97 virtual bool canTakeFocus(FocusDirection) = 0; 98 virtual void takeFocus(FocusDirection) = 0; 99 100 virtual void focusedNodeChanged(Node*) = 0; 101 102 // The Frame pointer provides the ChromeClient with context about which 103 // Frame wants to create the new Page. Also, the newly created window 104 // should not be shown to the user until the ChromeClient of the newly 105 // created Page has its show method called. 106 // The FrameLoadRequest parameter is only for ChromeClient to check if the 107 // request could be fulfilled. The ChromeClient should not load the request. 108 virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&, NavigationPolicy = NavigationPolicyIgnore) = 0; 109 virtual void show(NavigationPolicy) = 0; 110 111 virtual bool canRunModal() = 0; 112 virtual void runModal() = 0; 113 114 virtual void setToolbarsVisible(bool) = 0; 115 virtual bool toolbarsVisible() = 0; 116 117 virtual void setStatusbarVisible(bool) = 0; 118 virtual bool statusbarVisible() = 0; 119 120 virtual void setScrollbarsVisible(bool) = 0; 121 virtual bool scrollbarsVisible() = 0; 122 123 virtual void setMenubarVisible(bool) = 0; 124 virtual bool menubarVisible() = 0; 125 126 virtual void setResizable(bool) = 0; 127 128 virtual void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID) = 0; 129 // FIXME: Remove this MessageType variant once all the clients are updated. 130 virtual void addMessageToConsole(MessageSource source, MessageType, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID) 131 { 132 addMessageToConsole(source, level, message, lineNumber, sourceID); 133 } 134 135 virtual bool canRunBeforeUnloadConfirmPanel() = 0; 136 virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame*) = 0; 137 138 virtual void closeWindowSoon() = 0; 139 140 virtual void runJavaScriptAlert(Frame*, const String&) = 0; 141 virtual bool runJavaScriptConfirm(Frame*, const String&) = 0; 142 virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0; 143 virtual void setStatusbarText(const String&) = 0; 144 virtual bool tabsToLinks() = 0; 145 146 virtual void* webView() const = 0; 147 148 virtual IntRect windowResizerRect() const = 0; 149 150 // Methods used by HostWindow. 151 virtual void invalidateContentsAndRootView(const IntRect&) = 0; 152 virtual void invalidateContentsForSlowScroll(const IntRect&) = 0; 153 virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0; 154 virtual IntPoint screenToRootView(const IntPoint&) const = 0; 155 virtual IntRect rootViewToScreen(const IntRect&) const = 0; 156 virtual WebKit::WebScreenInfo screenInfo() const = 0; 157 virtual void setCursor(const Cursor&) = 0; 158 #if !USE(REQUEST_ANIMATION_FRAME_TIMER) 159 virtual void scheduleAnimation() = 0; 160 #endif 161 // End methods used by HostWindow. 162 163 virtual void dispatchViewportPropertiesDidChange(const ViewportArguments&) const { } 164 165 virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0; 166 virtual void deviceOrPageScaleFactorChanged() const { } 167 virtual void layoutUpdated(Frame*) const { } 168 169 // didProgrammaticallyScroll should be called whenever a Frame is programmatically scrolled. 170 virtual void didProgrammaticallyScroll(Frame*, const IntPoint& newScrollPosition) const { } 171 172 virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0; 173 174 virtual void setToolTip(const String&, TextDirection) = 0; 175 176 virtual void print(Frame*) = 0; 177 virtual bool shouldRubberBandInDirection(ScrollDirection) const = 0; 178 179 virtual void annotatedRegionsChanged() = 0; 180 181 virtual bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&) = 0; 182 183 virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0; 184 185 // This function is used for: 186 // - Mandatory date/time choosers if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) 187 // - Date/time choosers for types for which RenderTheme::supportsCalendarPicker 188 // returns true, if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 189 // - <datalist> UI for date/time input types regardless of 190 // ENABLE(INPUT_MULTIPLE_FIELDS_UI) 191 virtual PassRefPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) = 0; 192 193 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0; 194 195 // Asychronous request to enumerate all files in a directory chosen by the user. 196 virtual void enumerateChosenDirectory(FileChooser*) = 0; 197 198 // Notification that the given form element has changed. This function 199 // will be called frequently, so handling should be very fast. 200 virtual void formStateDidChange(const Node*) = 0; 201 202 // Allows ports to customize the type of graphics layers created by this page. 203 virtual GraphicsLayerFactory* graphicsLayerFactory() const { return 0; } 204 205 // Pass 0 as the GraphicsLayer to detatch the root layer. 206 virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0; 207 // Sets a flag to specify that the view needs to be updated, so we need 208 // to do an eager layout before the drawing. 209 virtual void scheduleCompositingLayerFlush() = 0; 210 // Returns whether or not the client can render the composited layer, 211 // regardless of the settings. 212 virtual bool allowsAcceleratedCompositing() const { return true; } 213 214 enum CompositingTrigger { 215 ThreeDTransformTrigger = 1 << 0, 216 VideoTrigger = 1 << 1, 217 PluginTrigger = 1 << 2, 218 CanvasTrigger = 1 << 3, 219 AnimationTrigger = 1 << 4, 220 FilterTrigger = 1 << 5, 221 ScrollableInnerFrameTrigger = 1 << 6, 222 AllTriggers = 0xFFFFFFFF 223 }; 224 typedef unsigned CompositingTriggerFlags; 225 226 // Returns a bitfield indicating conditions that can trigger the compositor. 227 virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); } 228 229 virtual void enterFullScreenForElement(Element*) { } 230 virtual void exitFullScreenForElement(Element*) { } 231 232 virtual void needTouchEvents(bool) = 0; 233 234 // Checks if there is an opened popup, called by RenderMenuList::showPopup(). 235 virtual bool hasOpenedPopup() const = 0; 236 virtual PassRefPtr<PopupMenu> createPopupMenu(Frame&, PopupMenuClient*) const = 0; 237 // Creates a PagePopup object, and shows it beside originBoundsInRootView. 238 // The return value can be 0. 239 virtual PagePopup* openPagePopup(PagePopupClient*, const IntRect& originBoundsInRootView) = 0; 240 virtual void closePagePopup(PagePopup*) = 0; 241 // For testing. 242 virtual void setPagePopupDriver(PagePopupDriver*) = 0; 243 virtual void resetPagePopupDriver() = 0; 244 245 // FIXME: Should these be on a different client interface? 246 virtual bool isPasswordGenerationEnabled() const { return false; } 247 virtual void openPasswordGenerator(HTMLInputElement*) { } 248 249 virtual void postAccessibilityNotification(AccessibilityObject*, AXObjectCache::AXNotification) { } 250 virtual String acceptLanguages() = 0; 251 252 enum DialogType { 253 AlertDialog = 0, 254 ConfirmDialog = 1, 255 PromptDialog = 2, 256 HTMLDialog = 3 257 }; 258 virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String& dialogMessage, FrameLoader::PageDismissalType) const { UNUSED_PARAM(dialogMessage); return true; } 259 260 virtual void numWheelEventHandlersChanged(unsigned) = 0; 261 262 virtual bool isSVGImageChromeClient() const { return false; } 263 264 virtual bool requestPointerLock() { return false; } 265 virtual void requestPointerUnlock() { } 266 virtual bool isPointerLocked() { return false; } 267 268 virtual FloatSize minimumWindowSize() const { return FloatSize(100, 100); }; 269 270 virtual bool isEmptyChromeClient() const { return false; } 271 272 virtual void didAssociateFormControls(const Vector<RefPtr<Element> >&) { }; 273 274 // Notifies the client of a new popup widget. The client should place 275 // and size the widget with the given bounds, relative to the screen. 276 // If handleExternal is true, then drawing and input handling for the 277 // popup will be handled by the external embedder. 278 virtual void popupOpened(PopupContainer* popupContainer, const IntRect& bounds, 279 bool handleExternal) = 0; 280 281 // Notifies the client a popup was closed. 282 virtual void popupClosed(PopupContainer* popupContainer) = 0; 283 284 protected: 285 virtual ~ChromeClient() { } 286 }; 287 288 } 289 #endif // ChromeClient_h 290