mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 08:15:31 +00:00
Bug 1574852 - part 68: Make HTMLEditRules::GetDefinitionListItemTypes()
to a stack class r=m_kato
It scans children and returns whether `<dt>` and `<dd>` are found or not. So, we can make it a stack class and makes caller pick the necessary value with getter methods. Differential Revision: https://phabricator.services.mozilla.com/D44461 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
f213a8f6d0
commit
c4c3b160eb
@ -974,11 +974,13 @@ nsresult HTMLEditRules::GetListItemState(bool* aMixed, bool* aLI, bool* aDT,
|
||||
} else if (node->IsHTMLElement(nsGkAtoms::dd)) {
|
||||
*aDD = true;
|
||||
} else if (node->IsHTMLElement(nsGkAtoms::dl)) {
|
||||
if (*aDT && *aDD) {
|
||||
continue;
|
||||
}
|
||||
// need to look inside dl and see which types of items it has
|
||||
bool bDT, bDD;
|
||||
GetDefinitionListItemTypes(node->AsElement(), &bDT, &bDD);
|
||||
*aDT |= bDT;
|
||||
*aDD |= bDD;
|
||||
DefinitionListItemScanner scanner(*node->AsElement());
|
||||
*aDT |= scanner.DTElementFound();
|
||||
*aDD |= scanner.DDElementFound();
|
||||
} else {
|
||||
bNonList = true;
|
||||
}
|
||||
@ -7871,24 +7873,6 @@ Element* HTMLEditor::GetDeepestEditableOnlyChildDivBlockquoteOrListElement(
|
||||
return parentElement;
|
||||
}
|
||||
|
||||
void HTMLEditRules::GetDefinitionListItemTypes(dom::Element* aElement,
|
||||
bool* aDT, bool* aDD) const {
|
||||
MOZ_ASSERT(aElement);
|
||||
MOZ_ASSERT(aElement->IsHTMLElement(nsGkAtoms::dl));
|
||||
MOZ_ASSERT(aDT);
|
||||
MOZ_ASSERT(aDD);
|
||||
|
||||
*aDT = *aDD = false;
|
||||
for (nsIContent* child = aElement->GetFirstChild(); child;
|
||||
child = child->GetNextSibling()) {
|
||||
if (child->IsHTMLElement(nsGkAtoms::dt)) {
|
||||
*aDT = true;
|
||||
} else if (child->IsHTMLElement(nsGkAtoms::dd)) {
|
||||
*aDD = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsresult HTMLEditRules::GetParagraphFormatNodes(
|
||||
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes) {
|
||||
MOZ_ASSERT(IsEditorDataAvailable());
|
||||
|
@ -367,8 +367,6 @@ class HTMLEditRules : public TextEditRules {
|
||||
OutdentPartOfBlock(Element& aBlockElement, nsIContent& aStartOfOutdent,
|
||||
nsIContent& aEndOutdent, bool aIsBlockIndentedWithCSS);
|
||||
|
||||
void GetDefinitionListItemTypes(Element* aElement, bool* aDT,
|
||||
bool* aDD) const;
|
||||
MOZ_CAN_RUN_SCRIPT
|
||||
nsresult GetParagraphFormatNodes(
|
||||
nsTArray<OwningNonNull<nsINode>>& outArrayOfNodes);
|
||||
|
@ -6,15 +6,13 @@
|
||||
#ifndef HTMLEditUtils_h
|
||||
#define HTMLEditUtils_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
#include "nsGkAtoms.h"
|
||||
|
||||
class nsAtom;
|
||||
class nsINode;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class Element;
|
||||
} // namespace dom
|
||||
|
||||
class HTMLEditUtils final {
|
||||
public:
|
||||
@ -64,6 +62,42 @@ class HTMLEditUtils final {
|
||||
static EditAction GetEditActionForAlignment(const nsAString& aAlignType);
|
||||
};
|
||||
|
||||
/**
|
||||
* DefinitionListItemScanner() scans given `<dl>` element's children.
|
||||
* Then, you can check whether `<dt>` and/or `<dd>` elements are in it.
|
||||
*/
|
||||
class MOZ_STACK_CLASS DefinitionListItemScanner final {
|
||||
public:
|
||||
DefinitionListItemScanner() = delete;
|
||||
explicit DefinitionListItemScanner(dom::Element& aDLElement) {
|
||||
MOZ_ASSERT(aDLElement.IsHTMLElement(nsGkAtoms::dl));
|
||||
for (nsIContent* child = aDLElement.GetFirstChild(); child;
|
||||
child = child->GetNextSibling()) {
|
||||
if (child->IsHTMLElement(nsGkAtoms::dt)) {
|
||||
mDTFound = true;
|
||||
if (mDDFound) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (child->IsHTMLElement(nsGkAtoms::dd)) {
|
||||
mDDFound = true;
|
||||
if (mDTFound) {
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DTElementFound() const { return mDTFound; }
|
||||
bool DDElementFound() const { return mDDFound; }
|
||||
|
||||
private:
|
||||
bool mDTFound = false;
|
||||
bool mDDFound = false;
|
||||
};
|
||||
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // #ifndef HTMLEditUtils_h
|
||||
|
Loading…
Reference in New Issue
Block a user