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 APPLE COMPUTER, INC. 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 "SkRect.h" 32 #include <jni.h> 33 34 namespace WebCore { 35 class PluginView; 36 } 37 38 namespace android { 39 class PluginSurface; 40 class WebViewCore; 41 } 42 43 class SkCanvas; 44 class SkFlipPixelRef; 45 46 /* 47 This is our extended state in a PluginView. This object is created and 48 kept insync with the PluginView, but is also available to WebViewCore 49 to allow its draw() method to be called from outside of the PluginView. 50 */ 51 struct PluginWidgetAndroid { 52 // initialize with our host pluginview. This will delete us when it is 53 // destroyed. 54 PluginWidgetAndroid(WebCore::PluginView* view); 55 ~PluginWidgetAndroid(); 56 pluginViewPluginWidgetAndroid57 WebCore::PluginView* pluginView() const { return m_pluginView; } 58 59 // Needed by PluginSurface to manage the java SurfaceView. webViewCorePluginWidgetAndroid60 android::WebViewCore* webViewCore() const { return m_core; } 61 62 /* Can't determine our core at construction time, so PluginView calls this 63 as soon as it has a parent. 64 */ 65 void init(android::WebViewCore*); 66 /* Called each time the PluginView gets a new size or position. 67 */ 68 void setWindow(NPWindow* window, bool isTransparent); 69 70 /* Called to notify us of the plugin's java class that implements the 71 * PluginStub interface. A local copy is made of the className so the caller 72 * can safely free the memory as soon as the function returns. 73 */ 74 bool setPluginStubJavaClassName(const char* className); 75 76 /* Called whenever the plugin itself requests a new drawing model. If the 77 hardware does not support the requested model then false is returned, 78 otherwise true is returned. 79 */ 80 bool setDrawingModel(ANPDrawingModel); 81 82 /* Utility method to convert from local (plugin) coordinates to document 83 coordinates. Needed (for instance) to convert the dirty rectangle into 84 document coordinates to inturn inval the screen. 85 */ 86 void localToDocumentCoords(SkIRect*) const; 87 88 /* Returns true (and optionally updates rect with the dirty bounds) if 89 the plugin has invalidate us. 90 */ 91 bool isDirty(SkIRect* dirtyBounds = NULL) const; 92 /* Called by PluginView to invalidate a portion of the plugin area (in 93 local plugin coordinates). If signalRedraw is true, this also triggers 94 a subsequent call to draw(NULL). 95 */ 96 void inval(const WebCore::IntRect&, bool signalRedraw); 97 98 /* Called to draw into the plugin's bitmap. If canvas is non-null, the 99 bitmap itself is then drawn into the canvas. 100 */ 101 void draw(SkCanvas* canvas = NULL); 102 103 /* Send this event to the plugin instance, and return true if the plugin 104 handled it. 105 */ 106 bool sendEvent(const ANPEvent&); 107 108 /* Update the plugins event flags. If a flag is set to true then the plugin 109 wants to be notified of events of this type. 110 */ 111 void updateEventFlags(ANPEventFlags); 112 113 /* Called to check if a plugin wants to accept a given event type. It 114 returns true if the plugin wants the events and false otherwise. 115 */ 116 bool isAcceptingEvent(ANPEventFlag); 117 118 /* Notify the plugin of the currently visible screen coordinates (document 119 space) and the current zoom level. 120 */ 121 void setVisibleScreen(const ANPRectI& visibleScreenRect, float zoom); 122 123 /** Registers a set of rectangles that the plugin would like to keep on 124 screen. The rectangles are listed in order of priority with the highest 125 priority rectangle in location rects[0]. The browser will attempt to keep 126 as many of the rectangles on screen as possible and will scroll them into 127 view in response to the invocation of this method and other various events. 128 The count specifies how many rectangles are in the array. If the count is 129 zero it signals the plugin that any existing rectangles should be cleared 130 and no rectangles will be tracked. 131 */ 132 void setVisibleRects(const ANPRectI rects[], int32_t count); 133 134 /** Called when a plugin wishes to enter into full screen mode. The plugin's 135 Java class (set using setPluginStubJavaClassName(...)) will be called 136 asynchronously to provide a View to be displayed in full screen. 137 */ 138 void requestFullScreenMode(); 139 140 private: 141 WebCore::IntPoint frameToDocumentCoords(int frameX, int frameY) const; 142 void computeVisibleFrameRect(); 143 void scrollToVisibleFrameRect(); 144 145 WebCore::PluginView* m_pluginView; 146 android::WebViewCore* m_core; 147 SkFlipPixelRef* m_flipPixelRef; 148 ANPDrawingModel m_drawingModel; 149 ANPEventFlags m_eventFlags; 150 NPWindow* m_pluginWindow; 151 SkIRect m_visibleDocRect; 152 SkIRect m_requestedFrameRect; 153 bool m_hasFocus; 154 float m_zoomLevel; 155 char* m_javaClassName; 156 jobject m_childView; 157 158 /* We limit the number of rectangles to minimize storage and ensure adequate 159 speed. 160 */ 161 enum { 162 MAX_REQUESTED_RECTS = 5, 163 }; 164 165 ANPRectI m_requestedVisibleRect[MAX_REQUESTED_RECTS]; 166 int32_t m_requestedVisibleRectCount; 167 }; 168 169 #endif 170