michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set sw=4 ts=8 et tw=80 : michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "ColorPickerParent.h" michael@0: #include "nsComponentManagerUtils.h" michael@0: #include "nsIDocument.h" michael@0: #include "nsIDOMWindow.h" michael@0: #include "mozilla/unused.h" michael@0: #include "mozilla/dom/Element.h" michael@0: #include "mozilla/dom/TabParent.h" michael@0: michael@0: using mozilla::unused; michael@0: using namespace mozilla::dom; michael@0: michael@0: NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback, michael@0: nsIColorPickerShownCallback); michael@0: michael@0: NS_IMETHODIMP michael@0: ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor) michael@0: { michael@0: if (mColorPickerParent) { michael@0: unused << mColorPickerParent->SendUpdate(nsString(aColor)); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor) michael@0: { michael@0: if (mColorPickerParent) { michael@0: unused << mColorPickerParent->Send__delete__(mColorPickerParent, michael@0: nsString(aColor)); michael@0: } michael@0: return NS_OK; michael@0: } michael@0: michael@0: void michael@0: ColorPickerParent::ColorPickerShownCallback::Destroy() michael@0: { michael@0: mColorPickerParent = nullptr; michael@0: } michael@0: michael@0: bool michael@0: ColorPickerParent::CreateColorPicker() michael@0: { michael@0: mPicker = do_CreateInstance("@mozilla.org/colorpicker;1"); michael@0: if (!mPicker) { michael@0: return false; michael@0: } michael@0: michael@0: Element* ownerElement = static_cast(Manager())->GetOwnerElement(); michael@0: if (!ownerElement) { michael@0: return false; michael@0: } michael@0: michael@0: nsCOMPtr window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow()); michael@0: if (!window) { michael@0: return false; michael@0: } michael@0: michael@0: return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialColor)); michael@0: } michael@0: michael@0: bool michael@0: ColorPickerParent::RecvOpen() michael@0: { michael@0: if (!CreateColorPicker()) { michael@0: unused << Send__delete__(this, mInitialColor); michael@0: return true; michael@0: } michael@0: michael@0: mCallback = new ColorPickerShownCallback(this); michael@0: michael@0: mPicker->Open(mCallback); michael@0: return true; michael@0: }; michael@0: michael@0: void michael@0: ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy) michael@0: { michael@0: if (mCallback) { michael@0: mCallback->Destroy(); michael@0: } michael@0: }