2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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/. */
|
1999-07-18 11:27:02 +04:00
|
|
|
|
|
|
|
#include "nsMenuBarListener.h"
|
|
|
|
#include "nsMenuBarFrame.h"
|
2007-07-04 19:49:38 +04:00
|
|
|
#include "nsMenuPopupFrame.h"
|
2012-08-04 11:44:00 +04:00
|
|
|
#include "nsIDOMEvent.h"
|
1999-07-18 11:27:02 +04:00
|
|
|
|
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1999-11-03 10:11:45 +03:00
|
|
|
#include "nsIDOMKeyEvent.h"
|
1999-07-18 11:27:02 +04:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
|
2004-04-30 03:34:19 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-05-22 08:06:06 +04:00
|
|
|
#include "mozilla/BasicEvents.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-09-25 15:21:19 +04:00
|
|
|
#include "mozilla/TextEvents.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2000-08-17 04:09:16 +04:00
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
/*
|
|
|
|
* nsMenuBarListener implementation
|
|
|
|
*/
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsMenuBarListener, nsIDOMEventListener)
|
1999-07-18 11:27:02 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-10-09 00:41:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsMenuBarListener::mAccessKey = -1;
|
2014-05-22 08:06:06 +04:00
|
|
|
Modifiers nsMenuBarListener::mAccessKeyMask = 0;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsMenuBarListener::mAccessKeyFocuses = false;
|
2000-08-25 03:39:39 +04:00
|
|
|
|
1999-07-19 06:02:38 +04:00
|
|
|
nsMenuBarListener::nsMenuBarListener(nsMenuBarFrame* aMenuBar)
|
2011-10-17 18:59:28 +04:00
|
|
|
:mAccessKeyDown(false), mAccessKeyDownCanceled(false)
|
1999-07-18 11:27:02 +04:00
|
|
|
{
|
1999-07-19 06:02:38 +04:00
|
|
|
mMenuBarFrame = aMenuBar;
|
1999-07-18 11:27:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsMenuBarListener::~nsMenuBarListener()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-05-15 14:42:14 +03:00
|
|
|
void
|
|
|
|
nsMenuBarListener::OnDestroyMenuBarFrame()
|
|
|
|
{
|
|
|
|
mMenuBarFrame = nullptr;
|
|
|
|
}
|
|
|
|
|
2014-02-18 21:07:27 +04:00
|
|
|
void
|
|
|
|
nsMenuBarListener::InitializeStatics()
|
|
|
|
{
|
|
|
|
Preferences::AddBoolVarCache(&mAccessKeyFocuses,
|
|
|
|
"ui.key.menuAccessKeyFocuses");
|
|
|
|
}
|
|
|
|
|
2000-08-25 04:46:16 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMenuBarListener::GetMenuAccessKey(int32_t* aAccessKey)
|
2000-08-25 03:39:39 +04:00
|
|
|
{
|
|
|
|
if (!aAccessKey)
|
|
|
|
return NS_ERROR_INVALID_POINTER;
|
|
|
|
InitAccessKey();
|
|
|
|
*aAccessKey = mAccessKey;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
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-02 03:20:37 +04:00
|
|
|
#ifdef XP_MACOSX
|
2000-08-17 04:09:16 +04:00
|
|
|
mAccessKey = 0;
|
2004-08-19 12:04:11 +04:00
|
|
|
mAccessKeyMask = 0;
|
2007-10-02 03:20:37 +04:00
|
|
|
#else
|
|
|
|
mAccessKey = nsIDOMKeyEvent::DOM_VK_ALT;
|
|
|
|
mAccessKeyMask = MODIFIER_ALT;
|
2000-08-17 04:09:16 +04:00
|
|
|
#endif
|
1999-07-18 11:27:02 +04:00
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
// Get the menu access key value from prefs, overriding the default:
|
2011-05-25 10:32:00 +04:00
|
|
|
mAccessKey = Preferences::GetInt("ui.key.menuAccessKey", mAccessKey);
|
2004-08-19 12:04:11 +04: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-19 05:28:16 +04:00
|
|
|
else if (mAccessKey == nsIDOMKeyEvent::DOM_VK_WIN)
|
|
|
|
mAccessKeyMask = MODIFIER_OS;
|
2000-08-17 04:09:16 +04:00
|
|
|
}
|
1999-07-18 11:27:02 +04:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
void
|
|
|
|
nsMenuBarListener::ToggleMenuActiveState()
|
|
|
|
{
|
|
|
|
nsMenuFrame* closemenu = mMenuBarFrame->ToggleMenuActiveState();
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm && closemenu) {
|
|
|
|
nsMenuPopupFrame* popupFrame = closemenu->GetPopup();
|
|
|
|
if (popupFrame)
|
2014-04-08 16:45:52 +04:00
|
|
|
pm->HidePopup(popupFrame->GetContent(), false, false, true, false);
|
2007-07-04 19:49:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
1999-07-19 12:09:30 +04:00
|
|
|
nsMenuBarListener::KeyUp(nsIDOMEvent* aKeyEvent)
|
|
|
|
{
|
2011-09-12 22:00:59 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
|
|
|
if (!keyEvent) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
InitAccessKey();
|
|
|
|
|
2002-03-27 09:29:39 +03:00
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 11:44:00 +04:00
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2004-09-02 19:25:39 +04:00
|
|
|
|
2012-08-04 11:44:00 +04:00
|
|
|
if (!trustedEvent) {
|
2012-08-04 21:05:15 +04:00
|
|
|
return NS_OK;
|
2012-08-04 11:44:00 +04:00
|
|
|
}
|
2012-08-04 21:05:15 +04:00
|
|
|
|
2000-08-24 04:05:40 +04:00
|
|
|
if (mAccessKey && mAccessKeyFocuses)
|
2000-08-17 04:09:16 +04:00
|
|
|
{
|
2012-05-10 03:25:48 +04:00
|
|
|
bool defaultPrevented = false;
|
|
|
|
aKeyEvent->GetDefaultPrevented(&defaultPrevented);
|
|
|
|
|
2000-08-17 04:09:16 +04: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 19:56:38 +04:00
|
|
|
uint32_t theChar;
|
2000-08-17 04:09:16 +04:00
|
|
|
keyEvent->GetKeyCode(&theChar);
|
|
|
|
|
2012-05-10 03:25:48 +04:00
|
|
|
if (!defaultPrevented && mAccessKeyDown && !mAccessKeyDownCanceled &&
|
2012-08-22 19:56:38 +04:00
|
|
|
(int32_t)theChar == mAccessKey)
|
2000-08-17 04:09:16 +04:00
|
|
|
{
|
2001-07-25 06:37:11 +04:00
|
|
|
// The access key was down and is now up, and no other
|
|
|
|
// keys were pressed in between.
|
2015-05-15 14:42:14 +03:00
|
|
|
bool toggleMenuActiveState = true;
|
2011-01-04 20:24:51 +03:00
|
|
|
if (!mMenuBarFrame->IsActive()) {
|
2015-05-15 14:42:14 +03:00
|
|
|
// First, close all existing popups because other popups shouldn't
|
|
|
|
// handle key events when menubar is active and IME should be
|
|
|
|
// disabled.
|
|
|
|
nsXULPopupManager* pm = nsXULPopupManager::GetInstance();
|
|
|
|
if (pm) {
|
|
|
|
pm->Rollup(0, false, nullptr, nullptr);
|
|
|
|
}
|
|
|
|
// If menubar active state is changed or the menubar is destroyed
|
|
|
|
// during closing the popups, we should do nothing anymore.
|
|
|
|
toggleMenuActiveState = !Destroyed() && !mMenuBarFrame->IsActive();
|
|
|
|
}
|
|
|
|
if (toggleMenuActiveState) {
|
|
|
|
if (!mMenuBarFrame->IsActive()) {
|
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
|
|
|
}
|
|
|
|
ToggleMenuActiveState();
|
2011-01-04 20:24:51 +03:00
|
|
|
}
|
2000-08-17 04:09:16 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mAccessKeyDown = false;
|
|
|
|
mAccessKeyDownCanceled = false;
|
2000-02-08 04:02:47 +03:00
|
|
|
|
2015-05-15 14:42:14 +03:00
|
|
|
bool active = !Destroyed() && mMenuBarFrame->IsActive();
|
2000-08-17 04:09:16 +04:00
|
|
|
if (active) {
|
2006-03-26 01:03:49 +03:00
|
|
|
aKeyEvent->StopPropagation();
|
2000-08-17 04:09:16 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
2007-07-04 19:49:38 +04:00
|
|
|
return NS_OK; // I am consuming event
|
2000-08-17 04:09:16 +04:00
|
|
|
}
|
|
|
|
}
|
2000-02-09 12:34:35 +03:00
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
2000-02-18 13:05:14 +03:00
|
|
|
nsMenuBarListener::KeyPress(nsIDOMEvent* aKeyEvent)
|
1999-07-19 12:09:30 +04:00
|
|
|
{
|
2000-09-15 02:55:19 +04:00
|
|
|
// if event has already been handled, bail
|
2012-08-04 11:44:00 +04:00
|
|
|
if (aKeyEvent) {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool eventHandled = false;
|
2013-05-26 01:05:36 +04:00
|
|
|
aKeyEvent->GetDefaultPrevented(&eventHandled);
|
2011-08-26 11:43:49 +04:00
|
|
|
if (eventHandled) {
|
2000-09-15 02:55:19 +04:00
|
|
|
return NS_OK; // don't consume event
|
2011-08-26 11:43:49 +04:00
|
|
|
}
|
2000-09-15 02:55:19 +04:00
|
|
|
}
|
|
|
|
|
2002-03-27 09:29:39 +03:00
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 11:44:00 +04:00
|
|
|
if (aKeyEvent) {
|
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2002-03-27 09:29:39 +03:00
|
|
|
}
|
|
|
|
|
2004-09-02 19:25:39 +04:00
|
|
|
if (!trustedEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2001-03-09 01:49:31 +03:00
|
|
|
nsresult retVal = NS_OK; // default is to not consume event
|
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
InitAccessKey();
|
2000-05-16 14:22:20 +04:00
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
if (mAccessKey)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool preventDefault;
|
2013-05-26 01:05:36 +04:00
|
|
|
aKeyEvent->GetDefaultPrevented(&preventDefault);
|
2000-08-17 04:09:16 +04:00
|
|
|
if (!preventDefault) {
|
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t keyCode, charCode;
|
2003-07-25 12:26:11 +04:00
|
|
|
keyEvent->GetKeyCode(&keyCode);
|
|
|
|
keyEvent->GetCharCode(&charCode);
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasAccessKeyCandidates = charCode != 0;
|
2008-04-15 08:16:24 +04:00
|
|
|
if (!hasAccessKeyCandidates) {
|
2013-10-01 11:22:58 +04:00
|
|
|
WidgetKeyboardEvent* nativeKeyEvent =
|
2013-10-18 10:10:24 +04:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsKeyboardEvent();
|
2008-04-15 08:16:24 +04:00
|
|
|
if (nativeKeyEvent) {
|
2012-08-22 19:56:38 +04:00
|
|
|
nsAutoTArray<uint32_t, 10> keys;
|
2008-04-15 08:16:24 +04:00
|
|
|
nsContentUtils::GetAccessKeyCandidates(nativeKeyEvent, keys);
|
|
|
|
hasAccessKeyCandidates = !keys.IsEmpty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-04 04:55:15 +03:00
|
|
|
// Cancel the access key flag unless we are pressing the access key.
|
2012-08-22 19:56:38 +04:00
|
|
|
if (keyCode != (uint32_t)mAccessKey) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mAccessKeyDownCanceled = true;
|
2010-12-04 04:55:15 +03:00
|
|
|
}
|
2004-02-13 17:05:57 +03:00
|
|
|
|
2008-04-15 08:16:24 +04:00
|
|
|
if (IsAccessKeyPressed(keyEvent) && hasAccessKeyCandidates) {
|
2000-08-17 04:09:16 +04: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 19:49:38 +04:00
|
|
|
nsMenuFrame* result = mMenuBarFrame->FindMenuWithShortcut(keyEvent);
|
|
|
|
if (result) {
|
2011-01-04 20:24:51 +03:00
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
2011-10-17 18:59:28 +04:00
|
|
|
mMenuBarFrame->SetActive(true);
|
|
|
|
result->OpenMenu(true);
|
2010-12-08 13:49:09 +03:00
|
|
|
|
|
|
|
// The opened menu will listen next keyup event.
|
|
|
|
// Therefore, we should clear the keydown flags here.
|
2011-10-17 18:59:28 +04:00
|
|
|
mAccessKeyDown = mAccessKeyDownCanceled = false;
|
2010-12-08 13:49:09 +03:00
|
|
|
|
2006-03-26 01:03:49 +03:00
|
|
|
aKeyEvent->StopPropagation();
|
2000-08-17 04:09:16 +04:00
|
|
|
aKeyEvent->PreventDefault();
|
2007-07-04 19:49:38 +04:00
|
|
|
retVal = NS_OK; // I am consuming event
|
2000-08-17 04:09:16 +04:00
|
|
|
}
|
|
|
|
}
|
2007-10-02 03:20:37 +04:00
|
|
|
#ifndef XP_MACOSX
|
2002-03-15 04:35:06 +03:00
|
|
|
// Also need to handle F10 specially on Non-Mac platform.
|
2003-07-25 12:26:11 +04:00
|
|
|
else if (keyCode == NS_VK_F10) {
|
2014-05-22 08:06:06 +04:00
|
|
|
if ((GetModifiersForAccessKey(keyEvent) & ~MODIFIER_CONTROL) == 0) {
|
2001-03-12 12:53:33 +03:00
|
|
|
// The F10 key just went down by itself or with ctrl pressed.
|
|
|
|
// In Windows, both of these activate the menu bar.
|
2011-01-04 20:24:51 +03:00
|
|
|
mMenuBarFrame->SetActiveByKeyboard();
|
2007-07-04 19:49:38 +04:00
|
|
|
ToggleMenuActiveState();
|
2001-03-12 12:53:33 +03:00
|
|
|
|
2012-05-30 11:33:20 +04:00
|
|
|
if (mMenuBarFrame->IsActive()) {
|
2014-01-16 23:31:12 +04:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
// In GTK, this also opens the first menu.
|
|
|
|
mMenuBarFrame->GetCurrentMenuItem()->OpenMenu(true);
|
|
|
|
#endif
|
2012-05-30 11:33:20 +04:00
|
|
|
aKeyEvent->StopPropagation();
|
|
|
|
aKeyEvent->PreventDefault();
|
|
|
|
return NS_OK; // consume the event
|
|
|
|
}
|
2001-03-12 12:53:33 +03:00
|
|
|
}
|
|
|
|
}
|
2007-10-02 03:20:37 +04:00
|
|
|
#endif // !XP_MACOSX
|
2000-08-17 04:09:16 +04:00
|
|
|
}
|
|
|
|
}
|
2007-07-04 19:49:38 +04:00
|
|
|
|
2001-03-09 01:49:31 +03:00
|
|
|
return retVal;
|
1999-07-18 11:27:02 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-08-19 13:11:15 +04:00
|
|
|
nsMenuBarListener::IsAccessKeyPressed(nsIDOMKeyEvent* aKeyEvent)
|
|
|
|
{
|
|
|
|
InitAccessKey();
|
|
|
|
// No other modifiers are allowed to be down except for Shift.
|
2014-05-22 08:06:06 +04:00
|
|
|
uint32_t modifiers = GetModifiersForAccessKey(aKeyEvent);
|
2004-08-19 13:11:15 +04:00
|
|
|
|
|
|
|
return (mAccessKeyMask != MODIFIER_SHIFT &&
|
|
|
|
(modifiers & mAccessKeyMask) &&
|
|
|
|
(modifiers & ~(mAccessKeyMask | MODIFIER_SHIFT)) == 0);
|
|
|
|
}
|
|
|
|
|
2014-05-22 08:06:06 +04:00
|
|
|
Modifiers
|
|
|
|
nsMenuBarListener::GetModifiersForAccessKey(nsIDOMKeyEvent* aKeyEvent)
|
2000-08-30 04:33:58 +04:00
|
|
|
{
|
2013-10-01 11:23:02 +04:00
|
|
|
WidgetInputEvent* inputEvent =
|
2013-10-18 10:10:26 +04:00
|
|
|
aKeyEvent->GetInternalNSEvent()->AsInputEvent();
|
2012-07-19 05:28:16 +04:00
|
|
|
MOZ_ASSERT(inputEvent);
|
2004-08-19 12:04:11 +04:00
|
|
|
|
2014-05-22 08:06:06 +04:00
|
|
|
static const Modifiers kPossibleModifiersForAccessKey =
|
|
|
|
(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_META |
|
|
|
|
MODIFIER_OS);
|
|
|
|
return (inputEvent->modifiers & kPossibleModifiersForAccessKey);
|
2000-08-30 04:33:58 +04:00
|
|
|
}
|
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
2000-02-18 13:05:14 +03:00
|
|
|
nsMenuBarListener::KeyDown(nsIDOMEvent* aKeyEvent)
|
1999-07-18 11:27:02 +04:00
|
|
|
{
|
2000-08-17 04:09:16 +04:00
|
|
|
InitAccessKey();
|
2000-02-18 13:05:14 +03:00
|
|
|
|
2002-03-27 09:29:39 +03:00
|
|
|
//handlers shouldn't be triggered by non-trusted events.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool trustedEvent = false;
|
2012-08-04 11:44:00 +04:00
|
|
|
if (aKeyEvent) {
|
|
|
|
aKeyEvent->GetIsTrusted(&trustedEvent);
|
2002-03-27 09:29:39 +03:00
|
|
|
}
|
|
|
|
|
2004-09-02 19:25:39 +04:00
|
|
|
if (!trustedEvent)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-08-29 02:21:30 +04:00
|
|
|
if (mAccessKey && mAccessKeyFocuses)
|
2000-08-17 04:09:16 +04:00
|
|
|
{
|
2012-05-10 03:25:48 +04:00
|
|
|
bool defaultPrevented = false;
|
|
|
|
aKeyEvent->GetDefaultPrevented(&defaultPrevented);
|
|
|
|
|
2000-08-17 04:09:16 +04:00
|
|
|
nsCOMPtr<nsIDOMKeyEvent> keyEvent = do_QueryInterface(aKeyEvent);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t theChar;
|
2000-08-17 04:09:16 +04:00
|
|
|
keyEvent->GetKeyCode(&theChar);
|
|
|
|
|
2012-02-14 04:56:03 +04: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 19:56:38 +04:00
|
|
|
((theChar == (uint32_t)mAccessKey) &&
|
2014-05-22 08:06:06 +04:00
|
|
|
(GetModifiersForAccessKey(keyEvent) & ~mAccessKeyMask) == 0);
|
2012-02-14 04:56:03 +04:00
|
|
|
|
|
|
|
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 18:59:28 +04:00
|
|
|
mAccessKeyDown = true;
|
2012-05-10 03:25:48 +04:00
|
|
|
// If default is prevented already, cancel the access key down.
|
|
|
|
mAccessKeyDownCanceled = defaultPrevented;
|
2012-02-14 04:56:03 +04:00
|
|
|
return NS_OK;
|
2000-02-18 13:05:14 +03:00
|
|
|
}
|
2001-07-25 06:37:11 +04:00
|
|
|
|
2012-05-10 03:25:48 +04:00
|
|
|
// If the pressed accesskey was canceled already or the event was
|
|
|
|
// consumed already, ignore the event.
|
|
|
|
if (mAccessKeyDownCanceled || defaultPrevented) {
|
2012-02-14 04:56:03 +04:00
|
|
|
return NS_OK;
|
2001-07-25 06:37:11 +04:00
|
|
|
}
|
2012-02-14 04:56:03 +04: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;
|
2000-02-18 13:05:14 +03:00
|
|
|
}
|
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
1999-07-21 11:42:16 +04:00
|
|
|
|
2000-01-11 01:05:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::Blur(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2007-07-04 19:49:38 +04:00
|
|
|
if (!mMenuBarFrame->IsMenuOpen() && mMenuBarFrame->IsActive()) {
|
|
|
|
ToggleMenuActiveState();
|
2000-01-11 01:05:27 +03:00
|
|
|
}
|
2012-02-14 04:56:03 +04:00
|
|
|
// Reset the accesskey state because we cannot receive the keyup event for
|
|
|
|
// the pressing accesskey.
|
|
|
|
mAccessKeyDown = false;
|
|
|
|
mAccessKeyDownCanceled = false;
|
2000-01-11 01:05:27 +03:00
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
2000-01-14 02:20:28 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|
|
|
{
|
2010-12-04 04:55:15 +03: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 18:59:28 +04:00
|
|
|
mAccessKeyDownCanceled = true;
|
2010-12-04 04:55:15 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t phase = 0;
|
2010-12-04 04:55:15 +03: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 19:49:38 +04:00
|
|
|
if (!mMenuBarFrame->IsMenuOpen() && mMenuBarFrame->IsActive())
|
|
|
|
ToggleMenuActiveState();
|
2001-07-25 06:37:11 +04:00
|
|
|
|
2000-01-14 02:20:28 +03:00
|
|
|
return NS_OK; // means I am NOT consuming event
|
|
|
|
}
|
|
|
|
|
2000-01-11 01:05:27 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-07-21 11:42:16 +04:00
|
|
|
nsresult
|
|
|
|
nsMenuBarListener::HandleEvent(nsIDOMEvent* aEvent)
|
|
|
|
{
|
2015-08-29 04:12:41 +03:00
|
|
|
// If the menu bar is collapsed, don't do anything.
|
|
|
|
if (!mMenuBarFrame->StyleVisibility()->IsVisible()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-01 01:20:02 +04: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();
|
|
|
|
|
1999-07-21 11:42:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|