Closed Bug 630811 Opened 13 years ago Closed 12 years ago

Implement DOM3 KeyboardEvent.getModifierState()

Categories

(Core :: DOM: Events, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla15

People

(Reporter: masayuki, Assigned: masayuki)

References

(Depends on 2 open bugs, Blocks 1 open bug, )

Details

(Keywords: dev-doc-complete)

Attachments

(8 files, 5 obsolete files)

21.75 KB, patch
smaug
: review+
Details | Diff | Splinter Review
78.68 KB, patch
smaug
: review+
Details | Diff | Splinter Review
15.69 KB, patch
smaug
: review+
Details | Diff | Splinter Review
6.10 KB, patch
jimm
: review+
Details | Diff | Splinter Review
9.80 KB, patch
karlt
: review+
Details | Diff | Splinter Review
9.75 KB, patch
Details | Diff | Splinter Review
20.93 KB, patch
Details | Diff | Splinter Review
1.83 KB, text/html
Details
We cannot know whether some modifier keys are pressed or not:

1. Windows key on Windows
2. Windows key which is mapped to Super key on Linux
3. Hyper key on Linux.

For them, we should implement KeyboardEvent.getModifierState().
Attached file testcase (obsolete) —
This replaces is* with Is*() or just removes them. Not changing any logic.
Attachment #616432 - Flags: review?(bugs)
> -  nsDragEvent geckoEvent(true, aMessage, nsnull);
> -  [self convertGenericCocoaEvent:[NSApp currentEvent] toGeckoEvent:&geckoEvent];
> +  nsDragEvent geckoEvent(true, aMessage, mGeckoChild);
> +  nsCocoaUtils::InitInputEvent(geckoEvent, [NSApp currentEvent]);

I realized that this always fails to initialize modifiers. I think that we should store latest modifiers by other events and use it. But I think we should do it in another bug.
Attachment #616440 - Flags: review?(smichaud)
Status: NEW → ASSIGNED
Attached file testcase (obsolete) —
This works with IE9 too.
Attachment #616410 - Attachment is obsolete: true
Attachment #616448 - Attachment is patch: false
Attachment #616448 - Attachment mime type: text/plain → text/html
Comment on attachment 616437 [details] [diff] [review]
part.4 Support new modifiers on all events derived from nsInputEvent on Windows

Functionality looks fine. r+ assuming this fits with the new spec.
Attachment #616437 - Flags: review?(jmathies) → review+
Blocks: 747013
Comment on attachment 616440 [details] [diff] [review]
part.6 Support new modifiers on all events derived from nsInputEvent on Cocoa

This looks fine to me.

I do have one question, though.

+    // Remove basic modifiers from keypress event because if they are included,
+    // nsPlaintextEditor ignores the event.
+    keypressEvent.modifiers &= ~(widget::MODIFIER_CONTROL |
+                                 widget::MODIFIER_ALT |
+                                 widget::MODIFIER_META);

Wouldn't it make better sense to move this to just before the
following lines?

  // TODO:
  // If mCurrentKeyEvent.mKeyEvent is null and when we implement textInput
  // event of DOM3 Events, we should dispatch it instead of keypress event.
  bool keyPressHandled = DispatchEvent(keypressEvent);

'keypressEvent' will get initialized with modifiers (by
nsCocoaUtils::InitInputEvent()) whether or not 'currentKeyEvent' is
nil.  Currently you only remove them if if 'currentKeyEvent' is
non-nil.
Attachment #616440 - Flags: review?(smichaud) → review+
(In reply to Steven Michaud from comment #11)
> Comment on attachment 616440 [details] [diff] [review]
> part.6 Support new modifiers on all events derived from nsInputEvent on Cocoa
> 
> This looks fine to me.
> 
> I do have one question, though.
> 
> +    // Remove basic modifiers from keypress event because if they are
> included,
> +    // nsPlaintextEditor ignores the event.
> +    keypressEvent.modifiers &= ~(widget::MODIFIER_CONTROL |
> +                                 widget::MODIFIER_ALT |
> +                                 widget::MODIFIER_META);
> 
> Wouldn't it make better sense to move this to just before the
> following lines?
> 
>   // TODO:
>   // If mCurrentKeyEvent.mKeyEvent is null and when we implement textInput
>   // event of DOM3 Events, we should dispatch it instead of keypress event.
>   bool keyPressHandled = DispatchEvent(keypressEvent);
> 
> 'keypressEvent' will get initialized with modifiers (by
> nsCocoaUtils::InitInputEvent()) whether or not 'currentKeyEvent' is
> nil.  Currently you only remove them if if 'currentKeyEvent' is
> non-nil.

Oh, you're right. Thank you, I'll update it.
Attachment #616438 - Flags: review?(karlt) → review+
Comment on attachment 616428 [details] [diff] [review]
part.1 Move modifiers from nsMouseEvent_base to nsInputEvent


> NS_IMETHODIMP
> nsDOMKeyboardEvent::GetAltKey(bool* aIsDown)
> {
>   NS_ENSURE_ARG_POINTER(aIsDown);
>-  *aIsDown = ((nsInputEvent*)mEvent)->isAlt;
>+  *aIsDown = ((nsInputEvent*)mEvent)->IsAlt();
While you're here, could you change the C style casting to
C++ static_cast



>+  widget::Modifiers modifiers = static_cast<nsInputEvent*>(mEvent)->modifiers;
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
>-    return static_cast<nsInputEvent*>(mEvent)->isShift;
>+    return (modifiers & widget::MODIFIER_SHIFT) != 0;
>   }
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_CONTROL)) {
>-    return static_cast<nsInputEvent*>(mEvent)->isControl;
>+    return (modifiers & widget::MODIFIER_CONTROL) != 0;
>   }
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_META)) {
>-    return static_cast<nsInputEvent*>(mEvent)->isMeta;
>+    return (modifiers & widget::MODIFIER_META) != 0;
>   }
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_ALT)) {
>-    return static_cast<nsInputEvent*>(mEvent)->isAlt;
>+    return (modifiers & widget::MODIFIER_ALT) != 0;
>   }
> 
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_ALTGRAPH)) {
>     return (modifiers & widget::MODIFIER_ALTGRAPH) != 0;
>   }
>   if (aKey.EqualsLiteral(NS_DOM_KEYNAME_WIN)) {
>     return (modifiers & widget::MODIFIER_WIN) != 0;
>   }
So why use modifiers & foo here, and not the helper methods, isAlt() etc. ?
I'd prefer using the methods. Perhaps there should be helpers for altgr and win modifiers too.
Attachment #616428 - Flags: review?(bugs) → review+
Attachment #616432 - Flags: review?(bugs) → review+
Comment on attachment 616436 [details] [diff] [review]
part.3 Improve nsDOMWindowUtils::send*Event() for new modifiers

