summaryrefslogtreecommitdiffstats
path: root/WebKit/android/plugins/PluginWidgetAndroid.cpp
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2009-08-04 09:28:51 -0400
committerDerek Sollenberger <djsollen@google.com>2009-08-04 09:57:19 -0400
commitdfe318f64605ccd0edac334790a5bce975921f47 (patch)
tree0680cdc01cfb411fc9048a0742d6249b6390dbe8 /WebKit/android/plugins/PluginWidgetAndroid.cpp
parent5655832af95b56bf25c0183a2d5d2cd909d6c8f4 (diff)
downloadexternal_webkit-dfe318f64605ccd0edac334790a5bce975921f47.zip
external_webkit-dfe318f64605ccd0edac334790a5bce975921f47.tar.gz
external_webkit-dfe318f64605ccd0edac334790a5bce975921f47.tar.bz2
enhancing visibleRect tracking and making it work within iframes.
Diffstat (limited to 'WebKit/android/plugins/PluginWidgetAndroid.cpp')
-rw-r--r--WebKit/android/plugins/PluginWidgetAndroid.cpp43
1 files changed, 32 insertions, 11 deletions
diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp
index 96aa74b..72714b4 100644
--- a/WebKit/android/plugins/PluginWidgetAndroid.cpp
+++ b/WebKit/android/plugins/PluginWidgetAndroid.cpp
@@ -47,6 +47,7 @@ PluginWidgetAndroid::PluginWidgetAndroid(WebCore::PluginView* view)
m_requestedVisibleRectCount = 0;
m_requestedFrameRect.setEmpty();
m_visibleDocRect.setEmpty();
+ m_hasFocus = false;
}
PluginWidgetAndroid::~PluginWidgetAndroid() {
@@ -71,7 +72,7 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) {
if (m_drawingModel == kSurface_ANPDrawingModel) {
if (m_surface) {
- IntPoint docPoint = getDocumentCoordinates(window->x, window->y);
+ IntPoint docPoint = frameToDocumentCoords(window->x, window->y);
m_surface->attach(docPoint.x(), docPoint.y(), window->width, window->height);
}
} else {
@@ -86,9 +87,12 @@ bool PluginWidgetAndroid::setDrawingModel(ANPDrawingModel model) {
return true;
}
-void PluginWidgetAndroid::localToPageCoords(SkIRect* rect) const {
- if (m_pluginWindow)
- rect->offset(m_pluginWindow->x, m_pluginWindow->y);
+void PluginWidgetAndroid::localToDocumentCoords(SkIRect* rect) const {
+ if (m_pluginWindow) {
+ IntPoint pluginDocCoords = frameToDocumentCoords(m_pluginWindow->x,
+ m_pluginWindow->y);
+ rect->offset(pluginDocCoords.x(), pluginDocCoords.y());
+ }
}
bool PluginWidgetAndroid::isDirty(SkIRect* rect) const {
@@ -166,6 +170,15 @@ bool PluginWidgetAndroid::sendEvent(const ANPEvent& evt) {
NPP instance = m_pluginView->instance();
// "missing" plugins won't have these
if (pkg && instance) {
+
+ // keep track of whether or not the plugin currently has focus
+ if (evt.eventType == kLifecycle_ANPEventType) {
+ if (evt.data.lifecycle.action == kLoseFocus_ANPLifecycleAction)
+ m_hasFocus = false;
+ else if (evt.data.lifecycle.action == kGainFocus_ANPLifecycleAction)
+ m_hasFocus = true;
+ }
+
// make a localCopy since the actual plugin may not respect its constness,
// and so we don't want our caller to have its param modified
ANPEvent localCopy = evt;
@@ -286,16 +299,24 @@ void PluginWidgetAndroid::computeVisibleFrameRect() {
void PluginWidgetAndroid::scrollToVisibleFrameRect() {
- if (m_requestedFrameRect.isEmpty() || m_visibleDocRect.isEmpty())
+ if (!m_hasFocus || m_requestedFrameRect.isEmpty() || m_visibleDocRect.isEmpty())
return;
- // TODO if the entire rect is already visible then we don't need to scroll,
- // this requires converting the m_requestedFrameRect from frame to doc coordinates
+ // 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))
+ return;
// find the center of the visibleRect in document coordinates
- IntPoint pluginDocPoint = getDocumentCoordinates(m_requestedFrameRect.fLeft, m_requestedFrameRect.fTop);
- int rectCenterX = pluginDocPoint.x() + m_requestedFrameRect.width()/2;
- int rectCenterY = pluginDocPoint.y() + m_requestedFrameRect.height()/2;
+ int rectCenterX = requestedDocRect.fLeft + requestedDocRect.width()/2;
+ int rectCenterY = requestedDocRect.fTop + requestedDocRect.height()/2;
// find document coordinates for center of the visible screen
int screenCenterX = m_visibleDocRect.fLeft + m_visibleDocRect.width()/2;
@@ -310,7 +331,7 @@ void PluginWidgetAndroid::scrollToVisibleFrameRect() {
core->scrollBy(deltaX, deltaY, true);
}
-IntPoint PluginWidgetAndroid::getDocumentCoordinates(int frameX, int frameY) {
+IntPoint PluginWidgetAndroid::frameToDocumentCoords(int frameX, int frameY) const {
IntPoint docPoint = IntPoint(frameX, frameY);
const ScrollView* currentScrollView = m_pluginView->parent();