1 /* 2 * Copyright 2008, The Android Open Source Project 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef PluginWidgetAndroid_H 27 #define PluginWidgetAndroid_H 28 29 #include "android_npapi.h" 30 #include "IntPoint.h" 31 #include "IntRect.h" 32 #include "SkRect.h" 33 #include <jni.h> 34 35 namespace WebCore { 36 class PluginView; 37 } 38 39 namespace android { 40 class PluginSurface; 41 class WebViewCore; 42 } 43 44 class SkCanvas; 45 class SkFlipPixelRef; 46 47 /* 48 This is our extended state in a PluginView. This object is created and 49 kept insync with the PluginView, but is also available to WebViewCore 50 to allow its draw() method to be called from outside of the PluginView. 51 */ 52 struct PluginWidgetAndroid { 53 // initialize with our host pluginview. This will delete us when it is 54 // destroyed. 55 PluginWidgetAndroid(WebCore::PluginView* view); 56 ~PluginWidgetAndroid(); 57 58 WebCore::PluginView* pluginView() const { return m_pluginView; } 59 60 // Needed by PluginSurface to manage the java SurfaceView. 61 android::WebViewCore* webViewCore() const { return m_core; } 62 63 /* Can't determine our core at construction time, so PluginView calls this 64 as soon as it has a parent. 65 */ 66 void init(android::WebViewCore*); 67 /* Called each time the PluginView gets a new size or position. 68 */ 69 void setWindow(NPWindow* window, bool isTransparent); 70 71 /* Called whenever the plugin itself requests a new drawing model. If the 72 hardware does not support the requested model then false is returned, 73 otherwise true is returned. 74 */ 75 bool setDrawingModel(ANPDrawingModel); 76 77 /* Called to check if the plugin is running in "windowed" mode (i.e. surface 78 view). 79 */ 80 bool isSurfaceDrawingModel() const { return kSurface_ANPDrawingModel == m_drawingModel; } 81 82 /* Returns true (and optionally updates rect with the dirty bounds in the 83 page coordinate) if the plugin has invalidate us. 84 */ 85 bool isDirty(SkIRect* dirtyBounds = NULL) const; 86 /* Called by PluginView to invalidate a portion of the plugin area (in 87 local plugin coordinates). If signalRedraw is true, this also triggers 88 a subsequent call to draw(NULL). 89 */ 90 void inval(const WebCore::IntRect&, bool signalRedraw); 91 92 /* Called to draw into the plugin's bitmap. If canvas is non-null, the 93 bitmap itself is then drawn into the canvas. 94 */ 95 void draw(SkCanvas* canvas = NULL); 96 97 /* Send this event to the plugin instance. A non-zero value will be 98 returned if the plugin handled the event. 99 */ 100 int16 sendEvent(const ANPEvent&); 101 102 /* Update the plugins event flags. If a flag is set to true then the plugin 103 wants to be notified of events of this type. 104 */ 105 void updateEventFlags(ANPEventFlags); 106 107 /* Called to check if a plugin wants to accept a given event type. It 108 returns true if the plugin wants the events and false otherwise. 109 */ 110 bool isAcceptingEvent(ANPEventFlag); 111 112 /* Notify the plugin of the currently visible screen coordinates (document 113 space) and the current zoom level. 114 */ 115 void setVisibleScreen(const ANPRectI& visibleScreenRect, float zoom); 116 117 /** Registers a set of rectangles that the plugin would like to keep on 118 screen. The rectangles are listed in order of priority with the highest 119 priority rectangle in location rects[0]. The browser will attempt to keep 120 as many of the rectangles on screen as possible and will scroll them into 121 view in response to the invocation of this method and other various events. 122 The count specifies how many rectangles are in the array. If the count is 123 zero it signals the plugin that any existing rectangles should be cleared 124 and no rectangles will be tracked. 125 */ 126 void setVisibleRects(const ANPRectI rects[], int32_t count); 127 128 /** Called when a plugin wishes to enter into full screen mode. It invokes 129 the plugin's Java class (defined in the plugin's apk manifest), which is 130 called asynchronously and provides a View to be displayed full screen. 131 */ 132 void requestFullScreen(); 133 134 /** Called when a plugin wishes to exit from full screen mode. As a result, 135 the plugin's full-screen view is discarded by the view system. It is also 136 called in order to notify the native code that the browser has discarded 137 the view. 138 */ 139 void exitFullScreen(bool pluginInitiated); 140 141 bool inFullScreen() { return m_isFullScreen; } 142 143 /** Called to check if a plugin currently has document focus, which is 144 required for certain operations (e.g. show/hide keyboard). It returns 145 true if the plugin currently has focus and false otherwise. 146 */ 147 bool hasFocus() const { return m_hasFocus; } 148 149 /** Called to ensure the surface is being correctly displayed within the 150 view hierarchy. For instance, if the visibility of the plugin has 151 changed then we need to ensure the surface is added or removed from the 152 view system. 153 */ 154 void layoutSurface(bool pluginBoundsChanged = false); 155 156 /** send the surface the currently visible portion of the plugin. This is not 157 the portion of the plugin visible on the screen but rather the portion of 158 the plugin that is not obscured by other HTML content. 159 */ 160 void setSurfaceClip(const SkIRect& clip); 161 162 /** Called when a plugin wishes to be zoomed and centered in the current view. 163 */ 164 void requestCenterFitZoom(); 165 166 private: 167 void computeVisiblePluginRect(); 168 void scrollToVisiblePluginRect(); 169 170 WebCore::PluginView* m_pluginView; 171 android::WebViewCore* m_core; 172 SkFlipPixelRef* m_flipPixelRef; 173 ANPDrawingModel m_drawingModel; 174 ANPEventFlags m_eventFlags; 175 NPWindow* m_pluginWindow; 176 SkIRect m_pluginBounds; // relative to the page 177 SkIRect m_visibleDocRect; // relative to the page 178 SkIRect m_requestedVisibleRect; // relative to the page 179 bool m_hasFocus; 180 bool m_isFullScreen; 181 bool m_visible; 182 float m_zoomLevel; 183 jobject m_embeddedView; 184 bool m_embeddedViewAttached; 185 bool m_acceptEvents; 186 bool m_isSurfaceClippedOut; 187 188 /* We limit the number of rectangles to minimize storage and ensure adequate 189 speed. 190 */ 191 enum { 192 MAX_REQUESTED_RECTS = 5, 193 }; 194 195 ANPRectI m_requestedVisibleRects[MAX_REQUESTED_RECTS]; 196 int32_t m_requestedVisibleRectCount; 197 }; 198 199 #endif 200