>   nsMouseEvent event(true, msg, widget, nsMouseEvent::eReal,
>                      contextMenuKey ?
>                        nsMouseEvent::eContextMenuKey : nsMouseEvent::eNormal);
>-  event.isShift = (aModifiers & nsIDOMNSEvent::SHIFT_MASK) ? true : false;
>-  event.isControl = (aModifiers & nsIDOMNSEvent::CONTROL_MASK) ? true : false;
>-  event.isAlt = (aModifiers & nsIDOMNSEvent::ALT_MASK) ? true : false;
>-  event.isMeta = (aModifiers & nsIDOMNSEvent::META_MASK) ? true : false;
>+  event.modifiers =GetWidgetModifiers(aModifiers);
space after =
Attachment #616436 - Flags: review?(bugs) → review+
Attachment #616441 - Flags: review?(bugs) → review+
Thank you for the quick review, smaug!

(In reply to Olli Pettay [:smaug] from comment #14)
> Comment on attachment 616428 [details] [diff] [review]
> part.1 Move modifiers from nsMouseEvent_base to nsInputEvent

> So why use modifiers & foo here, and not the helper methods, isAlt() etc. ?
> I'd prefer using the methods. Perhaps there should be helpers for altgr and
> win modifiers too.

Did you mean only for AltGraph and Win? How about the others, i.e., CapsLock, NumLock, Scroll, Fn, and SymbolLock? Currently, we will support only CapsLock, NumLock and Scroll at dispatching native event. Fn and SymbolLock are supported only for untrusted events. I think that the former 3 might be used in the future.
Attachment #617731 - Flags: superreview?(jst) → superreview+
(In reply to Masayuki Nakano (:masayuki) (Mozilla Japan) (away: 4/29 - 5/6) from comment #16)
> (In reply to Olli Pettay [:smaug] from comment #14)
> 
> Did you mean only for AltGraph and Win? How about the others, i.e.,
> CapsLock, NumLock, Scroll, Fn, and SymbolLock?
I mean all. Adding helper methods to get the value would be nice.
Attached file testcase (obsolete) —
Attachment #616448 - Attachment is obsolete: true
Attached file testcase
Attachment #640488 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: