From 054dde272820f12b4f3c60ee4c8b7ede47126aa6 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 15 Apr 2018 14:39:19 +0200 Subject: Bug 1344642 - Part 1: Cleanup dom.forms.datepicker related code --- dom/html/HTMLInputElement.cpp | 137 +-------------------- dom/html/HTMLInputElement.h | 10 +- dom/html/test/forms/test_input_types_pref.html | 14 +-- dom/html/test/forms/test_valueAsDate_pref.html | 16 ++- dom/ipc/DatePickerParent.cpp | 87 ------------- dom/ipc/DatePickerParent.h | 61 --------- dom/ipc/PBrowser.ipdl | 8 -- dom/ipc/PDatePicker.ipdl | 27 ---- dom/ipc/TabChild.cpp | 16 --- dom/ipc/TabChild.h | 4 - dom/ipc/TabParent.cpp | 15 --- dom/ipc/TabParent.h | 4 - dom/ipc/moz.build | 2 - .../en-US/chrome/layout/HtmlForm.properties | 1 - widget/moz.build | 2 - widget/nsContentProcessWidgetFactory.cpp | 6 - widget/nsDatePickerProxy.cpp | 61 --------- widget/nsDatePickerProxy.h | 33 ----- widget/nsIDatePicker.idl | 50 -------- widget/nsWidgetsCID.h | 5 - 20 files changed, 16 insertions(+), 543 deletions(-) delete mode 100644 dom/ipc/DatePickerParent.cpp delete mode 100644 dom/ipc/DatePickerParent.h delete mode 100644 dom/ipc/PDatePicker.ipdl delete mode 100644 widget/nsDatePickerProxy.cpp delete mode 100644 widget/nsDatePickerProxy.h delete mode 100644 widget/nsIDatePicker.idl diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index f1a54705e..3a3136a60 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -114,15 +114,12 @@ #include #include "nsIColorPicker.h" -#include "nsIDatePicker.h" #include "nsIStringEnumerator.h" #include "HTMLSplitOnSpacesTokenizer.h" #include "nsIController.h" #include "nsIMIMEInfo.h" #include "nsFrameSelection.h" -#include "nsIConsoleService.h" - // input type=date #include "js/Date.h" @@ -543,8 +540,7 @@ GetDOMFileOrDirectoryPath(const OwningFileOrDirectory& aData, bool HTMLInputElement::ValueAsDateEnabled(JSContext* cx, JSObject* obj) { - return IsExperimentalFormsEnabled() || IsDatePickerEnabled() || - IsInputDateTimeEnabled(); + return IsExperimentalFormsEnabled() || IsInputDateTimeEnabled(); } NS_IMETHODIMP @@ -746,59 +742,6 @@ nsColorPickerShownCallback::Done(const nsAString& aColor) NS_IMPL_ISUPPORTS(nsColorPickerShownCallback, nsIColorPickerShownCallback) -class DatePickerShownCallback final : public nsIDatePickerShownCallback -{ - ~DatePickerShownCallback() {} -public: - DatePickerShownCallback(HTMLInputElement* aInput, - nsIDatePicker* aDatePicker) - : mInput(aInput) - , mDatePicker(aDatePicker) - {} - - NS_DECL_ISUPPORTS - - NS_IMETHOD Done(const nsAString& aDate) override; - NS_IMETHOD Cancel() override; - -private: - RefPtr mInput; - nsCOMPtr mDatePicker; -}; - -NS_IMETHODIMP -DatePickerShownCallback::Cancel() -{ - mInput->PickerClosed(); - return NS_OK; -} - -NS_IMETHODIMP -DatePickerShownCallback::Done(const nsAString& aDate) -{ - nsAutoString oldValue; - - mInput->PickerClosed(); - mInput->GetValue(oldValue); - - if(!oldValue.Equals(aDate)){ - mInput->SetValue(aDate); - nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(), - static_cast(mInput.get()), - NS_LITERAL_STRING("input"), true, - false); - return nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(), - static_cast(mInput.get()), - NS_LITERAL_STRING("change"), true, - false); - } - - return NS_OK; -} - -NS_IMPL_ISUPPORTS(DatePickerShownCallback, nsIDatePickerShownCallback) - - bool HTMLInputElement::IsPopupBlocked() const { @@ -823,56 +766,6 @@ HTMLInputElement::IsPopupBlocked() const return permission == nsIPopupWindowManager::DENY_POPUP; } -nsresult -HTMLInputElement::InitDatePicker() -{ - if (!IsDatePickerEnabled()) { - return NS_OK; - } - - if (mPickerRunning) { - NS_WARNING("Just one nsIDatePicker is allowed"); - return NS_ERROR_FAILURE; - } - - nsCOMPtr doc = OwnerDoc(); - - nsCOMPtr win = doc->GetWindow(); - if (!win) { - return NS_ERROR_FAILURE; - } - - if (IsPopupBlocked()) { - win->FirePopupBlockedEvent(doc, nullptr, EmptyString(), EmptyString()); - return NS_OK; - } - - // Get Loc title - nsXPIDLString title; - nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, - "DatePicker", title); - - nsresult rv; - nsCOMPtr datePicker = do_CreateInstance("@mozilla.org/datepicker;1", &rv); - if (!datePicker) { - return rv; - } - - nsAutoString initialValue; - GetValueInternal(initialValue); - rv = datePicker->Init(win, title, initialValue); - - nsCOMPtr callback = - new DatePickerShownCallback(this, datePicker); - - rv = datePicker->Open(callback); - if (NS_SUCCEEDED(rv)) { - mPickerRunning = true; - } - - return rv; -} - nsresult HTMLInputElement::InitColorPicker() { @@ -2570,9 +2463,8 @@ HTMLInputElement::ApplyStep(int32_t aStep) bool HTMLInputElement::IsExperimentalMobileType(uint8_t aType) { - return (aType == NS_FORM_INPUT_DATE && - !IsInputDateTimeEnabled() && !IsDatePickerEnabled()) || - (aType == NS_FORM_INPUT_TIME && !IsInputDateTimeEnabled()); + return (aType == NS_FORM_INPUT_DATE || aType == NS_FORM_INPUT_TIME) && + !IsInputDateTimeEnabled(); } bool @@ -4429,9 +4321,6 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor) if (mType == NS_FORM_INPUT_COLOR) { return InitColorPicker(); } - if (mType == NS_FORM_INPUT_DATE) { - return InitDatePicker(); - } return NS_OK; } @@ -5814,10 +5703,8 @@ HTMLInputElement::ParseTime(const nsAString& aValue, uint32_t* aResult) /* static */ bool HTMLInputElement::IsDateTimeTypeSupported(uint8_t aDateTimeInputType) { - return (aDateTimeInputType == NS_FORM_INPUT_DATE && - (IsInputDateTimeEnabled() || IsExperimentalFormsEnabled() || - IsDatePickerEnabled())) || - (aDateTimeInputType == NS_FORM_INPUT_TIME && + return ((aDateTimeInputType == NS_FORM_INPUT_DATE || + aDateTimeInputType == NS_FORM_INPUT_TIME) && (IsInputDateTimeEnabled() || IsExperimentalFormsEnabled())) || ((aDateTimeInputType == NS_FORM_INPUT_MONTH || aDateTimeInputType == NS_FORM_INPUT_WEEK || @@ -5869,20 +5756,6 @@ HTMLInputElement::IsDirPickerEnabled() 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() { diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index adab663c3..305b76556 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -1451,7 +1451,6 @@ protected: }; nsresult InitFilePicker(FilePickerType aType); nsresult InitColorPicker(); - nsresult InitDatePicker(); /** * Use this function before trying to open a picker. @@ -1647,7 +1646,7 @@ private: /** * Checks if aDateTimeInputType should be supported based on "dom.forms.datetime", - * "dom.forms.datepicker" and "dom.experimental_forms". + * and "dom.experimental_forms". */ static bool IsDateTimeTypeSupported(uint8_t aDateTimeInputType); @@ -1673,13 +1672,6 @@ private: 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. diff --git a/dom/html/test/forms/test_input_types_pref.html b/dom/html/test/forms/test_input_types_pref.html index 243836f34..73c4d65ab 100644 --- a/dom/html/test/forms/test_input_types_pref.html +++ b/dom/html/test/forms/test_input_types_pref.html @@ -37,23 +37,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=764481 inputType: "color", expectedType: "color" }, { - prefs: [["dom.experimental_forms", false], ["dom.forms.datepicker", false], - ["dom.forms.datetime", false]], + prefs: [["dom.experimental_forms", false], ["dom.forms.datetime", false]], inputType: "date", expectedType: "text" }, { - prefs: [["dom.experimental_forms", true], ["dom.forms.datepicker", false], - ["dom.forms.datetime", false]], + prefs: [["dom.experimental_forms", true], ["dom.forms.datetime", false]], inputType: "date", expectedType: "date" }, { - prefs: [["dom.experimental_forms", false], ["dom.forms.datepicker", true], - ["dom.forms.datetime", false]], - inputType: "date", - expectedType: "date" - }, { - prefs: [["dom.experimental_forms", false], ["dom.forms.datepicker", false], - ["dom.forms.datetime", true]], + prefs: [["dom.experimental_forms", false], ["dom.forms.datetime", true]], inputType: "date", expectedType: "date" }, { diff --git a/dom/html/test/forms/test_valueAsDate_pref.html b/dom/html/test/forms/test_valueAsDate_pref.html index 8518c291b..91e2e1bfc 100644 --- a/dom/html/test/forms/test_valueAsDate_pref.html +++ b/dom/html/test/forms/test_valueAsDate_pref.html @@ -12,12 +12,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874640 /** Test for Bug 874640 **/ var states = [ - // dom.experimental_forms, dom.forms.datepicker, dom.forms.datetime, expectedValueAsDate - [ 'true', 'true', 'true', 'true' ], - [ 'true', 'false', 'false', 'true' ], - [ 'false', 'true', 'false', 'true' ], - [ 'false', 'false', 'true', 'true' ], - [ 'false', 'false', 'false', 'false' ], + // dom.experimental_forms, dom.forms.datetime, expectedValueAsDate + [ 'true', 'true', 'true' ], + [ 'true', 'false', 'true' ], + [ 'false', 'true', 'true' ], + [ 'false', 'false', 'false' ], 'end' ]; @@ -33,12 +32,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874640 SpecialPowers.pushPrefEnv({"set":[ ["dom.experimental_forms", state[0] === 'true'], - ["dom.forms.datepicker", state[1] === 'true'], - ["dom.forms.datetime", state[2] === 'true']]}, + ["dom.forms.datetime", state[1] === 'true']]}, function() { iframe.src = 'data:text/html,