Title: [210943] trunk/Source
Revision
210943
Author
aes...@apple.com
Date
2017-01-19 16:23:54 -0800 (Thu, 19 Jan 2017)

Log Message

Source/WebCore:
[iOS] Move the PDF password view into its own class for reuse
https://bugs.webkit.org/show_bug.cgi?id=167192

Reviewed by Tim Horton.

* English.lproj/Localizable.strings: Updated the failure alert strings to not be specific to PDFs.

Source/WebKit2:
[iOS] Move the PDF password view into its own class for possible reuse
https://bugs.webkit.org/show_bug.cgi?id=167192

Reviewed by Tim Horton.

* UIProcess/ios/WKPDFView.h: Stopped conforming to UIDocumentPasswordViewDelegate.
* UIProcess/ios/WKPDFView.mm: Changed _passwordView to a WKPasswordView.
(-[WKPDFView _passwordViewFrame]): Returns the frame to set on _passwordView.
(-[WKPDFView _updatePasswordEntryField]): Removed.
(-[WKPDFView _showPasswordEntryField]): Created a WKPasswordView, set a lambda on its
userDidEnterPassword property to do the work previously done in -_tryToUnlockWithPassword:,
and showed the password view.
(-[WKPDFView _keyboardDidShow:]): Moved to WKPasswordView.
(-[WKPDFView _hidePasswordEntryField]): Deleted. The userDidEnterPassword lambda now calls
-[WKPasswordView hide] when the document is unlocked.
(-[WKPDFView userDidEnterPassword:forPasswordView:]): Moved to WKPasswordView.
(-[WKPDFView didBeginEditingPassword:inView:]): Ditto.
(-[WKPDFView didEndEditingPassword:inView:]): Ditto.
(-[WKPDFView _didFailToUnlock]): Ditto.
(-[WKPDFView _tryToUnlockWithPassword:]): Moved into _passwordView's userDidEnterPassword lambda.
* UIProcess/ios/WKPasswordView.h: Added.
* UIProcess/ios/WKPasswordView.mm: Added.
(-[WKPasswordView initWithFrame:documentName:]): Created a UIDocumentPasswordView with
documentName, set self as its passwordDelegate, and added it as a subview.
(-[WKPasswordView layoutSubviews]): Updated _scrollView's contentSize if we are displaying
the view.
(-[WKPasswordView displayInContentView:]): Saved the scroll view's previous minimum/maximum
zoom scale and color, set new values for minimum/maximum zoom scale and color, and added
self as a subview of contentView.
(-[WKPasswordView hide]): Restored the saved minimum/maximum zoom scale and color on the
scroll view and removed self from its superview.
(-[WKPasswordView displayPasswordFailureAlert]): Displayed the alert previously shown by
-[WKPDFView _didFailToUnlock].
(-[WKPasswordView _keyboardDidShow:]): Moved from WKPDFView.
(-[WKPasswordView userDidEnterPassword:forPasswordView:]): Retained self and called the
_userDidEnterPassword block with the password.
(-[WKPasswordView didBeginEditingPassword:inView:]): Moved from WKPDFView.
(-[WKPasswordView didEndEditingPassword:inView:]): Ditto.
* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (210942 => 210943)


--- trunk/Source/WebCore/ChangeLog	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebCore/ChangeLog	2017-01-20 00:23:54 UTC (rev 210943)
@@ -1,3 +1,12 @@
+2017-01-19  Andy Estes  <aes...@apple.com>
+
+        [iOS] Move the PDF password view into its own class for reuse
+        https://bugs.webkit.org/show_bug.cgi?id=167192
+
+        Reviewed by Tim Horton.
+
+        * English.lproj/Localizable.strings: Updated the failure alert strings to not be specific to PDFs.
+
 2017-01-19  Chris Dumez  <cdu...@apple.com>
 
         Make sure HTML validation bubble gets dismissed when its associated element's frame gets detached

Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (210942 => 210943)


