Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(647)

Unified Diff: ios/web/web_state/js/resources/context_menu.js

Issue 2801213004: Eliminate extra Native->JS->Native roundrip when showing context menu. (Closed)
Patch Set: Fixed tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/js/resources/context_menu.js
diff --git a/ios/web/web_state/js/resources/context_menu.js b/ios/web/web_state/js/resources/context_menu.js
index ffd654bc361ad3ac54019befef6a87f13cc96606..3df19ecdd6f8fd64c557483bfe805b9932f6b6d9 100644
--- a/ios/web/web_state/js/resources/context_menu.js
+++ b/ios/web/web_state/js/resources/context_menu.js
@@ -13,9 +13,13 @@ goog.provide('__crWeb.contextMenu');
/**
* Returns the url of the image or link under the selected point. Returns an
- * empty string if no links or images are found.
- * @param {number} x Horizontal center of the selected point.
- * @param {number} y Vertical center of the selected point.
+ * empty object if no links or images are found.
+ * @param {number} x Horizontal center of the selected point in web view
+ * coordinates.
+ * @param {number} y Vertical center of the selected point in web view
+ * coordinates.
+ * @param {number} webViewWidth the width of web view.
+ * @param {number} webViewHeight the height of web view.
* @return {!Object} An object of the form {
* href, // URL of the link under the point
* innerText, // innerText of the link, if the selected element is a link
@@ -32,7 +36,36 @@ goog.provide('__crWeb.contextMenu');
* from the current page.
* </ul>
*/
- __gCrWeb['getElementFromPoint'] = function(x, y) {
+ __gCrWeb['getElementFromPoint'] =
+ function(x, y, webViewWidth, webViewHeight) {
+ var scale = getPageWidth() / webViewWidth;
+ return getElementFromPointInPageCoordinates(x * scale, y * scale)
+ };
+
+ /**
+ * Suppresses the next click such that they are not handled by JS click
+ * event handlers.
+ * @type {void}
+ */
+ __gCrWeb['suppressNextClick'] = function() {
+ var suppressNextClick = function(evt) {
+ evt.preventDefault();
+ document.removeEventListener('click', suppressNextClick, false);
+ };
+ document.addEventListener('click', suppressNextClick);
+ };
+
+ /**
+ * Returns the url of the image or link under the selected point in page
+ * coordinates. Returns an empty object if no links or images are found.
+ * @param {number} x Horizontal center of the selected point in page
+ * coordinates.
+ * @param {number} y Vertical center of the selected point in page
+ * coordinates.
+ * @return {!Object} An object in the same form as
+ * {@code getElementFromPoint} result.
+ */
+ var getElementFromPointInPageCoordinates = function(x, y) {
var hitCoordinates = spiralCoordinates_(x, y);
for (var index = 0; index < hitCoordinates.length; index++) {
var coordinates = hitCoordinates[index];
@@ -109,24 +142,11 @@ goog.provide('__crWeb.contextMenu');
};
/**
- * Suppresses the next click such that they are not handled by JS click
- * event handlers.
- * @type {void}
- */
- __gCrWeb['suppressNextClick'] = function() {
- var suppressNextClick = function(evt) {
- evt.preventDefault();
- document.removeEventListener('click', suppressNextClick, false);
- };
- document.addEventListener('click', suppressNextClick);
- };
-
- /**
* Returns the margin in points around touchable elements (e.g. links for
* custom context menu).
* @type {number}
*/
- __gCrWeb['getPageWidth'] = function() {
+ var getPageWidth = function() {
var documentElement = document.documentElement;
var documentBody = document.body;
return Math.max(documentElement.clientWidth,

Powered by Google App Engine
This is Rietveld 408576698