summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-23 21:06:24 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-23 21:08:25 +0200
commit634ce37663e1a77532c1612989d09166c3209841 (patch)
tree62821dfe68ff94d38930729b80b1d27e013e6435
parenta01fd7ecc5a1679e2fe9a223dd8688842967d912 (diff)
downloadserenity-634ce37663e1a77532c1612989d09166c3209841.zip
LibWeb: Make hit-testing work with display: inline-block;
When hit testing encountered a block with inline children, we assumed that the inline children are nothing but text boxes. An inline-block box is actually a block child of a block with inline children, so we have to handle that scenario as well. :^) Fixes #2353.
-rw-r--r--Base/home/anon/www/inline-block-link.html15
-rw-r--r--Base/home/anon/www/welcome.html1
-rw-r--r--Libraries/LibWeb/Layout/LayoutBlock.cpp2
3 files changed, 18 insertions, 0 deletions
diff --git a/Base/home/anon/www/inline-block-link.html b/Base/home/anon/www/inline-block-link.html
new file mode 100644
index 0000000000..c74a691e04
--- /dev/null
+++ b/Base/home/anon/www/inline-block-link.html
@@ -0,0 +1,15 @@
+<html>
+ <head>
+ <style>
+ p {
+ display: inline-block;
+ }
+ </style>
+ </head>
+ <body>
+ <p>
+ Here is some test text.
+ Here is a <a href="http://example.com">test link</a>.
+ </p>
+ </body>
+</html>
diff --git a/Base/home/anon/www/welcome.html b/Base/home/anon/www/welcome.html
index 927651e724..adb12f2f03 100644
--- a/Base/home/anon/www/welcome.html
+++ b/Base/home/anon/www/welcome.html
@@ -28,6 +28,7 @@ span#ua {
<p>Your user agent is: <b><span id="ua"></span></b></p>
<p>Some small test pages:</p>
<ul>
+ <li><a href="inline-block-link.html">link inside display: inline-block</a></li>
<li><a href="set-interval.html">setInterval() test</a></li>
<li><a href="html-escape-test.html">html character escape test</a></li>
<li><a href="location.html">window.location property</a></li>
diff --git a/Libraries/LibWeb/Layout/LayoutBlock.cpp b/Libraries/LibWeb/Layout/LayoutBlock.cpp
index 63fa16c5f6..4d83f405be 100644
--- a/Libraries/LibWeb/Layout/LayoutBlock.cpp
+++ b/Libraries/LibWeb/Layout/LayoutBlock.cpp
@@ -391,6 +391,8 @@ HitTestResult LayoutBlock::hit_test(const Gfx::Point& position) const
for (auto& line_box : m_line_boxes) {
for (auto& fragment : line_box.fragments()) {
if (enclosing_int_rect(fragment.rect()).contains(position)) {
+ if (fragment.layout_node().is_block())
+ return to<LayoutBlock>(fragment.layout_node()).hit_test(position);
return { fragment.layout_node(), fragment.text_index_at(position.x()) };
}
}