--- trunk/Source/WebCore/English.lproj/Localizable.strings	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings	2017-01-20 00:23:54 UTC (rev 210943)
@@ -403,8 +403,8 @@
 /* Option in segmented control for inserting a numbered list in text editing */
 "Numbered list" = "Numbered list";
 
-/* OK button label in PDF password failure alert */
-"OK (PDF password failure alert)" = "OK";
+/* OK button label in document password failure alert */
+"OK (document password failure alert)" = "OK";
 
 /* Menu item label for the track that represents disabling closed captions */
 "Off" = "Off";
@@ -661,7 +661,7 @@
 /* WebKitErrorGeolocationLocationUnknown description */
 "The current location cannot be found." = "The current location cannot be found.";
 
-/* PDF password failure alert message */
+/* document password failure alert message */
 "The document could not be opened with that password." = "The document could not be opened with that password.";
 
 /* WebKitErrorCannotFindPlugin description */

Modified: trunk/Source/WebKit2/ChangeLog (210942 => 210943)


--- trunk/Source/WebKit2/ChangeLog	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebKit2/ChangeLog	2017-01-20 00:23:54 UTC (rev 210943)
@@ -1,3 +1,45 @@
+2017-01-19  Andy Estes  <aes...@apple.com>
+
+        [iOS] Move the PDF password view into its own class for possible reuse
+        https://bugs.webkit.org/show_bug.cgi?id=167192
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/ios/WKPDFView.h: Stopped conforming to UIDocumentPasswordViewDelegate.
+        * UIProcess/ios/WKPDFView.mm: Changed _passwordView to a WKPasswordView.
+        (-[WKPDFView _passwordViewFrame]): Returns the frame to set on _passwordView.
+        (-[WKPDFView _updatePasswordEntryField]): Removed.
+        (-[WKPDFView _showPasswordEntryField]): Created a WKPasswordView, set a lambda on its
+        userDidEnterPassword property to do the work previously done in -_tryToUnlockWithPassword:,
+        and showed the password view.
+        (-[WKPDFView _keyboardDidShow:]): Moved to WKPasswordView.
+        (-[WKPDFView _hidePasswordEntryField]): Deleted. The userDidEnterPassword lambda now calls
+        -[WKPasswordView hide] when the document is unlocked.
+        (-[WKPDFView userDidEnterPassword:forPasswordView:]): Moved to WKPasswordView.
+        (-[WKPDFView didBeginEditingPassword:inView:]): Ditto.
+        (-[WKPDFView didEndEditingPassword:inView:]): Ditto.
+        (-[WKPDFView _didFailToUnlock]): Ditto.
+        (-[WKPDFView _tryToUnlockWithPassword:]): Moved into _passwordView's userDidEnterPassword lambda.
+        * UIProcess/ios/WKPasswordView.h: Added.
+        * UIProcess/ios/WKPasswordView.mm: Added.
+        (-[WKPasswordView initWithFrame:documentName:]): Created a UIDocumentPasswordView with
+        documentName, set self as its passwordDelegate, and added it as a subview.
+        (-[WKPasswordView layoutSubviews]): Updated _scrollView's contentSize if we are displaying
+        the view.
+        (-[WKPasswordView displayInContentView:]): Saved the scroll view's previous minimum/maximum
+        zoom scale and color, set new values for minimum/maximum zoom scale and color, and added
+        self as a subview of contentView.
+        (-[WKPasswordView hide]): Restored the saved minimum/maximum zoom scale and color on the
+        scroll view and removed self from its superview.
+        (-[WKPasswordView displayPasswordFailureAlert]): Displayed the alert previously shown by
+        -[WKPDFView _didFailToUnlock].
+        (-[WKPasswordView _keyboardDidShow:]): Moved from WKPDFView.
+        (-[WKPasswordView userDidEnterPassword:forPasswordView:]): Retained self and called the
+        _userDidEnterPassword block with the password.
+        (-[WKPasswordView didBeginEditingPassword:inView:]): Moved from WKPDFView.
+        (-[WKPasswordView didEndEditingPassword:inView:]): Ditto.
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2017-01-19  Chris Dumez  <cdu...@apple.com>
 
         Make sure HTML validation bubble gets dismissed when its associated element's frame gets detached

Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h (210942 => 210943)


