OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 , m_transformedStepsCount(0) | 47 , m_transformedStepsCount(0) |
48 , m_fixedStepsCount(0) | 48 , m_fixedStepsCount(0) |
49 , m_mapCoordinatesFlags(flags) | 49 , m_mapCoordinatesFlags(flags) |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 LayoutGeometryMap::~LayoutGeometryMap() | 53 LayoutGeometryMap::~LayoutGeometryMap() |
54 { | 54 { |
55 } | 55 } |
56 | 56 |
57 void LayoutGeometryMap::mapToContainer(TransformState& transformState, const Lay
outBoxModelObject* container) const | 57 void LayoutGeometryMap::mapToAncestor(TransformState& transformState, const Layo
utBoxModelObject* ancestor) const |
58 { | 58 { |
59 // If the mapping includes something like columns, we have to go via layoutO
bjects. | 59 // If the mapping includes something like columns, we have to go via layoutO
bjects. |
60 if (hasNonUniformStep()) { | 60 if (hasNonUniformStep()) { |
61 m_mapping.last().m_layoutObject->mapLocalToContainer(container, transfor
mState, ApplyContainerFlip | m_mapCoordinatesFlags); | 61 m_mapping.last().m_layoutObject->mapLocalToAncestor(ancestor, transformS
tate, ApplyContainerFlip | m_mapCoordinatesFlags); |
62 transformState.flatten(); | 62 transformState.flatten(); |
63 return; | 63 return; |
64 } | 64 } |
65 | 65 |
66 bool inFixed = false; | 66 bool inFixed = false; |
67 #if ENABLE(ASSERT) | 67 #if ENABLE(ASSERT) |
68 bool foundContainer = !container || (m_mapping.size() && m_mapping[0].m_layo
utObject == container); | 68 bool foundAncestor = !ancestor || (m_mapping.size() && m_mapping[0].m_layout
Object == ancestor); |
69 #endif | 69 #endif |
70 | 70 |
71 for (int i = m_mapping.size() - 1; i >= 0; --i) { | 71 for (int i = m_mapping.size() - 1; i >= 0; --i) { |
72 const LayoutGeometryMapStep& currentStep = m_mapping[i]; | 72 const LayoutGeometryMapStep& currentStep = m_mapping[i]; |
73 | 73 |
74 // If container is the root LayoutView (step 0) we want to apply its fix
ed position offset. | 74 // If container is the root LayoutView (step 0) we want to apply its fix
ed position offset. |
75 if (i > 0 && currentStep.m_layoutObject == container) { | 75 if (i > 0 && currentStep.m_layoutObject == ancestor) { |
76 #if ENABLE(ASSERT) | 76 #if ENABLE(ASSERT) |
77 foundContainer = true; | 77 foundAncestor = true; |
78 #endif | 78 #endif |
79 break; | 79 break; |
80 } | 80 } |
81 | 81 |
82 // If this box has a transform, it acts as a fixed position container | 82 // If this box has a transform, it acts as a fixed position container |
83 // for fixed descendants, which prevents the propagation of 'fixed' | 83 // for fixed descendants, which prevents the propagation of 'fixed' |
84 // unless the layer itself is also fixed position. | 84 // unless the layer itself is also fixed position. |
85 if (i && currentStep.m_hasTransform && !currentStep.m_isFixedPosition) | 85 if (i && currentStep.m_hasTransform && !currentStep.m_isFixedPosition) |
86 inFixed = false; | 86 inFixed = false; |
87 else if (currentStep.m_isFixedPosition) | 87 else if (currentStep.m_isFixedPosition) |
88 inFixed = true; | 88 inFixed = true; |
89 | 89 |
90 ASSERT(!i == isTopmostLayoutView(currentStep.m_layoutObject)); | 90 ASSERT(!i == isTopmostLayoutView(currentStep.m_layoutObject)); |
91 | 91 |
92 if (!i) { | 92 if (!i) { |
93 // A null container indicates mapping through the root LayoutView, s
o including its transform (the page scale). | 93 // A null container indicates mapping through the root LayoutView, s
o including its transform (the page scale). |
94 if (!container && currentStep.m_transform) | 94 if (!ancestor && currentStep.m_transform) |
95 transformState.applyTransform(*currentStep.m_transform.get()); | 95 transformState.applyTransform(*currentStep.m_transform.get()); |
96 } else { | 96 } else { |
97 TransformState::TransformAccumulation accumulate = currentStep.m_acc
umulatingTransform ? TransformState::AccumulateTransform : TransformState::Flatt
enTransform; | 97 TransformState::TransformAccumulation accumulate = currentStep.m_acc
umulatingTransform ? TransformState::AccumulateTransform : TransformState::Flatt
enTransform; |
98 if (currentStep.m_transform) | 98 if (currentStep.m_transform) |
99 transformState.applyTransform(*currentStep.m_transform.get(), ac
cumulate); | 99 transformState.applyTransform(*currentStep.m_transform.get(), ac
cumulate); |
100 else | 100 else |
101 transformState.move(currentStep.m_offset.width(), currentStep.m_
offset.height(), accumulate); | 101 transformState.move(currentStep.m_offset.width(), currentStep.m_
offset.height(), accumulate); |
102 } | 102 } |
103 | 103 |
104 if (inFixed && !currentStep.m_offsetForFixedPosition.isZero()) { | 104 if (inFixed && !currentStep.m_offsetForFixedPosition.isZero()) { |
105 ASSERT(currentStep.m_layoutObject->isLayoutView()); | 105 ASSERT(currentStep.m_layoutObject->isLayoutView()); |
106 transformState.move(currentStep.m_offsetForFixedPosition); | 106 transformState.move(currentStep.m_offsetForFixedPosition); |
107 } | 107 } |
108 } | 108 } |
109 | 109 |
110 ASSERT(foundContainer); | 110 ASSERT(foundAncestor); |
111 transformState.flatten(); | 111 transformState.flatten(); |
112 } | 112 } |
113 | 113 |
114 #ifndef NDEBUG | 114 #ifndef NDEBUG |
115 // Handy function to call from gdb while debugging mismatched point/rect errors. | 115 // Handy function to call from gdb while debugging mismatched point/rect errors. |
116 void LayoutGeometryMap::dumpSteps() const | 116 void LayoutGeometryMap::dumpSteps() const |
117 { | 117 { |
118 fprintf(stderr, "LayoutGeometryMap::dumpSteps accumulatedOffset=%d,%d\n", m_
accumulatedOffset.width().toInt(), m_accumulatedOffset.height().toInt()); | 118 fprintf(stderr, "LayoutGeometryMap::dumpSteps accumulatedOffset=%d,%d\n", m_
accumulatedOffset.width().toInt(), m_accumulatedOffset.height().toInt()); |
119 for (int i = m_mapping.size() - 1; i >= 0; --i) { | 119 for (int i = m_mapping.size() - 1; i >= 0; --i) { |
120 fprintf(stderr, " [%d] %s: offset=%d,%d", i, | 120 fprintf(stderr, " [%d] %s: offset=%d,%d", i, |
121 m_mapping[i].m_layoutObject->debugName().ascii().data(), | 121 m_mapping[i].m_layoutObject->debugName().ascii().data(), |
122 m_mapping[i].m_offset.width().toInt(), | 122 m_mapping[i].m_offset.width().toInt(), |
123 m_mapping[i].m_offset.height().toInt()); | 123 m_mapping[i].m_offset.height().toInt()); |
124 if (m_mapping[i].m_hasTransform) | 124 if (m_mapping[i].m_hasTransform) |
125 fprintf(stderr, " hasTransform"); | 125 fprintf(stderr, " hasTransform"); |
126 fprintf(stderr, "\n"); | 126 fprintf(stderr, "\n"); |
127 } | 127 } |
128 } | 128 } |
129 #endif | 129 #endif |
130 | 130 |
131 FloatQuad LayoutGeometryMap::mapToContainer(const FloatRect& rect, const LayoutB
oxModelObject* container) const | 131 FloatQuad LayoutGeometryMap::mapToAncestor(const FloatRect& rect, const LayoutBo
xModelObject* ancestor) const |
132 { | 132 { |
133 FloatQuad result; | 133 FloatQuad result; |
134 | 134 |
135 if (!hasFixedPositionStep() && !hasTransformStep() && !hasNonUniformStep() &
& (!container || (m_mapping.size() && container == m_mapping[0].m_layoutObject))
) { | 135 if (!hasFixedPositionStep() && !hasTransformStep() && !hasNonUniformStep() &
& (!ancestor || (m_mapping.size() && ancestor == m_mapping[0].m_layoutObject)))
{ |
136 result = rect; | 136 result = rect; |
137 result.move(m_accumulatedOffset); | 137 result.move(m_accumulatedOffset); |
138 } else { | 138 } else { |
139 TransformState transformState(TransformState::ApplyTransformDirection, r
ect.center(), rect); | 139 TransformState transformState(TransformState::ApplyTransformDirection, r
ect.center(), rect); |
140 mapToContainer(transformState, container); | 140 mapToAncestor(transformState, ancestor); |
141 result = transformState.lastPlanarQuad(); | 141 result = transformState.lastPlanarQuad(); |
142 } | 142 } |
143 | 143 |
144 #if ENABLE(ASSERT) | 144 #if ENABLE(ASSERT) |
145 if (m_mapping.size() > 0) { | 145 if (m_mapping.size() > 0) { |
146 const LayoutObject* lastLayoutObject = m_mapping.last().m_layoutObject; | 146 const LayoutObject* lastLayoutObject = m_mapping.last().m_layoutObject; |
147 | 147 |
148 FloatRect layoutObjectMappedResult = lastLayoutObject->localToContainerQ
uad(rect, container, m_mapCoordinatesFlags).boundingBox(); | 148 FloatRect layoutObjectMappedResult = lastLayoutObject->localToAncestorQu
ad(rect, ancestor, m_mapCoordinatesFlags).boundingBox(); |
149 | 149 |
150 // Inspector creates layoutObjects with negative width <https://bugs.web
kit.org/show_bug.cgi?id=87194>. | 150 // Inspector creates layoutObjects with negative width <https://bugs.web
kit.org/show_bug.cgi?id=87194>. |
151 // Taking FloatQuad bounds avoids spurious assertions because of that. | 151 // Taking FloatQuad bounds avoids spurious assertions because of that. |
152 ASSERT(enclosingIntRect(layoutObjectMappedResult) == enclosingIntRect(re
sult.boundingBox()) | 152 ASSERT(enclosingIntRect(layoutObjectMappedResult) == enclosingIntRect(re
sult.boundingBox()) |
153 || layoutObjectMappedResult.mayNotHaveExactIntRectRepresentation() | 153 || layoutObjectMappedResult.mayNotHaveExactIntRectRepresentation() |
154 || result.boundingBox().mayNotHaveExactIntRectRepresentation()); | 154 || result.boundingBox().mayNotHaveExactIntRectRepresentation()); |
155 } | 155 } |
156 #endif | 156 #endif |
157 | 157 |
158 return result; | 158 return result; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // If we're not working with multiple LayoutViews, then any view is consider
ed | 313 // If we're not working with multiple LayoutViews, then any view is consider
ed |
314 // "topmost" (to preserve original behavior). | 314 // "topmost" (to preserve original behavior). |
315 if (!(m_mapCoordinatesFlags & TraverseDocumentBoundaries)) | 315 if (!(m_mapCoordinatesFlags & TraverseDocumentBoundaries)) |
316 return true; | 316 return true; |
317 | 317 |
318 return layoutObject->frame()->isMainFrame(); | 318 return layoutObject->frame()->isMainFrame(); |
319 } | 319 } |
320 #endif | 320 #endif |
321 | 321 |
322 } // namespace blink | 322 } // namespace blink |
OLD | NEW |