Bug 920425 part.27 Use mozilla::WidgetEvent::AsInputEvent() r=smaug

This commit is contained in:
Masayuki Nakano 2013-10-18 15:10:26 +09:00
parent 87eb530a19
commit 92e611a583
22 changed files with 151 additions and 124 deletions

View File

@ -2249,8 +2249,7 @@ Element::PostHandleEventForLinks(nsEventChainPostVisitor& aVisitor)
case NS_MOUSE_CLICK:
if (aVisitor.mEvent->IsLeftClickEvent()) {
WidgetInputEvent* inputEvent =
static_cast<WidgetInputEvent*>(aVisitor.mEvent);
WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
if (inputEvent->IsControl() || inputEvent->IsMeta() ||
inputEvent->IsAlt() ||inputEvent->IsShift()) {
break;

View File

@ -526,7 +526,7 @@ nsDOMEvent::DuplicatePrivateData()
}
case NS_INPUT_EVENT:
{
WidgetInputEvent* oldInputEvent = static_cast<WidgetInputEvent*>(mEvent);
WidgetInputEvent* oldInputEvent = mEvent->AsInputEvent();
WidgetInputEvent* inputEvent = new WidgetInputEvent(false, msg, nullptr);
inputEvent->AssignInputEventData(*oldInputEvent, true);
newEvent = inputEvent;

View File

@ -33,6 +33,12 @@ NS_INTERFACE_MAP_BEGIN(nsDOMKeyboardEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMKeyEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
bool
nsDOMKeyboardEvent::AltKey()
{
return mEvent->AsKeyboardEvent()->IsAlt();
}
NS_IMETHODIMP
nsDOMKeyboardEvent::GetAltKey(bool* aIsDown)
{
@ -41,6 +47,12 @@ nsDOMKeyboardEvent::GetAltKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMKeyboardEvent::CtrlKey()
{
return mEvent->AsKeyboardEvent()->IsControl();
}
NS_IMETHODIMP
nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown)
{
@ -49,6 +61,12 @@ nsDOMKeyboardEvent::GetCtrlKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMKeyboardEvent::ShiftKey()
{
return mEvent->AsKeyboardEvent()->IsShift();
}
NS_IMETHODIMP
nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown)
{
@ -57,6 +75,12 @@ nsDOMKeyboardEvent::GetShiftKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMKeyboardEvent::MetaKey()
{
return mEvent->AsKeyboardEvent()->IsMeta();
}
NS_IMETHODIMP
nsDOMKeyboardEvent::GetMetaKey(bool* aIsDown)
{

View File

@ -10,7 +10,6 @@
#include "nsDOMUIEvent.h"
#include "mozilla/EventForwards.h"
#include "mozilla/dom/KeyboardEventBinding.h"
#include "mozilla/BasicEvents.h"
class nsDOMKeyboardEvent : public nsDOMUIEvent,
public nsIDOMKeyEvent
@ -34,25 +33,10 @@ public:
return mozilla::dom::KeyboardEventBinding::Wrap(aCx, aScope, this);
}
bool AltKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
}
bool CtrlKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
}
bool ShiftKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
}
bool MetaKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
}
bool AltKey();
bool CtrlKey();
bool ShiftKey();
bool MetaKey();
bool GetModifierState(const nsAString& aKey)
{

View File

@ -122,7 +122,7 @@ nsDOMMouseEvent::InitMouseEvent(const nsAString& aType,
case NS_WHEEL_EVENT:
case NS_DRAG_EVENT:
case NS_SIMPLE_GESTURE_EVENT:
static_cast<WidgetInputEvent*>(mEvent)->modifiers = modifiers;
mEvent->AsInputEvent()->modifiers = modifiers;
return NS_OK;
default:
MOZ_CRASH("There is no space to store the modifiers");
@ -354,6 +354,12 @@ nsDOMMouseEvent::ClientY()
mClientPoint).y;
}
bool
nsDOMMouseEvent::AltKey()
{
return mEvent->AsInputEvent()->IsAlt();
}
NS_IMETHODIMP
nsDOMMouseEvent::GetAltKey(bool* aIsDown)
{
@ -362,6 +368,12 @@ nsDOMMouseEvent::GetAltKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMMouseEvent::CtrlKey()
{
return mEvent->AsInputEvent()->IsControl();
}
NS_IMETHODIMP
nsDOMMouseEvent::GetCtrlKey(bool* aIsDown)
{
@ -370,6 +382,12 @@ nsDOMMouseEvent::GetCtrlKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMMouseEvent::ShiftKey()
{
return mEvent->AsInputEvent()->IsShift();
}
NS_IMETHODIMP
nsDOMMouseEvent::GetShiftKey(bool* aIsDown)
{
@ -378,6 +396,12 @@ nsDOMMouseEvent::GetShiftKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMMouseEvent::MetaKey()
{
return mEvent->AsInputEvent()->IsMeta();
}
NS_IMETHODIMP
nsDOMMouseEvent::GetMetaKey(bool* aIsDown)
{

View File

@ -9,7 +9,7 @@
#include "nsIDOMMouseEvent.h"
#include "nsDOMUIEvent.h"
#include "mozilla/dom/MouseEventBinding.h"
#include "mozilla/BasicEvents.h"
#include "mozilla/EventForwards.h"
class nsDOMMouseEvent : public nsDOMUIEvent,
public nsIDOMMouseEvent
@ -43,22 +43,10 @@ public:
int32_t ScreenY();
int32_t ClientX();
int32_t ClientY();
bool CtrlKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
}
bool ShiftKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
}
bool AltKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
}
bool MetaKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
}
bool CtrlKey();
bool ShiftKey();
bool AltKey();
bool MetaKey();
uint16_t Button();
uint16_t Buttons();
already_AddRefed<mozilla::dom::EventTarget> GetRelatedTarget();

