Title: [264637] trunk/Source
Revision
264637
Author
[email protected]
Date
2020-07-20 16:48:39 -0700 (Mon, 20 Jul 2020)

Log Message

Add OK button to Date/Time form controls.
https://bugs.webkit.org/show_bug.cgi?id=214195
Source/WebCore:

Reviewed by Darin Adler.

* en.lproj/Localizable.strings:

Source/WebKit:

<rdar://problem/65006000>

Reviewed by Darin Adler.

Add 'OK' button to add clarity to UI, and increase the default size of the control to
ensure space for both buttons. Also fixed a crash that happened when closing the control before
the animation completed.

* UIProcess/ios/forms/WKDateTimeInputControl.mm:
(-[WKDateTimeContextMenuViewController preferredContentSize]):
(-[WKDateTimePicker contextMenuInteraction:configurationForMenuAtLocation:]):
(-[WKDateTimePicker contextMenuInteraction:willDisplayMenuForConfiguration:animator:]):
(-[WKDateTimePicker contextMenuInteraction:willEndForConfiguration:animator:]):
(-[WKDateTimePicker ok:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (264636 => 264637)


--- trunk/Source/WebCore/ChangeLog	2020-07-20 23:43:55 UTC (rev 264636)
+++ trunk/Source/WebCore/ChangeLog	2020-07-20 23:48:39 UTC (rev 264637)
@@ -1,3 +1,12 @@
+2020-07-20  Megan Gardner  <[email protected]>
+
+        Add OK button to Date/Time form controls.
+        https://bugs.webkit.org/show_bug.cgi?id=214195
+
+        Reviewed by Darin Adler.
+
+        * en.lproj/Localizable.strings:
+
 2020-07-20  Geoffrey Garen  <[email protected]>
 
         REGRESSION (r264242): [ macOS ] imported/w3c/web-platform-tests/wasm/jsapi/constructor/instantiate.any.html is a flaky crash

Modified: trunk/Source/WebCore/en.lproj/Localizable.strings (264636 => 264637)


--- trunk/Source/WebCore/en.lproj/Localizable.strings	2020-07-20 23:43:55 UTC (rev 264636)
+++ trunk/Source/WebCore/en.lproj/Localizable.strings	2020-07-20 23:48:39 UTC (rev 264637)
@@ -544,6 +544,9 @@
 /* OK button label in document password failure alert */
 "OK (document password failure alert)" = "OK";
 
+/* Title of the OK button in date/time form controls. */
+"OK (OK button title in date/time picker)" = "OK";
+
 /* Menu item label for the track that represents disabling closed captions */
 "Off" = "Off";
 

Modified: trunk/Source/WebKit/ChangeLog (264636 => 264637)


--- trunk/Source/WebKit/ChangeLog	2020-07-20 23:43:55 UTC (rev 264636)
+++ trunk/Source/WebKit/ChangeLog	2020-07-20 23:48:39 UTC (rev 264637)
@@ -1,3 +1,22 @@
+2020-07-20  Megan Gardner  <[email protected]>
+
+        Add OK button to Date/Time form controls.
+        https://bugs.webkit.org/show_bug.cgi?id=214195
+        <rdar://problem/65006000>
+
+        Reviewed by Darin Adler.
+
+        Add 'OK' button to add clarity to UI, and increase the default size of the control to
+        ensure space for both buttons. Also fixed a crash that happened when closing the control before
+        the animation completed.
+
+        * UIProcess/ios/forms/WKDateTimeInputControl.mm:
+        (-[WKDateTimeContextMenuViewController preferredContentSize]):
+        (-[WKDateTimePicker contextMenuInteraction:configurationForMenuAtLocation:]):
+        (-[WKDateTimePicker contextMenuInteraction:willDisplayMenuForConfiguration:animator:]):
+        (-[WKDateTimePicker contextMenuInteraction:willEndForConfiguration:animator:]):
+        (-[WKDateTimePicker ok:]):
+
 2020-07-20  Adrian Perez de Castro  <[email protected]>
 
         Non unified build fixes, midsummer 2020 edition

Modified: trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h (264636 => 264637)


--- trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-07-20 23:43:55 UTC (rev 264636)
+++ trunk/Source/WebKit/Platform/spi/ios/UIKitSPI.h	2020-07-20 23:48:39 UTC (rev 264637)
@@ -1177,6 +1177,7 @@
 @interface UIContextMenuInteraction ()
 @property (nonatomic, readonly) UIGestureRecognizer *gestureRecognizerForFailureRelationships;
 - (void)_presentMenuAtLocation:(CGPoint)location;
+- (void)dismissMenu;
 @end
 
 #endif // USE(UICONTEXTMENU)

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKDateTimeInputControl.mm (264636 => 264637)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKDateTimeInputControl.mm	2020-07-20 23:43:55 UTC (rev 264636)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKDateTimeInputControl.mm	2020-07-20 23:48:39 UTC (rev 264637)
@@ -36,6 +36,7 @@
 #import <UIKit/UIBarButtonItem.h>
 #import <UIKit/UIDatePicker.h>
 #import <WebCore/LocalizedStrings.h>
+#import <algorithm>
 #import <wtf/RetainPtr.h>
 
 using namespace WebKit;
@@ -76,7 +77,7 @@
 - (CGSize)preferredContentSize
 {
     // FIXME: Workaround, should be able to be readdressed after <rdar://problem/64143534>
-    UIView *view = self.view;
+    UIView *view = self.view.subviews[0];
     if (UIEdgeInsetsEqualToEdgeInsets(view.layoutMargins, UIEdgeInsetsZero)) {
         view.translatesAutoresizingMaskIntoConstraints = NO;
         [view layoutIfNeeded];
@@ -83,8 +84,10 @@
         view.translatesAutoresizingMaskIntoConstraints = YES;
         view.layoutMargins = UIEdgeInsetsMake(16, 16, 16, 16);
     }
-
-    return [view systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
+    auto size = [view systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
+    
+    size.width = std::max<CGFloat>(size.width, 250.0);
+    return size;
 }
 
 @end
@@ -168,16 +171,31 @@
         [_viewController setView:nil];
         _viewController = adoptNS([[WKDateTimeContextMenuViewController alloc] init]);
         RetainPtr<UINavigationController> navigationController = adoptNS([[UINavigationController alloc] initWithRootViewController:_viewController.get()]);
+        
         NSString *resetString = WEB_UI_STRING_KEY("Reset", "Reset Button Date/Time Context Menu", "Reset button in date input context menu");
+        NSString *okString = WEB_UI_STRING_KEY("OK", "OK (OK button title in date/time picker)", "Title of the OK button in date/time form controls.");
 
+        RetainPtr<UIBarButtonItem> okBarButton = adoptNS([[UIBarButtonItem alloc] initWithTitle:okString style:UIBarButtonItemStyleDone target:self action:@selector(ok:)]);
         RetainPtr<UIBarButtonItem> blankBarButton = adoptNS([[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]);
         RetainPtr<UIBarButtonItem> resetBarButton = adoptNS([[UIBarButtonItem alloc] initWithTitle:resetString style:UIBarButtonItemStylePlain target:self action:@selector(reset:)]);
         
-        [_viewController setToolbarItems:@[blankBarButton.get(), resetBarButton.get()]];
+        [_viewController setToolbarItems:@[resetBarButton.get(), blankBarButton.get(), okBarButton.get()]];
         [navigationController setToolbarHidden:NO];
+        
+        auto centeringView = adoptNS([[UIView alloc] init]);
+        
+        [centeringView addSubview:_datePicker.get()];
+        
+        _datePicker.get().translatesAutoresizingMaskIntoConstraints = NO;
+        auto widthConstraint = [[centeringView widthAnchor] constraintGreaterThanOrEqualToAnchor:[_datePicker widthAnchor]];
+        auto heightConstraint = [[centeringView heightAnchor] constraintEqualToAnchor:[_datePicker heightAnchor]];
+        auto horizontalConstraint = [[centeringView centerXAnchor] constraintEqualToAnchor:[_datePicker centerXAnchor]];
+        auto verticalConstraint = [[centeringView centerYAnchor] constraintEqualToAnchor:[_datePicker centerYAnchor]];
 
-        [_viewController setView:_datePicker.get()];
+        [NSLayoutConstraint activateConstraints:@[verticalConstraint, horizontalConstraint, widthConstraint, heightConstraint]];
 
+        [_viewController setView:centeringView.get()];
+
         NSString *titleText = _view.inputLabelText;
         if (![titleText isEqual:@""]) {
             RetainPtr<UILabel> title = adoptNS([[UILabel alloc] init]);
@@ -190,10 +208,10 @@
         } else
             [navigationController setNavigationBarHidden:YES animated:NO];
         
-        [navigationController navigationBar].backgroundColor = UIColor.clearColor;
         [navigationController navigationBar].translucent = NO;
-        [navigationController toolbar].backgroundColor = UIColor.clearColor;
+        [navigationController navigationBar].barTintColor = [UIColor systemBackgroundColor];
         [navigationController toolbar].translucent = NO;
+        [navigationController toolbar].barTintColor = [UIColor systemBackgroundColor];
         return navigationController.get();
     } actionProvider:nil];
 }
@@ -202,7 +220,8 @@
 {
     [animator addCompletion:[weakSelf = WeakObjCPtr<WKDateTimePicker>(self)] {
         auto strongSelf = weakSelf.get();
-        [strongSelf->_view.webView _didShowContextMenu];
+        if (strongSelf)
+            [strongSelf->_view.webView _didShowContextMenu];
     }];
 }
 
@@ -210,8 +229,10 @@
 {
     [animator addCompletion:[weakSelf = WeakObjCPtr<WKDateTimePicker>(self)] {
         auto strongSelf = weakSelf.get();
-        [strongSelf->_view accessoryDone];
-        [strongSelf->_view.webView _didDismissContextMenu];
+        if (strongSelf) {
+            [strongSelf->_view accessoryDone];
+            [strongSelf->_view.webView _didDismissContextMenu];
+        }
     }];
 }
 
@@ -249,6 +270,13 @@
     [_view page]->setFocusedElementValue(String());
 }
 
+- (void)ok:(id)sender
+{
+#if USE(UICONTEXTMENU)
+    [_dateTimeContextMenuInteraction dismissMenu];
+#endif
+}
+
 - (NSString *)calendarType
 {
     return [_datePicker calendar].calendarIdentifier;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to