<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - AX: WKContentView needs to implement UITextInput methods to make speak selection highlighting work"
   href="https://bugs.webkit.org/show_bug.cgi?id=166955#c9">Comment # 9</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - AX: WKContentView needs to implement UITextInput methods to make speak selection highlighting work"
   href="https://bugs.webkit.org/show_bug.cgi?id=166955">bug 166955</a>
              from <span class="vcard"><a class="email" href="mailto:rniwa&#64;webkit.org" title="Ryosuke Niwa &lt;rniwa&#64;webkit.org&gt;"> <span class="fn">Ryosuke Niwa</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=299261&amp;action=diff" name="attach_299261" title="patch">attachment 299261</a> <a href="attachment.cgi?id=299261&amp;action=edit" title="patch">[details]</a></span>
patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=299261&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=299261&amp;action=review</a>

<span class="quote">&gt; Source/WebCore/dom/Range.cpp:1269
&gt; -void Range::collectSelectionRects(Vector&lt;SelectionRect&gt;&amp; rects)
&gt; +void Range::collectSelectionRectsWithoutUnionInteriorLines(Vector&lt;SelectionRect&gt;&amp; rects, int&amp; maxLineNumber)</span >

Why isn't this function simply returning the maxLineNumber?

<span class="quote">&gt; Source/WebCore/dom/Range.cpp:1432
&gt; +    int maxLineNumber;
&gt; +    collectSelectionRectsWithoutUnionInteriorLines(rects, maxLineNumber);
&gt; +    const size_t numberOfRects = rects.size();
&gt; +    </span >

A pattern like this where we rely on a function being called to set a value to maxLineNumber is dangerous.
If someone adds an early return in collectSelectionRectsWithoutUnionInteriorLines, for example,
we may end up never initializing maxLineNumber.

It's better if collectSelectionRectsWithoutUnionInteriorLines returned this value
so that maxLineNumber is always assigned some value, and the code leaves no ambiguity in that regard.

<span class="quote">&gt; Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:1819
&gt; +    // Hit test the position make sure it's visible.</span >

*to* make sure.

<span class="quote">&gt; Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:1822
&gt; +    FloatRect rect = result.absoluteCaretBounds();
&gt; +    IntPoint center = IntPoint(rect.center());
&gt; +    result = frame.visiblePositionForPoint(center);</span >

Are you sure we really need to do this? This is a very funky operation.

<span class="quote">&gt; Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:1839
&gt; +    WebCore::TextGranularity webGranularity = static_cast&lt;WebCore::TextGranularity&gt;(granularity);</span >

&quot;web&quot; prefix is usually used for WK/WebView types, not WebCore types.

<span class="quote">&gt; Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:1925
&gt; +        // Try to search for a word range within the selection range that matches the passed in text.
&gt; +        if (RefPtr&lt;Range&gt; wordRange = wordRangeForPositionMatchesText(startPosition, range, text, selectionRange))
&gt; +            range = wordRange;</span >

Why can't we just use findPlainText instead? That'd just return a range that includes the text inside a given range.

<span class="quote">&gt; Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm:1940
&gt; +    if (!resultRange || resultRange-&gt;collapsed())
&gt; +        resultRange = range;</span >

Why do we want to do this?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>