<!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>[52494] 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/52494">52494</a></dd>
<dt>Author</dt> <dd>darin@apple.com</dd>
<dt>Date</dt> <dd>2009-12-22 11:26:29 -0800 (Tue, 22 Dec 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Reentrancy problem with selection in some edge cases.
https://bugs.webkit.org/show_bug.cgi?id=32842
rdar://problem/7449974

Reviewed by Sam Weinig.

WebCore: 

Test: fast/forms/selection-layout-reentry-strange-case.html

Move the selection display update process done in the
selectionLayoutChanged function into the layout timer
instead of doing it immediately when selection changes occur.

* editing/SelectionController.cpp:
(WebCore::SelectionController::SelectionController):
Initialize m_needsDisplayUpdate to false.
(WebCore::SelectionController::setSelection): Call
the new setNeedsDisplayUpdate function instead of the old
badly named Frame::selectionLayoutChanged function.
(WebCore::SelectionController::setNeedsDisplayUpdate):
Set m_needsDisplayUpdate. If it is just becoming true, then
call FrameView::scheduleRelayout.

* editing/SelectionController.h: Added setNeedsDisplayUpdate,
needsDisplayUpdate, and m_needsDisplayUpdate.

* page/Frame.cpp:
(WebCore::Frame::setCaretVisible): Call setNeedsDisplayUpdate.
(WebCore::Frame::selectionLayoutChanged): Call
setNeedsDisplayUpdate to set it to false, since this is the
function that performs &quot;selection display update&quot;. Later I want
to rename this function.

* page/FrameView.cpp:
(WebCore::FrameView::needsLayout): Add a new clause, since
we need a call to layout if needsDisplayUpdate is true.

LayoutTests: 

* fast/forms/selection-layout-reentry-strange-case-expected.txt: Added.
* fast/forms/selection-layout-reentry-strange-case.html: Added.

* platform/mac/accessibility/frame-with-title-expected.txt: Updated since
the number of layouts is now different.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsplatformmacaccessibilityframewithtitleexpectedtxt">trunk/LayoutTests/platform/mac/accessibility/frame-with-title-expected.txt</a></li>
<li><a href="#trunkWebCoreChangeLog">trunk/WebCore/ChangeLog</a></li>
<li><a href="#trunkWebCoreeditingSelectionControllercpp">trunk/WebCore/editing/SelectionController.cpp</a></li>
<li><a href="#trunkWebCoreeditingSelectionControllerh">trunk/WebCore/editing/SelectionController.h</a></li>
<li><a href="#trunkWebCorepageFramecpp">trunk/WebCore/page/Frame.cpp</a></li>
<li><a href="#trunkWebCorepageFrameViewcpp">trunk/WebCore/page/FrameView.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastformsselectionlayoutreentrystrangecaseexpectedtxt">trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastformsselectionlayoutreentrystrangecasehtml">trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/LayoutTests/ChangeLog        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2009-12-21  Darin Adler  &lt;darin@apple.com&gt;
+
+        Reviewed by Sam Weinig.
+
+        Reentrancy problem with selection in some edge cases.
+        https://bugs.webkit.org/show_bug.cgi?id=32842
+        rdar://problem/7449974
+
+        * fast/forms/selection-layout-reentry-strange-case-expected.txt: Added.
+        * fast/forms/selection-layout-reentry-strange-case.html: Added.
+
+        * platform/mac/accessibility/frame-with-title-expected.txt: Updated since
+        the number of layouts is now different.
+
</ins><span class="cx"> 2009-12-21  Csaba Osztrogon√°c  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [Qt] Skip layoutTestController.notifyDone() related test until fix.
</span></span></pre></div>
<a id="trunkLayoutTestsfastformsselectionlayoutreentrystrangecaseexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case-expected.txt (0 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case-expected.txt        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -0,0 +1,2 @@
</span><ins>+t down
+Yes, this is a strange test case. If you can see this and it did not crash, then all is well.
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastformsselectionlayoutreentrystrangecasehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case.html (0 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case.html                                (rev 0)
+++ trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case.html        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+&lt;textarea id=&quot;container&quot;&gt;si
+&lt;DIV abcdefgh_POSIT&gt;&lt;/DIV&gt;
+&lt;/textarea&gt;t down
+
+&lt;script&gt;
+    document.execCommand(&quot;FindString&quot;, true, &quot;sit&quot;);
+    document.execCommand(&quot;FindString&quot;, true, &quot;down&quot;);
+&lt;/script&gt;
+
+&lt;style&gt;&lt;/style&gt;
+
+&lt;script type=&quot;text/javascript&quot;&gt;
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    document.getElementById('container').innerHTML=&quot;&quot;;
+&lt;/script&gt;
+
+&lt;p&gt;Yes, this is a strange test case. If you can see this and it
+did not crash, then all is well.&lt;/p&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/forms/selection-layout-reentry-strange-case.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsplatformmacaccessibilityframewithtitleexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac/accessibility/frame-with-title-expected.txt (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac/accessibility/frame-with-title-expected.txt        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/LayoutTests/platform/mac/accessibility/frame-with-title-expected.txt        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -21,7 +21,7 @@
</span><span class="cx"> AXTopLevelUIElement: &lt;AXWebArea&gt;
</span><span class="cx"> AXLinkUIElements: &lt;array of size 0&gt;
</span><span class="cx"> AXLoaded: 1
</span><del>-AXLayoutCount: 3
</del><ins>+AXLayoutCount: 4
</ins><span class="cx"> AXURL: about:blank
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> AXTopLevelUIElement: &lt;AXWebArea&gt;
</span><span class="cx"> AXLinkUIElements: &lt;array of size 0&gt;
</span><span class="cx"> AXLoaded: 1
</span><del>-AXLayoutCount: 4
</del><ins>+AXLayoutCount: 5
</ins><span class="cx"> AXURL: about:blank
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/ChangeLog (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/ChangeLog        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/WebCore/ChangeLog        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2009-12-21  Darin Adler  &lt;darin@apple.com&gt;
+
+        Reviewed by Sam Weinig.
+
+        Reentrancy problem with selection in some edge cases.
+        https://bugs.webkit.org/show_bug.cgi?id=32842
+        rdar://problem/7449974
+
+        Test: fast/forms/selection-layout-reentry-strange-case.html
+
+        Move the selection display update process done in the
+        selectionLayoutChanged function into the layout timer
+        instead of doing it immediately when selection changes occur.
+
+        * editing/SelectionController.cpp:
+        (WebCore::SelectionController::SelectionController):
+        Initialize m_needsDisplayUpdate to false.
+        (WebCore::SelectionController::setSelection): Call
+        the new setNeedsDisplayUpdate function instead of the old
+        badly named Frame::selectionLayoutChanged function.
+        (WebCore::SelectionController::setNeedsDisplayUpdate):
+        Set m_needsDisplayUpdate. If it is just becoming true, then
+        call FrameView::scheduleRelayout.
+
+        * editing/SelectionController.h: Added setNeedsDisplayUpdate,
+        needsDisplayUpdate, and m_needsDisplayUpdate.
+
+        * page/Frame.cpp:
+        (WebCore::Frame::setCaretVisible): Call setNeedsDisplayUpdate.
+        (WebCore::Frame::selectionLayoutChanged): Call
+        setNeedsDisplayUpdate to set it to false, since this is the
+        function that performs &quot;selection display update&quot;. Later I want
+        to rename this function.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::needsLayout): Add a new clause, since
+        we need a call to layout if needsDisplayUpdate is true.
+
</ins><span class="cx"> 2009-12-22  Kwang Yul Seo  &lt;skyul@company100.net&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Darin Adler.
</span></span></pre></div>
<a id="trunkWebCoreeditingSelectionControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/editing/SelectionController.cpp (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/editing/SelectionController.cpp        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/WebCore/editing/SelectionController.cpp        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -70,6 +70,7 @@
</span><span class="cx">     , m_isDragCaretController(isDragCaretController)
</span><span class="cx">     , m_isCaretBlinkingSuspended(false)
</span><span class="cx">     , m_focused(frame &amp;&amp; frame-&gt;page() &amp;&amp; frame-&gt;page()-&gt;focusController()-&gt;focusedFrame() == frame)
</span><ins>+    , m_needsDisplayUpdate(false)
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -145,7 +146,8 @@
</span><span class="cx">     if (!s.isNone())
</span><span class="cx">         m_frame-&gt;setFocusedNodeIfNeeded();
</span><span class="cx">     
</span><del>-    m_frame-&gt;selectionLayoutChanged();
</del><ins>+    setNeedsDisplayUpdate();
+
</ins><span class="cx">     // Always clear the x position used for vertical arrow navigation.
</span><span class="cx">     // It will be restored by the vertical arrow navigation code if necessary.
</span><span class="cx">     m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation;
</span><span class="lines">@@ -1301,6 +1303,20 @@
</span><span class="cx">     return m_focused &amp;&amp; m_frame-&gt;page() &amp;&amp; m_frame-&gt;page()-&gt;focusController()-&gt;isActive();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void SelectionController::setNeedsDisplayUpdate(bool needsUpdate)
+{
+    if (m_needsDisplayUpdate == needsUpdate)
+        return;
+    m_needsDisplayUpdate = needsUpdate;
+
+    if (!m_needsDisplayUpdate)
+        return;
+    FrameView* view = m_frame-&gt;view();
+    if (!view)
+        return;
+    view-&gt;scheduleRelayout();
+}
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx"> 
</span><span class="cx"> void SelectionController::formatForDebugger(char* buffer, unsigned length) const
</span></span></pre></div>
<a id="trunkWebCoreeditingSelectionControllerh"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/editing/SelectionController.h (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/editing/SelectionController.h        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/WebCore/editing/SelectionController.h        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
</del><ins>+ * Copyright (C) 2004, 2009 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -124,6 +124,10 @@
</span><span class="cx">     bool isFocusedAndActive() const;
</span><span class="cx">     void pageActivationChanged();
</span><span class="cx"> 
</span><ins>+    // Selection display machinery
+    void setNeedsDisplayUpdate(bool = true);
+    bool needsDisplayUpdate() const { return m_needsDisplayUpdate; }
+
</ins><span class="cx"> #ifndef NDEBUG
</span><span class="cx">     void formatForDebugger(char* buffer, unsigned length) const;
</span><span class="cx">     void showTreeForThis() const;
</span><span class="lines">@@ -174,7 +178,7 @@
</span><span class="cx">     bool m_isDragCaretController : 1;
</span><span class="cx">     bool m_isCaretBlinkingSuspended : 1;
</span><span class="cx">     bool m_focused : 1;
</span><del>-
</del><ins>+    bool m_needsDisplayUpdate : 1;
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> inline bool operator==(const SelectionController&amp; a, const SelectionController&amp; b)
</span></span></pre></div>
<a id="trunkWebCorepageFramecpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/page/Frame.cpp (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/page/Frame.cpp        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/WebCore/page/Frame.cpp        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -563,7 +563,7 @@
</span><span class="cx">         return;
</span><span class="cx">     clearCaretRectIfNeeded();
</span><span class="cx">     m_caretVisible = flag;
</span><del>-    selectionLayoutChanged();
</del><ins>+    selection()-&gt;setNeedsDisplayUpdate();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Frame::clearCaretRectIfNeeded()
</span><span class="lines">@@ -630,6 +630,8 @@
</span><span class="cx"> 
</span><span class="cx"> void Frame::selectionLayoutChanged()
</span><span class="cx"> {
</span><ins>+    selection()-&gt;setNeedsDisplayUpdate(false);
+
</ins><span class="cx">     bool caretRectChanged = selection()-&gt;recomputeCaretRect();
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(TEXT_CARET)
</span></span></pre></div>
<a id="trunkWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/WebCore/page/FrameView.cpp (52493 => 52494)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/WebCore/page/FrameView.cpp        2009-12-22 18:58:34 UTC (rev 52493)
+++ trunk/WebCore/page/FrameView.cpp        2009-12-22 19:26:29 UTC (rev 52494)
</span><span class="lines">@@ -1198,7 +1198,8 @@
</span><span class="cx">         || m_layoutRoot
</span><span class="cx">         || (document &amp;&amp; document-&gt;childNeedsStyleRecalc()) // can occur when using WebKit ObjC interface
</span><span class="cx">         || m_frame-&gt;needsReapplyStyles()
</span><del>-        || (m_deferSetNeedsLayouts &amp;&amp; m_setNeedsLayoutWasDeferred);
</del><ins>+        || (m_deferSetNeedsLayouts &amp;&amp; m_setNeedsLayoutWasDeferred)
+        || m_frame-&gt;selection()-&gt;needsDisplayUpdate();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void FrameView::setNeedsLayout()
</span></span></pre>
</div>
</div>

</body>
</html>