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

212 Коммитов

Автор SHA1 Сообщение Дата
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
Ting-Yu Chou 9e66f3af06 Bug 1322465 part 14 - Use explicit/MOZ_IMPLICIT for the unary constructors in widget/. r=Ehsan
MozReview-Commit-ID: JOrzksTzwVT

--HG--
extra : rebase_source : a7e92ef309025f6243fc8dba5cf30dfda591b181
2016-12-16 16:00:43 +08:00
Masayuki Nakano f0bff83240 Bug 1318265 NativeKey shouldn't handle messages when mWidget has already been destroyed r=m_kato
When mWidget was already destroyed, anybody shouldn't dispatch WidgetEvent on it. Therefore, NativeKey::InitKeyEvent() has MOZ_CRASH() for detecting such dangerous bug and some users hit it.

Each message handler of NativeKey should check if mWidget has already gone.

Ideally, nsWindow shouldn't create NativeKey and try to handle the message with it. However, using NativeKey's message handlers can put some information to the log. Therefore, this patch doesn't touch nsWindow.

MozReview-Commit-ID: 4k5VfaKHPgG

--HG--
extra : rebase_source : 4269847fbdf5daa66244ce924ddc54feb5c6cd01
2016-11-17 19:02:30 +09: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 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 add7eea556 Bug 1303273 part.1 KeyboardLayout::IsSysKey() should check MODIFIER_ALT as a bit flag r=m_kato
This is a simple mistake and blocks following patchs' automated tests.

For example, when Alt+Shift+foo doesn't cause text, this returns false even though it should return true.

MozReview-Commit-ID: 91L33vZhouT

--HG--
extra : rebase_source : be7d4e7ad670c1b03e6497c1c313c187ece80c1c
2016-10-11 13:00:45 +09:00
Masayuki Nakano 0f3c94dc03 Bug 1307112 part.10 Clean up NativeKey::HandleCharMessage() r=m_kato
Now, NativeKey::HandleCharMessage() has almost same code, one is for dispatching eKeyPress event for non-printable keys or printable keys when one of Alt or Ctrl key is pressed, the other is for printable keys when Alt or Ctrl key is pressed.

The difference of them is, the former block removes Alt state and Ctrl state for handling AltGr key.  When AltGr key is pressed, both Alt and Ctrl state are true.  However, EditorBase treas keypress events whose altKey or ctrlKey is true as non-printable key event.  Therefore, we need to set these modifier state to false when AltGr key is pressed and the key causes some text.

Note that as far as we know, when a key press with AltGr doesn't cause any characters, WM_CHAR isn't generated.  Therefore, we don't need to check with complicated logic if the key event is actually inputting a character.

MozReview-Commit-ID: BRNWfICvkSm

--HG--
extra : rebase_source : 3b8a2aaeb4c53be1567f7a8d17dfef1af90406dd
2016-10-04 23:01:14 +09:00
Masayuki Nakano 69a96b6460 Bug 1307112 part.9 Get rid of remaining hacks for KeyboardEvent.charCode when Ctrl or Alt is pressed r=m_kato
Current shortcut key handling is really difference from what we did before struggling with "key hell".  Therefore, remaining hacks for charCode in NativeKey::HandleCharMessage() are not necessary because they are for old code.

MozReview-Commit-ID: 3hvsBOiJ6VV

--HG--
extra : rebase_source : 7387fc89930f9b15d5d01612eb4a7a5726924bcd
2016-10-04 22:21:49 +09:00
Masayuki Nakano 337db43f23 Bug 1307112 part.8 NativeKey::HandleCharMessage() shouldn't dispatch eKeyPress event when its message is inputting a control character r=m_kato
This patch makes NativeKey::HandleCharMessage() stop dispatching eKeyPress event when the message is inputting a control character.  NativeKey::HandleCharMessage() runs following cases:

1. WM_KEYDOWN followed by a WM_CHAR message whose wParam is not a control character causes inputting printable characters.
2. WM_CHAR message is received without WM_KEYDOWN message.

So, when HandleCharMessage() is called for a control character, it's unusual case.  E.g., another application sends only WM_CHAR message with a control character.

On the other hand, Gecko is the only browser which dispatches "keypress" event even if pressed printable key doesn't cause inputting any characters.  And such "keypress" event is used for shortcut key handling and some default action handling.  So, even if we stop dispatching eKeyPress event from HandleCharMessage(), it shouldn't affect most users.

Note that this patch does NOT change the behavior when the user inputs a control character with usual keyboard layout such as Ctrl+A of en-US keyboard layout because DispatchKeyPressEventsWithoutCharMessage() dispatches eKeyPress event in such cases.

This patch also adds a lot of tests with Ctrl or Alt state for detecting regressions.

MozReview-Commit-ID: KUNqTp7RDSc

--HG--
extra : rebase_source : f91e37b0b82a8e8a95444a08f6d3101f14fadc50
2016-10-05 15:18:00 +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 2b007a1732 Bug 1307112 part.5 NativeKey should skip non-printable char messages when it initializes mCommittedCharsAndModifiers with following char messages r=m_kato
NativeKey shouldn't include characters which are provided by WM_SYSCHAR message or WM_DEADCHAR message into mCommittedCharsAndModifiers.

MozReview-Commit-ID: Ax1BmO5wTy0

--HG--
extra : rebase_source : 5d7d1735a783213f7c6a47cca0cadb1d4c5104c0
2016-10-03 18:20:29 +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 432f317b32 Bug 1307112 part.3 NativeKey::IsFollowedByNonControlCharMessage() should return true when one of following char messages is a printable char message r=m_kato
Currently, NativeKey::IsFollowedByNonControlCharMessage() returns true only when the first char message is a printable char message.  Although, I don't know actual cases coming printable WM_CHAR message after non-printable char message, i.e.,

1. WM_SYSCHAR or WM_DEADCHAR
2. WM_CHAR for a printable character

or

1. WM_CHAR with a non-printable character (a control character)
2. WM_CHAR with a printable character

, we should make it return true because when one or more characters are being inputted, we should ignore non-printable char messages and handle printable char messages in the path handling text input.

MozReview-Commit-ID: 1v7v5mCRFCP

--HG--
extra : rebase_source : f82f7b77376450168bad34be031164ecf7338621
2016-10-03 18:03:46 +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 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 6a00ae82ee Bug 1306549 part.8 Get rid of |virtualKey| and |isKeyDown| from KeyboardLayout::InitNativeKey() and KeyboardLayout::MaybeInitNativeKeyAsDeadKey() r=m_kato
For preventing wrapping long lines, old KeyboardLayout::InitNativeKey() uses two variables |virtualKey| and |isKeyDown| which are never modified.  However, they may be not clear for some developers where they came from.  Additionally, preceding patches reduced a lot of users of them and indent level.  Therefore, even if we remove these variables, we don't need additional line breaks in most cases.  So, removing them is better for easier to understand.

MozReview-Commit-ID: 680bYVINPAE

--HG--
extra : rebase_source : 15f4398072ccfe659fc6d2ae95a3f13261efa5af
2016-09-30 15:40:40 +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
Masayuki Nakano da22fd3b2b Bug 1306549 part.4 Create KeyboardLayout::GetNativeUniCharsAndModifiers() for wrapping VirtualKey::GetNativeUniChars() r=m_kato
Similar to VirtualKey::GetUniChars(), VirtualKey::GetNativeUniChars() needs key index.  So, it should be wrapped by a new helper method, KeyboardLayout::GetNativeUniCharsAndModifiers(), and KeyboardEvent::InitNativeKey() should use this instead of accessing its member's GetNativeUniChars().

MozReview-Commit-ID: 7M9OlNF698Y

--HG--
extra : rebase_source : e19a5c99014a8f0a0ed7cc3a86fe0c4ee10cebb5
2016-09-16 18:38:53 +09:00
Masayuki Nakano 49ebeb51f0 Bug 1306549 part.3 KeyboardLayout::InitNativeKey() should use GetUniCharsAndModifiers() instead of using VirtualKey::GetUniChars() directly r=m_kato
When InitNativeKey() retrieves UniCharsAndModifiers for a key, it needs key index for the given virtual keycode.  Therefore, wrapping the code with GetUniCharsAndModifiers() makes InitNativeKey() code simpler since each call specifies the virtual keycode to the method instead of key index.

MozReview-Commit-ID: Azy8chXexaz

--HG--
extra : rebase_source : 98da43e7f542037f952206cd3db731f6cbb097e7
2016-09-16 18:22:12 +09:00
Masayuki Nakano 1559d32969 Bug 1306549 part.2 Create overload methods which take ModifierKeyState instead of VirtualKey::ShiftState r=m_kato
This patch gets rid of |shiftState| from KeyboardLayout::InitNativeKey() and make each caller clearer.  This must make other developers understand what modifier state is used at each call.

MozReview-Commit-ID: 6zydP1jkffv

--HG--
extra : rebase_source : ea1d5f49ea02812aa632bdbad871688879f2b401
2016-09-30 15:32:10 +09:00
Masayuki Nakano af0de6d7e8 Bug 1306549 part.1 KeyboardLayout::InitNativeKey() should use KeyboardLayout::IsDeadKey() r=m_kato
KeyboardLayout::InitNativeKey() is very messy because it handles a lot of cases without helper methods.

It's important to make it simpler implementation for preventing regressions caused by some patches which are written with misunderstanding.  So, let's rewrite the method with helper method.

First, this patch make InitNativeKey() use IsDeadKey() instead of referring the table because calling IsDeadKey() is easier to understand.

MozReview-Commit-ID: DtN9qoh7Gz7

--HG--
extra : rebase_source : 8e769c1c88bfe646940491c111de609dbf53eeec
2016-09-16 17:24:39 +09:00
Masayuki Nakano caa4d59b38 Bug 1302956 part.2 NativeKey shouldn't handle char message if it's created during another instance is trying to remove a char message from the queue r=m_kato
When NativeKey tries to remove a char message from the queue, another NativeKey instance might be created due to odd API hook or something.  In such case, the old instance should handle the received message and the new instance should do nothing for keeping the order of message handling.

This patch makes:

* NativeKey::GetFollowingCharMsg() store removing char message to mRemovingMsg before calling PeekMessage() with PM_REMOVE.
* NativeKey::InitWithChar() set the old instance's mReceivedMsg to the received char message and do nothing even if HandleCharMessage() is called later.
* NativeKey::GetFollowingCharMsg() return received char message if mReceivedMsg is set during a call of PeekMessage().

MozReview-Commit-ID: KXYW0GgC9AY

--HG--
extra : rebase_source : 08472dec28e93450cd04a367843c1511cb812a9c
2016-09-23 16:40:01 +09:00
Masayuki Nakano bf273c667a Bug 1302956 part.1 NativeKey should store latest instance with sLatestInstance r=m_kato
For detecting nested creation of NativeKey instances, NativeKey should manage the latest instance with sLastestInstance for the other instances and previous instance with mLastInstance.

MozReview-Commit-ID: BFZ0cr1640S

--HG--
extra : rebase_source : e2439a21f5984c6246283924c2013038c734ae2a
2016-09-15 17:02:30 +09:00
Masayuki Nakano c4106a36a9 Bug 1297013 part.3 Make NativeKey log its behavior r=m_kato
MozReview-Commit-ID: 6ksuMFMxQdM

--HG--
extra : rebase_source : 28f04d8e5d33c018a8bcda7d8ae1a84da07eaeb9
2016-09-21 13:29:34 +09:00
Masayuki Nakano 92ba10120f Bug 1297013 part.1 Implement ToString(const MSG&) for logging key related message with detail r=m_kato
For logging message, we should have better log text generator for MSG.

Then, we can improve the note of crash reports which is appended in NativeKey::GetFollowingCharMessage().

MozReview-Commit-ID: 4sbZJaWFH2o

--HG--
extra : rebase_source : bbc3101a78e4e2aa8b5eb0f68cd6f3605ba924f6
2016-08-26 20:52:25 +09:00
Masayuki Nakano eac959a338 Bug 1300003 part.6 NativeKey shouldn't try to dispatch plugin events for removed char messages when mWidget won't dispatch plugin events r=m_kato
Currently, NativeKey::DispatchPluginEventsAndDiscardsCharMessages() calls nsWindowBase::DispatchPluginEvent() and nsWindowBase::DispatchPluginEvent() does nothing when windowless plugin doesn't have focus.  However, this is unclear when other developers read the code of DispatchPluginEventsAndDiscardsCharMessages() and it causes unnecessary virtual calls.  So, it should try to dispatch plugin events only when a windowless plugin has focus.

For making the check safer, nsWindowBase should expose the method to check it as ShouldDispatchPluginEvent().  Unfortunately, we cannot mark this method as const due to PluginHasFocus() needs to be not const method, though.  Then, for loops in DispatchPluginEventsAndDiscardsCharMessages() should check it at each try.

This change helps to log the behavior (working on bug 1297013) without noise.

Additionally, this patch renames the method to MaybeDispatchPluginEventsForRemovedCharMessages() because it doesn't remove any char messages anymore.

MozReview-Commit-ID: F14Lcx47M6U

--HG--
extra : rebase_source : 64b6da75590c99299f75358023844762198136d6
2016-09-15 00:16:18 +09:00
Masayuki Nakano 050c1b4088 Bug 1300003 part.5 Remove odd WM_CHAR messages which are caused by ATOK or WXG (both of them are Japanese IME) r=m_kato
NativeKey removes odd WM_CHAR messages which are caused by ATOK or WXG if the user tries to do "Kakutei-Undo" (meaning "undo the last commit") after dispatching eKeyDown event.

However, NativeKey should remove them from the queue first because there are some problems:

* If focus is moved during dispatching an eKeyDown event, we'll fail to remove the messages from the queue.
* If dispatching eKeyDown advance native event loop due to entering to a modal loop or dosing synchronous XHR, the message pattern is broken before removing the odd messages from the queue.

After removing the odd char messages, NativeKey should store them with mRemovedOddCharMsgs because NativeKey needs to dispatch them to focused windowless plugin.

Note that this patch also fixes a bug of the loop to remove the odd WM_CHAR messages.  Old code removes only one WM_CHAR messages, but we need to remove all WM_CHAR messages before WM_KEYUP.  This must be a regression.

MozReview-Commit-ID: I60bcIx2SFS

--HG--
extra : rebase_source : 19d0e70d9f39e6d0476c62def5e0a2dc1e0ab444
2016-09-14 16:20:53 +09:00
Masayuki Nakano c0ad8a8fb2 Bug 1300003 part.4 Remove NativeKey::mIsFollowedByNonControlCharMessage because calling NativeKey::IsFollowedByNonControlCharMessage() is enough fast r=m_kato
NativeKey is now removing and storing following char messages when it's created for a keydown message.  Therefore, IsFollowedByNonControlCharMessage() just refers the stored messages and it's enough fast.  So, we can get rid of mIsFollowedByNonControlCharMessage.

MozReview-Commit-ID: 542A2sHNXeC

--HG--
extra : rebase_source : e748c9855c3cf2d45609f94f9ccc8d43d29dc447
2016-09-05 21:47:58 +09:00
Masayuki Nakano 308955d236 Bug 1300003 part.3 NativeKey::GetFollowingCharMessage() should always remove following WM_CHAR message r=m_kato
GetFollowingCharMessage() is now called only when removing following char message.  Therefore, it does not need to have the optional argument indicating if removing the found message.

MozReview-Commit-ID: 7P39wyfSC1

--HG--
extra : rebase_source : a38bb961df1bc03adc21295bc39e4e9c16e864f2
2016-09-05 21:41:48 +09:00
Masayuki Nakano 6934d7ed93 Bug 1300003 part.2 Don't continue to dispatch eKeyPress event at handling WM_KEYDOWN or following WM_CHAR messages if focused window is changed during dispatching an event r=m_kato
While dispatching an event, focused widget may be changed.  In such case, NativeKey shouldn't continue to dispatch remaining events (eKeyPress events) for preventing to dispatch to input text in unexpected website.

MozReview-Commit-ID: 7geuqks0LQK

--HG--
extra : rebase_source : 3e6c82e1eb0e27115fe93b1a3b4a155914fd06f7
2016-09-05 18:56:34 +09:00
Masayuki Nakano af43a9e1dc Bug 1300003 part.1 NativeKey should remove following char messages before dispatching a keydown event r=m_kato
In some cases, we may receive following char message of WM_*KEYDOWN *during* dispatching an eKeyDown event. In such case, NativeKey shouldn't dispatch eKeyPress event twice (one is caused by receiving WM_*CHAR message, the other is caused by post dispatching eKeyDown event code).

This patch makes NativeKey consume following WM_*CHAR messages before dispatching eKeyDown.  Therefore, the former case will never occur.

For doing that, NativeKey stores following WM_*CHAR messages in mFollowingCharMsgs and uses it when it needs to dispatch eKeyPress events for each WM_*CHAR message.

MozReview-Commit-ID: 6QNvlwVVlTz

--HG--
extra : rebase_source : c33b5a1ac503326d51ef78f4f8a09c9a63df7871
2016-09-15 00:02:15 +09:00
Masayuki Nakano b8318c87fb Bug 1300937 part.4 NativeKey::GetScanCodeWithExtendedFlag() should return 0xE0XX even on WinXP or WinServer2003 r=m_kato
For safety, NativeKey::GetScanCodeWithExtendedFlag() returns without extended flag on WinXP and WinServer2003 because ::MapVirtualKeyEx() API doesn't support extend key conversion.

However, extended scan code is available even on them when lParam has 0x1000000 especially when it computes KeyboardEvent.code value.  Therefore, it should return with 0xE000 for extended keys on any versions of Windows.

Note that NativeKey::ComputeVirtualKeyCodeFromScanCodeEx() wraps ::MapVirtualKeyEx() API.  It checks if the API is not available for the result of NativeKey::GetScanCodeWithExtendedFlag().  So, returning extended scan code from NativeKey::GetScanCodeWithExtendedFlag() is safe.

MozReview-Commit-ID: D2RrHxPI9ET

--HG--
extra : rebase_source : 51f277e8331eb7ad109c3227ac1fe73f6de48105
2016-09-16 10:17:44 +09:00
Masayuki Nakano 05960c4ff6 Bug 1300937 part.2 Automated tests which synthesize native key events on Windows should specify scan code value explicitly r=smaug
On Windows, some keys are called "extended key".  Their scan code include 0xE000.  For example, Enter key in standard position is 0x001C but Numpad's Enter key is 0xE01C.  Unfortunately, both of them cause same virtual keycode value, VK_RETURN.  Therefore, currently, nsIDOMWindowUtils.sendNativeKey() can synthesize only one native key event of them (only non-extended key's event).  Additionally, MapVirtualKeyEx() API with MAPVK_VK_TO_VSC (even with MAPVK_VK_TO_VSC_EX) don't return extended scancode value as expected.

For solving these issues, we should include scan code value to the virtual keycode value at calling sendNativeKey().

Fortunately, virtual keycode value on Windows is 0 ~ 255 (0x00 ~ 0xFF) but aNativeKeyCode of sendNativeKey() is int32_t.  So, we can use upper 16 bit for specifying scan code.

This patch explicitly specifies scan code value at defining WIN_VK_* in NativeKeyCodes.js.  Additionally, this patch duplicates native virtual keycode definition for Home, End, Insert, Delete, PageUp, PageDown, ArrowUp, ArrowLeft, ArrowDown, ArrowRight and Enter as WIN_VK_* and WIN_VK_NUMPAD_*.  This makes automated tests can specify both positions' keys explicitly.

Finally, this patch adds some tests to test_keycodes.xul for testing KeyboardEvent.code value of those keys in both positions.

MozReview-Commit-ID: 8n1rQ71dilg

--HG--
extra : rebase_source : 8215e56ba1ed9fc54c04eb7ca037b12c3ced5c1b
2016-09-13 19:38:23 +09:00
Carsten "Tomcat" Book 915d632972 Backed out changeset be88a60abb7a (bug 1300937)
--HG--
extra : rebase_source : 19b90e94e16547a7a718a7c4c2f587e64fbe4b7a
2016-09-15 17:04:16 +02:00
Masayuki Nakano e8eae5c2a2 Bug 1300937 part.2 Automated tests which synthesize native key events on Windows should specify scan code value explicitly r=smaug
On Windows, some keys are called "extended key".  Their scan code include 0xE000.  For example, Enter key in standard position is 0x001C but Numpad's Enter key is 0xE01C.  Unfortunately, both of them cause same virtual keycode value, VK_RETURN.  Therefore, currently, nsIDOMWindowUtils.sendNativeKey() can synthesize only one native key event of them (only non-extended key's event).  Additionally, MapVirtualKeyEx() API with MAPVK_VK_TO_VSC (even with MAPVK_VK_TO_VSC_EX) don't return extended scancode value as expected.

For solving these issues, we should include scan code value to the virtual keycode value at calling sendNativeKey().

Fortunately, virtual keycode value on Windows is 0 ~ 255 (0x00 ~ 0xFF) but aNativeKeyCode of sendNativeKey() is int32_t.  So, we can use upper 16 bit for specifying scan code.

This patch explicitly specifies scan code value at defining WIN_VK_* in NativeKeyCodes.js.  Additionally, this patch duplicates native virtual keycode definition for Home, End, Insert, Delete, PageUp, PageDown, ArrowUp, ArrowLeft, ArrowDown, ArrowRight and Enter as WIN_VK_* and WIN_VK_NUMPAD_*.  This makes automated tests can specify both positions' keys explicitly.

Finally, this patch adds some tests to test_keycodes.xul for testing KeyboardEvent.code value of those keys in both positions.

MozReview-Commit-ID: 8n1rQ71dilg

--HG--
extra : rebase_source : 0f4bb9193aa06cd7985590636b77a6e2a71ac2e4
2016-09-13 19:38:23 +09:00
Masayuki Nakano 45df2cd377 Bug 1300319 part.1 NativeKey::IsControlChar() should return true when the char is 0x7F (control character, DELETE) r=m_kato
Ctrl+Backspace causes WM_CHAR for control character DELETE.  However, NativeKey::IsControlChar() doesn't treat it as a control character.  Therefore, NativeKey treats Backspace key as a printable character.

MozReview-Commit-ID: 29V45CNp8kW

--HG--
extra : rebase_source : 6656d884addf8b49dfa7c12d0b2c8d0543493c4f
2016-09-05 12:51:49 +09:00
Masayuki Nakano 8a11a75b19 Bug 1297985 part.2 KeyboardLayout should handle a composite character produced by 2 dead keys r=m_kato
On some keyboard layouts, a key sequence, a dead key -> another dead key, may produce a composite character instead of two base characters for each key.  For example, with "Russian - Mnemonic" keyboard layout on Win 8 or later, both 's' and 'c' are dead keys but key sequence, 's' -> 'c', produces a Unicode character.

For solving this issue, this patch fixes 2 bugs:

First, KeyboardLayout::GetDeadKeyCombinations() doesn't add dead key entry if 2nd key is a dead key (::ToUnicodeEx() returns -1).  In such case, it should add a dead key entry with the first character which is produced when only the 2nd key is pressed (the character is called as "base character" and used for index of the dead key table).

Next, KeyboardLayout::InitNativeKey() should check if 2nd dead key press produces a composite character.  If it's produced, it should initialize given NativeKey with the composite character.  Otherwise, it should initialize with base characters of each key.  This patch does it with KeyboardLayout::MaybeInitNativeKeyWithCompositeChar().

Finally, we should add automated test for this. However, unfortunately, it's not available on Win7 and our infra is still using Win7 for running automated tests.  Therefore, this patch doesn't include new automated tests.

MozReview-Commit-ID: G1DrfkHKNcK

--HG--
extra : rebase_source : 6ff4278d594a26a0908464b1e603a0a7ee2b3b38
2016-09-01 17:29:11 +09:00