Bug 1372276 - Part 4: Remove type and label attributes from menu HTML element; r?bz draft
authorGordon P. Hemsley <gphemsley@gmail.com>
Sat, 29 Jul 2017 22:38:05 -0400
changeset 618199 c8ff3a36771cd8932df9acede1b7c2460218b8cc
parent 618198 dbd69656c41b73ec0e0e78924474dd3d3068f4e2
child 618200 17995bbf0f7ff25ae9d14ef86c052242f0d6d724
push id71235
push userbmo:gphemsley@gphemsley.org
push dateSun, 30 Jul 2017 14:44:40 +0000
reviewersbz
bugs1372276
milestone56.0a1
Bug 1372276 - Part 4: Remove type and label attributes from menu HTML element; r?bz MozReview-Commit-ID: EvCVto72Fjb
dom/html/HTMLMenuElement.cpp
dom/html/HTMLMenuElement.h
dom/interfaces/html/nsIDOMHTMLMenuElement.idl
dom/webidl/HTMLMenuElement.webidl
testing/web-platform/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini
toolkit/components/passwordmgr/test/unit/test_context_menu.js
--- a/dom/html/HTMLMenuElement.cpp
+++ b/dom/html/HTMLMenuElement.cpp
@@ -17,67 +17,45 @@
 
 #define HTMLMENUBUILDER_CONTRACTID "@mozilla.org/content/html-menu-builder;1"
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Menu)
 
 namespace mozilla {
 namespace dom {
 
-enum MenuType : uint8_t
-{
-  MENU_TYPE_CONTEXT = 1,
-  MENU_TYPE_TOOLBAR
-};
-
-static const nsAttrValue::EnumTable kMenuTypeTable[] = {
-  { "context", MENU_TYPE_CONTEXT },
-  { "toolbar", MENU_TYPE_TOOLBAR },
-  { nullptr, 0 }
-};
-
-static const nsAttrValue::EnumTable* kMenuDefaultType =
-  &kMenuTypeTable[1];
-
 enum SeparatorType
 {
   ST_TRUE_INIT = -1,
   ST_FALSE = 0,
   ST_TRUE = 1
 };
 
 
 
 HTMLMenuElement::HTMLMenuElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
-  : nsGenericHTMLElement(aNodeInfo), mType(MENU_TYPE_TOOLBAR)
+  : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 HTMLMenuElement::~HTMLMenuElement()
 {
 }
 
 NS_IMPL_ISUPPORTS_INHERITED(HTMLMenuElement, nsGenericHTMLElement,
                             nsIDOMHTMLMenuElement)
 
 NS_IMPL_ELEMENT_CLONE(HTMLMenuElement)
 
 NS_IMPL_BOOL_ATTR(HTMLMenuElement, Compact, compact)
-NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(HTMLMenuElement, Type, type,
-                                kMenuDefaultType->tag)
-NS_IMPL_STRING_ATTR(HTMLMenuElement, Label, label)
 
 
 already_AddRefed<nsIMenuBuilder>
 HTMLMenuElement::CreateBuilder()
 {
-  if (mType != MENU_TYPE_CONTEXT) {
-    return nullptr;
-  }
-
   nsCOMPtr<nsIMenuBuilder> builder = do_CreateInstance(HTMLMENUBUILDER_CONTRACTID);
   NS_WARNING_ASSERTION(builder, "No builder available");
   return builder.forget();
 }
 
 void
 HTMLMenuElement::Build(nsIMenuBuilder* aBuilder)
 {
@@ -88,39 +66,26 @@ HTMLMenuElement::Build(nsIMenuBuilder* a
   BuildSubmenu(EmptyString(), this, aBuilder);
 }
 
 nsresult
 HTMLMenuElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
                               const nsAttrValue* aValue,
                               const nsAttrValue* aOldValue, bool aNotify)
 {
-  if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::type) {
-    if (aValue) {
-      mType = aValue->GetEnumValue();
-    } else {
-      mType = kMenuDefaultType->value;
-    }
-  }
-
   return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
                                             aOldValue, aNotify);
 }
 
 bool
 HTMLMenuElement::ParseAttribute(int32_t aNamespaceID,
                                 nsIAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsAttrValue& aResult)
 {
-  if (aNamespaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::type) {
-    return aResult.ParseEnumValue(aValue, kMenuTypeTable, false,
-                                  kMenuDefaultType);
-  }
-
   return nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
                                               aResult);
 }
 
 void
 HTMLMenuElement::BuildSubmenu(const nsAString& aLabel,
                               nsIContent* aContent,
                               nsIMenuBuilder* aBuilder)
--- a/dom/html/HTMLMenuElement.h
+++ b/dom/html/HTMLMenuElement.h
@@ -37,32 +37,18 @@ public:
   virtual bool ParseAttribute(int32_t aNamespaceID,
                                 nsIAtom* aAttribute,
                                 const nsAString& aValue,
                                 nsAttrValue& aResult) override;
 
   virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
                          bool aPreallocateChildren) const override;
 
