1/*
2 * Copyright (C) 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
24 * THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#ifndef WebChromeClient_h
28#define WebChromeClient_h
29
30#include <WebCore/ChromeClient.h>
31#include <WebCore/ViewportArguments.h>
32#include <wtf/text/WTFString.h>
33
34namespace WebKit {
35
36class WebFrame;
37class WebPage;
38
39class WebChromeClient : public WebCore::ChromeClient {
40public:
41    WebChromeClient(WebPage* page)
42        : m_cachedMainFrameHasHorizontalScrollbar(false)
43        , m_cachedMainFrameHasVerticalScrollbar(false)
44        , m_page(page)
45    {
46    }
47
48    WebPage* page() const { return m_page; }
49
50    virtual void* webView() const { return 0; }
51
52private:
53    virtual void chromeDestroyed() OVERRIDE;
54
55    virtual void setWindowRect(const WebCore::FloatRect&) OVERRIDE;
56    virtual WebCore::FloatRect windowRect() OVERRIDE;
57
58    virtual WebCore::FloatRect pageRect() OVERRIDE;
59
60    virtual void focus() OVERRIDE;
61    virtual void unfocus() OVERRIDE;
62
63    virtual bool canTakeFocus(WebCore::FocusDirection) OVERRIDE;
64    virtual void takeFocus(WebCore::FocusDirection) OVERRIDE;
65
66    virtual void focusedNodeChanged(WebCore::Node*) OVERRIDE;
67    virtual void focusedFrameChanged(WebCore::Frame*) OVERRIDE;
68
69    // The Frame pointer provides the ChromeClient with context about which
70    // Frame wants to create the new Page.  Also, the newly created window
71    // should not be shown to the user until the ChromeClient of the newly
72    // created Page has its show method called.
73    virtual WebCore::Page* createWindow(WebCore::Frame*, const WebCore::FrameLoadRequest&, const WebCore::WindowFeatures&, const WebCore::NavigationAction&) OVERRIDE;
74    virtual void show() OVERRIDE;
75
76    virtual bool canRunModal() OVERRIDE;
77    virtual void runModal() OVERRIDE;
78
79    virtual void setToolbarsVisible(bool) OVERRIDE;
80    virtual bool toolbarsVisible() OVERRIDE;
81
82    virtual void setStatusbarVisible(bool) OVERRIDE;
83    virtual bool statusbarVisible() OVERRIDE;
84
85    virtual void setScrollbarsVisible(bool) OVERRIDE;
86    virtual bool scrollbarsVisible() OVERRIDE;
87
88    virtual void setMenubarVisible(bool) OVERRIDE;
89    virtual bool menubarVisible() OVERRIDE;
90
91    virtual void setResizable(bool) OVERRIDE;
92
93    virtual void addMessageToConsole(WebCore::MessageSource, WebCore::MessageLevel, const String& message, unsigned lineNumber, unsigned columnNumber, const String& sourceID) OVERRIDE;
94
95    virtual bool canRunBeforeUnloadConfirmPanel() OVERRIDE;
96    virtual bool runBeforeUnloadConfirmPanel(const String& message, WebCore::Frame*) OVERRIDE;
97
98    virtual void closeWindowSoon() OVERRIDE;
99
100    virtual void runJavaScriptAlert(WebCore::Frame*, const String&) OVERRIDE;
101    virtual bool runJavaScriptConfirm(WebCore::Frame*, const String&) OVERRIDE;
102    virtual bool runJavaScriptPrompt(WebCore::Frame*, const String& message, const String& defaultValue, String& result) OVERRIDE;
103    virtual void setStatusbarText(const String&) OVERRIDE;
104    virtual bool shouldInterruptJavaScript() OVERRIDE;
105
106    virtual WebCore::KeyboardUIMode keyboardUIMode() OVERRIDE;
107
108    virtual WebCore::IntRect windowResizerRect() const OVERRIDE;
109
110    // HostWindow member function overrides.
111    virtual void invalidateRootView(const WebCore::IntRect&, bool) OVERRIDE;
112    virtual void invalidateContentsAndRootView(const WebCore::IntRect&, bool) OVERRIDE;
113    virtual void invalidateContentsForSlowScroll(const WebCore::IntRect&, bool) OVERRIDE;
114    virtual void scroll(const WebCore::IntSize& scrollDelta, const WebCore::IntRect& scrollRect, const WebCore::IntRect& clipRect) OVERRIDE;
115#if USE(TILED_BACKING_STORE)
116    virtual void delegatedScrollRequested(const WebCore::IntPoint& scrollOffset) OVERRIDE;
117#endif
118    virtual WebCore::IntPoint screenToRootView(const WebCore::IntPoint&) const OVERRIDE;
119    virtual WebCore::IntRect rootViewToScreen(const WebCore::IntRect&) const OVERRIDE;
120    virtual PlatformPageClient platformPageClient() const OVERRIDE;
121    virtual void contentsSizeChanged(WebCore::Frame*, const WebCore::IntSize&) const OVERRIDE;
122    virtual void scrollRectIntoView(const WebCore::IntRect&) const OVERRIDE; // Currently only Mac has a non empty implementation.
123
124    virtual bool shouldUnavailablePluginMessageBeButton(WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const OVERRIDE;
125    virtual void unavailablePluginButtonClicked(WebCore::Element*, WebCore::RenderEmbeddedObject::PluginUnavailabilityReason) const OVERRIDE;
126
127    virtual void scrollbarsModeDidChange() const OVERRIDE;
128    virtual void mouseDidMoveOverElement(const WebCore::HitTestResult&, unsigned modifierFlags) OVERRIDE;
129
130    virtual void setToolTip(const String&, WebCore::TextDirection) OVERRIDE;
131
132    virtual void print(WebCore::Frame*) OVERRIDE;
133
134#if ENABLE(SQL_DATABASE)
135    virtual void exceededDatabaseQuota(WebCore::Frame*, const String& databaseName, WebCore::DatabaseDetails) OVERRIDE;
136#endif
137
138    virtual void reachedMaxAppCacheSize(int64_t spaceNeeded) OVERRIDE;
139    virtual void reachedApplicationCacheOriginQuota(WebCore::SecurityOrigin*, int64_t spaceNeeded) OVERRIDE;
140
141#if ENABLE(DASHBOARD_SUPPORT)
142    virtual void annotatedRegionsChanged() OVERRIDE;
143#endif
144
145    virtual void populateVisitedLinks() OVERRIDE;
146
147    virtual WebCore::FloatRect customHighlightRect(WebCore::Node*, const WTF::AtomicString& type, const WebCore::FloatRect& lineRect) OVERRIDE;
148    virtual void paintCustomHighlight(WebCore::Node*, const AtomicString& type, const WebCore::FloatRect& boxRect, const WebCore::FloatRect& lineRect,
149                                      bool behindText, bool entireLine) OVERRIDE;
150
151    virtual bool shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename) OVERRIDE;
152    virtual String generateReplacementFile(const String& path) OVERRIDE;
153
154    virtual bool paintCustomOverhangArea(WebCore::GraphicsContext*, const WebCore::IntRect&, const WebCore::IntRect&, const WebCore::IntRect&) OVERRIDE;
155
156#if ENABLE(INPUT_TYPE_COLOR)
157    virtual PassOwnPtr<WebCore::ColorChooser> createColorChooser(WebCore::ColorChooserClient*, const WebCore::Color&) OVERRIDE;
158#endif
159
160    virtual void runOpenPanel(WebCore::Frame*, PassRefPtr<WebCore::FileChooser>) OVERRIDE;
161    virtual void loadIconForFiles(const Vector<String>&, WebCore::FileIconLoader*) OVERRIDE;
162
163    virtual void setCursor(const WebCore::Cursor&) OVERRIDE;
164    virtual void setCursorHiddenUntilMouseMoves(bool) OVERRIDE;
165#if ENABLE(REQUEST_ANIMATION_FRAME) && !USE(REQUEST_ANIMATION_FRAME_TIMER)
166    virtual void scheduleAnimation() OVERRIDE;
167#endif
168
169    // Notification that the given form element has changed. This function
170    // will be called frequently, so handling should be very fast.
171    virtual void formStateDidChange(const WebCore::Node*) OVERRIDE;
172
173    virtual void didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>&) OVERRIDE;
174    virtual bool shouldNotifyOnFormChanges() OVERRIDE;
175
176    virtual bool selectItemWritingDirectionIsNatural() OVERRIDE;
177    virtual bool selectItemAlignmentFollowsMenuWritingDirection() OVERRIDE;
178    virtual bool hasOpenedPopup() const OVERRIDE;
179    virtual PassRefPtr<WebCore::PopupMenu> createPopupMenu(WebCore::PopupMenuClient*) const OVERRIDE;
180    virtual PassRefPtr<WebCore::SearchPopupMenu> createSearchPopupMenu(WebCore::PopupMenuClient*) const OVERRIDE;
181
182#if USE(ACCELERATED_COMPOSITING)
183    virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() const OVERRIDE;
184    virtual void attachRootGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) OVERRIDE;
185    virtual void setNeedsOneShotDrawingSynchronization() OVERRIDE;
186    virtual void scheduleCompositingLayerFlush() OVERRIDE;
187
188    virtual CompositingTriggerFlags allowedCompositingTriggers() const
189    {
190        return static_cast<CompositingTriggerFlags>(
191            ThreeDTransformTrigger |
192            VideoTrigger |
193            PluginTrigger|
194            CanvasTrigger |
195            AnimationTrigger);
196    }
197
198    virtual bool layerTreeStateIsFrozen() const OVERRIDE;
199#endif
200
201#if ENABLE(TOUCH_EVENTS)
202    virtual void needTouchEvents(bool) OVERRIDE;
203#endif
204
205#if ENABLE(FULLSCREEN_API)
206    virtual bool supportsFullScreenForElement(const WebCore::Element*, bool withKeyboard) OVERRIDE;
207    virtual void enterFullScreenForElement(WebCore::Element*) OVERRIDE;
208    virtual void exitFullScreenForElement(WebCore::Element*) OVERRIDE;
209#endif
210
211#if PLATFORM(MAC)
212    virtual void makeFirstResponder() OVERRIDE;
213#endif
214
215    virtual void enableSuddenTermination() OVERRIDE;
216    virtual void disableSuddenTermination() OVERRIDE;
217
218    virtual void dispatchViewportPropertiesDidChange(const WebCore::ViewportArguments&) const OVERRIDE;
219
220    virtual void notifyScrollerThumbIsVisibleInRect(const WebCore::IntRect&) OVERRIDE;
221    virtual void recommendedScrollbarStyleDidChange(int32_t newStyle) OVERRIDE;
222    virtual bool shouldRubberBandInDirection(WebCore::ScrollDirection) const OVERRIDE;
223
224    virtual WebCore::Color underlayColor() const OVERRIDE;
225
226    virtual void numWheelEventHandlersChanged(unsigned) OVERRIDE;
227
228    virtual void logDiagnosticMessage(const String& message, const String& description, const String& success) OVERRIDE;
229
230    virtual String plugInStartLabelTitle(const String& mimeType) const OVERRIDE;
231    virtual String plugInStartLabelSubtitle(const String& mimeType) const OVERRIDE;
232    virtual String plugInExtraStyleSheet() const OVERRIDE;
233    virtual String plugInExtraScript() const OVERRIDE;
234
235    virtual void didAddHeaderLayer(WebCore::GraphicsLayer*) OVERRIDE;
236    virtual void didAddFooterLayer(WebCore::GraphicsLayer*) OVERRIDE;
237
238    virtual void incrementActivePageCount() OVERRIDE;
239    virtual void decrementActivePageCount() OVERRIDE;
240
241    String m_cachedToolTip;
242    mutable RefPtr<WebFrame> m_cachedFrameSetLargestFrame;
243    mutable bool m_cachedMainFrameHasHorizontalScrollbar;
244    mutable bool m_cachedMainFrameHasVerticalScrollbar;
245
246    WebPage* m_page;
247};
248
249} // namespace WebKit
250
251#endif // WebChromeClient_h
252