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