Bug 1462737. Make AsElement() not compile when called on Element or some subclass. r=mccr8

It's just noise if we already have an Element.
This commit is contained in:
Boris Zbarsky 2018-05-18 23:37:56 -04:00
parent 69f3dde06c
commit a02a40bdb5
9 changed files with 43 additions and 44 deletions

View File

@ -565,7 +565,7 @@ CandidateFinder::OrderedCandidates()
nsTArray<nsCOMPtr<Element>> orderedElements(mCandidates.Count());
for (Element* child = mDoc->GetFirstElementChild(); child; child = child->GetNextElementSibling()) {
if (!Traverse(child->AsElement(), orderedElements)) {
if (!Traverse(child, orderedElements)) {
break;
}
}

View File

@ -509,7 +509,6 @@ private:
static nsCheapSetOperator SetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aDir)
{
MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element");
aEntry->GetKey()->SetDirectionality(*reinterpret_cast<Directionality*>(aDir),
true);
return OpNext;
@ -523,7 +522,6 @@ private:
static nsCheapSetOperator ResetNodeDirection(nsPtrHashKey<Element>* aEntry, void* aData)
{
MOZ_ASSERT(aEntry->GetKey()->IsElement(), "Must be an Element");
// run the downward propagation algorithm
// and remove the text node from the map
nsTextNodeDirectionalityMapAndElement* data =

View File

@ -1964,6 +1964,10 @@ private:
nsIScrollableFrame* GetScrollFrame(nsIFrame **aStyledFrame = nullptr,
FlushType aFlushType = FlushType::Layout);
// Prevent people from doing pointless checks/casts on Element instances.
void IsElement() = delete;
void AsElement() = delete;
// Data members
EventStates mState;
// Per-node data managed by Servo.

View File

@ -11263,7 +11263,7 @@ nsIDocument::ApplyFullscreen(const FullscreenRequest& aRequest)
break;
}
nsIDocument* parent = child->GetParentDocument();
Element* element = parent->FindContentForSubDocument(child)->AsElement();
Element* element = parent->FindContentForSubDocument(child);
if (static_cast<nsDocument*>(parent)->FullScreenStackPush(element)) {
changed.AppendElement(parent);
child = parent;

View File

@ -534,7 +534,7 @@ HTMLSelectElement::GetFirstOptionIndex(nsIContent* aOptions)
int32_t listIndex = -1;
HTMLOptionElement* optElement = HTMLOptionElement::FromNode(aOptions);
if (optElement) {
mOptions->GetOptionIndex(optElement->AsElement(), 0, true, &listIndex);
mOptions->GetOptionIndex(optElement, 0, true, &listIndex);
return listIndex;
}

View File

@ -5125,7 +5125,7 @@ HTMLEditRules::ConvertListType(Element* aList,
}
if (aList->IsHTMLElement(aListType)) {
RefPtr<dom::Element> list = aList->AsElement();
RefPtr<dom::Element> list = aList;
return list.forget();
}
@ -7407,7 +7407,7 @@ HTMLEditRules::SplitParagraph(
}
// Remove ID attribute on the paragraph from the existing right node.
rv = htmlEditor->RemoveAttributeWithTransaction(*aParentDivOrP.AsElement(),
rv = htmlEditor->RemoveAttributeWithTransaction(aParentDivOrP,
*nsGkAtoms::id);
NS_ENSURE_SUCCESS(rv, rv);

View File

@ -584,7 +584,7 @@ nsNumberControlFrame::IsFocused() const
// Normally this depends on the state of our anonymous text control (which
// takes focus for us), but in the case that it does not have a frame we will
// have focus ourself.
return mTextField->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS) ||
return mTextField->State().HasState(NS_EVENT_STATE_FOCUS) ||
mContent->AsElement()->State().HasState(NS_EVENT_STATE_FOCUS);
}

View File

@ -2032,17 +2032,15 @@ nsTreeBodyFrame::PrefillPropertyArray(int32_t aRowIndex, nsTreeColumn* aCol)
}
// Read special properties from attributes on the column content node
if (aCol->mContent->IsElement() &&
aCol->mContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::insertbefore,
nsGkAtoms::_true,
eCaseMatters))
if (aCol->mContent->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::insertbefore,
nsGkAtoms::_true,
eCaseMatters))
mScratchArray.AppendElement(nsGkAtoms::insertbefore);
if (aCol->mContent->IsElement() &&
aCol->mContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::insertafter,
nsGkAtoms::_true,
eCaseMatters))
if (aCol->mContent->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::insertafter,
nsGkAtoms::_true,
eCaseMatters))
mScratchArray.AppendElement(nsGkAtoms::insertafter);
}
}

