summaryrefslogtreecommitdiffstats
path: root/layout/xul/nsMenuBarFrame.h
blob: 9601f8be2e490c51dee80f8563096d5ec5946ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

//
// nsMenuBarFrame
//

#ifndef nsMenuBarFrame_h__
#define nsMenuBarFrame_h__

#include "nsAtom.h"
#include "nsCOMPtr.h"
#include "nsBoxFrame.h"
#include "nsMenuBarListener.h"

class nsIContent;

namespace mozilla {
class PresShell;
namespace dom {
class KeyboardEvent;
class XULMenuParentElement;
}  // namespace dom
}  // namespace mozilla

nsIFrame* NS_NewMenuBarFrame(mozilla::PresShell* aPresShell,
                             mozilla::ComputedStyle* aStyle);

class nsMenuBarFrame final : public nsBoxFrame {
 public:
  NS_DECL_QUERYFRAME
  NS_DECL_FRAMEARENA_HELPERS(nsMenuBarFrame)

  explicit nsMenuBarFrame(ComputedStyle* aStyle, nsPresContext* aPresContext);

  void InstallKeyboardNavigator();
  void RemoveKeyboardNavigator();
  MOZ_CAN_RUN_SCRIPT void MenuClosed();

  void Init(nsIContent* aContent, nsContainerFrame* aParent,
            nsIFrame* aPrevInFlow) override;

  void DestroyFrom(nsIFrame* aDestructRoot,
                   PostDestroyData& aPostDestroyData) override;

  bool IsActiveByKeyboard() { return mActiveByKeyboard; }
  void SetActiveByKeyboard() { mActiveByKeyboard = true; }
  MOZ_CAN_RUN_SCRIPT void SetActive(bool aActive);
  bool IsActive() const { return mIsActive; }

  mozilla::dom::XULMenuParentElement& MenubarElement() const;

  // Called when Enter is pressed while the menubar is focused. If the current
  // menu is open, let the child handle the key.
  MOZ_CAN_RUN_SCRIPT void HandleEnterKeyPress(mozilla::WidgetEvent&);

  bool IsFrameOfType(uint32_t aFlags) const override {
    // Override bogus IsFrameOfType in nsBoxFrame.
    if (aFlags & (nsIFrame::eReplacedContainsBlock | nsIFrame::eReplaced))
      return false;
    return nsBoxFrame::IsFrameOfType(aFlags);
  }

#ifdef DEBUG_FRAME_DUMP
  nsresult GetFrameName(nsAString& aResult) const override {
    return MakeFrameName(u"MenuBar"_ns, aResult);
  }
#endif

 protected:
  RefPtr<nsMenuBarListener> mMenuBarListener;  // The listener that tells us
                                               // about key and mouse events.

  bool mIsActive = false;  // Whether or not the menu bar is active (a menu item
                           // is highlighted or shown).
  // Whether the menubar was made active via the keyboard.
  bool mActiveByKeyboard = false;
};  // class nsMenuBarFrame

#endif