Bug 825294 - Add framework for datepicker widgets to input[type=date]. r=smaug

-Add framework for datepicker widgets
-Split date input preference from dom.experimental_forms to dom.forms.date
This commit is contained in:
Jordan 2016-06-20 15:55:00 +02:00
parent 05dcd227c5
commit f35a9b375c
21 changed files with 546 additions and 19 deletions

View File

@ -112,12 +112,15 @@
#include <limits>
#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"
@ -938,6 +941,13 @@ GetDOMFileOrDirectoryPath(const OwningFileOrDirectory& aData,
} // namespace
/* static */
bool
HTMLInputElement::ValueAsDateEnabled(JSContext* cx, JSObject* obj)
{
return Preferences::GetBool("dom.experimental_forms", false) ||
Preferences::GetBool("dom.forms.datepicker", false);
}
NS_IMETHODIMP
HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult)
@ -1141,6 +1151,59 @@ 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<HTMLInputElement> mInput;
nsCOMPtr<nsIDatePicker> 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<nsIDOMHTMLInputElement*>(mInput.get()),
NS_LITERAL_STRING("input"), true,
false);
return nsContentUtils::DispatchTrustedEvent(mInput->OwnerDoc(),
static_cast<nsIDOMHTMLInputElement*>(mInput.get()),
NS_LITERAL_STRING("change"), true,
false);
}
return NS_OK;
}
NS_IMPL_ISUPPORTS(DatePickerShownCallback, nsIDatePickerShownCallback)
bool
HTMLInputElement::IsPopupBlocked() const
{
@ -1165,6 +1228,56 @@ HTMLInputElement::IsPopupBlocked() const
return permission == nsIPopupWindowManager::DENY_POPUP;
}
nsresult
HTMLInputElement::InitDatePicker()
{
if (!Preferences::GetBool("dom.forms.datepicker", false)) {
return NS_OK;
}
if (mPickerRunning) {
NS_WARNING("Just one nsIDatePicker is allowed");
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIDocument> doc = OwnerDoc();
nsCOMPtr<nsPIDOMWindowOuter> 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<nsIDatePicker> datePicker = do_CreateInstance("@mozilla.org/datepicker;1", &rv);
if (!datePicker) {
return rv;
}
nsAutoString initialValue;
GetValueInternal(initialValue);
rv = datePicker->Init(win, title, initialValue);
nsCOMPtr<nsIDatePickerShownCallback> callback =
new DatePickerShownCallback(this, datePicker);
rv = datePicker->Open(callback);
if (NS_SUCCEEDED(rv)) {
mPickerRunning = true;
}
return rv;
}
nsresult
HTMLInputElement::InitColorPicker()
{
@ -2020,7 +2133,8 @@ HTMLInputElement::GetValue(nsAString& aValue)
}
// Don't return non-sanitized value for types that are experimental on mobile.
if (IsExperimentalMobileType(mType)) {
// or date types
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
SanitizeValue(aValue);
}
@ -2654,6 +2768,15 @@ HTMLInputElement::ApplyStep(int32_t aStep)
return rv;
}
/* static */
bool
HTMLInputElement::IsExperimentalMobileType(uint8_t aType)
{
return aType == NS_FORM_INPUT_TIME ||
(aType == NS_FORM_INPUT_DATE &&
!Preferences::GetBool("dom.forms.datepicker", false));
}
NS_IMETHODIMP
HTMLInputElement::StepDown(int32_t n, uint8_t optional_argc)
{
@ -2843,7 +2966,7 @@ bool
HTMLInputElement::MozIsTextField(bool aExcludePassword)
{
// TODO: temporary until bug 773205 is fixed.
if (IsExperimentalMobileType(mType)) {
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
return false;
}
@ -3875,7 +3998,7 @@ HTMLInputElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
// Experimental mobile types rely on the system UI to prevent users to not
// set invalid values but we have to be extra-careful. Especially if the
// option has been enabled on desktop.
if (IsExperimentalMobileType(mType)) {
if (IsExperimentalMobileType(mType) || mType == NS_FORM_INPUT_DATE) {
nsAutoString aValue;
GetValueInternal(aValue);
nsresult rv =
@ -4291,6 +4414,10 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor)
if (mType == NS_FORM_INPUT_COLOR) {
return InitColorPicker();
}
if (mType == NS_FORM_INPUT_DATE) {
return InitDatePicker();
}
return NS_OK;
}
@ -4572,7 +4699,8 @@ HTMLInputElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
keyEvent->mKeyCode == NS_VK_RETURN &&
(IsSingleLineTextControl(false, mType) ||
mType == NS_FORM_INPUT_NUMBER ||
IsExperimentalMobileType(mType))) {
IsExperimentalMobileType(mType) ||
mType == NS_FORM_INPUT_DATE)) {
FireChangeEventIfNeeded();
rv = MaybeSubmitForm(aVisitor.mPresContext);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -270,6 +270,9 @@ public:
static void InitUploadLastDir();
static void DestroyUploadLastDir();
//If the valueAsDate attribute should be enabled in webIDL
static bool ValueAsDateEnabled(JSContext* cx, JSObject* obj);
void MaybeLoadImage();
void SetSelectionProperties(const nsTextEditorState::SelectionProperties& aProps)
@ -1246,10 +1249,7 @@ protected:
/**
* Returns if the current type is an experimental mobile type.
*/
static bool IsExperimentalMobileType(uint8_t aType)
{
return aType == NS_FORM_INPUT_DATE || aType == NS_FORM_INPUT_TIME;
}
static bool IsExperimentalMobileType(uint8_t aType);
/**
* Flushes the layout frame tree to make sure we have up-to-date frames.
@ -1276,6 +1276,7 @@ protected:
};
nsresult InitFilePicker(FilePickerType aType);
nsresult InitColorPicker();
nsresult InitDatePicker();
/**
* Use this function before trying to open a picker.

View File

@ -20,23 +20,31 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=764481
var input = document.createElement("input");
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", false]]}, function() {
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms", false], ["dom.forms.datepicker",false]]}, function() {
input.type = "date";
is(input.type, "text", "input type shouldn't be date when the experimental forms are disabled");
is(input.getAttribute('type'), "date", "input 'type' attribute should not change");
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms",true]]}, function() {
// Change the type of input to text and then back to date,
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms",true], ["dom.forms.datepicker",false]]}, function() {
// Change the type of input to text and then back to date,
// so that HTMLInputElement::ParseAttribute gets called with the pref enabled.
input.type = "text";
input.type = "date";
is(input.type, "date", "input type should be date when the experimental forms are enabled");
is(input.getAttribute('type'), "date", "input 'type' attribute should not change");
SimpleTest.finish();
SpecialPowers.pushPrefEnv({'set': [["dom.experimental_forms",false], ["dom.forms.datepicker",true]]}, function() {
// Change the type of input to text and then back to date,
// so that HTMLInputElement::ParseAttribute gets called with the pref enabled.
input.type = "text";
input.type = "date";
is(input.type, "date", "input type should be date when the datepicker is enabled");
is(input.getAttribute('type'), "date", "input 'type' attribute should not change");
SimpleTest.finish();
});
});
});
</script>
</pre>
</body>

View File

@ -11,8 +11,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874640
<script type="application/javascript">
/** Test for Bug 874640 **/
var states = [ 'true', 'false', 'end' ];
var pref = SpecialPowers.getBoolPref("dom.experimental_forms");
var states = [
//dom.experimental_forms, dom.forms.datepicker, expectedValueAsDate
[ 'true', 'true', 'true' ],
[ 'true', 'false', 'true' ],
[ 'false', 'true', 'true' ],
[ 'false', 'false', 'false' ],
'end'
];
SimpleTest.waitForExplicitFinish();
@ -24,11 +30,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874640
return;
}
SpecialPowers.pushPrefEnv({"set":[["dom.experimental_forms", state === 'true']]},
SpecialPowers.pushPrefEnv({"set":[
["dom.experimental_forms", state[0] === 'true'],
["dom.forms.datepicker", state[1] === 'true']]},
function() {
iframe.src = 'data:text/html,<script>' +
'parent.is("valueAsDate" in document.createElement("input"), ' +
state + ', "valueAsDate presence state should be ' + state + '");' +
state[2] + ', "valueAsDate presence state should be ' + state[2] + '");' +
'<\/script>'
});
}

