Граф коммитов

143 Коммитов

Автор SHA1 Сообщение Дата
Jens Stutte 223dc30826 Bug 1839051 - Use nsTArray::Sort in KeyboardLayout. r=xpcom-reviewers,emilio,win-reviewers,rkraesig
Depends on D181891

Differential Revision: https://phabricator.services.mozilla.com/D182724
2023-12-11 06:53:28 +00:00
Iulian Moraru 95f4da1719 Backed out 8 changesets (bug 1839051) for causing assertion failures on NotificationController.cpp. CLOSED TREE
Backed out changeset 94a4c163e417 (bug 1839051)
Backed out changeset 5204b97e40bc (bug 1839051)
Backed out changeset 8443a22a399d (bug 1839051)
Backed out changeset 2ab1e27d5945 (bug 1839051)
Backed out changeset 20a850a4fd7e (bug 1839051)
Backed out changeset 658568fe9662 (bug 1839051)
Backed out changeset 82525b11a7c3 (bug 1839051)
Backed out changeset 720e6863c41a (bug 1839051)
2023-12-04 22:34:25 +02:00
Jens Stutte 73ded710c0 Bug 1839051 - Use nsTArray::Sort in KeyboardLayout. r=xpcom-reviewers,emilio,win-reviewers,rkraesig
Depends on D181891

Differential Revision: https://phabricator.services.mozilla.com/D182724
2023-12-04 18:33:41 +00:00
Masayuki Nakano 8224e1138c Bug 1840519 - Make typing surrogate pair behavior switchable with prefs r=m_kato,smaug
A lone surrogate should not appear in `DOMString` at least when the attribute
values of events because of ill-formed UTF-16 string.

`TextEventDispatcher` does not handle surrogate pairs correctly. It should not
split surrogate pairs when it sets `KeyboardEvent.key` value for avoiding the
problem in some DOM API wrappers, e.g., Rust-running-as-wasm.

On the other hand, `.charCode` is an unsigned long attribute and web apps
may use `String.fromCharCode(event.charCode)` to convert the input to string,
and unfortunately, `fromCharCode` does not support Unicode character code
points over `0xFFFF`.  Therefore, we may need to keep dispatching 2 `keypress`
events per surrogate pair for the backward compatibility.

Therefore, this patch creates 2 prefs.  One is for using single-keypress
event model and double-keypress event model.  The other is for the latter,
whether `.key` value never has ill-formed UTF-16 or it's allowed.

If using the single-keypress event model --this is compatible with Safari and
Chrome in non-Windows platforms--, one `keypress` event is dispatched for
typing a surrogate pair.  Then, its `.charCode` is over `0xFFFF` which can
work with `String.fromCodePoint()` instead of `String.fromCharCode()` and
`.key` value is set to simply the surrogate pair (i.e., its length is 2).

If using the double-keypress event model and disallowing ill-formed UTF-16
--this is the new default behavior for both avoiding ill-formed UTF-16 string
creation and keeping backward compatibility with not-maintained web apps using
`String.fromCharCode`--, 2 `keypress` events are dispatched.  `.charCode` for
first one is the code of the high-surrogate, but `.key` is the surrogate pair.
Then, `.charCode` for second one is the low-surrogate and `.key` is empty
string.  In this mode, `TextEditor` and `HTMLEditor` ignores the second
`keypress`.  Therefore, web apps can cancel it only with the first `keypress`,
but it indicates the `keypress` introduces a surrogate pair with `.key`
attribute.

Otherwise, if using the double-keypress event model and allowing ill-formed
UTF-16 --this is the traditional our behavior and compatible with Chrome in
Windows--, 2 `keypress` events are dispatched with same `.charCode` values as
the previous mode, but first `.key` is the high-surrogate and the other's is
the low surrogate.  Therefore, web apps can cancel either one of them or
both of them.

Finally, this patch makes `TextEditor` and `HTMLEditor` handle text input
with `keypress` events properly.  Except in the last mode, `beforeinput` and
`input` events are fired once and their `data` values are the surrogate pair.
On the other hand, in the last mode, 2 sets of `beforeinput` and `input` are
fired and their `.data` values has only the surrogate so that ill-formed
UTF-16 values.

Note that this patch also fixes an issue on Windows.  Windows may send a high
surrogate and a low surrogate with 2 sets of `WM_KEYDOWN` and `WM_KEYUP` whose
virtual keycode is `VK_PACKET` (typically, this occurs with `SendInput` API).
For handling this correctly, this patch changes `NativeKey` class to make it
just store the high surrogate for the first `WM_KEYDOWN` and `WM_KEYUP` and use
it when it'll receive another `WM_KEYDOWN` for a low surrogate.

Differential Revision: https://phabricator.services.mozilla.com/D182142
2023-08-23 01:16:59 +00:00
Chris Martin 63ca6a38f3 Bug 1756621 - Remove nsWindowBase r=handyman
It looks like it was added to abstract commonalities between Win32 and
WinRT. But we dropped support for WinRT a long time ago, and there hasn't been
any work on this area of code in 8 years. In the meantime, it just adds an
extra layer of indirection that doesn't need to exist.

