dom/ipc/ColorPickerParent.cpp

Wed, 31 Dec 2014 06:55:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:55:50 +0100
changeset 2
7e26c7da4463
permissions
-rw-r--r--

Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set sw=4 ts=8 et tw=80 :
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "ColorPickerParent.h"
michael@0 8 #include "nsComponentManagerUtils.h"
michael@0 9 #include "nsIDocument.h"
michael@0 10 #include "nsIDOMWindow.h"
michael@0 11 #include "mozilla/unused.h"
michael@0 12 #include "mozilla/dom/Element.h"
michael@0 13 #include "mozilla/dom/TabParent.h"
michael@0 14
michael@0 15 using mozilla::unused;
michael@0 16 using namespace mozilla::dom;
michael@0 17
michael@0 18 NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback,
michael@0 19 nsIColorPickerShownCallback);
michael@0 20
michael@0 21 NS_IMETHODIMP
michael@0 22 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor)
michael@0 23 {
michael@0 24 if (mColorPickerParent) {
michael@0 25 unused << mColorPickerParent->SendUpdate(nsString(aColor));
michael@0 26 }
michael@0 27 return NS_OK;
michael@0 28 }
michael@0 29
michael@0 30 NS_IMETHODIMP
michael@0 31 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor)
michael@0 32 {
michael@0 33 if (mColorPickerParent) {
michael@0 34 unused << mColorPickerParent->Send__delete__(mColorPickerParent,
michael@0 35 nsString(aColor));
michael@0 36 }
michael@0 37 return NS_OK;
michael@0 38 }
michael@0 39
michael@0 40 void
michael@0 41 ColorPickerParent::ColorPickerShownCallback::Destroy()
michael@0 42 {
michael@0 43 mColorPickerParent = nullptr;
michael@0 44 }
michael@0 45
michael@0 46 bool
michael@0 47 ColorPickerParent::CreateColorPicker()
michael@0 48 {
michael@0 49 mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
michael@0 50 if (!mPicker) {
michael@0 51 return false;
michael@0 52 }
michael@0 53
michael@0 54 Element* ownerElement = static_cast<TabParent*>(Manager())->GetOwnerElement();
michael@0 55 if (!ownerElement) {
michael@0 56 return false;
michael@0 57 }
michael@0 58
michael@0 59 nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow());
michael@0 60 if (!window) {
michael@0 61 return false;
michael@0 62 }
michael@0 63
michael@0 64 return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialColor));
michael@0 65 }
michael@0 66
michael@0 67 bool
michael@0 68 ColorPickerParent::RecvOpen()
michael@0 69 {
michael@0 70 if (!CreateColorPicker()) {
michael@0 71 unused << Send__delete__(this, mInitialColor);
michael@0 72 return true;
michael@0 73 }
michael@0 74
michael@0 75 mCallback = new ColorPickerShownCallback(this);
michael@0 76
michael@0 77 mPicker->Open(mCallback);
michael@0 78 return true;
michael@0 79 };
michael@0 80
michael@0 81 void
michael@0 82 ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy)
michael@0 83 {
michael@0 84 if (mCallback) {
michael@0 85 mCallback->Destroy();
michael@0 86 }
michael@0 87 }

mercurial