diff options
author | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 18:34:05 +0000 |
---|---|---|
committer | boliu@chromium.org <boliu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 18:34:05 +0000 |
commit | a7198a1f23bd0fa70e1486e4deb71c1812572e26 (patch) | |
tree | ef9457229bb64e328d7602559c479101b0a11f6b /android_webview/browser | |
parent | 72bd37ea59cc9b056dda7005e761aaba958e9eca (diff) | |
download | chromium_src-a7198a1f23bd0fa70e1486e4deb71c1812572e26.zip chromium_src-a7198a1f23bd0fa70e1486e4deb71c1812572e26.tar.gz chromium_src-a7198a1f23bd0fa70e1486e4deb71c1812572e26.tar.bz2 |
Implement hit test related methods in Android WebView
The public Android WebView APIs are WebView.getHitTestResult,
WebView.requestFocusNodeHref, and WebView.requestImageRef.
These APIs are mostly used for creating context menus but have
become broken APIs as the Android evolved from the single
threaded initial version of WebView.
* The names are misleading since the value retrieved is based both on
a combination of touch events and FocusedNodeChanged callback
from WebKit.
* The methods are synchronous and there are inherently racy. This is
the case with with the latest version of Android WebView as well.
However this may become more of a problem as Chromium is
multi-processed.
* The methods are inefficient since work needs to be done even if the
client application never call these methods.
This is the first part of largely replicating the broken code with tests
and extensive comments. The goal is to replicate existing logic but
there are probably corner cases that are not matched.
Overall flow is on a touch event or focused node changed event, perform
a WebKit hit test, get the relevant result data and save it in the browser.
The return what is saved when apps query for the data.
Work still needs to be done after this:
* Implement updating hit test data after tab-ing to a link
* Hook up content detection code in content/
* Implement focus highlighting with DPAD controls.
BUG=
All bots are green except unrelated instrumentation tests.
AndroidWebView instrumentation tests are green.
NOTRY=true
Review URL: https://chromiumcodereview.appspot.com/11360037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166712 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview/browser')
-rw-r--r-- | android_webview/browser/renderer_host/aw_render_view_host_ext.cc | 21 | ||||
-rw-r--r-- | android_webview/browser/renderer_host/aw_render_view_host_ext.h | 16 |
2 files changed, 37 insertions, 0 deletions
diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc index 66e7134..e94970e 100644 --- a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc @@ -33,9 +33,22 @@ void AwRenderViewHostExt::DocumentHasImages(DocumentHasImagesResult result) { } void AwRenderViewHostExt::ClearCache() { + DCHECK(CalledOnValidThread()); Send(new AwViewMsg_ClearCache); } +void AwRenderViewHostExt::RequestNewHitTestDataAt(int view_x, int view_y) { + DCHECK(CalledOnValidThread()); + Send(new AwViewMsg_DoHitTest(web_contents()->GetRoutingID(), + view_x, + view_y)); +} + +const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { + DCHECK(CalledOnValidThread()); + return last_hit_test_data_; +} + void AwRenderViewHostExt::RenderViewGone(base::TerminationStatus status) { DCHECK(CalledOnValidThread()); for (std::map<int, DocumentHasImagesResult>::iterator pending_req = @@ -51,6 +64,8 @@ bool AwRenderViewHostExt::OnMessageReceived(const IPC::Message& message) { IPC_BEGIN_MESSAGE_MAP(AwRenderViewHostExt, message) IPC_MESSAGE_HANDLER(AwViewHostMsg_DocumentHasImagesResponse, OnDocumentHasImagesResponse) + IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData, + OnUpdateHitTestData) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -70,4 +85,10 @@ void AwRenderViewHostExt::OnDocumentHasImagesResponse(int msg_id, } } +void AwRenderViewHostExt::OnUpdateHitTestData( + const AwHitTestData& hit_test_data) { + DCHECK(CalledOnValidThread()); + last_hit_test_data_ = hit_test_data; +} + } // namespace android_webview diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.h b/android_webview/browser/renderer_host/aw_render_view_host_ext.h index fcde789..3052479 100644 --- a/android_webview/browser/renderer_host/aw_render_view_host_ext.h +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.h @@ -7,6 +7,7 @@ #include "content/public/browser/web_contents_observer.h" +#include "android_webview/common/aw_hit_test_data.h" #include "base/threading/non_thread_safe.h" namespace android_webview { @@ -28,15 +29,30 @@ class AwRenderViewHostExt : public content::WebContentsObserver, // Clear all WebCore memory cache (not only for this view). void ClearCache(); + // Do a hit test at the view port coordinates and asynchronously update + // |last_hit_test_data_|. + void RequestNewHitTestDataAt(int view_x, int view_y); + + // Return |last_hit_test_data_|. Note that this is unavoidably racy; + // the corresponding public WebView API is as well. + const AwHitTestData& GetLastHitTestData() const; + private: // content::WebContentsObserver implementation. virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; void OnDocumentHasImagesResponse(int msg_id, bool has_images); + void OnUpdateHitTestData( + const AwHitTestData& hit_test_data); std::map<int, DocumentHasImagesResult> pending_document_has_images_requests_; + // Master copy of hit test data on the browser side. This is updated + // as a result of DoHitTest called explicitly or when the FocusedNodeChanged + // is called in AwRenderViewExt. + AwHitTestData last_hit_test_data_; + DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt); }; |