Get MenuHelpersX compiling on 64-bit Mac OS X, some minor memory mgmt cleanup. b=459729 r=mstange sr=roc
authorJosh Aas <>
Wed, 29 Apr 2009 23:48:14 -0700
changeset 27906 3c1c49cf3fdef92a8a6124ce9e2777e9827aaf13
parent 27905 efe6d58c089d405fc0527600d12c17293dc1966a
child 27907 18a16a3b5e5503e35d591587013063893885964e
push id6768
push dateThu, 30 Apr 2009 06:46:49 +0000
treeherdermozilla-central@3c1c49cf3fde [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, roc
Get MenuHelpersX compiling on 64-bit Mac OS X, some minor memory mgmt cleanup. b=459729 r=mstange sr=roc
--- a/widget/src/cocoa/
+++ b/widget/src/cocoa/
@@ -132,19 +132,18 @@ nsresult nsMenuItemX::Create(nsMenuX* aP
     isEnabled = !mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled, nsWidgetAtoms::_true, eCaseMatters);
   // set up the native menu item
   if (mType == eSeparatorMenuItemType) {
     mNativeMenuItem = [[NSMenuItem separatorItem] retain];
   else {
-    NSString *newCocoaLabelString = nsMenuUtilsX::CreateTruncatedCocoaLabel(aLabel);
+    NSString *newCocoaLabelString = nsMenuUtilsX::GetTruncatedCocoaLabel(aLabel);
     mNativeMenuItem = [[NSMenuItem alloc] initWithTitle:newCocoaLabelString action:nil keyEquivalent:@""];
-    [newCocoaLabelString release];
     [mNativeMenuItem setEnabled:(BOOL)isEnabled];
     SetChecked(mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::checked,
                                      nsWidgetAtoms::_true, eCaseMatters));
     // Set key shortcut and modifiers
     if (domDoc) {
--- a/widget/src/cocoa/nsMenuUtilsX.h
+++ b/widget/src/cocoa/nsMenuUtilsX.h
@@ -51,17 +51,17 @@ class nsString;
 class nsMenuBarX;
 extern "C" MenuRef _NSGetCarbonMenu(NSMenu* aMenu);
 // Namespace containing utility functions used in our native menu implementation.
 namespace nsMenuUtilsX
   nsEventStatus DispatchCommandTo(nsIContent* aTargetContent);
-  NSString*     CreateTruncatedCocoaLabel(const nsString& itemLabel); // returned object is not retained
+  NSString*     GetTruncatedCocoaLabel(const nsString& itemLabel);
   PRUint8       GeckoModifiersForNodeAttribute(const nsString& modifiersAttribute);
   unsigned int  MacModifiersForGeckoModifiers(PRUint8 geckoModifiers);
   nsMenuBarX*   GetHiddenWindowMenuBar(); // returned object is not retained
   NSMenuItem*   GetStandardEditMenuItem(); // returned object is not retained
   PRBool        NodeIsHiddenOrCollapsed(nsIContent* inContent);
   int           CalculateNativeInsertionPoint(nsMenuObjectX* aParent, nsMenuObjectX* aChild);
--- a/widget/src/cocoa/
+++ b/widget/src/cocoa/
@@ -55,28 +55,34 @@ nsEventStatus nsMenuUtilsX::DispatchComm
   // FIXME: Should probably figure out how to init this with the actual
   // pressed keys, but this is a big old edge case anyway. -dwh
   aTargetContent->DispatchDOMEvent(&event, nsnull, nsnull, &status);
   return status;
-NSString* nsMenuUtilsX::CreateTruncatedCocoaLabel(const nsString& itemLabel)
+NSString* nsMenuUtilsX::GetTruncatedCocoaLabel(const nsString& itemLabel)
+#ifdef __LP64__
+  // Don't do anything on 64-bit Mac OS X for now, there is no API that does
+  // what we want. We'll probably need to roll our own solution.
+  return [NSString stringWithCharacters:itemLabel.get() length:itemLabel.Length()];
   // ::TruncateThemeText() doesn't take the number of characters to truncate to, it takes a pixel with
   // to fit the string in. Ugh. I talked it over with sfraser and we couldn't come up with an 
   // easy way to compute what this should be given the system font, etc, so we're just going
   // to hard code it to something reasonable and bigger fonts will just have to deal.
   const short kMaxItemPixelWidth = 300;
-  NSMutableString *label = [[NSMutableString stringWithCharacters:itemLabel.get() length:itemLabel.Length()] retain];
+  NSMutableString *label = [NSMutableString stringWithCharacters:itemLabel.get() length:itemLabel.Length()];
   ::TruncateThemeText((CFMutableStringRef)label, kThemeMenuItemFont, kThemeStateActive, kMaxItemPixelWidth, truncMiddle, NULL);
-  return label; // caller releases
+  return label;
 PRUint8 nsMenuUtilsX::GeckoModifiersForNodeAttribute(const nsString& modifiersAttribute)
   PRUint8 modifiers = knsMenuItemNoModifier;
--- a/widget/src/cocoa/
+++ b/widget/src/cocoa/
@@ -157,19 +157,18 @@ nsresult nsMenuX::Create(nsMenuObjectX* 
   NS_ASSERTION((parentType == eMenuBarObjectType || parentType == eSubmenuObjectType),
                "Menu parent not a menu bar or menu!");
   if (nsMenuUtilsX::NodeIsHiddenOrCollapsed(mContent))
     mVisible = PR_FALSE;
   if (mContent->GetChildCount() == 0)
     mVisible = PR_FALSE;
-  NSString *newCocoaLabelString = nsMenuUtilsX::CreateTruncatedCocoaLabel(mLabel);
+  NSString *newCocoaLabelString = nsMenuUtilsX::GetTruncatedCocoaLabel(mLabel);
   mNativeMenuItem = [[NSMenuItem alloc] initWithTitle:newCocoaLabelString action:nil keyEquivalent:@""];
-  [newCocoaLabelString release];
   [mNativeMenuItem setSubmenu:mNativeMenu];
   SetEnabled(!mContent->AttrValueIs(kNameSpaceID_None, nsWidgetAtoms::disabled,
                                     nsWidgetAtoms::_true, eCaseMatters));
   // We call MenuConstruct here because keyboard commands are dependent upon
   // native menu items being created. If we only call MenuConstruct when a menu
   // is actually selected, then we can't access keyboard commands until the
@@ -775,19 +774,18 @@ void nsMenuX::ObserveAttributeChanged(ns
     mContent->GetAttr(kNameSpaceID_None, nsWidgetAtoms::label, mLabel);
     // invalidate my parent. If we're a submenu parent, we have to rebuild
     // the parent menu in order for the changes to be picked up. If we're
     // a regular menu, just change the title and redraw the menubar.
     if (parentType == eMenuBarObjectType) {
       // reuse the existing menu, to avoid rebuilding the root menu bar.
       NS_ASSERTION(mNativeMenu, "nsMenuX::AttributeChanged: invalid menu handle.");
-      NSString *newCocoaLabelString = nsMenuUtilsX::CreateTruncatedCocoaLabel(mLabel);
+      NSString *newCocoaLabelString = nsMenuUtilsX::GetTruncatedCocoaLabel(mLabel);
       [mNativeMenu setTitle:newCocoaLabelString];
-      [newCocoaLabelString release];
     else {
   else if (aAttribute == nsWidgetAtoms::hidden || aAttribute == nsWidgetAtoms::collapsed) {