dom/ipc/ColorPickerParent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: set sw=4 ts=8 et 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 "nsIDocument.h"
    10 #include "nsIDOMWindow.h"
    11 #include "mozilla/unused.h"
    12 #include "mozilla/dom/Element.h"
    13 #include "mozilla/dom/TabParent.h"
    15 using mozilla::unused;
    16 using namespace mozilla::dom;
    18 NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback,
    19                   nsIColorPickerShownCallback);
    21 NS_IMETHODIMP
    22 ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor)
    23 {
    24   if (mColorPickerParent) {
    25     unused << mColorPickerParent->SendUpdate(nsString(aColor));
    26   }
    27   return NS_OK;
    28 }
    30 NS_IMETHODIMP
    31 ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor)
    32 {
    33   if (mColorPickerParent) {
    34     unused << mColorPickerParent->Send__delete__(mColorPickerParent,
    35                                                  nsString(aColor));
    36   }
    37   return NS_OK;
    38 }
    40 void
    41 ColorPickerParent::ColorPickerShownCallback::Destroy()
    42 {
    43   mColorPickerParent = nullptr;
    44 }
    46 bool
    47 ColorPickerParent::CreateColorPicker()
    48 {
    49   mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
    50   if (!mPicker) {
    51     return false;
    52   }
    54   Element* ownerElement = static_cast<TabParent*>(Manager())->GetOwnerElement();
    55   if (!ownerElement) {
    56     return false;
    57   }
    59   nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(ownerElement->OwnerDoc()->GetWindow());
    60   if (!window) {
    61     return false;
    62   }
    64   return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialColor));
    65 }
    67 bool
    68 ColorPickerParent::RecvOpen()
    69 {
    70   if (!CreateColorPicker()) {
    71     unused << Send__delete__(this, mInitialColor);
    72     return true;
    73   }
    75   mCallback = new ColorPickerShownCallback(this);
    77   mPicker->Open(mCallback);
    78   return true;
    79 };
    81 void
    82 ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy)
    83 {
    84   if (mCallback) {
    85     mCallback->Destroy();
    86   }
    87 }

mercurial