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 "nsMenuBarListener.h"
|
|
|
|
#include "nsMenuBarFrame.h"
|
2007-07-04 08:49:38 -07:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2012-08-04 00:44:00 -07:00
|
|
|
#include "nsIDOMEvent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMKeyEvent.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 04:21:19 -07:00
|
|
|
#include "mozilla/TextEvents.h"
|
2011-05-24 23:31:59 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* nsMenuBarListener implementation
|
|
|
|
*/
|
|
|
|
|
2011-06-30 14:20:02 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsMenuBarListener, nsIDOMEventListener)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define MODIFIER_SHIFT 1
|
|
|
|
#define MODIFIER_CONTROL 2
|
|
|
|
#define MODIFIER_ALT 4
|
|
|
|
#define MODIFIER_META 8
|
2012-07-18 18:28:16 -07:00
|
|
|
#define MODIFIER_OS 16
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nsMenuBarListener::mAccessKey = -1;
|
|
|
|
uint32_t nsMenuBarListener::mAccessKeyMask = 0;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool nsMenuBarListener::mAccessKeyFocuses = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsMenuBarListener::nsMenuBarListener(nsMenuBarFrame* aMenuBar)
|
2011-10-17 07:59:28 -07:00
|
|
|
:mAccessKeyDown(false), mAccessKeyDownCanceled(false)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mMenuBarFrame = aMenuBar;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsMenuBarListener::~nsMenuBarListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-18 09:07:27 -08:00
|
|
|
void
|
|
|
|
nsMenuBarListener::InitializeStatics()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&mAccessKeyFocuses,
|
|
|
|
"ui.key.menuAccessKeyFocuses");
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(int32_t* aAccessKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!aAccessKey)
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
InitAccessKey();
|
|
|
|
*aAccessKey = mAccessKey;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsMenuBarListener::InitAccessKey()
|
|
|
|
{
|
|
|
|
if (mAccessKey >= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Compiled-in defaults, in case we can't get LookAndFeel --
|
|
|
|
// mac doesn't have menu shortcuts, other platforms use alt.
|
2007-10-01 16:20:37 -07:00
|
|
|
#ifdef XP_MACOSX
|
2007-03-22 10:30:00 -07:00
|
|
|
mAccessKey = 0;
|
|
|
|
mAccessKeyMask = 0;
|
2007-10-01 16:20:37 -07:00
|
|
|
#else
|
|
|
|
mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
|
|
|
|
mAccessKeyMask = MODIFIER_ALT;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Get the menu access key value from prefs, overriding the default:
|
2011-05-24 23:32:00 -07:00
|
|
|
mAccessKey = Preferences::GetInt("ui.key.menuAccessKey", mAccessKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mAccessKey == nsIDOMKeyEvent::DOM_VK_SHIFT)
|
|
|
|
mAccessKeyMask = MODIFIER_SHIFT;
|
|
|
|
else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_CONTROL)
|
|
|
|
mAccessKeyMask = MODIFIER_CONTROL;
|
|
|
|
else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_ALT)
|
|
|
|
mAccessKeyMask = MODIFIER_ALT;
|
|
|
|
else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_META)
|
|
|
|
mAccessKeyMask = MODIFIER_META;
|
2012-07-18 18:28:16 -07:00
|
|
|
else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_WIN)
|
|
|
|
mAccessKeyMask = MODIFIER_OS;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
void
|
|
|
|
nsMenuBarListener::ToggleMenuActiveState()
|
|
|
|
{
|
|
|
|
nsMenuFrame* closemenu = mMenuBarFrame->ToggleMenuActiveState();
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && closemenu) {
|
|
|
|
nsMenuPopupFrame* popupFrame = closemenu->GetPopup();
|
|
|
|
if (popupFrame)
|
2014-04-08 05:45:52 -07:00
|
|
|
pm->HidePopup(popupFrame->GetContent(), false, false, true, false);
|
2007-07-04 08:49:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
2011-09-12 11:00:59 -07:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
|
|
|
if (!keyEvent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
InitAccessKey();
|
|
|
|
|
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 00:44:00 -07:00
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-04 00:44:00 -07:00
|
|
|
if (!trustedEvent) {
|
2012-08-04 10:05:15 -07:00
|
|
|
return NS_OK;
|
2012-08-04 00:44:00 -07:00
|
|
|
}
|
2012-08-04 10:05:15 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mAccessKey && mAccessKeyFocuses)
|
|
|
|
{
|
2012-05-09 16:25:48 -07:00
|
|
|
bool defaultPrevented = false;
|
|
|
|
aKeyEvent->GetDefaultPrevented(&defaultPrevented);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// On a press of the ALT key by itself, we toggle the menu's
|
|
|
|
// active/inactive state.
|
|
|
|
// Get the ascii key code.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t theChar;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->GetKeyCode(&theChar);
|
|
|
|
|
2012-05-09 16:25:48 -07:00
|
|
|
if (!defaultPrevented && mAccessKeyDown && !mAccessKeyDownCanceled &&
|
2012-08-22 08:56:38 -07:00
|
|
|
(int32_t)theChar == mAccessKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// The access key was down and is now up, and no other
|
|
|
|
// keys were pressed in between.
|
2011-01-04 09:24:51 -08:00
|
|
|
if (!mMenuBarFrame->IsActive()) {
|
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
ToggleMenuActiveState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
mAccessKeyDown = false;
|
|
|
|
mAccessKeyDownCanceled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool active = mMenuBarFrame->IsActive();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (active) {
|
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
aKeyEvent->PreventDefault();
|
2007-07-04 08:49:38 -07:00
|
|
|
return NS_OK; // I am consuming event
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
// if event has already been handled, bail
|
2012-08-04 00:44:00 -07:00
|
|
|
if (aKeyEvent) {
|
2011-09-28 23:19:26 -07:00
|
|
|
bool eventHandled = false;
|
2013-05-25 14:05:36 -07:00
|
|
|
aKeyEvent->GetDefaultPrevented(&eventHandled);
|
2011-08-26 00:43:49 -07:00
|
|
|
if (eventHandled) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; // don't consume event
|
2011-08-26 00:43:49 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 00:44:00 -07:00
|
|
|
if (aKeyEvent) {
|
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!trustedEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult retVal = NS_OK; // default is to not consume event
|
|
|
|
|
|
|
|
InitAccessKey();
|
|
|
|
|
|
|
|
if (mAccessKey)
|
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool preventDefault;
|
2013-05-25 14:05:36 -07:00
|
|
|
aKeyEvent->GetDefaultPrevented(&preventDefault);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!preventDefault) {
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t keyCode, charCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->GetKeyCode(&keyCode);
|
|
|
|
keyEvent->GetCharCode(&charCode);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool hasAccessKeyCandidates = charCode != 0;
|
2008-04-14 21:16:24 -07:00
|
|
|
if (!hasAccessKeyCandidates) {
|
2013-10-01 00:22:58 -07:00
|
|
|
WidgetKeyboardEvent* nativeKeyEvent =
|
2013-10-17 23:10:24 -07:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
2008-04-14 21:16:24 -07:00
|
|
|
if (nativeKeyEvent) {
|
2012-08-22 08:56:38 -07:00
|
|
|
nsAutoTArray<uint32_t, 10> keys;
|
2008-04-14 21:16:24 -07:00
|
|
|
nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, keys);
|
|
|
|
hasAccessKeyCandidates = !keys.IsEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-03 17:55:15 -08:00
|
|
|
// Cancel the access key flag unless we are pressing the access key.
|
2012-08-22 08:56:38 -07:00
|
|
|
if (keyCode != (uint32_t)mAccessKey) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mAccessKeyDownCanceled = true;
|
2010-12-03 17:55:15 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-04-14 21:16:24 -07:00
|
|
|
if (IsAccessKeyPressed(keyEvent) && hasAccessKeyCandidates) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do shortcut navigation.
|
|
|
|
// A letter was pressed. We want to see if a shortcut gets matched. If
|
|
|
|
// so, we'll know the menu got activated.
|
2007-07-04 08:49:38 -07:00
|
|
|
nsMenuFrame* result = mMenuBarFrame->FindMenuWithShortcut(keyEvent);
|
|
|
|
if (result) {
|
2011-01-04 09:24:51 -08:00
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
2011-10-17 07:59:28 -07:00
|
|
|
mMenuBarFrame->SetActive(true);
|
|
|
|
result->OpenMenu(true);
|
2010-12-08 02:49:09 -08:00
|
|
|
|
|
|
|
// The opened menu will listen next keyup event.
|
|
|
|
// Therefore, we should clear the keydown flags here.
|
2011-10-17 07:59:28 -07:00
|
|
|
mAccessKeyDown = mAccessKeyDownCanceled = false;
|
2010-12-08 02:49:09 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
aKeyEvent->PreventDefault();
|
2007-07-04 08:49:38 -07:00
|
|
|
retVal = NS_OK; // I am consuming event
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-10-01 16:20:37 -07:00
|
|
|
#ifndef XP_MACOSX
|
2007-03-22 10:30:00 -07:00
|
|
|
// Also need to handle F10 specially on Non-Mac platform.
|
|
|
|
else if (keyCode == NS_VK_F10) {
|
|
|
|
if ((GetModifiers(keyEvent) & ~MODIFIER_CONTROL) == 0) {
|
|
|
|
// The F10 key just went down by itself or with ctrl pressed.
|
|
|
|
// In Windows, both of these activate the menu bar.
|
2011-01-04 09:24:51 -08:00
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
2007-07-04 08:49:38 -07:00
|
|
|
ToggleMenuActiveState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-05-30 00:33:20 -07:00
|
|
|
if (mMenuBarFrame->IsActive()) {
|
2014-01-16 11:31:12 -08:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
// In GTK, this also opens the first menu.
|
|
|
|
mMenuBarFrame->GetCurrentMenuItem()->OpenMenu(true);
|
|
|
|
#endif
|
2012-05-30 00:33:20 -07:00
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
return NS_OK; // consume the event
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-10-01 16:20:37 -07:00
|
|
|
#endif // !XP_MACOSX
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 08:49:38 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarListener::IsAccessKeyPressed(nsIDOMKeyEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
InitAccessKey();
|
|
|
|
// No other modifiers are allowed to be down except for Shift.
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t modifiers = GetModifiers(aKeyEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return (mAccessKeyMask != MODIFIER_SHIFT &&
|
|
|
|
(modifiers & mAccessKeyMask) &&
|
|
|
|
(modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMenuBarListener::GetModifiers(nsIDOMKeyEvent* aKeyEvent)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t modifiers = 0;
|
2013-10-01 00:23:02 -07:00
|
|
|
WidgetInputEvent* inputEvent =
|
2013-10-17 23:10:26 -07:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsInputEvent();
|
2012-07-18 18:28:16 -07:00
|
|
|
MOZ_ASSERT(inputEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-18 18:28:16 -07:00
|
|
|
if (inputEvent->IsShift()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
modifiers |= MODIFIER_SHIFT;
|
2012-07-18 18:28:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-18 18:28:16 -07:00
|
|
|
if (inputEvent->IsControl()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
modifiers |= MODIFIER_CONTROL;
|
2012-07-18 18:28:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-18 18:28:16 -07:00
|
|
|
if (inputEvent->IsAlt()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
modifiers |= MODIFIER_ALT;
|
2012-07-18 18:28:16 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-18 18:28:16 -07:00
|
|
|
if (inputEvent->IsMeta()) {
|
2007-03-22 10:30:00 -07:00
|
|
|
modifiers |= MODIFIER_META;
|
2012-07-18 18:28:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (inputEvent->IsOS()) {
|
|
|
|
modifiers |= MODIFIER_OS;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return modifiers;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
InitAccessKey();
|
|
|
|
|
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 00:44:00 -07:00
|
|
|
if (aKeyEvent) {
|
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!trustedEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (mAccessKey && mAccessKeyFocuses)
|
|
|
|
{
|
2012-05-09 16:25:48 -07:00
|
|
|
bool defaultPrevented = false;
|
|
|
|
aKeyEvent->GetDefaultPrevented(&defaultPrevented);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t theChar;
|
2007-03-22 10:30:00 -07:00
|
|
|
keyEvent->GetKeyCode(&theChar);
|
|
|
|
|
2012-02-13 16:56:03 -08:00
|
|
|
// No other modifiers can be down.
|
|
|
|
// Especially CTRL. CTRL+ALT == AltGR, and we'll fuck up on non-US
|
|
|
|
// enhanced 102-key keyboards if we don't check this.
|
|
|
|
bool isAccessKeyDownEvent =
|
2012-08-22 08:56:38 -07:00
|
|
|
((theChar == (uint32_t)mAccessKey) &&
|
2012-02-13 16:56:03 -08:00
|
|
|
(GetModifiers(keyEvent) & ~mAccessKeyMask) == 0);
|
|
|
|
|
|
|
|
if (!mAccessKeyDown) {
|
|
|
|
// If accesskey isn't being pressed and the key isn't the accesskey,
|
|
|
|
// ignore the event.
|
|
|
|
if (!isAccessKeyDownEvent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, accept the accesskey state.
|
2011-10-17 07:59:28 -07:00
|
|
|
mAccessKeyDown = true;
|
2012-05-09 16:25:48 -07:00
|
|
|
// If default is prevented already, cancel the access key down.
|
|
|
|
mAccessKeyDownCanceled = defaultPrevented;
|
2012-02-13 16:56:03 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-05-09 16:25:48 -07:00
|
|
|
// If the pressed accesskey was canceled already or the event was
|
|
|
|
// consumed already, ignore the event.
|
|
|
|
if (mAccessKeyDownCanceled || defaultPrevented) {
|
2012-02-13 16:56:03 -08:00
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-13 16:56:03 -08:00
|
|
|
|
|
|
|
// Some key other than the access key just went down,
|
|
|
|
// so we won't activate the menu bar when the access key is released.
|
|
|
|
mAccessKeyDownCanceled = !isAccessKeyDownEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::Blur(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!mMenuBarFrame->IsMenuOpen() && mMenuBarFrame->IsActive()) {
|
|
|
|
ToggleMenuActiveState();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-02-13 16:56:03 -08:00
|
|
|
// Reset the accesskey state because we cannot receive the keyup event for
|
|
|
|
// the pressing accesskey.
|
|
|
|
mAccessKeyDown = false;
|
|
|
|
mAccessKeyDownCanceled = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2010-12-03 17:55:15 -08:00
|
|
|
// NOTE: MouseDown method listens all phases
|
|
|
|
|
|
|
|
// Even if the mousedown event is canceled, it means the user don't want
|
|
|
|
// to activate the menu. Therefore, we need to record it at capturing (or
|
|
|
|
// target) phase.
|
|
|
|
if (mAccessKeyDown) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mAccessKeyDownCanceled = true;
|
2010-12-03 17:55:15 -08:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint16_t phase = 0;
|
2010-12-03 17:55:15 -08:00
|
|
|
nsresult rv = aMouseEvent->GetEventPhase(&phase);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Don't do anything at capturing phase, any behavior should be cancelable.
|
|
|
|
if (phase == nsIDOMEvent::CAPTURING_PHASE) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-07-04 08:49:38 -07:00
|
|
|
if (!mMenuBarFrame->IsMenuOpen() && mMenuBarFrame->IsActive())
|
|
|
|
ToggleMenuActiveState();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2011-06-30 14:20:02 -07:00
|
|
|
nsAutoString eventType;
|
|
|
|
aEvent->GetType(eventType);
|
|
|
|
|
|
|
|
if (eventType.EqualsLiteral("keyup")) {
|
|
|
|
return KeyUp(aEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("keydown")) {
|
|
|
|
return KeyDown(aEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("keypress")) {
|
|
|
|
return KeyPress(aEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("blur")) {
|
|
|
|
return Blur(aEvent);
|
|
|
|
}
|
|
|
|
if (eventType.EqualsLiteral("mousedown")) {
|
|
|
|
return MouseDown(aEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ABORT();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|