mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-27 06:43:32 +00:00
Bug 963294 - [e10s] Implement a proxy for the color picker. r=jdm
This commit is contained in:
parent
23792bbdb4
commit
1a72f691ab
87
dom/ipc/ColorPickerParent.cpp
Normal file
87
dom/ipc/ColorPickerParent.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set sw=4 ts=8 et 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 "ColorPickerParent.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_ISUPPORTS1(ColorPickerParent::ColorPickerShownCallback,
|
||||
nsIColorPickerShownCallback);
|
||||
|
||||
NS_IMETHODIMP
|
||||
ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor)
|
||||
{
|
||||
if (mColorPickerParent) {
|
||||
unused << mColorPickerParent->SendUpdate(nsString(aColor));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor)
|
||||
{
|
||||
if (mColorPickerParent) {
|
||||
unused << mColorPickerParent->Send__delete__(mColorPickerParent,
|
||||
nsString(aColor));
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ColorPickerParent::ColorPickerShownCallback::Destroy()
|
||||
{
|
||||
mColorPickerParent = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
ColorPickerParent::CreateColorPicker()
|
||||
{
|
||||
mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
|
||||
if (!mPicker) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Element* ownerElement = static_cast<TabParent*>(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, mInitialColor));
|
||||
}
|
||||
|
||||
bool
|
||||
ColorPickerParent::RecvOpen()
|
||||
{
|
||||
if (!CreateColorPicker()) {
|
||||
unused << Send__delete__(this, mInitialColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
mCallback = new ColorPickerShownCallback(this);
|
||||
|
||||
mPicker->Open(mCallback);
|
||||
return true;
|
||||
};
|
||||
|
||||
void
|
||||
ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
if (mCallback) {
|
||||
mCallback->Destroy();
|
||||
}
|
||||
}
|
60
dom/ipc/ColorPickerParent.h
Normal file
60
dom/ipc/ColorPickerParent.h
Normal file
@ -0,0 +1,60 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* vim: set sw=4 ts=8 et 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_ColorPickerParent_h
|
||||
#define mozilla_dom_ColorPickerParent_h
|
||||
|
||||
#include "mozilla/dom/PColorPickerParent.h"
|
||||
#include "nsIColorPicker.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ColorPickerParent : public PColorPickerParent
|
||||
{
|
||||
public:
|
||||
ColorPickerParent(const nsString& aTitle,
|
||||
const nsString& aInitialColor)
|
||||
: mTitle(aTitle)
|
||||
, mInitialColor(aInitialColor)
|
||||
{}
|
||||
|
||||
virtual ~ColorPickerParent() {}
|
||||
|
||||
virtual bool RecvOpen() MOZ_OVERRIDE;
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;
|
||||
|
||||
class ColorPickerShownCallback MOZ_FINAL
|
||||
: public nsIColorPickerShownCallback
|
||||
{
|
||||
public:
|
||||
ColorPickerShownCallback(ColorPickerParent* aColorPickerParnet)
|
||||
: mColorPickerParent(aColorPickerParnet)
|
||||
{}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOLORPICKERSHOWNCALLBACK
|
||||
|
||||
void Destroy();
|
||||
|
||||
private:
|
||||
ColorPickerParent* mColorPickerParent;
|
||||
};
|
||||
|
||||
private:
|
||||
bool CreateColorPicker();
|
||||
|
||||
nsRefPtr<ColorPickerShownCallback> mCallback;
|
||||
nsCOMPtr<nsIColorPicker> mPicker;
|
||||
|
||||
nsString mTitle;
|
||||
nsString mInitialColor;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_ColorPickerParent_h
|
@ -6,6 +6,7 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PBlob;
|
||||
include protocol PColorPicker;
|
||||
include protocol PContent;
|
||||
include protocol PContentDialog;
|
||||
include protocol PDocumentRenderer;
|
||||
@ -57,6 +58,7 @@ intr protocol PBrowser
|
||||
{
|
||||
manager PContent;
|
||||
|
||||
manages PColorPicker;
|
||||
manages PContentDialog;
|
||||
manages PDocumentRenderer;
|
||||
manages PContentPermissionRequest;
|
||||
@ -221,6 +223,12 @@ parent:
|
||||
ShowTooltip(uint32_t x, uint32_t y, nsString tooltip);
|
||||
HideTooltip();
|
||||
|
||||
/**
|
||||
* Create an asynchronous color picker on the parent side,
|
||||
* but don't open it yet.
|
||||
*/
|
||||
PColorPicker(nsString title, nsString initialColor);
|
||||
|
||||
/**
|
||||
* Initiates an asynchronous request for permission for the
|
||||
* provided principal.
|
||||
|
27
dom/ipc/PColorPicker.ipdl
Normal file
27
dom/ipc/PColorPicker.ipdl
Normal 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 PColorPicker
|
||||
{
|
||||
manager PBrowser;
|
||||
|
||||
parent:
|
||||
Open();
|
||||
|
||||
child:
|
||||
Update(nsString color);
|
||||
|
||||
__delete__(nsString color);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
@ -75,6 +75,8 @@
|
||||
#include "ipc/nsGUIEventIPC.h"
|
||||
#include "mozilla/gfx/Matrix.h"
|
||||
|
||||
#include "nsColorPickerProxy.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#include "PCOMContentPermissionRequestChild.h"
|
||||
#endif /* DEBUG */
|
||||
@ -2093,6 +2095,21 @@ TabChild::RecvPDocumentRendererConstructor(PDocumentRendererChild* actor,
|
||||
return PDocumentRendererChild::Send__delete__(actor, renderSize, data);
|
||||
}
|
||||
|
||||
PColorPickerChild*
|
||||
TabChild::AllocPColorPickerChild(const nsString&, const nsString&)
|
||||
{
|
||||
NS_RUNTIMEABORT("unused");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
TabChild::DeallocPColorPickerChild(PColorPickerChild* aColorPicker)
|
||||
{
|
||||
nsColorPickerProxy* picker = static_cast<nsColorPickerProxy*>(aColorPicker);
|
||||
NS_RELEASE(picker);
|
||||
return true;
|
||||
}
|
||||
|
||||
PContentDialogChild*
|
||||
TabChild::AllocPContentDialogChild(const uint32_t&,
|
||||
const nsCString&,
|
||||
|
@ -278,6 +278,11 @@ public:
|
||||
const bool& flushLayout,
|
||||
const nsIntSize& renderSize) MOZ_OVERRIDE;
|
||||
|
||||
virtual PColorPickerChild*
|
||||
AllocPColorPickerChild(const nsString& title, const nsString& initialColor) MOZ_OVERRIDE;
|
||||
virtual bool DeallocPColorPickerChild(PColorPickerChild* actor) MOZ_OVERRIDE;
|
||||
|
||||
|
||||
virtual PContentDialogChild* AllocPContentDialogChild(const uint32_t&,
|
||||
const nsCString&,
|
||||
const nsCString&,
|
||||
@ -285,6 +290,7 @@ public:
|
||||
const InfallibleTArray<nsString>&)
|
||||
MOZ_OVERRIDE;
|
||||
virtual bool DeallocPContentDialogChild(PContentDialogChild* aDialog) MOZ_OVERRIDE;
|
||||
|
||||
static void ParamsToArrays(nsIDialogParamBlock* aParams,
|
||||
InfallibleTArray<int>& aIntParams,
|
||||
InfallibleTArray<nsString>& aStringParams);
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "mozIApplication.h"
|
||||
#include "mozilla/BrowserElementParent.h"
|
||||
#include "mozilla/docshell/OfflineCacheUpdateParent.h"
|
||||
#include "mozilla/dom/PColorPickerParent.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/PContentPermissionRequestParent.h"
|
||||
#include "mozilla/Hal.h"
|
||||
@ -1625,6 +1626,20 @@ TabParent::GetAuthPrompt(uint32_t aPromptReason, const nsIID& iid,
|
||||
reinterpret_cast<void**>(aResult));
|
||||
}
|
||||
|
||||
PColorPickerParent*
|
||||
TabParent::AllocPColorPickerParent(const nsString& aTitle,
|
||||
const nsString& aInitialColor)
|
||||
{
|
||||
return new ColorPickerParent(aTitle, aInitialColor);
|
||||
}
|
||||
|
||||
bool
|
||||
TabParent::DeallocPColorPickerParent(PColorPickerParent* actor)
|
||||
{
|
||||
delete actor;
|
||||
return true;
|
||||
}
|
||||
|
||||
PContentDialogParent*
|
||||
TabParent::AllocPContentDialogParent(const uint32_t& aType,
|
||||
const nsCString& aName,
|
||||
|
@ -187,6 +187,11 @@ public:
|
||||
const ZoomConstraints& aConstraints) MOZ_OVERRIDE;
|
||||
virtual bool RecvContentReceivedTouch(const ScrollableLayerGuid& aGuid,
|
||||
const bool& aPreventDefault) MOZ_OVERRIDE;
|
||||
|
||||
virtual PColorPickerParent*
|
||||
AllocPColorPickerParent(const nsString& aTitle, const nsString& aInitialColor) MOZ_OVERRIDE;
|
||||
virtual bool DeallocPColorPickerParent(PColorPickerParent* aColorPicker) MOZ_OVERRIDE;
|
||||
|
||||
virtual PContentDialogParent*
|
||||
AllocPContentDialogParent(const uint32_t& aType,
|
||||
const nsCString& aName,
|
||||
|
@ -40,6 +40,7 @@ EXPORTS.mozilla += [
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'AppProcessChecker.cpp',
|
||||
'ColorPickerParent.cpp',
|
||||
'ContentChild.cpp',
|
||||
'ContentParent.cpp',
|
||||
'ContentProcess.cpp',
|
||||
@ -68,6 +69,7 @@ IPDL_SOURCES += [
|
||||
'PBlob.ipdl',
|
||||
'PBlobStream.ipdl',
|
||||
'PBrowser.ipdl',
|
||||
'PColorPicker.ipdl',
|
||||
'PContent.ipdl',
|
||||
'PContentDialog.ipdl',
|
||||
'PContentPermission.ipdlh',
|
||||
|
@ -26,6 +26,7 @@ UNIFIED_SOURCES += [
|
||||
'nsClipboardHelper.cpp',
|
||||
'nsClipboardPrivacyHandler.cpp',
|
||||
'nsClipboardProxy.cpp',
|
||||
'nsColorPickerProxy.cpp',
|
||||
'nsContentProcessWidgetFactory.cpp',
|
||||
'nsFilePickerProxy.cpp',
|
||||
'nsHTMLFormatConverter.cpp',
|
||||
|
60
widget/xpwidgets/nsColorPickerProxy.cpp
Normal file
60
widget/xpwidgets/nsColorPickerProxy.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/* -*- 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 "nsColorPickerProxy.h"
|
||||
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
|
||||
using namespace mozilla::dom;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsColorPickerProxy, nsIColorPicker)
|
||||
|
||||
/* void init (in nsIDOMWindow parent, in AString title, in short mode); */
|
||||
NS_IMETHODIMP
|
||||
nsColorPickerProxy::Init(nsIDOMWindow* aParent, const nsAString& aTitle,
|
||||
const nsAString& aInitialColor)
|
||||
{
|
||||
TabChild* tabChild = TabChild::GetFrom(aParent);
|
||||
if (!tabChild) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
tabChild->SendPColorPickerConstructor(this,
|
||||
nsString(aTitle),
|
||||
nsString(aInitialColor));
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void open (in nsIColorPickerShownCallback aColorPickerShownCallback); */
|
||||
NS_IMETHODIMP
|
||||
nsColorPickerProxy::Open(nsIColorPickerShownCallback* aColorPickerShownCallback)
|
||||
{
|
||||
NS_ENSURE_STATE(!mCallback);
|
||||
mCallback = aColorPickerShownCallback;
|
||||
|
||||
SendOpen();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsColorPickerProxy::RecvUpdate(const nsString& aColor)
|
||||
{
|
||||
if (mCallback) {
|
||||
mCallback->Update(aColor);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
nsColorPickerProxy::Recv__delete__(const nsString& aColor)
|
||||
{
|
||||
if (mCallback) {
|
||||
mCallback->Done(aColor);
|
||||
mCallback = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
32
widget/xpwidgets/nsColorPickerProxy.h
Normal file
32
widget/xpwidgets/nsColorPickerProxy.h
Normal file
@ -0,0 +1,32 @@
|
||||
/* -*- 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 nsColorPickerProxy_h
|
||||
#define nsColorPickerProxy_h
|
||||
|
||||
#include "nsIColorPicker.h"
|
||||
|
||||
#include "mozilla/dom/PColorPickerChild.h"
|
||||
|
||||
class nsColorPickerProxy MOZ_FINAL : public nsIColorPicker,
|
||||
public mozilla::dom::PColorPickerChild
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICOLORPICKER
|
||||
|
||||
nsColorPickerProxy() {}
|
||||
~nsColorPickerProxy() {}
|
||||
|
||||
virtual bool RecvUpdate(const nsString& aColor) MOZ_OVERRIDE;
|
||||
virtual bool Recv__delete__(const nsString& aColor) MOZ_OVERRIDE;
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIColorPickerShownCallback> mCallback;
|
||||
nsString mTitle;
|
||||
nsString mInitialColor;
|
||||
};
|
||||
|
||||
#endif // nsColorPickerProxy_h
|
@ -8,6 +8,7 @@
|
||||
#include "mozilla/ModuleUtils.h"
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsClipboardProxy.h"
|
||||
#include "nsColorPickerProxy.h"
|
||||
#include "nsFilePickerProxy.h"
|
||||
|
||||
using namespace mozilla;
|
||||
@ -15,14 +16,18 @@ using namespace mozilla;
|
||||
#ifndef MOZ_B2G
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardProxy)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsColorPickerProxy)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePickerProxy)
|
||||
|
||||
NS_DEFINE_NAMED_CID(NS_CLIPBOARD_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_COLORPICKER_CID);
|
||||
NS_DEFINE_NAMED_CID(NS_FILEPICKER_CID);
|
||||
|
||||
static const mozilla::Module::CIDEntry kWidgetCIDs[] = {
|
||||
{ &kNS_CLIPBOARD_CID, false, nullptr, nsClipboardProxyConstructor,
|
||||
Module::CONTENT_PROCESS_ONLY },
|
||||
{ &kNS_COLORPICKER_CID, false, nullptr, nsColorPickerProxyConstructor,
|
||||
Module::CONTENT_PROCESS_ONLY },
|
||||
{ &kNS_FILEPICKER_CID, false, nullptr, nsFilePickerProxyConstructor,
|
||||
Module::CONTENT_PROCESS_ONLY },
|
||||
{ nullptr }
|
||||
@ -30,6 +35,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/filepicker;1", &kNS_FILEPICKER_CID, Module::CONTENT_PROCESS_ONLY },
|
||||
{ nullptr }
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user