Home | History | Annotate | Download | only in web
      1 /*
      2  * Copyright (C) 2009 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef WebWidgetClient_h
     32 #define WebWidgetClient_h
     33 
     34 #include "WebNavigationPolicy.h"
     35 #include "public/platform/WebCommon.h"
     36 #include "public/platform/WebLayerTreeView.h"
     37 #include "public/platform/WebRect.h"
     38 #include "public/platform/WebScreenInfo.h"
     39 #include "public/web/WebTouchAction.h"
     40 
     41 namespace blink {
     42 
     43 class WebGestureEvent;
     44 class WebString;
     45 class WebWidget;
     46 struct WebCursorInfo;
     47 struct WebSize;
     48 
     49 class WebWidgetClient {
     50 public:
     51     // Called when a region of the WebWidget needs to be re-painted.
     52     virtual void didInvalidateRect(const WebRect&) { }
     53 
     54     // Called when a region of the WebWidget, given by clipRect, should be
     55     // scrolled by the specified dx and dy amounts.
     56     virtual void didScrollRect(int dx, int dy, const WebRect& clipRect) { }
     57 
     58     // Called when the Widget has changed size as a result of an auto-resize.
     59     virtual void didAutoResize(const WebSize& newSize) { }
     60 
     61     // Attempt to initialize compositing for this widget. If this is successful,
     62     // layerTreeView() will return a valid WebLayerTreeView.
     63     virtual void initializeLayerTreeView() { }
     64 
     65     // Return a compositing view used for this widget. This is owned by the
     66     // WebWidgetClient.
     67     virtual WebLayerTreeView* layerTreeView() { return 0; }
     68     // FIXME: Remove all overrides of this and change layerTreeView() above to ASSERT_NOT_REACHED.
     69     virtual bool allowsBrokenNullLayerTreeView() const { return false; }
     70 
     71     // Sometimes the WebWidget enters a state where it will generate a sequence
     72     // of invalidations that should not, by themselves, trigger the compositor
     73     // to schedule a new frame. This call indicates to the embedder that it
     74     // should suppress compositor scheduling temporarily.
     75     virtual void suppressCompositorScheduling(bool enable) { }
     76 
     77     // Indicates to the embedder that the compositor is about to begin a
     78     // frame. This is primarily to signal to flow control mechanisms that a
     79     // frame is beginning, not to perform actual painting work.
     80     virtual void willBeginCompositorFrame() { }
     81 
     82     // Indicates to the embedder that the WebWidget is ready for additional
     83     // input.
     84     virtual void didBecomeReadyForAdditionalInput() { }
     85 
     86     // Called for compositing mode when a frame commit operation has finished.
     87     virtual void didCommitCompositorFrame() { }
     88 
     89     // Called for compositing mode when the draw commands for a WebKit-side
     90     // frame have been issued.
     91     virtual void didCommitAndDrawCompositorFrame() { }
     92 
     93     // Called for compositing mode when swapbuffers has been posted in the GPU
     94     // process.
     95     virtual void didCompleteSwapBuffers() { }
     96 
     97     // Called when a call to WebWidget::animate is required
     98     virtual void scheduleAnimation() { }
     99 
    100     // Called when the widget acquires or loses focus, respectively.
    101     virtual void didFocus() { }
    102     virtual void didBlur() { }
    103 
    104     // Called when the cursor for the widget changes.
    105     virtual void didChangeCursor(const WebCursorInfo&) { }
    106 
    107     // Called when the widget should be closed.  WebWidget::close() should
    108     // be called asynchronously as a result of this notification.
    109     virtual void closeWidgetSoon() { }
    110 
    111     // Called to show the widget according to the given policy.
    112     virtual void show(WebNavigationPolicy) { }
    113 
    114     // Called to block execution of the current thread until the widget is
    115     // closed.
    116     virtual void runModal() { }
    117 
    118     // Called to enter/exit fullscreen mode. If enterFullScreen returns true,
    119     // then WebWidget::{will,Did}EnterFullScreen should bound resizing the
    120     // WebWidget into fullscreen mode. Similarly, when exitFullScreen is
    121     // called, WebWidget::{will,Did}ExitFullScreen should bound resizing the
    122     // WebWidget out of fullscreen mode.
    123     virtual bool enterFullScreen() { return false; }
    124     virtual void exitFullScreen() { }
    125 
    126     // Called to get/set the position of the widget in screen coordinates.
    127     virtual WebRect windowRect() { return WebRect(); }
    128     virtual void setWindowRect(const WebRect&) { }
    129 
    130     // Called when a tooltip should be shown at the current cursor position.
    131     virtual void setToolTipText(const WebString&, WebTextDirection hint) { }
    132 
    133     // Called to get the position of the resizer rect in window coordinates.
    134     virtual WebRect windowResizerRect() { return WebRect(); }
    135 
    136     // Called to get the position of the root window containing the widget
    137     // in screen coordinates.
    138     virtual WebRect rootWindowRect() { return WebRect(); }
    139 
    140     // Called to query information about the screen where this widget is
    141     // displayed.
    142     virtual WebScreenInfo screenInfo() { return WebScreenInfo(); }
    143 
    144     // Called to get the scale factor of the display.
    145     virtual float deviceScaleFactor() { return 1; }
    146 
    147     // When this method gets called, WebWidgetClient implementation should
    148     // reset the input method by cancelling any ongoing composition.
    149     virtual void resetInputMethod() { }
    150 
    151     // Requests to lock the mouse cursor. If true is returned, the success
    152     // result will be asynchronously returned via a single call to
    153     // WebWidget::didAcquirePointerLock() or
    154     // WebWidget::didNotAcquirePointerLock().
    155     // If false, the request has been denied synchronously.
    156     virtual bool requestPointerLock() { return false; }
    157 
    158     // Cause the pointer lock to be released. This may be called at any time,
    159     // including when a lock is pending but not yet acquired.
    160     // WebWidget::didLosePointerLock() is called when unlock is complete.
    161     virtual void requestPointerUnlock() { }
    162 
    163     // Returns true iff the pointer is locked to this widget.
    164     virtual bool isPointerLocked() { return false; }
    165 
    166     // Called when a gesture event is handled.
    167     virtual void didHandleGestureEvent(const WebGestureEvent& event, bool eventCancelled) { }
    168 
    169     // Called to update if touch events should be sent.
    170     virtual void hasTouchEventHandlers(bool) { }
    171 
    172     // Called during WebWidget::HandleInputEvent for a TouchStart event to inform the embedder
    173     // of the touch actions that are permitted for this touch.
    174     virtual void setTouchAction(WebTouchAction touchAction) { }
    175 
    176     // Called when value of focused text field gets dirty, e.g. value is
    177     // modified by script, not by user input.
    178     virtual void didUpdateTextOfFocusedElementByNonUserInput() { }
    179 
    180 protected:
    181     ~WebWidgetClient() { }
    182 };
    183 
    184 } // namespace blink
    185 
    186 #endif
    187