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
|
|
|
|
|
|
|
#include "mozilla/dom/KeyboardEvent.h"
|
2018-02-09 19:17:09 +03:00
|
|
|
#include "mozilla/dom/KeyboardEventBinding.h"
|
2014-10-15 00:15:21 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2000-05-30 11:59:13 +04:00
|
|
|
#include "nsIFrame.h"
|
2011-01-04 20:24:51 +03:00
|
|
|
#include "nsMenuBarFrame.h"
|
2004-08-10 02:22:02 +04:00
|
|
|
#include "nsMenuBarListener.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2018-07-31 22:30:17 +03:00
|
|
|
#include "mozilla/dom/XULMenuElement.h"
|
|
|
|
#include "mozilla/dom/XULMenuElementBinding.h"
|
|
|
|
#include "nsXULPopupManager.h"
|
2000-05-30 11:59:13 +04:00
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace 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
|
|
|
}
|
|
|
|
|
2018-07-31 22:30:17 +03:00
|
|
|
already_AddRefed<Element> XULMenuElement::GetActiveChild() {
|
2018-10-18 15:40:10 +03:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
|
2014-10-15 00:15:21 +04:00
|
|
|
if (menu) {
|
2018-04-27 06:37:33 +03:00
|
|
|
RefPtr<Element> el;
|
2014-10-15 00:15:21 +04:00
|
|
|
menu->GetActiveChild(getter_AddRefs(el));
|
2018-04-27 06:37:33 +03:00
|
|
|
return el.forget();
|
2014-10-15 00:15:21 +04:00
|
|
|
}
|
|
|
|
return nullptr;
|
2000-08-17 13:15:51 +04:00
|
|
|
}
|
|
|
|
|
2018-07-31 22:30:17 +03:00
|
|
|
void XULMenuElement::SetActiveChild(Element* arg) {
|
2018-10-18 15:40:10 +03:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
|
2014-10-15 00:15:21 +04:00
|
|
|
if (menu) {
|
2018-04-27 06:37:33 +03:00
|
|
|
menu->SetActiveChild(arg);
|
2014-10-15 00:15:21 +04:00
|
|
|
}
|
2000-08-17 13:15:51 +04:00
|
|
|
}
|
2000-05-30 11:59:13 +04:00
|
|
|
|
2018-07-31 22:30:17 +03:00
|
|
|
bool XULMenuElement::HandleKeyPress(KeyboardEvent& keyEvent) {
|
2007-07-04 19:49:38 +04:00
|
|
|
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
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
if (nsMenuBarListener::IsAccessKeyPressed(&keyEvent)) return false;
|
2004-08-10 02:22:02 +04:00
|
|
|
|
2018-10-18 15:40:10 +03:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
|
2014-10-15 00:15:21 +04:00
|
|
|
if (!menu) {
|
|
|
|
return false;
|
|
|
|
}
|
2004-07-04 01:00:07 +04:00
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuPopupFrame* popupFrame = menu->GetPopup();
|
2014-10-15 00:15:21 +04:00
|
|
|
if (!popupFrame) {
|
|
|
|
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:
|
2014-10-15 00:15:21 +04:00
|
|
|
return pm->HandleShortcutNavigation(&keyEvent, popupFrame);
|
2004-07-04 01:00:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-31 22:30:17 +03:00
|
|
|
bool XULMenuElement::OpenedWithKey() {
|
2018-10-18 15:40:10 +03:00
|
|
|
nsMenuFrame* menuframe = do_QueryFrame(GetPrimaryFrame(FlushType::Frames));
|
2014-10-15 00:15:21 +04:00
|
|
|
if (!menuframe) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-01-04 20:24:51 +03:00
|
|
|
|
2012-07-31 04:43:28 +04:00
|
|
|
nsIFrame* frame = menuframe->GetParent();
|
2011-01-04 20:24:51 +03:00
|
|
|
while (frame) {
|
2012-07-31 04:43:28 +04:00
|
|
|
nsMenuBarFrame* menubar = do_QueryFrame(frame);
|
|
|
|
if (menubar) {
|
2014-10-15 00:15:21 +04:00
|
|
|
return menubar->IsActiveByKeyboard();
|
2011-01-04 20:24:51 +03:00
|
|
|
}
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
2014-10-15 00:15:21 +04:00
|
|
|
return false;
|
2011-01-04 20:24:51 +03:00
|
|
|
}
|
|
|
|
|
2014-10-15 00:15:21 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|