2011-11-03 00:53:59 +04:00
|
|
|
/* vim: se cin sw=2 ts=2 et : */
|
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2011-11-03 00:53:59 +04:00
|
|
|
|
|
|
|
#ifndef __mozilla_widget_GfxInfoCollector_h__
|
|
|
|
#define __mozilla_widget_GfxInfoCollector_h__
|
|
|
|
|
2013-05-13 02:29:53 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-20 00:02:03 +04:00
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "js/RootingAPI.h"
|
2011-11-03 00:53:59 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
|
|
|
|
|
|
|
/* this is handy wrapper around JSAPI to make it more pleasant to use.
|
|
|
|
* We collect the JSAPI errors and so that callers don't need to */
|
2013-05-13 02:29:53 +04:00
|
|
|
class MOZ_STACK_CLASS InfoObject
|
2011-11-03 00:53:59 +04:00
|
|
|
{
|
|
|
|
friend class GfxInfoBase;
|
|
|
|
|
|
|
|
public:
|
2013-09-20 00:02:03 +04:00
|
|
|
void DefineProperty(const char *name, int value);
|
|
|
|
void DefineProperty(const char *name, nsAString &value);
|
|
|
|
void DefineProperty(const char *name, const char *value);
|
2011-11-18 08:00:38 +04:00
|
|
|
|
2011-11-03 00:53:59 +04:00
|
|
|
private:
|
|
|
|
// We need to ensure that this object lives on the stack so that GC sees it properly
|
2014-08-05 17:38:21 +04:00
|
|
|
explicit InfoObject(JSContext *aCx);
|
2011-11-03 00:53:59 +04:00
|
|
|
InfoObject(InfoObject&);
|
|
|
|
|
|
|
|
JSContext *mCx;
|
2013-05-13 02:29:53 +04:00
|
|
|
JS::Rooted<JSObject*> mObj;
|
2013-08-09 02:53:04 +04:00
|
|
|
bool mOk;
|
2011-11-03 00:53:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Here's an example usage:
|
|
|
|
|
|
|
|
class Foo {
|
|
|
|
Foo::Foo() : mInfoCollector(this, &Foo::GetAweseomeness) {}
|
|
|
|
|
|
|
|
void GetAwesomeness(InfoObject &obj) {
|
|
|
|
obj.DefineProperty("awesome", mAwesome);
|
|
|
|
}
|
|
|
|
|
|
|
|
int mAwesome;
|
|
|
|
|
|
|
|
GfxInfoCollector<Foo> mInfoCollector;
|
|
|
|
}
|
|
|
|
|
|
|
|
This will define a property on the object
|
|
|
|
returned from calling getInfo() on a
|
|
|
|
GfxInfo object. e.g.
|
|
|
|
|
|
|
|
gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
|
|
|
|
info = gfxInfo.getInfo();
|
|
|
|
if (info.awesome)
|
|
|
|
alert(info.awesome);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class GfxInfoCollectorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GfxInfoCollectorBase();
|
|
|
|
virtual void GetInfo(InfoObject &obj) = 0;
|
|
|
|
virtual ~GfxInfoCollectorBase();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
class GfxInfoCollector : public GfxInfoCollectorBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GfxInfoCollector(T* aPointer, void (T::*aFunc)(InfoObject &obj)) : mPointer(aPointer), mFunc(aFunc) {
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void GetInfo(InfoObject &obj) override {
|
2011-11-03 00:53:59 +04:00
|
|
|
(mPointer->*mFunc)(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T* mPointer;
|
|
|
|
void (T::*mFunc)(InfoObject &obj);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|