Commit c42b37fa authored by Abhijeet Kandalkar's avatar Abhijeet Kandalkar Committed by Commit Bot

Use new downcast helper for LayoutTextControl & LayoutTextControlSingleLine

This CL has two goals to use new downcast helper for
blink::LayoutTextControl & blink::LayoutTextControlSingleLine.

Bug: 891908
Change-Id: I721ae55a1252a79b03575d5f2cd1c2a7ad3a0727
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2016697
Commit-Queue: Abhijeet Kandalkar <abhijeet@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748119}
parent b624321a
......@@ -547,9 +547,9 @@ static Node* FindFirstMarkable(Node* node) {
return nullptr;
if (node->GetLayoutObject()->IsText())
return node;
if (node->GetLayoutObject()->IsTextControl())
node = ToLayoutTextControl(node->GetLayoutObject())
->GetTextControlElement()
if (auto* text_control =
DynamicTo<LayoutTextControl>(node->GetLayoutObject()))
node = text_control->GetTextControlElement()
->VisiblePositionForIndex(1)
.DeepEquivalent()
.AnchorNode();
......
......@@ -238,8 +238,8 @@ void TextFieldInputType::ForwardEvent(Event& event) {
event.HasInterface(event_interface_names::kWheelEvent) ||
event.type() == event_type_names::kBlur ||
event.type() == event_type_names::kFocus)) {
LayoutTextControlSingleLine* layout_text_control =
ToLayoutTextControlSingleLine(GetElement().GetLayoutObject());
auto* layout_text_control =
To<LayoutTextControlSingleLine>(GetElement().GetLayoutObject());
if (event.type() == event_type_names::kBlur) {
if (LayoutBox* inner_editor_layout_object =
GetElement().InnerEditorElement()->GetLayoutBox()) {
......
......@@ -348,8 +348,8 @@ WebInputEventResult KeyboardEventManager::KeyEvent(
void KeyboardEventManager::CapsLockStateMayHaveChanged() {
if (Element* element = frame_->GetDocument()->FocusedElement()) {
if (LayoutObject* r = element->GetLayoutObject()) {
if (r->IsTextField())
ToLayoutTextControlSingleLine(r)->CapsLockStateMayHaveChanged();
if (auto* text_control = DynamicTo<LayoutTextControlSingleLine>(r))
text_control->CapsLockStateMayHaveChanged();
}
}
}
......
......@@ -92,7 +92,12 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
bool CanBeProgramaticallyScrolled() const final { return true; }
};
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTextControl, IsTextControl());
template <>
struct DowncastTraits<LayoutTextControl> {
static bool AllowFrom(const LayoutObject& object) {
return object.IsTextControl();
}
};
} // namespace blink
......
......@@ -89,7 +89,12 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
bool should_draw_caps_lock_indicator_;
};
DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutTextControlSingleLine, IsTextField());
template <>
struct DowncastTraits<LayoutTextControlSingleLine> {
static bool AllowFrom(const LayoutObject& object) {
return object.IsTextField();
}
};
// ----------------------------
......
......@@ -24,7 +24,7 @@ TEST_F(LayoutTextControlSingleLineTest, VisualOverflowCleared) {
<input id=input type="text"></input.
)HTML");
auto* input =
ToLayoutTextControlSingleLine(GetLayoutObjectByElementId("input"));
To<LayoutTextControlSingleLine>(GetLayoutObjectByElementId("input"));
if (::features::IsFormControlsRefreshEnabled()) {
EXPECT_EQ(LayoutRect(-3, -3, 74, 72), input->SelfVisualOverflowRect());
} else {
......
......@@ -580,11 +580,11 @@ bool AXLayoutObject::IsPlaceholder() const {
return false;
LayoutObject* parent_layout_object = parent_object->GetLayoutObject();
if (!parent_layout_object || !parent_layout_object->IsTextControl())
auto* layout_text_control =
DynamicTo<LayoutTextControl>(parent_layout_object);
if (!layout_text_control)
return false;
LayoutTextControl* layout_text_control =
ToLayoutTextControl(parent_layout_object);
DCHECK(layout_text_control);
TextControlElement* text_control_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