Skip to content

Commit

Permalink
fixup! Dispel the myth that enclosingLayer can return zero
Browse files Browse the repository at this point in the history
According from the commit messages of previous commit,
enclosingLayer() cannot be nullptr, but it removed a check
for container() returning nullptr actually.

We need to check nullptr before using it in
LayoutObject::ComputeLayerHitTestRects().

This patch is re-organizing the existing conditions
to remove potential risk factors.

Original patch = https://codereview.chromium.org/215843002

BUG=752371

Change-Id: I29a1d2d98f7daa200bf3f001e430d8e3aa9f38f3
Reviewed-on: https://chromium-review.googlesource.com/587691
Reviewed-by: Stephen Chenney <[email protected]>
Commit-Queue: Stephen Chenney <[email protected]>
Cr-Commit-Position: refs/heads/master@{#495222}
  • Loading branch information
djmixkim authored and Commit Bot committed Aug 17, 2017
1 parent 8451e2e commit 219e1da
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions third_party/WebKit/Source/core/layout/LayoutObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,16 +2357,19 @@ void LayoutObject::ComputeLayerHitTestRects(

if (!HasLayer()) {
LayoutObject* container = this->Container();
current_layer = container->EnclosingLayer();
if (container && current_layer->GetLayoutObject() != container) {
layer_offset.Move(container->OffsetFromAncestorContainer(
&current_layer->GetLayoutObject()));
// If the layer itself is scrolled, we have to undo the subtraction of its
// scroll offset since we want the offset relative to the scrolling
// content, not the element itself.
if (current_layer->GetLayoutObject().HasOverflowClip())
layer_offset.Move(
current_layer->GetLayoutBox()->ScrolledContentOffset());
if (container) {
current_layer = container->EnclosingLayer();
if (current_layer->GetLayoutObject() != container) {
layer_offset.Move(container->OffsetFromAncestorContainer(
&current_layer->GetLayoutObject()));
// If the layer itself is scrolled, we have to undo the subtraction of
// its scroll offset since we want the offset relative to the scrolling
// content, not the element itself.
if (current_layer->GetLayoutObject().HasOverflowClip()) {
layer_offset.Move(
current_layer->GetLayoutBox()->ScrolledContentOffset());
}
}
}
}

Expand Down

0 comments on commit 219e1da

Please sign in to comment.