Commit 30038c37 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

TextControl NG: Remove DowncastTraits<LayoutTextControl>

Text controls in LayoutNG won't inherit from LayoutTextControl. We
should avoid operations on LayoutTextControl.

All of usages of casting to LayoutTextControl were to get
TextControlElements. This CL replaces them with
To<TextControlElement>(layout_object->GetNode()).

This CL has no behavior changes.

Bug: 1040826
Change-Id: Ic6879147314e91cdaf361734e8d6a06300eaeb6f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438097
Commit-Queue: Kent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Auto-Submit: Kent Tamura <tkent@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812015}
parent 44a9864d
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#include "third_party/blink/renderer/core/html/forms/html_input_element.h" #include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html_names.h" #include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/input_type_names.h" #include "third_party/blink/renderer/core/input_type_names.h"
#include "third_party/blink/renderer/core/layout/layout_text_control.h" #include "third_party/blink/renderer/core/layout/layout_object.h"
#include "third_party/blink/renderer/core/loader/empty_clients.h" #include "third_party/blink/renderer/core/loader/empty_clients.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
...@@ -551,20 +551,21 @@ void SpellChecker::RemoveSpellingMarkersUnderWords( ...@@ -551,20 +551,21 @@ void SpellChecker::RemoveSpellingMarkersUnderWords(
static Node* FindFirstMarkable(Node* node) { static Node* FindFirstMarkable(Node* node) {
while (node) { while (node) {
if (!node->GetLayoutObject()) LayoutObject* layout_object = node->GetLayoutObject();
if (!layout_object)
return nullptr; return nullptr;
if (node->GetLayoutObject()->IsText()) if (layout_object->IsText())
return node; return node;
if (auto* text_control = if (layout_object->IsTextControl()) {
DynamicTo<LayoutTextControl>(node->GetLayoutObject())) node = To<TextControlElement>(node)
node = text_control->GetTextControlElement()
->VisiblePositionForIndex(1) ->VisiblePositionForIndex(1)
.DeepEquivalent() .DeepEquivalent()
.AnchorNode(); .AnchorNode();
else if (node->hasChildren()) } else if (node->hasChildren()) {
node = node->firstChild(); node = node->firstChild();
else } else {
node = node->nextSibling(); node = node->nextSibling();
}
} }
return nullptr; return nullptr;
......
...@@ -269,6 +269,14 @@ DEFINE_TEXT_CONTROL_CASTS(const TextControlElement, const Node); ...@@ -269,6 +269,14 @@ DEFINE_TEXT_CONTROL_CASTS(const TextControlElement, const Node);
#undef DEFINE_TEXT_CONTROL_CASTS #undef DEFINE_TEXT_CONTROL_CASTS
template <>
struct DowncastTraits<TextControlElement> {
static bool AllowFrom(const Node& node) {
return node.HasTagName(html_names::kInputTag) ||
node.HasTagName(html_names::kTextareaTag);
}
};
TextControlElement* EnclosingTextControl(const Position&); TextControlElement* EnclosingTextControl(const Position&);
TextControlElement* EnclosingTextControl(const PositionInFlatTree&); TextControlElement* EnclosingTextControl(const PositionInFlatTree&);
TextControlElement* EnclosingTextControl(const Node*); TextControlElement* EnclosingTextControl(const Node*);
......
...@@ -99,13 +99,6 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow { ...@@ -99,13 +99,6 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
} }
}; };
template <>
struct DowncastTraits<LayoutTextControl> {
static bool AllowFrom(const LayoutObject& object) {
return object.IsTextControl();
}
};
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_TEXT_CONTROL_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_LAYOUT_TEXT_CONTROL_H_
...@@ -71,7 +71,6 @@ ...@@ -71,7 +71,6 @@
#include "third_party/blink/renderer/core/layout/layout_table_cell.h" #include "third_party/blink/renderer/core/layout/layout_table_cell.h"
#include "third_party/blink/renderer/core/layout/layout_table_row.h" #include "third_party/blink/renderer/core/layout/layout_table_row.h"
#include "third_party/blink/renderer/core/layout/layout_table_section.h" #include "third_party/blink/renderer/core/layout/layout_table_section.h"
#include "third_party/blink/renderer/core/layout/layout_text_control.h"
#include "third_party/blink/renderer/core/layout/layout_text_fragment.h" #include "third_party/blink/renderer/core/layout/layout_text_fragment.h"
#include "third_party/blink/renderer/core/layout/layout_view.h" #include "third_party/blink/renderer/core/layout/layout_view.h"
#include "third_party/blink/renderer/core/layout/list_marker.h" #include "third_party/blink/renderer/core/layout/list_marker.h"
...@@ -592,18 +591,11 @@ bool AXLayoutObject::IsPlaceholder() const { ...@@ -592,18 +591,11 @@ bool AXLayoutObject::IsPlaceholder() const {
return false; return false;
LayoutObject* parent_layout_object = parent_object->GetLayoutObject(); LayoutObject* parent_layout_object = parent_object->GetLayoutObject();
auto* layout_text_control = if (!parent_layout_object || !parent_layout_object->IsTextControl())
DynamicTo<LayoutTextControl>(parent_layout_object);
if (!layout_text_control)
return false;
DCHECK(layout_text_control);
TextControlElement* text_control_element =
layout_text_control->GetTextControlElement();
if (!text_control_element)
return false; return false;
const auto* text_control_element =
To<TextControlElement>(parent_layout_object->GetNode());
HTMLElement* placeholder_element = text_control_element->PlaceholderElement(); HTMLElement* placeholder_element = text_control_element->PlaceholderElement();
return GetElement() == static_cast<Element*>(placeholder_element); return GetElement() == static_cast<Element*>(placeholder_element);
......
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