mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 06:35:42 +00:00
01583602a9
The bulk of this commit was generated with a script, executed at the top level of a typical source code checkout. The only non-machine-generated part was modifying MFBT's moz.build to reflect the new naming. CLOSED TREE makes big refactorings like this a piece of cake. # The main substitution. find . -name '*.cpp' -o -name '*.cc' -o -name '*.h' -o -name '*.mm' -o -name '*.idl'| \ xargs perl -p -i -e ' s/nsRefPtr\.h/RefPtr\.h/g; # handle includes s/nsRefPtr ?</RefPtr</g; # handle declarations and variables ' # Handle a special friend declaration in gfx/layers/AtomicRefCountedWithFinalize.h. perl -p -i -e 's/::nsRefPtr;/::RefPtr;/' gfx/layers/AtomicRefCountedWithFinalize.h # Handle nsRefPtr.h itself, a couple places that define constructors # from nsRefPtr, and code generators specially. We do this here, rather # than indiscriminantly s/nsRefPtr/RefPtr/, because that would rename # things like nsRefPtrHashtable. perl -p -i -e 's/nsRefPtr/RefPtr/g' \ mfbt/nsRefPtr.h \ xpcom/glue/nsCOMPtr.h \ xpcom/base/OwningNonNull.h \ ipc/ipdl/ipdl/lower.py \ ipc/ipdl/ipdl/builtin.py \ dom/bindings/Codegen.py \ python/lldbutils/lldbutils/utils.py # In our indiscriminate substitution above, we renamed # nsRefPtrGetterAddRefs, the class behind getter_AddRefs. Fix that up. find . -name '*.cpp' -o -name '*.h' -o -name '*.idl' | \ xargs perl -p -i -e 's/nsRefPtrGetterAddRefs/RefPtrGetterAddRefs/g' if [ -d .git ]; then git mv mfbt/nsRefPtr.h mfbt/RefPtr.h else hg mv mfbt/nsRefPtr.h mfbt/RefPtr.h fi --HG-- rename : mfbt/nsRefPtr.h => mfbt/RefPtr.h
185 lines
5.3 KiB
C++
185 lines
5.3 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIAtom.h"
|
|
#include "nsIDOMEventListener.h"
|
|
#include "nsIDOMKeyEvent.h"
|
|
#include "nsIDOMMouseEvent.h"
|
|
#include "nsXBLPrototypeHandler.h"
|
|
#include "nsContentUtils.h"
|
|
#include "mozilla/dom/Event.h" // for nsIDOMEvent::InternalDOMEvent()
|
|
#include "mozilla/dom/EventTarget.h"
|
|
#include "mozilla/TextEvents.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
nsXBLEventHandler::nsXBLEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
: mProtoHandler(aHandler)
|
|
{
|
|
}
|
|
|
|
nsXBLEventHandler::~nsXBLEventHandler()
|
|
{
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(nsXBLEventHandler, nsIDOMEventListener)
|
|
|
|
NS_IMETHODIMP
|
|
nsXBLEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
{
|
|
if (!mProtoHandler)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
uint8_t phase = mProtoHandler->GetPhase();
|
|
if (phase == NS_PHASE_TARGET) {
|
|
uint16_t eventPhase;
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
return NS_OK;
|
|
}
|
|
|
|
if (!EventMatched(aEvent))
|
|
return NS_OK;
|
|
|
|
mProtoHandler->ExecuteHandler(aEvent->InternalDOMEvent()->GetCurrentTarget(),
|
|
aEvent);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsXBLMouseEventHandler::nsXBLMouseEventHandler(nsXBLPrototypeHandler* aHandler)
|
|
: nsXBLEventHandler(aHandler)
|
|
{
|
|
}
|
|
|
|
nsXBLMouseEventHandler::~nsXBLMouseEventHandler()
|
|
{
|
|
}
|
|
|
|
bool
|
|
nsXBLMouseEventHandler::EventMatched(nsIDOMEvent* aEvent)
|
|
{
|
|
nsCOMPtr<nsIDOMMouseEvent> mouse(do_QueryInterface(aEvent));
|
|
return mouse && mProtoHandler->MouseEventMatched(mouse);
|
|
}
|
|
|
|
nsXBLKeyEventHandler::nsXBLKeyEventHandler(nsIAtom* aEventType, uint8_t aPhase,
|
|
uint8_t aType)
|
|
: mEventType(aEventType),
|
|
mPhase(aPhase),
|
|
mType(aType),
|
|
mIsBoundToChrome(false),
|
|
mUsingContentXBLScope(false)
|
|
{
|
|
}
|
|
|
|
nsXBLKeyEventHandler::~nsXBLKeyEventHandler()
|
|
{
|
|
}
|
|
|
|
NS_IMPL_ISUPPORTS(nsXBLKeyEventHandler, nsIDOMEventListener)
|
|
|
|
bool
|
|
nsXBLKeyEventHandler::ExecuteMatchedHandlers(
|
|
nsIDOMKeyEvent* aKeyEvent,
|
|
uint32_t aCharCode,
|
|
const IgnoreModifierState& aIgnoreModifierState)
|
|
{
|
|
WidgetEvent* event = aKeyEvent->GetInternalNSEvent();
|
|
nsCOMPtr<EventTarget> target = aKeyEvent->InternalDOMEvent()->GetCurrentTarget();
|
|
|
|
bool executed = false;
|
|
for (uint32_t i = 0; i < mProtoHandlers.Length(); ++i) {
|
|
nsXBLPrototypeHandler* handler = mProtoHandlers[i];
|
|
bool hasAllowUntrustedAttr = handler->HasAllowUntrustedAttr();
|
|
if ((event->mFlags.mIsTrusted ||
|
|
(hasAllowUntrustedAttr && handler->AllowUntrustedEvents()) ||
|
|
(!hasAllowUntrustedAttr && !mIsBoundToChrome && !mUsingContentXBLScope)) &&
|
|
handler->KeyEventMatched(aKeyEvent, aCharCode, aIgnoreModifierState)) {
|
|
handler->ExecuteHandler(target, aKeyEvent);
|
|
executed = true;
|
|
}
|
|
}
|
|
#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
|
|
return executed;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsXBLKeyEventHandler::HandleEvent(nsIDOMEvent* aEvent)
|
|
{
|
|
uint32_t count = mProtoHandlers.Length();
|
|
if (count == 0)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (mPhase == NS_PHASE_TARGET) {
|
|
uint16_t eventPhase;
|
|
aEvent->GetEventPhase(&eventPhase);
|
|
if (eventPhase != nsIDOMEvent::AT_TARGET)
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> key(do_QueryInterface(aEvent));
|
|
if (!key)
|
|
return NS_OK;
|
|
|
|
nsAutoTArray<nsShortcutCandidate, 10> accessKeys;
|
|
nsContentUtils::GetAccelKeyCandidates(key, accessKeys);
|
|
|
|
if (accessKeys.IsEmpty()) {
|
|
ExecuteMatchedHandlers(key, 0, IgnoreModifierState());
|
|
return NS_OK;
|
|
}
|
|
|
|
for (uint32_t i = 0; i < accessKeys.Length(); ++i) {
|
|
IgnoreModifierState ignoreModifierState;
|
|
ignoreModifierState.mShift = accessKeys[i].mIgnoreShift;
|
|
if (ExecuteMatchedHandlers(key, accessKeys[i].mCharCode,
|
|
ignoreModifierState)) {
|
|
return NS_OK;
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////
|
|
|
|
already_AddRefed<nsXBLEventHandler>
|
|
NS_NewXBLEventHandler(nsXBLPrototypeHandler* aHandler,
|
|
nsIAtom* aEventType)
|
|
{
|
|
RefPtr<nsXBLEventHandler> handler;
|
|
|
|
switch (nsContentUtils::GetEventClassID(nsDependentAtomString(aEventType))) {
|
|
case eDragEventClass:
|
|
case eMouseEventClass:
|
|
case eMouseScrollEventClass:
|
|
case eWheelEventClass:
|
|
case eSimpleGestureEventClass:
|
|
handler = new nsXBLMouseEventHandler(aHandler);
|
|
break;
|
|
default:
|
|
handler = new nsXBLEventHandler(aHandler);
|
|
break;
|
|
}
|
|
|
|
return handler.forget();
|
|
}
|