15267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)/*
25267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Copyright (C) 2009 Google Inc. All rights reserved.
35267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
45267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * modification, are permitted provided that the following conditions are
65267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * met:
75267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
85267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Redistributions of source code must retain the above copyright
95267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * notice, this list of conditions and the following disclaimer.
105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Redistributions in binary form must reproduce the above
115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * copyright notice, this list of conditions and the following disclaimer
125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * in the documentation and/or other materials provided with the
135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * distribution.
145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *     * Neither the name of Google Inc. nor the names of its
155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * contributors may be used to endorse or promote products derived from
165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * this software without specific prior written permission.
175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) *
185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles) */
305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#ifndef WebWidgetClient_h
325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#define WebWidgetClient_h
335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "WebNavigationPolicy.h"
3551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebCommon.h"
3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebLayerTreeView.h"
3751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebRect.h"
3851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "public/platform/WebScreenInfo.h"
39a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "public/web/WebTouchAction.h"
405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
4151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)namespace blink {
425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebGestureEvent;
445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebString;
455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebWidget;
465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct WebCursorInfo;
475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)struct WebSize;
485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)class WebWidgetClient {
505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)public:
515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when a region of the WebWidget needs to be re-painted.
525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didInvalidateRect(const WebRect&) { }
535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when the Widget has changed size as a result of an auto-resize.
555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didAutoResize(const WebSize& newSize) { }
565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Attempt to initialize compositing for this widget. If this is successful,
585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // layerTreeView() will return a valid WebLayerTreeView.
595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void initializeLayerTreeView() { }
605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Return a compositing view used for this widget. This is owned by the
625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidgetClient.
635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual WebLayerTreeView* layerTreeView() { return 0; }
64f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    // FIXME: Remove all overrides of this and change layerTreeView() above to ASSERT_NOT_REACHED.
65f91f5fa1608c2cdd9af1842fb5dadbe78275be2aBo Liu    virtual bool allowsBrokenNullLayerTreeView() const { return false; }
665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Sometimes the WebWidget enters a state where it will generate a sequence
685267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // of invalidations that should not, by themselves, trigger the compositor
695267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // to schedule a new frame. This call indicates to the embedder that it
705267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // should suppress compositor scheduling temporarily.
715267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void suppressCompositorScheduling(bool enable) { }
725267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
735267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Indicates to the embedder that the compositor is about to begin a
745267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // frame. This is primarily to signal to flow control mechanisms that a
755267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // frame is beginning, not to perform actual painting work.
765267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void willBeginCompositorFrame() { }
775267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
785267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Indicates to the embedder that the WebWidget is ready for additional
795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // input.
805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didBecomeReadyForAdditionalInput() { }
815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called for compositing mode when a frame commit operation has finished.
835267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didCommitCompositorFrame() { }
845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called for compositing mode when the draw commands for a WebKit-side
865267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // frame have been issued.
875267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didCommitAndDrawCompositorFrame() { }
885267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
895267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called for compositing mode when swapbuffers has been posted in the GPU
905267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // process.
915267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didCompleteSwapBuffers() { }
925267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
935267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when a call to WebWidget::animate is required
945267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void scheduleAnimation() { }
955267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
965267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when the widget acquires or loses focus, respectively.
975267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didFocus() { }
985267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didBlur() { }
995267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1005267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when the cursor for the widget changes.
1015267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didChangeCursor(const WebCursorInfo&) { }
1025267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1035267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when the widget should be closed.  WebWidget::close() should
1045267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // be called asynchronously as a result of this notification.
1055267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void closeWidgetSoon() { }
1065267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1075267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to show the widget according to the given policy.
1085267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void show(WebNavigationPolicy) { }
1095267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1105267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to block execution of the current thread until the widget is
1115267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // closed.
1125267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void runModal() { }
1135267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1145267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to enter/exit fullscreen mode. If enterFullScreen returns true,
1155267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // then WebWidget::{will,Did}EnterFullScreen should bound resizing the
1165267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidget into fullscreen mode. Similarly, when exitFullScreen is
1175267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // called, WebWidget::{will,Did}ExitFullScreen should bound resizing the
1185267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidget out of fullscreen mode.
1195267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool enterFullScreen() { return false; }
1205267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void exitFullScreen() { }
1215267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1225267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to get/set the position of the widget in screen coordinates.
1235267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual WebRect windowRect() { return WebRect(); }
1245267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void setWindowRect(const WebRect&) { }
1255267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1265267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when a tooltip should be shown at the current cursor position.
1275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void setToolTipText(const WebString&, WebTextDirection hint) { }
1285267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1295267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to get the position of the resizer rect in window coordinates.
1305267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual WebRect windowResizerRect() { return WebRect(); }
1315267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1325267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to get the position of the root window containing the widget
1335267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // in screen coordinates.
1345267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual WebRect rootWindowRect() { return WebRect(); }
1355267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1365267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to query information about the screen where this widget is
1375267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // displayed.
1385267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual WebScreenInfo screenInfo() { return WebScreenInfo(); }
1395267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1405267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to get the scale factor of the display.
1415267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual float deviceScaleFactor() { return 1; }
1425267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1435267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // When this method gets called, WebWidgetClient implementation should
1445267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // reset the input method by cancelling any ongoing composition.
1455267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void resetInputMethod() { }
1465267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1475267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Requests to lock the mouse cursor. If true is returned, the success
1485267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // result will be asynchronously returned via a single call to
1495267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidget::didAcquirePointerLock() or
1505267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidget::didNotAcquirePointerLock().
1515267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // If false, the request has been denied synchronously.
1525267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool requestPointerLock() { return false; }
1535267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1545267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Cause the pointer lock to be released. This may be called at any time,
1555267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // including when a lock is pending but not yet acquired.
1565267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // WebWidget::didLosePointerLock() is called when unlock is complete.
1575267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void requestPointerUnlock() { }
1585267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1595267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Returns true iff the pointer is locked to this widget.
1605267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual bool isPointerLocked() { return false; }
1615267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1625267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called when a gesture event is handled.
1635267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled) { }
1645267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1655267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    // Called to update if touch events should be sent.
1665267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    virtual void hasTouchEventHandlers(bool) { }
1675267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
168a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // Called during WebWidget::HandleInputEvent for a TouchStart event to inform the embedder
169a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    // of the touch actions that are permitted for this touch.
170a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    virtual void setTouchAction(WebTouchAction touchAction) { }
171a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)
172a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    // Called when value of focused text field gets dirty, e.g. value is
173a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    // modified by script, not by user input.
174a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    virtual void didUpdateTextOfFocusedElementByNonUserInput() { }
175a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch
176197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    // Request the browser to show the IME for current input type.
177197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    virtual void showImeIfNeeded() { }
178197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
1795267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)protected:
1805267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)    ~WebWidgetClient() { }
1815267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)};
1825267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
18351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)} // namespace blink
1845267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)
1855267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#endif
186