Cleanup and fix bugs in PresShell::HandleEvent
Categories
(Core :: DOM: UI Events & Focus Handling, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox67 | --- | fixed |
People
(Reporter: MatsPalmgren_bugz, Assigned: masayuki)
References
Details
Attachments
(46 files)
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
Bug 1466208 - part 37: Move trusted eMouseMove event preparation into the previous switch-case block
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
patch
|
Details | Diff | Splinter Review | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details | |
(deleted),
text/x-phabricator-request
|
Details |
Updated•6 years ago
|
Reporter | ||
Comment 1•6 years ago
|
||
Assignee | ||
Comment 2•6 years ago
|
||
Comment 3•6 years ago
|
||
Assignee | ||
Comment 5•6 years ago
|
||
I think that it is really risky method to change. So, we should fix this bug slowly for detecting regressions.
Assignee | ||
Comment 6•6 years ago
|
||
Assignee | ||
Comment 7•6 years ago
|
||
Assignee | ||
Comment 8•6 years ago
|
||
Assignee | ||
Comment 9•6 years ago
|
||
Well, I was thinking that the best solution is to split each block in HandleEvent() and HandleEventInternal() to methods of PresShell. However, this approach makes too many small methods into PresShell. And badly, some of them may be designed only for specific situations and need to take caller's local variables.
PresShell is a class not only for event handling. So, for grouping event handling helpers, I think that we should create a nexted stack based class called EventHandler
and HandleEvent() should use it. Then, methods can share some variables with members.
Comment 10•6 years ago
|
||
I think I like that approach. It could lead to quite elegant code.
Assignee | ||
Comment 11•6 years ago
|
||
Assignee | ||
Comment 12•6 years ago
|
||
Assignee | ||
Comment 13•6 years ago
|
||
Assignee | ||
Comment 14•6 years ago
|
||
Assignee | ||
Comment 15•6 years ago
|
||
Assignee | ||
Comment 16•6 years ago
|
||
Assignee | ||
Comment 17•6 years ago
|
||
PresShell::HandleEvent() and PresShell::HandleEventInternal() are too big.
Additionally, we have a lot of methods used only by them. So, if we'll
split those big methods, PresShell will have a lot of small methods which
are not grouped as a part of event handling. That's too bad because some
of them may depend on the calling order, etc.
So, for grouping them, PresShell should create a stack class instance to handle
each event. Then, we can store shared information in it only while we're
handling an event.
This patch creates PresShell::EventHandler and PresShell methods become
wrappers of the stack class, but this patch does not change any logic in the
code, i.e., just reorganizing existing methods.
Note that HandleEventWithTarget() and HandleEventInternal() need to take
WidgetEvent rather than WidgetGUIEvent. Additionally, some other methods
require WidgetGUIEvent to refer WidgetGUIEvent::mWidget. Therefore, this
patch does not make the new class store the event as a member.
Assignee | ||
Comment 18•6 years ago
|
||
PresShell::EventHandler::HandleEvent() is too big. That makes us difficult to
understand the flow of them. So, first of all, we should split the method to
smaller chunks. Then, we can understand what we're doing in HandleEvent() more.
This patch creates MaybeHandleEventWithAccessibleCaret() for first handling
block in HandleEvent(). Note that the following patch will clean it up.
I.e., this patch just moves the existing block into the new method.
Assignee | ||
Comment 19•6 years ago
|
||
Because of spinning out from PresShell::EventHandler::HandleEvent(), we can use
early-return style in MaybeHandleEventWithAccessibleCaret(). This patch
rewrites MaybeHandleEventWithAccessibleCaret() with the style.
Assignee | ||
Comment 20•6 years ago
|
||
PresShell::HandleEvent() treats capturing content only when received event is
related to pointing device. And it's used in 2 purposes. One is for computing
to target document of coming event. The other is for handling events using
coordinates. Therefore, if we create a helper method to retrieve it, we can
move the variable into smaller blocks.
Assignee | ||
Comment 21•6 years ago
|
||
In some cases, PresShell::EventHandler::HandleEvent() needs to call
HandleEvent() of another instance.
For retrieving the instance, we need to compute retarget document first.
This patch makes new method to retrieve it. The following patch will clean
up it.
Assignee | ||
Comment 22•6 years ago
|
||
Assignee | ||
Comment 23•6 years ago
|
||
Next, we need to look for a frame for first parameter of calling
PresShell::HandleEvent() of another PresShell instance. This patch creates
PresShell::EventHandler::GetFrameForHandlingEventWith() to do it.
Unfortunately, the result is used in 3 patterns. One is, the caller should
stop handling the event. Another one is, the caller should keep handling
the event by itself. The other is, the caller should call
PresShell::HandleEvent() of different PresShell instance. Therefore, this
patch makes the method take aFrame of the caller. Then, the caller can check
the last 2 patterns with check the result is same as aFrame. This is not so
smart approach, but I have no better idea without adding a bool argument or
making the return type bool and adding out argument of nsIFrame.
Assignee | ||
Comment 24•6 years ago
|
||
Assignee | ||
Comment 25•6 years ago
|
||
Let's move the redirection of coming event in
PresShell::EventHandler::HandleEvent() into a method. This makes the caller
easier to read.
Assignee | ||
Comment 26•6 years ago
|
||
It may not be safe to handle events even when
PresShell::EventHandler::HandleEvent(). In such case, we need to discard
received events with notifying somebody. This patch move this rare case
jobs into the new method, MaybeDiscardEvent(). Then, the caller, HandleEvnet(),
becomes easier to read.
Assignee | ||
Comment 27•6 years ago
|
||
Assignee | ||
Comment 28•6 years ago
|
||
Assignee | ||
Comment 29•6 years ago
|
||
Comment 30•6 years ago
|
||
Comment 31•6 years ago
|
||
bugherder |
Assignee | ||
Comment 32•6 years ago
|
||
Comment 33•6 years ago
|
||
Comment 34•6 years ago
|
||
bugherder |
Assignee | ||
Comment 35•6 years ago
|
||
Comment 36•6 years ago
|
||
Assignee | ||
Comment 37•6 years ago
|
||
Comment 38•6 years ago
|
||
bugherder |
Comment 39•6 years ago
|
||
Comment 40•6 years ago
|
||
bugherder |
Assignee | ||
Comment 41•6 years ago
|
||
Assignee | ||
Comment 42•6 years ago
|
||
Comment 43•6 years ago
|
||
Comment 44•6 years ago
|
||
bugherder |
Assignee | ||
Comment 45•6 years ago
|
||
Comment 46•6 years ago
|
||
Assignee | ||
Comment 47•6 years ago
|
||
Comment 48•6 years ago
|
||
bugherder |
Assignee | ||
Comment 49•6 years ago
|
||
Comment 50•6 years ago
|
||
Comment 51•6 years ago
|
||
bugherder |
Comment 52•6 years ago
|
||
Comment 53•6 years ago
|
||
bugherder |
Assignee | ||
Comment 54•6 years ago
|
||
Assignee | ||
Comment 55•6 years ago
|
||
Comment 56•6 years ago
|
||
Comment 57•6 years ago
|
||
bugherder |
Comment 58•6 years ago
|
||
Comment 59•6 years ago
|
||
bugherder |
Assignee | ||
Comment 60•6 years ago
|
||
Assignee | ||
Comment 61•6 years ago
|
||
PresShell::EventHandler::HandleEvent() discards or puts off to dispatch
the handling event if it's a keyboard event and event dispatching is
suppressed by the document.
This patch moves the block into the new method for making HandleEvent() simpler.
Assignee | ||
Comment 62•6 years ago
|
||
There is an unclear variable frame
in PresShell::EventHandler::HandleEvent().
It's overwritten with different frame and its meanings is changed sometimes.
Finally, it's necessary only in the if (aGUIEvent->IsUsingCoordinates())
block. Therefore, we can move it into the block and rename it when them for
each purpose.
Assignee | ||
Comment 63•6 years ago
|
||
PresShell::EventHandler::HandleEvent() tries to flush pending animation first
when it decides frame to handle events using coordinates. This patch moves
the code into the new method.
Assignee | ||
Comment 64•6 years ago
|
||
In some reasons, handling event should be handled in specific frame even if
the coordinates are out of the frame. PresShell::EventHandler::HandleEvent()
computes it with popups, capturing content, etc. This patch moves the blocks
into new method for making HandleEvent() simpler.
Note that most of the code is just moved. The following patch will clean it
up.
Assignee | ||
Comment 65•6 years ago
|
||
PresShell::EventHandler::ComputeRootFrameToHandleEvent() computes root frame
to handle event with popup frame and/or capturing content. The former result
can be rewritten with the latter. So, for cleaning it up with early return
style, we need to split it to 2 methods.
Assignee | ||
Comment 66•6 years ago
|
||
Assignee | ||
Comment 67•6 years ago
|
||
Updated•6 years ago
|
Assignee | ||
Comment 68•6 years ago
|
||
Comment 69•6 years ago
|
||
Comment 70•6 years ago
|
||
bugherder |
Comment 71•6 years ago
|
||
Comment 72•6 years ago
|
||
bugherder |
Assignee | ||
Comment 73•6 years ago
|
||
Assignee | ||
Comment 74•6 years ago
|
||
Comment 75•6 years ago
|
||
Comment 76•6 years ago
|
||
bugherder |
Comment 77•6 years ago
|
||
Comment 78•6 years ago
|
||
bugherder |
Assignee | ||
Comment 79•6 years ago
|
||
Assignee | ||
Comment 80•6 years ago
|
||
Comment 81•6 years ago
|
||
Comment 82•6 years ago
|
||
bugherder |
Comment 83•6 years ago
|
||
Assignee | ||
Comment 84•6 years ago
|
||
Assignee | ||
Comment 85•6 years ago
|
||
Comment 86•6 years ago
|
||
bugherder |
Assignee | ||
Comment 87•6 years ago
|
||
Assignee | ||
Comment 88•6 years ago
|
||
This patch splits the part handling event when there is pointer capturing
content but it does not have frame.
Assignee | ||
Comment 89•6 years ago
|
||
This patch moves the block, which discard or put the event into the delayed event
queue if handling event is a mouse event, to new method.
Assignee | ||
Comment 90•6 years ago
|
||
PresShell::EventHandler::HandleEvent() looks for PresShell, nsIFrame and
nsIContent a lot for aGUIEvent. Sometimes part of them are modified,
otherwise, all of them are modified by some reasons. Therefore, for
splitting each of the modifiers into separated methods, we need a struct
for making them as a group and usable for in/out parameter.
(If you have some ideas of better name, let me know.)
Assignee | ||
Comment 91•6 years ago
|
||
Now, we can create methods to update event target into EventTargetData().
This moves a block in PresShell::EventHandler::HandleEvent() to retarget
to active document into the new method.
Assignee | ||
Comment 92•6 years ago
|
||
Assignee | ||
Comment 93•6 years ago
|
||
This patch moves the block to compute event target of the event using
coordinates into the new method of PresShell::EventHandler::EventTargetData.
Comment 94•6 years ago
|
||
Comment 95•6 years ago
|
||
bugherder |
Comment 96•6 years ago
|
||
Comment 97•6 years ago
|
||
bugherder |
Comment 98•6 years ago
|
||
Comment 99•6 years ago
|
||
bugherder |
Comment 100•6 years ago
|
||
Comment 101•6 years ago
|
||
Comment 102•6 years ago
|
||
bugherder |
Comment 103•6 years ago
|
||
bugherder |
Comment 104•6 years ago
|
||
Comment 105•6 years ago
|
||
bugherder |
Assignee | ||
Comment 106•6 years ago
|
||
We cannot move each block into separated methods while computing EventTargetData
because we need to check capturing contents, etc. Therefore, only each block
should be moved to separated methods for now.
This moves a block which computes event target from point of the event. If
this can be moved to EventTargetData, it might be easier to understand, but
its helper method GetFrameToHandleNonTouchEvent() requires to access members
of EventHandler. Therefore, we need to treat EventTargetData as an out param
of the new method.
Assignee | ||
Comment 107•6 years ago
|
||
Currently, PresShell::EventHandler::HandleEvent() sets overrideClickTarget
only when Pointer Events is enabled and there is pointer capturing content,
and this is computed while dispatching a pointer event.
So, if we move it into EventTargetData, we can move the pointer event
dispatching block into a separated method and caller can receive it with
an EventTargetData instance which is anyway necessary to receive new
target frame after dispatching a pointer event.
Assignee | ||
Comment 108•6 years ago
|
||
Now, we can move the block dispatching preceding pointer event to separated
method. Then, we can hide the complicated retarget process after dispatching
a pointer event from HandleEvent().
Assignee | ||
Comment 109•6 years ago
|
||
After dispatching pointer events, PresShell::EventHandler::HandleEvent()
updates event target only when the event is a touch event. We should do it in
a new method of EventTargetData
.
Although I don't know why this is done in
PresShell::EventHandler::DispatchPrecedingPointerEvent()
.
Assignee | ||
Comment 110•6 years ago
|
||
Now, the block in HandleEvent(), which handles event using coordinates is
less than 200 lines. Perhaps, this is good amount to be split to a method.
This patch just moves the block to a new method.
Assignee | ||
Comment 111•6 years ago
|
||
When the event is not handled with coordinates and there is no frame for
mPresShell
, PresShell::EventHandler::HandleEvent()
handles the events
simpler than the case there is a frame. Therefore, this patch moves the
else
block of if (aFrame)
and reduce the indent of if (aFrame)
case.
Assignee | ||
Comment 112•6 years ago
|
||
Most remaining code in PresShell::EventHandler::HandleEvent()
is what computes
event target of the event which should be handled on focused content. This
patch moves the part to the new method.
Additionally, moves nsIPresShell::gKeyDownTarget
to
EventHandler::sLastKeyDownEventTargetElement
and make it use StaticRefPtr
.
Finally, for using Element*
instead of nsIContent*
, changes the result type
of Document::GetUnfocusedKeyEventTarget()
to Element*
.
Assignee | ||
Comment 113•6 years ago
|
||
If focused element is in another document,
PresShell::EventHandler::HandleEvent()
needs to retarget the event to another
PresShell
. This patch moves the case into new overload method,
MaybeHandleEventWithAnotherPresShell()
.
Additionally, removes PresShell::HandleRetargetedEvent()
and makes
EventHandler::HandleRetargetedEvent()
non-public because the new method
is the only user of them.
Assignee | ||
Comment 114•6 years ago
|
||
The remaining part of PresShell::EventHandler::HandleEvent()
does:
- Handles the event at focused content.
- Handles the event with given frame which is a frame for
mPresShell
.
For making them clearer, this patch moves them into new methods.
Assignee | ||
Comment 115•6 years ago
|
||
With splitting HandleEvent()
a lot, it becomes more difficult to keep
managing each set of calling PushCurrentEventInfo()
and
PopCurrentEventInfo()
. So, EventHandler
should have a helper class
to push and pop current event info into/from the stack.
Assignee | ||
Comment 116•6 years ago
|
||
PresShell::EventHandler::HandleEventInsternal()
recodes event handling
response performance with telemetry after it dispatches the event. We can move
it into new method simply.
Assignee | ||
Comment 117•6 years ago
|
||
PresShell::EventHandler::HandleEventInternal()
needs to accumulate event
handling time per each event type. The handling start time needs to be
recoded before sending EventStateManager. Therefore, this patch makes the
helper class which is a stack class, recodes current time at construction
and calls Telemetry::AccumulateTimeDelta()
at destruction automatically.
Assignee | ||
Comment 118•6 years ago
|
||
If aEvent
requires frame but there is no event target,
PresShell::EventHandler::HandleEventInternal()
just records the response
time. So, we can reduce one indent level in the big method.
Note that I'm not sure recoding the response time in such case because
the good values may make the average and median better. But this is
out of scope of bug 1466208.
Assignee | ||
Comment 119•6 years ago
|
||
If Shift
state of eContextMenu
event is active, we make it not fired on
web content. Additionally, if it's not time to open context menu, we shouldn't
dispatch it into the DOM. The new method prepare and check them.
Assignee | ||
Comment 120•6 years ago
|
||
Oddly, there are two trusted eMouseMove preparation code in
PresShell::EventHandler::HandleEventInternal()
. One is in the switch
statement which is used only when aEvent
is trusted. The other is after
TouchManager::PreHandleEvent()
is called and after
AutoHandlingUserInputStatePusher
is created. However, both of them do
nothing if the event is eMouseMove
. Therefore, we can move the latter
into the former.
Assignee | ||
Comment 121•6 years ago
|
||
The first switch statement of PresShell::EventHandler::HandleEventInternal()
has 2 jobs:
- Prepare something for specific event type.
- Record the preparation time of some types of events to telemetry.
This intermixed code is not easy to understand and somebody may add new
preparation after recording them. So, even though the preparation time
becomes worse a couple of milliseconds, we should split those jobs.
The patch moves the latter job into the new method.
Assignee | ||
Comment 122•6 years ago
|
||
PresShell::EventHandler::HandleEventInternal()
may handle Escape
key before
dispatching it in some cases. This requires too many lines for somebody who
investigate the method for the other events. Therefore, this patch moves it
into the new method.
Additionally, this patch creates WidgetKeyboardEvent::IsUserInteraction()
because PresShell::EventHandler
refers same result in 2 places. Finally,
its condition is not enough to what the comment wants to do since it does
not check some modifier keys. Therefore, this patch makes it check all
possible modifier keys too.
Assignee | ||
Comment 123•6 years ago
|
||
For making PresShell::EventHandler::HandleEventInternal()
easier to read,
move the large switch statement for preparation into the new method.
Comment 124•6 years ago
|
||
Assignee | ||
Comment 125•6 years ago
|
||
Updated•6 years ago
|
Updated•6 years ago
|
Updated•6 years ago
|
Comment 126•6 years ago
|
||
bugherder |
Comment 127•6 years ago
|
||
Comment 128•6 years ago
|
||
bugherder |
Comment 129•6 years ago
|
||
Comment 130•6 years ago
|
||
Comment 131•6 years ago
|
||
bugherder |
Comment 132•6 years ago
|
||
Comment 133•6 years ago
|
||
bugherder |
Comment 134•6 years ago
|
||
bugherder |
Comment 135•6 years ago
|
||
Comment 136•6 years ago
|
||
bugherder |
Comment 137•6 years ago
|
||
Comment 138•6 years ago
|
||
bugherder |
Comment 139•6 years ago
|
||
Comment 140•6 years ago
|
||
bugherder |
Comment 141•6 years ago
|
||
Comment 142•6 years ago
|
||
Comment 143•6 years ago
|
||
bugherder |
Comment 144•6 years ago
|
||
Comment 145•6 years ago
|
||
bugherder |
Assignee | ||
Comment 146•6 years ago
|
||
This is the part which actually handles the event. The new method should
notify EventStateManager of dispatching event before and after that, and
actually dispatch the event into the DOM.
Assignee | ||
Comment 147•6 years ago
|
||
Assignee | ||
Comment 148•6 years ago
|
||
Finally, we should move the last switch statement in HandleEventInternal()
to the new method. Then, `HandleEventInternal() does nothing complicated
things by itself.
Assignee | ||
Comment 149•6 years ago
|
||
In my understanding, PresShell::EventHandler::HandleEvent()
may redirect
the event to another class or PresShell first. Otherwise, it computes
event target and sets current event info of mPresShell to it. Then, calls
HandleEventInternal()
to dispatch the event. Then, HandleEventInternal()
may handle the event before dispatch, and/or prepare to dispatch, then,
finally dispatches the event and finalize the state of mPresShell and the
event. Therefore, HandleEventInternal()
actually handles the event, but
the word, "internal" is not explicitly explain its different points from
HandleEvent()
. Therefore, I think that HandleEventWithCurrentEventInfo()
is better name since HandleEvent()
considers the current event info.
Assignee | ||
Comment 150•6 years ago
|
||
Now, other methods taking aFrame
of HandleEvent()
names the argument as
aFrameForPresShell
. So, HandleEvent()
's aFrame
should also be renamed.
This patch renames it and adds MOZ_CAN_RUN_SCRIPT and comment to
nsIPresShell::HandleEvent()
.
This is the final patch for bug 1466208.
Comment 151•6 years ago
|
||
bugherder |
Comment 152•6 years ago
|
||
Comment 153•6 years ago
|
||
bugherder |
Comment 154•6 years ago
|
||
Comment 155•6 years ago
|
||
bugherder |
Comment 156•6 years ago
|
||
Comment 157•6 years ago
|
||
bugherder |
Comment 158•6 years ago
|
||
Comment 159•6 years ago
|
||
bugherder |
Comment 160•6 years ago
|
||
bugherder |
Comment 161•6 years ago
|
||
Comment 162•6 years ago
|
||
Comment 163•6 years ago
|
||
bugherder |
Comment 164•6 years ago
|
||
Comment 165•6 years ago
|
||
bugherder |
Comment 166•6 years ago
|
||
Comment 167•6 years ago
|
||
bugherder |
Comment 168•6 years ago
|
||
Comment 169•6 years ago
|
||
bugherder |
Comment 170•6 years ago
|
||
Comment 171•6 years ago
|
||
Allow me this drive-by comment. As the TB sheriff I'm watching M-C merges and I see this bug every day :-)
Nice job, two parts missing to land, so you're done before the next branch date.
Comment 172•6 years ago
|
||
bugherder |
Assignee | ||
Comment 173•6 years ago
|
||
(In reply to Jorg K (GMT+1) from comment #171)
Allow me this drive-by comment. As the TB sheriff I'm watching M-C merges and I see this bug every day :-)
Nice job, two parts missing to land, so you're done before the next branch date.
Thanks and yes, all patches will be landed 67 cycle. Note that the last patches have already been in the queue to land the autoland. So, this bug should be fixed in next 12 (or 24) hours.
Assignee | ||
Updated•6 years ago
|
Comment 174•6 years ago
|
||
bugherder |
Comment 175•6 years ago
|
||
Assignee | ||
Comment 176•6 years ago
|
||
Oh, failed to land part 45.
Updated•6 years ago
|
Comment 177•6 years ago
|
||
Updated•6 years ago
|
Comment 178•6 years ago
|
||
bugherder |
Description
•