ColorPickerParent.cpp (1857B)
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/. */ 6 7 #include "ColorPickerParent.h" 8 9 #include "mozilla/dom/BrowserParent.h" 10 #include "mozilla/dom/Document.h" 11 #include "mozilla/dom/Element.h" 12 #include "nsComponentManagerUtils.h" 13 14 using namespace mozilla::dom; 15 16 NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback, 17 nsIColorPickerShownCallback); 18 19 NS_IMETHODIMP 20 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor) { 21 if (mColorPickerParent) { 22 (void)mColorPickerParent->SendUpdate(aColor); 23 } 24 return NS_OK; 25 } 26 27 NS_IMETHODIMP 28 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor) { 29 if (mColorPickerParent) { 30 (void)ColorPickerParent::Send__delete__(mColorPickerParent, aColor); 31 } 32 return NS_OK; 33 } 34 35 void ColorPickerParent::ColorPickerShownCallback::Destroy() { 36 mColorPickerParent = nullptr; 37 } 38 39 bool ColorPickerParent::CreateColorPicker() { 40 if (!mBrowsingContext) { 41 return false; 42 } 43 44 mPicker = do_CreateInstance("@mozilla.org/colorpicker;1"); 45 if (!mPicker) { 46 return false; 47 } 48 49 return NS_SUCCEEDED( 50 mPicker->Init(mBrowsingContext, mTitle, mInitialColor, mDefaultColors)); 51 } 52 53 mozilla::ipc::IPCResult ColorPickerParent::RecvOpen() { 54 if (!CreateColorPicker()) { 55 (void)Send__delete__(this, mInitialColor); 56 return IPC_OK(); 57 } 58 59 MOZ_ASSERT(!mCallback); 60 mCallback = new ColorPickerShownCallback(this); 61 62 mPicker->Open(mCallback); 63 return IPC_OK(); 64 }; 65 66 void ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy) { 67 if (mCallback) { 68 mCallback->Destroy(); 69 } 70 }