diff options
Diffstat (limited to 'WebKit/android')
| -rw-r--r-- | WebKit/android/jni/WebViewCore.cpp | 2 | ||||
| -rw-r--r-- | WebKit/android/plugins/ANPTypefaceInterface.cpp | 8 | ||||
| -rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.cpp | 63 | ||||
| -rw-r--r-- | WebKit/android/plugins/PluginWidgetAndroid.h | 7 | ||||
| -rw-r--r-- | WebKit/android/plugins/android_npapi.h | 29 |
5 files changed, 94 insertions, 15 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp index 726f724..43a077f 100644 --- a/WebKit/android/jni/WebViewCore.cpp +++ b/WebKit/android/jni/WebViewCore.cpp @@ -1192,7 +1192,7 @@ void WebViewCore::drawPlugins() SkIRect dirty; if (w->isDirty(&dirty)) { w->draw(); - w->localToPageCoords(&dirty); + w->localToDocumentCoords(&dirty); inval.op(dirty, SkRegion::kUnion_Op); } } diff --git a/WebKit/android/plugins/ANPTypefaceInterface.cpp b/WebKit/android/plugins/ANPTypefaceInterface.cpp index d560d3e..e33e580 100644 --- a/WebKit/android/plugins/ANPTypefaceInterface.cpp +++ b/WebKit/android/plugins/ANPTypefaceInterface.cpp @@ -58,6 +58,13 @@ static ANPTypefaceStyle anp_getStyle(const ANPTypeface* tf) { return static_cast<ANPTypefaceStyle>(s); } +static int32_t anp_getFontPath(const ANPTypeface* tf, char fileName[], + int32_t length, int32_t* index) { + size_t size = SkFontHost::GetFileName(SkTypeface::UniqueID(tf), fileName, + length, index); + return static_cast<int32_t>(size); +} + static const char* gFontDir; #define FONT_DIR_SUFFIX "/fonts/" @@ -92,6 +99,7 @@ void ANPTypefaceInterfaceV0_Init(ANPInterface* v) { ASSIGN(i, ref); ASSIGN(i, unref); ASSIGN(i, getStyle); + ASSIGN(i, getFontPath); ASSIGN(i, getFontDirectoryPath); } diff --git a/WebKit/android/plugins/PluginWidgetAndroid.cpp b/WebKit/android/plugins/PluginWidgetAndroid.cpp index 30a55cb..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,8 @@ void PluginWidgetAndroid::setWindow(NPWindow* window, bool isTransparent) { if (m_drawingModel == kSurface_ANPDrawingModel) { if (m_surface) { - m_surface->attach(window->x, window->y, window->width, window->height); + IntPoint docPoint = frameToDocumentCoords(window->x, window->y); + m_surface->attach(docPoint.x(), docPoint.y(), window->width, window->height); } } else { m_flipPixelRef->safeUnref(); @@ -85,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 { @@ -165,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; @@ -285,18 +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 - ScrollView* scrollView = m_pluginView->parent(); - IntPoint pluginFramePoint = IntPoint(m_requestedFrameRect.fLeft, m_requestedFrameRect.fTop); - IntPoint pluginDocPoint = scrollView->convertToContainingWindow(pluginFramePoint); - 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; @@ -306,6 +326,25 @@ void PluginWidgetAndroid::scrollToVisibleFrameRect() { int deltaX = rectCenterX - screenCenterX; int deltaY = rectCenterY - screenCenterY; + ScrollView* scrollView = m_pluginView->parent(); android::WebViewCore* core = android::WebViewCore::getWebViewCore(scrollView); 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; +} diff --git a/WebKit/android/plugins/PluginWidgetAndroid.h b/WebKit/android/plugins/PluginWidgetAndroid.h index 1da618f..c278ffb 100644 --- a/WebKit/android/plugins/PluginWidgetAndroid.h +++ b/WebKit/android/plugins/PluginWidgetAndroid.h @@ -27,6 +27,7 @@ #define PluginWidgetAndroid_H #include "android_npapi.h" +#include "IntPoint.h" #include "SkRect.h" #include <wtf/OwnPtr.h> @@ -73,11 +74,11 @@ struct PluginWidgetAndroid { */ bool setDrawingModel(ANPDrawingModel); - /* Utility method to convert from local (plugin) coordinates to docuemnt + /* Utility method to convert from local (plugin) coordinates to document coordinates. Needed (for instance) to convert the dirty rectangle into document coordinates to inturn inval the screen. */ - void localToPageCoords(SkIRect*) const; + void localToDocumentCoords(SkIRect*) const; /* Returns true (and optionally updates rect with the dirty bounds) if the plugin has invalidate us. @@ -132,6 +133,7 @@ struct PluginWidgetAndroid { void setVisibleRects(const ANPRectI rects[], int32_t count); private: + WebCore::IntPoint frameToDocumentCoords(int frameX, int frameY) const; void computeVisibleFrameRect(); void scrollToVisibleFrameRect(); @@ -144,6 +146,7 @@ private: SkIRect m_visibleDocRect; SkIRect m_requestedFrameRect; OwnPtr<android::PluginSurface> m_surface; + bool m_hasFocus; /* We limit the number of rectangles to minimize storage and ensure adequate speed. diff --git a/WebKit/android/plugins/android_npapi.h b/WebKit/android/plugins/android_npapi.h index e50f031..80fd2c4 100644 --- a/WebKit/android/plugins/android_npapi.h +++ b/WebKit/android/plugins/android_npapi.h @@ -463,6 +463,35 @@ struct ANPTypefaceInterfaceV0 : ANPInterface { */ ANPTypefaceStyle (*getStyle)(const ANPTypeface*); + /** Some fonts are stored in files. If that is true for the fontID, then + this returns the byte length of the full file path. If path is not null, + then the full path is copied into path (allocated by the caller), up to + length bytes. If index is not null, then it is set to the truetype + collection index for this font, or 0 if the font is not in a collection. + + Note: getFontPath does not assume that path is a null-terminated string, + so when it succeeds, it only copies the bytes of the file name and + nothing else (i.e. it copies exactly the number of bytes returned by the + function. If the caller wants to treat path[] as a C string, it must be + sure that it is allocated at least 1 byte larger than the returned size, + and it must copy in the terminating 0. + + If the fontID does not correspond to a file, then the function returns + 0, and the path and index parameters are ignored. + + @param fontID The font whose file name is being queried + @param path Either NULL, or storage for receiving up to length bytes + of the font's file name. Allocated by the caller. + @param length The maximum space allocated in path (by the caller). + Ignored if path is NULL. + @param index Either NULL, or receives the TTC index for this font. + If the font is not a TTC, then will be set to 0. + @return The byte length of th font's file name, or 0 if the font is not + baked by a file. + */ + int32_t (*getFontPath)(const ANPTypeface*, char path[], int32_t length, + int32_t* index); + /** Return the path name for the font directory, or NULL if not supported */ const char* (*getFontDirectoryPath)(); |
