2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2014-10-15 00:15:21 +04:00
|
|
|
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
#include "mozilla/dom/XULMenuElement.h"
|
|
|
|
#include "mozilla/StaticAnalysisFunctions.h"
|
|
|
|
#include "mozilla/dom/XULButtonElement.h"
|
|
|
|
#include "mozilla/dom/XULMenuElementBinding.h"
|
|
|
|
#include "mozilla/dom/XULPopupElement.h"
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEventBinding.h"
|
2023-01-04 02:48:30 +03:00
|
|
|
#include "nsXULPopupManager.h"
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2000-05-30 11:59:13 +04:00
|
|
|
|
2022-05-09 23:41:21 +03:00
|
|
|
namespace mozilla::dom {
|
2000-05-30 11:59:13 +04:00
|
|
|
|
2018-07-31 22:30:17 +03:00
|
|
|
JSObject* XULMenuElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return XULMenuElement_Binding::Wrap(aCx, this, aGivenProto);
|
2000-05-30 11:59:13 +04:00
|
|
|
}
|
|
|
|
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
Element* XULMenuElement::GetActiveMenuChild() {
|
|
|
|
RefPtr popup = GetMenuPopupContent();
|
|
|
|
return popup ? popup->GetActiveMenuChild() : nullptr;
|
2023-01-04 02:48:30 +03:00
|
|
|
}
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 01:06:01 +03:00
|
|
|
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
void XULMenuElement::SetActiveMenuChild(Element* aChild) {
|
|
|
|
RefPtr popup = GetMenuPopupContent();
|
|
|
|
if (NS_WARN_IF(!popup)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aChild) {
|
|
|
|
popup->SetActiveMenuChild(nullptr);
|
|
|
|
return;
|
2014-10-15 00:15:21 +04:00
|
|
|
}
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
auto* button = XULButtonElement::FromNode(aChild);
|
|
|
|
if (NS_WARN_IF(!button) || NS_WARN_IF(!button->IsMenu())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// KnownLive because it's aChild.
|
|
|
|
popup->SetActiveMenuChild(MOZ_KnownLive(button));
|
2000-08-17 13:15:51 +04:00
|
|
|
}
|
2000-05-30 11:59:13 +04:00
|
|
|
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
bool XULButtonElement::HandleKeyPress(KeyboardEvent& keyEvent) {
|
|
|
|
RefPtr<nsXULPopupManager> pm = nsXULPopupManager::GetInstance();
|
2014-10-15 00:15:21 +04:00
|
|
|
if (!pm) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2004-08-10 02:22:02 +04:00
|
|
|
// if event has already been handled, bail
|
2018-04-20 19:53:17 +03:00
|
|
|
if (keyEvent.DefaultPrevented()) {
|
2014-10-15 00:15:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-08-10 02:22:02 +04:00
|
|
|
|
2023-02-07 19:29:40 +03:00
|
|
|
if (keyEvent.IsMenuAccessKeyPressed()) {
|
2014-10-15 00:15:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-04 01:00:07 +04:00
|
|
|
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
nsMenuPopupFrame* popupFrame = GetMenuPopup(FlushType::Frames);
|
|
|
|
if (NS_WARN_IF(!popupFrame)) {
|
2014-10-15 00:15:21 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-04 01:00:07 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
uint32_t keyCode = keyEvent.KeyCode();
|
2004-07-04 01:00:07 +04:00
|
|
|
switch (keyCode) {
|
2018-06-26 00:20:54 +03:00
|
|
|
case KeyboardEvent_Binding::DOM_VK_UP:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_DOWN:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_HOME:
|
|
|
|
case KeyboardEvent_Binding::DOM_VK_END: {
|
2007-07-23 21:08:10 +04:00
|
|
|
nsNavigationDirection theDirection;
|
2008-12-30 16:30:51 +03:00
|
|
|
theDirection = NS_DIRECTION_FROM_KEY_CODE(popupFrame, keyCode);
|
2014-10-15 00:15:21 +04:00
|
|
|
return pm->HandleKeyboardNavigationInPopup(popupFrame, theDirection);
|
2007-07-23 21:08:10 +04:00
|
|
|
}
|
2004-07-04 01:00:07 +04:00
|
|
|
default:
|
Bug 1805414 - Remove nsMenuFrame and nsMenuParent. r=smaug,Jamie,desktop-theme-reviewers,settings-reviewers,dao
Move most the event handling stuff to the DOM. I've left nsMenuBarFrame
for now, but I will be removing that in the future.
The basic set up is:
* nsMenuParent becomes XULMenuParentElement (menubar or popup, manages
the current active menu item)
* nsMenuFrame -> XULButtonElements that return true for IsMenu().
Can't use XULMenuElement because of <button type=menu>, which
behaves like a, well, menu.
This makes the a11y events for menus (DOMMenuItem{Active,Inactive}) make
sense (before that we were firing duplicate Inactive events etc, and the
event order was rather suspicious).
Differential Revision: https://phabricator.services.mozilla.com/D164210
2023-01-04 22:01:13 +03:00
|
|
|
return pm->HandleShortcutNavigation(keyEvent, popupFrame);
|
2011-01-04 20:24:51 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 23:41:21 +03:00
|
|
|
} // namespace mozilla::dom
|