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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBoxModelObject.cpp

Issue 2414683002: Make offsetTop/Left handle a relative positioned inline offsetParent correctly. (Closed)
Patch Set: Added one more test for abspos with relpos inline offsetParent. Created 4 years, 2 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) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010 Google Inc. All rights reserved. 7 * Copyright (C) 2010 Google Inc. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 // compositing inputs. 983 // compositing inputs.
984 if (!scrollableArea->stickyConstraintsMap().contains(layer())) 984 if (!scrollableArea->stickyConstraintsMap().contains(layer()))
985 return LayoutSize(); 985 return LayoutSize();
986 return LayoutSize( 986 return LayoutSize(
987 scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset( 987 scrollableArea->stickyConstraintsMap().get(layer()).computeStickyOffset(
988 constrainingRect)); 988 constrainingRect));
989 } 989 }
990 990
991 LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo( 991 LayoutPoint LayoutBoxModelObject::adjustedPositionRelativeTo(
992 const LayoutPoint& startPoint, 992 const LayoutPoint& startPoint,
993 const Element* element) const { 993 const Element* offsetParent) const {
994 // If the element is the HTML body element or doesn't have a parent 994 // If the element is the HTML body element or doesn't have a parent
995 // return 0 and stop this algorithm. 995 // return 0 and stop this algorithm.
996 if (isBody() || !parent()) 996 if (isBody() || !parent())
997 return LayoutPoint(); 997 return LayoutPoint();
998 998
999 LayoutPoint referencePoint = startPoint; 999 LayoutPoint referencePoint = startPoint;
1000 1000
1001 // If the base element is null, return the distance between the canvas origin 1001 // If the offsetParent is null, return the distance between the canvas origin
1002 // and the left border edge of the element and stop this algorithm. 1002 // and the left/top border edge of the element and stop this algorithm.
1003 if (!element) 1003 if (!offsetParent)
1004 return referencePoint; 1004 return referencePoint;
1005 1005
1006 if (const LayoutBoxModelObject* offsetParent = 1006 if (const LayoutBoxModelObject* offsetParentObject =
1007 element->layoutBoxModelObject()) { 1007 offsetParent->layoutBoxModelObject()) {
1008 if (!isOutOfFlowPositioned()) { 1008 if (!isOutOfFlowPositioned()) {
1009 if (isInFlowPositioned()) 1009 if (isInFlowPositioned())
1010 referencePoint.move(offsetForInFlowPosition()); 1010 referencePoint.move(offsetForInFlowPosition());
1011 1011
1012 // Note that we may fail to find |offsetParent| while walking the 1012 // Note that we may fail to find |offsetParent| while walking the
1013 // container chain, if |offsetParent| is an inline split into 1013 // container chain, if |offsetParent| is an inline split into
1014 // continuations: <body style="display:inline;" id="offsetParent"><div> 1014 // continuations: <body style="display:inline;" id="offsetParent"><div>
1015 // </div><span id="this"> 1015 // </div><span id="this">
1016 // This is why we have to do a nullptr check here. 1016 // This is why we have to do a nullptr check here.
1017 // offset(Left|Top) is generally broken when offsetParent is inline.
1018 for (const LayoutObject* current = container(); 1017 for (const LayoutObject* current = container();
1019 current && current != offsetParent; current = current->container()) { 1018 current && current != offsetParentObject;
1019 current = current->container()) {
1020 // FIXME: What are we supposed to do inside SVG content? 1020 // FIXME: What are we supposed to do inside SVG content?
1021 referencePoint.move(current->columnOffset(referencePoint)); 1021 referencePoint.move(current->columnOffset(referencePoint));
1022 if (current->isBox() && !current->isTableRow()) 1022 if (current->isBox() && !current->isTableRow())
1023 referencePoint.moveBy(toLayoutBox(current)->topLeftLocation()); 1023 referencePoint.moveBy(toLayoutBox(current)->topLeftLocation());
1024 } 1024 }
1025 1025
1026 if (offsetParent->isBox() && offsetParent->isBody() && 1026 if (offsetParentObject->isBox() && offsetParentObject->isBody() &&
1027 !offsetParent->isPositioned()) 1027 !offsetParentObject->isPositioned())
1028 referencePoint.moveBy(toLayoutBox(offsetParent)->topLeftLocation()); 1028 referencePoint += toLayoutBox(offsetParentObject)->topLeftLocation();
atotic 2016/10/25 19:28:58 Why replace moveBy with '+='? moveBy is used thr
Karl Øygard 2016/10/26 11:27:04 It was just done to conserve line space for cosmet
1029 } 1029 }
1030 if (offsetParent->isBox() && !offsetParent->isBody()) 1030
1031 referencePoint.move(-toLayoutBox(offsetParent)->borderLeft(), 1031 if (offsetParentObject->isLayoutInline()) {
1032 -toLayoutBox(offsetParent)->borderTop()); 1032 const LayoutInline* inlineParent = toLayoutInline(offsetParentObject);
atotic 2016/10/25 19:28:58 I am not very familiar with this code. Can you e
Karl Øygard 2016/10/26 11:27:04 This covers the case when offsetParent is an inlin
1033
1034 referencePoint -= inlineParent->firstLineBoxTopLeft();
1035
1036 if (isBox() && style()->position() == AbsolutePosition &&
1037 inlineParent->isInFlowPositioned()) {
1038 referencePoint +=
1039 inlineParent->offsetForInFlowPositionedInline(*toLayoutBox(this));
1040 }
1041 }
1042
1043 if (offsetParentObject->isBox() && !offsetParentObject->isBody()) {
1044 referencePoint.move(-toLayoutBox(offsetParentObject)->borderLeft(),
1045 -toLayoutBox(offsetParentObject)->borderTop());
1046 }
1033 } 1047 }
1034 1048
1035 return referencePoint; 1049 return referencePoint;
1036 } 1050 }
1037 1051
1038 LayoutSize LayoutBoxModelObject::offsetForInFlowPosition() const { 1052 LayoutSize LayoutBoxModelObject::offsetForInFlowPosition() const {
1039 if (isRelPositioned()) 1053 if (isRelPositioned())
1040 return relativePositionOffset(); 1054 return relativePositionOffset();
1041 1055
1042 if (isStickyPositioned()) 1056 if (isStickyPositioned())
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 if (rootElementStyle->hasBackground()) 1400 if (rootElementStyle->hasBackground())
1387 return false; 1401 return false;
1388 1402
1389 if (node() != document().firstBodyElement()) 1403 if (node() != document().firstBodyElement())
1390 return false; 1404 return false;
1391 1405
1392 return true; 1406 return true;
1393 } 1407 }
1394 1408
1395 } // namespace blink 1409 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698