offsetTop/offsetLeft of inline elements

- Fix offsetTopLeftInline.html for legacy (because I need the test
  coverage when working on visual rects).
- Add a test for offsetTop/offsetLeft of empty inline elements.
  The test fails in LayoutNG.

Bug: 953479
Change-Id: I31eceb4f22540c49db037f685867c95a33e0390d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1570749
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: Emil A Eklund <eae@chromium.org>
Cr-Commit-Position: refs/heads/master@{#651520}
diff --git a/third_party/blink/renderer/core/layout/layout_inline.cc b/third_party/blink/renderer/core/layout/layout_inline.cc
index 40e87c2..25ac202 100644
--- a/third_party/blink/renderer/core/layout/layout_inline.cc
+++ b/third_party/blink/renderer/core/layout/layout_inline.cc
@@ -1004,12 +1004,6 @@
 }
 
 LayoutPoint LayoutInline::FirstLineBoxTopLeft() const {
-  // This method is called from various places. It's mainly (only?) about
-  // calculating offsetLeft and offsetTop, though. Thus the callers seem to
-  // expect a purely physical point. This is what NG does. Legacy, on the other
-  // hand, sets the block-axis coordinate relatively to the block-start border
-  // edge, which means that offsetLeft will be wrong when writing-mode is
-  // vertical-rl.
   if (IsInLayoutNGInlineFormattingContext()) {
     const NGPhysicalBoxFragment* box_fragment =
         ContainingBlockFlowFragmentOf(*this);
@@ -1021,8 +1015,14 @@
       return LayoutPoint();
     return fragments.front().offset_to_container_box.ToLayoutPoint();
   }
-  if (InlineBox* first_box = FirstLineBoxIncludingCulling())
-    return first_box->Location();
+  if (InlineBox* first_box = FirstLineBoxIncludingCulling()) {
+    LayoutPoint location = first_box->Location();
+    if (UNLIKELY(HasFlippedBlocksWritingMode())) {
+      location = ContainingBlock()->FlipForWritingMode(location);
+      location.Move(-LinesBoundingBox().Width(), LayoutUnit());
+    }
+    return location;
+  }
   return LayoutPoint();
 }
 
diff --git a/third_party/blink/web_tests/FlagExpectations/enable-blink-features=LayoutNG b/third_party/blink/web_tests/FlagExpectations/enable-blink-features=LayoutNG
index 3e57f714..03715c1 100644
--- a/third_party/blink/web_tests/FlagExpectations/enable-blink-features=LayoutNG
+++ b/third_party/blink/web_tests/FlagExpectations/enable-blink-features=LayoutNG
@@ -235,7 +235,7 @@
 crbug.com/591099 external/wpt/css/css-writing-modes/vertical-alignment-009.xht [ Pass ]
 crbug.com/591099 external/wpt/css/cssom-view/elementsFromPoint-inline-vrl-ltr.html [ Pass ]
 crbug.com/591099 external/wpt/css/cssom-view/elementsFromPoint-inline-vrl-rtl.html [ Pass ]
-crbug.com/591099 external/wpt/css/cssom-view/offsetTopLeftInline.html [ Pass ]
+crbug.com/953479 external/wpt/css/cssom-view/offsetTopLeftEmptyInline.html [ Failure ]
 crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-align-self-horiz-002.xhtml [ Pass ]
 crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/flexbox/flexbox-writing-mode-011.html [ Pass ]
 crbug.com/591099 external/wpt/css/vendor-imports/mozilla/mozilla-central-reftests/ib-split/emptyspan-1.html [ Pass ]
diff --git a/third_party/blink/web_tests/TestExpectations b/third_party/blink/web_tests/TestExpectations
index be3a489..ceb4570 100644
--- a/third_party/blink/web_tests/TestExpectations
+++ b/third_party/blink/web_tests/TestExpectations
@@ -678,7 +678,6 @@
 crbug.com/591099 external/wpt/css/css-sizing/intrinsic-percent-non-replaced-005.html [ Failure ]
 crbug.com/591099 external/wpt/css/cssom-view/elementsFromPoint-inline-vrl-ltr.html [ Failure ]
 crbug.com/591099 external/wpt/css/cssom-view/elementsFromPoint-inline-vrl-rtl.html [ Failure ]
-crbug.com/591099 external/wpt/css/cssom-view/offsetTopLeftInline.html [ Failure ]
 crbug.com/591099 external/wpt/css/css-writing-modes/inline-box-border-vlr-001.html [ Failure ]
 crbug.com/591099 external/wpt/css/filter-effects/filtered-inline-applies-to-float.html [ Failure ]
 crbug.com/591099 tables/mozilla/bugs/bug14159-1.html [ Failure ]
diff --git a/third_party/blink/web_tests/external/wpt/css/cssom-view/offsetTopLeftEmptyInline.html b/third_party/blink/web_tests/external/wpt/css/cssom-view/offsetTopLeftEmptyInline.html
new file mode 100644
index 0000000..85abbb7
--- /dev/null
+++ b/third_party/blink/web_tests/external/wpt/css/cssom-view/offsetTopLeftEmptyInline.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<link rel="help" href="https://drafts.csswg.org/cssom-view-1/#extensions-to-the-htmlelement-interface">
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<style>
+  .container {
+    position: relative;
+    width: 8em;
+    height: 7em;
+    padding: 1em;
+  }
+</style>
+<div class="container" style="writing-mode:horizontal-tb;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<div class="container" style="writing-mode:vertical-lr;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<div class="container" style="writing-mode:vertical-rl;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<div class="container" style="writing-mode:horizontal-tb; direction:rtl;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<div class="container" style="writing-mode:vertical-lr; direction:rtl;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<div class="container" style="writing-mode:vertical-rl; direction:rtl;">
+  offset
+  <br>offset<span class="target"></span><span>ref</span>
+</div>
+<script>
+var i = 0;
+document.querySelectorAll('span.target').forEach((target) => {
+  var ref = target.nextSibling;
+  test(() => {
+    assert_equals(target.offsetLeft, ref.offsetLeft, 'offsetLeft');
+    assert_equals(target.offsetTop, ref.offsetTop, 'offsetTop');
+  }, 'offsetTop/Left of empty inline elements should work as if they were not empty: ' + i);
+  i++;
+});
+</script>