Commit 461b3245 authored by Anupam Snigdha's avatar Anupam Snigdha Committed by Commit Bot

Add helper functions for list item and list element tags.

Added helper functions that check whether a given node has list or
list items tags. This is used in editing commands for list related
operations.

Bug: 942133
Change-Id: I950a0c8a5e0b87eeed091d68cebab921ddc55d67
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2527961
Auto-Submit: Anupam Snigdha <snianu@microsoft.com>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825574}
parent c00f6f20
...@@ -1734,14 +1734,10 @@ bool CompositeEditCommand::BreakOutOfEmptyListItem( ...@@ -1734,14 +1734,10 @@ bool CompositeEditCommand::BreakOutOfEmptyListItem(
Node* next_list_node = empty_list_item->IsElementNode() Node* next_list_node = empty_list_item->IsElementNode()
? ElementTraversal::NextSibling(*empty_list_item) ? ElementTraversal::NextSibling(*empty_list_item)
: empty_list_item->nextSibling(); : empty_list_item->nextSibling();
if (next_list_node && (list_node->HasTagName(html_names::kOlTag) || if (next_list_node && IsListElementTag(list_node)) {
list_node->HasTagName(html_names::kUlTag) ||
list_node->HasTagName(html_names::kDlTag))) {
// If emptyListItem follows another list item or nested list, split the list // If emptyListItem follows another list item or nested list, split the list
// node. // node.
if (previous_list_node->HasTagName(html_names::kLiTag) || if (IsListItemTag(previous_list_node) ||
previous_list_node->HasTagName(html_names::kDdTag) ||
previous_list_node->HasTagName(html_names::kDtTag) ||
IsHTMLListElement(previous_list_node)) { IsHTMLListElement(previous_list_node)) {
SplitElement(To<Element>(list_node), empty_list_item); SplitElement(To<Element>(list_node), empty_list_item);
} }
......
...@@ -383,13 +383,7 @@ Node* EnclosingListChild(const Node* node) { ...@@ -383,13 +383,7 @@ Node* EnclosingListChild(const Node* node) {
// instead of node->parentNode() // instead of node->parentNode()
for (Node* n = const_cast<Node*>(node); n && n->parentNode(); for (Node* n = const_cast<Node*>(node); n && n->parentNode();
n = n->parentNode()) { n = n->parentNode()) {
if (((n->HasTagName(html_names::kLiTag) || if ((IsListItemTag(n) || IsListElementTag(n->parentNode())) && n != root) {
n->HasTagName(html_names::kDdTag) ||
n->HasTagName(html_names::kDtTag)) ||
(n->parentNode()->HasTagName(html_names::kUlTag) ||
n->parentNode()->HasTagName(html_names::kOlTag) ||
n->parentNode()->HasTagName(html_names::kDlTag))) &&
n != root) {
return n; return n;
} }
if (n == root || IsTableCell(n)) if (n == root || IsTableCell(n))
......
...@@ -1132,6 +1132,18 @@ bool IsListItem(const Node* n) { ...@@ -1132,6 +1132,18 @@ bool IsListItem(const Node* n) {
n->GetLayoutObject()->IsListItemIncludingNG(); n->GetLayoutObject()->IsListItemIncludingNG();
} }
bool IsListItemTag(const Node* n) {
return n && (n->HasTagName(html_names::kLiTag) ||
n->HasTagName(html_names::kDdTag) ||
n->HasTagName(html_names::kDtTag));
}
bool IsListElementTag(const Node* n) {
return n && (n->HasTagName(html_names::kUlTag) ||
n->HasTagName(html_names::kOlTag) ||
n->HasTagName(html_names::kDlTag));
}
bool IsPresentationalHTMLElement(const Node* node) { bool IsPresentationalHTMLElement(const Node* node) {
const auto* element = DynamicTo<HTMLElement>(node); const auto* element = DynamicTo<HTMLElement>(node);
if (!element) if (!element)
......
...@@ -166,6 +166,8 @@ bool IsDisplayInsideTable(const Node*); ...@@ -166,6 +166,8 @@ bool IsDisplayInsideTable(const Node*);
bool IsTableCell(const Node*); bool IsTableCell(const Node*);
bool IsHTMLListElement(const Node*); bool IsHTMLListElement(const Node*);
bool IsListItem(const Node*); bool IsListItem(const Node*);
bool IsListItemTag(const Node*);
bool IsListElementTag(const Node*);
bool IsPresentationalHTMLElement(const Node*); bool IsPresentationalHTMLElement(const Node*);
bool IsRenderedAsNonInlineTableImageOrHR(const Node*); bool IsRenderedAsNonInlineTableImageOrHR(const Node*);
bool IsNonTableCellHTMLBlockElement(const Node*); bool IsNonTableCellHTMLBlockElement(const Node*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment