Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: third_party/WebKit/Source/core/dom/Element.cpp

Issue 2825343003: Clean compositing inputs for location APIs for sticky-affected elements. (Closed)
Patch Set: Add test for sticky subtrees Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * (C) 2007 Eric Seidel (eric@webkit.org) 9 * (C) 2007 Eric Seidel (eric@webkit.org)
10 * 10 *
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 return attribute->Value(); 424 return attribute->Value();
425 return g_null_atom; 425 return g_null_atom;
426 } 426 }
427 427
428 AtomicString Element::LowercaseIfNecessary(const AtomicString& name) const { 428 AtomicString Element::LowercaseIfNecessary(const AtomicString& name) const {
429 return IsHTMLElement() && GetDocument().IsHTMLDocument() ? name.LowerASCII() 429 return IsHTMLElement() && GetDocument().IsHTMLDocument() ? name.LowerASCII()
430 : name; 430 : name;
431 } 431 }
432 432
433 void Element::scrollIntoView(bool align_to_top) { 433 void Element::scrollIntoView(bool align_to_top) {
434 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 434 EnsureLifecycleValidForLocationAPIs();
435 435
436 if (!GetLayoutObject()) 436 if (!GetLayoutObject())
437 return; 437 return;
438 438
439 bool make_visible_in_visual_viewport = 439 bool make_visible_in_visual_viewport =
440 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); 440 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport();
441 441
442 LayoutRect bounds = BoundingBox(); 442 LayoutRect bounds = BoundingBox();
443 // Align to the top / bottom and to the closest edge. 443 // Align to the top / bottom and to the closest edge.
444 if (align_to_top) 444 if (align_to_top)
445 GetLayoutObject()->ScrollRectToVisible( 445 GetLayoutObject()->ScrollRectToVisible(
446 bounds, ScrollAlignment::kAlignToEdgeIfNeeded, 446 bounds, ScrollAlignment::kAlignToEdgeIfNeeded,
447 ScrollAlignment::kAlignTopAlways, kProgrammaticScroll, 447 ScrollAlignment::kAlignTopAlways, kProgrammaticScroll,
448 make_visible_in_visual_viewport); 448 make_visible_in_visual_viewport);
449 else 449 else
450 GetLayoutObject()->ScrollRectToVisible( 450 GetLayoutObject()->ScrollRectToVisible(
451 bounds, ScrollAlignment::kAlignToEdgeIfNeeded, 451 bounds, ScrollAlignment::kAlignToEdgeIfNeeded,
452 ScrollAlignment::kAlignBottomAlways, kProgrammaticScroll, 452 ScrollAlignment::kAlignBottomAlways, kProgrammaticScroll,
453 make_visible_in_visual_viewport); 453 make_visible_in_visual_viewport);
454 454
455 GetDocument().SetSequentialFocusNavigationStartingPoint(this); 455 GetDocument().SetSequentialFocusNavigationStartingPoint(this);
456 } 456 }
457 457
458 void Element::scrollIntoViewIfNeeded(bool center_if_needed) { 458 void Element::scrollIntoViewIfNeeded(bool center_if_needed) {
459 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 459 EnsureLifecycleValidForLocationAPIs();
460 460
461 if (!GetLayoutObject()) 461 if (!GetLayoutObject())
462 return; 462 return;
463 463
464 bool make_visible_in_visual_viewport = 464 bool make_visible_in_visual_viewport =
465 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport(); 465 !GetDocument().GetPage()->GetSettings().GetInertVisualViewport();
466 466
467 LayoutRect bounds = BoundingBox(); 467 LayoutRect bounds = BoundingBox();
468 if (center_if_needed) 468 if (center_if_needed)
469 GetLayoutObject()->ScrollRectToVisible( 469 GetLayoutObject()->ScrollRectToVisible(
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 callback->handleEvent(&scroll_state); 636 callback->handleEvent(&scroll_state);
637 if (callback->NativeScrollBehavior() != 637 if (callback->NativeScrollBehavior() !=
638 WebNativeScrollBehavior::kDisableNativeScroll) 638 WebNativeScrollBehavior::kDisableNativeScroll)
639 NativeApplyScroll(scroll_state); 639 NativeApplyScroll(scroll_state);
640 if (callback->NativeScrollBehavior() == 640 if (callback->NativeScrollBehavior() ==
641 WebNativeScrollBehavior::kPerformAfterNativeScroll) 641 WebNativeScrollBehavior::kPerformAfterNativeScroll)
642 callback->handleEvent(&scroll_state); 642 callback->handleEvent(&scroll_state);
643 } 643 }
644 644
645 int Element::OffsetLeft() { 645 int Element::OffsetLeft() {
646 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 646 EnsureLifecycleValidForLocationAPIs();
647 if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) 647 if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject())
648 return AdjustLayoutUnitForAbsoluteZoom( 648 return AdjustLayoutUnitForAbsoluteZoom(
649 LayoutUnit( 649 LayoutUnit(
650 layout_object->PixelSnappedOffsetLeft(OffsetParent())), 650 layout_object->PixelSnappedOffsetLeft(OffsetParent())),
651 layout_object->StyleRef()) 651 layout_object->StyleRef())
652 .Round(); 652 .Round();
653 return 0; 653 return 0;
654 } 654 }
655 655
656 int Element::OffsetTop() { 656 int Element::OffsetTop() {
657 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 657 EnsureLifecycleValidForLocationAPIs();
fs 2017/04/29 09:59:06 I think OffsetWidth/Height needs this too (because
smcgruer 2017/05/01 20:15:15 Done, though I'm having trouble coming up with a u
fs 2017/05/01 21:19:34 Yes, effects would very likely be minor since only
smcgruer 2017/05/02 15:25:41 After looking at this for some time, I believe tha
658 if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject()) 658 if (LayoutBoxModelObject* layout_object = GetLayoutBoxModelObject())
659 return AdjustLayoutUnitForAbsoluteZoom( 659 return AdjustLayoutUnitForAbsoluteZoom(
660 LayoutUnit(layout_object->PixelSnappedOffsetTop(OffsetParent())), 660 LayoutUnit(layout_object->PixelSnappedOffsetTop(OffsetParent())),
661 layout_object->StyleRef()) 661 layout_object->StyleRef())
662 .Round(); 662 .Round();
663 return 0; 663 return 0;
664 } 664 }
665 665
666 int Element::OffsetWidth() { 666 int Element::OffsetWidth() {
667 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 667 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this);
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 IntSize viewport_size = GetDocument().GetPage()->GetVisualViewport().Size(); 1125 IntSize viewport_size = GetDocument().GetPage()->GetVisualViewport().Size();
1126 IntRect rect(0, 0, viewport_size.Width(), viewport_size.Height()); 1126 IntRect rect(0, 0, viewport_size.Width(), viewport_size.Height());
1127 // We don't use absoluteBoundingBoxRect() because it can return an IntRect 1127 // We don't use absoluteBoundingBoxRect() because it can return an IntRect
1128 // larger the actual size by 1px. crbug.com/470503 1128 // larger the actual size by 1px. crbug.com/470503
1129 rect.Intersect(GetDocument().View()->ContentsToViewport( 1129 rect.Intersect(GetDocument().View()->ContentsToViewport(
1130 RoundedIntRect(GetLayoutObject()->AbsoluteBoundingBoxFloatRect()))); 1130 RoundedIntRect(GetLayoutObject()->AbsoluteBoundingBoxFloatRect())));
1131 return rect; 1131 return rect;
1132 } 1132 }
1133 1133
1134 void Element::ClientQuads(Vector<FloatQuad>& quads) { 1134 void Element::ClientQuads(Vector<FloatQuad>& quads) {
1135 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheetsForNode(this); 1135 EnsureLifecycleValidForLocationAPIs();
fs 2017/04/29 09:59:06 Potentially a lot of other methods needs this trea
smcgruer 2017/05/01 20:15:15 Added to BoundsInViewport, but I suspect that gett
fs 2017/05/01 21:19:34 Yes, I'm a bit worried that we're heading into a g
smcgruer 2017/05/02 15:25:41 I've no experience to rely on here, so if someone
fs 2017/05/02 15:58:07 Well, you don't necessarily need to do any (additi
smcgruer 2017/05/02 17:25:30 Ack, opened http://crbug.com/717601 to track this.
1136 1136
1137 LayoutObject* element_layout_object = GetLayoutObject(); 1137 LayoutObject* element_layout_object = GetLayoutObject();
1138 if (!element_layout_object) 1138 if (!element_layout_object)
1139 return; 1139 return;
1140 1140
1141 if (IsSVGElement() && !element_layout_object->IsSVGRoot()) { 1141 if (IsSVGElement() && !element_layout_object->IsSVGRoot()) {
1142 // Get the bounding rectangle from the SVG model. 1142 // Get the bounding rectangle from the SVG model.
1143 if (ToSVGElement(this)->IsSVGGraphicsElement()) 1143 if (ToSVGElement(this)->IsSVGGraphicsElement())
1144 quads.push_back(element_layout_object->LocalToAbsoluteQuad( 1144 quads.push_back(element_layout_object->LocalToAbsoluteQuad(
1145 element_layout_object->ObjectBoundingBox())); 1145 element_layout_object->ObjectBoundingBox()));
(...skipping 3175 matching lines...) Expand 10 before | Expand all | Expand 10 after
4321 if (!activity_logger) 4321 if (!activity_logger)
4322 return; 4322 return;
4323 Vector<String, 4> argv; 4323 Vector<String, 4> argv;
4324 argv.push_back(element); 4324 argv.push_back(element);
4325 argv.push_back(params.name.ToString()); 4325 argv.push_back(params.name.ToString());
4326 argv.push_back(params.old_value); 4326 argv.push_back(params.old_value);
4327 argv.push_back(params.new_value); 4327 argv.push_back(params.new_value);
4328 activity_logger->LogEvent("blinkSetAttribute", argv.size(), argv.data()); 4328 activity_logger->LogEvent("blinkSetAttribute", argv.size(), argv.data());
4329 } 4329 }
4330 4330
4331 void Element::EnsureLifecycleValidForLocationAPIs() {
fs 2017/04/29 09:59:06 Maybe this method would be better placed in Docume
smcgruer 2017/05/01 20:15:15 Done. I welcome bike-shedding on the name, it's pr
fs 2017/05/01 21:19:33 Yes, naming... the lifecycle "duality" makes it ev
smcgruer 2017/05/02 15:25:41 Sgtm; if nobody has any objections I will update t
smcgruer 2017/05/03 17:56:58 So, I realized that this CL actually replaces the
4332 if (!InActiveDocument())
4333 return;
4334
4335 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
4336
4337 // The location of elements that are position: sticky is not known until
4338 // compositing inputs are cleaned. Therefore, for any elements that are either
4339 // sticky or are in a sticky sub-tree (e.g. are affected by a sticky element),
4340 // we need to also clean compositing inputs.
4341 FrameView* view = GetDocument().View();
4342 if (UNLIKELY(view && GetLayoutObject() &&
4343 GetLayoutObject()->Style()->IsInStickySubtree())) {
4344 if (RuntimeEnabledFeatures::slimmingPaintV2Enabled()) {
4345 // In SPv2, compositing inputs are cleaned as part of PrePaint.
4346 view->UpdateAllLifecyclePhasesExceptPaint();
4347 } else {
4348 view->UpdateLifecycleToCompositingInputsClean();
4349 }
4350 }
4351 }
4352
4331 DEFINE_TRACE(Element) { 4353 DEFINE_TRACE(Element) {
4332 if (HasRareData()) 4354 if (HasRareData())
4333 visitor->Trace(GetElementRareData()); 4355 visitor->Trace(GetElementRareData());
4334 visitor->Trace(element_data_); 4356 visitor->Trace(element_data_);
4335 ContainerNode::Trace(visitor); 4357 ContainerNode::Trace(visitor);
4336 } 4358 }
4337 4359
4338 DEFINE_TRACE_WRAPPERS(Element) { 4360 DEFINE_TRACE_WRAPPERS(Element) {
4339 if (HasRareData()) { 4361 if (HasRareData()) {
4340 visitor->TraceWrappers(GetElementRareData()); 4362 visitor->TraceWrappers(GetElementRareData());
4341 } 4363 }
4342 ContainerNode::TraceWrappers(visitor); 4364 ContainerNode::TraceWrappers(visitor);
4343 } 4365 }
4344 4366
4345 } // namespace blink 4367 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698