| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 4 * | 4 * |
| 5 * Portions are Copyright (C) 1998 Netscape Communications Corporation. | 5 * Portions are Copyright (C) 1998 Netscape Communications Corporation. |
| 6 * | 6 * |
| 7 * Other contributors: | 7 * Other contributors: |
| 8 * Robert O'Callahan <roc+@cs.cmu.edu> | 8 * Robert O'Callahan <roc+@cs.cmu.edu> |
| 9 * David Baron <dbaron@fas.harvard.edu> | 9 * David Baron <dbaron@fas.harvard.edu> |
| 10 * Christian Biesinger <cbiesinger@web.de> | 10 * Christian Biesinger <cbiesinger@web.de> |
| (...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 | 873 |
| 874 PaintLayer* PaintLayer::containingLayer(const PaintLayer* ancestor, | 874 PaintLayer* PaintLayer::containingLayer(const PaintLayer* ancestor, |
| 875 bool* skippedAncestor) const { | 875 bool* skippedAncestor) const { |
| 876 // If we have specified an ancestor, surely the caller needs to know whether | 876 // If we have specified an ancestor, surely the caller needs to know whether |
| 877 // we skipped it. | 877 // we skipped it. |
| 878 DCHECK(!ancestor || skippedAncestor); | 878 DCHECK(!ancestor || skippedAncestor); |
| 879 if (skippedAncestor) | 879 if (skippedAncestor) |
| 880 *skippedAncestor = false; | 880 *skippedAncestor = false; |
| 881 | 881 |
| 882 LayoutObject& layoutObject = this->layoutObject(); | 882 LayoutObject& layoutObject = this->layoutObject(); |
| 883 if (layoutObject.isColumnSpanAll() || | 883 // Column span need to find the containing layer through its containing block. |
| 884 layoutObject.isFloatingWithNonContainingBlockParent()) { | 884 // TODO(wangxianzhu): This can be combined with the loop handing possible |
| 885 // floating objects. |
| 886 if (layoutObject.isColumnSpanAll()) { |
| 885 Optional<LayoutObject::AncestorSkipInfo> skipInfo; | 887 Optional<LayoutObject::AncestorSkipInfo> skipInfo; |
| 886 if (skippedAncestor) | 888 if (skippedAncestor) |
| 887 skipInfo.emplace(&ancestor->layoutObject()); | 889 skipInfo.emplace(&ancestor->layoutObject()); |
| 888 if (auto containingBlock = layoutObject.containingBlock( | 890 if (auto containingBlock = layoutObject.containingBlock( |
| 889 skippedAncestor ? &*skipInfo : nullptr)) { | 891 skippedAncestor ? &*skipInfo : nullptr)) { |
| 890 if (skippedAncestor && skipInfo->ancestorSkipped()) | 892 if (skippedAncestor && skipInfo->ancestorSkipped()) |
| 891 *skippedAncestor = true; | 893 *skippedAncestor = true; |
| 892 return containingBlock->enclosingLayer(); | 894 return containingBlock->enclosingLayer(); |
| 893 } | 895 } |
| 894 return nullptr; | 896 return nullptr; |
| 895 } | 897 } |
| 896 | 898 |
| 897 if (layoutObject.isOutOfFlowPositioned()) { | 899 if (layoutObject.isOutOfFlowPositioned()) { |
| 898 auto canContainThisLayer = | 900 auto canContainThisLayer = |
| 899 layoutObject.isFixedPositioned() | 901 layoutObject.isFixedPositioned() |
| 900 ? &LayoutObject::canContainFixedPositionObjects | 902 ? &LayoutObject::canContainFixedPositionObjects |
| 901 : &LayoutObject::canContainAbsolutePositionObjects; | 903 : &LayoutObject::canContainAbsolutePositionObjects; |
| 902 | 904 |
| 903 PaintLayer* curr = parent(); | 905 PaintLayer* curr = parent(); |
| 904 while (curr && !((&curr->layoutObject())->*canContainThisLayer)()) { | 906 while (curr && !((&curr->layoutObject())->*canContainThisLayer)()) { |
| 905 if (skippedAncestor && curr == ancestor) | 907 if (skippedAncestor && curr == ancestor) |
| 906 *skippedAncestor = true; | 908 *skippedAncestor = true; |
| 907 curr = curr->parent(); | 909 curr = curr->parent(); |
| 908 } | 910 } |
| 909 return curr; | 911 return curr; |
| 910 } | 912 } |
| 911 | 913 |
| 912 return parent(); | 914 // If the parent layer is not a block, there might be floating objects |
| 915 // between this layer (included) and parent layer which need to escape the |
| 916 // inline parent to find the actual containing layer through the containing |
| 917 // block chain. |
| 918 if (!parent() || parent()->layoutObject().isLayoutBlock()) |
| 919 return parent(); |
| 920 |
| 921 // This is a universal approach to find containing layer, but is slower than |
| 922 // the earlier code. |
| 923 Optional<LayoutObject::AncestorSkipInfo> skipInfo; |
| 924 if (skippedAncestor) |
| 925 skipInfo.emplace(&ancestor->layoutObject()); |
| 926 auto* object = &layoutObject; |
| 927 while (auto* container = |
| 928 object->container(skippedAncestor ? &*skipInfo : nullptr)) { |
| 929 if (skippedAncestor && skipInfo->ancestorSkipped()) |
| 930 *skippedAncestor = true; |
| 931 if (container->hasLayer()) |
| 932 return toLayoutBoxModelObject(container)->layer(); |
| 933 object = container; |
| 934 } |
| 935 return nullptr; |
| 913 } | 936 } |
| 914 | 937 |
| 915 PaintLayer* PaintLayer::enclosingTransformedAncestor() const { | 938 PaintLayer* PaintLayer::enclosingTransformedAncestor() const { |
| 916 PaintLayer* curr = parent(); | 939 PaintLayer* curr = parent(); |
| 917 while (curr && !curr->isRootLayer() && !curr->transform()) | 940 while (curr && !curr->isRootLayer() && !curr->transform()) |
| 918 curr = curr->parent(); | 941 curr = curr->parent(); |
| 919 | 942 |
| 920 return curr; | 943 return curr; |
| 921 } | 944 } |
| 922 | 945 |
| (...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3227 } | 3250 } |
| 3228 | 3251 |
| 3229 void showLayerTree(const blink::LayoutObject* layoutObject) { | 3252 void showLayerTree(const blink::LayoutObject* layoutObject) { |
| 3230 if (!layoutObject) { | 3253 if (!layoutObject) { |
| 3231 LOG(INFO) << "Cannot showLayerTree. Root is (nil)"; | 3254 LOG(INFO) << "Cannot showLayerTree. Root is (nil)"; |
| 3232 return; | 3255 return; |
| 3233 } | 3256 } |
| 3234 showLayerTree(layoutObject->enclosingLayer()); | 3257 showLayerTree(layoutObject->enclosingLayer()); |
| 3235 } | 3258 } |
| 3236 #endif | 3259 #endif |
| OLD | NEW |