1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ColorPickerParent.h"
8 #include "nsComponentManagerUtils.h"
9 #include "mozilla/dom/Document.h"
10 #include "mozilla/Unused.h"
11 #include "mozilla/dom/Element.h"
12 #include "mozilla/dom/BrowserParent.h"
14 using mozilla::Unused
;
15 using namespace mozilla::dom
;
17 NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback
,
18 nsIColorPickerShownCallback
);
21 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString
& aColor
) {
22 if (mColorPickerParent
) {
23 Unused
<< mColorPickerParent
->SendUpdate(aColor
);
29 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString
& aColor
) {
30 if (mColorPickerParent
) {
31 Unused
<< ColorPickerParent::Send__delete__(mColorPickerParent
, aColor
);
36 void ColorPickerParent::ColorPickerShownCallback::Destroy() {
37 mColorPickerParent
= nullptr;
40 bool ColorPickerParent::CreateColorPicker() {
41 mPicker
= do_CreateInstance("@mozilla.org/colorpicker;1");
46 Element
* ownerElement
= BrowserParent::GetFrom(Manager())->GetOwnerElement();
51 nsCOMPtr
<nsPIDOMWindowOuter
> window
= ownerElement
->OwnerDoc()->GetWindow();
57 mPicker
->Init(window
, mTitle
, mInitialColor
, mDefaultColors
));
60 mozilla::ipc::IPCResult
ColorPickerParent::RecvOpen() {
61 if (!CreateColorPicker()) {
62 Unused
<< Send__delete__(this, mInitialColor
);
66 mCallback
= new ColorPickerShownCallback(this);
68 mPicker
->Open(mCallback
);
72 void ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy
) {