<!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>[181511] trunk/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/181511">181511</a></dd>
<dt>Author</dt> <dd>mitz@apple.com</dd>
<dt>Date</dt> <dd>2015-03-15 12:30:09 -0700 (Sun, 15 Mar 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Presenting a modal sheet on top of a WKWebView causes it to lose focused, active state
https://bugs.webkit.org/show_bug.cgi?id=142702

Reviewed by Anders Carlsson.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView becomeFirstResponder]): Override to delegate first responder status to the
WKContentView if possible.
(-[WKWebView _retainActiveFocusedState]): New SPI that prevents view hierarchy changes from
affecting the active and focused state of the view. Increments a counter ivar and returns a
completion block (which callers must call when they’re done) that decrements it back.
* UIProcess/API/Cocoa/WKWebViewInternal.h: Declared new _activeFocusedStateRetainCount ivar
with @package access.
* UIProcess/API/Cocoa/WKWebViewPrivate.h: Declared new method.

* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::isViewWindowActive): Return true if active/focused state is to be
maintained despite not being visible.
(WebKit::PageClientImpl::isViewFocused): Return true if active/focused state is to be
maintained despite not being active.

* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView resignFirstResponder]): Don’t blur the assisted node if active/focused
state is to be maintained.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewInternalh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh">trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosPageClientImplIOSmm">trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm">trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/ChangeLog        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2015-03-15  Dan Bernstein  &lt;mitz@apple.com&gt;
+
+        [iOS] Presenting a modal sheet on top of a WKWebView causes it to lose focused, active state
+        https://bugs.webkit.org/show_bug.cgi?id=142702
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView becomeFirstResponder]): Override to delegate first responder status to the
+        WKContentView if possible.
+        (-[WKWebView _retainActiveFocusedState]): New SPI that prevents view hierarchy changes from
+        affecting the active and focused state of the view. Increments a counter ivar and returns a
+        completion block (which callers must call when they’re done) that decrements it back.
+        * UIProcess/API/Cocoa/WKWebViewInternal.h: Declared new _activeFocusedStateRetainCount ivar
+        with @package access.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h: Declared new method.
+
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::isViewWindowActive): Return true if active/focused state is to be
+        maintained despite not being visible.
+        (WebKit::PageClientImpl::isViewFocused): Return true if active/focused state is to be
+        maintained despite not being active.
+
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView resignFirstResponder]): Don’t blur the assisted node if active/focused
+        state is to be maintained.
+
</ins><span class="cx"> 2015-03-14  Simon Fraser  &lt;simon.fraser@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Clean up use of flags in localToContainer-type functions
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -650,6 +650,11 @@
</span><span class="cx">     return [_contentView browsingContextController];
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (BOOL)becomeFirstResponder
+{
+    return [_contentView becomeFirstResponder] || [super becomeFirstResponder];
+}
+
</ins><span class="cx"> static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
</span><span class="cx"> {
</span><span class="cx">     return CGFloor(input * deviceScaleFactor) / deviceScaleFactor;
</span><span class="lines">@@ -1770,6 +1775,17 @@
</span><span class="cx"> {
</span><span class="cx">     return webView-&gt;_overridesInterfaceOrientation ? deviceOrientationForUIInterfaceOrientation(webView-&gt;_interfaceOrientationOverride) : webView-&gt;_page-&gt;deviceOrientation();
</span><span class="cx"> }
</span><ins>+
+- (void (^)(void))_retainActiveFocusedState
+{
+    ++_activeFocusedStateRetainCount;
+
+    // FIXME: Use something like CompletionHandlerCallChecker to ensure that the returned block is called before it's released.
+    return [[[self] {
+        --_activeFocusedStateRetainCount;
+    } copy] autorelease];
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> - (void)_didRelaunchProcess
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewInternal.h        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -60,6 +60,10 @@
</span><span class="cx">     RetainPtr&lt;WKWebViewConfiguration&gt; _configuration;
</span><span class="cx"> 
</span><span class="cx">     RefPtr&lt;WebKit::WebPageProxy&gt; _page;
</span><ins>+
+#if PLATFORM(IOS)
+    NSUInteger _activeFocusedStateRetainCount;
+#endif
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoaWKWebViewPrivateh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -151,6 +151,10 @@
</span><span class="cx"> - (void)_killWebContentProcess;
</span><span class="cx"> - (void)_didRelaunchProcess;
</span><span class="cx"> 
</span><ins>+// Puts the view into a state where being taken out of the view hierarchy and resigning first responder
+// will not count as becoming inactive and unfocused. The returned block must be called to exit the state.
+- (void (^)(void))_retainActiveFocusedState WK_AVAILABLE(NA, WK_IOS_TBA);
+
</ins><span class="cx"> #else
</span><span class="cx"> @property (readonly) NSColor *_pageExtendedBackgroundColor;
</span><span class="cx"> @property (nonatomic, setter=_setDrawsTransparentBackground:) BOOL _drawsTransparentBackground;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosPageClientImplIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -171,13 +171,13 @@
</span><span class="cx"> bool PageClientImpl::isViewWindowActive()
</span><span class="cx"> {
</span><span class="cx">     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
</span><del>-    return isViewVisible();
</del><ins>+    return isViewVisible() || m_webView-&gt;_activeFocusedStateRetainCount;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool PageClientImpl::isViewFocused()
</span><span class="cx"> {
</span><span class="cx">     // FIXME: https://bugs.webkit.org/show_bug.cgi?id=133098
</span><del>-    return isViewWindowActive();
</del><ins>+    return isViewWindowActive() || m_webView-&gt;_activeFocusedStateRetainCount;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool PageClientImpl::isViewVisible()
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (181510 => 181511)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2015-03-15 19:13:36 UTC (rev 181510)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2015-03-15 19:30:09 UTC (rev 181511)
</span><span class="lines">@@ -517,9 +517,13 @@
</span><span class="cx"> {
</span><span class="cx">     // FIXME: Maybe we should call resignFirstResponder on the superclass
</span><span class="cx">     // and do nothing if the return value is NO.
</span><del>-    // We need to complete the editing operation before we blur the element.
-    [_inputPeripheral endEditing];
-    _page-&gt;blurAssistedNode();
</del><ins>+
+    if (!_webView-&gt;_activeFocusedStateRetainCount) {
+        // We need to complete the editing operation before we blur the element.
+        [_inputPeripheral endEditing];
+        _page-&gt;blurAssistedNode();
+    }
+
</ins><span class="cx">     [self _cancelInteraction];
</span><span class="cx">     [_webSelectionAssistant resignedFirstResponder];
</span><span class="cx">     [_textSelectionAssistant deactivateSelection];
</span></span></pre>
</div>
</div>

</body>
</html>