Differential Revision: https://phabricator.services.mozilla.com/D139771
2022-02-28 15:08:03 +00:00
Masayuki Nakano 06bbff1f71 Bug 1689034 - part 2: Get rid of some native messages for plugins r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D103139
2021-01-29 04:00:16 +00:00
Masayuki Nakano 9e229babfa Bug 1683226 - part 11: Get rid of `IMEEnabled::Plugin` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D100123
2020-12-21 08:26:24 +00:00
Masayuki Nakano ff0e3ef67e Bug 1683226 - part 9: Get rid of `nsIWidget::PluginHasFocus()` r=m_kato
It's used only by IMM and keyboard handlers on Windows.

Differential Revision: https://phabricator.services.mozilla.com/D100121
2020-12-21 06:30:07 +00:00
Sylvestre Ledru bebb9f9181 Bug 1519636 - Reformat with clang-format-11 to the Google coding style r=andi,sg,geckoview-reviewers,snorp
It is bringing some minor changes

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D90795
2020-11-18 09:05:59 +00:00
Doug Thayer 8f54209ef6 Bug 1651165 - Rename idle service r=Gijs,geckoview-reviewers,snorp
Differential Revision: https://phabricator.services.mozilla.com/D83413
2020-07-20 16:06:59 +00:00
Simon Giesecke dbf542e979 Bug 1626570 - Improve handling of copying arrays in widget/. r=jhorak
Differential Revision: https://phabricator.services.mozilla.com/D73639
2020-05-07 08:49:18 +00:00
Masayuki Nakano 37b2bfa576 Bug 1615977 - Don't modify key value while pressing a numpad key with `Alt` but the virtual keycode is a function key r=m_kato
Inputting Unicode scalar value with `Alt` + numpad keys is available even
without NumLock state.  However, `Alt` + function key on numpad should also
be worked because user may intent to perform it.  Therefore, this patch
stops the hacking for bug 1606655 when given virtual keycode value is a
function key, but this means that users cannot type a Unicode scalar value
without NumLock key state if the value includes `7` (`Home`),
`4` (`ArrowLeft`), `6` (`ArrowRight`) because Firefox UI handles they are
shortcut keys (for "Go home", "Go back" and "Go forward").  Unfortunately,
I have no idea how to solve this conflict (if it's second key or latter key
after pressing `Alt` key, we could do that with a boolean flag, but I don't
like to make it only for this kind of edge case unless a lot of users want
to do it).

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

--HG--
extra : moz-landing-system : lando
2020-02-27 03:21:36 +00:00
Masayuki Nakano 70d3fedce5 Bug 1612238 - Make `NativeKey::IsTypingUnicodeScalarValue()` check `mIsExtended` r=m_kato
Scan code values of numpad keys are same as `End`, `ArrowDown`, `PageDown`,
`Insert`, `ArrowLeft`, `ArrowRight`, `Home`, `ArrowUp` and `PageUp`.  Only
the difference between them is that numpad keys are non-extended keys and
the others are extended keys.  Therefore, `IsTypingUnicodeScalarValue()` needs
to check whether the key is not extended key or not.

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

--HG--
extra : moz-landing-system : lando
2020-01-31 07:27:44 +00:00
Masayuki Nakano ddb9a88943 Bug 1606655 - Make `NativeKey` stop adding alternative char codes while user inputs a Unicode character with `Alt` + some numpad keys r=m_kato
Custom keyboard layout may set unusual character to each numpad key.  In our
shortcut and acceleration key handling, we refer alternative char code values
stored in `eKeyDown` or `eKeyPress` and they may contain an alphabet which is
used by menubar but it shouldn't be performed while user inputs a Unicode
character with `Alt` + numpad keys because it's being handled by Windows.
(In strictly speaking, I think that we shouldn't dispatch key events of the
sequence, but Chrome does it so that we should keep dispatching for web-compat.)

This patch makes `NativeKey` stores same `mCommittedCharsAndModifiers`,
`mShiftedString` and `mUnshiftedString` values as usual keyboard layout
even active keyboard layout customized numpad key values.

Note that Windows handles the key sequence without virtual key code, meaning
that even if the numpad keys are shuffled by keyboard layout, typed numbers
are computed from physical key position.  E.g., even if `Numpad7` is mapped
to `1`, it's treated as `7`.  Therefore, this patch refers scan code in
some places.

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

--HG--
extra : moz-landing-system : lando
2020-01-28 12:01:56 +00:00
Sylvestre Ledru 265e672179 Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset

--HG--
extra : amend_source : 4d301d3b0b8711c4692392aa76088ba7fd7d1022
2018-11-30 11:46:48 +01:00
Masayuki Nakano cccab7b98a Bug 900750 - part 4: Make NativeKey replaces MODIFIER_CONTROL and MODIFIER_ALT of mModKeyState with MODIFIER_ALTGRAPH if user emulates AltGr key press with pressing both Ctrl and Alt keys and current keydown produces character(s) r=m_kato,smaug
Users can emulate AltGr key with pressing both Ctrl key and Alt key on Windows
since AltGr is represented as so in Windows and physical keyboard may not have
AltRight key.

