[iOS DRT] Hook up uiController.zoomToScale() for DRT
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Aug 2016 23:58:45 +0000 (23:58 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Aug 2016 23:58:45 +0000 (23:58 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161173

Reviewed by Tim Horton.

Tools:

Make a UIWebScrollView subclass, DumpRenderTreeWebScrollView, which has an internal delegate to get
UIScrollView delegate callbacks. Store the zoomToScaleCompletionHandler on it.

UIScriptController::zoomToScale() has to bounce the zoom to the main thread (no poking UIKit from
the WebThread!), but queue up the callback first.

* DumpRenderTree/ios/DumpRenderTreeBrowserView.h:
* DumpRenderTree/ios/DumpRenderTreeBrowserView.mm:
(-[DumpRenderTreeWebScrollView initWithFrame:]):
(-[DumpRenderTreeWebScrollView dealloc]):
(-[DumpRenderTreeWebScrollView zoomToScale:animated:completionHandler:]):
(-[DumpRenderTreeWebScrollView completedZoomToScale]):
(-[DumpRenderTreeWebScrollViewDelegate initWithScrollView:]):
(-[DumpRenderTreeWebScrollViewDelegate viewForZoomingInScrollView:]): All UIScrollView delegates need to implement this.
(-[DumpRenderTreeWebScrollViewDelegate scrollViewDidEndZooming:withView:atScale:]):
* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::zoomToScale):
* DumpRenderTree/mac/DumpRenderTree.mm:
(createWebViewAndOffscreenWindow):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
(WTR::UIScriptController::context):

LayoutTests:

The one test in fast/zooming/ios works in DRT and WTR now.

* platform/ios-simulator-wk2/TestExpectations:
* platform/ios-simulator/TestExpectations:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@204945 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/ios-simulator-wk2/TestExpectations
LayoutTests/platform/ios-simulator/TestExpectations
Tools/ChangeLog
Tools/DumpRenderTree/ios/DumpRenderTreeBrowserView.h
Tools/DumpRenderTree/ios/DumpRenderTreeBrowserView.mm
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/DumpRenderTree/mac/DumpRenderTree.mm
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h

index 4110c51..418d687 100644 (file)
@@ -1,3 +1,15 @@
+2016-08-24  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS DRT] Hook up uiController.zoomToScale() for DRT
+        https://bugs.webkit.org/show_bug.cgi?id=161173
+
+        Reviewed by Tim Horton.
+        
+        The one test in fast/zooming/ios works in DRT and WTR now.
+
+        * platform/ios-simulator-wk2/TestExpectations:
+        * platform/ios-simulator/TestExpectations:
+
 2016-08-24  Jiewen Tan  <jiewen_tan@apple.com>
 
         Unreviewed, rebase iOS simulator WK1 fast/table tests
index 7af6ba6..ed05d7d 100644 (file)
@@ -8,7 +8,6 @@
 
 fast/scrolling/ios [ Pass ]
 fast/viewport/ios [ Pass ]
-fast/zooming/ios [ Pass ]
 
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End platform-specific directories.
index 2142209..1df5b59 100644 (file)
@@ -13,6 +13,7 @@ http/tests/quicklook [ Pass ]
 media/controls/ipad [ Pass ]
 
 fast/text-autosizing/ios [ Pass ]
+fast/zooming/ios [ Pass ]
 
 # <rdar://problem/22898927> Crashes in iWorkImport.framework
 quicklook/pages.html [ Pass Crash ]
index 1d17c3b..3b3e3b8 100644 (file)
@@ -1,3 +1,32 @@
+2016-08-24  Simon Fraser  <simon.fraser@apple.com>
+
+        [iOS DRT] Hook up uiController.zoomToScale() for DRT
+        https://bugs.webkit.org/show_bug.cgi?id=161173
+
+        Reviewed by Tim Horton.
+        
+        Make a UIWebScrollView subclass, DumpRenderTreeWebScrollView, which has an internal delegate to get
+        UIScrollView delegate callbacks. Store the zoomToScaleCompletionHandler on it.
+        
+        UIScriptController::zoomToScale() has to bounce the zoom to the main thread (no poking UIKit from
+        the WebThread!), but queue up the callback first.
+
+        * DumpRenderTree/ios/DumpRenderTreeBrowserView.h:
+        * DumpRenderTree/ios/DumpRenderTreeBrowserView.mm:
+        (-[DumpRenderTreeWebScrollView initWithFrame:]):
+        (-[DumpRenderTreeWebScrollView dealloc]):
+        (-[DumpRenderTreeWebScrollView zoomToScale:animated:completionHandler:]):
+        (-[DumpRenderTreeWebScrollView completedZoomToScale]):
+        (-[DumpRenderTreeWebScrollViewDelegate initWithScrollView:]):
+        (-[DumpRenderTreeWebScrollViewDelegate viewForZoomingInScrollView:]): All UIScrollView delegates need to implement this.
+        (-[DumpRenderTreeWebScrollViewDelegate scrollViewDidEndZooming:withView:atScale:]):
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::zoomToScale):
+        * DumpRenderTree/mac/DumpRenderTree.mm:
+        (createWebViewAndOffscreenWindow):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        (WTR::UIScriptController::context):
+
 2016-08-24  Ryan Haddad  <ryanhaddad@apple.com>
 
         Attempt to fix Windows build after r204918.
index b4cfd65..174b0c2 100644 (file)
 - (CGRect)documentVisibleRect;
 
 @end