View File

@ -107,8 +107,8 @@ nsDOMTouchEvent::InitTouchEvent(const nsAString& aType,
return;
}
static_cast<WidgetInputEvent*>(mEvent)->
InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
aShiftKey, aMetaKey);
mTouches = aTouches;
mTargetTouches = aTargetTouches;
mChangedTouches = aChangedTouches;
@ -213,6 +213,30 @@ nsDOMTouchEvent::PrefEnabled()
return prefValue;
}
bool
nsDOMTouchEvent::AltKey()
{
return mEvent->AsTouchEvent()->IsAlt();
}
bool
nsDOMTouchEvent::MetaKey()
{
return mEvent->AsTouchEvent()->IsMeta();
}
bool
nsDOMTouchEvent::CtrlKey()
{
return mEvent->AsTouchEvent()->IsControl();
}
bool
nsDOMTouchEvent::ShiftKey()
{
return mEvent->AsTouchEvent()->IsShift();
}
nsresult
NS_NewDOMTouchEvent(nsIDOMEvent** aInstancePtrResult,
mozilla::dom::EventTarget* aOwner,

View File

@ -8,8 +8,9 @@
#include "nsDOMUIEvent.h"
#include "nsTArray.h"
#include "mozilla/Attributes.h"
#include "mozilla/TouchEvents.h"
#include "mozilla/EventForwards.h"
#include "nsJSEnvironment.h"
#include "mozilla/dom/Touch.h"
#include "mozilla/dom/TouchEventBinding.h"
#include "nsWrapperCache.h"
@ -98,25 +99,10 @@ public:
nsDOMTouchList* TargetTouches();
nsDOMTouchList* ChangedTouches();
bool AltKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsAlt();
}
bool MetaKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsMeta();
}
bool CtrlKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsControl();
}
bool ShiftKey()
{
return static_cast<mozilla::WidgetInputEvent*>(mEvent)->IsShift();
}
bool AltKey();
bool MetaKey();
bool CtrlKey();
bool ShiftKey();
void InitTouchEvent(const nsAString& aType,
bool aCanBubble,

View File

@ -456,10 +456,8 @@ nsDOMUIEvent::ComputeModifierState(const nsAString& aModifiersList)
bool
nsDOMUIEvent::GetModifierStateInternal(const nsAString& aKey)
{
if (!mEvent->IsInputDerivedEvent()) {
MOZ_CRASH("mEvent must be WidgetInputEvent or derived class");
}
WidgetInputEvent* inputEvent = static_cast<WidgetInputEvent*>(mEvent);
WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
MOZ_ASSERT(inputEvent, "mEvent must be WidgetInputEvent or derived class");
if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
return inputEvent->IsShift();
}

View File

@ -34,6 +34,12 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMXULCommandEvent)
NS_INTERFACE_MAP_ENTRY(nsIDOMXULCommandEvent)
NS_INTERFACE_MAP_END_INHERITING(nsDOMUIEvent)
bool
nsDOMXULCommandEvent::AltKey()
{
return mEvent->AsInputEvent()->IsAlt();
}
NS_IMETHODIMP
nsDOMXULCommandEvent::GetAltKey(bool* aIsDown)
{
@ -42,6 +48,12 @@ nsDOMXULCommandEvent::GetAltKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMXULCommandEvent::CtrlKey()
{
return mEvent->AsInputEvent()->IsControl();
}
NS_IMETHODIMP
nsDOMXULCommandEvent::GetCtrlKey(bool* aIsDown)
{
@ -50,6 +62,12 @@ nsDOMXULCommandEvent::GetCtrlKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMXULCommandEvent::ShiftKey()
{
return mEvent->AsInputEvent()->IsShift();
}
NS_IMETHODIMP
nsDOMXULCommandEvent::GetShiftKey(bool* aIsDown)
{
@ -58,6 +76,12 @@ nsDOMXULCommandEvent::GetShiftKey(bool* aIsDown)
return NS_OK;
}
bool
nsDOMXULCommandEvent::MetaKey()
{
return mEvent->AsInputEvent()->IsMeta();
}
NS_IMETHODIMP
nsDOMXULCommandEvent::GetMetaKey(bool* aIsDown)
{
@ -87,7 +111,8 @@ nsDOMXULCommandEvent::InitCommandEvent(const nsAString& aType,
aView, aDetail);
NS_ENSURE_SUCCESS(rv, rv);
Event()->InitBasicModifiers(aCtrlKey, aAltKey, aShiftKey, aMetaKey);
mEvent->AsInputEvent()->InitBasicModifiers(aCtrlKey, aAltKey,
aShiftKey, aMetaKey);
mSourceEvent = aSourceEvent;
return NS_OK;

View File

@ -34,25 +34,10 @@ public:
return mozilla::dom::XULCommandEventBinding::Wrap(aCx, aScope, this);
}
bool AltKey()
{
return Event()->IsAlt();
}
bool CtrlKey()
{
return Event()->IsControl();
}
bool ShiftKey()
{
return Event()->IsShift();
}
bool MetaKey()
{
return Event()->IsMeta();
}
bool AltKey();
bool CtrlKey();
bool ShiftKey();
bool MetaKey();
already_AddRefed<nsDOMEvent> GetSourceEvent()
{
@ -76,11 +61,6 @@ public:
}
protected:
// Convenience accessor for the event
mozilla::WidgetInputEvent* Event() {
return static_cast<mozilla::WidgetInputEvent*>(mEvent);
}
nsCOMPtr<nsIDOMEvent> mSourceEvent;
};

View File

@ -3789,8 +3789,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor
if (nsIPresShell::GetCapturingContent()) {
break; // don't start drag if someone else is already capturing
}
WidgetInputEvent* inputEvent =
static_cast<WidgetInputEvent*>(aVisitor.mEvent);
WidgetInputEvent* inputEvent = aVisitor.mEvent->AsInputEvent();
if (inputEvent->IsShift() || inputEvent->IsControl() ||
inputEvent->IsAlt() || inputEvent->IsMeta() ||
inputEvent->IsAltGraph() || inputEvent->IsFn() ||
@ -3826,8 +3825,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor
break;
}
SetValueOfRangeForUserEvent(
rangeFrame->GetValueAtEventPoint(
static_cast<WidgetInputEvent*>(aVisitor.mEvent)));
rangeFrame->GetValueAtEventPoint(aVisitor.mEvent->AsInputEvent()));
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
break;
@ -3840,7 +3838,7 @@ HTMLInputElement::PostHandleEventForRangeThumb(nsEventChainPostVisitor& aVisitor
// call CancelRangeThumbDrag() if that is the case. We just finish off
// the drag and set our final value (unless someone has called
// preventDefault() and prevents us getting here).
FinishRangeThumbDrag(static_cast<WidgetInputEvent*>(aVisitor.mEvent));
FinishRangeThumbDrag(aVisitor.mEvent->AsInputEvent());
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
break;

View File

@ -197,7 +197,7 @@ HTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
EventFlags eventFlags;
eventFlags.mMultipleActionsPrevented = true;
DispatchClickEvent(aVisitor.mPresContext,
static_cast<WidgetInputEvent*>(aVisitor.mEvent),
aVisitor.mEvent->AsInputEvent(),
content, false, &eventFlags, &status);
// Do we care about the status this returned? I don't think we do...
// Don't run another <label> off of this click

View File

@ -910,9 +910,8 @@ bool
nsXBLPrototypeHandler::ModifiersMatchMask(nsIDOMUIEvent* aEvent,
bool aIgnoreShiftKey)
{
WidgetEvent* event = aEvent->GetInternalNSEvent();
NS_ENSURE_TRUE(event && event->IsInputDerivedEvent(), false);
WidgetInputEvent* inputEvent = static_cast<WidgetInputEvent*>(event);
WidgetInputEvent* inputEvent = aEvent->GetInternalNSEvent()->AsInputEvent();
NS_ENSURE_TRUE(inputEvent, false);
if (mKeyMask & cMetaMask) {
if (inputEvent->IsMeta() != ((mKeyMask & cMeta) != 0)) {

View File

@ -1190,8 +1190,7 @@ nsXULElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
}
}
WidgetInputEvent* orig =
static_cast<WidgetInputEvent*>(aVisitor.mEvent);
WidgetInputEvent* orig = aVisitor.mEvent->AsInputEvent();
nsContentUtils::DispatchXULCommand(
commandContent,
aVisitor.mEvent->mFlags.mIsTrusted,

View File

@ -2585,8 +2585,7 @@ nsFrame::HandlePress(nsPresContext* aPresContext,
//weaaak. only the editor can display frame selection not just text and images
isEditor = isEditor == nsISelectionDisplay::DISPLAY_ALL;
WidgetInputEvent* keyEvent = static_cast<WidgetInputEvent*>(aEvent);
if (!keyEvent->IsAlt()) {
if (!aEvent->AsInputEvent()->IsAlt()) {
for (nsIContent* content = mContent; content;
content = content->GetParent()) {
if (nsContentUtils::ContentIsDraggable(content) &&

View File

@ -132,10 +132,11 @@ nsButtonBoxFrame::DoMouseClick(WidgetGUIEvent* aEvent, bool aTrustEvent)
bool isAlt = false;
bool isMeta = false;
if(aEvent) {
isShift = static_cast<WidgetInputEvent*>(aEvent)->IsShift();
isControl = static_cast<WidgetInputEvent*>(aEvent)->IsControl();
isAlt = static_cast<WidgetInputEvent*>(aEvent)->IsAlt();
isMeta = static_cast<WidgetInputEvent*>(aEvent)->IsMeta();
WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
isShift = inputEvent->IsShift();
isControl = inputEvent->IsControl();
isAlt = inputEvent->IsAlt();
isMeta = inputEvent->IsMeta();
}
// Have the content handle the event, propagating it according to normal DOM rules.

View File

@ -270,7 +270,7 @@ nsMenuBarListener::GetModifiers(nsIDOMKeyEvent* aKeyEvent)
{
uint32_t modifiers = 0;
WidgetInputEvent* inputEvent =
static_cast<WidgetInputEvent*>(aKeyEvent->GetInternalNSEvent());
aKeyEvent->GetInternalNSEvent()->AsInputEvent();
MOZ_ASSERT(inputEvent);
if (inputEvent->IsShift()) {

View File

@ -1248,12 +1248,12 @@ nsMenuFrame::CreateMenuCommandEvent(WidgetGUIEvent* aEvent, bool aFlipChecked)
nsContentUtils::IsCallerChrome();
bool shift = false, control = false, alt = false, meta = false;
if (aEvent && (aEvent->eventStructType == NS_MOUSE_EVENT ||
aEvent->eventStructType == NS_KEY_EVENT)) {
shift = static_cast<WidgetInputEvent*>(aEvent)->IsShift();
control = static_cast<WidgetInputEvent*>(aEvent)->IsControl();
alt = static_cast<WidgetInputEvent*>(aEvent)->IsAlt();
meta = static_cast<WidgetInputEvent*>(aEvent)->IsMeta();
WidgetInputEvent* inputEvent = aEvent ? aEvent->AsInputEvent() : nullptr;
if (inputEvent) {
shift = inputEvent->IsShift();
control = inputEvent->IsControl();
alt = inputEvent->IsAlt();
meta = inputEvent->IsMeta();
}
// Because the command event is firing asynchronously, a flag is needed to

View File

@ -480,9 +480,9 @@ nsXULPopupManager::InitTriggerEvent(nsIDOMEvent* aEvent, nsIContent* aPopup,
NS_ASSERTION(aPopup, "Expected a popup node");
WidgetEvent* event = aEvent->GetInternalNSEvent();
if (event) {
if (event->eventStructType == NS_MOUSE_EVENT ||
event->eventStructType == NS_KEY_EVENT) {
mCachedModifiers = static_cast<WidgetInputEvent*>(event)->modifiers;
WidgetInputEvent* inputEvent = event->AsInputEvent();
if (inputEvent) {
mCachedModifiers = inputEvent->modifiers;
}
nsIDocument* doc = aPopup->GetCurrentDoc();
if (doc) {

View File

@ -4179,7 +4179,7 @@ bool
TextInputHandlerBase::DispatchEvent(WidgetGUIEvent& aEvent)
{
if (aEvent.message == NS_KEY_PRESS) {
WidgetInputEvent& inputEvent = static_cast<WidgetInputEvent&>(aEvent);
WidgetInputEvent& inputEvent = *aEvent.AsInputEvent();
if (!inputEvent.IsMeta()) {
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandlerBase::DispatchEvent, hiding mouse cursor", this));

View File

@ -1020,8 +1020,7 @@ MetroWidget::ApzReceiveInputEvent(WidgetInputEvent* aEvent)
if (!MetroWidget::sAPZC) {
return nsEventStatus_eIgnore;
}
WidgetInputEvent& event = static_cast<WidgetInputEvent&>(*aEvent);
return MetroWidget::sAPZC->ReceiveInputEvent(event);
return MetroWidget::sAPZC->ReceiveInputEvent(*aEvent->AsInputEvent());
}
nsEventStatus
@ -1034,8 +1033,8 @@ MetroWidget::ApzReceiveInputEvent(WidgetInputEvent* aInEvent,
if (!MetroWidget::sAPZC) {
return nsEventStatus_eIgnore;
}
WidgetInputEvent& event = static_cast<WidgetInputEvent&>(*aInEvent);
return MetroWidget::sAPZC->ReceiveInputEvent(event, aOutEvent);
return MetroWidget::sAPZC->ReceiveInputEvent(*aInEvent->AsInputEvent(),
aOutEvent);
}
LayerManager*