Skip to content

Commit

Permalink
Handle case when layout object does not exist in Delegated Ink API up…
Browse files Browse the repository at this point in the history
…dateInkTrailStartPoint

Early exit if layout object associated with presentation area element
does not exist.

Bug: 1264352
Change-Id: I70fa3c2e3f36c6eba36ab4202e21198bdea31b46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3261969
Reviewed-by: Kent Tamura <[email protected]>
Commit-Queue: Olga Gerchikov <[email protected]>
Cr-Commit-Position: refs/heads/main@{#938777}
NOKEYCHECK=True
GitOrigin-RevId: 83b73115559bb86fff5f904319e70febbea0766e
  • Loading branch information
ogerchikov authored and copybara-github committed Nov 5, 2021
1 parent e74727c commit 16a57cc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,26 @@ void DelegatedInkTrailPresenter::updateInkTrailStartPoint(
}

LayoutView* layout_view = local_frame_->ContentLayoutObject();
DCHECK(layout_view);
const float effective_zoom = layout_view->StyleRef().EffectiveZoom();

PhysicalOffset physical_point(LayoutUnit(evt->x()), LayoutUnit(evt->y()));
physical_point.Scale(effective_zoom);
physical_point = layout_view->LocalToAbsolutePoint(
physical_point, kTraverseDocumentBoundaries);
gfx::PointF point = ToGfxPointF(FloatPoint(physical_point));

LayoutBox* layout_box = nullptr;
if (presentation_area_) {
layout_box = presentation_area_->GetLayoutBox();
DCHECK(layout_box);
} else {
// If presentation_area_ wasn't provided, then default to the layout
// viewport.
layout_box = layout_view;
}
// The layout might not be initialized or the associated element deleted from
// the DOM.
if (!layout_box || !layout_view)
return;

const float effective_zoom = layout_view->StyleRef().EffectiveZoom();

PhysicalOffset physical_point(LayoutUnit(evt->x()), LayoutUnit(evt->y()));
physical_point.Scale(effective_zoom);
physical_point = layout_view->LocalToAbsolutePoint(
physical_point, kTraverseDocumentBoundaries);
gfx::PointF point = ToGfxPointF(FloatPoint(physical_point));

// Intersect with the visible viewport so that the presentation area can't
// extend beyond the edges of the window or over the scrollbars. The frame
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-actions.js"></script>
<script src="/resources/testdriver-vendor.js"></script>

<canvas id="canvas"></canvas>
<script>
promise_test(async (t) => {
const presenter = await navigator.ink.requestPresenter({presentationArea: canvas});
const style = { color: "green", diameter: 6 };

window.addEventListener("pointermove", evt => {
presenter.updateInkTrailStartPoint(evt, style);
});
document.body.removeChild(canvas);
const actions_promise = new test_driver.Actions().pointerMove(10, 10).send();
t.add_cleanup(() => actions_promise);
}, "No crash when accessing presenter associated with deleted presentation area.");
</script>

0 comments on commit 16a57cc

Please sign in to comment.