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

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: Changes according to review. Created 4 years, 1 month 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.moveBy(
1029 toLayoutBox(offsetParentObject)->topLeftLocation());
1030 }
1029 } 1031 }
1030 if (offsetParent->isBox() && !offsetParent->isBody()) 1032
1031 referencePoint.move(-toLayoutBox(offsetParent)->borderLeft(), 1033 if (offsetParentObject->isLayoutInline()) {
atotic 2016/10/31 22:54:25 Can offsetParentObject be null here? We're checkin
Karl Øygard 2016/11/03 11:23:31 offsetParentObject is checked for null in an if st
1032 -toLayoutBox(offsetParent)->borderTop()); 1034 const LayoutInline* inlineParent = toLayoutInline(offsetParentObject);
1035
1036 if (isBox() && style()->position() == AbsolutePosition &&
1037 inlineParent->isInFlowPositioned()) {
1038 // Absolute positioned objects need to be placed on the line
atotic 2016/10/31 22:54:25 This still leaves me wondering: - "on the line" wi
Karl Øygard 2016/11/03 11:23:31 Agreed, I have amended the comment accordingly.
1039
atotic 2016/10/31 22:54:25 Remove blank line
1040 referencePoint +=
1041 inlineParent->offsetForInFlowPositionedInline(*toLayoutBox(this));
1042 }
1043
1044 referencePoint -= inlineParent->firstLineBoxTopLeft();
1045 }
1046
1047 if (offsetParentObject->isBox() && !offsetParentObject->isBody()) {
1048 referencePoint.move(-toLayoutBox(offsetParentObject)->borderLeft(),
1049 -toLayoutBox(offsetParentObject)->borderTop());
1050 }
1033 } 1051 }
1034 1052
1035 return referencePoint; 1053 return referencePoint;
1036 } 1054 }
1037 1055
1038 LayoutSize LayoutBoxModelObject::offsetForInFlowPosition() const { 1056 LayoutSize LayoutBoxModelObject::offsetForInFlowPosition() const {
1039 if (isRelPositioned()) 1057 if (isRelPositioned())
1040 return relativePositionOffset(); 1058 return relativePositionOffset();
1041 1059
1042 if (isStickyPositioned()) 1060 if (isStickyPositioned())
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 if (rootElementStyle->hasBackground()) 1404 if (rootElementStyle->hasBackground())
1387 return false; 1405 return false;
1388 1406
1389 if (node() != document().firstBodyElement()) 1407 if (node() != document().firstBodyElement())
1390 return false; 1408 return false;
1391 1409
1392 return true; 1410 return true;
1393 } 1411 }
1394 1412
1395 } // namespace blink 1413 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698