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

Side by Side Diff: Source/core/rendering/RenderLayerModelObject.cpp

Issue 898783003: Move rendering/RenderLayer* to layout/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2010, 2012 Google Inc. All rights reserved.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
18 *
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
23 */
24
25 #include "config.h"
26 #include "core/rendering/RenderLayerModelObject.h"
27
28 #include "core/frame/LocalFrame.h"
29 #include "core/layout/compositing/CompositedLayerMapping.h"
30 #include "core/rendering/RenderLayer.h"
31 #include "core/rendering/RenderView.h"
32
33 namespace blink {
34
35 bool RenderLayerModelObject::s_wasFloating = false;
36
37 RenderLayerModelObject::RenderLayerModelObject(ContainerNode* node)
38 : RenderObject(node)
39 {
40 }
41
42 RenderLayerModelObject::~RenderLayerModelObject()
43 {
44 // Our layer should have been destroyed and cleared by now
45 ASSERT(!hasLayer());
46 ASSERT(!m_layer);
47 }
48
49 void RenderLayerModelObject::destroyLayer()
50 {
51 setHasLayer(false);
52 m_layer = nullptr;
53 }
54
55 void RenderLayerModelObject::createLayer(LayerType type)
56 {
57 ASSERT(!m_layer);
58 m_layer = adoptPtr(new RenderLayer(this, type));
59 setHasLayer(true);
60 m_layer->insertOnlyThisLayer();
61 }
62
63 bool RenderLayerModelObject::hasSelfPaintingLayer() const
64 {
65 return m_layer && m_layer->isSelfPaintingLayer();
66 }
67
68 RenderLayerScrollableArea* RenderLayerModelObject::scrollableArea() const
69 {
70 return m_layer ? m_layer->scrollableArea() : 0;
71 }
72
73 void RenderLayerModelObject::willBeDestroyed()
74 {
75 if (isPositioned()) {
76 // Don't use this->view() because the document's renderView has been set to 0 during destruction.
77 if (LocalFrame* frame = this->frame()) {
78 if (FrameView* frameView = frame->view()) {
79 if (style()->hasViewportConstrainedPosition())
80 frameView->removeViewportConstrainedObject(this);
81 }
82 }
83 }
84
85 RenderObject::willBeDestroyed();
86
87 destroyLayer();
88 }
89
90 void RenderLayerModelObject::styleWillChange(StyleDifference diff, const RenderS tyle& newStyle)
91 {
92 s_wasFloating = isFloating();
93
94 if (RenderStyle* oldStyle = style()) {
95 if (parent() && diff.needsPaintInvalidationLayer()) {
96 if (oldStyle->hasAutoClip() != newStyle.hasAutoClip()
97 || oldStyle->clip() != newStyle.clip())
98 layer()->clipper().clearClipRectsIncludingDescendants();
99 }
100 }
101
102 RenderObject::styleWillChange(diff, newStyle);
103 }
104
105 void RenderLayerModelObject::styleDidChange(StyleDifference diff, const RenderSt yle* oldStyle)
106 {
107 bool hadTransform = hasTransformRelatedProperty();
108 bool hadLayer = hasLayer();
109 bool layerWasSelfPainting = hadLayer && layer()->isSelfPaintingLayer();
110
111 RenderObject::styleDidChange(diff, oldStyle);
112 updateFromStyle();
113
114 LayerType type = layerTypeRequired();
115 if (type != NoLayer) {
116 if (!layer() && layerCreationAllowedForSubtree()) {
117 if (s_wasFloating && isFloating())
118 setChildNeedsLayout();
119 createLayer(type);
120 if (parent() && !needsLayout()) {
121 // FIXME: We should call a specialized version of this function.
122 layer()->updateLayerPositionsAfterLayout();
123 }
124 }
125 } else if (layer() && layer()->parent()) {
126 setHasTransformRelatedProperty(false); // Either a transform wasn't spec ified or the object doesn't support transforms, so just null out the bit.
127 setHasReflection(false);
128 layer()->removeOnlyThisLayer(); // calls destroyLayer() which clears m_l ayer
129 if (s_wasFloating && isFloating())
130 setChildNeedsLayout();
131 if (hadTransform)
132 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
133 }
134
135 if (layer()) {
136 // FIXME: Ideally we shouldn't need this setter but we can't easily infe r an overflow-only layer
137 // from the style.
138 layer()->setLayerType(type);
139
140 layer()->styleChanged(diff, oldStyle);
141 if (hadLayer && layer()->isSelfPaintingLayer() != layerWasSelfPainting)
142 setChildNeedsLayout();
143 }
144
145 if (FrameView *frameView = view()->frameView()) {
146 bool newStyleIsViewportConstained = style()->hasViewportConstrainedPosit ion();
147 bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportCo nstrainedPosition();
148 if (newStyleIsViewportConstained != oldStyleIsViewportConstrained) {
149 if (newStyleIsViewportConstained && layer())
150 frameView->addViewportConstrainedObject(this);
151 else
152 frameView->removeViewportConstrainedObject(this);
153 }
154 }
155 }
156
157 void RenderLayerModelObject::addLayerHitTestRects(LayerHitTestRects& rects, cons t RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& c ontainerRect) const
158 {
159 if (hasLayer()) {
160 if (isRenderView()) {
161 // RenderView is handled with a special fast-path, but it needs to k now the current layer.
162 RenderObject::addLayerHitTestRects(rects, layer(), LayoutPoint(), La youtRect());
163 } else {
164 // Since a RenderObject never lives outside it's container RenderLay er, we can switch
165 // to marking entire layers instead. This may sometimes mark more th an necessary (when
166 // a layer is made of disjoint objects) but in practice is a signifi cant performance
167 // savings.
168 layer()->addLayerHitTestRects(rects);
169 }
170 } else {
171 RenderObject::addLayerHitTestRects(rects, currentLayer, layerOffset, con tainerRect);
172 }
173 }
174
175 void RenderLayerModelObject::invalidateTreeIfNeeded(const PaintInvalidationState & paintInvalidationState)
176 {
177 ASSERT(!needsLayout());
178
179 if (!shouldCheckForPaintInvalidation(paintInvalidationState))
180 return;
181
182 bool establishesNewPaintInvalidationContainer = isPaintInvalidationContainer ();
183 const RenderLayerModelObject& newPaintInvalidationContainer = *adjustComposi tedContainerForSpecialAncestors(establishesNewPaintInvalidationContainer ? this : &paintInvalidationState.paintInvalidationContainer());
184 // FIXME: This assert should be re-enabled when we move paint invalidation t o after compositing update. crbug.com/360286
185 // ASSERT(&newPaintInvalidationContainer == containerForPaintInvalidation()) ;
186
187 PaintInvalidationReason reason = invalidatePaintIfNeeded(paintInvalidationSt ate, newPaintInvalidationContainer);
188 clearPaintInvalidationState(paintInvalidationState);
189
190 PaintInvalidationState childTreeWalkState(paintInvalidationState, *this, new PaintInvalidationContainer);
191 if (reason == PaintInvalidationLocationChange)
192 childTreeWalkState.setForceCheckForPaintInvalidation();
193 invalidatePaintOfSubtreesIfNeeded(childTreeWalkState);
194 }
195
196 void RenderLayerModelObject::setBackingNeedsPaintInvalidationInRect(const Layout Rect& r, PaintInvalidationReason invalidationReason) const
197 {
198 // https://bugs.webkit.org/show_bug.cgi?id=61159 describes an unreproducible crash here,
199 // so assert but check that the layer is composited.
200 ASSERT(compositingState() != NotComposited);
201
202 // FIXME: generalize accessors to backing GraphicsLayers so that this code i s squashing-agnostic.
203 if (layer()->groupedMapping()) {
204 LayoutRect paintInvalidationRect = r;
205 if (GraphicsLayer* squashingLayer = layer()->groupedMapping()->squashing Layer()) {
206 // Note: the subpixel accumulation of layer() does not need to be ad ded here. It is already taken into account.
207 squashingLayer->setNeedsDisplayInRect(pixelSnappedIntRect(paintInval idationRect), invalidationReason);
208 }
209 } else {
210 layer()->compositedLayerMapping()->setContentsNeedDisplayInRect(r, inval idationReason);
211 }
212 }
213
214 void RenderLayerModelObject::addChildFocusRingRects(Vector<LayoutRect>& rects, c onst LayoutPoint& additionalOffset) const
215 {
216 for (RenderObject* current = slowFirstChild(); current; current = current->n extSibling()) {
217 if (current->isText() || current->isListMarker())
218 continue;
219
220 if (!current->isBox()) {
221 current->addFocusRingRects(rects, additionalOffset);
222 continue;
223 }
224
225 RenderBox* box = toRenderBox(current);
226 if (!box->hasLayer()) {
227 box->addFocusRingRects(rects, additionalOffset + box->locationOffset ());
228 continue;
229 }
230
231 Vector<LayoutRect> layerFocusRingRects;
232 box->addFocusRingRects(layerFocusRingRects, LayoutPoint());
233 for (size_t i = 0; i < layerFocusRingRects.size(); ++i) {
234 FloatQuad quadInBox = box->localToContainerQuad(FloatQuad(layerFocus RingRects[i]), this);
235 LayoutRect rect = LayoutRect(quadInBox.boundingBox());
236 if (!rect.isEmpty()) {
237 rect.moveBy(additionalOffset);
238 rects.append(rect);
239 }
240 }
241 }
242 }
243
244 } // namespace blink
245
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderLayerModelObject.h ('k') | Source/core/rendering/RenderLayerReflectionInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698