Skip to content

Commit b2191d0

Browse files
[WK2][Cocoa] Implement user interface for HTML form validation
https://bugs.webkit.org/show_bug.cgi?id=164143 <rdar://problem/28944652> Reviewed by Simon Fraser. Source/WebCore: Add ValidationBubble class to show HTML form validation messages using native dialogs. It currently has an implementation for both Mac and iOS. It is in WebCore under platform/ so that it can be used by both WebKit1 and WebKit2. Update ownership of ValidationMessageClient so that is is owned by the Page using a unique_ptr<>, which seems to be the modern way of handling lifetime for page clients. Test: fast/forms/validation-messages.html * WebCore.xcodeproj/project.pbxproj: * html/HTMLFormControlElement.cpp: (WebCore::HTMLFormControlElement::focusAndShowValidationMessage): * html/ValidationMessage.cpp: (WebCore::ValidationMessage::updateValidationMessage): * page/Page.cpp: (WebCore::Page::Page): (WebCore::Page::~Page): * page/Page.h: (WebCore::Page::validationMessageClient): * page/PageConfiguration.cpp: * page/PageConfiguration.h: * platform/ValidationBubble.h: Copied from Tools/DumpRenderTree/mac/UIScriptControllerMac.mm. (WebCore::ValidationBubble::message): * platform/ios/ValidationBubbleIOS.mm: Added. (-[WebValidationBubbleDelegate adaptivePresentationStyleForPresentationController:traitCollection:]): (WebCore::ValidationBubble::ValidationBubble): (WebCore::ValidationBubble::~ValidationBubble): (WebCore::ValidationBubble::show): (WebCore::ValidationBubble::setAnchorRect): * platform/mac/ValidationBubbleMac.mm: Added. (WebCore::ValidationBubble::ValidationBubble): (WebCore::ValidationBubble::~ValidationBubble): (WebCore::ValidationBubble::showRelativeTo): Source/WebKit2: Implement the ValidationMessageClient in WebKit2 and have it display a ValidationBubble on Cocoa. ValidationBubble is implemented using native popovers on both Mac and iOS. As a result, Mac and iOS WK2 now use native popover for HTML form validation instead of the old Shadow DOM based UI in WebCore. The native popover shows at the bottom (or top) of the input and it disapears as soon as the user starts typing or interacts with the view (e.g. tap / scroll / zoom). The feature is still disabled at runtime. * UIProcess/API/Cocoa/WKWebView.mm: (-[WKWebView _initializeWithConfiguration:]): (-[WKWebView _keyboardWillShow:]): (-[WKWebView _keyboardDidShow:]): (-[WKWebView _contentsOfUserInterfaceItem:]): * UIProcess/API/Cocoa/WKWebViewPrivate.h: * UIProcess/Cocoa/WebPageProxyCocoa.mm: * UIProcess/PageClient.h: * UIProcess/WebPageProxy.cpp: (WebKit::WebPageProxy::handleWheelEvent): (WebKit::WebPageProxy::setPageZoomFactor): (WebKit::WebPageProxy::setPageAndTextZoomFactors): (WebKit::WebPageProxy::pageDidScroll): (WebKit::WebPageProxy::resetState): (WebKit::WebPageProxy::hideValidationMessage): * UIProcess/WebPageProxy.h: (WebKit::WebPageProxy::validationBubble): (WebKit::WebPageProxy::setIsKeyboardAnimatingIn): * UIProcess/WebPageProxy.messages.in: * UIProcess/ios/PageClientImplIOS.h: * UIProcess/ios/PageClientImplIOS.mm: (WebKit::PageClientImpl::createValidationBubble): * UIProcess/ios/WKContentViewInteraction.mm: (-[WKContentView _willStartScrollingOrZooming]): (-[WKContentView scrollViewWillStartPanOrPinchGesture]): (-[WKContentView _didEndScrollingOrZooming]): * UIProcess/ios/WebPageProxyIOS.mm: (WebKit::WebPageProxy::dynamicViewportSizeUpdate): (WebKit::WebPageProxy::potentialTapAtPosition): (WebKit::WebPageProxy::showValidationMessage): (WebKit::WebPageProxy::setIsScrollingOrZooming): * UIProcess/mac/PageClientImpl.h: * UIProcess/mac/PageClientImpl.mm: (WebKit::PageClientImpl::createValidationBubble): * UIProcess/mac/WebPageProxyMac.mm: (WebKit::WebPageProxy::showValidationMessage): * WebKit2.xcodeproj/project.pbxproj: * WebProcess/WebCoreSupport/WebValidationMessageClient.cpp: Copied from Tools/DumpRenderTree/mac/UIScriptControllerMac.mm. (WebKit::WebValidationMessageClient::WebValidationMessageClient): (WebKit::WebValidationMessageClient::~WebValidationMessageClient): (WebKit::WebValidationMessageClient::showValidationMessage): (WebKit::WebValidationMessageClient::hideValidationMessage): (WebKit::WebValidationMessageClient::isValidationMessageVisible): * WebProcess/WebCoreSupport/WebValidationMessageClient.h: Copied from Tools/DumpRenderTree/mac/UIScriptControllerMac.mm. * WebProcess/WebPage/WebPage.cpp: (WebKit::m_userInterfaceLayoutDirection): Tools: Add support for UIScriptController::contentsOfUserInterfaceItem("validationBubble") on both Mac and iOS to retrieve the currently displayed validation message. * DumpRenderTree/mac/UIScriptControllerMac.mm: (WTR::UIScriptController::contentsOfUserInterfaceItem): * TestRunnerShared/UIScriptContext/UIScriptController.cpp: (WTR::UIScriptController::contentsOfUserInterfaceItem): (WTR::UIScriptController::selectFormAccessoryPickerRow): * WebKitTestRunner/mac/UIScriptControllerMac.mm: (WTR::UIScriptController::contentsOfUserInterfaceItem): LayoutTests: * fast/forms/validation-messages-expected.txt: Added. * fast/forms/validation-messages.html: Added. Add layout test coverage for checking that the right validation messages are displayed when submitting forms with constraint violations. More testing will be landed in follow up to cover other things besides the messages (e.g. when does the bubble disappear). * platform/mac-wk1/TestExpectations: Skip new test on WebKit1 because the feature is WebKit2 only at the moment. * platform/ios-simulator-wk2/TestExpectations: * platform/mac-wk2/TestExpectations: Skip tests for the Shadow DOM based HTML form validation UI on Mac and iOS WK2 now that those ports use native popovers instead. git-svn-id: http://svn.webkit.org/repository/webkit/trunk@208361 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent ed726b7 commit b2191d0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+936
-19
lines changed

