Skip to content

Commit

Permalink
moebius#92: HTML - input - datetime
Browse files Browse the repository at this point in the history
+ native in moebius:

Bug 1317600: https://bugzilla.mozilla.org/show_bug.cgi?id=1317600
A note - not implemented: Bug 1282768:
https://bugzilla.mozilla.org/show_bug.cgi?id=1282768
*.css: filter: url("chrome://global/skin/filters.svg#fill");, fill:

Bug 1283385: https://bugzilla.mozilla.org/show_bug.cgi?id=1283385
Bug 1323109: https://bugzilla.mozilla.org/show_bug.cgi?id=1323109
Bug 1314544: https://bugzilla.mozilla.org/show_bug.cgi?id=1314544
Bug 1286182: https://bugzilla.mozilla.org/show_bug.cgi?id=1286182

Bug 1325922: https://bugzilla.mozilla.org/show_bug.cgi?id=1325922
A note - not implemented: Bug 1282768:
https://bugzilla.mozilla.org/show_bug.cgi?id=1282768
*.css: filter: url("chrome://global/skin/filters.svg#fill");, fill:

Bug 1320225: https://bugzilla.mozilla.org/show_bug.cgi?id=1320225
Bug 1341190: https://bugzilla.mozilla.org/show_bug.cgi?id=1341190
  • Loading branch information
janekptacijarabaci committed Mar 30, 2018
1 parent a1a007a commit e254301
Show file tree
Hide file tree
Showing 34 changed files with 1,267 additions and 248 deletions.
2 changes: 1 addition & 1 deletion browser/base/content/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ toolbar:not(#TabsToolbar) > #personal-bookmarks {
transition: none;
}

#DateTimePickerPanel {
#DateTimePickerPanel[active="true"] {
-moz-binding: url("chrome://global/content/bindings/datetimepopup.xml#datetime-popup");
}

Expand Down
4 changes: 3 additions & 1 deletion browser/base/content/browser.xul
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@
hidden="true"
orient="vertical"
noautofocus="true"
noautohide="true"
consumeoutsideclicks="false"
level="parent">
level="parent"
tabspecific="true">
<iframe id="dateTimePopupFrame"/>
</panel>