If user emulates AltGr key, we should set MODIFIER_ALTGRAPH to a set of
keyboard events for printable keys only when the key press produces
character(s) or a dead key.  For example:

1. ControlLeft keydown event should make ctrlKey true.
2. AltLeft keydown event should make altKey true (not AltGraph state).
3. ctrlKey and altKey of printable keydown, keypress and keyup events should be
   set to false, but getModifierState("AltGraph") should return true.
4. AltLeft keyup event should make altKey false.
5. ControlLeft keyup event should make ctrlKey false.

(If AltLeft key is pressed first, altKey of AltLeft keydown is true and
both altKey and ctrlKey of the following ControlLeft keydown are true as
usual.)

MozReview-Commit-ID: 8Km8GXPDQw1

--HG--
extra : rebase_source : f4924f075c68361c8ce563910280ea24774c519f
2018-06-04 14:45:28 +09:00
Masayuki Nakano ad475fd697 Bug 900750 - part 3: Remove unnecessary ModifierKeyState argument from some methods of NativeKey and KeyboardLayout r=m_kato
KeyboardLayout::InitNativeKey() takes |const ModifierKeyState&| as its
argument with NativeKey reference and it calls some internal methods with
the given ModifierKeyState without any changes.  Additionally, its caller
is only NativeKey::InitWithKeyChar() and its called with given NativeKey
instance's mModKeyState.  So, removing the redundant arguments from
some methods makes them clearer what they compute with.

So, this patch does not change any behavior.

MozReview-Commit-ID: 3w9Ee7PMU05

--HG--
extra : rebase_source : b724a18d5a14672e60ffa5fb9feca5c11dac42a3
2018-06-01 15:22:41 +09:00
Masayuki Nakano 8fc19f6752 Bug 900750 - part 2: Make ModifierKeyState and VirtualKey treat AltGraph as new modifier and won't set Control and Alt state while AltGraph is active r=m_kato,smaug
By the proposal from Google, <https://github.com/w3c/uievents/issues/147>,
Chromium treat AltRight key as "AltGraph" modifier if the keyboard layout
has AltGr key.

When AltRight key is pressed with a keyboard layout which has AltGr key,
modifiers should as following:

1. "keydown" for ControlLeft:
  ctrlKey:  true, altKey: false, getModifierState("AltGraph"): false
2. "keydown" for AltRight:
  ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
3. Some "keydown", "keypress" and "keyup" events:
  ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
4. "keyup" for ControlLeft:
  ctrlKey: false, altKey: false, getModifierState("AltGraph"): true
5. "keyup" for AltRight:
  ctrlKey: false, altKey: false, getModifierState("AltGraph"): false

So, only when the preceding "keydown" event for ControlLeft, ctrlKey should
be set to true as usual.  However, after AltRight key is pressed actually,
we should treat "AltGraph" modifier is true and both ctrlKey and altKey
should be set to false for web apps can handle text input normally.

So, MODIFIER_ALTGRAPH and MODIFIER_CONTROL/MODIFIER_ALT should not be set
at the same time.

This patch makes ModifierKeyState have only MODIFIER_ALTGRAPH or
MODIFIER_CONTROL/MODIFIER_ALT.

Additionally, this patch makes VirtualKey::ShiftState treat "AltGraph" as a
modifier.  So, now, VirtualKey needs to convert ShiftState to index value when
it accesses its mShiftStates array.  Therefore, this patch adds
VirtualKey::ToIndex() and make each VirtualKey method use it before
accessing mShiftStates.

Note that this patch also fixes bug of WinUtils::SetupKeyModifiersSequence().
The constructor of KeyPair takes 2 keycode values, but the second virtual
keycode can have scancode to distinguish if the key is left or right.
However, WinUtils::SetupKeyModifiersSequence() never sets scancode to
KeyPair.  Therefore, it fails to dispatch AltRight key event.

MozReview-Commit-ID: 7ealxJH9KlZ

--HG--
extra : rebase_source : 761bc4416222def020a0731d6ae7940ef074ebe0
2018-05-30 17:27:31 +09:00
Masayuki Nakano ac32b59118 Bug 900750 - part 1: Make KeyboardLayout store the information if current keyboard layout has AltGr key r=m_kato
For setting AltRight key's key value to "AltGraph" if it should work as so,
we need to know if current keyboard layout has AltGr key.  Unfortunately,
Windows doesn't provide such information but we retrieve all input characters
from each key when a keyboard layout is loaded.  So, when we load a keyboard
layout, we can mark if current keyboard layout has AltGr key with checking
at least one key inputs different character(s) when AltGr key is pressed.

MozReview-Commit-ID: 8GI3phSVTUS

