2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2000-03-21 16:14:34 +03:00
|
|
|
|
2000-01-26 13:06:30 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2007-05-14 13:11:38 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
2000-01-26 13:06:30 +03:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-05-21 10:58:15 +04:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2003-09-11 16:25:06 +04:00
|
|
|
#include "nsXBLPrototypeHandler.h"
|
2007-04-15 20:28:53 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-03-05 04:37:43 +04:00
|
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
2013-04-06 04:44:26 +04:00
|
|
|
#include "mozilla/dom/EventTarget.h"
|
2014-12-12 15:17:37 +03:00
|
|
|
#include "mozilla/TextEvents.h"
|
2013-04-06 04:44:26 +04:00
|
|
|
|
2014-08-04 09:28:50 +04:00
|
|
|
using namespace mozilla;
|
2013-04-06 04:44:26 +04:00
|
|
|
using namespace mozilla::dom;
|
2000-01-26 13:06:30 +03:00
|
|
|
|
2003-09-11 16:25:06 +04:00
|
|
|
nsXBLEventHandler::nsXBLEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: mProtoHandler(aHandler)
|
2000-01-26 13:06:30 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLEventHandler::~nsXBLEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLEventHandler, nsIDOMEventListener)
|
2000-01-26 13:06:30 +03:00
|
|
|
|
2003-09-11 16:25:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
2000-06-22 04:36:19 +04:00
|
|
|
{
|
2000-09-03 10:00:09 +04:00
|
|
|
if (!mProtoHandler)
|
2003-09-11 16:25:06 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2000-09-03 10:00:09 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t phase = mProtoHandler->GetPhase();
|
2003-09-11 16:25:06 +04:00
|
|
|
if (phase == NS_PHASE_TARGET) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t eventPhase;
|
2003-09-11 16:25:06 +04:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
2003-03-24 07:00:58 +03:00
|
|
|
}
|
2003-09-11 16:25:06 +04:00
|
|
|
|
|
|
|
if (!EventMatched(aEvent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2013-04-06 04:44:26 +04:00
|
|
|
mProtoHandler->ExecuteHandler(aEvent->InternalDOMEvent()->GetCurrentTarget(),
|
|
|
|
aEvent);
|
2003-09-11 16:25:06 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
2000-06-22 04:36:19 +04:00
|
|
|
}
|
|
|
|
|
2003-09-11 16:25:06 +04:00
|
|
|
nsXBLMouseEventHandler::nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
|
|
: nsXBLEventHandler(aHandler)
|
|
|
|
{
|
|
|
|
}
|
2000-01-26 13:06:30 +03:00
|
|
|
|
2003-09-11 16:25:06 +04:00
|
|
|
nsXBLMouseEventHandler::~nsXBLMouseEventHandler()
|
2000-05-15 11:19:35 +04:00
|
|
|
{
|
2003-09-11 16:25:06 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2003-09-11 16:25:06 +04:00
|
|
|
nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
|
2008-12-20 01:39:47 +03:00
|
|
|
return mouse && mProtoHandler->MouseEventMatched(mouse);
|
2003-09-11 16:25:06 +04:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsAtom* aEventType, uint8_t aPhase,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aType)
|
2003-09-11 16:25:06 +04:00
|
|
|
: mEventType(aEventType),
|
|
|
|
mPhase(aPhase),
|
2007-04-15 20:28:53 +04:00
|
|
|
mType(aType),
|
2013-11-01 18:31:58 +04:00
|
|
|
mIsBoundToChrome(false),
|
2014-06-03 05:04:21 +04:00
|
|
|
mUsingContentXBLScope(false)
|
2003-09-11 16:25:06 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsXBLKeyEventHandler::~nsXBLKeyEventHandler()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener)
|
2003-09-11 16:25:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-12-12 15:17:37 +03:00
|
|
|
nsXBLKeyEventHandler::ExecuteMatchedHandlers(
|
|
|
|
nsIDOMKeyEvent* aKeyEvent,
|
|
|
|
uint32_t aCharCode,
|
|
|
|
const IgnoreModifierState& aIgnoreModifierState)
|
2008-04-15 08:16:24 +04:00
|
|
|
{
|
2016-02-12 18:40:07 +03:00
|
|
|
WidgetEvent* event = aKeyEvent->AsEvent()->WidgetEventPtr();
|
2016-01-12 07:19:08 +03:00
|
|
|
nsCOMPtr<EventTarget> target = aKeyEvent->AsEvent()->InternalDOMEvent()->GetCurrentTarget();
|
2008-04-15 08:16:24 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool executed = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) {
|
2009-03-20 11:15:35 +03:00
|
|
|
nsXBLPrototypeHandler* handler = mProtoHandlers[i];
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
|
2016-03-17 10:01:30 +03:00
|
|
|
if ((event->IsTrusted() ||
|
2008-04-15 08:16:24 +04:00
|
|
|
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
|
2014-06-03 05:04:21 +04:00
|
|
|
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingContentXBLScope)) &&
|
2014-12-12 15:17:37 +03:00
|
|
|
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreModifierState)) {
|
2016-01-12 07:19:08 +03:00
|
|
|
handler->ExecuteHandler(target, aKeyEvent->AsEvent());
|
2011-10-17 18:59:28 +04:00
|
|
|
executed = true;
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
|
|
|
}
|
2014-12-12 15:17:37 +03: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-15 08:16:24 +04:00
|
|
|
return executed;
|
|
|
|
}
|
|
|
|
|
2003-09-11 16:25:06 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = mProtoHandlers.Length();
|
2003-09-11 16:25:06 +04:00
|
|
|
if (count == 0)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mPhase == NS_PHASE_TARGET) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t eventPhase;
|
2003-09-11 16:25:06 +04:00
|
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
|
|
return NS_OK;
|
2000-05-15 11:19:35 +04:00
|
|
|
}
|
2003-09-11 16:25:06 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
|
2008-09-16 05:37:13 +04:00
|
|
|
if (!key)
|
|
|
|
return NS_OK;
|
2003-09-11 16:25:06 +04:00
|
|
|
|
2016-03-18 05:22:37 +03:00
|
|
|
WidgetKeyboardEvent* nativeKeyboardEvent =
|
|
|
|
aEvent->WidgetEventPtr()->AsKeyboardEvent();
|
|
|
|
MOZ_ASSERT(nativeKeyboardEvent);
|
|
|
|
AutoShortcutKeyCandidateArray shortcutKeys;
|
|
|
|
nativeKeyboardEvent->GetShortcutKeyCandidates(shortcutKeys);
|
2005-08-22 02:20:36 +04:00
|
|
|
|
2016-03-18 05:22:37 +03:00
|
|
|
if (shortcutKeys.IsEmpty()) {
|
2014-12-12 15:17:37 +03:00
|
|
|
ExecuteMatchedHandlers(key, 0, IgnoreModifierState());
|
2008-04-15 08:16:24 +04:00
|
|
|
return NS_OK;
|
2003-09-11 16:25:06 +04:00
|
|
|
}
|
|
|
|
|
2016-03-18 05:22:37 +03:00
|
|
|
for (uint32_t i = 0; i < shortcutKeys.Length(); ++i) {
|
2014-12-12 15:17:37 +03:00
|
|
|
IgnoreModifierState ignoreModifierState;
|
2016-03-18 05:22:37 +03:00
|
|
|
ignoreModifierState.mShift = shortcutKeys[i].mIgnoreShift;
|
|
|
|
if (ExecuteMatchedHandlers(key, shortcutKeys[i].mCharCode,
|
2014-12-12 15:17:37 +03:00
|
|
|
ignoreModifierState)) {
|
2008-04-15 08:16:24 +04:00
|
|
|
return NS_OK;
|
2014-12-12 15:17:37 +03:00
|
|
|
}
|
2008-04-15 08:16:24 +04:00
|
|
|
}
|
2000-05-15 11:19:35 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-26 13:06:30 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-01-30 21:55:11 +03:00
|
|
|
already_AddRefed<nsXBLEventHandler>
|
2003-09-11 16:25:06 +04:00
|
|
|
NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aEventType)
|
2000-01-26 13:06:30 +03:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsXBLEventHandler> handler;
|
2015-01-30 21:55:11 +03:00
|
|
|
|
2014-08-04 09:28:58 +04:00
|
|
|
switch (nsContentUtils::GetEventClassID(nsDependentAtomString(aEventType))) {
|
2014-08-04 09:28:50 +04:00
|
|
|
case eDragEventClass:
|
2014-08-04 09:28:50 +04:00
|
|
|
case eMouseEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eMouseScrollEventClass:
|
2014-08-04 09:28:51 +04:00
|
|
|
case eWheelEventClass:
|
2014-08-04 09:28:53 +04:00
|
|
|
case eSimpleGestureEventClass:
|
2015-01-30 21:55:11 +03:00
|
|
|
handler = new nsXBLMouseEventHandler(aHandler);
|
2011-04-19 00:57:32 +04:00
|
|
|
break;
|
|
|
|
default:
|
2015-01-30 21:55:11 +03:00
|
|
|
handler = new nsXBLEventHandler(aHandler);
|
2011-04-19 00:57:32 +04:00
|
|
|
break;
|
2003-09-11 16:25:06 +04:00
|
|
|
}
|
|
|
|
|
2015-01-30 21:55:11 +03:00
|
|
|
return handler.forget();
|
2000-01-26 13:06:30 +03:00
|
|
|
}
|