<!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>[175856] branches/safari-600.3-branch/Source/WebKit2</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/175856">175856</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2014-11-10 23:55:09 -0800 (Mon, 10 Nov 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/175705">r175705</a>. rdar://problems/18892496</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari6003branchSourceWebKit2ChangeLog">branches/safari-600.3-branch/Source/WebKit2/ChangeLog</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2SharedTextIndicatorcpp">branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp</a></li>
<li><a href="#branchessafari6003branchSourceWebKit2SharedTextIndicatorh">branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari6003branchSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/ChangeLog (175855 => 175856)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/ChangeLog        2014-11-11 07:49:01 UTC (rev 175855)
+++ branches/safari-600.3-branch/Source/WebKit2/ChangeLog        2014-11-11 07:55:09 UTC (rev 175856)
</span><span class="lines">@@ -1,5 +1,55 @@
</span><span class="cx"> 2014-11-10  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r175705. &lt;rdar://problem/18892496&gt;
+
+    2014-11-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
+    
+            TextIndicatorWindow's bounce animation is lopsided when indicating two short lines of text
+            https://bugs.webkit.org/show_bug.cgi?id=138458
+    
+            Reviewed by Simon Fraser.
+    
+            Previously, the TextIndicator's frame() covered the entire selection highlight bounds.
+            This was undesirable in cases where the highlight included areas far outside the
+            bounds of the selected text, as the TextIndicatorWindow's 'bounce' animation
+            would be misaligned (centered on the highlight instead of on the text).
+    
+            * Shared/TextIndicator.cpp:
+            Get rid of the many-argument TextIndicator::create, because it was only used
+            internally, and have createWithSelectionInFrame make a ::Data instead.
+    
+            (WebKit::TextIndicator::createWithSelectionInFrame):
+            Compute and store the bounding rect of all of the selected text rects, and store
+            all of the text rects relative to that bounding rect instead of relative to the
+            selection highlight bounds. We do this because the selection highlight bounds
+            often includes area which is far outside of the text bounds (in the case of a
+            selection that spans multiple lines), and causes the text indicator bounce
+            animation to bounce in a lopsided manner.
+    
+            (WebKit::TextIndicator::TextIndicator):
+            Adjust to the rename of textRectsInSelectionRectCoordinates -&gt; textRectsInBoundingRectCoordinates.
+    
+            (WebKit::TextIndicator::frameRect):
+            Instead of the TextIndicator's frame being the selection highlight bounds,
+            it is now the bounds of all of the text rects.
+    
+            (WebKit::TextIndicator::draw):
+            Translate into the image by the difference between the selection highlight bounds
+            and the text bounding rect. This is necessary because the content image is still generated
+            covering the entire selection highlight bounds, but the text rects are in text-rect-bounds coordinates.
+    
+            (WebKit::TextIndicator::Data::encode):
+            (WebKit::TextIndicator::Data::decode):
+            Adjust to the rename of textRectsInSelectionRectCoordinates -&gt; textRectsInBoundingRectCoordinates.
+            Encode/decode textBoundingRectInWindowCoordinates.
+    
+            * Shared/TextIndicator.h:
+            (WebKit::TextIndicator::contentImage): Deleted.
+            Get rid of an unnecessary getter and constructor.
+    
+
+2014-11-10  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r175704. &lt;rdar://problem/18869036&gt;
</span><span class="cx"> 
</span><span class="cx">     2014-11-06  Tim Horton  &lt;timothy_horton@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2SharedTextIndicatorcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp (175855 => 175856)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp        2014-11-11 07:49:01 UTC (rev 175855)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.cpp        2014-11-11 07:55:09 UTC (rev 175856)
</span><span class="lines">@@ -149,17 +149,6 @@
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-PassRefPtr&lt;TextIndicator&gt; TextIndicator::create(const WebCore::FloatRect&amp; selectionRectInWindowCoordinates, const Vector&lt;WebCore::FloatRect&gt;&amp; textRectsInSelectionRectCoordinates, float contentImageScaleFactor, PassRefPtr&lt;ShareableBitmap&gt; contentImage)
-{
-    TextIndicator::Data data;
-    data.selectionRectInWindowCoordinates = selectionRectInWindowCoordinates;
-    data.textRectsInSelectionRectCoordinates = textRectsInSelectionRectCoordinates;
-    data.contentImageScaleFactor = contentImageScaleFactor;
-    data.contentImage = contentImage;
-
-    return TextIndicator::create(data);
-}
-
</del><span class="cx"> PassRefPtr&lt;TextIndicator&gt; TextIndicator::create(const TextIndicator::Data&amp; data)
</span><span class="cx"> {
</span><span class="cx">     return adoptRef(new TextIndicator(data));
</span><span class="lines">@@ -173,22 +162,38 @@
</span><span class="cx">     if (!indicatorBitmap)
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><del>-    // We want the selection rect in window coordinates.
</del><ins>+    // Store the selection rect in window coordinates, to be used subsequently
+    // to determine if the indicator and selection still precisely overlap.
</ins><span class="cx">     IntRect selectionRectInWindowCoordinates = coreFrame.view()-&gt;contentsToWindow(selectionRect);
</span><span class="cx"> 
</span><span class="cx">     Vector&lt;FloatRect&gt; textRects;
</span><span class="cx">     coreFrame.selection().getClippedVisibleTextRectangles(textRects);
</span><span class="cx"> 
</span><del>-    // We want the text rects in selection rect coordinates.
-    Vector&lt;FloatRect&gt; textRectsInSelectionRectCoordinates;
-
</del><ins>+    // The bounding rect of all the text rects can be different than the selection
+    // rect when the selection spans multiple lines; the indicator doesn't actually
+    // care where the selection highlight goes, just where the text actually is.
+    FloatRect textBoundingRectInWindowCoordinates;
+    Vector&lt;FloatRect&gt; textRectsInWindowCoordinates;
</ins><span class="cx">     for (const FloatRect&amp; textRect : textRects) {
</span><del>-        IntRect textRectInSelectionRectCoordinates = coreFrame.view()-&gt;contentsToWindow(enclosingIntRect(textRect));
-        textRectInSelectionRectCoordinates.move(-selectionRectInWindowCoordinates.x(), -selectionRectInWindowCoordinates.y());
-        textRectsInSelectionRectCoordinates.append(textRectInSelectionRectCoordinates);
</del><ins>+        FloatRect textRectInWindowCoordinates = coreFrame.view()-&gt;contentsToWindow(enclosingIntRect(textRect));
+        textRectsInWindowCoordinates.append(textRectInWindowCoordinates);
+        textBoundingRectInWindowCoordinates.unite(textRectInWindowCoordinates);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    return TextIndicator::create(selectionRectInWindowCoordinates, textRectsInSelectionRectCoordinates, frame.page()-&gt;deviceScaleFactor(), indicatorBitmap);
</del><ins>+    Vector&lt;FloatRect&gt; textRectsInBoundingRectCoordinates;
+    for (auto rect : textRectsInWindowCoordinates) {
+        rect.moveBy(-textBoundingRectInWindowCoordinates.location());
+        textRectsInBoundingRectCoordinates.append(rect);
+    }
+
+    TextIndicator::Data data;
+    data.selectionRectInWindowCoordinates = selectionRectInWindowCoordinates;
+    data.textBoundingRectInWindowCoordinates = textBoundingRectInWindowCoordinates;
+    data.textRectsInBoundingRectCoordinates = textRectsInBoundingRectCoordinates;
+    data.contentImageScaleFactor = frame.page()-&gt;deviceScaleFactor();
+    data.contentImage = indicatorBitmap;
+
+    return TextIndicator::create(data);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> TextIndicator::TextIndicator(const TextIndicator::Data&amp; data)
</span><span class="lines">@@ -196,9 +201,9 @@
</span><span class="cx"> {
</span><span class="cx">     ASSERT(m_data.contentImageScaleFactor != 1 || m_data.contentImage-&gt;size() == enclosingIntRect(m_data.selectionRectInWindowCoordinates).size());
</span><span class="cx"> 
</span><del>-    if (textIndicatorsForTextRectsOverlap(m_data.textRectsInSelectionRectCoordinates)) {
-        m_data.textRectsInSelectionRectCoordinates[0] = unionRect(m_data.textRectsInSelectionRectCoordinates);
-        m_data.textRectsInSelectionRectCoordinates.shrink(1);
</del><ins>+    if (textIndicatorsForTextRectsOverlap(m_data.textRectsInBoundingRectCoordinates)) {
+        m_data.textRectsInBoundingRectCoordinates[0] = unionRect(m_data.textRectsInBoundingRectCoordinates);
+        m_data.textRectsInBoundingRectCoordinates.shrink(1);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -208,7 +213,7 @@
</span><span class="cx"> 
</span><span class="cx"> FloatRect TextIndicator::frameRect() const
</span><span class="cx"> {
</span><del>-    return outsetIndicatorRectIncludingShadow(m_data.selectionRectInWindowCoordinates);
</del><ins>+    return outsetIndicatorRectIncludingShadow(m_data.textBoundingRectInWindowCoordinates);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
</span><span class="lines">@@ -255,16 +260,23 @@
</span><span class="cx">     return Color(0, 0, 0, 51);
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><del>-    
</del><ins>+
+void TextIndicator::drawContentImage(WebCore::GraphicsContext&amp; graphicsContext, WebCore::FloatRect textRect)
+{
+    FloatRect imageRect = textRect;
+    imageRect.move(m_data.textBoundingRectInWindowCoordinates.location() - m_data.selectionRectInWindowCoordinates.location());
+    m_data.contentImage-&gt;paint(graphicsContext, m_data.contentImageScaleFactor, enclosingIntRect(textRect).location(), enclosingIntRect(imageRect));
+}
+
</ins><span class="cx"> void TextIndicator::draw(GraphicsContext&amp; graphicsContext, const IntRect&amp; /*dirtyRect*/)
</span><span class="cx"> {
</span><span class="cx"> #if ENABLE(LEGACY_TEXT_INDICATOR_STYLE)
</span><del>-    for (size_t i = 0; i &lt; m_data.textRectsInSelectionRectCoordinates.size(); ++i) {
-        FloatRect textRect = m_data.textRectsInSelectionRectCoordinates[i];
-        textRect.move(leftBorderThickness, topBorderThickness);
</del><ins>+    for (auto&amp; textRect : m_data.textRectsInBoundingRectCoordinates) {
+        FloatRect borderedTextRect = textRect;
+        borderedTextRect.move(leftBorderThickness, topBorderThickness);
</ins><span class="cx"> 
</span><del>-        FloatRect outerPathRect = inflateRect(textRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder);
-        FloatRect innerPathRect = inflateRect(textRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder);
</del><ins>+        FloatRect outerPathRect = inflateRect(borderedTextRect, horizontalOutsetToCenterOfLightBorder, verticalOutsetToCenterOfLightBorder);
+        FloatRect innerPathRect = inflateRect(borderedTextRect, horizontalPaddingInsideLightBorder, verticalPaddingInsideLightBorder);
</ins><span class="cx"> 
</span><span class="cx">         {
</span><span class="cx">             GraphicsContextStateSaver stateSaver(graphicsContext);
</span><span class="lines">@@ -287,12 +299,11 @@
</span><span class="cx">             GraphicsContextStateSaver stateSaver(graphicsContext);
</span><span class="cx">             graphicsContext.translate(FloatSize(roundf(leftBorderThickness), roundf(topBorderThickness)));
</span><span class="cx"> 
</span><del>-            IntRect contentImageRect = enclosingIntRect(m_data.textRectsInSelectionRectCoordinates[i]);
-            m_data.contentImage-&gt;paint(graphicsContext, m_data.contentImageScaleFactor, contentImageRect.location(), contentImageRect);
</del><ins>+            drawContentImage(graphicsContext, textRect);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> #else
</span><del>-    for (auto&amp; textRect : m_data.textRectsInSelectionRectCoordinates) {
</del><ins>+    for (auto&amp; textRect : m_data.textRectsInBoundingRectCoordinates) {
</ins><span class="cx">         FloatRect blurRect = textRect;
</span><span class="cx">         blurRect.move(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder);
</span><span class="cx">         FloatRect outerPathRect = inflateRect(blurRect, flatStyleHorizontalBorder, flatStyleVerticalBorder);
</span><span class="lines">@@ -310,8 +321,7 @@
</span><span class="cx">             GraphicsContextStateSaver stateSaver(graphicsContext);
</span><span class="cx">             graphicsContext.translate(FloatSize(flatShadowBlurRadius + flatStyleHorizontalBorder, flatShadowBlurRadius + flatStyleVerticalBorder));
</span><span class="cx"> 
</span><del>-            IntRect contentImageRect = enclosingIntRect(textRect);
-            m_data.contentImage-&gt;paint(graphicsContext, m_data.contentImageScaleFactor, contentImageRect.location(), contentImageRect);
</del><ins>+            drawContentImage(graphicsContext, textRect);
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="lines">@@ -320,7 +330,8 @@
</span><span class="cx"> void TextIndicator::Data::encode(IPC::ArgumentEncoder&amp; encoder) const
</span><span class="cx"> {
</span><span class="cx">     encoder &lt;&lt; selectionRectInWindowCoordinates;
</span><del>-    encoder &lt;&lt; textRectsInSelectionRectCoordinates;
</del><ins>+    encoder &lt;&lt; textBoundingRectInWindowCoordinates;
+    encoder &lt;&lt; textRectsInBoundingRectCoordinates;
</ins><span class="cx">     encoder &lt;&lt; contentImageScaleFactor;
</span><span class="cx"> 
</span><span class="cx">     ShareableBitmap::Handle contentImageHandle;
</span><span class="lines">@@ -334,9 +345,12 @@
</span><span class="cx">     if (!decoder.decode(textIndicatorData.selectionRectInWindowCoordinates))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (!decoder.decode(textIndicatorData.textRectsInSelectionRectCoordinates))
</del><ins>+    if (!decoder.decode(textIndicatorData.textBoundingRectInWindowCoordinates))
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><ins>+    if (!decoder.decode(textIndicatorData.textRectsInBoundingRectCoordinates))
+        return false;
+
</ins><span class="cx">     if (!decoder.decode(textIndicatorData.contentImageScaleFactor))
</span><span class="cx">         return false;
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari6003branchSourceWebKit2SharedTextIndicatorh"></a>
<div class="modfile"><h4>Modified: branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h (175855 => 175856)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h        2014-11-11 07:49:01 UTC (rev 175855)
+++ branches/safari-600.3-branch/Source/WebKit2/Shared/TextIndicator.h        2014-11-11 07:55:09 UTC (rev 175856)
</span><span class="lines">@@ -49,7 +49,8 @@
</span><span class="cx"> public:
</span><span class="cx">     struct Data {
</span><span class="cx">         WebCore::FloatRect selectionRectInWindowCoordinates;
</span><del>-        Vector&lt;WebCore::FloatRect&gt; textRectsInSelectionRectCoordinates;
</del><ins>+        WebCore::FloatRect textBoundingRectInWindowCoordinates;
+        Vector&lt;WebCore::FloatRect&gt; textRectsInBoundingRectCoordinates;
</ins><span class="cx">         float contentImageScaleFactor;
</span><span class="cx">         RefPtr&lt;ShareableBitmap&gt; contentImage;
</span><span class="cx"> 
</span><span class="lines">@@ -57,7 +58,6 @@
</span><span class="cx">         static bool decode(IPC::ArgumentDecoder&amp;, Data&amp;);
</span><span class="cx">     };
</span><span class="cx"> 
</span><del>-    static PassRefPtr&lt;TextIndicator&gt; create(const WebCore::FloatRect&amp; selectionRectInWindowCoordinates, const Vector&lt;WebCore::FloatRect&gt;&amp; textRectsInSelectionCoordinates, float contentImageScaleFactor, PassRefPtr&lt;ShareableBitmap&gt; contentImage);
</del><span class="cx">     static PassRefPtr&lt;TextIndicator&gt; create(const TextIndicator::Data&amp;);
</span><span class="cx">     static PassRefPtr&lt;TextIndicator&gt; createWithSelectionInFrame(WebFrame&amp;);
</span><span class="cx"> 
</span><span class="lines">@@ -65,7 +65,6 @@
</span><span class="cx"> 
</span><span class="cx">     WebCore::FloatRect selectionRectInWindowCoordinates() const { return m_data.selectionRectInWindowCoordinates; }
</span><span class="cx">     WebCore::FloatRect frameRect() const;
</span><del>-    ShareableBitmap* contentImage() const { return m_data.contentImage.get(); }
</del><span class="cx">     Data data() const { return m_data; }
</span><span class="cx"> 
</span><span class="cx">     void draw(WebCore::GraphicsContext&amp;, const WebCore::IntRect&amp; dirtyRect);
</span><span class="lines">@@ -73,6 +72,8 @@
</span><span class="cx"> private:
</span><span class="cx">     TextIndicator(const TextIndicator::Data&amp;);
</span><span class="cx"> 
</span><ins>+    void drawContentImage(WebCore::GraphicsContext&amp;, WebCore::FloatRect textRect);
+
</ins><span class="cx">     Data m_data;
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>