From f535f1d0ddd24ee1c52b660fa96f61d85621490b Mon Sep 17 00:00:00 2001 From: Kyle Machulis Date: Wed, 8 Nov 2017 17:43:09 -0800 Subject: [PATCH] Bug 1415716 - Remove nsIDOMHTMLOptionElement; r=bz MozReview-Commit-ID: JGxQxeFBQlO --- dom/html/HTMLOptionElement.cpp | 64 ++----------------- dom/html/HTMLOptionElement.h | 42 ++++++------ dom/html/HTMLOptionsCollection.h | 2 - dom/html/HTMLSelectElement.cpp | 22 ++----- dom/html/HTMLSelectElement.h | 13 ---- dom/interfaces/html/moz.build | 1 - .../html/nsIDOMHTMLOptionElement.idl | 31 --------- .../WebBrowserPersistLocalDocument.cpp | 13 ++-- dom/webidl/HTMLOptionElement.webidl | 23 ++++--- layout/forms/nsListControlFrame.cpp | 23 +++---- xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp | 4 -- 11 files changed, 64 insertions(+), 174 deletions(-) delete mode 100644 dom/interfaces/html/nsIDOMHTMLOptionElement.idl diff --git a/dom/html/HTMLOptionElement.cpp b/dom/html/HTMLOptionElement.cpp index 7d8d00eabe0d..b1b2ed0b7d6a 100644 --- a/dom/html/HTMLOptionElement.cpp +++ b/dom/html/HTMLOptionElement.cpp @@ -49,19 +49,10 @@ HTMLOptionElement::~HTMLOptionElement() { } -NS_IMPL_ISUPPORTS_INHERITED(HTMLOptionElement, nsGenericHTMLElement, - nsIDOMHTMLOptionElement) +NS_IMPL_ISUPPORTS_INHERITED0(HTMLOptionElement, nsGenericHTMLElement) NS_IMPL_ELEMENT_CLONE(HTMLOptionElement) - -NS_IMETHODIMP -HTMLOptionElement::GetForm(nsIDOMHTMLFormElement** aForm) -{ - NS_IF_ADDREF(*aForm = GetForm()); - return NS_OK; -} - mozilla::dom::HTMLFormElement* HTMLOptionElement::GetForm() { @@ -115,15 +106,7 @@ HTMLOptionElement::UpdateDisabledState(bool aNotify) } } -NS_IMETHODIMP -HTMLOptionElement::GetSelected(bool* aValue) -{ - NS_ENSURE_ARG_POINTER(aValue); - *aValue = Selected(); - return NS_OK; -} - -NS_IMETHODIMP +void HTMLOptionElement::SetSelected(bool aValue) { // Note: The select content obj maintains all the PresState @@ -141,21 +124,6 @@ HTMLOptionElement::SetSelected(bool aValue) } else { SetSelectedInternal(aValue, true); } - - return NS_OK; -} - -NS_IMPL_BOOL_ATTR(HTMLOptionElement, DefaultSelected, selected) -// GetText returns a whitespace compressed .textContent value. -NS_IMPL_STRING_ATTR_WITH_FALLBACK(HTMLOptionElement, Label, label, GetText) -NS_IMPL_STRING_ATTR_WITH_FALLBACK(HTMLOptionElement, Value, value, GetText) -NS_IMPL_BOOL_ATTR(HTMLOptionElement, Disabled, disabled) - -NS_IMETHODIMP -HTMLOptionElement::GetIndex(int32_t* aIndex) -{ - *aIndex = Index(); - return NS_OK; } int32_t @@ -179,18 +147,6 @@ HTMLOptionElement::Index() return index; } -bool -HTMLOptionElement::Selected() const -{ - return mIsSelected; -} - -bool -HTMLOptionElement::DefaultSelected() const -{ - return HasAttr(kNameSpaceID_None, nsGkAtoms::selected); -} - nsChangeHint HTMLOptionElement::GetAttributeChangeHint(const nsAtom* aAttribute, int32_t aModType) const @@ -288,7 +244,7 @@ HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, aValue, aOldValue, aSubjectPrincipal, aNotify); } -NS_IMETHODIMP +void HTMLOptionElement::GetText(nsAString& aText) { nsAutoString text; @@ -310,14 +266,12 @@ HTMLOptionElement::GetText(nsAString& aText) // XXX No CompressWhitespace for nsAString. Sad. text.CompressWhitespace(true, true); aText = text; - - return NS_OK; } -NS_IMETHODIMP -HTMLOptionElement::SetText(const nsAString& aText) +void +HTMLOptionElement::SetText(const nsAString& aText, ErrorResult& aRv) { - return nsContentUtils::SetNodeTextContent(this, aText, true); + aRv = nsContentUtils::SetNodeTextContent(this, aText, true); } nsresult @@ -435,11 +389,7 @@ HTMLOptionElement::Option(const GlobalObject& aGlobal, } } - option->SetSelected(aSelected, aError); - if (aError.Failed()) { - return nullptr; - } - + option->SetSelected(aSelected); option->SetSelectedChanged(false); return option.forget(); diff --git a/dom/html/HTMLOptionElement.h b/dom/html/HTMLOptionElement.h index 7cc208e703f3..0328fcbc7215 100644 --- a/dom/html/HTMLOptionElement.h +++ b/dom/html/HTMLOptionElement.h @@ -9,7 +9,6 @@ #include "mozilla/Attributes.h" #include "nsGenericHTMLElement.h" -#include "nsIDOMHTMLOptionElement.h" #include "mozilla/dom/HTMLFormElement.h" namespace mozilla { @@ -17,8 +16,7 @@ namespace dom { class HTMLSelectElement; -class HTMLOptionElement final : public nsGenericHTMLElement, - public nsIDOMHTMLOptionElement +class HTMLOptionElement final : public nsGenericHTMLElement { public: explicit HTMLOptionElement(already_AddRefed& aNodeInfo); @@ -36,13 +34,15 @@ public: // nsISupports NS_DECL_ISUPPORTS_INHERITED - // nsIDOMHTMLOptionElement using mozilla::dom::Element::SetText; using mozilla::dom::Element::GetText; - NS_DECL_NSIDOMHTMLOPTIONELEMENT - bool Selected() const; - bool DefaultSelected() const; + bool Selected() const + { + return mIsSelected; + } + void SetSelected(bool aValue); + void SetSelectedChanged(bool aValue) { @@ -106,35 +106,39 @@ public: HTMLFormElement* GetForm(); - // The XPCOM GetLabel is OK for us + void GetLabel(DOMString& aLabel) + { + if (!GetAttr(kNameSpaceID_None, nsGkAtoms::label, aLabel)) { + GetText(aLabel); + } + } void SetLabel(const nsAString& aLabel, ErrorResult& aError) { SetHTMLAttr(nsGkAtoms::label, aLabel, aError); } - // The XPCOM DefaultSelected is OK for us + bool DefaultSelected() const + { + return HasAttr(kNameSpaceID_None, nsGkAtoms::selected); + } void SetDefaultSelected(bool aValue, ErrorResult& aRv) { SetHTMLBoolAttr(nsGkAtoms::selected, aValue, aRv); } - // The XPCOM Selected is OK for us - void SetSelected(bool aValue, ErrorResult& aRv) + void GetValue(nsAString& aValue) { - aRv = SetSelected(aValue); + if (!GetAttr(kNameSpaceID_None, nsGkAtoms::value, aValue)) { + GetText(aValue); + } } - - // The XPCOM GetValue is OK for us void SetValue(const nsAString& aValue, ErrorResult& aRv) { SetHTMLAttr(nsGkAtoms::value, aValue, aRv); } - // The XPCOM GetText is OK for us - void SetText(const nsAString& aValue, ErrorResult& aRv) - { - aRv = SetText(aValue); - } + void GetText(nsAString& aText); + void SetText(const nsAString& aText, ErrorResult& aRv); int32_t Index(); diff --git a/dom/html/HTMLOptionsCollection.h b/dom/html/HTMLOptionsCollection.h index 7a3138d28c03..b0bceff7c16d 100644 --- a/dom/html/HTMLOptionsCollection.h +++ b/dom/html/HTMLOptionsCollection.h @@ -17,8 +17,6 @@ #include "nsGenericHTMLElement.h" #include "nsTArray.h" -class nsIDOMHTMLOptionElement; - namespace mozilla { namespace dom { diff --git a/dom/html/HTMLSelectElement.cpp b/dom/html/HTMLSelectElement.cpp index b35481721ed1..4bf0ec3519c0 100644 --- a/dom/html/HTMLSelectElement.cpp +++ b/dom/html/HTMLSelectElement.cpp @@ -513,7 +513,7 @@ HTMLSelectElement::GetFirstOptionIndex(nsIContent* aOptions) int32_t listIndex = -1; HTMLOptionElement* optElement = HTMLOptionElement::FromContent(aOptions); if (optElement) { - GetOptionIndex(optElement, 0, true, &listIndex); + mOptions->GetOptionIndex(optElement->AsElement(), 0, true, &listIndex); return listIndex; } @@ -711,15 +711,6 @@ HTMLSelectElement::SetSelectedIndexInternal(int32_t aIndex, bool aNotify) return rv; } -NS_IMETHODIMP -HTMLSelectElement::GetOptionIndex(nsIDOMHTMLOptionElement* aOption, - int32_t aStartIndex, bool aForward, - int32_t* aIndex) -{ - nsCOMPtr option = do_QueryInterface(aOption); - return mOptions->GetOptionIndex(option->AsElement(), aStartIndex, aForward, aIndex); -} - bool HTMLSelectElement::IsOptionSelectedByIndex(int32_t aIndex) { @@ -1032,8 +1023,7 @@ HTMLSelectElement::GetValue(DOMString& aValue) return; } - DebugOnly rv = option->GetValue(aValue); - MOZ_ASSERT(NS_SUCCEEDED(rv)); + option->GetValue(aValue); } void @@ -1479,8 +1469,8 @@ HTMLSelectElement::RestoreStateTo(SelectState* aNewSelected) HTMLOptionElement* option = Item(i); if (option) { nsAutoString value; - nsresult rv = option->GetValue(value); - if (NS_SUCCEEDED(rv) && aNewSelected->ContainsOption(i, value)) { + option->GetValue(value); + if (aNewSelected->ContainsOption(i, value)) { SetOptionsSelectedByIndex(i, i, IS_SELECTED | SET_DISABLED | NOTIFY); } } @@ -1579,7 +1569,7 @@ HTMLSelectElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission) } nsString value; - MOZ_ALWAYS_SUCCEEDS(option->GetValue(value)); + option->GetValue(value); if (keyGenProcessor) { nsString tmp(value); @@ -1659,7 +1649,7 @@ HTMLSelectElement::IsValueMissing() const // Check for a placeholder label option, don't count it as a valid value. if (i == 0 && !Multiple() && Size() <= 1 && option->GetParent() == this) { nsAutoString value; - MOZ_ALWAYS_SUCCEEDS(option->GetValue(value)); + option->GetValue(value); if (value.IsEmpty()) { continue; } diff --git a/dom/html/HTMLSelectElement.h b/dom/html/HTMLSelectElement.h index e78104075ca0..782df8bbae8c 100644 --- a/dom/html/HTMLSelectElement.h +++ b/dom/html/HTMLSelectElement.h @@ -360,19 +360,6 @@ public: int32_t aEndIndex, uint32_t aOptionsMask); - /** - * Finds the index of a given option element - * - * @param aOption the option to get the index of - * @param aStartIndex the index to start looking at - * @param aForward TRUE to look forward, FALSE to look backward - * @return the option index - */ - NS_IMETHOD GetOptionIndex(nsIDOMHTMLOptionElement* aOption, - int32_t aStartIndex, - bool aForward, - int32_t* aIndex); - /** * Called when an attribute is about to be changed */ diff --git a/dom/interfaces/html/moz.build b/dom/interfaces/html/moz.build index a98c101f3416..56644ae6a243 100644 --- a/dom/interfaces/html/moz.build +++ b/dom/interfaces/html/moz.build @@ -16,7 +16,6 @@ XPIDL_SOURCES += [ 'nsIDOMHTMLHtmlElement.idl', 'nsIDOMHTMLInputElement.idl', 'nsIDOMHTMLMediaElement.idl', - 'nsIDOMHTMLOptionElement.idl', 'nsIDOMHTMLScriptElement.idl', 'nsIDOMMozBrowserFrame.idl', 'nsIDOMTimeRanges.idl', diff --git a/dom/interfaces/html/nsIDOMHTMLOptionElement.idl b/dom/interfaces/html/nsIDOMHTMLOptionElement.idl deleted file mode 100644 index 7ff7a90abc60..000000000000 --- a/dom/interfaces/html/nsIDOMHTMLOptionElement.idl +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* 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/. */ - -#include "nsIDOMHTMLElement.idl" - -/** - * The nsIDOMHTMLOptionElement interface is the interface to a [X]HTML - * option element. - * - * This interface is trying to follow the DOM Level 2 HTML specification: - * http://www.w3.org/TR/DOM-Level-2-HTML/ - * - * with changes from the work-in-progress WHATWG HTML specification: - * http://www.whatwg.org/specs/web-apps/current-work/ - */ - -[uuid(c2b3e9ff-6b36-4158-ace3-05a9c5b8e1c1)] -interface nsIDOMHTMLOptionElement : nsISupports -{ - attribute boolean disabled; - readonly attribute nsIDOMHTMLFormElement form; - attribute DOMString label; - attribute boolean defaultSelected; - attribute boolean selected; - attribute DOMString value; - - attribute DOMString text; - readonly attribute long index; -}; diff --git a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp index 07014e44ef63..d4670529cc0d 100644 --- a/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp +++ b/dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp @@ -11,6 +11,7 @@ #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/dom/HTMLLinkElement.h" #include "mozilla/dom/HTMLObjectElement.h" +#include "mozilla/dom/HTMLOptionElement.h" #include "mozilla/dom/HTMLSharedElement.h" #include "mozilla/dom/HTMLTextAreaElement.h" #include "mozilla/dom/TabParent.h" @@ -29,7 +30,6 @@ #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLMediaElement.h" -#include "nsIDOMHTMLOptionElement.h" #include "nsIDOMHTMLScriptElement.h" #include "nsIDOMMozNamedAttrMap.h" #include "nsIDOMNode.h" @@ -1166,14 +1166,15 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn, return rv; } - nsCOMPtr nodeAsOption = do_QueryInterface(aNodeIn); + dom::HTMLOptionElement* nodeAsOption = dom::HTMLOptionElement::FromContent(content); if (nodeAsOption) { rv = GetNodeToFixup(aNodeIn, aNodeOut); if (NS_SUCCEEDED(rv) && *aNodeOut) { - nsCOMPtr outElt = do_QueryInterface(*aNodeOut); - bool selected; - nodeAsOption->GetSelected(&selected); - outElt->SetDefaultSelected(selected); + nsCOMPtr outContent = do_QueryInterface(*aNodeOut); + dom::HTMLOptionElement* outElt = dom::HTMLOptionElement::FromContent(outContent); + bool selected = nodeAsOption->Selected(); + IgnoredErrorResult ignored; + outElt->SetDefaultSelected(selected, ignored); } return rv; } diff --git a/dom/webidl/HTMLOptionElement.webidl b/dom/webidl/HTMLOptionElement.webidl index 8592bf96b137..415f6fdd4a04 100644 --- a/dom/webidl/HTMLOptionElement.webidl +++ b/dom/webidl/HTMLOptionElement.webidl @@ -13,19 +13,18 @@ [HTMLConstructor, NamedConstructor=Option(optional DOMString text = "", optional DOMString value, optional boolean defaultSelected = false, optional boolean selected = false)] interface HTMLOptionElement : HTMLElement { - [CEReactions, SetterThrows] - attribute boolean disabled; + [CEReactions, SetterThrows] + attribute boolean disabled; readonly attribute HTMLFormElement? form; - [CEReactions, SetterThrows] - attribute DOMString label; - [CEReactions, SetterThrows] - attribute boolean defaultSelected; - [SetterThrows] - attribute boolean selected; - [CEReactions, SetterThrows] - attribute DOMString value; + [CEReactions, SetterThrows] + attribute DOMString label; + [CEReactions, SetterThrows] + attribute boolean defaultSelected; + attribute boolean selected; + [CEReactions, SetterThrows] + attribute DOMString value; - [CEReactions, SetterThrows] - attribute DOMString text; + [CEReactions, SetterThrows] + attribute DOMString text; readonly attribute long index; }; diff --git a/layout/forms/nsListControlFrame.cpp b/layout/forms/nsListControlFrame.cpp index adb89fa00e6d..0582f1d7f4c6 100644 --- a/layout/forms/nsListControlFrame.cpp +++ b/layout/forms/nsListControlFrame.cpp @@ -10,7 +10,6 @@ #include "nsListControlFrame.h" #include "nsCheckboxRadioFrame.h" // for COMPARE macro #include "nsGkAtoms.h" -#include "nsIDOMHTMLOptionElement.h" #include "nsComboboxControlFrame.h" #include "nsIPresShell.h" #include "nsIDOMMouseEvent.h" @@ -231,12 +230,9 @@ void nsListControlFrame::PaintFocus(DrawTarget* aDrawTarget, nsPoint aPt) fRect += aPt; bool lastItemIsSelected = false; - if (focusedContent) { - nsCOMPtr domOpt = - do_QueryInterface(focusedContent); - if (domOpt) { - domOpt->GetSelected(&lastItemIsSelected); - } + HTMLOptionElement* domOpt = HTMLOptionElement::FromContentOrNull(focusedContent); + if (domOpt) { + lastItemIsSelected = domOpt->Selected(); } // set up back stop colors and then ask L&F service for the real colors @@ -1857,7 +1853,8 @@ nsListControlFrame::MouseDown(nsIDOMEvent* aMouseEvent) if (mComboboxFrame->IsOpenInParentProcess()) { nsCOMPtr etarget; aMouseEvent->GetTarget(getter_AddRefs(etarget)); - nsCOMPtr option = do_QueryInterface(etarget); + nsCOMPtr econtent = do_QueryInterface(etarget); + HTMLOptionElement* option = HTMLOptionElement::FromContentOrNull(econtent); if (option) { return NS_OK; } @@ -2453,11 +2450,11 @@ nsListControlFrame::KeyPress(nsIDOMEvent* aKeyEvent) } nsAutoString text; - if (NS_FAILED(optionElement->GetText(text)) || - !StringBeginsWith( - nsContentUtils::TrimWhitespace< - nsContentUtils::IsHTMLWhitespaceOrNBSP>(text, false), - incrementalString, nsCaseInsensitiveStringComparator())) { + optionElement->GetText(text); + if (!StringBeginsWith( + nsContentUtils::TrimWhitespace< + nsContentUtils::IsHTMLWhitespaceOrNBSP>(text, false), + incrementalString, nsCaseInsensitiveStringComparator())) { continue; } diff --git a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp index af79a69dba4b..0ed327d9d18f 100644 --- a/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp +++ b/xpcom/reflect/xptinfo/ShimInterfaceInfo.cpp @@ -53,7 +53,6 @@ #include "nsIDOMHTMLHtmlElement.h" #include "nsIDOMHTMLInputElement.h" #include "nsIDOMHTMLMediaElement.h" -#include "nsIDOMHTMLOptionElement.h" #include "nsIDOMHTMLScriptElement.h" #include "nsIDOMKeyEvent.h" #include "nsIDOMMediaList.h" @@ -153,8 +152,6 @@ #include "mozilla/dom/HTMLHtmlElementBinding.h" #include "mozilla/dom/HTMLInputElementBinding.h" #include "mozilla/dom/HTMLMediaElementBinding.h" -#include "mozilla/dom/HTMLObjectElementBinding.h" -#include "mozilla/dom/HTMLOptionElementBinding.h" #include "mozilla/dom/HTMLScriptElementBinding.h" #include "mozilla/dom/KeyEventBinding.h" #include "mozilla/dom/ListBoxObjectBinding.h" @@ -306,7 +303,6 @@ const ComponentsInterfaceShimEntry kComponentsInterfaceShimMap[] = DEFINE_SHIM(HTMLHtmlElement), DEFINE_SHIM(HTMLInputElement), DEFINE_SHIM(HTMLMediaElement), - DEFINE_SHIM(HTMLOptionElement), DEFINE_SHIM(HTMLScriptElement), DEFINE_SHIM(KeyEvent), DEFINE_SHIM_WITH_CUSTOM_INTERFACE(nsIListBoxObject, ListBoxObject),