Bug 1646817 - Support DocumentChannel process switching in sidebars and popups r...
[gecko.git] / widget / cocoa / nsMenuItemX.h
blobca102a426cfee3269c673ff1b9d5d4e1c4842718
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsMenuItemX_h_
7 #define nsMenuItemX_h_
9 #include "mozilla/RefPtr.h"
10 #include "nsMenuBaseX.h"
11 #include "nsMenuGroupOwnerX.h"
12 #include "nsChangeObserver.h"
13 #include "nsStringFwd.h"
15 #import <Cocoa/Cocoa.h>
17 class nsMenuItemIconX;
18 class nsMenuX;
20 namespace mozilla {
21 namespace dom {
22 class Element;
24 } // namespace mozilla
26 enum {
27 knsMenuItemNoModifier = 0,
28 knsMenuItemShiftModifier = (1 << 0),
29 knsMenuItemAltModifier = (1 << 1),
30 knsMenuItemControlModifier = (1 << 2),
31 knsMenuItemCommandModifier = (1 << 3)
34 enum EMenuItemType {
35 eRegularMenuItemType = 0,
36 eCheckboxMenuItemType,
37 eRadioMenuItemType,
38 eSeparatorMenuItemType
41 // Once instantiated, this object lives until its DOM node or its parent window
42 // is destroyed. Do not hold references to this, they can become invalid any
43 // time the DOM node can be destroyed.
44 class nsMenuItemX : public nsMenuObjectX, public nsChangeObserver {
45 public:
46 nsMenuItemX();
47 virtual ~nsMenuItemX();
49 NS_DECL_CHANGEOBSERVER
51 // nsMenuObjectX
52 void* NativeData() override { return (void*)mNativeMenuItem; }
53 nsMenuObjectTypeX MenuObjectType() override { return eMenuItemObjectType; }
55 // nsMenuItemX
56 nsresult Create(nsMenuX* aParent, const nsString& aLabel,
57 EMenuItemType aItemType, nsMenuGroupOwnerX* aMenuGroupOwner,
58 nsIContent* aNode);
59 nsresult SetChecked(bool aIsChecked);
60 EMenuItemType GetMenuItemType();
61 void DoCommand();
62 nsresult DispatchDOMEvent(const nsString& eventName,
63 bool* preventDefaultCalled);
64 void SetupIcon();
66 protected:
67 void UncheckRadioSiblings(nsIContent* inCheckedElement);
68 void SetKeyEquiv();
70 EMenuItemType mType;
72 // nsMenuItemX objects should always have a valid native menu item.
73 NSMenuItem* mNativeMenuItem; // [strong]
74 nsMenuX* mMenuParent; // [weak]
75 nsMenuGroupOwnerX* mMenuGroupOwner; // [weak]
76 RefPtr<mozilla::dom::Element> mCommandElement;
77 // The icon object should never outlive its creating nsMenuItemX object.
78 RefPtr<nsMenuItemIconX> mIcon;
79 bool mIsChecked;
82 #endif // nsMenuItemX_h_