Bug 1745005 - Add showPicker() to <input> elements. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D142754
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include "mozilla/dom/UserActivation.h"
|
||||
#include "mozilla/dom/MutationEventBinding.h"
|
||||
#include "mozilla/dom/WheelEventBinding.h"
|
||||
#include "mozilla/dom/WindowGlobalChild.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/TextUtils.h"
|
||||
@@ -5522,6 +5523,74 @@ void HTMLInputElement::SetSelectionDirection(const nsAString& aDirection,
|
||||
state->SetSelectionDirection(aDirection, aRv);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#dom-input-showpicker
|
||||
void HTMLInputElement::ShowPicker(ErrorResult& aRv) {
|
||||
// Step 1. If this is not mutable, then throw an "InvalidStateError"
|
||||
// DOMException.
|
||||
if (!IsMutable()) {
|
||||
return aRv.ThrowInvalidStateError(
|
||||
"This input is either disabled or readonly.");
|
||||
}
|
||||
|
||||
// Step 2. If this's relevant settings object's origin is not same origin with
|
||||
// this's relevant settings object's top-level origin, and this's type
|
||||
// attribute is not in the File Upload state or Color state, then throw a
|
||||
// "SecurityError" DOMException.
|
||||
if (mType != FormControlType::InputFile &&
|
||||
mType != FormControlType::InputColor) {
|
||||
nsPIDOMWindowInner* window = OwnerDoc()->GetInnerWindow();
|
||||
WindowGlobalChild* windowGlobalChild =
|
||||
window ? window->GetWindowGlobalChild() : nullptr;
|
||||
if (!windowGlobalChild || !windowGlobalChild->SameOriginWithTop()) {
|
||||
return aRv.ThrowSecurityError(
|
||||
"Call was blocked because the current origin isn't same-origin with "
|
||||
"top.");
|
||||
}
|
||||
}
|
||||
|
||||
// Step 3. If this's relevant global object does not have transient
|
||||
// activation, then throw a "NotAllowedError" DOMException.
|
||||
if (!OwnerDoc()->HasValidTransientUserGestureActivation()) {
|
||||
return aRv.ThrowNotAllowedError(
|
||||
"Call was blocked due to lack of user activation.");
|
||||
}
|
||||
|
||||
// Step 4. Show the picker, if applicable, for this.
|
||||
//
|
||||
// https://html.spec.whatwg.org/multipage/input.html#show-the-picker,-if-applicable
|
||||
// To show the picker, if applicable for an input element element:
|
||||
|
||||
// Step 1. Assert: element's relevant global object has transient activation.
|
||||
// Step 2. If element is not mutable, then return.
|
||||
// (See above.)
|
||||
|
||||
// Step 3. If element's type attribute is in the File Upload state, then run
|
||||
// these steps in parallel:
|
||||
if (mType == FormControlType::InputFile) {
|
||||
FilePickerType type = FILE_PICKER_FILE;
|
||||
if (StaticPrefs::dom_webkitBlink_dirPicker_enabled() &&
|
||||
HasAttr(nsGkAtoms::webkitdirectory)) {
|
||||
type = FILE_PICKER_DIRECTORY;
|
||||
}
|
||||
InitFilePicker(type);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 4. Otherwise, the user agent should show any relevant user interface
|
||||
// for selecting a value for element, in the way it normally would when the
|
||||
// user interacts with the control
|
||||
if (mType == FormControlType::InputColor) {
|
||||
InitColorPicker();
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsDateTimeInputType(mType) && IsInComposedDoc()) {
|
||||
DateTimeValue value;
|
||||
GetDateTimeInputBoxValue(value);
|
||||
OpenDateTimePicker(value);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef ACCESSIBILITY
|
||||
/*static*/ nsresult FireEventForAccessibility(HTMLInputElement* aTarget,
|
||||
EventMessage aEventMessage) {
|
||||
|
||||
Reference in New Issue
Block a user