--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h	2017-01-20 00:23:54 UTC (rev 210943)
@@ -26,11 +26,10 @@
 #if PLATFORM(IOS)
 
 #import "CorePDFSPI.h"
-#import "UIKitSPI.h"
 #import "WKActionSheetAssistant.h"
 #import "WKWebViewContentProvider.h"
 
-@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate, WKActionSheetAssistantDelegate, UIDocumentPasswordViewDelegate>
+@interface WKPDFView : UIView <WKWebViewContentProvider, UIPDFPageViewDelegate, UIPDFAnnotationControllerDelegate, WKActionSheetAssistantDelegate>
 
 @property (nonatomic, readonly) NSString *suggestedFilename;
 @property (nonatomic, readonly) CGPDFDocumentRef pdfDocument;

Modified: trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm (210942 => 210943)


--- trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPDFView.mm	2017-01-20 00:23:54 UTC (rev 210943)
@@ -35,6 +35,7 @@
 #import "SessionState.h"
 #import "UIKitSPI.h"
 #import "WKPDFPageNumberIndicator.h"
+#import "WKPasswordView.h"
 #import "WKWebViewInternal.h"
 #import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
@@ -54,8 +55,6 @@
 const CGFloat pdfMinimumZoomScale = 1;
 const CGFloat pdfMaximumZoomScale = 5;
 
-const CGFloat passwordEntryFieldPadding = 10;
-
 const float overdrawHeightMultiplier = 1.5;
 
 static const CGFloat smartMagnificationElementPadding = 0.05;
@@ -77,7 +76,7 @@
     RetainPtr<NSString> _suggestedFilename;
     RetainPtr<WKPDFPageNumberIndicator> _pageNumberIndicator;
 
-    RetainPtr<UIDocumentPasswordView> _passwordView;
+    RetainPtr<WKPasswordView> _passwordView;
 
     Vector<PDFPageInfo> _pages;
     unsigned _centerPageNumber;
@@ -207,7 +206,7 @@
 - (void)web_setMinimumSize:(CGSize)size
 {
     if (_passwordView) {
-        [self _updatePasswordEntryField];
+        [_passwordView setFrame:[self _passwordViewFrame]];
         return;
     }
 
@@ -747,108 +746,30 @@
 
 #pragma mark Password protection UI
 
-- (void)_updatePasswordEntryField
+- (CGRect)_passwordViewFrame
 {
-    [_passwordView setFrame:CGRectMake(0, 0, _webView.bounds.size.width, _webView.bounds.size.height)];
-    [_scrollView setContentSize:[_passwordView bounds].size];
+    CGRect webViewBounds = _webView.bounds;
+    return CGRectMake(0, 0, webViewBounds.size.width, webViewBounds.size.height);
 }
 
-- (void)_keyboardDidShow:(NSNotification *)notification
-{
-    UITextField *passwordField = [_passwordView passwordField];
-    if (!passwordField.isEditing)
-        return;
-
-    CGRect keyboardRect = [UIPeripheralHost visiblePeripheralFrame];
-    if (CGRectIsEmpty(keyboardRect))
-        return;
-
-    UIWindow *window = _scrollView.window;
-    keyboardRect = [window convertRect:keyboardRect fromWindow:nil];
-    keyboardRect = [_scrollView convertRect:keyboardRect fromView:window];
-
-    CGRect passwordFieldFrame = [passwordField convertRect:passwordField.bounds toView:_scrollView];
-
-    CGSize contentSize = [_passwordView bounds].size;
-    contentSize.height += CGRectGetHeight(keyboardRect);
-    [_scrollView setContentSize:contentSize];
-
-    if (CGRectIntersectsRect(passwordFieldFrame, keyboardRect)) {
-        CGFloat yDelta = CGRectGetMaxY(passwordFieldFrame) - CGRectGetMinY(keyboardRect);
-
-        CGPoint contentOffset = _scrollView.contentOffset;
-        contentOffset.y += yDelta + passwordEntryFieldPadding;
-
-        [_scrollView setContentOffset:contentOffset animated:YES];
-    }
-}
-
 - (void)_showPasswordEntryField
 {
-    [_scrollView setMinimumZoomScale:1];
-    [_scrollView setMaximumZoomScale:1];
-    [_scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
+    _passwordView = adoptNS([[WKPasswordView alloc] initWithFrame:[self _passwordViewFrame] documentName:_suggestedFilename.get()]);
 
-    _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:_suggestedFilename.get()]);
-    [_passwordView setPasswordDelegate:self];
+    [_passwordView setUserDidEnterPassword:[retainedSelf = retainPtr(self)](NSString *password) {
+        if (!CGPDFDocumentUnlockWithPassword(retainedSelf->_cgPDFDocument.get(), password.UTF8String)) {
+            [retainedSelf->_passwordView displayPasswordFailureAlert];
+            return;
+        }
 
-    [self _updatePasswordEntryField];
+        [retainedSelf->_passwordView hide];
+        retainedSelf->_passwordView = nil;
+        [retainedSelf _didLoadPDFDocument];
+    }];
 
-    [self addSubview:_passwordView.get()];
+    [_passwordView displayInContentView:self];
 }
 