--HG--
extra : rebase_source : f1622615f03740609984da6d216391e23cae6796
2018-05-29 20:36:38 +09:00
Masayuki Nakano a20855c9f5 Bug 1441821 - NativeKey shouldn't mark eKeyDown and eKeyPress as "skippable in remote process" if message is not caused by physical key press r=m_kato,smaug
Currently, TabChild discards eKeyDown and eKeyPress events which are marked as
"repeated" and were dispatched after the latest eKeyDown event comes into the
process.  However, keyboard layout utils may generate native key events
as "repeated" even if each native key is important to input proper text.

So, TabChild shouldn't decide if coming keyboard event is skippable only with
mIsRepeat.  For solving this issue, this patch adds
mMaybeSkippableInRemoteProcess to WidgetKeyboardEvent and makes
TabChild::SkipRepeatedKeyEvent() check
WidgetKeyboardEvent::CanSkipInRemoteProcess() instead.

On Windows, there are two ways to generate keyboard input messages.  One is
using SendMessage() or PostMessage().  The other is SendInput() API.  In both
ways, utils can make their input as repeated key messages.

The former case must be safe for this issue since such utils need to set 31st
bit of lParam to 1 explicitly.

On the other hand, in the latter case, the utils probably need to append
KEYEVENTF_KEYUP into KEYBDINPUT::dwFlags.  Otherwise, only first call is
treated as non-repeated event.

So, when given message does not came from physical key operation, NativeKey
should set WidgetKeyboardEvent::mMaybeSkippableInRemoteProcess to false
even if WidgetKeyboardEvent::mIsRepeat is true.

MozReview-Commit-ID: 3rinrOjx8Tf

--HG--
extra : rebase_source : 26b6d869260176fc7ef535323b83001bb4b725c2
2018-06-06 23:35:16 +09:00
Sylvestre Ledru d60d69e2cb Bug 1411001 - Remove the +x permissions on cpp & h files r=froydnj
MozReview-Commit-ID: DjDkL20wRg0

--HG--
extra : rebase_source : a343d83d1f4e97e4ba56d0f57fec93079df0b5ea
2017-10-23 20:59:55 +02:00
Tom Ritter 6d7c28697b Bug 1409620 Move definition of inline function from .cpp to .h in widget/windows/KeyboardLayout r=jimm
inline functions are supposed to be declared in the header file, so the compiler can inline them.
gcc complains about this, but clang/msvc apparently do not.

We also needed to move the DeadKey struct and class into the header, as the function calls a
method on the DeadKey class, and you can't do that on a forward declared class.

MozReview-Commit-ID: 8NxP59AXuZi

--HG--
extra : rebase_source : 9fd74d2c571bdeb4244cb63baf508946a2f19aa6
2017-10-17 23:58:37 -05:00
Masayuki Nakano 7edb06b6ab Bug 1367482 NativeKey::HandleCharMessage() should treat a WM_CHAR message for '\r' as a Enter key press r=m_kato
Starting from 52, NativeKey::HandleCharMessage() ignores all control characters.  However, some keyboard layout utilities may send WM_CHAR message whose wParam is '\r' for emulating pressing Enter key.  For supporting such utilities, we should dispatch Enter keypress event when HandleCharMessage() receives such event.

Note that this patch does NOT support a pair of WM_KEYDOWN and WM_CHAR whose wParam is '\r' but the WM_KEYDOWN isn't VK_RETURN.  If there is such case, we need to support it too.  However, it needs a lot of code changes.  So, we shouldn't support it until such bug is filed actually.

MozReview-Commit-ID: CWyvBtLmXgg

--HG--
extra : rebase_source : 6e9b27dc2fb9eb75626cdd5ab339d348a7be3040
2017-07-08 03:08:07 +09:00
Masayuki Nakano bd8834c19e Bug 1346499 Don't remove Ctrl nor Alt modifier state at dispatching eKeyPress event when the modifier doesn't change inputting character r=m_kato
Ctrl+Space causes WM_CHAR of ' '.  On the other native applications, you can input ' ' with this key combination though, we shouldn't allow this because we need to remove Ctrl and Alt modifier state at dispatching keypress event for the limitation of TextEditor but this is important key combination for custom shortcut keys.

So, when Ctrl or Alt key is pressed but it doesn't change the inputting character, i.e., the character can be inputted without Ctrl or Alt, we shouldn't remove those modifier state from eKeyPress event.

MozReview-Commit-ID: 7omLvNdQWzW

--HG--
extra : rebase_source : 66d5015567799c489d925ac2419358913f808d63
2017-03-14 00:32:50 +09:00
Masayuki Nakano 9021b5582c Bug 1338369 part.1 nsWindow for Windows should consume Shift key state at dispatching eContextMenu event if it's caused by Shift+F10 r=smaug
In PresShell, eContextMenu event is marked as dispatched only in chrome when its shiftKey state is true. However, Shift+F10 causes the context menu, it should not be marked as so because this is standard shortcut key to open context menu on Windows.

This patch consumes Shift key state if previous key message is WM_SYSKEYDOWN of F10 before dispatching eContextMenu event.  So, user cannot block to prevent its default at opening context menu with Shift+F10, we should discuss this later.

