<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[178459] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/178459">178459</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2015-01-14 15:50:57 -0800 (Wed, 14 Jan 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/154769">r154769</a>): Wrong &lt;title&gt; taken as a tooltip for SVG element.
https://bugs.webkit.org/show_bug.cgi?id=139690.

Patch by Said Abou-Hallawa &lt;sabouhallawa@apple.com&gt; on 2015-01-14
Reviewed by Daniel Bates.

Source/WebCore:

Before <a href="http://trac.webkit.org/projects/webkit/changeset/154769">r154769</a>, we were calling Traversal&lt;SVGTitleElement&gt;::firstWithin(), which returns
the first immediate SVGTitleElement child. In <a href="http://trac.webkit.org/projects/webkit/changeset/154769">r154769</a>, Traversal&lt;SVGTitleElement&gt;::firstWithin()
was replaced by descendantsOfType&lt;SVGTitleElement&gt; which returns all descendants SVGTitleElements.
Then we were returning the first element of these descendants, which may not be an immediate
child of the element, as the title of the SVGElement. This was the reason of this bug. The
fix is to use childrenOfType&lt;SVGTitleElement&gt;() instead, which returns the immediate SVGTitleElement
children of an SVGElement.

Also we were not following exactly the specs for the rootmost SVG element's title value.
According to the W3C specs, for stand-alone SVG documents only, the rootmost SVG element
should not return a title. But we were not returning a title for the rootmost SVG element
always. The fix is to return a empty title for the rootmost SVG element only if topDocument()
of the element isSVGDocument().

NOTE: The main SVG specs http://www.w3.org/TR/SVG/interact.html#hit-testing (W3C Recommendation
16 August 2011) and http://www.w3.org/TR/SVG/struct.html#DescriptionAndTitleElements (W3C
Recommendation 16 August 2011) do not say how the tooltip of an SVG element is calculated. But
the SVG tiny specs http://www.w3.org/TR/SVGTiny12/struct.html#uiTitleDescBehavior (W3C
Recommendation 22 December 2008) however explains well the tooltip calculation for the embedded
and the stand-alone SVG cases. And it seems this what we should rely on.

Test: svg/hittest/svg-standalone-tooltip.svg
      svg/hittest/svg-embedded-tooltip.html

* WebCore.exp.in:
* rendering/HitTestResult.h:
Make HitTestResult::setInnerNode be WEBCORE_EXPORT

* svg/SVGElement.cpp:
(WebCore::SVGElement::title):
Replace descendantsOfType&lt;SVGTitleElement&gt;() by childrenOfType&lt;SVGTitleElement&gt;().
Fix the title value of the rootmost SVG element.

* testing/Internals.cpp:
(WebCore::Internals::toolTipFromElement):
* testing/Internals.h:
* testing/Internals.idl:
Add a new internal function toolTipFromElement() which returns the tooltip text for a
given element.

LayoutTests:

* svg/hittest/resources: Added.
* svg/hittest/resources/svg-tooltip.svg: Added.
Shared resources to be used by the tests.

* svg/hittest/resources/svg-tooltip.js: Added.
This code mimics the C++ tooltip calculation and compares its result with what the C++
code returns.

* svg/hittest/svg-embedded-tooltip-expected.txt: Added.
* svg/hittest/svg-embedded-tooltip.html: Added.
This test ensures that the tooltip text for SVG elements is calculated correctly when
the SVG is embedded in an HTML either through inline &lt;svg&gt; tag or through an &lt;embed&gt;
tag. In both cases, the rootmost SVG element should return the SVG document title.

