2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2016-07-11 10:22:37 +03:00
|
|
|
#ifndef nsMenuBarListener_h
|
|
|
|
#define nsMenuBarListener_h
|
1999-07-18 11:27:02 +04:00
|
|
|
|
2013-05-29 23:37:49 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-05-22 08:06:06 +04:00
|
|
|
#include "mozilla/EventForwards.h"
|
2018-11-13 01:20:52 +03:00
|
|
|
#include "nsIContent.h"
|
2011-07-01 01:20:02 +04:00
|
|
|
#include "nsIDOMEventListener.h"
|
1999-07-18 11:27:02 +04:00
|
|
|
|
2011-07-01 01:20:02 +04:00
|
|
|
// X.h defines KeyPress
|
|
|
|
#ifdef KeyPress
|
|
|
|
# undef KeyPress
|
|
|
|
#endif
|
|
|
|
|
2017-11-10 02:42:40 +03:00
|
|
|
class nsMenuFrame;
|
1999-07-18 11:27:02 +04:00
|
|
|
class nsMenuBarFrame;
|
|
|
|
|
2016-12-26 10:19:02 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class EventTarget;
|
2018-02-09 19:17:09 +03:00
|
|
|
class KeyboardEvent;
|
2016-12-26 10:19:02 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
/**
|
|
|
|
* EventListener implementation for menubar.
|
1999-07-18 11:27:02 +04:00
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsMenuBarListener final : public nsIDOMEventListener {
|
1999-07-18 11:27:02 +04:00
|
|
|
public:
|
2016-12-26 10:19:02 +03:00
|
|
|
explicit nsMenuBarListener(nsMenuBarFrame* aMenuBarFrame,
|
|
|
|
nsIContent* aMenuBarContent);
|
2014-02-18 21:07:27 +04:00
|
|
|
|
1999-07-18 11:27:02 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
/**
|
|
|
|
* nsIDOMEventListener interface method.
|
|
|
|
*/
|
2018-04-20 07:49:29 +03:00
|
|
|
NS_DECL_NSIDOMEVENTLISTENER
|
2004-08-10 02:22:02 +04:00
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
/**
|
|
|
|
* When mMenuBarFrame is being destroyed, this should be called.
|
|
|
|
*/
|
2015-05-15 14:42:14 +03:00
|
|
|
void OnDestroyMenuBarFrame();
|
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
static void InitializeStatics();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GetMenuAccessKey() returns keyCode value of a modifier key which is
|
|
|
|
* used for accesskey. Returns 0 if the platform doesn't support access key.
|
|
|
|
*/
|
|
|
|
static nsresult GetMenuAccessKey(int32_t* aAccessKey);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* IsAccessKeyPressed() returns true if the modifier state of aEvent matches
|
|
|
|
* the modifier state of access key.
|
2014-06-24 02:40:01 +04:00
|
|
|
*/
|
2018-02-09 19:17:09 +03:00
|
|
|
static bool IsAccessKeyPressed(mozilla::dom::KeyboardEvent* aEvent);
|
2016-07-11 10:22:37 +03:00
|
|
|
|
|
|
|
protected:
|
2014-06-24 02:40:01 +04:00
|
|
|
virtual ~nsMenuBarListener();
|
|
|
|
|
2018-04-20 07:49:29 +03:00
|
|
|
nsresult KeyUp(mozilla::dom::Event* aMouseEvent);
|
|
|
|
nsresult KeyDown(mozilla::dom::Event* aMouseEvent);
|
|
|
|
nsresult KeyPress(mozilla::dom::Event* aMouseEvent);
|
|
|
|
nsresult Blur(mozilla::dom::Event* aEvent);
|
|
|
|
nsresult OnWindowDeactivated(mozilla::dom::Event* aEvent);
|
|
|
|
nsresult MouseDown(mozilla::dom::Event* aMouseEvent);
|
|
|
|
nsresult Fullscreen(mozilla::dom::Event* aEvent);
|
2016-07-11 10:22:37 +03:00
|
|
|
|
2000-08-25 03:39:39 +04:00
|
|
|
static void InitAccessKey();
|
2000-08-17 04:09:16 +04:00
|
|
|
|
2018-02-09 19:17:09 +03:00
|
|
|
static mozilla::Modifiers GetModifiersForAccessKey(
|
|
|
|
mozilla::dom::KeyboardEvent* event);
|
2004-08-19 12:04:11 +04:00
|
|
|
|
2017-11-10 02:42:40 +03:00
|
|
|
/**
|
|
|
|
* Given a key event for an Alt+shortcut combination,
|
2018-01-15 23:16:56 +03:00
|
|
|
* return the menu, if any, that would be opened. If aPeek
|
|
|
|
* is false, then play a beep and deactivate the menubar on Windows.
|
2017-11-10 02:42:40 +03:00
|
|
|
*/
|
2018-02-09 19:17:09 +03:00
|
|
|
nsMenuFrame* GetMenuForKeyEvent(mozilla::dom::KeyboardEvent* aKeyEvent,
|
|
|
|
bool aPeek);
|
2017-11-10 02:42:40 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Call MarkAsReservedByChrome if the user's preferences indicate that
|
|
|
|
* the key should be chrome-only.
|
|
|
|
*/
|
2018-04-20 07:49:29 +03:00
|
|
|
void ReserveKeyIfNeeded(mozilla::dom::Event* aKeyEvent);
|
2017-11-10 02:42:40 +03:00
|
|
|
|
2007-07-04 19:49:38 +04:00
|
|
|
// This should only be called by the nsMenuBarListener during event dispatch,
|
|
|
|
// thus ensuring that this doesn't get destroyed during the process.
|
|
|
|
void ToggleMenuActiveState();
|
|
|
|
|
2015-05-15 14:42:14 +03:00
|
|
|
bool Destroyed() const { return !mMenuBarFrame; }
|
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
// The menu bar object.
|
|
|
|
nsMenuBarFrame* mMenuBarFrame;
|
2016-12-26 10:19:02 +03:00
|
|
|
// The event target to listen to the events.
|
|
|
|
// XXX Should this store this as strong reference? However,
|
|
|
|
// OnDestroyMenuBarFrame() should be called at destroying mMenuBarFrame.
|
|
|
|
// So, weak reference must be safe.
|
|
|
|
mozilla::dom::EventTarget* mEventTarget;
|
2016-12-26 10:22:13 +03:00
|
|
|
// The top window as EventTarget.
|
|
|
|
mozilla::dom::EventTarget* mTopWindowEventTarget;
|
2010-12-04 04:55:15 +03:00
|
|
|
// Whether or not the ALT key is currently down.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAccessKeyDown;
|
2010-12-04 04:55:15 +03:00
|
|
|
// Whether or not the ALT key down is canceled by other action.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mAccessKeyDownCanceled;
|
2016-07-11 10:22:37 +03:00
|
|
|
// Does the access key by itself focus the menubar?
|
|
|
|
static bool mAccessKeyFocuses;
|
2018-02-09 19:17:09 +03:00
|
|
|
// See KeyboardEvent for sample values (DOM_VK_* constants).
|
2016-07-11 10:22:37 +03:00
|
|
|
static int32_t mAccessKey;
|
|
|
|
// Modifier mask for the access key.
|
|
|
|
static mozilla::Modifiers mAccessKeyMask;
|
1999-07-18 11:27:02 +04:00
|
|
|
};
|
|
|
|
|
2016-07-11 10:22:37 +03:00
|
|
|
#endif // #ifndef nsMenuBarListener_h
|