mirror of
https://github.com/classilla/tenfourfox.git
synced 2024-12-29 02:31:05 +00:00
#405: date picker abstract interface definition
This commit is contained in:
parent
aebc3385bd
commit
6e6ed0b4ba
@ -65,6 +65,7 @@ XPIDL_SOURCES += [
|
||||
'nsIClipboardHelper.idl',
|
||||
'nsIClipboardOwner.idl',
|
||||
'nsIColorPicker.idl',
|
||||
'nsIDatePicker.idl',
|
||||
'nsIDisplayInfo.idl',
|
||||
'nsIDragService.idl',
|
||||
'nsIDragSession.idl',
|
||||
@ -197,6 +198,11 @@ if CONFIG['MOZ_X11']:
|
||||
'GfxInfoX11.cpp'
|
||||
]
|
||||
|
||||
if toolkit == 'cocoa':
|
||||
SOURCES += [
|
||||
'nsBaseDatePicker.cpp',
|
||||
]
|
||||
|
||||
if toolkit in ('cocoa', 'windows'):
|
||||
UNIFIED_SOURCES += [
|
||||
'nsBaseClipboard.cpp',
|
||||
|
98
widget/nsBaseDatePicker.cpp
Normal file
98
widget/nsBaseDatePicker.cpp
Normal file
@ -0,0 +1,98 @@
|
||||
/* -*- 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 "nsCOMPtr.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIBaseWindow.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMArray.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "WidgetUtils.h"
|
||||
#include "nsThreadUtils.h"
|
||||
|
||||
#include "nsBaseDatePicker.h"
|
||||
|
||||
using namespace mozilla::widget;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/**
|
||||
* A runnable to dispatch from the main thread to the main thread to display
|
||||
* the date picker while letting the showAsync method return right away.
|
||||
*/
|
||||
class AsyncShowDatePicker : public nsRunnable
|
||||
{
|
||||
public:
|
||||
AsyncShowDatePicker(nsIDatePicker *aDatePicker,
|
||||
nsIDatePickerShownCallback *aCallback) :
|
||||
mDatePicker(aDatePicker),
|
||||
mCallback(aCallback)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHOD Run()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(),
|
||||
"AsyncShowDatePicker should be on the main thread!");
|
||||
|
||||
// It's possible that some widget implementations require GUI operations
|
||||
// to be on the main thread, so that's why we're not dispatching to another
|
||||
// thread and calling back to the main after it's done.
|
||||
int16_t result = nsIDatePicker::returnCancel;
|
||||
nsresult rv = mDatePicker->Show(&result);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("DatePicker's Show() implementation failed!");
|
||||
}
|
||||
|
||||
if (mCallback) {
|
||||
mCallback->Done(result);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<nsIDatePicker> mDatePicker;
|
||||
RefPtr<nsIDatePickerShownCallback> mCallback;
|
||||
};
|
||||
|
||||
nsBaseDatePicker::nsBaseDatePicker()
|
||||
{
|
||||
}
|
||||
|
||||
nsBaseDatePicker::~nsBaseDatePicker()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsBaseDatePicker::Init(nsIDOMWindow *aParent,
|
||||
const nsAString& aTitle)
|
||||
{
|
||||
NS_PRECONDITION(aParent, "Null parent passed to datepicker, no date "
|
||||
"picker for you!");
|
||||
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(aParent);
|
||||
NS_ENSURE_TRUE(widget, NS_ERROR_FAILURE);
|
||||
|
||||
mParent = do_QueryInterface(aParent);
|
||||
if (!mParent->IsInnerWindow()) {
|
||||
mParent = mParent->GetCurrentInnerWindow();
|
||||
}
|
||||
|
||||
InitNative(widget, aTitle);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBaseDatePicker::Open(nsIDatePickerShownCallback *aCallback)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> filePickerEvent =
|
||||
new AsyncShowDatePicker(this, aCallback);
|
||||
return NS_DispatchToMainThread(filePickerEvent);
|
||||
}
|
37
widget/nsBaseDatePicker.h
Normal file
37
widget/nsBaseDatePicker.h
Normal file
@ -0,0 +1,37 @@
|
||||
/* -*- 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 nsBaseDatePicker_h__
|
||||
#define nsBaseDatePicker_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDatePicker.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
class nsPIDOMWindow;
|
||||
class nsIWidget;
|
||||
|
||||
class nsBaseDatePicker : public nsIDatePicker
|
||||
{
|
||||
public:
|
||||
nsBaseDatePicker();
|
||||
virtual ~nsBaseDatePicker();
|
||||
|
||||
NS_IMETHOD Init(nsIDOMWindow *aParent,
|
||||
const nsAString& aTitle);
|
||||
|
||||
NS_IMETHOD Open(nsIDatePickerShownCallback *aCallback);
|
||||
|
||||
protected:
|
||||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle) = 0;
|
||||
|
||||
// This is an innerWindow.
|
||||
nsCOMPtr<nsPIDOMWindow> mParent;
|
||||
};
|
||||
|
||||
#endif // nsBaseDatePicker_h__
|
74
widget/nsIDatePicker.idl
Normal file
74
widget/nsIDatePicker.idl
Normal file
@ -0,0 +1,74 @@
|
||||
/* -*- 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 nsIURI;
|
||||
interface nsIDOMWindow;
|
||||
|
||||
[scriptable, function, uuid(0d79adad-b244-49A5-9997-2a8cad93fc45)]
|
||||
interface nsIDatePickerShownCallback : nsISupports
|
||||
{
|
||||
/**
|
||||
* Callback which is called when a datepicker is shown and a result
|
||||
* is returned.
|
||||
*
|
||||
* @param aResult One of returnOK, returnCancel
|
||||
*/
|
||||
void done(in short aResult);
|
||||
};
|
||||
|
||||
[scriptable, uuid(9840d564-42c8-4d78-9a4d-71002343c919)]
|
||||
interface nsIDatePicker : nsISupports
|
||||
{
|
||||
const short returnOK = 0; // User hit Ok, process selection
|
||||
const short returnCancel = 1; // User hit cancel, ignore selection
|
||||
|
||||
/**
|
||||
* Initialize the date picker widget. The date picker is not valid until this
|
||||
* method is called.
|
||||
*
|
||||
* @param title The title for the file widget
|
||||
*/
|
||||
void init(in nsIDOMWindow parent, in AString title);
|
||||
|
||||
/**
|
||||
* The date that should be suggested to the user as a default.
|
||||
* The date is a string in YYYY-MM-DD format.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE on attempts to get
|
||||
*/
|
||||
attribute AString defaultDate;
|
||||
|
||||
/**
|
||||
* The minimum date range. If null, there is no minimum date.
|
||||
* The date is a string in YYYY-MM-DD format.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE on attempts to get
|
||||
*/
|
||||
attribute AString minDate;
|
||||
|
||||
/**
|
||||
* The maximum date range. If null, there is no maximum date.
|
||||
* The date is a string in YYYY-MM-DD format.
|
||||
*
|
||||
* @throws NS_ERROR_FAILURE on attempts to get
|
||||
*/
|
||||
attribute AString maxDate;
|
||||
|
||||
/**
|
||||
* Show date dialog. The dialog is displayed modally.
|
||||
*
|
||||
* @return returnOK if the user selects OK, returnCancel if the user selects cancel
|
||||
*/
|
||||
[deprecated] short show();
|
||||
|
||||
/**
|
||||
* Opens the date dialog asynchrounously.
|
||||
* The passed in object's done method will be called upon completion.
|
||||
*/
|
||||
void open(in nsIDatePickerShownCallback aDatePickerShownCallback);
|
||||
};
|
Loading…
Reference in New Issue
Block a user