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 "WebCanvas.h" 35 #include "WebCommon.h" 36 #include "WebCompositionUnderline.h" 37 #include "WebTextInputType.h" 38 #include "WebTextDirection.h" 39 40 namespace WebKit { 41 42 class WebInputEvent; 43 class WebString; 44 struct WebPoint; 45 struct WebRect; 46 struct WebSize; 47 template <typename T> class WebVector; 48 49 class WebWidget { 50 public: 51 // This method closes and deletes the WebWidget. 52 virtual void close() = 0; 53 54 // Returns the current size of the WebWidget. 55 virtual WebSize size() = 0; 56 57 // Called to resize the WebWidget. 58 virtual void resize(const WebSize&) = 0; 59 60 // Called to update imperative animation state. This should be called before 61 // paint, although the client can rate-limit these calls. 62 virtual void animate() = 0; 63 64 // Called to layout the WebWidget. This MUST be called before Paint, 65 // and it may result in calls to WebWidgetClient::didInvalidateRect. 66 virtual void layout() = 0; 67 68 // Called to paint the rectangular region within the WebWidget 69 // onto the specified canvas at (viewPort.x,viewPort.y). You MUST call 70 // Layout before calling this method. It is okay to call paint 71 // multiple times once layout has been called, assuming no other 72 // changes are made to the WebWidget (e.g., once events are 73 // processed, it should be assumed that another call to layout is 74 // warranted before painting again). 75 virtual void paint(WebCanvas*, const WebRect& viewPort) = 0; 76 77 // Triggers compositing of the current layers onto the screen. 78 // The finish argument controls whether the compositor will wait for the 79 // GPU to finish rendering before returning. You MUST call Layout 80 // before calling this method, for the same reasons described in 81 // the paint method above. 82 virtual void composite(bool finish) = 0; 83 84 // Called to inform the WebWidget of a change in theme. 85 // Implementors that cache rendered copies of widgets need to re-render 86 // on receiving this message 87 virtual void themeChanged() = 0; 88 89 // Called to inform the WebWidget of an input event. Returns true if 90 // the event has been processed, false otherwise. 91 virtual bool handleInputEvent(const WebInputEvent&) = 0; 92 93 // Called to inform the WebWidget that mouse capture was lost. 94 virtual void mouseCaptureLost() = 0; 95 96 // Called to inform the WebWidget that it has gained or lost keyboard focus. 97 virtual void setFocus(bool) = 0; 98 99 // Called to inform the WebWidget of a new composition text. 100 // If selectionStart and selectionEnd has the same value, then it indicates 101 // the input caret position. If the text is empty, then the existing 102 // composition text will be cancelled. 103 // Returns true if the composition text was set successfully. 104 virtual bool setComposition( 105 const WebString& text, 106 const WebVector<WebCompositionUnderline>& underlines, 107 int selectionStart, 108 int selectionEnd) = 0; 109 110 // Called to inform the WebWidget to confirm an ongoing composition. 111 // This method is same as confirmComposition(WebString()); 112 // Returns true if there is an ongoing composition. 113 virtual bool confirmComposition() = 0; 114 115 // Called to inform the WebWidget to confirm an ongoing composition with a 116 // new composition text. If the text is empty then the current composition 117 // text is confirmed. If there is no ongoing composition, then deletes the 118 // current selection and inserts the text. This method has no effect if 119 // there is no ongoing composition and the text is empty. 120 // Returns true if there is an ongoing composition or the text is inserted. 121 virtual bool confirmComposition(const WebString& text) = 0; 122 123 // Returns the current text input type of this WebWidget. 124 virtual WebTextInputType textInputType() = 0; 125 126 // Returns the current caret bounds of this WebWidget. The selection bounds 127 // will be returned if a selection range is available. 128 virtual WebRect caretOrSelectionBounds() = 0; 129 130 // Returns the start and end point for the current selection, aligned to the 131 // bottom of the selected line. 132 virtual bool selectionRange(WebPoint& start, WebPoint& end) const = 0; 133 134 // Changes the text direction of the selected input node. 135 virtual void setTextDirection(WebTextDirection) = 0; 136 137 // Returns true if the WebWidget uses GPU accelerated compositing 138 // to render its contents. 139 virtual bool isAcceleratedCompositingActive() const = 0; 140 141 protected: ~WebWidget()142 ~WebWidget() { } 143 }; 144 145 } // namespace WebKit 146 147 #endif 148