1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/KeyboardEvent.h"
8 #include "mozilla/dom/KeyboardEventBinding.h"
9 #include "mozilla/dom/Element.h"
11 #include "nsMenuBarFrame.h"
12 #include "nsMenuBarListener.h"
13 #include "nsMenuFrame.h"
14 #include "nsMenuPopupFrame.h"
15 #include "mozilla/dom/XULMenuElement.h"
16 #include "mozilla/dom/XULMenuElementBinding.h"
17 #include "nsXULPopupManager.h"
22 JSObject
* XULMenuElement::WrapNode(JSContext
* aCx
,
23 JS::Handle
<JSObject
*> aGivenProto
) {
24 return XULMenuElement_Binding::Wrap(aCx
, this, aGivenProto
);
27 already_AddRefed
<Element
> XULMenuElement::GetActiveChild() {
28 nsMenuFrame
* menu
= do_QueryFrame(GetPrimaryFrame(FlushType::Frames
));
31 menu
->GetActiveChild(getter_AddRefs(el
));
37 void XULMenuElement::SetActiveChild(Element
* arg
) {
38 nsMenuFrame
* menu
= do_QueryFrame(GetPrimaryFrame(FlushType::Frames
));
40 menu
->SetActiveChild(arg
);
44 bool XULMenuElement::HandleKeyPress(KeyboardEvent
& keyEvent
) {
45 nsXULPopupManager
* pm
= nsXULPopupManager::GetInstance();
50 // if event has already been handled, bail
51 if (keyEvent
.DefaultPrevented()) {
55 if (nsMenuBarListener::IsAccessKeyPressed(&keyEvent
)) return false;
57 nsMenuFrame
* menu
= do_QueryFrame(GetPrimaryFrame(FlushType::Frames
));
62 nsMenuPopupFrame
* popupFrame
= menu
->GetPopup();
67 uint32_t keyCode
= keyEvent
.KeyCode();
69 case KeyboardEvent_Binding::DOM_VK_UP
:
70 case KeyboardEvent_Binding::DOM_VK_DOWN
:
71 case KeyboardEvent_Binding::DOM_VK_HOME
:
72 case KeyboardEvent_Binding::DOM_VK_END
: {
73 nsNavigationDirection theDirection
;
74 theDirection
= NS_DIRECTION_FROM_KEY_CODE(popupFrame
, keyCode
);
75 return pm
->HandleKeyboardNavigationInPopup(popupFrame
, theDirection
);
78 return pm
->HandleShortcutNavigation(&keyEvent
, popupFrame
);
82 bool XULMenuElement::OpenedWithKey() {
83 nsMenuFrame
* menuframe
= do_QueryFrame(GetPrimaryFrame(FlushType::Frames
));
88 nsIFrame
* frame
= menuframe
->GetParent();
90 nsMenuBarFrame
* menubar
= do_QueryFrame(frame
);
92 return menubar
->IsActiveByKeyboard();
94 frame
= frame
->GetParent();
100 } // namespace mozilla