Commit d138371e authored by Andrey Kraynov's avatar Andrey Kraynov Committed by Commit Bot

Change CanMergeLists() function to take |const Element&| instead of

|Element*| objects.

Bug: 766448
Change-Id: I5c195095cc692f3cc3fd6d7fb68fbaf98ffc875e
Reviewed-on: https://chromium-review.googlesource.com/673146Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Andrey Kraynov <iceman@yandex-team.ru>
Cr-Commit-Position: refs/heads/master@{#504360}
parent 651834b6
......@@ -1475,23 +1475,22 @@ static bool IsVisiblyAdjacent(const Position& first, const Position& second) {
.DeepEquivalent();
}
bool CanMergeLists(Element* first_list, Element* second_list) {
if (!first_list || !second_list || !first_list->IsHTMLElement() ||
!second_list->IsHTMLElement())
bool CanMergeLists(const Element& first_list, const Element& second_list) {
if (!first_list.IsHTMLElement() || !second_list.IsHTMLElement())
return false;
DCHECK(!NeedsLayoutTreeUpdate(*first_list));
DCHECK(!NeedsLayoutTreeUpdate(*second_list));
return first_list->HasTagName(
DCHECK(!NeedsLayoutTreeUpdate(first_list));
DCHECK(!NeedsLayoutTreeUpdate(second_list));
return first_list.HasTagName(
second_list
->TagQName()) // make sure the list types match (ol vs. ul)
&& HasEditableStyle(*first_list) &&
HasEditableStyle(*second_list) // both lists are editable
&& RootEditableElement(*first_list) ==
RootEditableElement(
*second_list) // don't cross editing boundaries
&& IsVisiblyAdjacent(Position::InParentAfterNode(*first_list),
Position::InParentBeforeNode(*second_list));
.TagQName()) // make sure the list types match (ol vs. ul)
&& HasEditableStyle(first_list) &&
HasEditableStyle(second_list) // both lists are editable
&&
RootEditableElement(first_list) ==
RootEditableElement(second_list) // don't cross editing boundaries
&& IsVisiblyAdjacent(Position::InParentAfterNode(first_list),
Position::InParentBeforeNode(second_list));
// Make sure there is no visible content between this li and the previous list
}
......
......@@ -367,7 +367,7 @@ HTMLSpanElement* CreateTabSpanElement(Document&, const String& tab_text);
// Boolean functions on Element
bool CanMergeLists(Element* first_list, Element* second_list);
bool CanMergeLists(const Element& first_list, const Element& second_list);
CORE_EXPORT bool ElementCannotHaveEndTag(const Node&);
......
......@@ -68,6 +68,13 @@ static bool IsTableRowEmpty(Node* row) {
return true;
}
static bool CanMergeListElements(Element* first_list, Element* second_list) {
if (!first_list || !second_list || first_list == second_list)
return false;
return CanMergeLists(*first_list, *second_list);
}
DeleteSelectionCommand::DeleteSelectionCommand(
Document& document,
bool smart_delete,
......@@ -877,10 +884,8 @@ void DeleteSelectionCommand::MergeParagraphs(EditingState* editing_state) {
Node* list_item_in_second_paragraph =
EnclosingNodeOfType(downstream_end_, IsListItem);
if (list_item_in_first_paragraph && list_item_in_second_paragraph &&
list_item_in_first_paragraph->parentElement() !=
list_item_in_second_paragraph->parentElement() &&
CanMergeLists(list_item_in_first_paragraph->parentElement(),
list_item_in_second_paragraph->parentElement())) {
CanMergeListElements(list_item_in_first_paragraph->parentElement(),
list_item_in_second_paragraph->parentElement())) {
MergeIdenticalElements(list_item_in_first_paragraph->parentElement(),
list_item_in_second_paragraph->parentElement(),
editing_state);
......
......@@ -134,14 +134,15 @@ bool IndentOutdentCommand::TryIndentingAsListItem(const Position& start,
}
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (CanMergeLists(previous_list, new_list)) {
DCHECK(new_list);
if (previous_list && CanMergeLists(*previous_list, *new_list)) {
MergeIdenticalElements(previous_list, new_list, editing_state);
if (editing_state->IsAborted())
return false;
}
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (CanMergeLists(new_list, next_list)) {
if (next_list && CanMergeLists(*new_list, *next_list)) {
MergeIdenticalElements(new_list, next_list, editing_state);
if (editing_state->IsAborted())
return false;
......
......@@ -72,10 +72,11 @@ HTMLUListElement* InsertListCommand::FixOrphanedListChild(
HTMLElement* InsertListCommand::MergeWithNeighboringLists(
HTMLElement* passed_list,
EditingState* editing_state) {
DCHECK(passed_list);
HTMLElement* list = passed_list;
Element* previous_list = ElementTraversal::PreviousSibling(*list);
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (CanMergeLists(previous_list, list)) {
if (previous_list && CanMergeLists(*previous_list, *list)) {
MergeIdenticalElements(previous_list, list, editing_state);
if (editing_state->IsAborted())
return nullptr;
......@@ -90,7 +91,7 @@ HTMLElement* InsertListCommand::MergeWithNeighboringLists(
HTMLElement* next_list = ToHTMLElement(next_sibling);
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (CanMergeLists(list, next_list)) {
if (CanMergeLists(*list, *next_list)) {
MergeIdenticalElements(list, next_list, editing_state);
if (editing_state->IsAborted())
return nullptr;
......@@ -599,7 +600,7 @@ void InsertListCommand::ListifyParagraph(const VisiblePosition& original_start,
return;
GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
if (CanMergeLists(previous_list, next_list))
if (previous_list && next_list && CanMergeLists(*previous_list, *next_list))
MergeIdenticalElements(previous_list, next_list, editing_state);
return;
......
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