-- (void)_hidePasswordEntryField
-{
-    [_passwordView removeFromSuperview];
-    _passwordView = nil;
-
-    [_scrollView setMinimumZoomScale:pdfMinimumZoomScale];
-    [_scrollView setMaximumZoomScale:pdfMaximumZoomScale];
-    [_scrollView setBackgroundColor:[UIColor grayColor]];
-}
-
-- (void)userDidEnterPassword:(NSString *)password forPasswordView:(UIDocumentPasswordView *)passwordView
-{
-    [self _tryToUnlockWithPassword:password];
-}
-
-- (void)didBeginEditingPassword:(UITextField *)passwordField inView:(UIDocumentPasswordView *)passwordView
-{
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
-}
-
-- (void)didEndEditingPassword:(UITextField *)passwordField inView:(UIDocumentPasswordView *)passwordView
-{
-    [_scrollView setContentSize:[_passwordView frame].size];
-    [_scrollView setContentOffset:CGPointMake(-_scrollView.contentInset.left, -_scrollView.contentInset.top) animated:YES];
-
-    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
-}
-
-- (void)_didFailToUnlock
-{
-    [[_passwordView passwordField] setText:@""];
-    UIAlertController* alert = [UIAlertController alertControllerWithTitle:WEB_UI_STRING("The document could not be opened with that password.", "PDF password failure alert message") message:@"" preferredStyle:UIAlertControllerStyleAlert];
-
-    UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY("OK", "OK (PDF password failure alert)", "OK button label in PDF password failure alert") style:UIAlertActionStyleDefault handler:[](UIAlertAction *) { }];
-    
-    [alert addAction:defaultAction];
-
-    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
-}
-
-- (BOOL)_tryToUnlockWithPassword:(NSString *)password
-{
-    if (CGPDFDocumentUnlockWithPassword(_cgPDFDocument.get(), [password UTF8String])) {
-        [self _hidePasswordEntryField];
-        [self _didLoadPDFDocument];
-        return YES;
-    }
-
-    [self _didFailToUnlock];
-    return NO;
-}
-
 - (void)willMoveToWindow:(UIWindow *)newWindow
 {
     if (newWindow)

Copied: trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.h (from rev 210942, trunk/Source/WebKit2/UIProcess/ios/WKPDFView.h) (0 => 210943)


--- trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.h	2017-01-20 00:23:54 UTC (rev 210943)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if PLATFORM(IOS)
+
+#import <UIKit/UIKit.h>
+
+@interface WKPasswordView : UIView
+
+- (instancetype)initWithFrame:(CGRect)frame documentName:(NSString *)documentName;
+- (void)displayInContentView:(UIView *)contentView;
+- (void)hide;
+- (void)displayPasswordFailureAlert;
+
+@property (nonatomic, copy) void (^userDidEnterPassword)(NSString *);
+
+@end
+
+#endif // PLATFORM(IOS)

Added: trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.mm (0 => 210943)


--- trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.mm	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/ios/WKPasswordView.mm	2017-01-20 00:23:54 UTC (rev 210943)
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "WKPasswordView.h"
+
+#if PLATFORM(IOS)
+
+#import "UIKitSPI.h"
+#import "WKContentView.h"
+#import "WKWebViewContentProvider.h"
+#import <WebCore/LocalizedStrings.h>
+#import <wtf/RetainPtr.h>
+#import <wtf/text/WTFString.h>
+
+const CGFloat passwordEntryFieldPadding = 10;
+
+@interface WKPasswordView () <UIDocumentPasswordViewDelegate>
+@end
+
+@implementation WKPasswordView {
+    RetainPtr<UIScrollView> _scrollView;
+    RetainPtr<UIDocumentPasswordView> _passwordView;
+    CGFloat _savedMinimumZoomScale;
+    CGFloat _savedMaximumZoomScale;
+    RetainPtr<UIColor> _savedBackgroundColor;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame documentName:(NSString *)documentName
+{
+    self = [super initWithFrame:frame];
+    if (!self)
+        return nil;
+
+    _passwordView = adoptNS([[UIDocumentPasswordView alloc] initWithDocumentName:documentName]);
+    [_passwordView setFrame:self.bounds];
+    [_passwordView setPasswordDelegate:self];
+    [_passwordView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
+
+    self.autoresizesSubviews = YES;
+    [self addSubview:_passwordView.get()];
+
+    return self;
+}
+
+- (void)layoutSubviews
+{
+    if (_scrollView)
+        [_scrollView setContentSize:self.frame.size];
+}
+
+- (void)displayInContentView:(UIView *)contentView
+{
+    ASSERT([contentView isKindOfClass:[WKContentView class]] || [contentView conformsToProtocol:@protocol(WKWebViewContentProvider)]);
+    ASSERT([contentView.superview isKindOfClass:[UIScrollView class]]);
+    _scrollView = (UIScrollView *)contentView.superview;
+
+    _savedMinimumZoomScale = [_scrollView minimumZoomScale];
+    _savedMaximumZoomScale = [_scrollView maximumZoomScale];
+    _savedBackgroundColor = [_scrollView backgroundColor];
+
+    [_scrollView setMinimumZoomScale:1];
+    [_scrollView setMaximumZoomScale:1];
+    [_scrollView setContentSize:self.frame.size];
+    [_scrollView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
+
+    [contentView addSubview:self];
+}
+
+- (void)hide
+{
+    [_scrollView setMinimumZoomScale:_savedMinimumZoomScale];
+    [_scrollView setMaximumZoomScale:_savedMaximumZoomScale];
+    [_scrollView setBackgroundColor:_savedBackgroundColor.get()];
+
+    _scrollView = nil;
+    _savedBackgroundColor = nil;
+
+    [self removeFromSuperview];
+}
+
+- (void)displayPasswordFailureAlert
+{
+    [[_passwordView passwordField] setText:@""];
+    UIAlertController *alert = [UIAlertController alertControllerWithTitle:WEB_UI_STRING("The document could not be opened with that password.", "document password failure alert message") message:@"" preferredStyle:UIAlertControllerStyleAlert];
+
+    UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:WEB_UI_STRING_KEY("OK", "OK (document password failure alert)", "OK button label in document password failure alert") style:UIAlertActionStyleDefault handler:[](UIAlertAction *) { }];
+
+    [alert addAction:defaultAction];
+
+    [self.window.rootViewController presentViewController:alert animated:YES completion:nil];
+}
+
+- (void)_keyboardDidShow:(NSNotification *)notification
+{
+    UITextField *passwordField = [_passwordView passwordField];
+    if (!passwordField.isEditing)
+        return;
+
+    CGRect keyboardRect = [UIPeripheralHost visiblePeripheralFrame];
+    if (CGRectIsEmpty(keyboardRect))
+        return;
+
+    UIWindow *window = [_scrollView window];
+    keyboardRect = [window convertRect:keyboardRect fromWindow:nil];
+    keyboardRect = [_scrollView convertRect:keyboardRect fromView:window];
+
+    CGRect passwordFieldFrame = [passwordField convertRect:passwordField.bounds toView:_scrollView.get()];
+
+    CGSize contentSize = [_passwordView bounds].size;
+    contentSize.height += CGRectGetHeight(keyboardRect);
+    [_scrollView setContentSize:contentSize];
+
+    if (CGRectIntersectsRect(passwordFieldFrame, keyboardRect)) {
+        CGFloat yDelta = CGRectGetMaxY(passwordFieldFrame) - CGRectGetMinY(keyboardRect);
+
+        CGPoint contentOffset = [_scrollView contentOffset];
+        contentOffset.y += yDelta + passwordEntryFieldPadding;
+
+        [_scrollView setContentOffset:contentOffset animated:YES];
+    }
+}
+
+#pragma mark UIDocumentPasswordViewDelegate
+
+- (void)userDidEnterPassword:(NSString *)password forPasswordView:(UIDocumentPasswordView *)passwordView
+{
+    auto protectedSelf = retainPtr(self);
+    if (_userDidEnterPassword)
+        _userDidEnterPassword(password);
+}
+
+- (void)didBeginEditingPassword:(UITextField *)passwordField inView:(UIDocumentPasswordView *)passwordView
+{
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
+}
+
+- (void)didEndEditingPassword:(UITextField *)passwordField inView:(UIDocumentPasswordView *)passwordView
+{
+    [_scrollView setContentSize:[_passwordView frame].size];
+
+    UIEdgeInsets contentInset = [_scrollView contentInset];
+    [_scrollView setContentOffset:CGPointMake(-contentInset.left, -contentInset.top) animated:YES];
+
+    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
+}
+
+@end
+
+#endif // PLATFORM(IOS)

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (210942 => 210943)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2017-01-19 23:43:51 UTC (rev 210942)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2017-01-20 00:23:54 UTC (rev 210943)
@@ -1343,6 +1343,8 @@
 		A118A9EF1907AD6F00F7C92B /* QuickLookDocumentData.h in Headers */ = {isa = PBXBuildFile; fileRef = A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */; };
 		A118A9F21908B8EA00F7C92B /* _WKNSFileManagerExtras.mm in Sources */ = {isa = PBXBuildFile; fileRef = A118A9F01908B8EA00F7C92B /* _WKNSFileManagerExtras.mm */; };
 		A118A9F31908B8EA00F7C92B /* _WKNSFileManagerExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = A118A9F11908B8EA00F7C92B /* _WKNSFileManagerExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		A15EEDE51E301CEE000069B0 /* WKPasswordView.mm in Sources */ = {isa = PBXBuildFile; fileRef = A15EEDE31E301CEE000069B0 /* WKPasswordView.mm */; };
+		A15EEDE61E301CEE000069B0 /* WKPasswordView.h in Headers */ = {isa = PBXBuildFile; fileRef = A15EEDE41E301CEE000069B0 /* WKPasswordView.h */; };
 		A182D5B41BE6BD250087A7CC /* AccessibilityIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = A182D5B21BE6BD250087A7CC /* AccessibilityIOS.mm */; };
 		A182D5B51BE6BD250087A7CC /* AccessibilityIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = A182D5B31BE6BD250087A7CC /* AccessibilityIOS.h */; };
 		A19DD3C01D07D16800AC823B /* _WKWebViewPrintFormatterInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = A19DD3BF1D07D16800AC823B /* _WKWebViewPrintFormatterInternal.h */; };
