forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
boliu@chromium.org
committed
Nov 8, 2012
1 parent
72bd37e
commit a7198a1
Showing
14 changed files
with
603 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "android_webview/common/aw_hit_test_data.h" | ||
|
||
namespace android_webview { | ||
|
||
AwHitTestData::AwHitTestData() : type(UNKNOWN_TYPE) {} | ||
|
||
AwHitTestData::~AwHitTestData() {} | ||
|
||
} // namespace android_webview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_ | ||
#define ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_ | ||
|
||
#include "base/string16.h" | ||
#include "googleurl/src/gurl.h" | ||
|
||
namespace android_webview { | ||
|
||
// Holdes all hit test data needed by public WebView APIs. | ||
// The Java counter part to this is AwContents.HitTestData. | ||
struct AwHitTestData { | ||
|
||
// Matches exactly with constants in WebView.HitTestResult, with deprecated | ||
// values removed. | ||
enum Type { | ||
// Default type where nothing we are interested in is hit. | ||
// |extra_data_for_type| will be empty. All other values should be emtpy | ||
// except the special case described below. | ||
// For special case of invalid or javascript scheme url that would | ||
// otherwise be type an LINK type, |href|, |anchor_text|, |img_src| contain | ||
// their normal values for the respective type. | ||
UNKNOWN_TYPE = 0, | ||
|
||
// Content detection types. Not used yet. | ||
// TODO(boliu): Hook up content detection. | ||
PHONE_TYPE = 2, | ||
GEO_TYPE = 3, | ||
EMAIL_TYPE = 4, | ||
|
||
// Hit on a pure image (without links). |extra_data_for_type|, |href|, | ||
// and |anchor_text| will be empty. |img_src| will contain the absolute | ||
// source url of the image. | ||
IMAGE_TYPE = 5, | ||
|
||
// Hit on a link with valid and non-javascript url and without embedded | ||
// image. |extra_data_for_type| is the valid absolute url of the link. | ||
// |href| will contain the exact href attribute string. |anchor_text| will | ||
// contain the anchor text if the link is an anchor tag. |img_src| will be | ||
// empty. | ||
// Note 1: If the link url is invalid or javascript scheme, then the type | ||
// will be UNKNOWN_TYPE. | ||
// Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView | ||
// Java API, but the actual tag can be something other than <a>, such as | ||
// <link> or <area>. | ||
SRC_LINK_TYPE = 7, | ||
|
||
// Same as SRC_LINK_TYPE except the link contains an image. |img_src| and | ||
// |extra_data_for_type| will contain the absolute valid url of the image | ||
// source. |href| will contain the (possibly invalid or javascript-scheme) | ||
// link href attribute. |anchor_text| will be empty. | ||
// Both notes from SRC_LINK_TYPE apply. | ||
SRC_IMAGE_LINK_TYPE = 8, | ||
|
||
// Hit on an editable text input element. All other values will be empty. | ||
EDIT_TEXT_TYPE = 9, | ||
}; | ||
|
||
// For all strings/GURLs, empty/invalid will become null upon conversion to | ||
// Java. | ||
int type; // Only values from enum Type above. | ||
std::string extra_data_for_type; | ||
string16 href; | ||
string16 anchor_text; | ||
GURL img_src; | ||
|
||
AwHitTestData(); | ||
~AwHitTestData(); | ||
}; | ||
|
||
} // namespace android_webview | ||
|
||
#endif // ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.