2001-09-25 01:32:19 +00:00
|
|
|
/* -*- 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/. */
|
2000-03-21 13:14:34 +00:00
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-01-26 10:25:55 +00:00
|
|
|
#include "nsIAtom.h"
|
2007-05-14 09:11:38 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-01-26 10:06:30 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-05-21 06:58:15 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2003-09-11 12:25:06 +00:00
|
|
|
#include "nsXBLPrototypeHandler.h"
|
2007-04-15 16:28:53 +00:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-05 00:37:43 +00:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-04-06 00:44:26 +00:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2000-01-26 10:06:30 +00:00
|
|
|
|
2003-09-11 12:25:06 +00:00
|
|
|
nsXBLEventHandler::nsXBLEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: mProtoHandler(aHandler)
|
2000-01-26 10:06:30 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLEventHandler::~nsXBLEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLEventHandler, nsIDOMEventListener)
|
2000-01-26 10:06:30 +00:00
|
|
|
|
2003-09-11 12:25:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
2000-06-22 00:36:19 +00:00
|
|
|
{
|
2000-09-03 06:00:09 +00:00
|
|
|
if (!mProtoHandler)
|
2003-09-11 12:25:06 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-03 06:00:09 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t phase = mProtoHandler->GetPhase();
|
2003-09-11 12:25:06 +00:00
|
|
|
if (phase == NS_PHASE_TARGET) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t eventPhase;
|
2003-09-11 12:25:06 +00:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
2003-03-24 04:00:58 +00:00
|
|
|
}
|
2003-09-11 12:25:06 +00:00
|
|
|
|
|
|
|
if (!EventMatched(aEvent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-04-06 00:44:26 +00:00
|
|
|
mProtoHandler->ExecuteHandler(aEvent->InternalDOMEvent()->GetCurrentTarget(),
|
|
|
|
aEvent);
|
2003-09-11 12:25:06 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-06-22 00:36:19 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:25:06 +00:00
|
|
|
nsXBLMouseEventHandler::nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: nsXBLEventHandler(aHandler)
|
|
|
|
{
|
|
|
|
}
|
2000-01-26 10:06:30 +00:00
|
|
|
|
2003-09-11 12:25:06 +00:00
|
|
|
nsXBLMouseEventHandler::~nsXBLMouseEventHandler()
|
2000-05-15 07:19:35 +00:00
|
|
|
{
|
2003-09-11 12:25:06 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2003-09-11 12:25:06 +00:00
|
|
|
nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
|
2008-12-19 22:39:47 +00:00
|
|
|
return mouse && mProtoHandler->MouseEventMatched(mouse);
|
2003-09-11 12:25:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
|
|
|
|
uint8_t aType)
|
2003-09-11 12:25:06 +00:00
|
|
|
: mEventType(aEventType),
|
|
|
|
mPhase(aPhase),
|
2007-04-15 16:28:53 +00:00
|
|
|
mType(aType),
|
2013-11-01 14:31:58 +00:00
|
|
|
mIsBoundToChrome(false),
|
|
|
|
mUsingXBLScope(false)
|
2003-09-11 12:25:06 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLKeyEventHandler::~nsXBLKeyEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener)
|
2003-09-11 12:25:06 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2008-04-15 04:16:24 +00:00
|
|
|
nsXBLKeyEventHandler::ExecuteMatchedHandlers(nsIDOMKeyEvent* aKeyEvent,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aCharCode,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aIgnoreShiftKey)
|
2008-04-15 04:16:24 +00:00
|
|
|
{
|
2011-09-29 06:19:26 +00:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 07:44:00 +00:00
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2008-04-15 04:16:24 +00:00
|
|
|
|
2013-04-06 00:44:26 +00:00
|
|
|
nsCOMPtr<EventTarget> target = aKeyEvent->InternalDOMEvent()->GetCurrentTarget();
|
2008-04-15 04:16:24 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool executed = false;
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) {
|
2009-03-20 08:15:35 +00:00
|
|
|
nsXBLPrototypeHandler* handler = mProtoHandlers[i];
|
2011-09-29 06:19:26 +00:00
|
|
|
bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
|
2008-04-15 04:16:24 +00:00
|
|
|
if ((trustedEvent ||
|
|
|
|
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
|
2013-11-01 14:31:58 +00:00
|
|
|
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingXBLScope)) &&
|
2008-04-15 04:16:24 +00:00
|
|
|
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreShiftKey)) {
|
2011-06-24 02:18:01 +00:00
|
|
|
handler->ExecuteHandler(target, aKeyEvent);
|
2011-10-17 14:59:28 +00:00
|
|
|
executed = true;
|
2008-04-15 04:16:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return executed;
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:25:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count = mProtoHandlers.Length();
|
2003-09-11 12:25:06 +00:00
|
|
|
if (count == 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mPhase == NS_PHASE_TARGET) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t eventPhase;
|
2003-09-11 12:25:06 +00:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
2000-05-15 07:19:35 +00:00
|
|
|
}
|
2003-09-11 12:25:06 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
|
2008-09-16 01:37:13 +00:00
|
|
|
if (!key)
|
|
|
|
return NS_OK;
|
2003-09-11 12:25:06 +00:00
|
|
|
|
2008-04-15 04:16:24 +00:00
|
|
|
nsAutoTArray<nsShortcutCandidate, 10> accessKeys;
|
2008-09-16 01:37:13 +00:00
|
|
|
nsContentUtils::GetAccelKeyCandidates(key, accessKeys);
|
2005-08-21 22:20:36 +00:00
|
|
|
|
2008-04-15 04:16:24 +00:00
|
|
|
if (accessKeys.IsEmpty()) {
|
2011-10-17 14:59:28 +00:00
|
|
|
ExecuteMatchedHandlers(key, 0, false);
|
2008-04-15 04:16:24 +00:00
|
|
|
return NS_OK;
|
2003-09-11 12:25:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
for (uint32_t i = 0; i < accessKeys.Length(); ++i) {
|
2008-04-15 04:16:24 +00:00
|
|
|
if (ExecuteMatchedHandlers(key, accessKeys[i].mCharCode,
|
|
|
|
accessKeys[i].mIgnoreShift))
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-05-15 07:19:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
2003-09-11 12:25:06 +00:00
|
|
|
NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
|
|
|
|
nsIAtom* aEventType,
|
2000-01-26 10:06:30 +00:00
|
|
|
nsXBLEventHandler** aResult)
|
|
|
|
{
|
2011-04-18 20:57:32 +00:00
|
|
|
switch (nsContentUtils::GetEventCategory(nsDependentAtomString(aEventType))) {
|
|
|
|
case NS_DRAG_EVENT:
|
|
|
|
case NS_MOUSE_EVENT:
|
|
|
|
case NS_MOUSE_SCROLL_EVENT:
|
2012-08-12 01:42:34 +00:00
|
|
|
case NS_WHEEL_EVENT:
|
2011-04-18 20:57:32 +00:00
|
|
|
case NS_SIMPLE_GESTURE_EVENT:
|
|
|
|
*aResult = new nsXBLMouseEventHandler(aHandler);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*aResult = new nsXBLEventHandler(aHandler);
|
|
|
|
break;
|
2003-09-11 12:25:06 +00:00
|
|
|
}
|
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-09-11 12:25:06 +00:00
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
NS_ADDREF(*aResult);
|
2003-09-11 12:25:06 +00:00
|
|
|
|
2000-01-26 10:06:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-09-11 12:25:06 +00:00
|
|
|
|
|
|
|
nsresult
|
2012-08-22 15:56:38 +00:00
|
|
|
NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType,
|
2003-09-11 12:25:06 +00:00
|
|
|
nsXBLKeyEventHandler** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXBLKeyEventHandler(aEventType, aPhase, aType);
|
|
|
|
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
2003-09-17 19:19:53 +00:00
|
|
|
}
|