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/FocusType.h"
31#include "core/rendering/style/RenderStyleConstants.h"
32#include "platform/Cursor.h"
33#include "platform/HostWindow.h"
34#include "platform/PopupMenu.h"
35#include "platform/PopupMenuClient.h"
36#include "platform/heap/Handle.h"
37#include "platform/scroll/ScrollTypes.h"
38#include "wtf/Forward.h"
39#include "wtf/PassOwnPtr.h"
40#include "wtf/Vector.h"
41
42namespace blink {
43
44class AXObject;
45class ColorChooser;
46class ColorChooserClient;
47class DateTimeChooser;
48class DateTimeChooserClient;
49class Element;
50class FileChooser;
51class FloatRect;
52class Frame;
53class GraphicsContext;
54class GraphicsLayer;
55class GraphicsLayerFactory;
56class HitTestResult;
57class HTMLFormControlElement;
58class HTMLInputElement;
59class IntRect;
60class LocalFrame;
61class Node;
62class Page;
63class PagePopup;
64class PagePopupClient;
65class PagePopupDriver;
66class PopupMenuClient;
67
68struct CompositedSelectionBound;
69struct DateTimeChooserParameters;
70struct FrameLoadRequest;
71struct GraphicsDeviceAdapter;
72struct ViewportDescription;
73struct WindowFeatures;
74
75class ChromeClient {
76public:
77    virtual void chromeDestroyed() = 0;
78
79    virtual void setWindowRect(const FloatRect&) = 0;
80    virtual FloatRect windowRect() = 0;
81
82    virtual FloatRect pageRect() = 0;
83
84    virtual void focus() = 0;
85
86    virtual bool canTakeFocus(FocusType) = 0;
87    virtual void takeFocus(FocusType) = 0;
88
89    virtual void focusedNodeChanged(Node*) = 0;
90
91    virtual void focusedFrameChanged(LocalFrame*) = 0;
92
93    // The LocalFrame pointer provides the ChromeClient with context about which
94    // LocalFrame wants to create the new Page. Also, the newly created window
95    // should not be shown to the user until the ChromeClient of the newly
96    // created Page has its show method called.
97    // The FrameLoadRequest parameter is only for ChromeClient to check if the
98    // request could be fulfilled. The ChromeClient should not load the request.
99    virtual Page* createWindow(LocalFrame*, const FrameLoadRequest&, const WindowFeatures&, NavigationPolicy, ShouldSendReferrer) = 0;
100    virtual void show(NavigationPolicy) = 0;
101
102    virtual bool canRunModal() = 0;
103    virtual void runModal() = 0;
104
105    virtual void setToolbarsVisible(bool) = 0;
106    virtual bool toolbarsVisible() = 0;
107
108    virtual void setStatusbarVisible(bool) = 0;
109    virtual bool statusbarVisible() = 0;
110
111    virtual void setScrollbarsVisible(bool) = 0;
112    virtual bool scrollbarsVisible() = 0;
113
114    virtual void setMenubarVisible(bool) = 0;
115    virtual bool menubarVisible() = 0;
116
117    virtual void setResizable(bool) = 0;
118
119    virtual bool shouldReportDetailedMessageForSource(const String& source) = 0;
120    virtual void addMessageToConsole(LocalFrame*, MessageSource, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID, const String& stackTrace) = 0;
121
122    virtual bool canRunBeforeUnloadConfirmPanel() = 0;
123    virtual bool runBeforeUnloadConfirmPanel(const String& message, LocalFrame*) = 0;
124
125    virtual void closeWindowSoon() = 0;
126
127    virtual void runJavaScriptAlert(LocalFrame*, const String&) = 0;
128    virtual bool runJavaScriptConfirm(LocalFrame*, const String&) = 0;
129    virtual bool runJavaScriptPrompt(LocalFrame*, const String& message, const String& defaultValue, String& result) = 0;
130    virtual void setStatusbarText(const String&) = 0;
131    virtual bool tabsToLinks() = 0;
132
133    virtual void* webView() const = 0;
134
135    virtual IntRect windowResizerRect() const = 0;
136
137    // Methods used by HostWindow.
138    virtual void invalidateContentsAndRootView(const IntRect&) = 0;
139    virtual void invalidateContentsForSlowScroll(const IntRect&) = 0;
140    virtual IntRect rootViewToScreen(const IntRect&) const = 0;
141    virtual blink::WebScreenInfo screenInfo() const = 0;
142    virtual void setCursor(const Cursor&) = 0;
143    virtual void scheduleAnimation() = 0;
144    // End methods used by HostWindow.
145
146    virtual void dispatchViewportPropertiesDidChange(const ViewportDescription&) const { }
147
148    virtual void contentsSizeChanged(LocalFrame*, const IntSize&) const = 0;
149    virtual void deviceOrPageScaleFactorChanged() const { }
150    virtual void layoutUpdated(LocalFrame*) const { }
151
152    virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) = 0;
153
154    virtual void setToolTip(const String&, TextDirection) = 0;
155
156    virtual void print(LocalFrame*) = 0;
157
158    virtual void annotatedRegionsChanged() = 0;
159
160    virtual bool paintCustomOverhangArea(GraphicsContext*, const IntRect&, const IntRect&, const IntRect&) = 0;
161
162    virtual PassOwnPtr<ColorChooser> createColorChooser(LocalFrame*, ColorChooserClient*, const Color&) = 0;
163
164    // This function is used for:
165    //  - Mandatory date/time choosers if !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
166    //  - Date/time choosers for types for which RenderTheme::supportsCalendarPicker
167    //    returns true, if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
168    //  - <datalist> UI for date/time input types regardless of
169    //    ENABLE(INPUT_MULTIPLE_FIELDS_UI)
170    virtual PassRefPtr<DateTimeChooser> openDateTimeChooser(DateTimeChooserClient*, const DateTimeChooserParameters&) = 0;
171
172    virtual void openTextDataListChooser(HTMLInputElement&) = 0;
173
174    virtual void runOpenPanel(LocalFrame*, PassRefPtr<FileChooser>) = 0;
175
176    // Asychronous request to enumerate all files in a directory chosen by the user.
177    virtual void enumerateChosenDirectory(FileChooser*) = 0;
178
179    // Allows ports to customize the type of graphics layers created by this page.
180    virtual GraphicsLayerFactory* graphicsLayerFactory() const { return 0; }
181
182    // Pass 0 as the GraphicsLayer to detatch the root layer.
183    virtual void attachRootGraphicsLayer(GraphicsLayer*) = 0;
184
185    virtual void enterFullScreenForElement(Element*) { }
186    virtual void exitFullScreenForElement(Element*) { }
187
188    virtual void clearCompositedSelectionBounds() { }
189    virtual void updateCompositedSelectionBounds(const CompositedSelectionBound& anchor, const CompositedSelectionBound& focus) { }
190
191    virtual void needTouchEvents(bool) = 0;
192
193    virtual void setTouchAction(TouchAction) = 0;
194
195    // Checks if there is an opened popup, called by RenderMenuList::showPopup().
196    virtual bool hasOpenedPopup() const = 0;
197    virtual PassRefPtrWillBeRawPtr<PopupMenu> createPopupMenu(LocalFrame&, PopupMenuClient*) const = 0;
198    // For testing.
199    virtual void setPagePopupDriver(PagePopupDriver*) = 0;
200    virtual void resetPagePopupDriver() = 0;
201
202    virtual void postAccessibilityNotification(AXObject*, AXObjectCache::AXNotification) { }
203    virtual String acceptLanguages() = 0;
204
205    enum DialogType {
206        AlertDialog = 0,
207        ConfirmDialog = 1,
208        PromptDialog = 2,
209        HTMLDialog = 3
210    };
211    virtual bool shouldRunModalDialogDuringPageDismissal(const DialogType&, const String&, Document::PageDismissalType) const { return true; }
212
213    virtual bool isSVGImageChromeClient() const { return false; }
214
215    virtual bool requestPointerLock() { return false; }
216    virtual void requestPointerUnlock() { }
217
218    virtual FloatSize minimumWindowSize() const { return FloatSize(100, 100); };
219
220    virtual bool isChromeClientImpl() const { return false; }
221
222    virtual void didAssociateFormControls(const WillBeHeapVector<RefPtrWillBeMember<Element> >&) { };
223    virtual void didChangeValueInTextField(HTMLFormControlElement&) { }
224    virtual void didEndEditingOnTextField(HTMLInputElement&) { }
225    virtual void handleKeyboardEventOnTextField(HTMLInputElement&, KeyboardEvent&) { }
226
227    // FIXME: Remove this method once we have input routing in the browser
228    // process. See http://crbug.com/339659.
229    virtual void forwardInputEvent(blink::Frame*, blink::Event*) { }
230
231    // Input mehtod editor related functions.
232    virtual void didCancelCompositionOnSelectionChange() { }
233    virtual void willSetInputMethodState() { }
234    virtual void didUpdateTextOfFocusedElementByNonUserInput() { }
235    virtual void showImeIfNeeded() { }
236
237protected:
238    virtual ~ChromeClient() { }
239};
240
241}
242#endif // ChromeClient_h
243