Commit 1e1006ab authored by Eugene But's avatar Eugene But Committed by Commit Bot

Fixed context menu handling for -webkit-touch-callout styled elements.

Context menu is sometimes invoked for parent elements. f.e. a link can
be a parent element of an image and even though user has pressed on the
image, context menu is still shown for link, not for image.

This CL checks -webkit-touch-callout style on element it is about to
present a menu for (which can be a parent). Before the change
-webkit-touch-callout was always checked for a parent causing system
context menu to show up.

Bug: 736480
Change-Id: I9239d75a1bfd9926dd67d1c742763c56837b0c38
Reviewed-on: https://chromium-review.googlesource.com/578215
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488423}
parent b2ffed36
......@@ -204,4 +204,24 @@ TEST_F(ContextMenuJsTest, LinkOfImage) {
}
}
// Tests context menu invoked on an image with "-webkit-touch-callout:none"
// style and parent link.
TEST_F(ContextMenuJsTest, LinkOfImageWithCalloutNone) {
// A page with an image surrounded by a link.
static const char image_html[] =
"<a href='%s'>"
"<img style='width:9;height:9;display:block;-webkit-touch-callout:none;'>"
"</a>";
// A page with a link to a destination URL.
LoadHtml(base::StringPrintf(image_html, "http://destination"));
id result = ExecuteGetElementFromPointJavaScript(5, 5);
NSDictionary* expected_result = @{
kContextMenuElementInnerText : @"",
kContextMenuElementReferrerPolicy : @"default",
kContextMenuElementHyperlink : @"http://destination/",
};
EXPECT_NSEQ(expected_result, result);
}
} // namespace web
......@@ -76,8 +76,6 @@ goog.provide('__crWeb.contextMenu');
continue;
}
if (getComputedWebkitTouchCallout_(element) === 'none')
continue;
// Also check element's ancestors. A bound on the level is used here to
// avoid large overhead when no links or images are found.
var level = 0;
......@@ -94,6 +92,7 @@ goog.provide('__crWeb.contextMenu');
return {};
}
if (getComputedWebkitTouchCallout_(element) !== 'none') {
if (tagName === 'a' && element.href) {
// Found a link.
return {
......@@ -135,6 +134,7 @@ goog.provide('__crWeb.contextMenu');
}
return result;
}
}
element = element.parentNode;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment