[Webkit-unassigned] [Bug 16735] keyboard events created with DOM have keyCode and charCode of 0; thus they aren't handled correctly internally

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Nov 18 16:45:21 PST 2009


https://bugs.webkit.org/show_bug.cgi?id=16735





--- Comment #14 from Darin Adler <darin at apple.com>  2009-11-18 16:45:20 PST ---
(From update of attachment 43253)
> +    int firstChar = keyIdentifier.characterStartingAt(0);

The type is UChar32, not int.

> +    if (keyIdentifier.length() == 1 && isASCIIPrintable(firstChar))
> +        return static_cast<unsigned>(firstChar);
> +    if (keyIdentifier.length() == 1)
> +        return 0; // Non-printable ASCII character.

Nicer to combine these two with a nested if. Also best to put the length into a
local variable since we use it multiple times.

> +    if (keyIdentifier.length() == (2 /* "U+" */ + numUnicodeCodePointHexDigits) && keyIdentifier.substring(0, 2) == "U+") {

It's much more efficient to index twice or call startsWith than to actually
compute a substring.

    keyIdentifier[0] == 'U' || keyIdentifier[1] == '+'

> +        const UChar* p = keyIdentifier.characters();
> +        p += 2; // Skip over "U+", so that we point to the first hex digit.

Seems these should go into one line.

> +        unsigned unicodeValue = 0;

This should have the type UChar.

> +        unsigned numHexDigits = numUnicodeCodePointHexDigits;
> +        while (numHexDigits--)
> +            unicodeValue = unicodeValue << 4 | toASCIIHexValue(*(p++));      

Strange trailing spaces here.

Seems tom me that for four digits it would be cleaner to not write this as a
loop.

> +        return isValidCharCode(unicodeValue)? unicodeValue : 0;

We use a space before the "?" in these kinds of expression.

> +        return m_keyEvent? m_keyEvent->windowsVirtualKeyCode() : keyCodeForKeyIdentifier(m_keyIdentifier);

Here too.

> +    return m_keyEvent? static_cast<int>(m_keyEvent->text().characterStartingAt(0)) : charCodeForKeyIdentifier(m_keyIdentifier);

And here.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list