2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:30:37 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-18 14:30:37 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
2004-04-18 14:30:37 +00:00
|
|
|
* Original Author: David W. Hyatt (hyatt@netscape.com)
|
2000-05-30 07:59:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:30:37 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-28 20:14:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:30:37 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:30:37 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
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"
|
|
|
|
#include "nsIFrame.h"
|
2004-07-03 21:00:07 +00:00
|
|
|
#include "nsGUIEvent.h"
|
2004-08-09 22:22:02 +00:00
|
|
|
#include "nsIDOMNSUIEvent.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,
|
|
|
|
public nsBoxObject,
|
|
|
|
public nsIMenuBoxObject_MOZILLA_2_0_BRANCH
|
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
|
2011-01-17 14:36:33 +00:00
|
|
|
NS_DECL_NSIMENUBOXOBJECT_MOZILLA_2_0_BRANCH
|
2000-05-30 07:59:13 +00:00
|
|
|
|
|
|
|
nsMenuBoxObject();
|
|
|
|
virtual ~nsMenuBoxObject();
|
|
|
|
};
|
|
|
|
|
|
|
|
nsMenuBoxObject::nsMenuBoxObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMenuBoxObject::~nsMenuBoxObject()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-17 14:36:33 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED2(nsMenuBoxObject, nsBoxObject, nsIMenuBoxObject, nsIMenuBoxObject_MOZILLA_2_0_BRANCH)
|
2007-08-07 15:18:36 +00:00
|
|
|
|
2000-05-30 07:59:13 +00:00
|
|
|
/* void openMenu (in boolean openFlag); */
|
|
|
|
NS_IMETHODIMP nsMenuBoxObject::OpenMenu(PRBool aOpenFlag)
|
|
|
|
{
|
2007-07-04 15:49:38 +00:00
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
|
|
|
if (frame) {
|
|
|
|
if (aOpenFlag) {
|
|
|
|
nsCOMPtr<nsIContent> content = mContent;
|
|
|
|
pm->ShowMenu(content, PR_FALSE, PR_FALSE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (frame->GetType() == nsGkAtoms::menuFrame) {
|
2007-07-08 07:08:04 +00:00
|
|
|
nsMenuPopupFrame* popupFrame = (static_cast<nsMenuFrame *>(frame))->GetPopup();
|
2007-07-04 15:49:38 +00:00
|
|
|
if (popupFrame)
|
|
|
|
pm->HidePopup(popupFrame->GetContent(), PR_FALSE, PR_TRUE, PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2004-07-26 10:14:10 +00:00
|
|
|
*aResult = nsnull;
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (frame && frame->GetType() == nsGkAtoms::menuFrame)
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsMenuFrame *>(frame)->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)
|
|
|
|
{
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (frame && frame->GetType() == nsGkAtoms::menuFrame)
|
2007-07-08 07:08:04 +00:00
|
|
|
return static_cast<nsMenuFrame *>(frame)->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); */
|
|
|
|
NS_IMETHODIMP nsMenuBoxObject::HandleKeyPress(nsIDOMKeyEvent* aKeyEvent, PRBool* aHandledFlag)
|
|
|
|
{
|
|
|
|
*aHandledFlag = PR_FALSE;
|
|
|
|
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
|
|
|
|
nsCOMPtr<nsIDOMNSUIEvent> uiEvent(do_QueryInterface(aKeyEvent));
|
|
|
|
if (!uiEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRBool eventHandled = PR_FALSE;
|
|
|
|
uiEvent->GetPreventDefault(&eventHandled);
|
|
|
|
if (eventHandled)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (nsMenuBarListener::IsAccessKeyPressed(aKeyEvent))
|
|
|
|
return NS_OK;
|
|
|
|
|
2006-03-07 03:20:39 +00:00
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!frame || frame->GetType() != nsGkAtoms::menuFrame)
|
2004-07-03 21:00:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2007-07-08 07:08:04 +00:00
|
|
|
nsMenuPopupFrame* popupFrame = static_cast<nsMenuFrame *>(frame)->GetPopup();
|
2007-07-04 15:49:38 +00:00
|
|
|
if (!popupFrame)
|
2004-07-03 21:00:07 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 keyCode;
|
|
|
|
aKeyEvent->GetKeyCode(&keyCode);
|
|
|
|
switch (keyCode) {
|
|
|
|
case NS_VK_UP:
|
|
|
|
case NS_VK_DOWN:
|
|
|
|
case NS_VK_HOME:
|
|
|
|
case NS_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
|
|
|
|
nsMenuBoxObject::GetOpenedWithKey(PRBool* aOpenedWithKey)
|
|
|
|
{
|
|
|
|
*aOpenedWithKey = PR_FALSE;
|
|
|
|
|
|
|
|
nsIFrame* frame = GetFrame(PR_FALSE);
|
|
|
|
if (!frame || frame->GetType() != nsGkAtoms::menuFrame)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
frame = frame->GetParent();
|
|
|
|
while (frame) {
|
|
|
|
if (frame->GetType() == nsGkAtoms::menuBarFrame) {
|
|
|
|
*aOpenedWithKey = (static_cast<nsMenuBarFrame *>(frame))->IsActiveByKeyboard();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|