Commit ba1249ed authored by Alex Rudenko's avatar Alex Rudenko Committed by Chromium LUCI CQ

Change the order in which local points are converted to absolute ones

The order of transformation makes a difference when device parameters
such as deviceScaleFactor don't equal 1.

Bug: 1151864
Change-Id: I7d0b5fc2a19b5d1ab18053068b190aff7c7f2079
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2563477
Commit-Queue: Alex Rudenko <alexrudenko@chromium.org>
Reviewed-by: default avatarPeter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#832296}
parent e2b6399d
......@@ -526,12 +526,13 @@ PhysicalOffset LocalToAbsolutePoint(Node* node,
float scale) {
LayoutObject* layout_object = node->GetLayoutObject();
auto* layout_grid = To<LayoutGrid>(layout_object);
FloatPoint local_in_frame = FramePointToViewport(
node->GetDocument().View(), FloatPoint(local.left, local.top));
PhysicalOffset abs_number_pos = layout_grid->LocalToAbsolutePoint(
PhysicalOffset::FromFloatPointRound(local_in_frame));
abs_number_pos.Scale(scale);
return abs_number_pos;
PhysicalOffset abs_point = layout_grid->LocalToAbsolutePoint(local);
FloatPoint abs_point_in_viewport = FramePointToViewport(
node->GetDocument().View(), FloatPoint(abs_point.left, abs_point.top));
PhysicalOffset scaled_abs_point =
PhysicalOffset::FromFloatPointRound(abs_point_in_viewport);
scaled_abs_point.Scale(scale);
return scaled_abs_point;
}
std::unique_ptr<protocol::DictionaryValue> BuildPosition(
......
Verifies that Overlay.setShowGridOverlays works together with Emulation.setDeviceMetricsOverride.
Expected 3 track size labels; actual: 3
Positions:
{
bottom : 27.53125
height : 18
left : 382
right : 418
top : 9.53125
width : 36
}
{
bottom : 23.6875
height : 18
left : 9.53125
right : 39.53125
top : 5.6875
width : 30
}
{
bottom : 40.015625
height : 18
left : 9.53125
right : 39.53125
top : 22.015625
width : 30
}
(async function(testRunner) {
const {page, session, dp} = await testRunner.startHTML(`
<style>
#grid {
display: grid;
}
</style>
<div id="grid"><div>A</div><div>B</div></div>
`, 'Verifies that Overlay.setShowGridOverlays works together with Emulation.setDeviceMetricsOverride.');
await dp.DOM.enable();
await dp.CSS.enable();
await dp.Emulation.enable();
await dp.Overlay.enable();
await dp.Emulation.setDeviceMetricsOverride({
width: 0,
height: 0,
deviceScaleFactor: 2,
mobile: true,
scale: 1,
screenWidth: 800,
screenHeight: 600,
positionX: 0,
positionY: 0,
dontSetVisibleSize: true,
screenOrientation: {
type: 'landscapePrimary',
angle: 90
}
});
const CSSHelper = await testRunner.loadScript('../resources/css-helper.js');
const cssHelper = new CSSHelper(testRunner, dp);
const documentNodeId = await cssHelper.requestDocumentNodeId();
const nodeId = await cssHelper.requestNodeId(documentNodeId, '#grid');
await dp.Overlay.setShowGridOverlays({
gridNodeHighlightConfigs: [{
nodeId,
gridHighlightConfig: {
showTrackSizes: true,
},
}]
});
// Wait for overlay rendering to finish by requesting an animation frame.
await session.evaluate(() => {
return new Promise(resolve => requestAnimationFrame(resolve));
});
async function getGridLabelPositions() {
return await session.evaluate(() => {
return internals.evaluateInInspectorOverlay(`(function () {
const labels = document.querySelectorAll('.grid-label-content');
const positions = [];
for (const label of labels) {
const rect = label.getBoundingClientRect();
positions.push({
left: rect.left,
right: rect.right,
bottom: rect.bottom,
top: rect.top,
width: rect.width,
height: rect.height,
});
}
return JSON.stringify(positions);
})()`);
});
}
const labelPositions = JSON.parse(await getGridLabelPositions());
testRunner.log('Expected 3 track size labels; actual: ' + labelPositions.length);
testRunner.log('Positions: ');
for (const position of labelPositions) {
testRunner.log(position);
}
testRunner.completeTest();
});
Verifies that Overlay.setShowGridOverlays works together with Emulation.setDeviceMetricsOverride.
Expected 3 track size labels; actual: 3
Positions:
{
bottom : 27.53125
height : 18
left : 382
right : 418
top : 9.53125
width : 36
}
{
bottom : 23.6875
height : 18
left : 9.53125
right : 39.53125
top : 5.6875
width : 30
}
{
bottom : 40.015625
height : 18
left : 9.53125
right : 39.53125
top : 22.015625
width : 30
}
Verifies that Overlay.setShowGridOverlays works together with Emulation.setDeviceMetricsOverride.
Expected 3 track size labels; actual: 3
Positions:
{
bottom : 26.53125
height : 17
left : 381.9375
right : 418.046875
top : 9.53125
width : 36.109375
}
{
bottom : 22.375
height : 17
left : 9.53125
right : 39.625
top : 5.375
width : 30.09375
}
{
bottom : 37.078125
height : 17
left : 9.53125
right : 39.625
top : 20.078125
width : 30.09375
}
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