+
+
+@class DumpRenderTreeWebScrollViewDelegate;
+
+@interface DumpRenderTreeWebScrollView : UIWebScrollView
+
+@property (nonatomic, retain) DumpRenderTreeWebScrollViewDelegate *scrollViewDelegate;
+
+@property (nonatomic, copy) void (^zoomToScaleCompletionHandler)(void);
+
+- (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler;
+
+@end
index 0a6ac3b..bdb19c5 100644 (file)
@@ -28,6 +28,8 @@
 
 #if PLATFORM(IOS)
 
+#import <WebCore/WebCoreThreadRun.h>
+#import <WebKit/WebCoreThread.h>
 #import <WebKit/WebView.h>
 
 @interface UIWebBrowserView (WebUIKitDelegate)
 
 @end
 
+@interface DumpRenderTreeWebScrollViewDelegate : NSObject <UIScrollViewDelegate> {
+    DumpRenderTreeWebScrollView *_scrollView;
+}
+- (instancetype)initWithScrollView:(DumpRenderTreeWebScrollView *)scrollView;
+@end
+
+
+@implementation DumpRenderTreeWebScrollView
+
+- (instancetype)initWithFrame:(CGRect)frame
+{
+    self = [super initWithFrame:frame];
+    if (!self)
+        return nil;
+    
+    self.scrollViewDelegate = [[[DumpRenderTreeWebScrollViewDelegate alloc] initWithScrollView:self] autorelease];
+    self.delegate = self.scrollViewDelegate;
+
+    return self;
+}
+
+- (void)dealloc
+{
+    self.scrollViewDelegate = nil;
+    [super dealloc];
+}
+
+- (void)zoomToScale:(double)scale animated:(BOOL)animated completionHandler:(void (^)(void))completionHandler
+{
+    ASSERT(!self.zoomToScaleCompletionHandler);
+    self.zoomToScaleCompletionHandler = completionHandler;
+
+    [self setZoomScale:scale animated:animated];
+}
+
+- (void)completedZoomToScale
+{
+    if (self.zoomToScaleCompletionHandler) {
+        auto completionHandlerCopy = Block_copy(self.zoomToScaleCompletionHandler);
+
+        WebThreadRun(^{
+            completionHandlerCopy();
+            Block_release(completionHandlerCopy);
+        });
+        self.zoomToScaleCompletionHandler = nullptr;
+    }
+}
+
+@end
+
+@implementation DumpRenderTreeWebScrollViewDelegate
+
+- (instancetype)initWithScrollView:(DumpRenderTreeWebScrollView *)scrollView
+{
+    self = [super init];
+    if (!self)
+        return nil;
+    
+    _scrollView = scrollView;
+    return self;
+}
+
+- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
+{
+    return [scrollView.subviews firstObject];
+}
+
+// UIScrollView delegate methods.
+- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale
+{
+    [_scrollView completedZoomToScale];
+}
+
+@end
+
 #endif // PLATFORM(IOS)
index 9799acf..380cc4b 100644 (file)
 #import "DumpRenderTreeBrowserView.h"
 #import "UIScriptContext.h"
 #import <WebCore/FloatRect.h>
+#import <wtf/MainThread.h>
 
 extern DumpRenderTreeBrowserView *gWebBrowserView;
-extern UIWebScrollView *gWebScrollView;
+extern DumpRenderTreeWebScrollView *gWebScrollView;
 
 namespace WTR {
 
@@ -50,6 +51,16 @@ void UIScriptController::doAsyncTask(JSValueRef callback)
 
 void UIScriptController::zoomToScale(double scale, JSValueRef callback)
 {
+    RefPtr<UIScriptController> protectedThis(this);
+    unsigned callbackID = strongThis->context()->prepareForAsyncTask(callback, CallbackTypeNonPersistent);
+
+    dispatch_async(dispatch_get_main_queue(), ^{
+        [gWebScrollView zoomToScale:scale animated:YES completionHandler:^{
+            if (!strongThis->context())
+                return;
+            strongThis->context()->asyncTaskComplete(callbackID);
+        }];
+    });
 }
 
 double UIScriptController::zoomScale() const
index 2d60e06..be2dd6c 100644 (file)
@@ -222,7 +222,7 @@ static WebHistoryItem *prevTestBFItem; // current b/f item at the end of the pre
 #if PLATFORM(IOS)
 const CGRect layoutTestViewportRect = { {0, 0}, {static_cast<CGFloat>(TestRunner::viewWidth), static_cast<CGFloat>(TestRunner::viewHeight)} };
 DumpRenderTreeBrowserView *gWebBrowserView = nil;
-UIWebScrollView *gWebScrollView = nil;
+DumpRenderTreeWebScrollView *gWebScrollView = nil;
 DumpRenderTreeWindow *gDrtWindow = nil;
 #endif
 
@@ -829,7 +829,7 @@ WebView *createWebViewAndOffscreenWindow()
     drtWindow.uiWindow = uiWindow;
     drtWindow.browserView = webBrowserView;
 
-    UIWebScrollView *scrollView = [[UIWebScrollView alloc] initWithFrame:layoutTestViewportRect];
+    DumpRenderTreeWebScrollView *scrollView = [[DumpRenderTreeWebScrollView alloc] initWithFrame:layoutTestViewportRect];
     [scrollView addSubview:webBrowserView];
 
     [viewController.view addSubview:scrollView];
index 27ef5d6..8463ac2 100644 (file)
@@ -100,6 +100,8 @@ public:
 
 private:
     UIScriptController(UIScriptContext&);
+    
+    UIScriptContext* context() { return m_context; }
 
     void platformSetDidStartFormControlInteractionCallback();
     void platformSetDidEndFormControlInteractionCallback();