Title: [276919] trunk/Source/WebKit
Revision
276919
Author
[email protected]
Date
2021-05-03 13:13:43 -0700 (Mon, 03 May 2021)

Log Message

[iOS][FCR] Grouped <select> options should appear inline in the menu
https://bugs.webkit.org/show_bug.cgi?id=225314
<rdar://problem/76785797>

Reviewed by Wenson Hsieh.

Currently, <select> options within an <optgroup> element are presented
within an expandable/collapsible submenu. However, to better match the
visual style across the rest of the system, the grouped options should
appear inline in the root menu, and groups should be separated by a
visual separator.

Covered by existing tests. A testing-only method was updated to reflect
the changes.

* UIProcess/ios/forms/WKFormSelectPicker.mm:
(-[WKSelectPicker createMenu]):

Used UIMenuOptionsDisplayInline to present submenus inline in the root
menu. This option separates submenus using a visual separator.

Since inline submenus do not support a title, and <optgroup> elements
can be labeled, the group title is displayed as a disabled action at
the top of the submenu.

Removed logic to promote the grouped submenu to the root menu in the
case where only one submenu contains all options, since the submenu
now appears inline, and an additional tap is no longer necessary to
view the options.

(-[WKSelectPicker actionForOptionIndex:]):

Updated this testing-only method to account for the potential existence
of an additional action representing a group title.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (276918 => 276919)


--- trunk/Source/WebKit/ChangeLog	2021-05-03 19:58:44 UTC (rev 276918)
+++ trunk/Source/WebKit/ChangeLog	2021-05-03 20:13:43 UTC (rev 276919)
@@ -1,3 +1,40 @@
+2021-05-03  Aditya Keerthi  <[email protected]>
+
+        [iOS][FCR] Grouped <select> options should appear inline in the menu
+        https://bugs.webkit.org/show_bug.cgi?id=225314
+        <rdar://problem/76785797>
+
+        Reviewed by Wenson Hsieh.
+
+        Currently, <select> options within an <optgroup> element are presented
+        within an expandable/collapsible submenu. However, to better match the
+        visual style across the rest of the system, the grouped options should
+        appear inline in the root menu, and groups should be separated by a
+        visual separator.
+
+        Covered by existing tests. A testing-only method was updated to reflect
+        the changes.
+
+        * UIProcess/ios/forms/WKFormSelectPicker.mm:
+        (-[WKSelectPicker createMenu]):
+
+        Used UIMenuOptionsDisplayInline to present submenus inline in the root
+        menu. This option separates submenus using a visual separator.
+
+        Since inline submenus do not support a title, and <optgroup> elements
+        can be labeled, the group title is displayed as a disabled action at
+        the top of the submenu.
+
+        Removed logic to promote the grouped submenu to the root menu in the
+        case where only one submenu contains all options, since the submenu
+        now appears inline, and an additional tap is no longer necessary to
+        view the options.
+
+        (-[WKSelectPicker actionForOptionIndex:]):
+
+        Updated this testing-only method to account for the potential existence
+        of an additional action representing a group title.
+
 2021-05-03  Devin Rousso  <[email protected]>
 
         [macCatalyst] "Enter Full Screen" button in media controls disappears

Modified: trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectPicker.mm (276918 => 276919)


--- trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectPicker.mm	2021-05-03 19:58:44 UTC (rev 276918)
+++ trunk/Source/WebKit/UIProcess/ios/forms/WKFormSelectPicker.mm	2021-05-03 20:13:43 UTC (rev 276919)
@@ -564,6 +564,12 @@
             NSString *groupText = optionItem.text;
             NSMutableArray *groupedItems = [NSMutableArray array];
 
+            if (groupText.length) {
+                UIAction *action = "" actionWithTitle:groupText image:nil identifier:nil handler:^(UIAction *action) { }];
+                action.attributes = UIMenuElementAttributesDisabled;
+                [groupedItems addObject:action];
+            }
+
             currentIndex++;
             while (currentIndex < _view.focusedSelectElementOptions.size()) {
                 auto& childOptionItem = _view.focusedSelectElementOptions[currentIndex];
@@ -576,7 +582,7 @@
                 currentIndex++;
             }
 
-            UIMenu *groupMenu = [UIMenu menuWithTitle:groupText children:groupedItems];
+            UIMenu *groupMenu = [UIMenu menuWithTitle:groupText image:nil identifier:nil options:UIMenuOptionsDisplayInline children:groupedItems];
             [items addObject:groupMenu];
             continue;
         }
@@ -587,12 +593,6 @@
         currentIndex++;
     }
 
-    // Some sites, such as Square Checkout, wrap all the element's <option>s in
-    // an a single <optgroup>. In this case, promote the grouped submenu to the
-    // root menu, avoiding the need for an additional tap to view the options.
-    if (items.count == 1 && [[items firstObject] isKindOfClass:UIMenu.class])
-        return [items firstObject];
-
     return [UIMenu menuWithTitle:@"" children:items];
 }
 
@@ -626,10 +626,16 @@
         }
 
         UIMenu *groupedMenu = (UIMenu *)menuElement;
-        if (currentIndex + groupedMenu.children.count <= (NSUInteger)optionIndex)
-            currentIndex += groupedMenu.children.count;
+        NSUInteger numGroupedOptions = groupedMenu.children.count;
+
+        // The first child of a grouped menu with a title represents the title, and is not a selectable option.
+        if (groupedMenu.title.length)
+            numGroupedOptions--;
+
+        if (currentIndex + numGroupedOptions <= (NSUInteger)optionIndex)
+            currentIndex += numGroupedOptions;
         else
-            return (UIAction *)[groupedMenu.children objectAtIndex:optionIndex - currentIndex];
+            return (UIAction *)[groupedMenu.children objectAtIndex:(groupedMenu.children.count - numGroupedOptions) + (optionIndex - currentIndex)];
     }
 
     return nil;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to