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
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIAtom.h"
|
2007-05-14 02:11:38 -07:00
|
|
|
#include "nsIDOMEventListener.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIDOMMouseEvent.h"
|
|
|
|
#include "nsXBLPrototypeHandler.h"
|
2007-04-15 09:28:53 -07:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-04 16:37:43 -08:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-04-05 17:44:26 -07:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-12-12 04:17:37 -08:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-04-05 17:44:26 -07:00
|
|
|
|
2014-08-03 22:28:50 -07:00
|
|
|
using namespace mozilla;
|
2013-04-05 17:44:26 -07:00
|
|
|
using namespace mozilla::dom;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsXBLEventHandler::nsXBLEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: mProtoHandler(aHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLEventHandler::~nsXBLEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLEventHandler, nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
if (!mProtoHandler)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint8_t phase = mProtoHandler->GetPhase();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (phase == NS_PHASE_TARGET) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t eventPhase;
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!EventMatched(aEvent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-04-05 17:44:26 -07:00
|
|
|
mProtoHandler->ExecuteHandler(aEvent->InternalDOMEvent()->GetCurrentTarget(),
|
|
|
|
aEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLMouseEventHandler::nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: nsXBLEventHandler(aHandler)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLMouseEventHandler::~nsXBLMouseEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
|
2008-12-19 14:39:47 -08:00
|
|
|
return mouse && mProtoHandler->MouseEventMatched(mouse);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
|
|
|
|
uint8_t aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mEventType(aEventType),
|
|
|
|
mPhase(aPhase),
|
2007-04-15 09:28:53 -07:00
|
|
|
mType(aType),
|
2013-11-01 07:31:58 -07:00
|
|
|
mIsBoundToChrome(false),
|
2014-06-02 18:04:21 -07:00
|
|
|
mUsingContentXBLScope(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLKeyEventHandler::~nsXBLKeyEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2014-12-12 04:17:37 -08:00
|
|
|
nsXBLKeyEventHandler::ExecuteMatchedHandlers(
|
|
|
|
nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
uint32_t aCharCode,
|
|
|
|
const IgnoreModifierState& aIgnoreModifierState)
|
2008-04-14 21:16:24 -07:00
|
|
|
{
|
2014-12-12 04:17:37 -08:00
|
|
|
WidgetEvent* event = aKeyEvent->GetInternalNSEvent();
|
2013-04-05 17:44:26 -07:00
|
|
|
nsCOMPtr<EventTarget> target = aKeyEvent->InternalDOMEvent()->GetCurrentTarget();
|
2008-04-14 21:16:24 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool executed = false;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) {
|
2009-03-20 01:15:35 -07:00
|
|
|
nsXBLPrototypeHandler* handler = mProtoHandlers[i];
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
|
2014-12-12 04:17:37 -08:00
|
|
|
if ((event->mFlags.mIsTrusted ||
|
2008-04-14 21:16:24 -07:00
|
|
|
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
|
2014-06-02 18:04:21 -07:00
|
|
|
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingContentXBLScope)) &&
|
2014-12-12 04:17:37 -08:00
|
|
|
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreModifierState)) {
|
2011-06-23 19:18:01 -07:00
|
|
|
handler->ExecuteHandler(target, aKeyEvent);
|
2011-10-17 07:59:28 -07:00
|
|
|
executed = true;
|
2008-04-14 21:16:24 -07:00
|
|
|
}
|
|
|
|
}
|
2014-12-12 04:17:37 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
// Windows native applications ignore Windows-Logo key state when checking
|
|
|
|
// shortcut keys even if the key is pressed. Therefore, if there is no
|
|
|
|
// shortcut key which exactly matches current modifier state, we should
|
|
|
|
// retry to look for a shortcut key without the Windows-Logo key press.
|
|
|
|
if (!executed && !aIgnoreModifierState.mOS) {
|
|
|
|
WidgetKeyboardEvent* keyEvent = event->AsKeyboardEvent();
|
|
|
|
if (keyEvent && keyEvent->IsOS()) {
|
|
|
|
IgnoreModifierState ignoreModifierState(aIgnoreModifierState);
|
|
|
|
ignoreModifierState.mOS = true;
|
|
|
|
return ExecuteMatchedHandlers(aKeyEvent, aCharCode, ignoreModifierState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2008-04-14 21:16:24 -07:00
|
|
|
return executed;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t count = mProtoHandlers.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (count == 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mPhase == NS_PHASE_TARGET) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t eventPhase;
|
2007-03-22 10:30:00 -07:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
|
2008-09-15 18:37:13 -07:00
|
|
|
if (!key)
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
nsAutoTArray<nsShortcutCandidate, 10> accessKeys;
|
2008-09-15 18:37:13 -07:00
|
|
|
nsContentUtils::GetAccelKeyCandidates(key, accessKeys);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
if (accessKeys.IsEmpty()) {
|
2014-12-12 04:17:37 -08:00
|
|
|
ExecuteMatchedHandlers(key, 0, IgnoreModifierState());
|
2008-04-14 21:16:24 -07:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < accessKeys.Length(); ++i) {
|
2014-12-12 04:17:37 -08:00
|
|
|
IgnoreModifierState ignoreModifierState;
|
|
|
|
ignoreModifierState.mShift = accessKeys[i].mIgnoreShift;
|
2008-04-14 21:16:24 -07:00
|
|
|
if (ExecuteMatchedHandlers(key, accessKeys[i].mCharCode,
|
2014-12-12 04:17:37 -08:00
|
|
|
ignoreModifierState)) {
|
2008-04-14 21:16:24 -07:00
|
|
|
return NS_OK;
|
2014-12-12 04:17:37 -08:00
|
|
|
}
|
2008-04-14 21:16:24 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
|
|
|
|
nsIAtom* aEventType,
|
|
|
|
nsXBLEventHandler** aResult)
|
|
|
|
{
|
2014-08-03 22:28:58 -07:00
|
|
|
switch (nsContentUtils::GetEventClassID(nsDependentAtomString(aEventType))) {
|
2014-08-03 22:28:50 -07:00
|
|
|
case eDragEventClass:
|
2014-08-03 22:28:50 -07:00
|
|
|
case eMouseEventClass:
|
2014-08-03 22:28:51 -07:00
|
|
|
case eMouseScrollEventClass:
|
2014-08-03 22:28:51 -07:00
|
|
|
case eWheelEventClass:
|
2014-08-03 22:28:53 -07:00
|
|
|
case eSimpleGestureEventClass:
|
2011-04-18 13:57:32 -07:00
|
|
|
*aResult = new nsXBLMouseEventHandler(aHandler);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*aResult = new nsXBLEventHandler(aHandler);
|
|
|
|
break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_NewXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase, uint8_t aType,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsXBLKeyEventHandler** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsXBLKeyEventHandler(aEventType, aPhase, aType);
|
|
|
|
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|