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) { ...@@ -547,9 +547,9 @@ static Node* FindFirstMarkable(Node* node) {
return nullptr; return nullptr;
if (node->GetLayoutObject()->IsText()) if (node->GetLayoutObject()->IsText())
return node; return node;
if (node->GetLayoutObject()->IsTextControl()) if (auto* text_control =
node = ToLayoutTextControl(node->GetLayoutObject()) DynamicTo<LayoutTextControl>(node->GetLayoutObject()))
->GetTextControlElement() node = text_control->GetTextControlElement()
->VisiblePositionForIndex(1) ->VisiblePositionForIndex(1)
.DeepEquivalent() .DeepEquivalent()
.AnchorNode(); .AnchorNode();
......
...@@ -238,8 +238,8 @@ void TextFieldInputType::ForwardEvent(Event& event) { ...@@ -238,8 +238,8 @@ void TextFieldInputType::ForwardEvent(Event& event) {
event.HasInterface(event_interface_names::kWheelEvent) || event.HasInterface(event_interface_names::kWheelEvent) ||
event.type() == event_type_names::kBlur || event.type() == event_type_names::kBlur ||
event.type() == event_type_names::kFocus)) { event.type() == event_type_names::kFocus)) {
LayoutTextControlSingleLine* layout_text_control = auto* layout_text_control =
ToLayoutTextControlSingleLine(GetElement().GetLayoutObject()); To<LayoutTextControlSingleLine>(GetElement().GetLayoutObject());
if (event.type() == event_type_names::kBlur) { if (event.type() == event_type_names::kBlur) {
if (LayoutBox* inner_editor_layout_object = if (LayoutBox* inner_editor_layout_object =
GetElement().InnerEditorElement()->GetLayoutBox()) { GetElement().InnerEditorElement()->GetLayoutBox()) {
......
...@@ -348,8 +348,8 @@ WebInputEventResult KeyboardEventManager::KeyEvent( ...@@ -348,8 +348,8 @@ WebInputEventResult KeyboardEventManager::KeyEvent(
void KeyboardEventManager::CapsLockStateMayHaveChanged() { void KeyboardEventManager::CapsLockStateMayHaveChanged() {
if (Element* element = frame_->GetDocument()->FocusedElement()) { if (Element* element = frame_->GetDocument()->FocusedElement()) {
if (LayoutObject* r = element->GetLayoutObject()) { if (LayoutObject* r = element->GetLayoutObject()) {
if (r->IsTextField()) if (auto* text_control = DynamicTo<LayoutTextControlSingleLine>(r))
ToLayoutTextControlSingleLine(r)->CapsLockStateMayHaveChanged(); text_control->CapsLockStateMayHaveChanged();
} }
} }
} }
......
...@@ -92,7 +92,12 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow { ...@@ -92,7 +92,12 @@ class CORE_EXPORT LayoutTextControl : public LayoutBlockFlow {
bool CanBeProgramaticallyScrolled() const final { return true; } 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 } // namespace blink
......
...@@ -89,7 +89,12 @@ class LayoutTextControlSingleLine : public LayoutTextControl { ...@@ -89,7 +89,12 @@ class LayoutTextControlSingleLine : public LayoutTextControl {
bool should_draw_caps_lock_indicator_; 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) { ...@@ -24,7 +24,7 @@ TEST_F(LayoutTextControlSingleLineTest, VisualOverflowCleared) {
<input id=input type="text"></input. <input id=input type="text"></input.
)HTML"); )HTML");
auto* input = auto* input =
ToLayoutTextControlSingleLine(GetLayoutObjectByElementId("input")); To<LayoutTextControlSingleLine>(GetLayoutObjectByElementId("input"));
if (::features::IsFormControlsRefreshEnabled()) { if (::features::IsFormControlsRefreshEnabled()) {
EXPECT_EQ(LayoutRect(-3, -3, 74, 72), input->SelfVisualOverflowRect()); EXPECT_EQ(LayoutRect(-3, -3, 74, 72), input->SelfVisualOverflowRect());
} else { } else {
......
...@@ -580,11 +580,11 @@ bool AXLayoutObject::IsPlaceholder() const { ...@@ -580,11 +580,11 @@ bool AXLayoutObject::IsPlaceholder() const {
return false; return false;
LayoutObject* parent_layout_object = parent_object->GetLayoutObject(); 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; return false;
LayoutTextControl* layout_text_control =
ToLayoutTextControl(parent_layout_object);
DCHECK(layout_text_control); DCHECK(layout_text_control);
TextControlElement* text_control_element = 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