View File

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "DatePickerParent.h"
#include "nsComponentManagerUtils.h"
#include "nsIDocument.h"
#include "nsIDOMWindow.h"
#include "mozilla/unused.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"
using mozilla::Unused;
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS(DatePickerParent::DatePickerShownCallback,
nsIDatePickerShownCallback);
NS_IMETHODIMP
DatePickerParent::DatePickerShownCallback::Cancel()
{
if (mDatePickerParent) {
Unused << mDatePickerParent->SendCancel();
}
return NS_OK;
}
NS_IMETHODIMP
DatePickerParent::DatePickerShownCallback::Done(const nsAString& aDate)
{
if (mDatePickerParent) {
Unused << mDatePickerParent->Send__delete__(mDatePickerParent,
nsString(aDate));
}
return NS_OK;
}
void
DatePickerParent::DatePickerShownCallback::Destroy()
{
mDatePickerParent = nullptr;
}
bool
DatePickerParent::CreateDatePicker()
{
mPicker = do_CreateInstance("@mozilla.org/datepicker;1");
if (!mPicker) {
return false;
}
Element* ownerElement = TabParent::GetFrom(Manager())->GetOwnerElement();
if (!ownerElement) {
return false;
}
nsCOMPtr<mozIDOMWindowProxy> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow());
if (!window) {
return false;
}
return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialDate));
}
bool
DatePickerParent::RecvOpen()
{
if (!CreateDatePicker()) {
Unused << Send__delete__(this, mInitialDate);
return true;
}
mCallback = new DatePickerShownCallback(this);
mPicker->Open(mCallback);
return true;
};
void
DatePickerParent::ActorDestroy(ActorDestroyReason aWhy)
{
if (mCallback) {
mCallback->Destroy();
}
}

