Skip to content

Commit

Permalink
Bug 1415716 - Remove nsIDOMHTMLOptionElement; r=bz
Browse files Browse the repository at this point in the history
MozReview-Commit-ID: JGxQxeFBQlO
  • Loading branch information
qdot committed Nov 9, 2017
1 parent 7dd6fa0 commit 68fa69c
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 174 deletions.
64 changes: 7 additions & 57 deletions dom/html/HTMLOptionElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -288,7 +244,7 @@ HTMLOptionElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
aValue, aOldValue, aSubjectPrincipal, aNotify);
}

NS_IMETHODIMP
void
HTMLOptionElement::GetText(nsAString& aText)
{
nsAutoString text;
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
42 changes: 23 additions & 19 deletions dom/html/HTMLOptionElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

#include "mozilla/Attributes.h"
#include "nsGenericHTMLElement.h"
#include "nsIDOMHTMLOptionElement.h"
#include "mozilla/dom/HTMLFormElement.h"

namespace mozilla {
namespace dom {

class HTMLSelectElement;

class HTMLOptionElement final : public nsGenericHTMLElement,
public nsIDOMHTMLOptionElement
class HTMLOptionElement final : public nsGenericHTMLElement
{
public:
explicit HTMLOptionElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo);
Expand All @@ -36,13 +34,15 @@ class HTMLOptionElement final : public nsGenericHTMLElement,
// 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)
{
Expand Down Expand Up @@ -106,35 +106,39 @@ class HTMLOptionElement final : public nsGenericHTMLElement,

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();

Expand Down
2 changes: 0 additions & 2 deletions dom/html/HTMLOptionsCollection.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
#include "nsGenericHTMLElement.h"
#include "nsTArray.h"

class nsIDOMHTMLOptionElement;

namespace mozilla {
namespace dom {

Expand Down
22 changes: 6 additions & 16 deletions dom/html/HTMLSelectElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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<nsINode> option = do_QueryInterface(aOption);
return mOptions->GetOptionIndex(option->AsElement(), aStartIndex, aForward, aIndex);
}

bool
HTMLSelectElement::IsOptionSelectedByIndex(int32_t aIndex)
{
Expand Down Expand Up @@ -1032,8 +1023,7 @@ HTMLSelectElement::GetValue(DOMString& aValue)
return;
}

DebugOnly<nsresult> rv = option->GetValue(aValue);
MOZ_ASSERT(NS_SUCCEEDED(rv));
option->GetValue(aValue);
}

void
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -1579,7 +1569,7 @@ HTMLSelectElement::SubmitNamesValues(HTMLFormSubmission* aFormSubmission)
}

nsString value;
MOZ_ALWAYS_SUCCEEDS(option->GetValue(value));
option->GetValue(value);

if (keyGenProcessor) {
nsString tmp(value);
Expand Down Expand Up @@ -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;
}
Expand Down
13 changes: 0 additions & 13 deletions dom/html/HTMLSelectElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,19 +360,6 @@ class HTMLSelectElement final : public nsGenericHTMLFormElementWithState,
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
*/
Expand Down
1 change: 0 additions & 1 deletion dom/interfaces/html/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ XPIDL_SOURCES += [
'nsIDOMHTMLHtmlElement.idl',
'nsIDOMHTMLInputElement.idl',
'nsIDOMHTMLMediaElement.idl',
'nsIDOMHTMLOptionElement.idl',
'nsIDOMHTMLScriptElement.idl',
'nsIDOMMozBrowserFrame.idl',
'nsIDOMTimeRanges.idl',
Expand Down
31 changes: 0 additions & 31 deletions dom/interfaces/html/nsIDOMHTMLOptionElement.idl

This file was deleted.

13 changes: 7 additions & 6 deletions dom/webbrowserpersist/WebBrowserPersistLocalDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -1166,14 +1166,15 @@ PersistNodeFixup::FixupNode(nsIDOMNode *aNodeIn,
return rv;
}

nsCOMPtr<nsIDOMHTMLOptionElement> nodeAsOption = do_QueryInterface(aNodeIn);
dom::HTMLOptionElement* nodeAsOption = dom::HTMLOptionElement::FromContent(content);
if (nodeAsOption) {
rv = GetNodeToFixup(aNodeIn, aNodeOut);
if (NS_SUCCEEDED(rv) && *aNodeOut) {
nsCOMPtr<nsIDOMHTMLOptionElement> outElt = do_QueryInterface(*aNodeOut);
bool selected;
nodeAsOption->GetSelected(&selected);
outElt->SetDefaultSelected(selected);
nsCOMPtr<nsIContent> outContent = do_QueryInterface(*aNodeOut);
dom::HTMLOptionElement* outElt = dom::HTMLOptionElement::FromContent(outContent);
bool selected = nodeAsOption->Selected();
IgnoredErrorResult ignored;
outElt->SetDefaultSelected(selected, ignored);
}
return rv;
}
Expand Down
Loading

0 comments on commit 68fa69c

Please sign in to comment.