2011-11-02 20:53:59 +00: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 11:12:37 +00: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-02 20:53:59 +00:00
|
|
|
|
|
|
|
#ifndef __mozilla_widget_GfxInfoCollector_h__
|
|
|
|
#define __mozilla_widget_GfxInfoCollector_h__
|
|
|
|
|
2013-05-12 22:29:53 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-19 20:02:03 +00:00
|
|
|
#include "nsStringFwd.h"
|
|
|
|
#include "js/RootingAPI.h"
|
2011-11-02 20:53:59 +00: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-12 22:29:53 +00:00
|
|
|
class MOZ_STACK_CLASS InfoObject
|
2011-11-02 20:53:59 +00:00
|
|
|
{
|
|
|
|
friend class GfxInfoBase;
|
|
|
|
|
|
|
|
public:
|
2013-09-19 20:02:03 +00: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 04:00:38 +00:00
|
|
|
|
2011-11-02 20:53:59 +00:00
|
|
|
private:
|
|
|
|
// We need to ensure that this object lives on the stack so that GC sees it properly
|
2014-08-05 13:38:21 +00:00
|
|
|
explicit InfoObject(JSContext *aCx);
|
2011-11-02 20:53:59 +00:00
|
|
|
InfoObject(InfoObject&);
|
|
|
|
|
|
|
|
JSContext *mCx;
|
2013-05-12 22:29:53 +00:00
|
|
|
JS::Rooted<JSObject*> mObj;
|
2013-08-08 22:53:04 +00:00
|
|
|
bool mOk;
|
2011-11-02 20:53:59 +00: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) {
|
|
|
|
}
|
|
|
|
virtual void GetInfo(InfoObject &obj) {
|
|
|
|
(mPointer->*mFunc)(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
T* mPointer;
|
|
|
|
void (T::*mFunc)(InfoObject &obj);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|