2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsXBLPrototypeHandler_h__
|
|
|
|
#define nsXBLPrototypeHandler_h__
|
|
|
|
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIController.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsXBLEventHandler.h"
|
|
|
|
#include "nsIWeakReference.h"
|
2007-12-04 23:21:18 -08:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2013-08-27 19:59:14 -07:00
|
|
|
#include "js/TypeDecls.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsIDOMEvent;
|
|
|
|
class nsIContent;
|
|
|
|
class nsIDOMUIEvent;
|
|
|
|
class nsIDOMKeyEvent;
|
|
|
|
class nsIDOMMouseEvent;
|
2013-03-20 13:09:09 -07:00
|
|
|
class nsIObjectInputStream;
|
|
|
|
class nsIObjectOutputStream;
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsXBLPrototypeBinding;
|
|
|
|
|
2013-04-05 17:44:26 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-04-15 09:28:53 -07:00
|
|
|
#define NS_HANDLER_TYPE_XBL_JS (1 << 0)
|
|
|
|
#define NS_HANDLER_TYPE_XBL_COMMAND (1 << 1)
|
|
|
|
#define NS_HANDLER_TYPE_XUL (1 << 2)
|
|
|
|
#define NS_HANDLER_HAS_ALLOW_UNTRUSTED_ATTR (1 << 4)
|
|
|
|
#define NS_HANDLER_ALLOW_UNTRUSTED (1 << 5)
|
|
|
|
#define NS_HANDLER_TYPE_SYSTEM (1 << 6)
|
|
|
|
#define NS_HANDLER_TYPE_PREVENTDEFAULT (1 << 7)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// XXX Use nsIDOMEvent:: codes?
|
|
|
|
#define NS_PHASE_CAPTURING 1
|
|
|
|
#define NS_PHASE_TARGET 2
|
|
|
|
#define NS_PHASE_BUBBLING 3
|
|
|
|
|
|
|
|
class nsXBLPrototypeHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// This constructor is used by XBL handlers (both the JS and command shorthand variety)
|
2014-01-04 07:02:17 -08:00
|
|
|
nsXBLPrototypeHandler(const char16_t* aEvent, const char16_t* aPhase,
|
|
|
|
const char16_t* aAction, const char16_t* aCommand,
|
|
|
|
const char16_t* aKeyCode, const char16_t* aCharCode,
|
|
|
|
const char16_t* aModifiers, const char16_t* aButton,
|
|
|
|
const char16_t* aClickCount, const char16_t* aGroup,
|
|
|
|
const char16_t* aPreventDefault,
|
|
|
|
const char16_t* aAllowUntrusted,
|
2007-12-04 23:21:18 -08:00
|
|
|
nsXBLPrototypeBinding* aBinding,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aLineNumber);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This constructor is used only by XUL key handlers (e.g., <key>)
|
|
|
|
nsXBLPrototypeHandler(nsIContent* aKeyElement);
|
|
|
|
|
2011-11-03 13:39:08 -07:00
|
|
|
// This constructor is used for handlers loaded from the cache
|
|
|
|
nsXBLPrototypeHandler(nsXBLPrototypeBinding* aBinding);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
~nsXBLPrototypeHandler();
|
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
// if aCharCode is not zero, it is used instead of the charCode of aKeyEvent.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool KeyEventMatched(nsIDOMKeyEvent* aKeyEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCharCode = 0,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIgnoreShiftKey = false);
|
|
|
|
inline bool KeyEventMatched(nsIAtom* aEventType,
|
2008-04-14 21:16:24 -07:00
|
|
|
nsIDOMKeyEvent* aEvent,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t aCharCode = 0,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aIgnoreShiftKey = false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aEventType != mEventName)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
return KeyEventMatched(aEvent, aCharCode, aIgnoreShiftKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool MouseEventMatched(nsIDOMMouseEvent* aMouseEvent);
|
|
|
|
inline bool MouseEventMatched(nsIAtom* aEventType,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIDOMMouseEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (aEventType != mEventName)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return MouseEventMatched(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIContent> GetHandlerElement();
|
|
|
|
|
|
|
|
void AppendHandlerText(const nsAString& aText);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t GetPhase() { return mPhase; }
|
|
|
|
uint8_t GetType() { return mType; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXBLPrototypeHandler* GetNextHandler() { return mNextHandler; }
|
|
|
|
void SetNextHandler(nsXBLPrototypeHandler* aHandler) { mNextHandler = aHandler; }
|
|
|
|
|
2013-04-05 17:44:26 -07:00
|
|
|
nsresult ExecuteHandler(mozilla::dom::EventTarget* aTarget, nsIDOMEvent* aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
already_AddRefed<nsIAtom> GetEventName();
|
|
|
|
void SetEventName(nsIAtom* aName) { mEventName = aName; }
|
|
|
|
|
|
|
|
nsXBLEventHandler* GetEventHandler()
|
|
|
|
{
|
|
|
|
if (!mHandler) {
|
|
|
|
NS_NewXBLEventHandler(this, mEventName, getter_AddRefs(mHandler));
|
|
|
|
// XXX Need to signal out of memory?
|
|
|
|
}
|
|
|
|
|
|
|
|
return mHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLEventHandler* GetCachedEventHandler()
|
|
|
|
{
|
|
|
|
return mHandler;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool HasAllowUntrustedAttr()
|
2007-04-15 09:28:53 -07:00
|
|
|
{
|
|
|
|
return (mType & NS_HANDLER_HAS_ALLOW_UNTRUSTED_ATTR) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This returns a valid value only if HasAllowUntrustedEventsAttr returns
|
2011-10-17 07:59:28 -07:00
|
|
|
// true.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AllowUntrustedEvents()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return (mType & NS_HANDLER_ALLOW_UNTRUSTED) != 0;
|
|
|
|
}
|
|
|
|
|
2013-08-09 09:25:13 -07:00
|
|
|
nsresult Read(nsIObjectInputStream* aStream);
|
|
|
|
nsresult Write(nsIObjectOutputStream* aStream);
|
2011-11-03 13:39:08 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
static uint32_t gRefCnt;
|
2013-04-05 17:44:26 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2011-11-03 13:39:08 -07:00
|
|
|
void Init() {
|
|
|
|
++gRefCnt;
|
|
|
|
if (gRefCnt == 1)
|
|
|
|
// Get the primary accelerator key.
|
|
|
|
InitAccessKeys();
|
|
|
|
}
|
|
|
|
|
2013-04-05 17:44:26 -07:00
|
|
|
already_AddRefed<nsIController> GetController(mozilla::dom::EventTarget* aTarget);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
inline int32_t GetMatchingKeyCode(const nsAString& aKeyName);
|
2013-04-05 17:44:26 -07:00
|
|
|
void ConstructPrototype(nsIContent* aKeyElement,
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t* aEvent=nullptr, const char16_t* aPhase=nullptr,
|
|
|
|
const char16_t* aAction=nullptr, const char16_t* aCommand=nullptr,
|
|
|
|
const char16_t* aKeyCode=nullptr, const char16_t* aCharCode=nullptr,
|
|
|
|
const char16_t* aModifiers=nullptr, const char16_t* aButton=nullptr,
|
|
|
|
const char16_t* aClickCount=nullptr, const char16_t* aGroup=nullptr,
|
|
|
|
const char16_t* aPreventDefault=nullptr,
|
|
|
|
const char16_t* aAllowUntrusted=nullptr);
|
|
|
|
|
|
|
|
void ReportKeyConflict(const char16_t* aKey, const char16_t* aModifiers, nsIContent* aElement, const char *aMessageName);
|
2007-03-22 10:30:00 -07:00
|
|
|
void GetEventType(nsAString& type);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ModifiersMatchMask(nsIDOMUIEvent* aEvent,
|
|
|
|
bool aIgnoreShiftKey = false);
|
2013-04-05 17:44:26 -07:00
|
|
|
nsresult DispatchXBLCommand(mozilla::dom::EventTarget* aTarget, nsIDOMEvent* aEvent);
|
2007-12-04 23:21:18 -08:00
|
|
|
nsresult DispatchXULKeyCommand(nsIDOMEvent* aEvent);
|
|
|
|
nsresult EnsureEventHandler(nsIScriptGlobalObject* aGlobal,
|
|
|
|
nsIScriptContext *aBoundContext, nsIAtom *aName,
|
2013-03-20 13:09:09 -07:00
|
|
|
JS::MutableHandle<JSObject*> aHandler);
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t KeyToMask(int32_t key);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t kAccelKey;
|
|
|
|
static int32_t kMenuAccessKey;
|
2007-03-22 10:30:00 -07:00
|
|
|
static void InitAccessKeys();
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t cShift;
|
|
|
|
static const int32_t cAlt;
|
|
|
|
static const int32_t cControl;
|
|
|
|
static const int32_t cMeta;
|
|
|
|
static const int32_t cOS;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t cShiftMask;
|
|
|
|
static const int32_t cAltMask;
|
|
|
|
static const int32_t cControlMask;
|
|
|
|
static const int32_t cMetaMask;
|
|
|
|
static const int32_t cOSMask;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const int32_t cAllModifiers;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
union {
|
|
|
|
nsIWeakReference* mHandlerElement; // For XUL <key> element handlers. [STRONG]
|
2014-01-04 07:02:17 -08:00
|
|
|
char16_t* mHandlerText; // For XBL handlers (we don't build an
|
2007-03-22 10:30:00 -07:00
|
|
|
// element for the <handler>, and instead
|
|
|
|
// we cache the JS text or command name
|
|
|
|
// that we should use.
|
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mLineNumber; // The line number we started at in the XBL file
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The following four values make up 32 bits.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mPhase; // The phase (capturing, bubbling)
|
|
|
|
uint8_t mType; // The type of the handler. The handler is either a XUL key
|
2007-03-22 10:30:00 -07:00
|
|
|
// handler, an XBL "command" event, or a normal XBL event with
|
|
|
|
// accompanying JavaScript. The high bit is used to indicate
|
|
|
|
// whether this handler should prevent the default action.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t mMisc; // Miscellaneous extra information. For key events,
|
2007-03-22 10:30:00 -07:00
|
|
|
// stores whether or not we're a key code or char code.
|
|
|
|
// For mouse events, stores the clickCount.
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mKeyMask; // Which modifier keys this event handler expects to have down
|
2012-07-18 18:28:16 -07:00
|
|
|
// in order to be matched.
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// The primary filter information for mouse/key events.
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mDetail; // For key events, contains a charcode or keycode. For
|
2007-03-22 10:30:00 -07:00
|
|
|
// mouse events, stores the button info.
|
2007-12-04 23:21:18 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Prototype handlers are chained. We own the next handler in the chain.
|
|
|
|
nsXBLPrototypeHandler* mNextHandler;
|
|
|
|
nsCOMPtr<nsIAtom> mEventName; // The type of the event, e.g., "keypress"
|
|
|
|
nsRefPtr<nsXBLEventHandler> mHandler;
|
|
|
|
nsXBLPrototypeBinding* mPrototypeBinding; // the binding owns us
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|