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/frame/ConsoleTypes.h" 30 #include "core/page/FocusDirection.h" 31 #include "core/rendering/RenderEmbeddedObject.h" 32 #include "core/rendering/style/RenderStyleConstants.h" 33 #include "platform/Cursor.h" 34 #include "platform/HostWindow.h" 35 #include "platform/PopupMenu.h" 36 #include "platform/PopupMenuClient.h" 37 #include "platform/graphics/GraphicsContext.h" 38 #include "platform/scroll/ScrollTypes.h" 39 #include "wtf/Forward.h" 40 #include "wtf/PassOwnPtr.h" 41 #include "wtf/Vector.h" 42 43 44 #ifndef __OBJC__ 45 class NSMenu; 46 class NSResponder; 47 #endif 48 49 namespace WebCore { 50 51 class AXObject; 52 class ColorChooser; 53 class ColorChooserClient; 54 class DateTimeChooser; 55 class DateTimeChooserClient; 56 class Element; 57 class FileChooser; 58 class FloatRect; 59 class Frame; 60 class Geolocation; 61 class GraphicsContext3D; 62 class GraphicsLayer; 63 class GraphicsLayerFactory; 64 class HitTestResult; 65 class HTMLInputElement; 66 class IntRect; 67 class Node; 68 class Page; 69 class PagePopup; 70 class PagePopupClient; 71 class PagePopupDriver; 72 class PopupContainer; 73 class PopupMenuClient; 74 class SecurityOrigin; 75 class Widget; 76 77 struct DateTimeChooserParameters; 78 struct FrameLoadRequest; 79 struct GraphicsDeviceAdapter; 80 struct ViewportDescription; 81 struct WindowFeatures; 82 83 class ChromeClient { 84 public: 85 virtual void chromeDestroyed() = 0; 86 87 virtual void setWindowRect(const FloatRect&) = 0; 88 virtual FloatRect windowRect() = 0; 89 90 virtual FloatRect pageRect() = 0; 91 92 virtual void focus() = 0; 93 virtual void unfocus() = 0; 94 95 virtual bool canTakeFocus(FocusDirection) = 0; 96 virtual void takeFocus(FocusDirection) = 0; 97 98 virtual void focusedNodeChanged(Node*) = 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&, NavigationPolicy, ShouldSendReferrer) = 0; 107 virtual void show(NavigationPolicy) = 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 bool shouldReportDetailedMessageForSource(const String& source) = 0; 127 virtual void addMessageToConsole(MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace) = 0; 128 129 virtual bool canRunBeforeUnloadConfirmPanel() = 0; 130 virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame*) = 0; 131 132 virtual void closeWindowSoon() = 0; 133 134 virtual void runJavaScriptAlert(Frame*, const String&) = 0; 135 virtual bool runJavaScriptConfirm(Frame*, const String&) = 0; 136 virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) = 0; 137 virtual void setStatusbarText(const String&) = 0; 138 virtual bool tabsToLinks() = 0; 139 140 virtual void* webView() const = 0; 141 142 virtual IntRect windowResizerRect() const = 0; 143 144 // Methods used by HostWindow. 145 virtual void invalidateContentsAndRootView(const IntRect&) = 0; 146 virtual void invalidateContentsForSlowScroll(const IntRect&) = 0; 147 virtual void scroll(const IntSize&, const IntRect&, const IntRect&) = 0; 148 virtual IntPoint screenToRootView(const IntPoint&) const = 0; 149 virtual IntRect rootViewToScreen(const IntRect&) const = 0; 150 virtual blink::WebScreenInfo screenInfo() const = 0; 151 virtual void setCursor(const Cursor&) = 0; 152 virtual void scheduleAnimation() = 0; 153 // End methods used by HostWindow. 154 155 virtual bool isCompositorFramePending() const = 0; 156 157 virtual void dispatchViewportPropertiesDidChange(const ViewportDescription&) const { } 158 159 virtual void contentsSizeChanged(Frame*, const IntSize&) const = 0; 160 virtual void deviceOrPageScaleFactorChanged() const { } 161 virtual void layoutUpdated(Frame*) const { } 162 163 virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0; 164 165 virtual void setToolTip(const String&, TextDirection) = 0; 166 167 virtual void print(Frame*) = 0; 168 virtual bool shouldRubberBandInDirection(ScrollDirection) const = 0; 169 170 virtual void annotatedRegionsChanged() = 0; 171 172 virtual bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&) = 0; 173 174 virtual PassOwnPtr<ColorChooser> createColorChooser(ColorChooserClient*, const Color&) = 0; 175 176 // This function is used for: 177 // - Mandatory date/time choosers if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) 178 // - Date/time choosers for types for which RenderTheme::supportsCalendarPicker 179 // returns true, if ENABLE(INPUT_MULTIPLE_FIELDS_UI) 180 // - <datalist> UI for date/time input types regardless of 181 // ENABLE(INPUT_MULTIPLE_FIELDS_UI) 182 virtual PassRefPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) = 0; 183 184 virtual void openTextDataListChooser(HTMLInputElement&) = 0; 185 186 virtual void runOpenPanel(Frame*, PassRefPtr<FileChooser>) = 0; 187 188 // Asychronous request to enumerate all files in a directory chosen by the user. 189 virtual void enumerateChosenDirectory(FileChooser*) = 0; 190 191 // Notification that the given form element has changed. This function 192 // will be called frequently, so handling should be very fast. 193 virtual void formStateDidChange(const Node*) = 0; 194 195 // Allows ports to customize the type of graphics layers created by this page. 196 virtual GraphicsLayerFactory* graphicsLayerFactory() const { return 0; } 197 198 // Pass 0 as the GraphicsLayer to detatch the root layer. 199 virtual void attachRootGraphicsLayer(Frame*, GraphicsLayer*) = 0; 200 // Sets a flag to specify that the view needs to be updated, so we need 201 // to do an eager layout before the drawing. 202 virtual void scheduleCompositingLayerFlush() = 0; 203 // Returns whether or not the client can render the composited layer, 204 // regardless of the settings. 205 virtual bool allowsAcceleratedCompositing() const { return true; } 206 207 enum CompositingTrigger { 208 ThreeDTransformTrigger = 1 << 0, 209 VideoTrigger = 1 << 1, 210 PluginTrigger = 1 << 2, 211 CanvasTrigger = 1 << 3, 212 AnimationTrigger = 1 << 4, 213 FilterTrigger = 1 << 5, 214 ScrollableInnerFrameTrigger = 1 << 6, 215 AllTriggers = 0xFFFFFFFF 216 }; 217 typedef unsigned CompositingTriggerFlags; 218 219 // Returns a bitfield indicating conditions that can trigger the compositor. 220 virtual CompositingTriggerFlags allowedCompositingTriggers() const { return static_cast<CompositingTriggerFlags>(AllTriggers); } 221 222 virtual void enterFullScreenForElement(Element*) { } 223 virtual void exitFullScreenForElement(Element*) { } 224 225 virtual void needTouchEvents(bool) = 0; 226 227 virtual void setTouchAction(TouchAction) = 0; 228 229 // Checks if there is an opened popup, called by RenderMenuList::showPopup(). 230 virtual bool hasOpenedPopup() const = 0; 231 virtual PassRefPtr<PopupMenu> createPopupMenu(Frame&, PopupMenuClient*) const = 0; 232 // Creates a PagePopup object, and shows it beside originBoundsInRootView. 233 // The return value can be 0. 234 virtual PagePopup* openPagePopup(PagePopupClient*, const IntRect& originBoundsInRootView) = 0; 235 virtual void closePagePopup(PagePopup*) = 0; 236 // For testing. 237 virtual void setPagePopupDriver(PagePopupDriver*) = 0; 238 virtual void resetPagePopupDriver() = 0; 239 240 // FIXME: Should these be on a different client interface? 241 virtual bool isPasswordGenerationEnabled() const { return false; } 242 virtual void openPasswordGenerator(HTMLInputElement*) { } 243 244 virtual void postAccessibilityNotification(AXObject*, AXObjectCache::AXNotification) { } 245 virtual String acceptLanguages() = 0; 246 247 enum DialogType { 248 AlertDialog = 0, 249 ConfirmDialog = 1, 250 PromptDialog = 2, 251 HTMLDialog = 3 252 }; 253 virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String&, Document::PageDismissalType) const { return true; } 254 255 virtual void numWheelEventHandlersChanged(unsigned) = 0; 256 257 virtual bool isSVGImageChromeClient() const { return false; } 258 259 virtual bool requestPointerLock() { return false; } 260 virtual void requestPointerUnlock() { } 261 virtual bool isPointerLocked() { return false; } 262 263 virtual FloatSize minimumWindowSize() const { return FloatSize(100, 100); }; 264 265 virtual bool isEmptyChromeClient() const { return false; } 266 virtual bool isChromeClientImpl() const { return false; } 267 268 virtual void didAssociateFormControls(const Vector<RefPtr<Element> >&) { }; 269 virtual void didChangeValueInTextField(HTMLInputElement&) { } 270 virtual void didEndEditingOnTextField(HTMLInputElement&) { } 271 virtual void handleKeyboardEventOnTextField(HTMLInputElement&, KeyboardEvent&) { } 272 273 // Input mehtod editor related functions. 274 virtual void didCancelCompositionOnSelectionChange() { } 275 virtual void willSetInputMethodState() { } 276 277 // Notifies the client of a new popup widget. The client should place 278 // and size the widget with the given bounds, relative to the screen. 279 // If handleExternal is true, then drawing and input handling for the 280 // popup will be handled by the external embedder. 281 virtual void popupOpened(PopupContainer* popupContainer, const IntRect& bounds, 282 bool handleExternal) = 0; 283 284 // Notifies the client a popup was closed. 285 virtual void popupClosed(PopupContainer* popupContainer) = 0; 286 287 protected: 288 virtual ~ChromeClient() { } 289 }; 290 291 } 292 #endif // ChromeClient_h 293