From f84ecc96c9ff962ced259f983351807e4282cfba Mon Sep 17 00:00:00 2001 From: Markus Stange Date: Thu, 18 Mar 2021 15:37:38 +0000 Subject: [PATCH] Bug 1698668 - Add (unused) Dump methods to nsMenuX and nsMenuItemX that can be used during debugging. r=harry Depends on D108550 Differential Revision: https://phabricator.services.mozilla.com/D108551 --- widget/cocoa/nsMenuItemX.h | 2 ++ widget/cocoa/nsMenuItemX.mm | 6 ++++++ widget/cocoa/nsMenuX.h | 2 ++ widget/cocoa/nsMenuX.mm | 27 +++++++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/widget/cocoa/nsMenuItemX.h b/widget/cocoa/nsMenuItemX.h index 155ae7fdea47..a1dd317343c3 100644 --- a/widget/cocoa/nsMenuItemX.h +++ b/widget/cocoa/nsMenuItemX.h @@ -63,6 +63,8 @@ class nsMenuItemX final : public nsMenuObjectX, public nsChangeObserver { nsIContent* Content() { return mContent; } NSMenuItem* NativeNSMenuItem() { return mNativeMenuItem; } + void Dump(uint32_t aIndent) const; + protected: void UncheckRadioSiblings(nsIContent* aCheckedElement); void SetKeyEquiv(); diff --git a/widget/cocoa/nsMenuItemX.mm b/widget/cocoa/nsMenuItemX.mm index e73abdeca280..1af8886382b8 100644 --- a/widget/cocoa/nsMenuItemX.mm +++ b/widget/cocoa/nsMenuItemX.mm @@ -257,6 +257,12 @@ void nsMenuItemX::SetKeyEquiv() { NS_OBJC_END_TRY_ABORT_BLOCK; } +void nsMenuItemX::Dump(uint32_t aIndent) const { + printf("%*s - item [%p] %-16s <%s>\n", aIndent * 2, "", this, + mType == eSeparatorMenuItemType ? "----" : [mNativeMenuItem.title UTF8String], + NS_ConvertUTF16toUTF8(mContent->NodeName()).get()); +} + // // nsChangeObserver // diff --git a/widget/cocoa/nsMenuX.h b/widget/cocoa/nsMenuX.h index 173d087f78b9..cdff909b3e9a 100644 --- a/widget/cocoa/nsMenuX.h +++ b/widget/cocoa/nsMenuX.h @@ -67,6 +67,8 @@ class nsMenuX final : public nsMenuObjectX, public nsChangeObserver { NSMenuItem* NativeNSMenuItem() { return mNativeMenuItem; } GeckoNSMenu* NativeNSMenu() { return mNativeMenu; } + void Dump(uint32_t aIndent) const; + static bool IsXULHelpMenu(nsIContent* aMenuContent); protected: diff --git a/widget/cocoa/nsMenuX.mm b/widget/cocoa/nsMenuX.mm index 0b5e32a0af32..3a8741805a23 100644 --- a/widget/cocoa/nsMenuX.mm +++ b/widget/cocoa/nsMenuX.mm @@ -692,6 +692,33 @@ void nsMenuX::IconUpdated() { mParent->IconUpdated(); } +void nsMenuX::Dump(uint32_t aIndent) const { + printf("%*s - menu [%p] %-16s <%s>", aIndent * 2, "", this, + mLabel.IsEmpty() ? "(empty label)" : NS_ConvertUTF16toUTF8(mLabel).get(), + NS_ConvertUTF16toUTF8(mContent->NodeName()).get()); + if (mNeedsRebuild) { + printf(" [NeedsRebuild]"); + } + if (mConstructed) { + printf(" [Constructed]"); + } + if (mVisible) { + printf(" [Visible]"); + } + if (mIsEnabled) { + printf(" [IsEnabled]"); + } + printf(" (%d visible items)", int(mVisibleItemsCount)); + printf("\n"); + for (const auto& subitem : mMenuObjectsArray) { + if (subitem->MenuObjectType() == eSubmenuObjectType) { + static_cast(subitem.get())->Dump(aIndent + 1); + } else if (subitem->MenuObjectType() == eMenuItemObjectType) { + static_cast(subitem.get())->Dump(aIndent + 1); + } + } +} + // // MenuDelegate Objective-C class, used to set up Carbon events //