<!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>[169664] 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/169664">169664</a></dd>
<dt>Author</dt> <dd>enrica@apple.com</dd>
<dt>Date</dt> <dd>2014-06-06 15:06:25 -0700 (Fri, 06 Jun 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Adopt the new UIAlertController API to replace UIActionSheet.
https://bugs.webkit.org/show_bug.cgi?id=133582
&lt;rdar://problem/16845223&gt;

Reviewed by Joseph Pecoraro.

UIActionSheet is deprecated. We need to move out action sheets
implementation to UIAlertView.

* UIProcess/API/Cocoa/_WKElementAction.h:
* UIProcess/API/Cocoa/_WKElementAction.mm:
* UIProcess/ios/WKActionSheet.h:
* UIProcess/ios/WKActionSheet.mm:
(-[WKActionSheet presentSheetFromRect:]):
(-[WKActionSheet doneWithSheet]):
(-[WKActionSheet willRotate]):
(-[WKActionSheet updateSheetPosition]):
(-[WKActionSheet _didRotateAndLayout]):
(-[WKActionSheet didRotate]):
* UIProcess/ios/WKActionSheetAssistant.h:
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]):
(-[WKActionSheetAssistant showImageSheet]):
(-[WKActionSheetAssistant showLinkSheet]):
(-[WKActionSheetAssistant showDataDetectorsSheet]):
(-[WKActionSheetAssistant cleanupSheet]):
(-[WKActionSheetAssistant actionSheet:clickedButtonAtIndex:]): Deleted.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _longPressRecognized:]):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKElementActionh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKElementActionmm">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheeth">trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistanth">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.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 (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/ChangeLog        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-06-06  Enrica Casucci  &lt;enrica@apple.com&gt;
+
+        Adopt the new UIAlertController API to replace UIActionSheet.
+        https://bugs.webkit.org/show_bug.cgi?id=133582
+        &lt;rdar://problem/16845223&gt;
+
+        Reviewed by Joseph Pecoraro.
+
+        UIActionSheet is deprecated. We need to move out action sheets
+        implementation to UIAlertView.
+
+        * UIProcess/API/Cocoa/_WKElementAction.h:
+        * UIProcess/API/Cocoa/_WKElementAction.mm:
+        * UIProcess/ios/WKActionSheet.h:
+        * UIProcess/ios/WKActionSheet.mm:
+        (-[WKActionSheet presentSheetFromRect:]):
+        (-[WKActionSheet doneWithSheet]):
+        (-[WKActionSheet willRotate]):
+        (-[WKActionSheet updateSheetPosition]):
+        (-[WKActionSheet _didRotateAndLayout]):
+        (-[WKActionSheet didRotate]):
+        * UIProcess/ios/WKActionSheetAssistant.h:
+        * UIProcess/ios/WKActionSheetAssistant.mm:
+        (-[WKActionSheetAssistant _createSheetWithElementActions:showLinkTitle:]):
+        (-[WKActionSheetAssistant showImageSheet]):
+        (-[WKActionSheetAssistant showLinkSheet]):
+        (-[WKActionSheetAssistant showDataDetectorsSheet]):
+        (-[WKActionSheetAssistant cleanupSheet]):
+        (-[WKActionSheetAssistant actionSheet:clickedButtonAtIndex:]): Deleted.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _longPressRecognized:]):
+
</ins><span class="cx"> 2014-06-06  Gavin Barraclough  &lt;baraclough@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Should boost ChildProcesses on iOS
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKElementActionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.h        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -32,6 +32,7 @@
</span><span class="cx"> #import &lt;WebKit/_WKActivatedElementInfo.h&gt;
</span><span class="cx"> 
</span><span class="cx"> typedef void (^WKElementActionHandler)(_WKActivatedElementInfo *);
</span><ins>+typedef BOOL (^WKElementActionDismissalHandler)(void);
</ins><span class="cx"> 
</span><span class="cx"> typedef NS_ENUM(NSInteger, _WKElementActionType) {
</span><span class="cx">     _WKElementActionTypeCustom,
</span><span class="lines">@@ -51,6 +52,7 @@
</span><span class="cx"> 
</span><span class="cx"> @property (nonatomic, readonly) _WKElementActionType type;
</span><span class="cx"> @property (nonatomic, readonly) NSString* title;
</span><ins>+@property (nonatomic, copy) WKElementActionDismissalHandler dismissalHandler;
</ins><span class="cx"> 
</span><span class="cx"> @end
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKElementActionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKElementAction.mm        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx"> @implementation _WKElementAction  {
</span><span class="cx">     RetainPtr&lt;NSString&gt; _title;
</span><span class="cx">     WKElementActionHandlerInternal _actionHandler;
</span><ins>+    WKElementActionDismissalHandler _dismissalHandler;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (id)_initWithTitle:(NSString *)title actionHandler:(WKElementActionHandlerInternal)handler type:(_WKElementActionType)type
</span><span class="lines">@@ -63,6 +64,7 @@
</span><span class="cx"> - (void)dealloc
</span><span class="cx"> {
</span><span class="cx">     [_actionHandler release];
</span><ins>+    [_dismissalHandler release];
</ins><span class="cx"> 
</span><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheeth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.h        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -25,13 +25,13 @@
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> 
</span><del>-#import &lt;UIKit/UIActionSheet.h&gt;
</del><ins>+#import &lt;UIKit/UIAlertController.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIPopoverController.h&gt;
</span><span class="cx"> 
</span><span class="cx"> @protocol WKActionSheetDelegate;
</span><span class="cx"> @class WKContentView;
</span><span class="cx"> 
</span><del>-@interface WKActionSheet : UIActionSheet
</del><ins>+@interface WKActionSheet : UIAlertController
</ins><span class="cx"> 
</span><span class="cx"> @property (nonatomic, assign) id &lt;WKActionSheetDelegate&gt; sheetDelegate;
</span><span class="cx"> @property (nonatomic) UIPopoverArrowDirection arrowDirections;
</span><span class="lines">@@ -42,7 +42,7 @@
</span><span class="cx"> - (void)updateSheetPosition;
</span><span class="cx"> @end
</span><span class="cx"> 
</span><del>-@protocol WKActionSheetDelegate&lt;UIActionSheetDelegate&gt;
</del><ins>+@protocol WKActionSheetDelegate
</ins><span class="cx"> @required
</span><span class="cx"> - (UIView *)hostViewForSheet;
</span><span class="cx"> - (CGRect)initialPresentationRectInHostViewForSheet;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheet.mm        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -29,15 +29,18 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> 
</span><span class="cx"> #import &quot;WKContentViewInteraction.h&quot;
</span><del>-#import &lt;UIKit/UIActionSheet_Private.h&gt;
</del><ins>+#import &lt;UIKit/UIAlertController_Private.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIWindow_Private.h&gt;
</span><span class="cx"> 
</span><span class="cx"> @implementation WKActionSheet {
</span><span class="cx">     id &lt;WKActionSheetDelegate&gt; _sheetDelegate;
</span><del>-    id &lt;UIActionSheetDelegate&gt; _delegateWhileRotating;
</del><span class="cx">     WKContentView *_view;
</span><span class="cx">     UIPopoverArrowDirection _arrowDirections;
</span><span class="cx">     BOOL _isRotating;
</span><ins>+    BOOL _readyToPresentAfterRotation;
+
+    RetainPtr&lt;UIViewController&gt; _presentedViewControllerWhileRotating;
+    RetainPtr&lt;id &lt;UIPopoverPresentationControllerDelegate&gt;&gt; _popoverPresentationControllerDelegateWhileRotating;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (id)initWithView:(WKContentView *)view
</span><span class="lines">@@ -88,74 +91,140 @@
</span><span class="cx">     if (!view)
</span><span class="cx">         return NO;
</span><span class="cx"> 
</span><del>-    if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
-        [self presentFromRect:presentationRect
-                       inView:view
-                    direction:_arrowDirections
-    allowInteractionWithViews:nil
-              backgroundStyle:UIPopoverBackgroundStyleDefault
-                     animated:YES];
-    } else
-        [self showInView:view]; 
</del><ins>+    UIViewController *presentedViewController = _presentedViewControllerWhileRotating.get() ? _presentedViewControllerWhileRotating.get() : self;
+    presentedViewController.modalPresentationStyle = UIModalPresentationPopover;
</ins><span class="cx"> 
</span><ins>+    UIPopoverPresentationController *presentationController = presentedViewController.popoverPresentationController;
+    presentationController.sourceView = view;
+    presentationController.sourceRect = presentationRect;
+    presentationController.permittedArrowDirections = _arrowDirections;
+
+    if (_popoverPresentationControllerDelegateWhileRotating)
+        presentationController.delegate = _popoverPresentationControllerDelegateWhileRotating.get();
+
+    UIViewController *presentingViewController = [view.window rootViewController];
+    [presentingViewController presentViewController:presentedViewController animated:YES completion:NULL];
+
</ins><span class="cx">     return YES;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)doneWithSheet
</span><span class="cx"> {
</span><del>-    _delegateWhileRotating = nil;
</del><ins>+    _presentedViewControllerWhileRotating = nil;
+    _popoverPresentationControllerDelegateWhileRotating = nil;
</ins><span class="cx"> 
</span><del>-    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(didRotate) object:nil];
</del><ins>+    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_didRotateAndLayout) object:nil];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #pragma mark - Rotation handling code
</span><span class="cx"> 
</span><span class="cx"> - (void)willRotate
</span><span class="cx"> {
</span><del>-    ASSERT(UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);
</del><ins>+    // We want to save the view controller that is currently being presented to re-present it after rotation.
+    // Here are the various possible states that we have to handle:
+    // a) topViewController presenting ourselves (alertViewController) -&gt; nominal case.
+    //    There is no need to save the presented view controller, which is self.
+    // b) topViewController presenting ourselves presenting a content view controller -&gt;
+    //    This happens if one of the actions in the action sheet presented a different view controller inside the popover,
+    //    using a current context presentation. This is for example the case with the Data Detectors action &quot;Add to Contacts&quot;.
+    // c) topViewController presenting that content view controller directly.
+    //    This happens if we were in the (b) case and then rotated the device. Since we dismiss the popover during the
+    //    rotation, we take this opportunity to simplify the view controller hierarchy and simply re-present the content
+    //    view controller, without re-presenting the alert controller.
</ins><span class="cx"> 
</span><ins>+    UIView *view = [_sheetDelegate hostViewForSheet];
+    UIViewController *presentingViewController = view.window.rootViewController;
+
+    // topPresentedViewController is either self (cases (a) and (b) above) or an action's view controller
+    // (case (c) above).
+    UIViewController *topPresentedViewController = [presentingViewController presentedViewController];
+
+    // We only have something to do if we're showing a popover (that we have to reposition).
+    // Otherwise the default UIAlertController behaviour is enough.
+    if ([topPresentedViewController presentationController].presentationStyle != UIModalPresentationPopover)
+        return;
+
</ins><span class="cx">     if (_isRotating)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    // Clear the delegate so that the method:
-    // - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
-    // is not called when the ActionSheet is dismissed below. Delegate is re-instated after rotation.
-    _delegateWhileRotating = [self delegate];
-    self.delegate = nil;
</del><span class="cx">     _isRotating = YES;
</span><ins>+    _readyToPresentAfterRotation = NO;
</ins><span class="cx"> 
</span><del>-    [self dismissWithClickedButtonIndex:[self cancelButtonIndex] animated:NO];
</del><ins>+    UIViewController *presentedViewController = nil;
+    if ([self presentingViewController] != nil) {
+        // Handle cases (a) and (b) above (we (UIAlertController) are still in the presentation hierarchy).
+        // Save the view controller presented by one of the actions if there is one.
+        // (In the (a) case, presentedViewController will be nil).
+
+        presentedViewController = [self presentedViewController];
+    } else {
+        // Handle case (c) above.
+        // The view controller that we want to save is the top presented view controller, since we
+        // are not presenting it anymore.
+
+        presentedViewController = topPresentedViewController;
+    }
+
+    _presentedViewControllerWhileRotating = presentedViewController;
+
+    // Save the popover presentation controller's delegate, because in case (b) we're going to use
+    // a different popoverPresentationController after rotation to re-present the action view controller,
+    // and that action is still expecting delegate callbacks when the popover is dismissed.
+    _popoverPresentationControllerDelegateWhileRotating = [topPresentedViewController popoverPresentationController].delegate;
+
+    [presentingViewController dismissViewControllerAnimated:NO completion:^{
+        [self updateSheetPosition];
+    }];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)updateSheetPosition
</span><span class="cx"> {
</span><del>-    ASSERT(UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);
</del><ins>+    UIViewController *presentedViewController = _presentedViewControllerWhileRotating.get() ? _presentedViewControllerWhileRotating.get() : self;
</ins><span class="cx"> 
</span><del>-    if (!_isRotating)
</del><ins>+    // There are two asynchronous events which might trigger this call, and we have to wait for both of them before doing something.
+    // - One runloop iteration after rotation (to let the Web content re-layout, see below)
+    // - The completion of the view controller dismissal in willRotate.
+    // (We cannot present something again until the dismissal is done)
+
+    BOOL isBeingPresented = [presentedViewController presentingViewController] || [self presentingViewController];
+
+    if (!_isRotating || !_readyToPresentAfterRotation || isBeingPresented)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    _isRotating = NO;
-    
-    CGRect presentationRect = [_sheetDelegate presentationRectInHostViewForSheet];
-    if (!CGRectIsEmpty(presentationRect)) {
-        // Re-present the popover only if we are still pointing to content onscreen.
</del><ins>+    CGRect presentationRect = [_sheetDelegate initialPresentationRectInHostViewForSheet];
+    BOOL wasPresentedViewControllerModal = [_presentedViewControllerWhileRotating isModalInPopover];
+
+    if (!CGRectIsEmpty(presentationRect) || wasPresentedViewControllerModal) {
+        // Re-present the popover only if we are still pointing to content onscreen, or if we can't dismiss it without losing information.
+        // (if the view controller is modal)
+
</ins><span class="cx">         CGRect intersection = CGRectIntersection([[_sheetDelegate hostViewForSheet] bounds], presentationRect);
</span><del>-        if (!CGRectIsEmpty(intersection)) {
-            self.delegate = _delegateWhileRotating;
</del><ins>+        if (!CGRectIsEmpty(intersection))
</ins><span class="cx">             [self presentSheetFromRect:intersection];
</span><del>-            return;
-        }
</del><ins>+        else if (wasPresentedViewControllerModal)
+            [self presentSheet];
+
+        _presentedViewControllerWhileRotating = nil;
+        _popoverPresentationControllerDelegateWhileRotating = nil;
</ins><span class="cx">     }
</span><del>-    
-    // Cancel the sheet as there is either no view or the content has now moved off screen.
-    [_delegateWhileRotating actionSheet:self clickedButtonAtIndex:[self cancelButtonIndex]];
</del><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (void)_didRotateAndLayout
+{
+    _isRotating = NO;
+    _readyToPresentAfterRotation = YES;
+    [_view _updatePositionInformation];
+    [self updateSheetPosition];
+}
+
</ins><span class="cx"> - (void)didRotate
</span><span class="cx"> {
</span><del>-    ASSERT(UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone);
</del><ins>+    // Handle the rotation on the next run loop interation as this
+    // allows the onOrientationChange event to fire, and the element node may
+    // be removed.
+    // &lt;rdar://problem/9360929&gt; Should re-present popover after layout rather than on the next runloop
</ins><span class="cx"> 
</span><del>-    [_view _updatePositionInformation];
</del><ins>+    [self performSelector:@selector(_didRotateAndLayout) withObject:nil afterDelay:0];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistanth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.h        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -27,7 +27,7 @@
</span><span class="cx"> 
</span><span class="cx"> #import &quot;WKActionSheet.h&quot;
</span><span class="cx"> 
</span><del>-#import &lt;UIKit/UIActionSheet.h&gt;
</del><ins>+#import &lt;DataDetectorsUI/DDDetectionController.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIPopoverController.h&gt;
</span><span class="cx"> #import &lt;WebKit/WKDeclarationSpecifiers.h&gt;
</span><span class="cx"> #import &lt;wtf/RetainPtr.h&gt;
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx"> class WebPageProxy;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-@interface WKActionSheetAssistant : NSObject &lt;WKActionSheetDelegate&gt;
</del><ins>+@interface WKActionSheetAssistant : NSObject &lt;WKActionSheetDelegate, DDDetectionControllerInteractionDelegate&gt;
</ins><span class="cx"> 
</span><span class="cx"> - (id)initWithView:(WKContentView *)view;
</span><span class="cx"> - (void)showLinkSheet;
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -34,10 +34,11 @@
</span><span class="cx"> #import &quot;WebPageProxy.h&quot;
</span><span class="cx"> #import &quot;_WKActivatedElementInfoInternal.h&quot;
</span><span class="cx"> #import &quot;_WKElementActionInternal.h&quot;
</span><ins>+#import &lt;DataDetectorsUI/DDAction.h&gt;
</ins><span class="cx"> #import &lt;DataDetectorsUI/DDDetectionController.h&gt;
</span><span class="cx"> #import &lt;SafariServices/SSReadingList.h&gt;
</span><span class="cx"> #import &lt;TCC/TCC.h&gt;
</span><del>-#import &lt;UIKit/UIActionSheet_Private.h&gt;
</del><ins>+#import &lt;UIKit/UIAlertController_Private.h&gt;
</ins><span class="cx"> #import &lt;UIKit/UIView.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIViewController_Private.h&gt;
</span><span class="cx"> #import &lt;UIKit/UIWindow_Private.h&gt;
</span><span class="lines">@@ -66,7 +67,6 @@
</span><span class="cx"> @implementation WKActionSheetAssistant {
</span><span class="cx">     RetainPtr&lt;WKActionSheet&gt; _interactionSheet;
</span><span class="cx">     RetainPtr&lt;_WKActivatedElementInfo&gt; _elementInfo;
</span><del>-    RetainPtr&lt;NSArray&gt; _elementActions;
</del><span class="cx">     WKContentView *_view;
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -159,18 +159,6 @@
</span><span class="cx">     return [_interactionSheet presentSheetFromRect:presentationRect];
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
-{
-    ASSERT(actionSheet == _interactionSheet);
-    if (actionSheet != _interactionSheet)
-        return;
-
-    if (_elementActions &amp;&amp; buttonIndex &lt; (NSInteger)[_elementActions count])
-        [[_elementActions objectAtIndex:buttonIndex] _runActionWithElementInfo:_elementInfo.get() view:_view];
-
-    [self cleanupSheet];
-}
-
</del><span class="cx"> - (void)updateSheetPosition
</span><span class="cx"> {
</span><span class="cx">     [_interactionSheet updateSheetPosition];
</span><span class="lines">@@ -187,8 +175,7 @@
</span><span class="cx"> 
</span><span class="cx">     _interactionSheet = adoptNS([[WKActionSheet alloc] initWithView:_view]);
</span><span class="cx">     _interactionSheet.get().sheetDelegate = self;
</span><del>-    _interactionSheet.get().actionSheetStyle = UIActionSheetStyleAutomatic;
-    _interactionSheet.get().delegate = self;
</del><ins>+    _interactionSheet.get().preferredStyle = UIAlertControllerStyleActionSheet;
</ins><span class="cx"> 
</span><span class="cx">     NSString *titleString = nil;
</span><span class="cx">     BOOL titleIsURL = NO;
</span><span class="lines">@@ -204,18 +191,26 @@
</span><span class="cx"> 
</span><span class="cx">     if ([titleString length]) {
</span><span class="cx">         [_interactionSheet setTitle:titleString];
</span><del>-        if (titleIsURL) {
-            [[_interactionSheet _titleLabel] setLineBreakMode:NSLineBreakByTruncatingMiddle];
-            [_interactionSheet setTitleMaxLineCount:2];
-        } else
-            [[_interactionSheet _titleLabel] setLineBreakMode:NSLineBreakByTruncatingTail];
</del><ins>+        // We should configure the text field's line breaking mode correctly here, based on whether
+        // the title is an URL or not, but the appropriate UIAlertController SPIs are not available yet.
+        // The code that used to do this in the UIActionSheet world has been saved for reference in
+        // &lt;rdar://problem/17049781&gt; Configure the UIAlertController's title appropriately.
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _elementActions = adoptNS([actions copy]);
-    for (_WKElementAction *action in _elementActions.get())
-        [_interactionSheet addButtonWithTitle:[action title]];
</del><ins>+    for (_WKElementAction *action in actions) {
+        [_interactionSheet _addActionWithTitle:[action title] style:UIAlertActionStyleDefault handler:^{
+            [action _runActionWithElementInfo:_elementInfo.get() view:_view];
+            [self cleanupSheet];
+        } shouldDismissHandler:^{
+            return (BOOL)(!action.dismissalHandler || action.dismissalHandler());
+        }];
+    }
</ins><span class="cx"> 
</span><del>-    [_interactionSheet setCancelButtonIndex:[_interactionSheet addButtonWithTitle:WEB_UI_STRING_KEY(&quot;Cancel&quot;, &quot;Cancel button label in button bar&quot;, &quot;Title for Cancel button label in button bar&quot;)]];
</del><ins>+    [_interactionSheet addAction:[UIAlertAction actionWithTitle:WEB_UI_STRING_KEY(&quot;Cancel&quot;, &quot;Cancel button label in button bar&quot;, &quot;Title for Cancel button label in button bar&quot;)
+                                                          style:UIAlertActionStyleCancel
+                                                        handler:^(UIAlertAction *action) {
+                                                            [self cleanupSheet];
+                                                        }]];
</ins><span class="cx">     _view.page-&gt;startInteractionWithElementAtPosition(_view.positionInformation.point);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -252,7 +247,7 @@
</span><span class="cx">     _elementInfo = std::move(elementInfo);
</span><span class="cx"> 
</span><span class="cx">     if (![_interactionSheet presentSheet])
</span><del>-        [self actionSheet:_interactionSheet.get() clickedButtonAtIndex:[_interactionSheet cancelButtonIndex]];
</del><ins>+        [self cleanupSheet];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)showLinkSheet
</span><span class="lines">@@ -288,7 +283,7 @@
</span><span class="cx">     _elementInfo = std::move(elementInfo);
</span><span class="cx"> 
</span><span class="cx">     if (![_interactionSheet presentSheet])
</span><del>-        [self actionSheet:_interactionSheet.get() clickedButtonAtIndex:[_interactionSheet cancelButtonIndex]];
</del><ins>+        [self cleanupSheet];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)showDataDetectorsSheet
</span><span class="lines">@@ -308,33 +303,26 @@
</span><span class="cx">     NSMutableArray *elementActions = [NSMutableArray array];
</span><span class="cx">     for (NSUInteger actionNumber = 0; actionNumber &lt; [dataDetectorsActions count]; actionNumber++) {
</span><span class="cx">         DDAction *action = [dataDetectorsActions objectAtIndex:actionNumber];
</span><del>-        [elementActions addObject:[_WKElementAction elementActionWithTitle:[action localizedName] actionHandler:^(_WKActivatedElementInfo *actionInfo) {
-            UIPopoverController *popoverController = nil;
-            if (UI_USER_INTERFACE_IDIOM() != UIUserInterfaceIdiomPhone) {
-                [_interactionSheet setUserInteractionEnabled:NO];
-                // &lt;rdar://problem/11015751&gt; Action sheet becomes black if a button is clicked twice on iPad
-                // prevent any further tap on the sheet while DD is loading its view controller, otherwise UIActionSheet goes amok
-
-                popoverController = [_interactionSheet _relinquishPopoverController];
-            }
-
</del><ins>+        _WKElementAction *elementAction = [_WKElementAction elementActionWithTitle:[action localizedName] actionHandler:^(_WKActivatedElementInfo *actionInfo) {
</ins><span class="cx">             [[getDDDetectionControllerClass() sharedController] performAction:action
</span><del>-                                                                       inView:[self superviewForSheet]
-                                                        withPopoverController:popoverController
</del><ins>+                                                          fromAlertController:_interactionSheet.get()
</ins><span class="cx">                                                           interactionDelegate:self];
</span><del>-        }]];
</del><ins>+        }];
+        elementAction.dismissalHandler = ^{
+            return (BOOL)!action.hasUserInterface;
+        };
+        [elementActions addObject:elementAction];
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     [self _createSheetWithElementActions:elementActions showLinkTitle:NO];
</span><span class="cx">     if (!_interactionSheet)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    // The implicit second button is &quot;cancel&quot;, which is swallowed by the popover at presentation time.
-    if (_interactionSheet.get().numberOfButtons &lt;= 2)
</del><ins>+    if (elementActions.count &lt;= 1)
</ins><span class="cx">         _interactionSheet.get().arrowDirections = UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown;
</span><span class="cx"> 
</span><span class="cx">     if (![_interactionSheet presentSheet])
</span><del>-        [self actionSheet:_interactionSheet.get() clickedButtonAtIndex:[_interactionSheet cancelButtonIndex]];
</del><ins>+        [self cleanupSheet];
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> - (void)cleanupSheet
</span><span class="lines">@@ -343,11 +331,8 @@
</span><span class="cx"> 
</span><span class="cx">     [_interactionSheet doneWithSheet];
</span><span class="cx">     [_interactionSheet setSheetDelegate:nil];
</span><del>-    [_interactionSheet setDelegate:nil];
</del><span class="cx">     _interactionSheet = nil;
</span><span class="cx">     _elementInfo = nil;
</span><del>-
-    _elementActions = nil;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> @end
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKContentViewInteractionmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm (169663 => 169664)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-06-06 21:43:52 UTC (rev 169663)
+++ trunk/Source/WebKit2/UIProcess/ios/WKContentViewInteraction.mm        2014-06-06 22:06:25 UTC (rev 169664)
</span><span class="lines">@@ -757,8 +757,10 @@
</span><span class="cx"> 
</span><span class="cx">     if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
</span><span class="cx">         SEL action = [self _actionForLongPress];
</span><del>-        if (action)
</del><ins>+        if (action) {
</ins><span class="cx">             [self performSelector:action];
</span><ins>+            [self _cancelLongPressGestureRecognizer];
+        }
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>