<!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>[163476] trunk/Source</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/163476">163476</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2014-02-05 13:54:49 -0800 (Wed, 05 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>WK2: Caret, selections and autocorrection bubbles are incorrectly positioned when inside an iframe.
https://bugs.webkit.org/show_bug.cgi?id=128264
&lt;rdar://problem/15986954&gt;

Reviewed by Simon Fraser.

Source/WebCore: 

Adding new exported function.

* WebCore.exp.in:

Source/WebKit2: 

Everywhere we return rectangles to the UIProcess, we need to convert them
to root view coordinates. Also, we should allow hit testing to go into child
frames.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::editorState):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::selectWithGesture):
(WebKit::WebPage::updateSelectionWithTouches):
(WebKit::WebPage::convertSelectionRectsToRootView):
(WebKit::WebPage::requestAutocorrectionData):
(WebKit::WebPage::getPositionInformation):</pre>

<h3>Modified Paths</h3>
<ul>
<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="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebCore/ChangeLog        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2014-02-05  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        WK2: Caret, selections and autocorrection bubbles are incorrectly positioned when inside an iframe.
+        https://bugs.webkit.org/show_bug.cgi?id=128264
+        &lt;rdar://problem/15986954&gt;
+
+        Reviewed by Simon Fraser.
+
+        Adding new exported function.
+
+        * WebCore.exp.in:
+
</ins><span class="cx"> 2014-02-05  Antti Koivisto  &lt;antti@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ElementRuleCollector should not use StyleResolver::State
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -1434,6 +1434,7 @@
</span><span class="cx"> __ZNK7WebCore10ScrollView16windowToContentsERKNS_8IntPointE
</span><span class="cx"> __ZNK7WebCore10ScrollView18contentsToRootViewERKNS_7IntRectE
</span><span class="cx"> __ZNK7WebCore10ScrollView18contentsToRootViewERKNS_8IntPointE
</span><ins>+__ZNK7WebCore10ScrollView18rootViewToContentsERKNS_8IntPointE
</ins><span class="cx"> __ZNK7WebCore10ScrollView23rootViewToTotalContentsERKNS_8IntPointE
</span><span class="cx"> __ZNK7WebCore10ScrollView30scrollOffsetRelativeToDocumentEv
</span><span class="cx"> __ZNK7WebCore10StorageMap6lengthEv
</span></span></pre></div>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebKit2/ChangeLog        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -1,3 +1,25 @@
</span><ins>+2014-02-05  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        WK2: Caret, selections and autocorrection bubbles are incorrectly positioned when inside an iframe.
+        https://bugs.webkit.org/show_bug.cgi?id=128264
+        &lt;rdar://problem/15986954&gt;
+
+        Reviewed by Simon Fraser.
+
+        Everywhere we return rectangles to the UIProcess, we need to convert them
+        to root view coordinates. Also, we should allow hit testing to go into child
+        frames.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::editorState):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::selectWithGesture):
+        (WebKit::WebPage::updateSelectionWithTouches):
+        (WebKit::WebPage::convertSelectionRectsToRootView):
+        (WebKit::WebPage::requestAutocorrectionData):
+        (WebKit::WebPage::getPositionInformation):
+
</ins><span class="cx"> 2014-02-05  Dan Bernstein  &lt;mitz@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] WKRemoteObjectInterface fails with doubles, NSNull, and empty NSStrings
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -666,16 +666,18 @@
</span><span class="cx">             result.lastMarkedRect = result.firstMarkedRect;
</span><span class="cx">         result.markedText = plainText(compositionRange.get());
</span><span class="cx">     }
</span><ins>+    FrameView* view = frame.view();
</ins><span class="cx">     if (selection.isCaret()) {
</span><del>-        result.caretRectAtStart = frame.selection().absoluteCaretBounds();
</del><ins>+        result.caretRectAtStart = view-&gt;contentsToRootView(frame.selection().absoluteCaretBounds());
</ins><span class="cx">         result.caretRectAtEnd = result.caretRectAtStart;
</span><span class="cx">         if (m_shouldReturnWordAtSelection)
</span><span class="cx">             result.wordAtSelection = plainText(wordRangeFromPosition(selection.start()).get());
</span><span class="cx">     } else if (selection.isRange()) {
</span><del>-        result.caretRectAtStart = VisiblePosition(selection.start()).absoluteCaretBounds();
-        result.caretRectAtEnd = VisiblePosition(selection.end()).absoluteCaretBounds();
</del><ins>+        result.caretRectAtStart = view-&gt;contentsToRootView(VisiblePosition(selection.start()).absoluteCaretBounds());
+        result.caretRectAtEnd = view-&gt;contentsToRootView(VisiblePosition(selection.end()).absoluteCaretBounds());
</ins><span class="cx">         RefPtr&lt;Range&gt; selectedRange = selection.toNormalizedRange();
</span><span class="cx">         selectedRange-&gt;collectSelectionRects(result.selectionRects);
</span><ins>+        convertSelectionRectsToRootView(view, result.selectionRects);
</ins><span class="cx">         result.selectedTextLength = plainText(selectedRange.get(), TextIteratorDefaultBehavior, true).length();
</span><span class="cx">     }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -707,6 +707,9 @@
</span><span class="cx">     void didReceiveWebPageMessage(IPC::Connection*, IPC::MessageDecoder&amp;);
</span><span class="cx">     void didReceiveSyncWebPageMessage(IPC::Connection*, IPC::MessageDecoder&amp;, std::unique_ptr&lt;IPC::MessageEncoder&gt;&amp;);
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+    static void convertSelectionRectsToRootView(WebCore::FrameView*, Vector&lt;WebCore::SelectionRect&gt;&amp;);
+#endif
</ins><span class="cx"> #if !PLATFORM(MAC)
</span><span class="cx">     static const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (163475 => 163476)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-02-05 21:50:55 UTC (rev 163475)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-02-05 21:54:49 UTC (rev 163476)
</span><span class="lines">@@ -384,9 +384,9 @@
</span><span class="cx"> void WebPage::selectWithGesture(const IntPoint&amp; point, uint32_t granularity, uint32_t gestureType, uint32_t gestureState, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     Frame&amp; frame = m_page-&gt;focusController().focusedOrMainFrame();
</span><del>-    FloatPoint adjustedPoint(point);
</del><ins>+    IntPoint adjustedPoint(frame.view()-&gt;rootViewToContents(point));
</ins><span class="cx"> 
</span><del>-    IntPoint constrainedPoint = m_assistedNode ? constrainPoint(point, &amp;frame, m_assistedNode.get()) : point;
</del><ins>+    IntPoint constrainedPoint = m_assistedNode ? constrainPoint(adjustedPoint, &amp;frame, m_assistedNode.get()) : adjustedPoint;
</ins><span class="cx">     VisiblePosition position = frame.visiblePositionForPoint(constrainedPoint);
</span><span class="cx">     if (position.isNull()) {
</span><span class="cx">         send(Messages::WebPageProxy::GestureCallback(point, gestureType, gestureState, 0, callbackID));
</span><span class="lines">@@ -578,7 +578,7 @@
</span><span class="cx"> void WebPage::updateSelectionWithTouches(const IntPoint&amp; point, uint32_t touches, bool baseIsStart, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     Frame&amp; frame = m_page-&gt;focusController().focusedOrMainFrame();
</span><del>-    VisiblePosition position = frame.visiblePositionForPoint(point);
</del><ins>+    VisiblePosition position = frame.visiblePositionForPoint(frame.view()-&gt;rootViewToContents(point));
</ins><span class="cx">     if (position.isNull()) {
</span><span class="cx">         send(Messages::WebPageProxy::TouchesCallback(point, touches, callbackID));
</span><span class="cx">         return;
</span><span class="lines">@@ -649,6 +649,14 @@
</span><span class="cx">     frame.selection().setSelectedRange(wordRangeFromPosition(position).get(), position.affinity(), true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::convertSelectionRectsToRootView(FrameView* view, Vector&lt;SelectionRect&gt;&amp; selectionRects)
+{
+    for (size_t i = 0; i &lt; selectionRects.size(); ++i) {
+        SelectionRect&amp; currentRect = selectionRects[i];
+        currentRect.setRect(view-&gt;contentsToRootView(currentRect.rect()));
+    }
+}
+
</ins><span class="cx"> void WebPage::requestAutocorrectionData(const String&amp; textForAutocorrection, uint64_t callbackID)
</span><span class="cx"> {
</span><span class="cx">     RefPtr&lt;Range&gt; range;
</span><span class="lines">@@ -674,6 +682,7 @@
</span><span class="cx">     Vector&lt;FloatRect&gt; rectsForText;
</span><span class="cx">     rectsForText.resize(selectionRects.size());
</span><span class="cx"> 
</span><ins>+    convertSelectionRectsToRootView(frame.view(), selectionRects);
</ins><span class="cx">     for (size_t i = 0; i &lt; selectionRects.size(); i++)
</span><span class="cx">         rectsForText[i] = selectionRects[i].rect();
</span><span class="cx"> 
</span><span class="lines">@@ -852,13 +861,16 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (!elementIsLinkOrImage) {
</span><del>-        Frame&amp; frame = m_page-&gt;mainFrame();
-        hitNode = frame.eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent).innerNode();
-        if (hitNode-&gt;isTextNode()) {
-            VisiblePosition position = frame.visiblePositionForPoint(point);
</del><ins>+        HitTestResult result = m_page-&gt;mainFrame().eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent | HitTestRequest::AllowChildFrameContent);
+        hitNode = result.innerNode();
+        if (hitNode &amp;&amp; hitNode-&gt;isTextNode()) {
+            m_page-&gt;focusController().setFocusedFrame(result.innerNodeFrame());
+            FrameView* view = result.innerNodeFrame()-&gt;view();
+            VisiblePosition position = result.innerNodeFrame()-&gt;visiblePositionForPoint(view-&gt;rootViewToContents(point));
</ins><span class="cx">             RefPtr&lt;Range&gt; range = wordRangeFromPosition(position);
</span><span class="cx">             if (range)
</span><span class="cx">                 range-&gt;collectSelectionRects(info.selectionRects);
</span><ins>+            convertSelectionRectsToRootView(view, info.selectionRects);
</ins><span class="cx">         } else {
</span><span class="cx">             // FIXME: implement the logic for the block selection.
</span><span class="cx">         }
</span></span></pre>
</div>
</div>

</body>
</html>