summaryrefslogtreecommitdiffstats
path: root/WebKit/android/plugins/PluginWidgetAndroid.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/plugins/PluginWidgetAndroid.cpp')
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.cpp133
1 files changed, 57 insertions, 76 deletions
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 113a3bc..b815c90 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -24,10 +24,15 @@
*/
#include "config.h"
-#include "android_graphics.h"
+#include "PluginWidgetAndroid.h"
+
+#if ENABLE(TOUCH_EVENTS)
+#include "ChromeClient.h"
+#endif
#include "Document.h"
#include "Element.h"
#include "Frame.h"
+#include "Page.h"
#include "PluginPackage.h"
#include "PluginView.h"
#include "PluginWidgetAndroid.h"
@@ -36,7 +41,8 @@
#include "SkFlipPixelRef.h"
#include "SkString.h"
#include "WebViewCore.h"
-#include "jni_utility.h"
+#include "android_graphics.h"
+#include <JNIUtility.h>
#define DEBUG_VISIBLE_RECTS 1 // temporary debug printfs and fixes
@@ -48,7 +54,7 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
m_eventFlags = 0;
m_pluginWindow = NULL;
m_requestedVisibleRectCount = 0;
- m_requestedFrameRect.setEmpty();
+ m_requestedDocRect.setEmpty();
m_visibleDocRect.setEmpty();
m_pluginBounds.setEmpty();
m_hasFocus = false;
@@ -56,11 +62,16 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
m_visible = true;
m_zoomLevel = 0;
m_embeddedView = NULL;
+ m_acceptEvents = false;
}
PluginWidgetAndroid::~PluginWidgetAndroid() {
+ m_acceptEvents = false;
if (m_core) {
m_core->removePlugin(this);
+ if (m_isFullScreen) {
+ exitFullScreen(true);
+ }
if (m_embeddedView) {
m_core->destroySurface(m_embeddedView);
}
@@ -78,6 +89,7 @@ PluginWidgetAndroid::~PluginWidgetAndroid() {
void PluginWidgetAndroid::init(android::WebViewCore* core) {
m_core = core;
m_core->addPlugin(this);
+ m_acceptEvents = true;
}
static SkBitmap::Config computeConfig(bool isTransparent) {
@@ -101,36 +113,32 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
if (m_drawingModel == kSurface_ANPDrawingModel) {
- IntPoint docPoint = frameToDocumentCoords(window->x, window->y);
-
- // if the surface exists check for changes and update accordingly
- if (m_embeddedView && m_pluginBounds != oldPluginBounds) {
-
- m_core->updateSurface(m_embeddedView, docPoint.x(), docPoint.y(),
- window->width, window->height);
-
// if the surface does not exist then create a new surface
- } else if(!m_embeddedView) {
+ if (!m_embeddedView) {
WebCore::PluginPackage* pkg = m_pluginView->plugin();
NPP instance = m_pluginView->instance();
-
jobject pluginSurface;
pkg->pluginFuncs()->getvalue(instance, kJavaSurface_ANPGetValue,
static_cast<void*>(&pluginSurface));
jobject tempObj = m_core->addSurface(pluginSurface,
- docPoint.x(), docPoint.y(),
+ window->x, window->y,
window->width, window->height);
if (tempObj) {
JNIEnv* env = JSC::Bindings::getJNIEnv();
m_embeddedView = env->NewGlobalRef(tempObj);
}
- }
- if (m_isFullScreen && m_pluginBounds != oldPluginBounds) {
- m_core->updateFullScreenPlugin(docPoint.x(), docPoint.y(),
- window->width, window->height);
+ } else if (m_pluginBounds != oldPluginBounds) {
+ // if the surface exists check for changes and update accordingly
+ if (m_isFullScreen) {
+ m_core->updateFullScreenPlugin(window->x, window->y,
+ window->width, window->height);
+ } else {
+ m_core->updateSurface(m_embeddedView, window->x, window->y,
+ window->width, window->height);
+ }
}
} else {
m_flipPixelRef->safeUnref();
@@ -144,14 +152,7 @@ bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) {
return true;
}
-void PluginWidgetAndroid::localToDocumentCoords(SkIRect* rect) const {
- if (m_pluginWindow) {
- IntPoint pluginDocCoords = frameToDocumentCoords(m_pluginWindow->x,
- m_pluginWindow->y);
- rect->offset(pluginDocCoords.x(), pluginDocCoords.y());
- }
-}
-
+// returned rect is in the page coordinate
bool PluginWidgetAndroid::isDirty(SkIRect* rect) const {
// nothing to report if we haven't had setWindow() called yet
if (NULL == m_flipPixelRef) {
@@ -164,6 +165,7 @@ bool PluginWidgetAndroid::isDirty(SkIRect* rect) const {
} else {
if (rect) {
*rect = dirty.getBounds();
+ rect->offset(m_pluginWindow->x, m_pluginWindow->y);
}
return true;
}
@@ -211,8 +213,7 @@ void PluginWidgetAndroid::draw(SkCanvas* canvas) {
if (canvas && m_pluginWindow) {
SkBitmap bm(bitmap);
bm.setPixelRef(m_flipPixelRef);
- canvas->drawBitmap(bm, SkIntToScalar(m_pluginWindow->x),
- SkIntToScalar(m_pluginWindow->y), NULL);
+ canvas->drawBitmap(bm, 0, 0);
}
}
break;
@@ -223,6 +224,8 @@ void PluginWidgetAndroid::draw(SkCanvas* canvas) {
}
bool PluginWidgetAndroid::sendEvent(const ANPEvent& evt) {
+ if (!m_acceptEvents)
+ return false;
WebCore::PluginPackage* pkg = m_pluginView->plugin();
NPP instance = m_pluginView->instance();
// "missing" plugins won't have these
@@ -252,12 +255,18 @@ void PluginWidgetAndroid::updateEventFlags(ANPEventFlags flags) {
}
Document* doc = m_pluginView->getParentFrame()->document();
+#if ENABLE(TOUCH_EVENTS)
if((m_eventFlags ^ flags) & kTouch_ANPEventFlag) {
- if(flags & kTouch_ANPEventFlag)
- doc->addTouchEventListener(m_pluginView->getElement());
- else
- doc->removeTouchEventListener(m_pluginView->getElement());
+ if (flags & kTouch_ANPEventFlag) {
+ if (Page* page = doc->page())
+ page->chrome()->client()->needTouchEvents(true, false);
+ doc->addListenerTypeIfNeeded(eventNames().touchstartEvent);
+ } else {
+ if (Page* page = doc->page())
+ page->chrome()->client()->needTouchEvents(false, false);
+ }
}
+#endif
m_eventFlags = flags;
}
@@ -283,7 +292,7 @@ void PluginWidgetAndroid::setVisibleScreen(const ANPRectI& visibleDocRect, float
int newScreenH = m_visibleDocRect.height();
if (oldScreenW != newScreenW || oldScreenH != newScreenH)
- computeVisibleFrameRect();
+ computeVisibleDocRect();
bool visible = SkIRect::Intersects(m_visibleDocRect, m_pluginBounds);
if(m_visible != visible) {
@@ -328,10 +337,10 @@ void PluginWidgetAndroid::setVisibleRects(const ANPRectI rects[], int32_t count)
}
}
#endif
- computeVisibleFrameRect();
+ computeVisibleDocRect();
}
-void PluginWidgetAndroid::computeVisibleFrameRect() {
+void PluginWidgetAndroid::computeVisibleDocRect() {
// ensure the visibleDocRect has been set (i.e. not equal to zero)
if (m_visibleDocRect.isEmpty() || !m_pluginWindow)
@@ -345,7 +354,7 @@ void PluginWidgetAndroid::computeVisibleFrameRect() {
ANPRectI* rect = &m_requestedVisibleRect[counter];
- // create skia rect for easier manipulation and convert it to frame coordinates
+ // create skia rect for easier manipulation and convert it to page coordinates
SkIRect pluginRect;
pluginRect.set(rect->left, rect->top, rect->right, rect->bottom);
pluginRect.offset(m_pluginWindow->x, m_pluginWindow->y);
@@ -377,35 +386,27 @@ void PluginWidgetAndroid::computeVisibleFrameRect() {
visibleRect = pluginRect;
}
- m_requestedFrameRect = visibleRect;
- scrollToVisibleFrameRect();
+ m_requestedDocRect = visibleRect;
+ scrollToVisibleDocRect();
}
-void PluginWidgetAndroid::scrollToVisibleFrameRect() {
+void PluginWidgetAndroid::scrollToVisibleDocRect() {
- if (!m_hasFocus || m_requestedFrameRect.isEmpty() || m_visibleDocRect.isEmpty()) {
+ if (!m_hasFocus || m_requestedDocRect.isEmpty() || m_visibleDocRect.isEmpty()) {
#if DEBUG_VISIBLE_RECTS
- SkDebugf("%s call m_hasFocus=%d m_requestedFrameRect.isEmpty()=%d"
+ SkDebugf("%s call m_hasFocus=%d m_requestedDocRect.isEmpty()=%d"
" m_visibleDocRect.isEmpty()=%d", __FUNCTION__, m_hasFocus,
- m_requestedFrameRect.isEmpty(), m_visibleDocRect.isEmpty());
+ m_requestedDocRect.isEmpty(), m_visibleDocRect.isEmpty());
#endif
return;
}
- // if the entire rect is already visible then we don't need to scroll, which
- // requires converting the m_requestedFrameRect from frame to doc coordinates
- IntPoint pluginDocPoint = frameToDocumentCoords(m_requestedFrameRect.fLeft,
- m_requestedFrameRect.fTop);
- SkIRect requestedDocRect;
- requestedDocRect.set(pluginDocPoint.x(), pluginDocPoint.y(),
- pluginDocPoint.x() + m_requestedFrameRect.width(),
- pluginDocPoint.y() + m_requestedFrameRect.height());
-
- if (m_visibleDocRect.contains(requestedDocRect))
+ // if the entire rect is already visible then we don't need to scroll
+ if (m_visibleDocRect.contains(m_requestedDocRect))
return;
// find the center of the visibleRect in document coordinates
- int rectCenterX = requestedDocRect.fLeft + requestedDocRect.width()/2;
- int rectCenterY = requestedDocRect.fTop + requestedDocRect.height()/2;
+ int rectCenterX = m_requestedDocRect.fLeft + m_requestedDocRect.width()/2;
+ int rectCenterY = m_requestedDocRect.fTop + m_requestedDocRect.height()/2;
// find document coordinates for center of the visible screen
int screenCenterX = m_visibleDocRect.fLeft + m_visibleDocRect.width()/2;
@@ -423,24 +424,6 @@ void PluginWidgetAndroid::scrollToVisibleFrameRect() {
core->scrollBy(deltaX, deltaY, true);
}
-IntPoint PluginWidgetAndroid::frameToDocumentCoords(int frameX, int frameY) const {
- IntPoint docPoint = IntPoint(frameX, frameY);
-
- const ScrollView* currentScrollView = m_pluginView->parent();
- if (currentScrollView) {
- const ScrollView* parentScrollView = currentScrollView->parent();
- while (parentScrollView) {
-
- docPoint.move(currentScrollView->x(), currentScrollView->y());
-
- currentScrollView = parentScrollView;
- parentScrollView = parentScrollView->parent();
- }
- }
-
- return docPoint;
-}
-
void PluginWidgetAndroid::requestFullScreen() {
if (m_isFullScreen || !m_embeddedView) {
return;
@@ -456,9 +439,8 @@ void PluginWidgetAndroid::requestFullScreen() {
m_core->destroySurface(m_embeddedView);
// add the full screen view
- IntPoint docPoint = frameToDocumentCoords(m_pluginWindow->x, m_pluginWindow->y);
m_core->showFullScreenPlugin(m_embeddedView, m_pluginView->instance(),
- docPoint.x(), docPoint.y(), m_pluginWindow->width,
+ m_pluginWindow->x, m_pluginWindow->y, m_pluginWindow->width,
m_pluginWindow->height);
m_isFullScreen = true;
}
@@ -474,8 +456,7 @@ void PluginWidgetAndroid::exitFullScreen(bool pluginInitiated) {
}
// add the embedded view back
- IntPoint docPoint = frameToDocumentCoords(m_pluginWindow->x, m_pluginWindow->y);
- m_core->updateSurface(m_embeddedView, docPoint.x(), docPoint.y(),
+ m_core->updateSurface(m_embeddedView, m_pluginWindow->x, m_pluginWindow->y,
m_pluginWindow->width, m_pluginWindow->height);
// send event to notify plugin of full screen change