@@ -3500,6 +3502,8 @@
 		A118A9ED1907AD6F00F7C92B /* QuickLookDocumentData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = QuickLookDocumentData.h; path = ios/QuickLookDocumentData.h; sourceTree = "<group>"; };
 		A118A9F01908B8EA00F7C92B /* _WKNSFileManagerExtras.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = _WKNSFileManagerExtras.mm; sourceTree = "<group>"; };
 		A118A9F11908B8EA00F7C92B /* _WKNSFileManagerExtras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKNSFileManagerExtras.h; sourceTree = "<group>"; };
+		A15EEDE31E301CEE000069B0 /* WKPasswordView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKPasswordView.mm; path = ios/WKPasswordView.mm; sourceTree = "<group>"; };
+		A15EEDE41E301CEE000069B0 /* WKPasswordView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = WKPasswordView.h; path = ios/WKPasswordView.h; sourceTree = "<group>"; };
 		A182D5B21BE6BD250087A7CC /* AccessibilityIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AccessibilityIOS.mm; sourceTree = "<group>"; };
 		A182D5B31BE6BD250087A7CC /* AccessibilityIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AccessibilityIOS.h; sourceTree = "<group>"; };
 		A19DD3BF1D07D16800AC823B /* _WKWebViewPrintFormatterInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKWebViewPrintFormatterInternal.h; sourceTree = "<group>"; };
@@ -5161,6 +5165,8 @@
 				2D6AB540192B1C4A003A9FD1 /* WKPDFPageNumberIndicator.mm */,
 				2DA1E4FC18C02B6A00DBC929 /* WKPDFView.h */,
 				2DA1E4FD18C02B6A00DBC929 /* WKPDFView.mm */,
