Bug 1885602 - Part 5: Implement navigating to the SUMO help topic from the menu heade...
[gecko.git] / dom / ipc / ColorPickerParent.cpp
blob18cf1973309bbdee7cdacaaad173e74574f179c8
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);
20 NS_IMETHODIMP
21 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor) {
22 if (mColorPickerParent) {
23 Unused << mColorPickerParent->SendUpdate(aColor);
25 return NS_OK;
28 NS_IMETHODIMP
29 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor) {
30 if (mColorPickerParent) {
31 Unused << ColorPickerParent::Send__delete__(mColorPickerParent, aColor);
33 return NS_OK;
36 void ColorPickerParent::ColorPickerShownCallback::Destroy() {
37 mColorPickerParent = nullptr;
40 bool ColorPickerParent::CreateColorPicker() {
41 mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
42 if (!mPicker) {
43 return false;
46 Element* ownerElement = BrowserParent::GetFrom(Manager())->GetOwnerElement();
47 if (!ownerElement) {
48 return false;
51 nsCOMPtr<nsPIDOMWindowOuter> window = ownerElement->OwnerDoc()->GetWindow();
52 if (!window) {
53 return false;
56 return NS_SUCCEEDED(
57 mPicker->Init(window, mTitle, mInitialColor, mDefaultColors));
60 mozilla::ipc::IPCResult ColorPickerParent::RecvOpen() {
61 if (!CreateColorPicker()) {
62 Unused << Send__delete__(this, mInitialColor);
63 return IPC_OK();
66 MOZ_ASSERT(!mCallback);
67 mCallback = new ColorPickerShownCallback(this);
69 mPicker->Open(mCallback);
70 return IPC_OK();
73 void ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy) {
74 if (mCallback) {
75 mCallback->Destroy();