Skip to content

Commit

Permalink
#405: implement interface, widget, plumbing for time picker
Browse files Browse the repository at this point in the history
  • Loading branch information
classilla committed Jun 30, 2018
1 parent 52f6389 commit 1c5fbc3
Show file tree
Hide file tree
Showing 24 changed files with 1,156 additions and 3 deletions.
1 change: 1 addition & 0 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@

#include "nsIColorPicker.h"
#include "nsIDatePicker.h" // TenFourFox issue 405
#include "nsITimePicker.h" // TenFourFox issue 405
#include "nsIStringEnumerator.h"
#include "HTMLSplitOnSpacesTokenizer.h"
#include "nsIController.h"
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/PBrowser.ipdl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include protocol PDatePicker;
include protocol PFilePicker;
include protocol PIndexedDBPermissionRequest;
include protocol PRenderFrame;
include protocol PTimePicker;
include protocol PPluginWidget;
include DOMTypes;
include JavaScriptTypes;
Expand Down Expand Up @@ -106,6 +107,7 @@ prio(normal upto urgent) sync protocol PBrowser
manages PDocumentRenderer;
manages PFilePicker;
manages PDatePicker;
manages PTimePicker;
manages PIndexedDBPermissionRequest;
manages PRenderFrame;
manages PPluginWidget;
Expand Down Expand Up @@ -381,6 +383,8 @@ parent:

PDatePicker(nsString aTitle);

PTimePicker(nsString aTitle);

/**
* Initiates an asynchronous request for one of the special indexedDB
* permissions for the provided principal.
Expand Down
27 changes: 27 additions & 0 deletions dom/ipc/PTimePicker.ipdl
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
16 changes: 16 additions & 0 deletions dom/ipc/TabChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "nsExceptionHandler.h"
#endif
#include "nsDatePickerProxy.h"
#include "nsTimePickerProxy.h"
#include "nsFilePickerProxy.h"
#include "mozilla/dom/Element.h"
#include "nsIBaseWindow.h"
Expand Down Expand Up @@ -2152,6 +2153,21 @@ TabChild::DeallocPDatePickerChild(PDatePickerChild* actor)
return true;
}

PTimePickerChild*
TabChild::AllocPTimePickerChild(const nsString&)
{
NS_RUNTIMEABORT("unused");
return nullptr;
}

bool
TabChild::DeallocPTimePickerChild(PTimePickerChild* actor)
{
nsTimePickerProxy* datePicker = static_cast<nsTimePickerProxy*>(actor);
NS_RELEASE(datePicker);
return true;
}

auto
TabChild::AllocPIndexedDBPermissionRequestChild(const Principal& aPrincipal)
-> PIndexedDBPermissionRequestChild*
Expand Down
5 changes: 5 additions & 0 deletions dom/ipc/TabChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,11 @@ class TabChild final : public TabChildBase,
virtual bool
DeallocPDatePickerChild(PDatePickerChild* actor) override;

virtual PTimePickerChild*
AllocPTimePickerChild(const nsString& aTitle) override;
virtual bool
DeallocPTimePickerChild(PTimePickerChild* actor) override;

virtual PIndexedDBPermissionRequestChild*
AllocPIndexedDBPermissionRequestChild(const Principal& aPrincipal)
override;
Expand Down
14 changes: 14 additions & 0 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "StructuredCloneData.h"
#include "ColorPickerParent.h"
#include "DatePickerParent.h"
#include "TimePickerParent.h"
#include "FilePickerParent.h"
#include "TabChild.h"
#include "LoadContext.h"
Expand Down Expand Up @@ -1228,6 +1229,19 @@ TabParent::DeallocPDatePickerParent(PDatePickerParent* actor)
return true;
}

PTimePickerParent*
TabParent::AllocPTimePickerParent(const nsString& aTitle)
{
return new TimePickerParent(aTitle);
}

bool
TabParent::DeallocPTimePickerParent(PTimePickerParent* actor)
{
delete actor;
return true;
}

auto
TabParent::AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal)
-> PIndexedDBPermissionRequestParent*
Expand Down
4 changes: 4 additions & 0 deletions dom/ipc/TabParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ class TabParent final : public PBrowserParent
AllocPDatePickerParent(const nsString& aTitle) override;
virtual bool DeallocPDatePickerParent(PDatePickerParent* actor) override;

virtual PTimePickerParent*
AllocPTimePickerParent(const nsString& aTitle) override;
virtual bool DeallocPTimePickerParent(PTimePickerParent* actor) override;

virtual PIndexedDBPermissionRequestParent*
AllocPIndexedDBPermissionRequestParent(const Principal& aPrincipal)
override;
Expand Down
93 changes: 93 additions & 0 deletions dom/ipc/TimePickerParent.cpp
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();
}
}
63 changes: 63 additions & 0 deletions dom/ipc/TimePickerParent.h
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
2 changes: 2 additions & 0 deletions dom/ipc/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ UNIFIED_SOURCES += [
'TabContext.cpp',
'TabMessageUtils.cpp',
'TabParent.cpp',
'TimePickerParent.cpp',
]

# Blob.cpp cannot be compiled in unified mode because it triggers a fatal gcc warning.
Expand Down Expand Up @@ -112,6 +113,7 @@ IPDL_SOURCES += [
'PProcessHangMonitor.ipdl',
'PScreenManager.ipdl',
'PTabContext.ipdlh',
'PTimePicker.ipdl',
]

include('/ipc/chromium/chromium-config.mozbuild')
Expand Down
1 change: 1 addition & 0 deletions widget/cocoa/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ SOURCES += [
'nsDatePicker.mm',
'nsDragService.mm',
'nsNativeThemeCocoa.mm',
'nsTimePicker.mm',
]

if not CONFIG['RELEASE_BUILD'] or CONFIG['MOZ_DEBUG']:
Expand Down
2 changes: 2 additions & 0 deletions widget/cocoa/nsDatePicker.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ - (NSDoubleDatePicker *)datePicker:(NSString *)message
- (void)onSwitchControl:(NSDatePicker *)which newDate:(NSDate **)newDate;
- (NSDate *)date;
- (void)setDate:(NSDate *)date;
- (void)setMinDate:(NSDate *)date;
- (void)setMaxDate:(NSDate *)date;
@end

@interface NSDoubleDatePicker(Private)
Expand Down
52 changes: 52 additions & 0 deletions widget/cocoa/nsTimePicker.h
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_
Loading

0 comments on commit 1c5fbc3

Please sign in to comment.