View File

@ -265,7 +265,7 @@ nsTreeColumn::Invalidate()
NS_ENSURE_TRUE(frame, NS_ERROR_FAILURE);
// Fetch the Id.
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mId);
mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, mId);
// If we have an Id, cache the Id as an atom.
if (!mId.IsEmpty()) {
@ -273,7 +273,7 @@ nsTreeColumn::Invalidate()
}
// Cache our index.
nsTreeUtils::GetColumnIndex(mContent->AsElement(), &mIndex);
nsTreeUtils::GetColumnIndex(mContent, &mIndex);
const nsStyleVisibility* vis = frame->StyleVisibility();
@ -294,38 +294,38 @@ nsTreeColumn::Invalidate()
// Figure out if we're the primary column (that has to have indentation
// and twisties drawn.
mIsPrimary = mContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::primary,
nsGkAtoms::_true,
eCaseMatters);
mIsPrimary = mContent->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::primary,
nsGkAtoms::_true,
eCaseMatters);
// Figure out if we're a cycling column (one that doesn't cause a selection
// to happen).
mIsCycler =
mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::cycler,
nsGkAtoms::_true, eCaseMatters);
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::cycler,
nsGkAtoms::_true, eCaseMatters);
mIsEditable =
mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
nsGkAtoms::_true, eCaseMatters);
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::editable,
nsGkAtoms::_true, eCaseMatters);
mIsSelectable =
!mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::selectable,
nsGkAtoms::_false, eCaseMatters);
!mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::selectable,
nsGkAtoms::_false, eCaseMatters);
mOverflow =
mContent->AsElement()->AttrValueIs(kNameSpaceID_None, nsGkAtoms::overflow,
nsGkAtoms::_true, eCaseMatters);
mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::overflow,
nsGkAtoms::_true, eCaseMatters);
// Figure out our column type. Default type is text.
mType = nsITreeColumn::TYPE_TEXT;
static Element::AttrValuesArray typestrings[] =
{&nsGkAtoms::checkbox, &nsGkAtoms::password,
nullptr};
switch (mContent->AsElement()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::type,
typestrings,
eCaseMatters)) {
switch (mContent->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::type,
typestrings,
eCaseMatters)) {
case 0: mType = nsITreeColumn::TYPE_CHECKBOX; break;
case 1: mType = nsITreeColumn::TYPE_PASSWORD; break;
}
@ -334,9 +334,9 @@ nsTreeColumn::Invalidate()
mCropStyle = 0;
static Element::AttrValuesArray cropstrings[] =
{&nsGkAtoms::center, &nsGkAtoms::left, &nsGkAtoms::start, nullptr};
switch (mContent->AsElement()->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::crop, cropstrings,
eCaseMatters)) {
switch (mContent->FindAttrValueIn(kNameSpaceID_None,
nsGkAtoms::crop, cropstrings,
eCaseMatters)) {
case 0:
mCropStyle = 1;
break;
@ -535,11 +535,10 @@ nsTreeColumns::GetKeyColumn()
for (nsTreeColumn* currCol = mFirstColumn; currCol; currCol = currCol->GetNext()) {
// Skip hidden columns.
if (!currCol->mContent ||
!currCol->mContent->IsElement() ||
currCol->mContent->AsElement()->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::hidden,
nsGkAtoms::_true,
eCaseMatters))
currCol->mContent->AttrValueIs(kNameSpaceID_None,
nsGkAtoms::hidden,
nsGkAtoms::_true,
eCaseMatters))
continue;
// Skip non-text column