Commit f4baddfd authored by Alex Rudenko's avatar Alex Rudenko Committed by Commit Bot

Fix track size label positioning in inspector overlay

Previously, `TrackSizesForComputedStyle` was used incorrectly
because it didn't account for paddings and borders. This CL
changes that to using `ColumnPositions`/`RowPositions` instead.

Bug: 1105808
Change-Id: I5bb0994dfb670ae2d43641f8a576a4acf43dd369
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317225
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Reviewed-by: default avatarOriol Brufau <obrufau@igalia.com>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Reviewed-by: default avatarBrandon Goddard <brgoddar@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#791820}
parent 4b7b5918
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h" #include "third_party/blink/renderer/core/inspector/dom_traversal_utils.h"
#include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h" #include "third_party/blink/renderer/core/inspector/inspector_dom_agent.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h" #include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/layout/geometry/physical_offset.h"
#include "third_party/blink/renderer/core/layout/layout_box.h" #include "third_party/blink/renderer/core/layout/layout_box.h"
#include "third_party/blink/renderer/core/layout/layout_grid.h" #include "third_party/blink/renderer/core/layout/layout_grid.h"
#include "third_party/blink/renderer/core/layout/layout_inline.h" #include "third_party/blink/renderer/core/layout/layout_inline.h"
...@@ -26,6 +27,7 @@ ...@@ -26,6 +27,7 @@
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/style/computed_style_constants.h" #include "third_party/blink/renderer/core/style/computed_style_constants.h"
#include "third_party/blink/renderer/core/style/grid_positions_resolver.h" #include "third_party/blink/renderer/core/style/grid_positions_resolver.h"
#include "third_party/blink/renderer/platform/geometry/layout_unit.h"
#include "third_party/blink/renderer/platform/graphics/path.h" #include "third_party/blink/renderer/platform/graphics/path.h"
#include "third_party/blink/renderer/platform/web_test_support.h" #include "third_party/blink/renderer/platform/web_test_support.h"
...@@ -409,28 +411,32 @@ std::unique_ptr<protocol::ListValue> BuildGridTrackSizes( ...@@ -409,28 +411,32 @@ std::unique_ptr<protocol::ListValue> BuildGridTrackSizes(
float scale, float scale,
LayoutUnit gap) { LayoutUnit gap) {
std::unique_ptr<protocol::ListValue> sizes = protocol::ListValue::create(); std::unique_ptr<protocol::ListValue> sizes = protocol::ListValue::create();
const Vector<LayoutUnit>& positions = direction == kForRows
unsigned i = 0; ? layout_grid->RowPositions()
float start = 0; : layout_grid->ColumnPositions();
for (LayoutUnit track : layout_grid->TrackSizesForComputedStyle(direction)) { const Vector<LayoutUnit>& alt_positions = direction == kForRows
if (i > 0) ? layout_grid->ColumnPositions()
start += gap; : layout_grid->RowPositions();
LayoutUnit first_offset = alt_positions.front();
for (unsigned i = 1; i < positions.size(); i++) {
LayoutUnit current_position = positions.at(i);
LayoutUnit prev_position = positions.at(i - 1);
LayoutUnit gap_offset = i < positions.size() - 1 ? gap : LayoutUnit();
LayoutUnit width = current_position - prev_position - gap_offset;
LayoutUnit label_pos = prev_position + width / 2;
std::unique_ptr<protocol::DictionaryValue> size_info = std::unique_ptr<protocol::DictionaryValue> size_info =
protocol::DictionaryValue::create(); protocol::DictionaryValue::create();
auto adjusted_size = AdjustForAbsoluteZoom::AdjustFloat( auto adjusted_size = AdjustForAbsoluteZoom::AdjustFloat(
track.ToFloat() * scale, layout_grid->StyleRef()); width * scale, layout_grid->StyleRef());
size_info->setDouble("computedSize", adjusted_size); size_info->setDouble("computedSize", adjusted_size);
// TODO (alexrudenko): Add authored sizes here PhysicalOffset local_arrow_pos(
float offset = start + track / 2; direction == kForColumns ? label_pos : first_offset,
FloatPoint local_arrow_pos(direction == kForColumns ? offset : 0, direction == kForColumns ? first_offset : label_pos);
direction == kForColumns ? 0 : offset); PhysicalOffset abs_arrow_pos =
FloatPoint abs_arrow_pos = layout_grid->LocalToAbsolutePoint(local_arrow_pos);
layout_grid->LocalToAbsoluteFloatPoint(local_arrow_pos); size_info->setDouble("x", abs_arrow_pos.left * scale);
size_info->setDouble("x", abs_arrow_pos.X() * scale); size_info->setDouble("y", abs_arrow_pos.top * scale);
size_info->setDouble("y", abs_arrow_pos.Y() * scale);
sizes->pushValue(std::move(size_info)); sizes->pushValue(std::move(size_info));
start += track;
i++;
} }
return sizes; return sizes;
......
...@@ -102,25 +102,25 @@ paddedGrid{ ...@@ -102,25 +102,25 @@ paddedGrid{
"columnTrackSizes": [ "columnTrackSizes": [
{ {
"computedSize": 50, "computedSize": 50,
"x": 118, "x": 173,
"y": 1173 "y": 383
}, },
{ {
"computedSize": 200, "computedSize": 200,
"x": 118, "x": 173,
"y": 1023 "y": 233
} }
], ],
"rowTrackSizes": [ "rowTrackSizes": [
{ {
"computedSize": 25, "computedSize": 25,
"x": 130.5, "x": 185.5,
"y": 1198 "y": 408
}, },
{ {
"computedSize": 25, "computedSize": 25,
"x": 170.5, "x": 225.5,
"y": 1198 "y": 408
} }
], ],
"rows": [ "rows": [
......
...@@ -7,25 +7,25 @@ This test verifies the position and size of the highlight rectangles overlayed o ...@@ -7,25 +7,25 @@ This test verifies the position and size of the highlight rectangles overlayed o
"columnTrackSizes": [ "columnTrackSizes": [
{ {
"computedSize": 50, "computedSize": 50,
"x": 118, "x": 173,
"y": 1173 "y": 383
}, },
{ {
"computedSize": 200, "computedSize": 200,
"x": 118, "x": 173,
"y": 1023 "y": 233
} }
], ],
"rowTrackSizes": [ "rowTrackSizes": [
{ {
"computedSize": 25, "computedSize": 25,
"x": 130.5, "x": 185.5,
"y": 1198 "y": 408
}, },
{ {
"computedSize": 25, "computedSize": 25,
"x": 170.5, "x": 225.5,
"y": 1198 "y": 408
} }
], ],
"rows": [ "rows": [
......
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