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

Unified Diff: third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp

Issue 1668553003: Fix server-side image map click location with "Open link in new tab" Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add Test for HTMLAnchorElement Created 4 years, 9 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: third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp b/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp
index f858f4ff170bb2e954455e1b33ce27f9b6cd2a43..72f509db7039bdc88431ebc4314e8dd92e4c9099 100644
--- a/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp
+++ b/third_party/WebKit/Source/core/html/HTMLAnchorElement.cpp
@@ -106,24 +106,31 @@ bool HTMLAnchorElement::isKeyboardFocusable() const
return HTMLElement::isKeyboardFocusable();
}
-static void appendServerMapMousePosition(StringBuilder& url, Event* event)
+bool HTMLAnchorElement::getClampedPointFromEvent(IntPoint& clampedPoint, const Event* event)
{
+ if (!event)
+ return false;
+
if (!event->isMouseEvent())
- return;
+ return false;
+
+ if (!event->target())
+ return false;
- ASSERT(event->target());
Node* target = event->target()->toNode();
- ASSERT(target);
+ if (!target)
+ return false;
+
if (!isHTMLImageElement(*target))
- return;
+ return false;
HTMLImageElement& imageElement = toHTMLImageElement(*target);
if (!imageElement.isServerMap())
- return;
+ return false;
LayoutObject* layoutObject = imageElement.layoutObject();
if (!layoutObject || !layoutObject->isBox())
- return;
+ return false;
// The coordinates sent in the query string are relative to the height and
// width of the image element, ignoring CSS transform/zoom.
@@ -139,9 +146,14 @@ static void appendServerMapMousePosition(StringBuilder& url, Event* event)
// Negative coordinates are clamped to 0 such that clicks in the left and
// top padding/border areas receive an X or Y coordinate of 0.
- IntPoint clampedPoint(roundedIntPoint(mapPoint));
+ clampedPoint = IntPoint(roundedIntPoint(mapPoint));
clampedPoint.clampNegativeToZero();
+ return true;
+}
+
+void HTMLAnchorElement::appendServerMapMousePosition(StringBuilder& url, IntPoint& clampedPoint)
tkent 2016/03/14 00:06:33 IntPoint& -> const IntPoint&
+{
url.append('?');
url.appendNumber(clampedPoint.x());
url.append(',');
@@ -325,7 +337,11 @@ void HTMLAnchorElement::handleClick(Event* event)
StringBuilder url;
url.append(stripLeadingAndTrailingHTMLSpaces(fastGetAttribute(hrefAttr)));
- appendServerMapMousePosition(url, event);
+ IntPoint clampedPoint;
+ bool success = getClampedPointFromEvent(clampedPoint, event);
+ if (success) {
+ appendServerMapMousePosition(url, clampedPoint);
+ }
KURL completedURL = document().completeURL(url.toString());
// Schedule the ping before the frame load. Prerender in Chrome may kill the renderer as soon as the navigation is

Powered by Google App Engine
This is Rietveld 408576698