+				A15EEDE41E301CEE000069B0 /* WKPasswordView.h */,
+				A15EEDE31E301CEE000069B0 /* WKPasswordView.mm */,
 				0FCB4E4418BBE044000FCFC9 /* WKScrollView.h */,
 				0FCB4E4518BBE044000FCFC9 /* WKScrollView.mm */,
 				26F10BE619187E2E001D0E68 /* WKSyntheticClickTapGestureRecognizer.h */,
@@ -8038,6 +8044,7 @@
 				1AA3D75C1651B44F008713D0 /* RemoteLayerTreeHost.h in Headers */,
 				2DDE0AFA18298CC900F97EAA /* RemoteLayerTreePropertyApplier.h in Headers */,
 				0FF264A01A1FF9CC001FE759 /* RemoteLayerTreeScrollingPerformanceData.h in Headers */,
+				A15EEDE61E301CEE000069B0 /* WKPasswordView.h in Headers */,
 				1AF1AC6C1651759E00C17D7F /* RemoteLayerTreeTransaction.h in Headers */,
 				E1B78471163F24690007B692 /* RemoteNetworkingContext.h in Headers */,
 				1A5704FC1BE1751100874AF1 /* RemoteObjectInvocation.h in Headers */,
@@ -9925,6 +9932,7 @@
 				C54256B618BEC18C00DE4179 /* WKFormInputControl.mm in Sources */,
 				C54256B918BEC18C00DE4179 /* WKFormPopover.mm in Sources */,
 				C57193BE18C14A44002D0F12 /* WKFormSelectControl.mm in Sources */,
+				A15EEDE51E301CEE000069B0 /* WKPasswordView.mm in Sources */,
 				C55CB5B818C2A5D600CA81E1 /* WKFormSelectPicker.mm in Sources */,
 				C55CB5B718C269CF00CA81E1 /* WKFormSelectPopover.mm in Sources */,
 				BCE469591214EDF4000B98EB /* WKFormSubmissionListener.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to