2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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/. */
|
2004-07-03 21:00:07 +00:00
|
|
|
#include "nsISupportsUtils.h"
|
2000-05-30 07:59:13 +00:00
|
|
|
#include "nsIMenuBoxObject.h"
|
|
|
|
#include "nsBoxObject.h"
|
2013-09-25 11:21:19 +00:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
2000-05-30 07:59:13 +00:00
|
|
|
#include "nsIFrame.h"
|
2011-01-04 17:24:51 +00:00
|
|
|
#include "nsMenuBarFrame.h"
|
2004-08-09 22:22:02 +00:00
|
|
|
#include "nsMenuBarListener.h"
|
2007-07-04 15:49:38 +00:00
|
|
|
#include "nsMenuFrame.h"
|
|
|
|
#include "nsMenuPopupFrame.h"
|
2000-05-30 07:59:13 +00:00
|
|
|
|
2011-01-17 14:36:33 +00:00
|
|
|
class nsMenuBoxObject : public nsIMenuBoxObject,
|
2011-03-25 15:03:35 +00:00
|
|
|
public nsBoxObject
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
|
|
|
public:
|
2007-08-07 15:18:36 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2000-05-30 07:59:13 +00:00
|
|
|
NS_DECL_NSIMENUBOXOBJECT
|
|
|
|
|
|
|
|
nsMenuBoxObject();
|
|
|
|
virtual ~nsMenuBoxObject();
|
|
|
|
};
|
|
|
|
|
|
|
|
nsMenuBoxObject::nsMenuBoxObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuBoxObject::~nsMenuBoxObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsMenuBoxObject, nsBoxObject, nsIMenuBoxObject)
|
2007-08-07 15:18:36 +00:00
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
/* void openMenu (in boolean openFlag); */
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsMenuBoxObject::OpenMenu(bool aOpenFlag)
|
2000-05-30 07:59:13 +00:00
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
2011-10-17 14:59:28 +00:00
|
|
|
nsIFrame* frame = GetFrame(false);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (frame) {
|
|
|
|
if (aOpenFlag) {
|
|
|
|
nsCOMPtr<nsIContent> content = mContent;
|
2011-10-17 14:59:28 +00:00
|
|
|
pm->ShowMenu(content, false, false);
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
else {
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(frame);
|
|
|
|
if (menu) {
|
|
|
|
nsMenuPopupFrame* popupFrame = menu->GetPopup();
|
2007-07-04 15:49:38 +00:00
|
|
|
if (popupFrame)
|
2014-04-08 12:45:52 +00:00
|
|
|
pm->HidePopup(popupFrame->GetContent(), false, true, false, false);
|
2007-07-04 15:49:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-06-29 22:15:59 +00:00
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
return NS_OK;
|
2000-05-30 07:59:13 +00:00
|
|
|
}
|
|
|
|
|
2000-08-17 09:15:51 +00:00
|
|
|
NS_IMETHODIMP nsMenuBoxObject::GetActiveChild(nsIDOMElement** aResult)
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetFrame(false));
|
|
|
|
if (menu)
|
|
|
|
return menu->GetActiveChild(aResult);
|
2004-07-26 10:14:10 +00:00
|
|
|
return NS_OK;
|
2000-08-17 09:15:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMenuBoxObject::SetActiveChild(nsIDOMElement* aResult)
|
|
|
|
{
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetFrame(false));
|
|
|
|
if (menu)
|
|
|
|
return menu->SetActiveChild(aResult);
|
2004-07-26 10:14:10 +00:00
|
|
|
return NS_OK;
|
2000-08-17 09:15:51 +00:00
|
|
|
}
|
2000-05-30 07:59:13 +00:00
|
|
|
|
2004-07-03 21:00:07 +00:00
|
|
|
/* boolean handleKeyPress (in nsIDOMKeyEvent keyEvent); */
|
2011-09-29 06:19:26 +00:00
|
|
|
NS_IMETHODIMP nsMenuBoxObject::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent, bool* aHandledFlag)
|
2004-07-03 21:00:07 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aHandledFlag = false;
|
2004-07-03 21:00:07 +00:00
|
|
|
NS_ENSURE_ARG(aKeyEvent);
|
|
|
|
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (!pm)
|
|
|
|
return NS_OK;
|
|
|
|
|
2004-08-09 22:22:02 +00:00
|
|
|
// if event has already been handled, bail
|
2011-09-29 06:19:26 +00:00
|
|
|
bool eventHandled = false;
|
2013-05-25 21:05:36 +00:00
|
|
|
aKeyEvent->GetDefaultPrevented(&eventHandled);
|
2004-08-09 22:22:02 +00:00
|
|
|
if (eventHandled)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (nsMenuBarListener::IsAccessKeyPressed(aKeyEvent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuFrame* menu = do_QueryFrame(GetFrame(false));
|
|
|
|
if (!menu)
|
2004-07-03 21:00:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuPopupFrame* popupFrame = menu->GetPopup();
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!popupFrame)
|
2004-07-03 21:00:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t keyCode;
|
2004-07-03 21:00:07 +00:00
|
|
|
aKeyEvent->GetKeyCode(&keyCode);
|
|
|
|
switch (keyCode) {
|
2013-09-25 11:21:19 +00:00
|
|
|
case nsIDOMKeyEvent::DOM_VK_UP:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_DOWN:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_HOME:
|
|
|
|
case nsIDOMKeyEvent::DOM_VK_END:
|
2007-07-23 17:08:10 +00:00
|
|
|
{
|
|
|
|
nsNavigationDirection theDirection;
|
2008-12-30 13:30:51 +00:00
|
|
|
theDirection = NS_DIRECTION_FROM_KEY_CODE(popupFrame, keyCode);
|
2007-07-23 17:08:10 +00:00
|
|
|
*aHandledFlag =
|
|
|
|
pm->HandleKeyboardNavigationInPopup(popupFrame, theDirection);
|
2007-07-04 15:49:38 +00:00
|
|
|
return NS_OK;
|
2007-07-23 17:08:10 +00:00
|
|
|
}
|
2004-07-03 21:00:07 +00:00
|
|
|
default:
|
2007-07-23 17:08:10 +00:00
|
|
|
*aHandledFlag = pm->HandleShortcutNavigation(aKeyEvent, popupFrame);
|
2007-07-04 15:49:38 +00:00
|
|
|
return NS_OK;
|
2004-07-03 21:00:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-04 17:24:51 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsMenuBoxObject::GetOpenedWithKey(bool* aOpenedWithKey)
|
2011-01-04 17:24:51 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*aOpenedWithKey = false;
|
2011-01-04 17:24:51 +00:00
|
|
|
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuFrame* menuframe = do_QueryFrame(GetFrame(false));
|
|
|
|
if (!menuframe)
|
2011-01-04 17:24:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-07-31 00:43:28 +00:00
|
|
|
nsIFrame* frame = menuframe->GetParent();
|
2011-01-04 17:24:51 +00:00
|
|
|
while (frame) {
|
2012-07-31 00:43:28 +00:00
|
|
|
nsMenuBarFrame* menubar = do_QueryFrame(frame);
|
|
|
|
if (menubar) {
|
|
|
|
*aOpenedWithKey = menubar->IsActiveByKeyboard();
|
2011-01-04 17:24:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
frame = frame->GetParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
// Creation Routine ///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewMenuBoxObject(nsIBoxObject** aResult)
|
|
|
|
{
|
|
|
|
*aResult = new nsMenuBoxObject;
|
|
|
|
if (!*aResult)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|