MozReview-Commit-ID: 1P9LpeJoQof

--HG--
extra : rebase_source : f77fcf6a4587bc131901d717325f6083b4a89393
2017-02-24 20:07:52 +09:00
Masayuki Nakano 5442d350f3 Bug 1337739 Create an enum eKeyLocation* for avoiding to use nsIDOMKeyEvent::DOM_KEY_LOCATION_* r=smaug
Currently, we use alias NS_VK_* for WidgetKeyboardEvent::mKeyCode.  Similarly, we should create alias enum for nsIDOMKeyEvent::DOM_KEY_LOCATION_*.  Then, we can reduce the length and avoid to include nsIDOMKeyEvent in some cpp files.

MozReview-Commit-ID: 5cs4zQ061Lc

--HG--
extra : rebase_source : e6a6edd27718b9e3d4a40b07902d029791876999
2017-02-08 21:04:22 +09:00
Masayuki Nakano fb6e71084a Bug 1336028 NativeKey::GetFollowingCharMessage() should take newer char message when found char message and removed message from the queue is different but their scancode indicates same physical key r=m_kato
NativeKey::GetFollowingCharMessage() may remove a char message which is different from previously found message in the queue because hacky keyboard layout or utility can overwrite the wParam when it's removed from the queue.

Now, we should assume that newer message, i.e., actually removed from the queue, is the expected message by the user.  See bug 1336028 comment 0 for the actual scenarios which are collected by crash reports.
https://bugzilla.mozilla.org/show_bug.cgi?id=1336028#c0

MozReview-Commit-ID: 9ZgukHH1vfi

--HG--
extra : rebase_source : 15559e62882f97d5062703e2308fa1c22016f340
2017-02-02 23:28:48 +09:00
Masayuki Nakano 6868da62c8 Bug 1334947 Treat a keydown event as inputting empty text if following char message has gone and gets WM_NULL message at calling PeekMessage() for removing a found char message r=m_kato
There are still a lot of crash due to failing to get following WM_CHAR message.  Almost half of them are, we found a WM_CHAR message but it's gone at removing the message from the queue.

Although, we're still not sure what happen actually.  It could be possible if somebody hooks PeekMessage() or something.  Then, we can assume that the found message isn't necessary for the user because it must be removed by somebody when it became unnecessary or is handled.

This patch mark a new bool flag, mCharMessageHasGone, as true in such case.  Then, NativeKey will dispatch keypress events without following char messages and mark the event as consumed.

MozReview-Commit-ID: mporX1sihC

--HG--
extra : rebase_source : a1badc205a99efd803de624d24b69e911f81d308
2017-01-30 15:43:09 +09:00
Masayuki Nakano d8294a4512 Bug 1335306 Append active keyboard layout information into crash report when NativeKey crashes due to detecting impossible case caused by 3rd party's keyboard layout or utils r=m_kato
When NativeKey crashes by itself, it means that we detect an impossible situation in usual environment. In such case, active 3rd party's keyboard layout or something other utility may hook API and returns odd result to us.

For investigating the cause and deciding what we should do in such cases, we should collect active keyboard layout name via crash reports.

MozReview-Commit-ID: HYRj24GwDHZ

--HG--
extra : rebase_source : 5f01c2a3b36179a61dc00eebd4de6f05596d217b
2017-01-31 23:23:06 +09:00
Nicholas Nethercote 0b2b65edc8 Bug 1325503 - Remove Windows {XP, Server 2003, Vista} support from widget/. r=jimm.
I did my best to remove as much stuff as possible in this patch. The starting
point was to remove all the IsVistaOrLater() and IsWin7OrLater() calls, but I
also grepped for various strings and found some other removable stuff that way.
I may have still missed some things.

Notable things done by this patch.

- It removes numerous blocklist entries.

- It removes CanComputeVirtualKeyCodeFromScanCode(), because it's always true
  now.

- It removes ShowXP{Folder,File}Picker(), even though these were available as
  fallbacks on Vista+. The "when platform is built without the longhorn SDK"
  condition in the comment above nsFilePicker::ShowXPFolderPicker() sounds like
  it won't ever happen any more.

- It removes the config.trim_on_minimize preference. This requires adding a
  bool sHaveInitializedPrefs variable; previously the lack of pref
  initialization was indicated by the tri-state sTrimOnMinimize variable having
  the value 2.

Notable things *not* done by this patch.

- ClearThemeRegion() still exists. The comment suggests that it is XP/Vista
  only, but the code suggests otherwise. jimm thinks the comment is wrong.

- The comment in WinWakeLockListener::Callback() suggests that the StartTimer()
  call is no longer needed to block the screen saver. I'm uncertain about this
  and so I think it's best left to a follow-up.

--HG--
extra : rebase_source : f46645907d237423fd6115ab1b4725b023a0dce3
2016-12-23 13:13:31 +11:00
Masayuki Nakano 99651541fb Bug 791300 KeyboardLayout should respect following WM_(SYS)DEADCHAR messages for supporting chained dead keys r=m_kato
Currently, KeyboardLayout doesn't support chained dead keys because probably, the initial developer didn't expect there are such keyboard layout.  Additionally, if we'd try to handle them with KeyboardLayout, it'd need to create too big and too complicated table at loading such keyboard layout.  It's really nightmare.  Therefore, this patch takes different approach.

