Commit a07837fd authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

TextControl NG: Port LayoutTextControlSingleLine::NodeAtPoint

... to LayoutNGTextControlSingleLine.

This CL has no behavior changes for now, however this CL fixes at least
four unit test failures with LayoutNGTextField flag.

Bug: 1040826
Change-Id: I9c6677b7de9d595602caa312678856d79ffb94d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2501103
Auto-Submit: Kent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821097}
parent 39e35ad3
......@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/layout/ng/layout_ng_text_control_single_line.h"
#include "third_party/blink/renderer/core/html/forms/text_control_element.h"
#include "third_party/blink/renderer/core/html/shadow/shadow_element_names.h"
#include "third_party/blink/renderer/core/layout/layout_text_control.h"
namespace blink {
......@@ -16,6 +17,18 @@ HTMLElement* LayoutNGTextControlSingleLine::InnerEditorElement() const {
return To<TextControlElement>(GetNode())->InnerEditorElement();
}
Element* LayoutNGTextControlSingleLine::ContainerElement() const {
NOT_DESTROYED();
return To<Element>(GetNode())->UserAgentShadowRoot()->getElementById(
shadow_element_names::kIdTextFieldContainer);
}
Element* LayoutNGTextControlSingleLine::EditingViewPortElement() const {
NOT_DESTROYED();
return To<Element>(GetNode())->UserAgentShadowRoot()->getElementById(
shadow_element_names::kIdEditingViewPort);
}
bool LayoutNGTextControlSingleLine::IsOfType(LayoutObjectType type) const {
return type == kLayoutObjectNGTextControlSingleLine ||
LayoutNGBlockFlow::IsOfType(type);
......@@ -29,4 +42,41 @@ void LayoutNGTextControlSingleLine::StyleDidChange(
StyleRef());
}
bool LayoutNGTextControlSingleLine::NodeAtPoint(
HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset,
HitTestAction hit_test_action) {
NOT_DESTROYED();
if (!LayoutNGBlockFlow::NodeAtPoint(result, hit_test_location,
accumulated_offset, hit_test_action))
return false;
const LayoutObject* stop_node = result.GetHitTestRequest().GetStopNode();
if (stop_node && stop_node->NodeForHitTest() == result.InnerNode())
return true;
// Say that we hit the inner text element if
// - we hit a node inside the inner editor element,
// - we hit the <input> element (e.g. we're over the border or padding), or
// - we hit regions not in any decoration buttons.
Element* container = ContainerElement();
HTMLElement* inner_editor = InnerEditorElement();
Element* view_port = EditingViewPortElement();
if (result.InnerNode()->IsDescendantOf(inner_editor) ||
result.InnerNode() == GetNode() ||
(container && container == result.InnerNode())) {
PhysicalOffset inner_editor_accumulated_offset = accumulated_offset;
if (container && view_port) {
if (auto* view_port_box = view_port->GetLayoutBox())
inner_editor_accumulated_offset += view_port_box->PhysicalLocation();
if (auto* container_box = container->GetLayoutBox())
inner_editor_accumulated_offset += container_box->PhysicalLocation();
}
LayoutTextControl::HitInnerEditorElement(
*this, *inner_editor, result, hit_test_location, accumulated_offset);
}
return true;
}
} // namespace blink
......@@ -16,6 +16,8 @@ class LayoutNGTextControlSingleLine final : public LayoutNGBlockFlow {
private:
HTMLElement* InnerEditorElement() const;
Element* ContainerElement() const;
Element* EditingViewPortElement() const;
bool IsOfType(LayoutObjectType) const override;
......@@ -30,6 +32,11 @@ class LayoutNGTextControlSingleLine final : public LayoutNGBlockFlow {
}
void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
bool NodeAtPoint(HitTestResult& result,
const HitTestLocation& hit_test_location,
const PhysicalOffset& accumulated_offset,
HitTestAction hit_test_action) override;
};
} // namespace blink
......
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