-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#405: implement interface, widget, plumbing for time picker
- Loading branch information
Showing
24 changed files
with
1,156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 PTimePicker | ||
{ | ||
manager PBrowser; | ||
|
||
parent: | ||
Open(); | ||
|
||
child: | ||
Update(nsString time); | ||
|
||
__delete__(nsString time); | ||
}; | ||
|
||
} // namespace dom | ||
} // namespace mozilla |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* -*- 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 "TimePickerParent.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(TimePickerParent::TimePickerShownCallback, | ||
nsITimePickerShownCallback); | ||
|
||
NS_IMETHODIMP | ||
TimePickerParent::TimePickerShownCallback::Update(const nsAString& aTime) | ||
{ | ||
if (mTimePickerParent) { | ||
Unused << mTimePickerParent->SendUpdate(nsString(aTime)); | ||
} | ||
return NS_OK; | ||
} | ||
|
||
NS_IMETHODIMP | ||
TimePickerParent::TimePickerShownCallback::Done(int16_t aResult) | ||
{ | ||
if (mTimePickerParent) { | ||
mTimePickerParent->Done(aResult); | ||
} | ||
return NS_OK; | ||
} | ||
|
||
void | ||
TimePickerParent::TimePickerShownCallback::Destroy() | ||
{ | ||
mTimePickerParent = nullptr; | ||
} | ||
|
||
bool | ||
TimePickerParent::CreateTimePicker() | ||
{ | ||
mPicker = do_CreateInstance("@mozilla.org/timepicker;1"); | ||
if (!mPicker) { | ||
return false; | ||
} | ||
|
||
Element* ownerElement = TabParent::GetFrom(Manager())->GetOwnerElement(); | ||
if (!ownerElement) { | ||
return false; | ||
} | ||
|
||
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow()); | ||
if (!window) { | ||
return false; | ||
} | ||
|
||
return NS_SUCCEEDED(mPicker->Init(window, mTitle)); | ||
} | ||
|
||
void | ||
TimePickerParent::Done(int16_t aResult) | ||
{ | ||
Unused << Send__delete__(this, nsString()); | ||
MOZ_CRASH("TimePickerParent::Done NYI"); | ||
} | ||
|
||
bool | ||
TimePickerParent::RecvOpen() | ||
{ | ||
if (!CreateTimePicker()) { | ||
Unused << Send__delete__(this, nsString()); | ||
return true; | ||
} | ||
|
||
mCallback = new TimePickerShownCallback(this); | ||
|
||
mPicker->Open(mCallback); | ||
return true; | ||
}; | ||
|
||
void | ||
TimePickerParent::ActorDestroy(ActorDestroyReason aWhy) | ||
{ | ||
if (mCallback) { | ||
mCallback->Destroy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* -*- 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_TimePickerParent_h | ||
#define mozilla_dom_TimePickerParent_h | ||
|
||
#include "mozilla/dom/PTimePickerParent.h" | ||
#include "nsITimePicker.h" | ||
|
||
namespace mozilla { | ||
namespace dom { | ||
|
||
class TimePickerParent : public PTimePickerParent | ||
{ | ||
public: | ||
TimePickerParent(const nsString& aTitle) | ||
: mTitle(aTitle) | ||
{} | ||
|
||
virtual bool RecvOpen() override; | ||
virtual void ActorDestroy(ActorDestroyReason aWhy) override; | ||
|
||
void Done(int16_t aResult); | ||
|
||
class TimePickerShownCallback final | ||
: public nsITimePickerShownCallback | ||
{ | ||
public: | ||
explicit TimePickerShownCallback(TimePickerParent* aTimePickerParent) | ||
: mTimePickerParent(aTimePickerParent) | ||
{} | ||
|
||
NS_DECL_ISUPPORTS | ||
NS_DECL_NSIDATEPICKERSHOWNCALLBACK | ||
|
||
NS_IMETHODIMP Update(const nsAString& aTime); | ||
|
||
void Destroy(); | ||
|
||
private: | ||
~TimePickerShownCallback() {} | ||
|
||
TimePickerParent* mTimePickerParent; | ||
}; | ||
|
||
private: | ||
virtual ~TimePickerParent() {} | ||
|
||
bool CreateTimePicker(); | ||
|
||
RefPtr<TimePickerShownCallback> mCallback; | ||
nsCOMPtr<nsITimePicker> mPicker; | ||
|
||
nsString mTitle; | ||
}; | ||
|
||
} // namespace dom | ||
} // namespace mozilla | ||
|
||
#endif // mozilla_dom_TimePickerParent_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* -*- 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 nsTimePicker_h_ | ||
#define nsTimePicker_h_ | ||
|
||
#include "nsBaseTimePicker.h" | ||
|
||
class nsTimePicker : public nsBaseTimePicker | ||
{ | ||
public: | ||
nsTimePicker(); | ||
|
||
NS_DECL_ISUPPORTS | ||
|
||
// nsITimePicker (less what's in nsBaseTimePicker) | ||
NS_IMETHOD Show(int16_t *_retval) override; | ||
NS_IMETHOD GetDefaultTime(nsAString &aDefaultTime) override; | ||
NS_IMETHOD SetDefaultTime(const nsAString &aDefaultTime) override; | ||
NS_IMETHOD GetMinTime(nsAString &aMinTime) override; | ||
NS_IMETHOD SetMinTime(const nsAString &aMinTime) override; | ||
NS_IMETHOD GetMaxTime(nsAString &aMaxTime) override; | ||
NS_IMETHOD SetMaxTime(const nsAString &aMaxTime) override; | ||
NS_IMETHOD GetStep(double *aStep) override; | ||
NS_IMETHOD SetStep(const double aStep) override; | ||
NS_IMETHOD GetSelectedTime(nsAString &aSelectedTime); | ||
|
||
protected: | ||
virtual ~nsTimePicker(); | ||
|
||
virtual void InitNative(nsIWidget *aParent, const nsAString& aTitle) override; | ||
|
||
int16_t GetTime(); | ||
|
||
// Native control controls | ||
void SetDialogTitle(const nsString& inTitle, id aDialog); | ||
|
||
nsString mTitle; | ||
nsString mTime; | ||
bool mHasDefault; | ||
nsString mDefault; | ||
nsString mMinTime; | ||
bool mHasMin; | ||
nsString mMaxTime; | ||
bool mHasMax; | ||
double mStep; | ||
}; | ||
|
||
#endif // nsTimePicker_h_ |
Oops, something went wrong.