-  uint8_t GetType() const { return mType; }
-
   // WebIDL
 
-  // The XPCOM GetType is OK for us
-  void SetType(const nsAString& aType, ErrorResult& aError)
-  {
-    SetHTMLAttr(nsGkAtoms::type, aType, aError);
-  }
-
-  // The XPCOM GetLabel is OK for us
-  void SetLabel(const nsAString& aLabel, ErrorResult& aError)
-  {
-    SetHTMLAttr(nsGkAtoms::label, aLabel, aError);
-  }
-
   bool Compact() const
   {
     return GetBoolAttr(nsGkAtoms::compact);
   }
   void SetCompact(bool aCompact, ErrorResult& aError)
   {
     SetHTMLBoolAttr(nsGkAtoms::compact, aCompact, aError);
   }
@@ -84,16 +70,14 @@ protected:
                     nsIContent* aContent,
                     nsIMenuBuilder* aBuilder);
 
   void TraverseContent(nsIContent* aContent,
                        nsIMenuBuilder* aBuilder,
                        int8_t& aSeparator);
 
   void AddSeparator(nsIMenuBuilder* aBuilder, int8_t& aSeparator);
-
-  uint8_t mType;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_HTMLMenuElement_h
--- a/dom/interfaces/html/nsIDOMHTMLMenuElement.idl
+++ b/dom/interfaces/html/nsIDOMHTMLMenuElement.idl
@@ -15,12 +15,9 @@
  * with changes from the work-in-progress WHATWG HTML specification:
  * http://www.whatwg.org/specs/web-apps/current-work/
  */
 
 [uuid(a1ca9af6-f865-4fdf-901d-5858bb0ad5ea)]
 interface nsIDOMHTMLMenuElement : nsISupports
 {
            attribute boolean          compact;
-
-           attribute DOMString        type;
-           attribute DOMString        label;
 };
--- a/dom/webidl/HTMLMenuElement.webidl
+++ b/dom/webidl/HTMLMenuElement.webidl
@@ -12,20 +12,16 @@
  * and create derivative works of this document.
  */
 
 interface MenuBuilder;
 
 // http://www.whatwg.org/specs/web-apps/current-work/#the-menu-element
 [HTMLConstructor]
 interface HTMLMenuElement : HTMLElement {
-           [CEReactions, SetterThrows]
-           attribute DOMString type;
-           [CEReactions, SetterThrows]
-           attribute DOMString label;
 };
 
 // http://www.whatwg.org/specs/web-apps/current-work/#other-elements,-attributes-and-apis
 partial interface HTMLMenuElement {
            [CEReactions, SetterThrows]
            attribute boolean compact;
 };
 
--- a/testing/web-platform/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini
+++ b/testing/web-platform/meta/html/semantics/interactive-elements/contextmenu-historical.html.ini
@@ -5,16 +5,16 @@
 
   [onshow must not be present on the GlobalEventHandlers locations]
     expected: PASS
 
   [el.contextMenu must not be present]
     expected: PASS
 
   [menu.type must not exist or reflect the content attribute]
-    expected: FAIL
+    expected: PASS
 
   [menu.label must not exist or reflect the content attribute]
-    expected: FAIL
+    expected: PASS
 
   [The user-agent stylesheet must leave type="context" menus as block display like other menus]
     expected: PASS
 
--- a/toolkit/components/passwordmgr/test/unit/test_context_menu.js
+++ b/toolkit/components/passwordmgr/test/unit/test_context_menu.js
@@ -102,31 +102,31 @@ function checkLoginItems(logins, items) 
   }
   let duplicates = findDuplicates(logins);
 
   let dateAndTimeFormatter = Services.intl.createDateTimeFormat(undefined,
                              { dateStyle: "medium" });
   for (let login of logins) {
     if (login.username && !duplicates.has(login.username)) {
       // If login is not duplicate and we can't find an item for it, fail.
-      if (!items.find(item => item.label == login.username)) {
+      if (!items.find(item => item.getAttribute("label") == login.username)) {
         return false;
       }
       continue;
     }
 
     let meta = login.QueryInterface(Ci.nsILoginMetaInfo);
     let time = dateAndTimeFormatter.format(new Date(meta.timePasswordChanged));
     // If login is duplicate, check if we have a login item with appended date.
-    if (login.username && !items.find(item => item.label == login.username + " (" + time + ")")) {
+    if (login.username && !items.find(item => item.getAttribute("label") == login.username + " (" + time + ")")) {
       return false;
     }
     // If login is empty, check if we have a login item with appended date.
     if (!login.username &&
-        !items.find(item => item.label == _stringBundle.GetStringFromName("noUsername") + " (" + time + ")")) {
+        !items.find(item => item.getAttribute("label") == _stringBundle.GetStringFromName("noUsername") + " (" + time + ")")) {
       return false;
     }
   }
   return true;
 }
 
 /**
  * Gets the list of expected logins for a hostname.