Expand Down
185 changes: 147 additions & 38 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,8 @@ GetDOMFileOrDirectoryPath(const OwningFileOrDirectory& aData,
bool
HTMLInputElement::ValueAsDateEnabled(JSContext* cx, JSObject* obj)
{
return Preferences::GetBool("dom.experimental_forms", false) ||
Preferences::GetBool("dom.forms.datepicker", false) ||
Preferences::GetBool("dom.forms.datetime", false);
return IsExperimentalFormsEnabled() || IsDatePickerEnabled() ||
IsInputDateTimeEnabled();
}

NS_IMETHODIMP
Expand Down Expand Up @@ -628,7 +627,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
RefPtr<DispatchChangeEventCallback> dispatchChangeEventCallback =
new DispatchChangeEventCallback(mInput);

if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
if (IsWebkitDirPickerEnabled() &&
mInput->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) {
ErrorResult error;
GetFilesHelper* helper = mInput->GetOrCreateGetFilesHelper(true, error);
Expand Down Expand Up @@ -827,7 +826,7 @@ HTMLInputElement::IsPopupBlocked() const
nsresult
HTMLInputElement::InitDatePicker()
{
if (!Preferences::GetBool("dom.forms.datepicker", false)) {
if (!IsDatePickerEnabled()) {
return NS_OK;
}

Expand Down Expand Up @@ -2516,10 +2515,8 @@ bool
HTMLInputElement::IsExperimentalMobileType(uint8_t aType)
{
return (aType == NS_FORM_INPUT_DATE &&
!Preferences::GetBool("dom.forms.datetime", false) &&
!Preferences::GetBool("dom.forms.datepicker", false)) ||
(aType == NS_FORM_INPUT_TIME &&
!Preferences::GetBool("dom.forms.datetime", false));
!IsInputDateTimeEnabled() && !IsDatePickerEnabled()) ||
(aType == NS_FORM_INPUT_TIME && !IsInputDateTimeEnabled());
}

bool
Expand Down Expand Up @@ -3025,8 +3022,8 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const
nsXPIDLString value;

if (mFilesOrDirectories.IsEmpty()) {
if ((Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs()) ||
(Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
if ((IsDirPickerEnabled() && Allowdirs()) ||
(IsWebkitDirPickerEnabled() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) {
nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES,
"NoDirSelected", value);
Expand Down Expand Up @@ -3055,7 +3052,7 @@ HTMLInputElement::SetFilesOrDirectories(const nsTArray<OwningFileOrDirectory>& a
{
ClearGetFilesHelpers();

if (Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false)) {
if (IsWebkitFileSystemEnabled()) {
HTMLInputElementBinding::ClearCachedWebkitEntriesValue(this);
mEntries.Clear();
}
Expand All @@ -3074,7 +3071,7 @@ HTMLInputElement::SetFiles(nsIDOMFileList* aFiles,
mFilesOrDirectories.Clear();
ClearGetFilesHelpers();

if (Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false)) {
if (IsWebkitFileSystemEnabled()) {
HTMLInputElementBinding::ClearCachedWebkitEntriesValue(this);
mEntries.Clear();
}
Expand All @@ -3097,14 +3094,14 @@ HTMLInputElement::MozSetDndFilesAndDirectories(const nsTArray<OwningFileOrDirect
{
SetFilesOrDirectories(aFilesOrDirectories, true);

if (Preferences::GetBool("dom.webkitBlink.filesystem.enabled", false)) {
if (IsWebkitFileSystemEnabled()) {
UpdateEntries(aFilesOrDirectories);
}

RefPtr<DispatchChangeEventCallback> dispatchChangeEventCallback =
new DispatchChangeEventCallback(this);

if (Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
if (IsWebkitDirPickerEnabled() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) {
ErrorResult rv;
GetFilesHelper* helper = GetOrCreateGetFilesHelper(true /* recursionFlag */,
Expand Down Expand Up @@ -3182,8 +3179,8 @@ HTMLInputElement::GetFiles()
return nullptr;
}

if (Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs() &&
(!Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) ||
if (IsDirPickerEnabled() && Allowdirs() &&
(!IsWebkitDirPickerEnabled() ||
!HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) {
return nullptr;
}
Expand Down Expand Up @@ -4366,8 +4363,8 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
do_QueryInterface(aVisitor.mEvent->mOriginalTarget);
if (target &&
target->FindFirstNonChromeOnlyAccessContent() == this &&
((Preferences::GetBool("dom.input.dirpicker", false) && Allowdirs()) ||
(Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) &&
((IsDirPickerEnabled() && Allowdirs()) ||
(IsWebkitDirPickerEnabled() &&
HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)))) {
type = FILE_PICKER_DIRECTORY;
}
Expand Down Expand Up @@ -5735,20 +5732,133 @@ HTMLInputElement::ParseTime(const nsAString& aValue, uint32_t* aResult)
return true;
}

static bool
IsDateTimeEnabled(int32_t aNewType)
/* static */ bool
HTMLInputElement::IsDateTimeTypeSupported(uint8_t aDateTimeInputType)
{
return (aDateTimeInputType == NS_FORM_INPUT_DATE &&
(IsInputDateTimeEnabled() || IsExperimentalFormsEnabled() ||
IsDatePickerEnabled())) ||
(aDateTimeInputType == NS_FORM_INPUT_TIME &&
(IsInputDateTimeEnabled() || IsExperimentalFormsEnabled())) ||
((aDateTimeInputType == NS_FORM_INPUT_MONTH ||
aDateTimeInputType == NS_FORM_INPUT_WEEK ||
aDateTimeInputType == NS_FORM_INPUT_DATETIME_LOCAL) &&
IsInputDateTimeEnabled());
}

/* static */ bool
HTMLInputElement::IsWebkitDirPickerEnabled()
{
static bool sWebkitDirPickerEnabled = false;
static bool sWebkitDirPickerPrefCached = false;
if (!sWebkitDirPickerPrefCached) {
sWebkitDirPickerPrefCached = true;
Preferences::AddBoolVarCache(&sWebkitDirPickerEnabled,
"dom.webkitBlink.dirPicker.enabled",
false);
}

return sWebkitDirPickerEnabled;
}

/* static */ bool
HTMLInputElement::IsWebkitFileSystemEnabled()
{
static bool sWebkitFileSystemEnabled = false;
static bool sWebkitFileSystemPrefCached = false;
if (!sWebkitFileSystemPrefCached) {
sWebkitFileSystemPrefCached = true;
Preferences::AddBoolVarCache(&sWebkitFileSystemEnabled,
"dom.webkitBlink.filesystem.enabled",
false);
}

return sWebkitFileSystemEnabled;
}

/* static */ bool
HTMLInputElement::IsDirPickerEnabled()
{
static bool sDirPickerEnabled = false;
static bool sDirPickerPrefCached = false;
if (!sDirPickerPrefCached) {
sDirPickerPrefCached = true;
Preferences::AddBoolVarCache(&sDirPickerEnabled, "dom.input.dirpicker",
false);
}

return sDirPickerEnabled;
}

/* static */ bool
HTMLInputElement::IsDatePickerEnabled()
{
static bool sDatePickerEnabled = false;
static bool sDatePickerPrefCached = false;
if (!sDatePickerPrefCached) {
sDatePickerPrefCached = true;
Preferences::AddBoolVarCache(&sDatePickerEnabled, "dom.forms.datepicker",
false);
}

return sDatePickerEnabled;
}

/* static */ bool
HTMLInputElement::IsExperimentalFormsEnabled()
{
return (aNewType == NS_FORM_INPUT_DATE &&
(Preferences::GetBool("dom.forms.datetime", false) ||
Preferences::GetBool("dom.experimental_forms", false) ||
Preferences::GetBool("dom.forms.datepicker", false))) ||
(aNewType == NS_FORM_INPUT_TIME &&
(Preferences::GetBool("dom.forms.datetime", false) ||
Preferences::GetBool("dom.experimental_forms", false))) ||
((aNewType == NS_FORM_INPUT_MONTH ||
aNewType == NS_FORM_INPUT_WEEK ||
aNewType == NS_FORM_INPUT_DATETIME_LOCAL) &&
Preferences::GetBool("dom.forms.datetime", false));
static bool sExperimentalFormsEnabled = false;
static bool sExperimentalFormsPrefCached = false;
if (!sExperimentalFormsPrefCached) {
sExperimentalFormsPrefCached = true;
Preferences::AddBoolVarCache(&sExperimentalFormsEnabled,
"dom.experimental_forms",
false);
}

return sExperimentalFormsEnabled;
}

/* static */ bool
HTMLInputElement::IsInputDateTimeEnabled()
{
static bool sDateTimeEnabled = false;
static bool sDateTimePrefCached = false;
if (!sDateTimePrefCached) {
sDateTimePrefCached = true;
Preferences::AddBoolVarCache(&sDateTimeEnabled, "dom.forms.datetime",
false);
}

return sDateTimeEnabled;
}

/* static */ bool
HTMLInputElement::IsInputNumberEnabled()
{
static bool sInputNumberEnabled = false;
static bool sInputNumberPrefCached = false;
if (!sInputNumberPrefCached) {
sInputNumberPrefCached = true;
Preferences::AddBoolVarCache(&sInputNumberEnabled, "dom.forms.number",
false);
}

return sInputNumberEnabled;
}

/* static */ bool
HTMLInputElement::IsInputColorEnabled()
{
static bool sInputColorEnabled = false;
static bool sInputColorPrefCached = false;
if (!sInputColorPrefCached) {
sInputColorPrefCached = true;
Preferences::AddBoolVarCache(&sInputColorEnabled, "dom.forms.color",
false);
}

return sInputColorEnabled;
}

bool
Expand All @@ -5766,12 +5876,11 @@ HTMLInputElement::ParseAttribute(int32_t aNamespaceID,
if (success) {
newType = aResult.GetEnumValue();
if ((IsExperimentalMobileType(newType) &&
!Preferences::GetBool("dom.experimental_forms", false)) ||
(newType == NS_FORM_INPUT_NUMBER &&
!Preferences::GetBool("dom.forms.number", false)) ||
(newType == NS_FORM_INPUT_COLOR &&
!Preferences::GetBool("dom.forms.color", false)) ||
(IsDateTimeInputType(newType) && !IsDateTimeEnabled(newType))) {
!IsExperimentalFormsEnabled()) ||
(newType == NS_FORM_INPUT_NUMBER && !IsInputNumberEnabled()) ||
(newType == NS_FORM_INPUT_COLOR && !IsInputColorEnabled()) ||
(IsDateTimeInputType(newType) &&
!IsDateTimeTypeSupported(newType))) {
newType = kInputDefaultType->value;
aResult.SetTo(newType, &aValue);
}
Expand Down
66 changes: 65 additions & 1 deletion dom/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -1632,9 +1632,73 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
return IsSingleLineTextControl(false, aType) ||
aType == NS_FORM_INPUT_RANGE ||
aType == NS_FORM_INPUT_NUMBER ||
aType == NS_FORM_INPUT_TIME;
aType == NS_FORM_INPUT_TIME ||
aType == NS_FORM_INPUT_DATE;
}

/**
* Checks if aDateTimeInputType should be supported based on "dom.forms.datetime",
* "dom.forms.datepicker" and "dom.experimental_forms".
*/
static bool
IsDateTimeTypeSupported(uint8_t aDateTimeInputType);

/**
* Checks preference "dom.webkitBlink.dirPicker.enabled" to determine if
* webkitdirectory should be supported.
*/
static bool
IsWebkitDirPickerEnabled();

/**
* Checks preference "dom.webkitBlink.filesystem.enabled" to determine if
* webkitEntries should be supported.
*/
static bool
IsWebkitFileSystemEnabled();

/**
* Checks preference "dom.input.dirpicker" to determine if file and directory
* entries API should be supported.
*/
static bool
IsDirPickerEnabled();

/**
* Checks preference "dom.forms.datepicker" to determine if date picker should
* be supported.
*/
static bool
IsDatePickerEnabled();

/**
* Checks preference "dom.experimental_forms" to determine if experimental
* implementation of input element should be enabled.
*/
static bool
IsExperimentalFormsEnabled();

/**
* Checks preference "dom.forms.datetime" to determine if input date/time
* related types should be supported.
*/
static bool
IsInputDateTimeEnabled();

/**
* Checks preference "dom.forms.number" to determine if input type=number
* should be supported.
*/
static bool
IsInputNumberEnabled();

/**
* Checks preference "dom.forms.color" to determine if date/time related
* types should be supported.
*/
static bool
IsInputColorEnabled();

struct nsFilePickerFilter {
nsFilePickerFilter()
: mFilterMask(0) {}
Expand Down
2 changes: 2 additions & 0 deletions dom/html/test/forms/mochitest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ skip-if = android_version == '18' # Android, bug 1147974
skip-if = android_version == '18' # Android, bug 1147974
[test_input_date_key_events.html]
skip-if = os == "android"
[test_input_datetime_input_change_events.html]
skip-if = os == "android"
[test_input_datetime_focus_blur.html]
skip-if = os == "android"
[test_input_datetime_focus_blur_events.html]
Expand Down
Loading

0 comments on commit e254301

Please sign in to comment.