2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2014-02-24 00:19:43 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ColorPickerParent.h"
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "mozilla/unused.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
|
|
|
|
2015-11-02 08:53:26 +03:00
|
|
|
using mozilla::Unused;
|
2014-02-24 00:19:43 +04:00
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(ColorPickerParent::ColorPickerShownCallback,
|
|
|
|
nsIColorPickerShownCallback);
|
2014-02-24 00:19:43 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ColorPickerParent::ColorPickerShownCallback::Update(const nsAString& aColor)
|
|
|
|
{
|
|
|
|
if (mColorPickerParent) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mColorPickerParent->SendUpdate(nsString(aColor));
|
2014-02-24 00:19:43 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
ColorPickerParent::ColorPickerShownCallback::Done(const nsAString& aColor)
|
|
|
|
{
|
|
|
|
if (mColorPickerParent) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << mColorPickerParent->Send__delete__(mColorPickerParent,
|
2014-02-24 00:19:43 +04:00
|
|
|
nsString(aColor));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ColorPickerParent::ColorPickerShownCallback::Destroy()
|
|
|
|
{
|
|
|
|
mColorPickerParent = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ColorPickerParent::CreateColorPicker()
|
|
|
|
{
|
|
|
|
mPicker = do_CreateInstance("@mozilla.org/colorpicker;1");
|
|
|
|
if (!mPicker) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-06 00:47:32 +03:00
|
|
|
Element* ownerElement = TabParent::GetFrom(Manager())->GetOwnerElement();
|
2014-02-24 00:19:43 +04:00
|
|
|
if (!ownerElement) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = ownerElement->OwnerDoc()->GetWindow();
|
2014-02-24 00:19:43 +04:00
|
|
|
if (!window) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_SUCCEEDED(mPicker->Init(window, mTitle, mInitialColor));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ColorPickerParent::RecvOpen()
|
|
|
|
{
|
|
|
|
if (!CreateColorPicker()) {
|
2015-11-02 08:53:26 +03:00
|
|
|
Unused << Send__delete__(this, mInitialColor);
|
2014-02-24 00:19:43 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCallback = new ColorPickerShownCallback(this);
|
|
|
|
|
|
|
|
mPicker->Open(mCallback);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ColorPickerParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
|
|
|
if (mCallback) {
|
|
|
|
mCallback->Destroy();
|
|
|
|
}
|
|
|
|
}
|