View File

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_DatePickerParent_h
#define mozilla_dom_DatePickerParent_h
#include "mozilla/dom/PDatePickerParent.h"
#include "nsIDatePicker.h"
namespace mozilla {
namespace dom {
class DatePickerParent : public PDatePickerParent
{
public:
DatePickerParent(const nsString& aTitle,
const nsString& aInitialDate)
: mTitle(aTitle)
, mInitialDate(aInitialDate)
{}
virtual bool RecvOpen() override;
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
class DatePickerShownCallback final
: public nsIDatePickerShownCallback
{
public:
explicit DatePickerShownCallback(DatePickerParent* aDatePickerParnet)
: mDatePickerParent(aDatePickerParnet)
{}
NS_DECL_ISUPPORTS
NS_DECL_NSIDATEPICKERSHOWNCALLBACK
void Destroy();
private:
~DatePickerShownCallback() {}
DatePickerParent* mDatePickerParent;
};
private:
virtual ~DatePickerParent() {}
bool CreateDatePicker();
RefPtr<DatePickerShownCallback> mCallback;
nsCOMPtr<nsIDatePicker> mPicker;
nsString mTitle;
nsString mInitialDate;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_DatePickerParent_h

View File

@ -9,6 +9,7 @@ include protocol PBlob;
include protocol PColorPicker;
include protocol PContent;
include protocol PContentBridge;
include protocol PDatePicker;
include protocol PDocAccessible;
include protocol PDocumentRenderer;
include protocol PFilePicker;
@ -111,6 +112,7 @@ prio(normal upto urgent) sync protocol PBrowser
manager PContent or PContentBridge;
manages PColorPicker;
manages PDatePicker;
manages PDocAccessible;
manages PDocumentRenderer;
manages PFilePicker;
@ -420,6 +422,12 @@ parent:
*/
async PColorPicker(nsString title, nsString initialColor);
/**
* Create an asynchronous date picker on the parent side,
* but don't open it yet.
*/
async PDatePicker(nsString title, nsString initialDate);
async PFilePicker(nsString aTitle, int16_t aMode);
/**

27
dom/ipc/PDatePicker.ipdl Normal file
View File

@ -0,0 +1,27 @@
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8 -*- */
/* vim: set sw=4 ts=8 et tw=80 ft=cpp : */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
include protocol PBrowser;
namespace mozilla {
namespace dom {
protocol PDatePicker
{
manager PBrowser;
parent:
async Open();
child:
async Cancel();
async __delete__(nsString color);
};
} // namespace dom
} // namespace mozilla

View File

@ -102,6 +102,7 @@
#include "nsIOService.h"
#include "nsDOMClassInfoID.h"
#include "nsColorPickerProxy.h"
#include "nsDatePickerProxy.h"
#include "nsContentPermissionHelper.h"
#include "nsPresShell.h"
#include "nsIAppsService.h"
@ -2284,6 +2285,21 @@ TabChild::DeallocPColorPickerChild(PColorPickerChild* aColorPicker)
return true;
}
PDatePickerChild*
TabChild::AllocPDatePickerChild(const nsString&, const nsString&)
{
NS_RUNTIMEABORT("unused");
return nullptr;
}
bool
TabChild::DeallocPDatePickerChild(PDatePickerChild* aDatePicker)
{
nsDatePickerProxy* picker = static_cast<nsDatePickerProxy*>(aDatePicker);
NS_RELEASE(picker);
return true;
}
PFilePickerChild*
TabChild::AllocPFilePickerChild(const nsString&, const int16_t&)
{

View File

@ -453,6 +453,10 @@ public:
virtual bool DeallocPColorPickerChild(PColorPickerChild* aActor) override;
virtual PDatePickerChild*
AllocPDatePickerChild(const nsString& title, const nsString& initialDate) override;
virtual bool DeallocPDatePickerChild(PDatePickerChild* actor) override;
virtual PFilePickerChild*
AllocPFilePickerChild(const nsString& aTitle, const int16_t& aMode) override;

View File

@ -80,6 +80,7 @@
#include "PermissionMessageUtils.h"
#include "StructuredCloneData.h"
#include "ColorPickerParent.h"
#include "DatePickerParent.h"
#include "FilePickerParent.h"
#include "TabChild.h"
#include "LoadContext.h"
@ -2587,6 +2588,20 @@ TabParent::DeallocPColorPickerParent(PColorPickerParent* actor)
return true;
}
PDatePickerParent*
TabParent::AllocPDatePickerParent(const nsString& aTitle,
const nsString& aInitialDate)
{
return new DatePickerParent(aTitle, aInitialDate);
}
bool
TabParent::DeallocPDatePickerParent(PDatePickerParent* actor)
{
delete actor;
return true;
}
PRenderFrameParent*
TabParent::AllocPRenderFrameParent()
{

View File

@ -379,6 +379,10 @@ public:
virtual bool
DeallocPColorPickerParent(PColorPickerParent* aColorPicker) override;
virtual PDatePickerParent*
AllocPDatePickerParent(const nsString& aTitle, const nsString& aInitialDate) override;
virtual bool DeallocPDatePickerParent(PDatePickerParent* aDatePicker) override;
virtual PDocAccessibleParent*
AllocPDocAccessibleParent(PDocAccessibleParent*, const uint64_t&) override;

View File

@ -61,6 +61,7 @@ UNIFIED_SOURCES += [
'ContentProcess.cpp',
'ContentProcessManager.cpp',
'CrashReporterParent.cpp',
'DatePickerParent.cpp',
'FilePickerParent.cpp',
'nsIContentChild.cpp',
'nsIContentParent.cpp',
@ -102,6 +103,7 @@ IPDL_SOURCES += [
'PContentPermissionRequest.ipdl',
'PCrashReporter.ipdl',
'PCycleCollectWithLogs.ipdl',
'PDatePicker.ipdl',
'PDocumentRenderer.ipdl',
'PFilePicker.ipdl',
'PMemoryReportRequest.ipdl',

View File

@ -30,6 +30,7 @@ NoFilesSelected=No files selected.
# %S will be a number greater or equal to 2.
XFilesSelected=%S files selected.
ColorPicker=Choose a color
DatePicker=Choose a date
# LOCALIZATION NOTE (AndNMoreFiles): Semi-colon list of plural forms.
# See: http://developer.mozilla.org/en/docs/Localization_and_Plurals
# This string is shown at the end of the tooltip text for <input type='file'

View File

@ -88,7 +88,7 @@ interface HTMLInputElement : HTMLElement {
attribute DOMString defaultValue;
[Pure, TreatNullAs=EmptyString, Throws]
attribute DOMString value;
[Throws, Pref="dom.experimental_forms"]
[Throws, Func="HTMLInputElement::ValueAsDateEnabled"]
attribute Date? valueAsDate;
[Pure, SetterThrows]
attribute unrestricted double valueAsNumber;

View File

@ -65,6 +65,7 @@ XPIDL_SOURCES += [
'nsIClipboardHelper.idl',
'nsIClipboardOwner.idl',
'nsIColorPicker.idl',
'nsIDatePicker.idl',
'nsIDisplayInfo.idl',
'nsIDragService.idl',
'nsIDragSession.idl',
@ -147,6 +148,7 @@ UNIFIED_SOURCES += [
'nsClipboardProxy.cpp',
'nsColorPickerProxy.cpp',
'nsContentProcessWidgetFactory.cpp',
'nsDatePickerProxy.cpp',
'nsDragServiceProxy.cpp',
'nsFilePickerProxy.cpp',
'nsHTMLFormatConverter.cpp',

View File

@ -9,6 +9,7 @@
#include "nsWidgetsCID.h"
#include "nsClipboardProxy.h"
#include "nsColorPickerProxy.h"
#include "nsDatePickerProxy.h"
#include "nsDragServiceProxy.h"
#include "nsFilePickerProxy.h"
#include "nsScreenManagerProxy.h"
@ -21,6 +22,7 @@ using namespace mozilla::widget;
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardProxy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsColorPickerProxy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDatePickerProxy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragServiceProxy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePickerProxy)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerProxy)
@ -28,6 +30,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(PuppetBidiKeyboard)
NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID);
NS_DEFINE_NAMED_CID(NS_DATEPICKER_CID);
NS_DEFINE_NAMED_CID(NS_DRAGSERVICE_CID);
NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
NS_DEFINE_NAMED_CID(PUPPETBIDIKEYBOARD_CID);
@ -38,6 +41,8 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
Module::CONTENT_PROCESS_ONLY },
{ &kNS_COLORPICKER_CID, false, nullptr, nsColorPickerProxyConstructor,
Module::CONTENT_PROCESS_ONLY },
{ &kNS_DATEPICKER_CID, false, nullptr, nsDatePickerProxyConstructor,
Module::CONTENT_PROCESS_ONLY },
{ &kNS_DRAGSERVICE_CID, false, nullptr, nsDragServiceProxyConstructor,
Module::CONTENT_PROCESS_ONLY },
{ &kNS_FILEPICKER_CID, false, nullptr, nsFilePickerProxyConstructor,
@ -52,6 +57,7 @@ static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
static const mozilla::Module::ContractIDEntry kWidgetContracts[] = {
{ "@mozilla.org/widget/clipboard;1", &kNS_CLIPBOARD_CID, Module::CONTENT_PROCESS_ONLY },
{ "@mozilla.org/colorpicker;1", &kNS_COLORPICKER_CID, Module::CONTENT_PROCESS_ONLY },
{ "@mozilla.org/datepicker;1", &kNS_DATEPICKER_CID, Module::CONTENT_PROCESS_ONLY },
{ "@mozilla.org/filepicker;1", &kNS_FILEPICKER_CID, Module::CONTENT_PROCESS_ONLY },
{ "@mozilla.org/gfx/screenmanager;1", &kNS_SCREENMANAGER_CID, Module::CONTENT_PROCESS_ONLY },
{ "@mozilla.org/widget/dragservice;1", &kNS_DRAGSERVICE_CID, Module::CONTENT_PROCESS_ONLY },

View File

@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsDatePickerProxy.h"
#include "mozilla/dom/TabChild.h"
using namespace mozilla::dom;
NS_IMPL_ISUPPORTS(nsDatePickerProxy, nsIDatePicker)
/* void init (in nsIDOMWindow parent, in AString title, in short mode); */
NS_IMETHODIMP
nsDatePickerProxy::Init(mozIDOMWindowProxy* aParent, const nsAString& aTitle,
const nsAString& aInitialDate)
{
TabChild* tabChild = TabChild::GetFrom(aParent);
if (!tabChild) {
return NS_ERROR_FAILURE;
}
tabChild->SendPDatePickerConstructor(this,
nsString(aTitle),
nsString(aInitialDate));
NS_ADDREF_THIS(); //Released in DeallocPDatePickerChild
return NS_OK;
}
/* void open (in nsIDatePickerShownCallback aDatePickerShownCallback); */
NS_IMETHODIMP
nsDatePickerProxy::Open(nsIDatePickerShownCallback* aDatePickerShownCallback)
{
NS_ENSURE_STATE(!mCallback);
mCallback = aDatePickerShownCallback;
SendOpen();
return NS_OK;
}
bool
nsDatePickerProxy::RecvCancel()
{
if (mCallback) {
mCallback->Cancel();
mCallback = nullptr;
}
return true;
}
bool
nsDatePickerProxy::Recv__delete__(const nsString& aDate)
{
if (mCallback) {
mCallback->Done(aDate);
mCallback = nullptr;
}
return true;
}

View File

@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsDatePickerProxy_h
#define nsDatePickerProxy_h
#include "nsIDatePicker.h"
#include "mozilla/dom/PDatePickerChild.h"
class nsDatePickerProxy final : public nsIDatePicker,
public mozilla::dom::PDatePickerChild
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDATEPICKER
nsDatePickerProxy() {}
virtual bool RecvCancel() override;
virtual bool Recv__delete__(const nsString& aDate) override;
private:
~nsDatePickerProxy() {}
nsCOMPtr<nsIDatePickerShownCallback> mCallback;
nsString mTitle;
nsString mInitialDate;
};
#endif // nsDatePickerProxy_h

50
widget/nsIDatePicker.idl Normal file
View File

@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsISupports.idl"
interface mozIDOMWindowProxy;
[scriptable, uuid(13388a28-1b0b-4218-a31b-588f7a4ec26c)]
interface nsIDatePickerShownCallback : nsISupports
{
/**
* Callback called when the user selects cancel in the date picker
* This callback can not be called after done() is called.
*/
void cancel();
/**
* Callback called when the user has finished selecting the date
*
* @param date The new selected date value following the format "YYYY-MM-DD"
*/
void done(in AString date);
};
[scriptable, uuid(7becfc64-966b-4d53-87d2-9161f36bd3b3)]
interface nsIDatePicker : nsISupports
{
/**
* Initialize the date picker widget. The date picker will not be shown until
* open() is called.
* If the initialDate parameter does not follow the format "YYYY-MM-DD" then
* the behavior will be unspecified.
*
* @param parent nsIDOMWindow parent. This dialog will be dependent
* on this parent. parent may be null.
* @param title The title for the date picker widget.
* @param initialDate The date to show when the widget is opened. The
* parameter has to follow the format "YYYY-MM-DD"
*/
void init(in mozIDOMWindowProxy parent, in AString title, in AString initialDate);
/**
* Opens the date dialog asynchrounously.
* The results are provided via the callback object.
*/
void open(in nsIDatePickerShownCallback callback);
};

View File

@ -33,6 +33,11 @@
{ 0x0f872c8c, 0x3ee6, 0x46bd, \
{ 0x92, 0xa2, 0x69, 0x65, 0x2c, 0x6b, 0x47, 0x4e } }
/* 0ca832f8-978a-4dc7-a57d-adb803925d39 */
#define NS_DATEPICKER_CID \
{ 0x0ca832f8, 0x978a, 0x4dc7, \
{ 0xa5, 0x7d, 0xad, 0xb8, 0x03, 0x92, 0x5d, 0x39 } }
/* 2d96b3df-c051-11d1-a827-0040959a28c9 */
#define NS_APPSHELL_CID \
{ 0x2d96b3df, 0xc051, 0x11d1, \