Currently, when WM_(SYS)KEYDOWN is received, KeyboardLayout (and NativeKey) respects following WM_(SYS)CHAR.  Similarly, this patch makes KeyboardLayout respect WM_(SYS)DEADCHAR when it handles dead key.  If WM_(SYS)KEYDOWN is followed by WM_DEADCHAR, that means that the key press is in a dead key sequence and not finishing the existing dead key sequence.  Therefore, when WM_(SYS)KEYDOWN is followed by WM_(SYS)DEADCHAR, KeyboardLayout activates dead key sequence.

For supporting dead key chain, this patch makes KeyboardLayout::mActiveDeadKey and KeyboardLayout::mDeadKeyShiftState arrays.  When dead keydown message is received, KeyboardLayout appends an item to each of them.  (I.e., when the array is not empty, it's in a dead key sequence.)

When WM_(SYS)KEYUP is received, KeyboardLayout checks if it's in mActiveDeadKey.  If it's included in the array, it initializes NativeKey as a dead keyup event.

Otherwise, when non-printable key (probably) is received in a dead key sequence, KeyboardLayout doesn't handle it as a part of the dead key sequence.  For example, a modifier key may be pressed for next key.  (Even if the keyboard layout maps text input to a non-printable key, we can ignore them because such key's KeyboardEvent.key value should be decided only with the virtual keyboard.)

MozReview-Commit-ID: 9n8B0YYuKCO

--HG--
extra : rebase_source : d18ca896829274d35cc8b7744c5e1645a9e78784
2016-11-10 23:24:33 +09:00
Masayuki Nakano 2fb6e9eb1c Bug 1303273 part.9 NativeKey::mFollowingCharMsgs should be AutoTArray r=m_kato
Similarly, NativeKey is a stack class and mFollowingCharMsgs which stores following char messages of WM_(SYS)KEYDOWN should be AutoTArray for preventing to use heap at handling inputs with usual keyboard layout.

5 is enough size for handling usual keyboard layout because we support only 5 or less characters per dead key sequence.

MozReview-Commit-ID: IphcIOmPW0C

--HG--
extra : rebase_source : 74ce6f9fef73df4b9bbccbbdd713470ff7357889
2016-10-07 14:38:14 +09:00
Masayuki Nakano af0bc7745d Bug 1303273 part.8 UniCharsAndModifiers should use nsAutoString and AutoTArray to store characters and modifiers r=m_kato
Fortunately, UniCharsAndModifiers instances are only in stack.  Therefore, we can make it a stack class and use nsAutoString and AutoTArray for not using heap at handling inputs from usual keyboard layouts.

MozReview-Commit-ID: 9ZPbdjGst64

--HG--
extra : rebase_source : 06a21c20575747591c6bf1a55dff7e6e38884333
2016-10-07 14:32:45 +09:00
Masayuki Nakano 2c0c609d8a Bug 1303273 part.7 Hide UniCharsAndModifiers::mLength and make its type size_t r=m_kato
MozReview-Commit-ID: 7QLdmgopOwG

--HG--
extra : rebase_source : 89d077c20edab65ac7c2c637b2cda94b6d1ab30d
2016-10-07 13:39:15 +09:00
Masayuki Nakano c20c0f333a Bug 1303273 part.6 Hide UniCharsAndModifiers::mModifiers r=m_kato
MozReview-Commit-ID: 9KKN5mlJadg

--HG--
extra : rebase_source : a3109eca884b3795f4a069bc5c694d1f495ef86b
2016-10-07 13:25:40 +09:00
Masayuki Nakano 0d6b0439b4 Bug 1303273 part.5 UniCharsAndModifiers should hide mChars r=m_kato
Now, we have an security issue.  mCommittedCharsAndModifiers may be initialized with multiple WM_(SYS)CHAR messages.  However, if it's generated by odd (or malicious) middleware, mCommittedCharsAndModifiers may be overflown because it has only fixed array.  For fixing this issue, first, we should hide the members for making the users not depend on the design of UniCharsAndModifiers.

This patch changes UniCharsAndModifiers to a class and hiding mChars and adding |CharAt() const|.

MozReview-Commit-ID: 5EjrIhmCdE4

--HG--
extra : rebase_source : a3dc68998f5f177582addd8587c4da86b2d17b3b
2016-10-07 12:04:49 +09:00
Masayuki Nakano 8c926d5f82 Bug 1303273 part.3 Dispatch eKeyPress events without NativeKey::HandleCharMessage() when it handles WM_(SYS)KEYDOWN message and there are following WM_(SYS)CHAR messages which includes non-control character r=m_kato
This patch creates NativeKey::DispatchKeyPressEventsWithRetrievedCharMessages() for dispatching eKeyPress event with mCommittedCharsAndModifiers when it stores following printable WM_(SYS)CHAR messages.

