Skip to content

Commit 46fa9e9

Browse files
Bug 910978 part.6 Implement nsTextEvent::AssignTextEventData() and make nsTextEvent not a derived class of nsInputEvent because nobody uses the stored data r=smaug
1 parent 2e5e9a0 commit 46fa9e9

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

content/events/src/nsDOMEvent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ nsDOMEvent::DuplicatePrivateData()
576576
{
577577
nsTextEvent* oldTextEvent = static_cast<nsTextEvent*>(mEvent);
578578
nsTextEvent* textEvent = new nsTextEvent(false, msg, nullptr);
579-
textEvent->AssignGUIEventData(*oldTextEvent, true);
579+
textEvent->AssignTextEventData(*oldTextEvent, true);
580580
newEvent = textEvent;
581581
break;
582582
}

content/events/src/nsDOMUIEvent.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,9 @@ nsDOMUIEvent::ComputeModifierState(const nsAString& aModifiersList)
460460
bool
461461
nsDOMUIEvent::GetModifierStateInternal(const nsAString& aKey)
462462
{
463+
if (!NS_IS_INPUT_EVENT(mEvent)) {
464+
MOZ_CRASH("mEvent must be nsInputEvent or derived class");
465+
}
463466
nsInputEvent* inputEvent = static_cast<nsInputEvent*>(mEvent);
464467
if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
465468
return inputEvent->IsShift();

widget/nsGUIEvent.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ struct nsTextRange
13311331

13321332
typedef nsTextRange* nsTextRangeArray;
13331333

1334-
class nsTextEvent : public nsInputEvent
1334+
class nsTextEvent : public nsGUIEvent
13351335
{
13361336
private:
13371337
friend class mozilla::dom::PBrowserParent;
@@ -1347,7 +1347,7 @@ class nsTextEvent : public nsInputEvent
13471347

13481348
public:
13491349
nsTextEvent(bool isTrusted, uint32_t msg, nsIWidget *w)
1350-
: nsInputEvent(isTrusted, msg, w, NS_TEXT_EVENT),
1350+
: nsGUIEvent(isTrusted, msg, w, NS_TEXT_EVENT),
13511351
rangeCount(0), rangeArray(nullptr), isChar(false)
13521352
{
13531353
}
@@ -1359,6 +1359,16 @@ class nsTextEvent : public nsInputEvent
13591359
// array.
13601360
nsTextRangeArray rangeArray;
13611361
bool isChar;
1362+
1363+
void AssignTextEventData(const nsTextEvent& aEvent, bool aCopyTargets)
1364+
{
1365+
AssignGUIEventData(aEvent, aCopyTargets);
1366+
1367+
isChar = aEvent.isChar;
1368+
1369+
// Currently, we don't need to copy the other members because they are
1370+
// for internal use only (not available from JS).
1371+
}
13621372
};
13631373

13641374
class nsCompositionEvent : public nsGUIEvent
@@ -1924,10 +1934,10 @@ enum nsDragDropEventStatus {
19241934
(((evnt)->eventStructType == NS_INPUT_EVENT) || \
19251935
((evnt)->eventStructType == NS_MOUSE_EVENT) || \
19261936
((evnt)->eventStructType == NS_KEY_EVENT) || \
1927-
((evnt)->eventStructType == NS_TEXT_EVENT) || \
19281937
((evnt)->eventStructType == NS_TOUCH_EVENT) || \
19291938
((evnt)->eventStructType == NS_DRAG_EVENT) || \
19301939
((evnt)->eventStructType == NS_MOUSE_SCROLL_EVENT) || \
1940+
((evnt)->eventStructType == NS_WHEEL_EVENT) || \
19311941
((evnt)->eventStructType == NS_SIMPLE_GESTURE_EVENT))
19321942

19331943
#define NS_IS_MOUSE_EVENT(evnt) \

widget/nsGUIEventIPC.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ struct ParamTraits<nsTextEvent>
338338

339339
static void Write(Message* aMsg, const paramType& aParam)
340340
{
341-
WriteParam(aMsg, static_cast<nsInputEvent>(aParam));
341+
WriteParam(aMsg, static_cast<nsGUIEvent>(aParam));
342342
WriteParam(aMsg, aParam.seqno);
343343
WriteParam(aMsg, aParam.theText);
344344
WriteParam(aMsg, aParam.isChar);
@@ -349,7 +349,7 @@ struct ParamTraits<nsTextEvent>
349349

350350
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
351351
{
352-
if (!ReadParam(aMsg, aIter, static_cast<nsInputEvent*>(aResult)) ||
352+
if (!ReadParam(aMsg, aIter, static_cast<nsGUIEvent*>(aResult)) ||
353353
!ReadParam(aMsg, aIter, &aResult->seqno) ||
354354
!ReadParam(aMsg, aIter, &aResult->theText) ||
355355
!ReadParam(aMsg, aIter, &aResult->isChar) ||

widget/tests/test_assign_event_data.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,29 @@
218218
},
219219
todoMismatch: [],
220220
},
221+
{ description: "nsTextEvent (text)",
222+
targetID: "input-text", eventType: "text",
223+
dispatchEvent: function () {
224+
document.getElementById(this.targetID).value = "";
225+
document.getElementById(this.targetID).focus();
226+
synthesizeComposition({ type: "compositionstart" });
227+
synthesizeComposition({ type: "compositionupdate", data: "\u306D" });
228+
synthesizeText({ "composition":
229+
{ "string": "\u306D",
230+
"clauses":
231+
[
232+
{ "length": 0, "attr": 0 }
233+
]
234+
},
235+
"caret": { "start": 1, "length": 0 }
236+
});
237+
synthesizeComposition({ type: "compositionend", data: "\u732B" });
238+
},
239+
canRun: function () {
240+
return true;
241+
},
242+
todoMismatch: [ ],
243+
},
221244
];
222245

223246
function doTest(aTest)

widget/windows/nsIMM32Handler.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,8 +1593,6 @@ nsIMM32Handler::DispatchTextEvent(nsWindow* aWindow,
15931593
event.rangeArray = textRanges.Elements();
15941594

15951595
event.theText = mCompositionString.get();
1596-
mozilla::widget::ModifierKeyState modKeyState;
1597-
modKeyState.InitInputEvent(event);
15981596

15991597
aWindow->DispatchWindowEvent(&event);
16001598

0 commit comments

Comments
 (0)