summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCary Clark <cary@android.com>2010-12-15 11:27:24 -0500
committerCary Clark <cary@android.com>2010-12-15 15:23:12 -0500
commitd331bd5120eaafe86ad76f1e9364524a2daf2e78 (patch)
treef187c8829596de69db103066fe00febaced28150
parentff8665d820cc087df2b169dc727396c2a57e65ae (diff)
downloadexternal_webkit-d331bd5120eaafe86ad76f1e9364524a2daf2e78.zip
external_webkit-d331bd5120eaafe86ad76f1e9364524a2daf2e78.tar.gz
external_webkit-d331bd5120eaafe86ad76f1e9364524a2daf2e78.tar.bz2
extract anchor href and image src separately
Long pressing a link may return an anchor, an image, or an image in an anchor. Sometimes we want one, sometimes the other. Make both available so the context menu can choose. Companion changes are in packages/apps/Browser, frameworks/base bug:3282745 bug:3263340 Change-Id: I422db224ad67147f0cbacc4078df305b1cf8564d
-rw-r--r--WebKit/android/jni/WebViewCore.cpp38
-rw-r--r--WebKit/android/jni/WebViewCore.h8
2 files changed, 39 insertions, 7 deletions
diff --git a/WebKit/android/jni/WebViewCore.cpp b/WebKit/android/jni/WebViewCore.cpp
index c62ae0e..cbed244 100644
--- a/WebKit/android/jni/WebViewCore.cpp
+++ b/WebKit/android/jni/WebViewCore.cpp
@@ -1330,7 +1330,8 @@ void WebViewCore::dumpNavTree()
#endif
}
-WebCore::HTMLAnchorElement* WebViewCore::retrieveAnchorElement(int x, int y)
+HTMLElement* WebViewCore::retrieveElement(int x, int y,
+ const QualifiedName& tagName)
{
HitTestResult hitTestResult = m_mainFrame->eventHandler()
->hitTestResultAtPoint(IntPoint(x, y), false, false,
@@ -1347,14 +1348,26 @@ WebCore::HTMLAnchorElement* WebViewCore::retrieveAnchorElement(int x, int y)
}
Node* node = hitTestResult.innerNode();
Node* element = node;
- while (element && !element->isElementNode())
+ while (element && (!element->isElementNode()
+ || !element->hasTagName(tagName))) {
element = element->parentNode();
+ }
DBG_NAV_LOGD("node=%p element=%p x=%d y=%d nodeName=%s tagName=%s", node,
element, x, y, node->nodeName().utf8().data(),
- ((Element*) element)->tagName().utf8().data());
- if (!element->hasTagName(WebCore::HTMLNames::aTag))
- return 0;
- return static_cast<WebCore::HTMLAnchorElement*>(element);
+ element ? ((Element*) element)->tagName().utf8().data() : "<none>");
+ return static_cast<WebCore::HTMLElement*>(element);
+}
+
+HTMLAnchorElement* WebViewCore::retrieveAnchorElement(int x, int y)
+{
+ return static_cast<HTMLAnchorElement*>
+ (retrieveElement(x, y, HTMLNames::aTag));
+}
+
+HTMLImageElement* WebViewCore::retrieveImageElement(int x, int y)
+{
+ return static_cast<HTMLImageElement*>
+ (retrieveElement(x, y, HTMLNames::imgTag));
}
WTF::String WebViewCore::retrieveHref(int x, int y)
@@ -1369,6 +1382,12 @@ WTF::String WebViewCore::retrieveAnchorText(int x, int y)
return anchor ? anchor->text() : WTF::String();
}
+WTF::String WebViewCore::retrieveImageSource(int x, int y)
+{
+ HTMLImageElement* image = retrieveImageElement(x, y);
+ return image ? image->src().string() : WTF::String();
+}
+
WTF::String WebViewCore::requestLabel(WebCore::Frame* frame,
WebCore::Node* node)
{
@@ -3714,6 +3733,11 @@ static jstring RetrieveAnchorText(JNIEnv *env, jobject obj, jint x, jint y)
return 0;
}
+static jstring RetrieveImageSource(JNIEnv *env, jobject obj, jint x, jint y)
+{
+ WTF::String result = GET_NATIVE_VIEW(env, obj)->retrieveImageSource(x, y);
+ return !result.isEmpty() ? WtfStringToJstring(env, result) : 0;
+}
static void MoveFocus(JNIEnv *env, jobject obj, jint framePtr, jint nodePtr)
{
@@ -4100,6 +4124,8 @@ static JNINativeMethod gJavaWebViewCoreMethods[] = {
(void*) RetrieveHref },
{ "nativeRetrieveAnchorText", "(II)Ljava/lang/String;",
(void*) RetrieveAnchorText },
+ { "nativeRetrieveImageSource", "(II)Ljava/lang/String;",
+ (void*) RetrieveImageSource },
{ "nativeUpdateFrameCache", "()V",
(void*) UpdateFrameCache },
{ "nativeGetContentMinPrefWidth", "()I",
diff --git a/WebKit/android/jni/WebViewCore.h b/WebKit/android/jni/WebViewCore.h
index 41dc2e0f..b223191 100644
--- a/WebKit/android/jni/WebViewCore.h
+++ b/WebKit/android/jni/WebViewCore.h
@@ -50,11 +50,14 @@ namespace WebCore {
class Color;
class FrameView;
class HTMLAnchorElement;
+ class HTMLElement;
+ class HTMLImageElement;
class HTMLSelectElement;
class RenderPart;
class RenderText;
class Node;
class PlatformKeyboardEvent;
+ class QualifiedName;
class RenderTextControl;
class ScrollView;
class TimerBase;
@@ -287,9 +290,9 @@ namespace android {
// Followings support calls from Java to native WebCore
//
-
WTF::String retrieveHref(int x, int y);
WTF::String retrieveAnchorText(int x, int y);
+ WTF::String retrieveImageSource(int x, int y);
WTF::String requestLabel(WebCore::Frame* , WebCore::Node* );
// If the focus is a textfield (<input>), textarea, or contentEditable,
@@ -610,6 +613,9 @@ namespace android {
void sendNotifyProgressFinished();
bool handleMouseClick(WebCore::Frame* framePtr, WebCore::Node* nodePtr);
WebCore::HTMLAnchorElement* retrieveAnchorElement(int x, int y);
+ WebCore::HTMLElement* retrieveElement(int x, int y,
+ const WebCore::QualifiedName& );
+ WebCore::HTMLImageElement* retrieveImageElement(int x, int y);
// below are members responsible for accessibility support
String modifySelectionTextNavigationAxis(DOMSelection* selection, int direction, int granularity);
String modifySelectionDomNavigationAxis(DOMSelection* selection, int direction, int granularity);