Skip to content

Commit

Permalink
Bug 970802 - part 4: Make TextControlState dispatch "beforeinput" e…
Browse files Browse the repository at this point in the history
…vent if there is no `TextEditor` r=smaug

If `TextControlState` does not have `TextEditor` and its `SetValue()` is called
from `SetUserInput()`, `TextControlState` itself needs to dispatch `beforeinput`
event.

If the value is modified by `beforeinput` event listener, it's intended that
`preventDefault()` is called by the web apps.  However, the behavior in this
case is not mentioned by UI Events nor Input Events spec.  We should just file
a spec issue instead of emulating Chrome's behavior for now because it requires
more changes, but this case must be an edge case.
The spec issue is: w3c/input-events#106

Differential Revision: https://phabricator.services.mozilla.com/D58126

UltraBlame original commit: 1fb9cf2264b668a76d3671a5a3b06f67c587c0c0
  • Loading branch information
marco-c committed Jan 16, 2020
1 parent daaad06 commit 61d4794
Show file tree
Hide file tree
Showing 10 changed files with 3,175 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,12 +533,29 @@
=
false
;
let
element
=
document
.
querySelector
(
selector
)
;
let
hadEditor
=
SpecialPowers
.
wrap
(
element
)
.
hasEditor
;
element
.
addEventListener
(
Expand Down Expand Up @@ -679,12 +696,7 @@
}
)
;
document
.
querySelector
(
selector
)
element
.
addEventListener
(
Expand All @@ -697,16 +709,19 @@
=
>
{
if
(
hadEditor
)
{
todo
(
beforeInputFired
'
"
beforeinput
"
event
should
\
'
ve
been
Expand All @@ -715,9 +730,64 @@
"
input
"
on
<
{
element
.
tagName
}
type
=
"
{
element
.
type
}
"
>
)
;
}
else
{
ok
(
beforeInputFired
"
beforeinput
"
event
should
'
ve
been
fired
before
"
input
"
on
<
{
element
.
tagName
}
type
=
"
{
element
.
type
}
"
>
)
;
}
ok
(
event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,18 @@ beforeInputFired
=
false
;
let
hadEditor
=
SpecialPowers
.
wrap
(
element
)
.
hasEditor
;
element
.
addEventListener
Expand Down Expand Up @@ -1157,6 +1169,11 @@ text
"
)
{
if
(
hadEditor
)
{
todo
(
beforeInputFired
Expand All @@ -1182,6 +1199,35 @@ tagName
}
)
;
}
else
{
ok
(
beforeInputFired
"
beforeinput
"
event
should
'
ve
been
fired
before
"
input
"
event
on
{
element
.
tagName
}
)
;
}
ok
(
event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,18 @@
.
value
;
let
hadEditor
=
SpecialPowers
.
wrap
(
element
)
.
hasEditor
;
element
.
addEventListener
Expand Down Expand Up @@ -680,6 +692,11 @@
"
)
{
if
(
hadEditor
)
{
todo
(
beforeInputFired
Expand All @@ -705,6 +722,35 @@
event
)
;
}
else
{
ok
(
beforeInputFired
"
beforeinput
"
event
shoud
'
ve
been
fired
on
{
element
.
name
}
before
"
input
"
event
)
;
}
ok
(
event
Expand Down
16 changes: 16 additions & 0 deletions dom/html/HTMLInputElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13409,6 +13409,22 @@ GetTextEditorFromState
)
;
}
bool
HTMLInputElement
:
:
HasEditor
(
)
{
return
!
!
GetTextEditorWithoutCreation
(
)
;
}
TextEditor
*
HTMLInputElement
Expand Down
10 changes: 9 additions & 1 deletion dom/html/HTMLInputElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -5143,7 +5143,10 @@ aExcludePassword
GetEditor
(
)
is
and
HasEditor
(
)
for
webidl
bindings
Expand All @@ -5158,6 +5161,11 @@ GetEditor
)
;
bool
HasEditor
(
)
;
bool
IsInputEventTarget
(
)
Expand Down
21 changes: 21 additions & 0 deletions dom/html/HTMLTextAreaElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -1808,6 +1808,27 @@ GetTextEditor
;
}
bool
HasEditor
(
)
{
MOZ_ASSERT
(
mState
)
;
return
!
!
mState
-
>
GetTextEditorWithoutCreation
(
)
;
}
bool
IsInputEventTarget
(
)
Expand Down
Loading

0 comments on commit 61d4794

Please sign in to comment.