Using loop for dispatching eKeyPress event for every WM_(SYS)CHAR message is wrong because WidgetKeyboardEvent::mKeyValue is initialized with mCommittedCharsAndModifiers and it causes TextEventDispatcher dispatching multiple eKeyPress events at every call of MaybeDispatchKeypressEvents().  Therefore, if mKeyValue is "^^", eKeyPress event is dispatched 4 times --for the first message, eKeyPress events are fired for each "^" and for the second message, eKeyPress events are fired again for each "^"--.  Therefore, when it handles WM_(SYS)KEYDOWN and it causes inputting one or more printable characters, it's the easiest way not to use HandleCharMessage().

The new method calls TextEventDispatcher::MaybeDispatchKeypressEvents() only once and it requests to call the callback method with new argument of MaybeDispatchKeypressEvents() when it needs to dispatch 2 or more eKeyPress events.  Then, NativeKey::WillDispatchKeyboardEvent() can set each eKeyPress event to raw information of the message and proper modifier state.

With this change, we can dispatch multiple eKeyPress events with retrieved WM_(SYS)CHAR message information rather than retrieved information from active keyboard layout.  Therefore, NeedsToHandleWithoutFollowingCharMessages() doesn't return true even when mCommittedCharsAndModifiers stores two or more characters.

FYI: there is a bug in test_keycodes.xul. That is, Alt+'A' of Greek keyboard layout should cause WM_SYSCHAR with a corresponding Greek character but ASCII characters are specified.  Therefore, this patch includes the fix of these bugs

MozReview-Commit-ID: JVm7ZJVug0O

--HG--
extra : rebase_source : 414ecbe2c01c53f294d1346414b1a289aa0abfe8
2016-10-06 20:52:03 +09:00
Masayuki Nakano 642d448ca7 Bug 1303273 part.2 KeyboardLayout::InitNativeKey() should initialize aNativeKey.mCommittedCharsAndModifiers with following WM_CHAR or WM_SYSCHAR messages which are not providing a control character r=m_kato
First, mCommittedCharsAndModifiers should be initialized with following char messages because the messages could be different from the information of current keyboard layout.

So, this patch guarantees that mCommittedCharsAndModifiers are same as the user expected when there is one or more WM_CHAR or WM_SYSCHAR messages.

MozReview-Commit-ID: I5Ack0xccoL

--HG--
extra : rebase_source : e4c7af75fd200f30ec52b53dc05f49ae8887c6f0
2016-10-07 11:36:34 +09:00
Masayuki Nakano 1c049b2afa Bug 1307112 part.7 Get rid of Enter and Backspace key hack in NativeKey class r=m_kato
Currently, Enter and Backspace keys are handled without following WM_(SYS)CHAR message.  However, older code needs hack for them for avoiding conflict with Ctrl+J vs. Ctrl+Enter, etc.

So, we can get rid of them now.  And when a keydown causes inputting a control character, NativeKey should handle it with keyboard layout (i.e., without following char message(s)).

MozReview-Commit-ID: 6bVuK0BzFbx

--HG--
extra : rebase_source : 08ff45c1990ef8f3ed7703c69b2dc22e5f1dd6f5
2016-10-04 00:21:40 +09:00
Masayuki Nakano 151e2402f9 Bug 1307112 part.6 Get rid of char message argument from public NativeKey::HandleCharMessage() method r=m_kato
Currently, NativeKey::HandleCharMessage() is only a public method and it takes any char message.  However, when it's called outside of NativeKey, it should work only with NativeKey::mMsg.

Therefore, we should make current HandleCharMessage() a private method and create new overload method which doesn't take MSG as an argument.

MozReview-Commit-ID: LowV2FUmR3U

--HG--
extra : rebase_source : 271c61515752cf1ea56cf12c4f7ef6f1a90c9cac
2016-10-03 23:55:14 +09:00
Masayuki Nakano b445cf93ba Bug 1307112 part.4 Rename NativeKey::IsFollowedByNonControlCharMessage() to IsFollowedByPrintableCharMessage() r=m_kato
For consistency with IsPrintableCharMessage(), IsFollowedByNonControlCharMessage() should be renamed to IsFollowedByPrintableCharMessage().

MozReview-Commit-ID: CBJFPO4FZej

--HG--
extra : rebase_source : f5d677743be35a3bb5fca35e7658e907aa46dbcb
2016-10-03 18:07:33 +09:00
Masayuki Nakano b8a5c9fef9 Bug 1307112 part.2 Create NativeKey::IsPrintableCharMessage() which returns true when given message is WM_CHAR and inputting a printable character r=m_kato
MozReview-Commit-ID: 7f74273Ogo5

--HG--
extra : rebase_source : 860b01320a7f02f9bebea570be43c5c508fd4f41
2016-10-03 17:52:41 +09:00
Masayuki Nakano 4bbcc90d42 Bug 1307112 part.1 Rename NativeKey::IsPrintableCharMessage() to IsCharOrSysCharMessage() r=m_kato
Currently, NativeKey::IsPrintableCharMessage() returns true if given message is WM_CHAR or WM_SYSCHAR.  However, WM_SYSCHAR never causes inputting any character and even if WM_CHAR has a control character (i.e., non-printable character), it returns true.