* svg/hittest/svg-standalone-tooltip-expected.txt: Added.
* svg/hittest/svg-standalone-tooltip.svg: Added.
This test ensures that for stand-alone SVG documents, the tooltip text for SVG elements
is calculated correctly. In this case, the rootmost SVG element should not return a
title since the SVG document title will be displayed in the browser chrome.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCorerenderingHitTestResulth">trunk/Source/WebCore/rendering/HitTestResult.h</a></li>
<li><a href="#trunkSourceWebCoresvgSVGElementcpp">trunk/Source/WebCore/svg/SVGElement.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalscpp">trunk/Source/WebCore/testing/Internals.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsh">trunk/Source/WebCore/testing/Internals.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalsidl">trunk/Source/WebCore/testing/Internals.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>trunk/LayoutTests/svg/hittest/resources/</li>
<li><a href="#trunkLayoutTestssvghittestresourcessvgtooltipjs">trunk/LayoutTests/svg/hittest/resources/svg-tooltip.js</a></li>
<li><a href="#trunkLayoutTestssvghittestresourcessvgtooltipsvg">trunk/LayoutTests/svg/hittest/resources/svg-tooltip.svg</a></li>
<li><a href="#trunkLayoutTestssvghittestsvgembeddedtooltipexpectedtxt">trunk/LayoutTests/svg/hittest/svg-embedded-tooltip-expected.txt</a></li>
<li><a href="#trunkLayoutTestssvghittestsvgembeddedtooltiphtml">trunk/LayoutTests/svg/hittest/svg-embedded-tooltip.html</a></li>
<li><a href="#trunkLayoutTestssvghittestsvgstandalonetooltipexpectedtxt">trunk/LayoutTests/svg/hittest/svg-standalone-tooltip-expected.txt</a></li>
<li><a href="#trunkLayoutTestssvghittestsvgstandalonetooltipsvg">trunk/LayoutTests/svg/hittest/svg-standalone-tooltip.svg</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/LayoutTests/ChangeLog        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-01-14  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
+
+        REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+        https://bugs.webkit.org/show_bug.cgi?id=139690.
+
+        Reviewed by Daniel Bates.
+
+        * svg/hittest/resources: Added.
+        * svg/hittest/resources/svg-tooltip.svg: Added.
+        Shared resources to be used by the tests.
+
+        * svg/hittest/resources/svg-tooltip.js: Added.
+        This code mimics the C++ tooltip calculation and compares its result with what the C++
+        code returns.
+        
+        * svg/hittest/svg-embedded-tooltip-expected.txt: Added.
+        * svg/hittest/svg-embedded-tooltip.html: Added.
+        This test ensures that the tooltip text for SVG elements is calculated correctly when
+        the SVG is embedded in an HTML either through inline &lt;svg&gt; tag or through an &lt;embed&gt;
+        tag. In both cases, the rootmost SVG element should return the SVG document title.
+        
+        * svg/hittest/svg-standalone-tooltip-expected.txt: Added.
+        * svg/hittest/svg-standalone-tooltip.svg: Added.
+        This test ensures that for stand-alone SVG documents, the tooltip text for SVG elements
+        is calculated correctly. In this case, the rootmost SVG element should not return a
+        title since the SVG document title will be displayed in the browser chrome.
+
</ins><span class="cx"> 2015-01-14  Bartlomiej Gajda  &lt;b.gajda@samsung.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [MSE] Implement per TrackBuffer buffered.
</span></span></pre></div>
<a id="trunkLayoutTestssvghittestresourcessvgtooltipjs"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/resources/svg-tooltip.js (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/resources/svg-tooltip.js                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/resources/svg-tooltip.js        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+//
+// REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+// https://bugs.webkit.org/show_bug.cgi?id=139690.
+//
+// This code mimics the C++ code for calculating the tooltip text for an SVG element. 
+// It also verifies the tooltip text for an SVG element and all its descendants. If
+// mismatches are found, it logs them by calling the function &quot;log()&quot; which should
+// be defined by the test.
+//
+
+// Returns true if an element can return a title or not
+function canReturnTitle(element)
+{
+  if (!element || element.tagName == &quot;svg&quot; &amp;&amp; element.ownerDocument instanceof SVGDocument)
+      return false;
+
+  return true;
+}
+
+// Searches the tree elements upward till it finds an SVGTitleElement child
+function titleElementFromElementUpward(element)
+{
+  for (; canReturnTitle(element); element = element.parentElement) {
+
+      var children = element.childNodes;
+
+      // Search immediate children and if any of them is a title element return it
+      for (var i = 0; i &lt; children.length; i++) {
+        if (children[i].tagName == &quot;title&quot;)
+          return children[i];
+      }
+  }
+        
+  return null;
+}
+
+// Returns the string of the SVGTitleElement child if it exists in the element's
+// children list or in its parent's children list.
+function titleFromElementUpward(element)
+{
+    var titleElement = titleElementFromElementUpward(element);
+    return !titleElement ? &quot;&quot; : titleElement.textContent;
+}
+
+// Verifies the tooltip text of an SVG element 
+function verifyElementToolTip(element)
+{
+  var actual = internals.toolTipFromElement(element);
+  var expected = titleFromElementUpward(element);
+
+  if (actual == expected)
+    return true;
+    
+  // If the C++ code expected tooltip is different from the calculated tooltip, log
+  // them to the actual result file.
+  log(element.tagName + &quot;:&quot;);
+  log(&quot;\tid:\t\t&quot; + element.id);
+  log(&quot;\tactual:\t\t'&quot; + actual + &quot;'&quot;);
+  log(&quot;\texpected:\t'&quot; + expected + &quot;'\n&quot;);
+  return false;
+}
+
+// Verifies the tooltip text for an SVG element and all its descendants
+function verifyElementTreeToolTips(element)
+{
+  var children = element.childNodes;
+  var result = verifyElementToolTip(element);
+
+  // Verify the tooltips of the children elements
+  for (var i = 0; i &lt; children.length; i++) {
+    if (children[i].nodeType != document.ELEMENT_NODE)
+      continue;
+      
+    if (children[i].tagName == &quot;defs&quot; || children[i].tagName == &quot;title&quot;)
+      continue;
+      
+    result &amp;= verifyElementTreeToolTips(children[i]);
+  }
+  
+  return result;
+}
</ins></span></pre></div>
<a id="trunkLayoutTestssvghittestresourcessvgtooltipsvg"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/resources/svg-tooltip.svg (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/resources/svg-tooltip.svg                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/resources/svg-tooltip.svg        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,59 @@
</span><ins>+&lt;svg
+    xmlns=&quot;http://www.w3.org/2000/svg&quot;
+    xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;
+    width=&quot;200&quot; height=&quot;400&quot;
+    id=&quot;main_svg&quot;&gt;
+    
+  &lt;!--
+      REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+      https://bugs.webkit.org/show_bug.cgi?id=139690.
+
+      This SVG is included in the test svg-embedded-tooltip.html in an &lt;embed&gt; element.
+      The goal is to test the elements' titles of an embedded SVG.
+  --&gt;
+
+  &lt;!-- This is the tooltip of the rootmost SVG element when the SVG is embedded in an HTML --&gt;
+  &lt;title&gt;outermost svg&lt;/title&gt;
+  
+  &lt;defs&gt;
+    &lt;g id=&quot;shape&quot;&gt;
+      &lt;rect width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+      &lt;circle cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+        &lt;title&gt;def small circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;circle cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+        &lt;title&gt;def big circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;g&gt;
+        &lt;rect x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+        &lt;circle cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+          &lt;title&gt;nested circle!&lt;/title&gt;
+        &lt;/circle&gt;
+      &lt;/g&gt;
+      &lt;title&gt;def g element!&lt;/title&gt;
+    &lt;/g&gt;
+  &lt;/defs&gt;
+  
+  &lt;g id=&quot;main_g&quot;&gt;
+    &lt;rect id=&quot;yellow_rect&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+    &lt;circle id=&quot;small_circle&quot; cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+      &lt;title&gt;small circle!&lt;/title&gt;
+    &lt;/circle&gt;
+    &lt;circle id=&quot;big_circle&quot; cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+      &lt;title&gt;big circle!&lt;/title&gt;
+    &lt;/circle&gt;
+    &lt;g id=&quot;sub_g&quot;&gt;
+      &lt;rect id=&quot;lime_rect&quot; x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+      &lt;circle id=&quot;nested_circle&quot; cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+        &lt;title&gt;nested circle!&lt;/title&gt;
+      &lt;/circle&gt;
+    &lt;/g&gt;
+    &lt;title&gt;main g element&lt;/title&gt;
+  &lt;/g&gt;
+
+  &lt;!-- &lt;use&gt; element should return the first &lt;title&gt; element child if it exists --&gt;  
+  &lt;use id=&quot;use_with_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;120&quot;&gt;
+    &lt;title&gt;use element!&lt;/title&gt;
+  &lt;/use&gt;
+  &lt;use id=&quot;use_without_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;240&quot;/&gt;
+&lt;/svg&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestssvghittestsvgembeddedtooltipexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/svg-embedded-tooltip-expected.txt (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/svg-embedded-tooltip-expected.txt                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/svg-embedded-tooltip-expected.txt        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,8 @@
</span><ins>+  
+
+Verifying the inline SVG:
+PASS
+
+Verifying the embedded SVG:
+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestssvghittestsvgembeddedtooltiphtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/svg-embedded-tooltip.html (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/svg-embedded-tooltip.html                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/svg-embedded-tooltip.html        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,91 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;!--
+    REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+    https://bugs.webkit.org/show_bug.cgi?id=139690.
+
+    This test ensures that the tooltip text for SVG elements is calculated correctly.
+    It covers the case when an SVG is embedded in an HTML either through an inline
+    &lt;svg&gt; tag or through an &lt;embed&gt; tag.
+--&gt;
+&lt;head&gt;
+  &lt;script src=&quot;resources/svg-tooltip.js&quot;&gt;&lt;/script&gt;
+  &lt;script&gt;
+    function log(message)
+    {
+      document.getElementById(&quot;log&quot;).appendChild(document.createTextNode(message + '\n'));
+    }
+
+    function runTest()
+    {
+      if (window.testRunner) {
+        testRunner.dumpAsText();
+
+        // Verify the inline &lt;svg&gt; case
+        log(&quot;Verifying the inline SVG:&quot;);
+        log(verifyElementTreeToolTips(document.getElementsByTagName(&quot;svg&quot;)[0]) ? &quot;PASS&quot; : &quot;&quot;);
+
+        // Verify the &lt;embed&gt; SVG case
+        log(&quot;\nVerifying the embedded SVG:&quot;);
+        var element = document.getElementById(&quot;embedId&quot;);
+        var SVGDocment = element.getSVGDocument();
+        log(verifyElementTreeToolTips(SVGDocment.rootElement, 0) ? &quot;PASS&quot; : &quot;&quot;);
+      }
+    }
+  &lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+    
+  &lt;!-- Inline SVG --&gt;
+  &lt;svg width=&quot;200&quot; height=&quot;400&quot; id=&quot;main_svg&quot;&gt;
+    &lt;title&gt;outermost svg&lt;/title&gt;
+    &lt;defs&gt;
+      &lt;g id=&quot;shape&quot;&gt;
+        &lt;rect width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+        &lt;circle cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+          &lt;title&gt;def small circle!&lt;/title&gt;
+        &lt;/circle&gt;
+        &lt;circle cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+          &lt;title&gt;def big circle!&lt;/title&gt;
+        &lt;/circle&gt;
+        &lt;g&gt;
+          &lt;rect x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+          &lt;circle cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+            &lt;title&gt;nested circle!&lt;/title&gt;
+          &lt;/circle&gt;
+        &lt;/g&gt;
+        &lt;title&gt;def g element!&lt;/title&gt;
+      &lt;/g&gt;
+    &lt;/defs&gt;
+    
+    &lt;g id=&quot;main_g&quot;&gt;
+      &lt;rect id=&quot;yellow_rect&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+      &lt;circle id=&quot;small_circle&quot; cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+        &lt;title&gt;small circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;circle id=&quot;big_circle&quot; cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+        &lt;title&gt;big circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;g id=&quot;sub_g&quot;&gt;
+        &lt;rect id=&quot;lime_rect&quot; x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+        &lt;circle id=&quot;nested_circle&quot; cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+          &lt;title&gt;nested circle!&lt;/title&gt;
+        &lt;/circle&gt;
+      &lt;/g&gt;
+      &lt;title&gt;main g element&lt;/title&gt;
+    &lt;/g&gt;
+    
+    &lt;!-- &lt;use&gt; element should return the first &lt;title&gt; element child if it exists --&gt;
+    &lt;use id=&quot;use_with_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;120&quot;&gt;
+      &lt;title&gt;use element!&lt;/title&gt;
+    &lt;/use&gt;
+    &lt;use id=&quot;use_without_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;240&quot;/&gt;
+  &lt;/svg&gt;
+
+  &lt;!-- Embedded SVG --&gt;
+  &lt;embed id=&quot;embedId&quot; src=&quot;resources/svg-tooltip.svg&quot;&gt;
+
+  &lt;!-- For logging the test results --&gt;      
+  &lt;pre id=&quot;log&quot;&gt;&lt;br&gt;&lt;/pre&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestssvghittestsvgstandalonetooltipexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/svg-standalone-tooltip-expected.txt (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/svg-standalone-tooltip-expected.txt                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/svg-standalone-tooltip-expected.txt        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,3 @@
</span><ins>+Verifying the SVG document:
+PASS
+
</ins></span></pre></div>
<a id="trunkLayoutTestssvghittestsvgstandalonetooltipsvg"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/svg/hittest/svg-standalone-tooltip.svg (0 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/svg/hittest/svg-standalone-tooltip.svg                                (rev 0)
+++ trunk/LayoutTests/svg/hittest/svg-standalone-tooltip.svg        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -0,0 +1,81 @@
</span><ins>+&lt;svg
+    xmlns=&quot;http://www.w3.org/2000/svg&quot;
+    xmlns:xlink=&quot;http://www.w3.org/1999/xlink&quot;
+    width=&quot;200&quot; height=&quot;400&quot;
+    id=&quot;main_svg&quot;&gt;
+
+  &lt;!--
+      REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+      https://bugs.webkit.org/show_bug.cgi?id=139690.
+
+      This test ensures that the tooltip text for SVG elements is calculated correctly.
+      It covers the stand-aline SVG case.
+  --&gt;
+    
+  &lt;script xlink:href=&quot;resources/svg-tooltip.js&quot;&gt;&lt;/script&gt;
+  &lt;script&gt;
+    function log(message)
+    {
+      var element = document.getElementById(&quot;log&quot;);
+      element.textContent = element.textContent + message + &quot;\n&quot;;
+    }
+  &lt;/script&gt;
+
+  &lt;!-- This title should only appear in the browser chrome and not as a tooltip --&gt;
+  &lt;title&gt;outermost svg&lt;/title&gt;
+  
+  &lt;defs&gt;
+    &lt;g id=&quot;shape&quot;&gt;
+      &lt;rect width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+      &lt;circle cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+        &lt;title&gt;def small circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;circle cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+        &lt;title&gt;def big circle!&lt;/title&gt;
+      &lt;/circle&gt;
+      &lt;g&gt;
+        &lt;rect x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+        &lt;circle cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+          &lt;title&gt;nested circle!&lt;/title&gt;
+        &lt;/circle&gt;
+      &lt;/g&gt;
+      &lt;title&gt;def g element!&lt;/title&gt;
+    &lt;/g&gt;
+  &lt;/defs&gt;
+  
+  &lt;g id=&quot;main_g&quot;&gt;
+    &lt;rect id=&quot;yellow_rect&quot; width=&quot;100&quot; height=&quot;100&quot; fill=&quot;yellow&quot;/&gt;
+    &lt;circle id=&quot;small_circle&quot; cx=&quot;10&quot; cy=&quot;10&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt; 
+      &lt;title&gt;small circle!&lt;/title&gt;
+    &lt;/circle&gt;
+    &lt;circle id=&quot;big_circle&quot; cx=&quot;80&quot; cy=&quot;80&quot; r=&quot;20&quot; fill=&quot;red&quot;&gt;
+      &lt;title&gt;big circle!&lt;/title&gt;
+    &lt;/circle&gt;
+    &lt;g id=&quot;sub_g&quot;&gt;
+      &lt;rect id=&quot;lime_rect&quot; x=&quot;20&quot; y=&quot;20&quot; width=&quot;40&quot; height=&quot;40&quot; fill=&quot;lime&quot;/&gt;
+      &lt;circle id=&quot;nested_circle&quot; cx=&quot;40&quot; cy=&quot;40&quot; r=&quot;10&quot; fill=&quot;red&quot;&gt;
+        &lt;title&gt;nested circle!&lt;/title&gt;
+      &lt;/circle&gt;
+    &lt;/g&gt;
+    &lt;title&gt;main g element&lt;/title&gt;
+  &lt;/g&gt;
+
+  &lt;!-- &lt;use&gt; element should return the first &lt;title&gt; element  child if it exists --&gt;
+  &lt;use id=&quot;use_with_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;120&quot;&gt;
+    &lt;title&gt;use element!&lt;/title&gt;
+  &lt;/use&gt;
+  &lt;use id=&quot;use_without_title&quot; xlink:href=&quot;#shape&quot; x=&quot;0&quot; y=&quot;240&quot;/&gt;
+
+  &lt;!-- For logging the test results --&gt;
+  &lt;foreignObject&gt;
+    &lt;pre id=&quot;log&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;/pre&gt;
+  &lt;/foreignObject&gt;
+  
+  &lt;script&gt;
+    if (window.testRunner) {
+      testRunner.dumpAsText();
+      log(&quot;Verifying the SVG document:&quot;);
+      log(verifyElementTreeToolTips(document.rootElement) ? &quot;PASS&quot; : &quot;&quot;);
+    }
+  &lt;/script&gt;
+&lt;/svg&gt;
</ins></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/ChangeLog        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -1,3 +1,50 @@
</span><ins>+2015-01-14  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
+
+        REGRESSION (r154769): Wrong &lt;title&gt; taken as a tooltip for SVG element.
+        https://bugs.webkit.org/show_bug.cgi?id=139690.
+
+        Reviewed by Daniel Bates.
+
+        Before r154769, we were calling Traversal&lt;SVGTitleElement&gt;::firstWithin(), which returns
+        the first immediate SVGTitleElement child. In r154769, Traversal&lt;SVGTitleElement&gt;::firstWithin()
+        was replaced by descendantsOfType&lt;SVGTitleElement&gt; which returns all descendants SVGTitleElements.
+        Then we were returning the first element of these descendants, which may not be an immediate
+        child of the element, as the title of the SVGElement. This was the reason of this bug. The
+        fix is to use childrenOfType&lt;SVGTitleElement&gt;() instead, which returns the immediate SVGTitleElement
+        children of an SVGElement.
+
+        Also we were not following exactly the specs for the rootmost SVG element's title value.
+        According to the W3C specs, for stand-alone SVG documents only, the rootmost SVG element
+        should not return a title. But we were not returning a title for the rootmost SVG element
+        always. The fix is to return a empty title for the rootmost SVG element only if topDocument()
+        of the element isSVGDocument().
+        
+        NOTE: The main SVG specs http://www.w3.org/TR/SVG/interact.html#hit-testing (W3C Recommendation
+        16 August 2011) and http://www.w3.org/TR/SVG/struct.html#DescriptionAndTitleElements (W3C
+        Recommendation 16 August 2011) do not say how the tooltip of an SVG element is calculated. But
+        the SVG tiny specs http://www.w3.org/TR/SVGTiny12/struct.html#uiTitleDescBehavior (W3C
+        Recommendation 22 December 2008) however explains well the tooltip calculation for the embedded
+        and the stand-alone SVG cases. And it seems this what we should rely on.
+
+        Test: svg/hittest/svg-standalone-tooltip.svg
+              svg/hittest/svg-embedded-tooltip.html
+
+        * WebCore.exp.in:
+        * rendering/HitTestResult.h:
+        Make HitTestResult::setInnerNode be WEBCORE_EXPORT
+        
+        * svg/SVGElement.cpp:
+        (WebCore::SVGElement::title):
+        Replace descendantsOfType&lt;SVGTitleElement&gt;() by childrenOfType&lt;SVGTitleElement&gt;().
+        Fix the title value of the rootmost SVG element.
+        
+        * testing/Internals.cpp:
+        (WebCore::Internals::toolTipFromElement):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Add a new internal function toolTipFromElement() which returns the tooltip text for a
+        given element.
+
</ins><span class="cx"> 2015-01-14  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Buildfix after r178434
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/WebCore.exp.in        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -312,6 +312,7 @@
</span><span class="cx"> __ZN7WebCore13HTTPHeaderMap6removeENS_14HTTPHeaderNameE
</span><span class="cx"> __ZN7WebCore13HTTPHeaderMapC1Ev
</span><span class="cx"> __ZN7WebCore13HTTPHeaderMapD1Ev
</span><ins>+__ZN7WebCore13HitTestResult12setInnerNodeEPNS_4NodeE
</ins><span class="cx"> __ZN7WebCore13HitTestResult22setToNonShadowAncestorEv
</span><span class="cx"> __ZN7WebCore13HitTestResultC1ERKNS_11LayoutPointE
</span><span class="cx"> __ZN7WebCore13HitTestResultC1ERKNS_11LayoutPointEjjjj
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingHitTestResulth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/HitTestResult.h (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/HitTestResult.h        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/rendering/HitTestResult.h        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -86,7 +86,7 @@
</span><span class="cx"> 
</span><span class="cx">     const HitTestLocation&amp; hitTestLocation() const { return m_hitTestLocation; }
</span><span class="cx"> 
</span><del>-    void setInnerNode(Node*);
</del><ins>+    WEBCORE_EXPORT void setInnerNode(Node*);
</ins><span class="cx">     void setInnerNonSharedNode(Node*);
</span><span class="cx">     void setURLElement(Element*);
</span><span class="cx">     void setScrollbar(Scrollbar*);
</span></span></pre></div>
<a id="trunkSourceWebCoresvgSVGElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/svg/SVGElement.cpp (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/svg/SVGElement.cpp        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/svg/SVGElement.cpp        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -954,9 +954,10 @@
</span><span class="cx"> 
</span><span class="cx"> String SVGElement::title() const
</span><span class="cx"> {
</span><del>-    // According to spec, we should not return titles when hovering over root &lt;svg&gt; elements (those
-    // &lt;title&gt; elements are the title of the document, not a tooltip) so we instantly return.
-    if (isOutermostSVGSVGElement())
</del><ins>+    // According to spec, for stand-alone SVG documents we should not return a title when
+    // hovering over the rootmost SVG element (the first &lt;title&gt; element is the title of
+    // the document, not a tooltip) so we instantly return.
+    if (isOutermostSVGSVGElement() &amp;&amp; document().topDocument().isSVGDocument())
</ins><span class="cx">         return String();
</span><span class="cx"> 
</span><span class="cx">     // Walk up the tree, to find out whether we're inside a &lt;use&gt; shadow tree, to find the right title.
</span><span class="lines">@@ -978,7 +979,7 @@
</span><span class="cx"> 
</span><span class="cx">     // If we aren't an instance in a &lt;use&gt; or the &lt;use&gt; title was not found, then find the first
</span><span class="cx">     // &lt;title&gt; child of this element.
</span><del>-    auto firstTitle = descendantsOfType&lt;SVGTitleElement&gt;(*this).first();
</del><ins>+    auto firstTitle = childrenOfType&lt;SVGTitleElement&gt;(*this).first();
</ins><span class="cx">     return firstTitle ? const_cast&lt;SVGTitleElement*&gt;(firstTitle)-&gt;innerText() : String();
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.cpp (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.cpp        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/testing/Internals.cpp        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -2099,6 +2099,18 @@
</span><span class="cx">     return WebCore::markerTextForListItem(element);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+String Internals::toolTipFromElement(Element* element, ExceptionCode&amp; ec) const
+{
+    if (!element) {
+        ec = INVALID_ACCESS_ERR;
+        return String();
+    }
+    HitTestResult result;
+    result.setInnerNode(element);
+    TextDirection dir;
+    return result.title(dir);
+}
+
</ins><span class="cx"> String Internals::getImageSourceURL(Element* element, ExceptionCode&amp; ec)
</span><span class="cx"> {
</span><span class="cx">     if (!element) {
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.h (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.h        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/testing/Internals.h        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -290,6 +290,8 @@
</span><span class="cx"> 
</span><span class="cx">     String markerTextForListItem(Element*, ExceptionCode&amp;);
</span><span class="cx"> 
</span><ins>+    String toolTipFromElement(Element*, ExceptionCode&amp;) const;
+
</ins><span class="cx">     void forceReload(bool endToEnd);
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(ENCRYPTED_MEDIA_V2)
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/Internals.idl (178458 => 178459)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/Internals.idl        2015-01-14 23:46:30 UTC (rev 178458)
+++ trunk/Source/WebCore/testing/Internals.idl        2015-01-14 23:50:57 UTC (rev 178459)
</span><span class="lines">@@ -256,6 +256,8 @@
</span><span class="cx"> 
</span><span class="cx">     [RaisesException] DOMString markerTextForListItem(Element element);
</span><span class="cx"> 
</span><ins>+    [RaisesException] DOMString toolTipFromElement(Element element);
+
</ins><span class="cx">     SerializedScriptValue deserializeBuffer(ArrayBuffer buffer);
</span><span class="cx">     ArrayBuffer serializeObject(SerializedScriptValue obj);
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>