LayoutTests/ChangeLog

+24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
1+
2016-11-03 Chris Dumez <[email protected]>
2+
3+
[WK2][Cocoa] Implement user interface for HTML form validation
4+
https://bugs.webkit.org/show_bug.cgi?id=164143
5+
<rdar://problem/28944652>
6+
7+
Reviewed by Simon Fraser.
8+
9+
* fast/forms/validation-messages-expected.txt: Added.
10+
* fast/forms/validation-messages.html: Added.
11+
Add layout test coverage for checking that the right validation messages
12+
are displayed when submitting forms with constraint violations. More
13+
testing will be landed in follow up to cover other things besides the
14+
messages (e.g. when does the bubble disappear).
15+
16+
* platform/mac-wk1/TestExpectations:
17+
Skip new test on WebKit1 because the feature is WebKit2 only at the
18+
moment.
19+
20+
* platform/ios-simulator-wk2/TestExpectations:
21+
* platform/mac-wk2/TestExpectations:
22+
Skip tests for the Shadow DOM based HTML form validation UI on
23+
Mac and iOS WK2 now that those ports use native popovers instead.
24+
125
2016-11-03 Ryosuke Niwa <[email protected]>
226

327
Update custom elements tests
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Tests the HTML form validation messages being shown on UI side.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS validationBubbleContents.message is "Please fill out this field."
7+
PASS validationBubbleContents.message is "Please check this box if you want to proceed."
8+
PASS validationBubbleContents.message is "Please select one of these options."
9+
PASS validationBubbleContents.message is "Please select a file."
10+
PASS validationBubbleContents.message is "Please enter an email address."
11+
PASS validationBubbleContents.message is "Please enter a URL."
12+
PASS validationBubbleContents.message is "Please match the requested format."
13+
PASS validationBubbleContents.message is "Please use at least 100 characters."
14+
PASS validationBubbleContents.message is "Value must be greater than or equal to 5."
15+
PASS validationBubbleContents.message is "Value must be less than or equal to 5."
16+
PASS validationBubbleContents.message is "Please enter a valid value."
17+
PASS successfullyParsed is true
18+
19+
TEST COMPLETE
20+
Required text input:
21+
Required checkbox input:
22+
Required radio input:
23+
Required radio input:
24+
Required file input:
25+
Required email input:
26+
Required url input:
27+
Required input with pattern:
28+
Required input with minlength=100:
29+
Required range with min=5:
30+
Required range with max=5:
31+
Required range with step=3 / min=0:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<script src="../../resources/js-test-pre.js"></script>
5+
<form>
6+
Required text input: <input type="text" required><input id="required_text_input_submit" type="submit">
7+
</form>
8+
<form>
9+
Required checkbox input: <input type="checkbox" required><input id="required_checkbox_submit" type="submit">
10+
</form>
11+
<form>
12+
Required radio input: <input type="radio" name="myradiogroup1" required><br>
13+
Required radio input: <input type="radio" name="myradiogroup1">
14+
<input id="required_radio_submit" type="submit">
15+
</form>
16+
<form>
17+
Required file input: <input type="file" required><input id="required_file_submit" type="submit">
18+
</form>
19+
<form>
20+
Required email input: <input type="email" value="invalid" required><input id="required_email_submit" type="submit">
21+
</form>
22+
<form>
23+
Required url input: <input type="url" value="invalid" required><input id="required_url_submit" type="submit">
24+
</form>
25+
<form>
26+
Required input with pattern: <input type="text" value="1" pattern="[a-z]" required><input id="input_with_pattern_submit" type="submit">
27+
</form>
28+
<form>
29+
Required input with minlength=100: <input type="text" minlength=100 id="field_with_minlength" required><input id="input_with_minlength_submit" type="submit">
30+
</form>
31+
<form>
32+
Required range with min=5: <input type="number" value="1" min=5 required><input id="range_with_min_submit" type="submit">
33+
</form>
34+
<form>
35+
Required range with max=5: <input type="number" value="10" max=5 required><input id="range_with_max_submit" type="submit">
36+
</form>
37+
<form>
38+
Required range with step=3 / min=0: <input type="number" value="10" min=0 step=3 required><input id="range_with_step_submit" type="submit">
39+
</form>
40+
<script>
41+
description("Tests the HTML form validation messages being shown on UI side.");
42+
jsTestIsAsync = true;
43+
44+
function getValidationBubbleContents()
45+
{
46+
return `
47+
(function() {
48+
uiController.uiScriptComplete(JSON.stringify(uiController.contentsOfUserInterfaceItem('validationBubble')));
49+
})();`
50+
}
51+
52+
var tests = [
53+
['required_text_input_submit', 'Please fill out this field.'],
54+
['required_checkbox_submit', 'Please check this box if you want to proceed.'],
55+
['required_radio_submit', 'Please select one of these options.'],
56+
['required_file_submit', 'Please select a file.'],
57+
['required_email_submit', 'Please enter an email address.'],
58+
['required_url_submit', 'Please enter a URL.'],
59+
['input_with_pattern_submit', 'Please match the requested format.'],
60+
['input_with_minlength_submit', 'Please use at least 100 characters.'],
61+
['range_with_min_submit', 'Value must be greater than or equal to 5.'],
62+
['range_with_max_submit', 'Value must be less than or equal to 5.'],
63+
['range_with_step_submit', 'Please enter a valid value.'],
64+
];
65+
var currentTestIndex = -1;
66+
67+
function runNextTest()
68+
{
69+
++currentTestIndex;
70+
if (currentTestIndex >= tests.length) {
71+
finishJSTest();
72+
return;
73+
}
74+
75+
var currentTest = tests[currentTestIndex];
76+
var submitButton = document.getElementById(currentTest[0]);
77+
expectedMessage = currentTest[1];
78+
79+
submitButton.click();
80+
testRunner.runUIScript(getValidationBubbleContents(), function(result) {
81+
validationBubbleContents = JSON.parse(result).validationBubble;
82+
shouldBeEqualToString("validationBubbleContents.message", "" + expectedMessage);
83+
runNextTest();
84+
});
85+
}
86+
87+
function setup()
88+
{
89+
var field = document.getElementById("field_with_minlength");
90+
field.focus();
91+
eventSender.keyDown("Z");
92+
}
93+
94+
onload = function() {
95+
setup();
96+
setTimeout(function() {
97+
runNextTest();
98+
}, 0);
99+
}
100+
</script>
101+
<script src="../../resources/js-test-post.js"></script>
102+
</body>
103+
<html>

