Skip to content

Commit

Permalink
Sync and update 'which' across KeyboardEvent, MouseEvent and UIEvent …
Browse files Browse the repository at this point in the history
…interfaces as per web specification

https://bugs.webkit.org/show_bug.cgi?id=253366
rdar://problem/106580687

Reviewed by Ryosuke Niwa.

This patch aligns WebKit with Gecko / Firefox, Blink / Chromium and Web Specifications [1], [2] and [3].

[1] https://w3c.github.io/uievents/#idl-uievent
[2] https://w3c.github.io/uievents/#idl-keyboardevent
[3] https://w3c.github.io/uievents/#idl-mouseevent

This patch modifies 'which' to be 'unsigned' as per web-specification and also remove it from 'KeyboardEvent'.

Merge: https://chromium.googlesource.com/chromium/src.git/+/cf13270c47f29b21ce7a8c937f598989cd66c840

* Source/WebCore/dom/KeyboardEvent.cpp:
(KeyboardEvent::which):
* Source/WebCore/dom/KeyboardEvent.h:
* Source/WebCore/dom/KeyboardEvent.idl:
* Source/WebCore/dom/MouseEvent.cpp:
(MouseEvent::which):
* Source/WebCore/dom/MouseEvent.h:
* Source/WebCore/dom/UIEvent.cpp:
(UIEvent::which):
* Source/WebCore/dom/UIEvent.h:
* Source/WebCore/dom/UIEvent.idl: Remove FIXME and align with web-spec

Canonical link: https://commits.webkit.org/273701@main
  • Loading branch information
Ahmad-S792 authored and Ahmad Saleem committed Jan 30, 2024
1 parent f98fe54 commit df7782c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 21 deletions.
5 changes: 3 additions & 2 deletions Source/WebCore/dom/KeyboardEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -232,13 +233,13 @@ bool KeyboardEvent::isKeyboardEvent() const
return true;
}

int KeyboardEvent::which() const
unsigned KeyboardEvent::which() const
{
// Netscape's "which" returns a virtual key code for keydown and keyup, and a character code for keypress.
// That's exactly what IE's "keyCode" returns. So they are the same for keyboard events.
if (m_which)
return m_which.value();
return keyCode();
return static_cast<unsigned>(keyCode());
}

} // namespace WebCore
3 changes: 2 additions & 1 deletion Source/WebCore/dom/KeyboardEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -83,7 +84,7 @@ class KeyboardEvent final : public UIEventWithKeyState {

EventInterface eventInterface() const final;
bool isKeyboardEvent() const final;
int which() const final;
unsigned which() const final;

bool isComposing() const { return m_isComposing; }

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/dom/KeyboardEvent.idl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2006-2024 Apple Inc.
* Copyright (C) 2006-2024 Apple Inc. All rights reserved.
* Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -48,7 +49,6 @@
readonly attribute [AtomString] DOMString keyIdentifier;
readonly attribute unsigned long charCode;
readonly attribute unsigned long keyCode;
readonly attribute unsigned long which;

// FIXME: this does not match the version in the DOM spec.
undefined initKeyboardEvent([AtomString] DOMString type, optional boolean canBubble = false, optional boolean cancelable = false,
Expand Down
7 changes: 4 additions & 3 deletions Source/WebCore/dom/MouseEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003-2016 Apple Inc. All rights reserved.
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -194,14 +195,14 @@ MouseButton MouseEvent::button() const
return isKnownButton ? static_cast<MouseButton>(m_button) : MouseButton::Other;
}

int MouseEvent::which() const
unsigned MouseEvent::which() const
{
// For the DOM, the return values for left, middle and right mouse buttons are 0, 1, 2, respectively.
// For the Netscape "which" property, the return values for left, middle and right mouse buttons are 1, 2, 3, respectively.
// So we must add 1.
if (!m_buttonDown)
return 0;
return m_button + 1;
return static_cast<unsigned>(m_button + 1);
}

RefPtr<Node> MouseEvent::toElement() const
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/dom/MouseEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003-2016 Apple Inc. All rights reserved.
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -89,7 +90,7 @@ class MouseEvent : public MouseRelatedEvent {

static bool canTriggerActivationBehavior(const Event&);

int which() const final;
unsigned which() const final;

protected:
MouseEvent(const AtomString& type, CanBubble, IsCancelable, IsComposed, MonotonicTime timestamp, RefPtr<WindowProxy>&&, int detail,
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/dom/UIEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -99,7 +100,7 @@ int UIEvent::pageY() const
return 0;
}

int UIEvent::which() const
unsigned UIEvent::which() const
{
return 0;
}
Expand Down
5 changes: 3 additions & 2 deletions Source/WebCore/dom/UIEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* Copyright (C) 2001 Peter Kelly (pmk@post.com)
* Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
* Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2013 Apple Inc. All rights reserved.
* Copyright (C) 2003-2024 Apple Inc. All rights reserved.
* Copyright (C) 2017 Google Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -62,7 +63,7 @@ class UIEvent : public Event {
virtual int pageX() const;
virtual int pageY() const;

virtual int which() const;
virtual unsigned which() const;

protected:
UIEvent();
Expand Down
13 changes: 6 additions & 7 deletions Source/WebCore/dom/UIEvent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@
* Boston, MA 02110-1301, USA.
*/

// https://w3c.github.io/uievents/#idl-uievent

[
Exposed=Window
] interface UIEvent : Event {
constructor([AtomString] DOMString type, optional UIEventInit eventInitDict);

readonly attribute WindowProxy view;
constructor([AtomString] DOMString type, optional UIEventInit eventInitDict = {});
readonly attribute WindowProxy? view;
readonly attribute long detail;

// https://w3c.github.io/uievents/#idl-interface-UIEvent-initializers
undefined initUIEvent([AtomString] DOMString type, optional boolean canBubble = false, optional boolean cancelable = false, optional WindowProxy? view = null, optional long detail = 0);

readonly attribute long layerX;
readonly attribute long layerY;
readonly attribute long pageX;
readonly attribute long pageY;

// FIXME: This should be on KeyboardEvent only as per the specification but Firefox and Chrome
// still have this attribute on UIEvent as of December 2016.
readonly attribute long which;
readonly attribute unsigned long which;
};

0 comments on commit df7782c

Please sign in to comment.