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 WebWidget_h
     32 #define WebWidget_h
     33 
     34 #include "../platform/WebCanvas.h"
     35 #include "../platform/WebCommon.h"
     36 #include "../platform/WebRect.h"
     37 #include "../platform/WebSize.h"
     38 #include "WebCompositionUnderline.h"
     39 #include "WebTextDirection.h"
     40 #include "WebTextInputInfo.h"
     41 
     42 namespace blink {
     43 
     44 class WebInputEvent;
     45 class WebLayerTreeView;
     46 class WebMouseEvent;
     47 class WebString;
     48 struct WebPoint;
     49 struct WebRenderingStats;
     50 template <typename T> class WebVector;
     51 
     52 class WebWidget {
     53 public:
     54     // This method closes and deletes the WebWidget.
     55     virtual void close() { }
     56 
     57     // Returns the current size of the WebWidget.
     58     virtual WebSize size() { return WebSize(); }
     59 
     60     // Used to group a series of resize events. For example, if the user
     61     // drags a resizer then willStartLiveResize will be called, followed by a
     62     // sequence of resize events, ending with willEndLiveResize when the user
     63     // lets go of the resizer.
     64     virtual void willStartLiveResize() { }
     65 
     66     // Called to resize the WebWidget.
     67     virtual void resize(const WebSize&) { }
     68 
     69     // Ends a group of resize events that was started with a call to
     70     // willStartLiveResize.
     71     virtual void willEndLiveResize() { }
     72 
     73     // Called to notify the WebWidget of entering/exiting fullscreen mode. The
     74     // resize method may be called between will{Enter,Exit}FullScreen and
     75     // did{Enter,Exit}FullScreen.
     76     virtual void willEnterFullScreen() { }
     77     virtual void didEnterFullScreen() { }
     78     virtual void willExitFullScreen() { }
     79     virtual void didExitFullScreen() { }
     80 
     81     // Called to update imperative animation state. This should be called before
     82     // paint, although the client can rate-limit these calls.
     83     virtual void animate(double monotonicFrameBeginTime) { }
     84 
     85     // Called to layout the WebWidget. This MUST be called before Paint,
     86     // and it may result in calls to WebWidgetClient::didInvalidateRect.
     87     virtual void layout() { }
     88 
     89     // Called to toggle the WebWidget in or out of force compositing mode. This
     90     // should be called before paint.
     91     virtual void enterForceCompositingMode(bool enter) { }
     92 
     93     // Called to notify the WebWidget that the widget has exited compositing
     94     // mode and cannot reenter.
     95     virtual void didExitCompositingMode() { }
     96 
     97     enum PaintOptions {
     98         // Attempt to fulfill the painting request by reading back from the
     99         // compositor, assuming we're using a compositor to render.
    100         ReadbackFromCompositorIfAvailable,
    101 
    102         // Force the widget to rerender onto the canvas using software. This
    103         // mode ignores 3d transforms and ignores GPU-resident content, such
    104         // as video, canvas, and WebGL.
    105         //
    106         // Note: This option exists on OS(ANDROID) and will hopefully be
    107         //       removed once the link disambiguation feature renders using
    108         //       the compositor.
    109         ForceSoftwareRenderingAndIgnoreGPUResidentContent,
    110     };
    111 
    112     // Called to paint the rectangular region within the WebWidget
    113     // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call
    114     // Layout before calling this method. It is okay to call paint
    115     // multiple times once layout has been called, assuming no other
    116     // changes are made to the WebWidget (e.g., once events are
    117     // processed, it should be assumed that another call to layout is
    118     // warranted before painting again).
    119     virtual void paint(WebCanvas*, const WebRect& viewPort, PaintOptions = ReadbackFromCompositorIfAvailable) { }
    120 
    121     // Returns true if we've started tracking repaint rectangles.
    122     virtual bool isTrackingRepaints() const { return false; }
    123 
    124     // Indicates that the compositing surface associated with this WebWidget is
    125     // ready to use.
    126     virtual void setCompositorSurfaceReady() { }
    127 
    128     // Called to inform the WebWidget of a change in theme.
    129     // Implementors that cache rendered copies of widgets need to re-render
    130     // on receiving this message
    131     virtual void themeChanged() { }
    132 
    133     // Called to inform the WebWidget of an input event. Returns true if
    134     // the event has been processed, false otherwise.
    135     virtual bool handleInputEvent(const WebInputEvent&) { return false; }
    136 
    137     // Called to inform the WebWidget of the mouse cursor's visibility.
    138     virtual void setCursorVisibilityState(bool isVisible) { }
    139 
    140     // Check whether the given point hits any registered touch event handlers.
    141     virtual bool hasTouchEventHandlersAt(const WebPoint&) { return true; }
    142 
    143     // Applies a scroll delta to the root layer, which is bundled with a page
    144     // scale factor that may apply a CSS transform on the whole document (used
    145     // for mobile-device pinch zooming). This is triggered by events sent to the
    146     // compositor thread.
    147     virtual void applyScrollAndScale(const WebSize& scrollDelta, float scaleFactor) { }
    148 
    149     // Called to inform the WebWidget that mouse capture was lost.
    150     virtual void mouseCaptureLost() { }
    151 
    152     // Called to inform the WebWidget that it has gained or lost keyboard focus.
    153     virtual void setFocus(bool) { }
    154 
    155     // Called to inform the WebWidget of a new composition text.
    156     // If selectionStart and selectionEnd has the same value, then it indicates
    157     // the input caret position. If the text is empty, then the existing
    158     // composition text will be cancelled.
    159     // Returns true if the composition text was set successfully.
    160     virtual bool setComposition(
    161         const WebString& text,
    162         const WebVector<WebCompositionUnderline>& underlines,
    163         int selectionStart,
    164         int selectionEnd) { return false; }
    165 
    166     enum ConfirmCompositionBehavior {
    167         DoNotKeepSelection,
    168         KeepSelection,
    169     };
    170 
    171     // Called to inform the WebWidget to confirm an ongoing composition.
    172     // This method is same as confirmComposition(WebString());
    173     // Returns true if there is an ongoing composition.
    174     virtual bool confirmComposition() { return false; } // Deprecated
    175     virtual bool confirmComposition(ConfirmCompositionBehavior selectionBehavior) { return false; }
    176 
    177     // Called to inform the WebWidget to confirm an ongoing composition with a
    178     // new composition text. If the text is empty then the current composition
    179     // text is confirmed. If there is no ongoing composition, then deletes the
    180     // current selection and inserts the text. This method has no effect if
    181     // there is no ongoing composition and the text is empty.
    182     // Returns true if there is an ongoing composition or the text is inserted.
    183     virtual bool confirmComposition(const WebString& text) { return false; }
    184 
    185     // Fetches the character range of the current composition, also called the
    186     // "marked range." Returns true and fills the out-paramters on success;
    187     // returns false on failure.
    188     virtual bool compositionRange(size_t* location, size_t* length) { return false; }
    189 
    190     // Returns information about the current text input of this WebWidget.
    191     virtual WebTextInputInfo textInputInfo() { return WebTextInputInfo(); }
    192 
    193     // Returns the anchor and focus bounds of the current selection.
    194     // If the selection range is empty, it returns the caret bounds.
    195     virtual bool selectionBounds(WebRect& anchor, WebRect& focus) const { return false; }
    196 
    197     // Called to notify that IME candidate window has changed its visibility or
    198     // its appearance. These calls correspond to trigger
    199     // candidatewindow{show,update,hide} events defined in W3C IME API.
    200     virtual void didShowCandidateWindow() { }
    201     virtual void didUpdateCandidateWindow() { }
    202     virtual void didHideCandidateWindow() { }
    203 
    204     // Returns the text direction at the start and end bounds of the current selection.
    205     // If the selection range is empty, it returns false.
    206     virtual bool selectionTextDirection(WebTextDirection& start, WebTextDirection& end) const { return false; }
    207 
    208     // Returns true if the selection range is nonempty and its anchor is first
    209     // (i.e its anchor is its start).
    210     virtual bool isSelectionAnchorFirst() const { return false; }
    211 
    212     // Fetch the current selection range of this WebWidget. If there is no
    213     // selection, it will output a 0-length range with the location at the
    214     // caret. Returns true and fills the out-paramters on success; returns false
    215     // on failure.
    216     virtual bool caretOrSelectionRange(size_t* location, size_t* length) { return false; }
    217 
    218     // Changes the text direction of the selected input node.
    219     virtual void setTextDirection(WebTextDirection) { }
    220 
    221     // Returns true if the WebWidget uses GPU accelerated compositing
    222     // to render its contents.
    223     virtual bool isAcceleratedCompositingActive() const { return false; }
    224 
    225     // Returns true if the WebWidget created is of type WebPagePopup.
    226     virtual bool isPagePopup() const { return false; }
    227     // Returns true if the WebWidget created is of type WebPopupMenu.
    228     virtual bool isPopupMenu() const { return false; }
    229     // Returns true if the WebWidget created is of type WebHelperPlugin.
    230     virtual bool isHelperPlugin() const { return false; }
    231 
    232     // The WebLayerTreeView initialized on this WebWidgetClient will be going away and
    233     // is no longer safe to access.
    234     virtual void willCloseLayerTreeView() { }
    235 
    236     // Calling WebWidgetClient::requestPointerLock() will result in one
    237     // return call to didAcquirePointerLock() or didNotAcquirePointerLock().
    238     virtual void didAcquirePointerLock() { }
    239     virtual void didNotAcquirePointerLock() { }
    240 
    241     // Pointer lock was held, but has been lost. This may be due to a
    242     // request via WebWidgetClient::requestPointerUnlock(), or for other
    243     // reasons such as the user exiting lock, window focus changing, etc.
    244     virtual void didLosePointerLock() { }
    245 
    246     // Informs the WebWidget that the resizer rect changed. Happens for example
    247     // on mac, when a widget appears below the WebWidget without changing the
    248     // WebWidget's size (WebWidget::resize() automatically checks the resizer
    249     // rect.)
    250     virtual void didChangeWindowResizerRect() { }
    251 
    252     // The page background color. Can be used for filling in areas without
    253     // content.
    254     virtual WebColor backgroundColor() const { return 0xFFFFFFFF; /* SK_ColorWHITE */ }
    255 
    256 protected:
    257     ~WebWidget() { }
    258 };
    259 
    260 } // namespace blink
    261 
    262 #endif
    263