LayoutTests/platform/ios-simulator-wk2/TestExpectations

+11
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,17 @@ http/tests/navigation/target-blank-opener-post.html [ Skip ]
14571457
css2.1/20110323/replaced-intrinsic-002.htm [ Pass ]
14581458
fast/replaced/pdf-as-object-and-embed.html [ Pass ]
14591459

1460+
# These tests test the Shadow DOM based HTML form validation UI but iOS WK2 is using native dialogs instead.
1461+
fast/forms/validation-message-on-listbox.html
1462+
fast/forms/validation-message-on-menulist.html
1463+
fast/forms/validation-message-on-radio.html
1464+
fast/forms/validation-message-on-checkbox.html
1465+
fast/forms/validation-message-on-range.html
1466+
fast/forms/validation-message-clone.html
1467+
fast/forms/validation-message-in-relative-body.html
1468+
fast/forms/validation-message-appearance.html
1469+
fast/forms/validation-message-on-textarea.html
1470+
14601471
# Flaky as of 06/08/2015
14611472
compositing/overflow/overflow-positioning.html [ Failure ImageOnlyFailure Pass ]
14621473
editing/deleting/delete-3775172-fix.html [ Failure ImageOnlyFailure Pass ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Tests the HTML form validation messages being shown on UI side.
2+
3+
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
4+
5+
6+
PASS validationBubbleContents.message is "Please fill out this field."
7+
PASS validationBubbleContents.message is "Please check this box if you want to proceed."
8+
PASS validationBubbleContents.message is "Please select one of these options."
9+
PASS validationBubbleContents.message is "Please select a file."
10+
PASS validationBubbleContents.message is "Please enter an email address."
11+
PASS validationBubbleContents.message is "Please enter a URL."
12+
PASS validationBubbleContents.message is "Please match the requested format."
13+
FAIL validationBubbleContents.message should be Please use at least 100 characters.. Was Please fill out this field..
14+
PASS validationBubbleContents.message is "Value must be greater than or equal to 5."
15+
PASS validationBubbleContents.message is "Value must be less than or equal to 5."
16+
PASS validationBubbleContents.message is "Please enter a valid value."
17+
PASS successfullyParsed is true
18+
19+
TEST COMPLETE
20+
Required text input:
21+
Required checkbox input:
22+
Required radio input:
23+
Required radio input:
24+
Required file input:
25+
Required email input:
26+
Required url input:
27+
Required input with pattern:
28+
Required input with minlength=100:
29+
Required range with min=5:
30+
Required range with max=5:
31+
Required range with step=3 / min=0:

LayoutTests/platform/mac-wk1/TestExpectations

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ webkit.org/b/158585 webgl/webgl-backing-store-size-update.html [ Pass Timeout ]
239239
# rdar://problem/26478296
240240
[ Sierra+ ] svg/hixie/text/003.html [ Failure ]
241241

242+
# We do not support the new HTML validation UI on WebKit1 yet (rdar://problem/28944652).
243+
fast/forms/validation-messages.html [ Skip ]
244+
242245
[ Yosemite ] http/tests/media/hls/video-controller-getStartDate.html [ Pass Timeout ]
243246

244247
webkit.org/b/159893 [ Debug ] imported/w3c/web-platform-tests/XMLHttpRequest/event-readystatechange-loaded.htm [ Pass Failure ]

LayoutTests/platform/mac-wk2/TestExpectations

+11
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ webkit.org/b/90156 editing/mac/spelling/autocorrection-blockquote-crash.html [ F
193193

194194
webkit.org/b/95043 http/tests/security/local-user-CSS-from-remote.html [ Failure ]
195195

196+
# These tests test the Shadow DOM based HTML form validation UI but Mac WK2 is using native dialogs instead.
197+
fast/forms/validation-message-on-listbox.html
198+
fast/forms/validation-message-on-menulist.html
199+
fast/forms/validation-message-on-radio.html
200+
fast/forms/validation-message-on-checkbox.html
201+
fast/forms/validation-message-on-range.html
202+
fast/forms/validation-message-clone.html
203+
fast/forms/validation-message-in-relative-body.html
204+
fast/forms/validation-message-appearance.html
205+
fast/forms/validation-message-on-textarea.html
206+
196207
# All spatial navigation tests fail on Mac WK2
197208
webkit.org/b/96438 fast/spatial-navigation
198209

Source/WebCore/ChangeLog

+44
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1+
2016-11-03 Chris Dumez <[email protected]>
2+
3+
[WK2][Cocoa] Implement user interface for HTML form validation
4+
https://bugs.webkit.org/show_bug.cgi?id=164143
5+
<rdar://problem/28944652>
6+
7+
Reviewed by Simon Fraser.
8+
9+
Add ValidationBubble class to show HTML form validation messages
10+
using native dialogs. It currently has an implementation for both
11+
Mac and iOS. It is in WebCore under platform/ so that it can be
12+
used by both WebKit1 and WebKit2.
13+
14+
Update ownership of ValidationMessageClient so that is is owned
15+
by the Page using a unique_ptr<>, which seems to be the modern
16+
way of handling lifetime for page clients.
17+
18+
Test: fast/forms/validation-messages.html
19+
20+
* WebCore.xcodeproj/project.pbxproj:
21+
* html/HTMLFormControlElement.cpp:
22+
(WebCore::HTMLFormControlElement::focusAndShowValidationMessage):
23+
* html/ValidationMessage.cpp:
24+
(WebCore::ValidationMessage::updateValidationMessage):
25+
* page/Page.cpp:
26+
(WebCore::Page::Page):
27+
(WebCore::Page::~Page):
28+
* page/Page.h:
29+
(WebCore::Page::validationMessageClient):
30+
* page/PageConfiguration.cpp:
31+
* page/PageConfiguration.h:
32+
* platform/ValidationBubble.h: Copied from Tools/DumpRenderTree/mac/UIScriptControllerMac.mm.
33+
(WebCore::ValidationBubble::message):
34+
* platform/ios/ValidationBubbleIOS.mm: Added.
35+
(-[WebValidationBubbleDelegate adaptivePresentationStyleForPresentationController:traitCollection:]):
36+
(WebCore::ValidationBubble::ValidationBubble):
37+
(WebCore::ValidationBubble::~ValidationBubble):
38+
(WebCore::ValidationBubble::show):
39+
(WebCore::ValidationBubble::setAnchorRect):
40+
* platform/mac/ValidationBubbleMac.mm: Added.
41+
(WebCore::ValidationBubble::ValidationBubble):
42+
(WebCore::ValidationBubble::~ValidationBubble):
43+
(WebCore::ValidationBubble::showRelativeTo):
44+
145
2016-11-03 Brady Eidson <[email protected]>
246

347
IndexedDB 2.0: Rename IDBKeyRange.contains to IDBKeyRange.includes.

0 commit comments

Comments
 (0)