MozReview-Commit-ID: IoU5F06WImz

--HG--
extra : rebase_source : c48f424f3d2960e6e9ceaa6d2fb09952ca634c3f
2016-10-03 17:45:03 +09:00
David Major fcbab1c99e Bug 1307812: Re-work IsEmptyMSG() to avoid taking the address of a temporary. r=masayuki
--HG--
extra : rebase_source : 2d5c3223f56165b3059c9c75cd8ecdeef0e7ce34
2016-10-06 09:22:18 -05:00
Masayuki Nakano 6f3a61eba6 Bug 1305943 Don't consume following WM_SYSCHAR message for some key combinations which are reserved by the system r=m_kato
When key combination is reserved by the system, web apps shouldn't be able to consume the key events.  In such case, we've decided that we never expose the key events in web contents (including chrome contents).  Therefore, NativeKey stops dispatching keyboard events only for Alt+Space.

However, new code of the fix of bug 1300003 always consumes WM_SYSCHAR which follows WM_SYSKEYDOWN of Alt+Space.  This is the cause of bug 1305943.

For fixing this bug, NativeKey should have a helper method, IsReservedBySystem(), and when it returns true, it should do nothing when Handle*Message() is called and should not consume following WM_SYSCHAR messages at handling WM_*KEYDOWN.

Unfortunately, it's impossible to test this regression because nsDOMWindowUtils::SendNativeKeyEvent() may call nsIWidget::SynthesizeNativeKeyEvent() asynchronously.  See <https://dxr.mozilla.org/mozilla-central/source/dom/base/nsDOMWindowUtils.cpp#1105-1108>.  Therefore, it cannot return if it's consumed.

MozReview-Commit-ID: 9ABh2rYNkFs

--HG--
extra : rebase_source : 7416e45babccce3af795dc523f46dc00fdddc6c7
2016-09-30 17:32:34 +09:00
Masayuki Nakano e2d42463da Bug 1306549 part.10 Reorder member declaration of KeyboardLayout class r=m_kato
We usually declare class members with following order:

1. public members
2. private members
3. friends

However, current KeyboardLayout is declared with completely opposite order.  Let's use usual order for preventing mistakes.

MozReview-Commit-ID: LwOcEUbJzes

--HG--
extra : rebase_source : 828b5d14f1b38f46e4ae5244d15de68c4db6785c
2016-10-04 16:37:07 +09:00
Masayuki Nakano d2ec7a36c3 Bug 1306549 part.9 Create KeyboardLayout::IsInDeadKeySequence() which returns true while it's in a dead key sequence r=m_kato
Currently, checking if it's in dead key sequence directly refers mActiveDeadKey.  However, this isn't clear for most developers.  So, let's create a helper method, IsInDeadKeySequence(), and wrap the nonintuitive check.

MozReview-Commit-ID: 7qTer9R8Gfs

--HG--
extra : rebase_source : 6ecb20cc3f5e28cfcf41fb33df8603785288bdda
2016-09-30 15:55:51 +09:00
Masayuki Nakano 05ede9d10b Bug 1306549 part.7 Create KeyboardLayout::MaybeInitNativeKeyAsDeadKey() r=m_kato
This patch creates KeyboardLayout::MaybeInitNativeKeyAsDeadKey() for wrapping dead key handling code in KeyboardLayout::InitNativeKey().

This makes InitNativeKey() code simpler.  Now, any developers must be able to understand what InitNativeKey() does easier than before fixing this bug.

MozReview-Commit-ID: C59ESUXeTxU

--HG--
extra : rebase_source : c840a0544470ec4081e80c11e050d4dfedef4cad
2016-09-30 16:06:00 +09:00
Masayuki Nakano 022c2c76a7 Bug 1306549 part.6 Create KeyboardLayout::ActivateDeadKeyState() r=m_kato
There is DeactivateDeadKeyState() but not ActivateDeadKeyState().  There should be both of them and hides the dead key state management into them.

MozReview-Commit-ID: JvAPE5f2HVy

--HG--
extra : rebase_source : d7027a1a6b75c6859e79d651d3e9b0136cc09891
2016-09-16 19:09:12 +09:00
Masayuki Nakano c5efc36210 Bug 1306549 part.5 Create KeyboardLayout::GetCompositeChar() for wrapping VirtualKey::GetCompositeChar() r=m_kato
VirtualKey::GetCompositeChar() needs index of virtual keycode which may make around the caller messy.  So, KeyboardLayout::GetCompositeChar() should wrap it and KeyboardLayout::MaybeInitNativeKeyWithCompositeChar() should use it.

MozReview-Commit-ID: 8KLTJpCFZ8u

--HG--
extra : rebase_source : fd13c009330fd485c8cba30f469fc645b560c623
2016-09-16 18:54:48 +09:00