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.
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.
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.
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.
26 #include "core/rendering/RenderLayerModelObject.h"
28 #include "core/frame/LocalFrame.h"
29 #include "core/rendering/RenderLayer.h"
30 #include "core/rendering/RenderView.h"
34 bool RenderLayerModelObject::s_wasFloating = false;
36 RenderLayerModelObject::RenderLayerModelObject(ContainerNode* node)
41 RenderLayerModelObject::~RenderLayerModelObject()
43 // Our layer should have been destroyed and cleared by now
48 void RenderLayerModelObject::destroyLayer()
54 void RenderLayerModelObject::createLayer(LayerType type)
57 m_layer = adoptPtr(new RenderLayer(this, type));
59 m_layer->insertOnlyThisLayer();
62 bool RenderLayerModelObject::hasSelfPaintingLayer() const
64 return m_layer && m_layer->isSelfPaintingLayer();
67 ScrollableArea* RenderLayerModelObject::scrollableArea() const
69 return m_layer ? m_layer->scrollableArea() : 0;
72 void RenderLayerModelObject::willBeDestroyed()
75 // Don't use this->view() because the document's renderView has been set to 0 during destruction.
76 if (LocalFrame* frame = this->frame()) {
77 if (FrameView* frameView = frame->view()) {
78 if (style()->hasViewportConstrainedPosition())
79 frameView->removeViewportConstrainedObject(this);
84 RenderObject::willBeDestroyed();
89 void RenderLayerModelObject::styleWillChange(StyleDifference diff, const RenderStyle& newStyle)
91 s_wasFloating = isFloating();
93 if (RenderStyle* oldStyle = style()) {
94 if (parent() && diff.needsPaintInvalidationLayer()) {
95 if (oldStyle->hasClip() != newStyle.hasClip()
96 || oldStyle->clip() != newStyle.clip())
97 layer()->clipper().clearClipRectsIncludingDescendants();
101 RenderObject::styleWillChange(diff, newStyle);
104 void RenderLayerModelObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
106 bool hadTransform = hasTransform();
108 RenderObject::styleDidChange(diff, oldStyle);
111 LayerType type = layerTypeRequired();
112 if (type != NoLayer) {
113 if (!layer() && layerCreationAllowedForSubtree()) {
114 if (s_wasFloating && isFloating())
115 setChildNeedsLayout();
117 if (parent() && !needsLayout()) {
118 // FIXME: This invalidation is overly broad. We should update to
119 // do the correct invalidation at RenderStyle::diff time. crbug.com/349061
120 layer()->renderer()->setShouldDoFullPaintInvalidation(true);
121 // FIXME: We should call a specialized version of this function.
122 layer()->updateLayerPositionsAfterLayout();
125 } else if (layer() && layer()->parent()) {
126 setHasTransform(false); // Either a transform wasn't specified or the object doesn't support transforms, so just null out the bit.
127 setHasReflection(false);
128 layer()->removeOnlyThisLayer(); // calls destroyLayer() which clears m_layer
129 if (s_wasFloating && isFloating())
130 setChildNeedsLayout();
132 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation();
136 // FIXME: Ideally we shouldn't need this setter but we can't easily infer an overflow-only layer
138 layer()->setLayerType(type);
139 layer()->styleChanged(diff, oldStyle);
142 if (FrameView *frameView = view()->frameView()) {
143 bool newStyleIsViewportConstained = style()->hasViewportConstrainedPosition();
144 bool oldStyleIsViewportConstrained = oldStyle && oldStyle->hasViewportConstrainedPosition();
145 if (newStyleIsViewportConstained != oldStyleIsViewportConstrained) {
146 if (newStyleIsViewportConstained && layer())
147 frameView->addViewportConstrainedObject(this);
149 frameView->removeViewportConstrainedObject(this);
154 void RenderLayerModelObject::addLayerHitTestRects(LayerHitTestRects& rects, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const
157 if (isRenderView()) {
158 // RenderView is handled with a special fast-path, but it needs to know the current layer.
159 RenderObject::addLayerHitTestRects(rects, layer(), LayoutPoint(), LayoutRect());
161 // Since a RenderObject never lives outside it's container RenderLayer, we can switch
162 // to marking entire layers instead. This may sometimes mark more than necessary (when
163 // a layer is made of disjoint objects) but in practice is a significant performance
165 layer()->addLayerHitTestRects(rects);
168 RenderObject::addLayerHitTestRects(rects, currentLayer, layerOffset, containerRect);
172 InvalidationReason RenderLayerModelObject::invalidatePaintIfNeeded(const PaintInvalidationState& paintInvalidationState, const RenderLayerModelObject& newPaintInvalidationContainer)
174 const LayoutRect oldPaintInvalidationRect = previousPaintInvalidationRect();
175 const LayoutPoint oldPositionFromPaintInvalidationContainer = previousPositionFromPaintInvalidationContainer();
176 setPreviousPaintInvalidationRect(boundsRectForPaintInvalidation(&newPaintInvalidationContainer, &paintInvalidationState));
177 setPreviousPositionFromPaintInvalidationContainer(RenderLayer::positionFromPaintInvalidationContainer(this, &newPaintInvalidationContainer, &paintInvalidationState));
179 // If we are set to do a full paint invalidation that means the RenderView will issue
180 // paint invalidations. We can then skip issuing of paint invalidations for the child
181 // renderers as they'll be covered by the RenderView.
182 if (view()->doingFullPaintInvalidation())
183 return InvalidationNone;
185 return RenderObject::invalidatePaintIfNeeded(newPaintInvalidationContainer, oldPaintInvalidationRect, oldPositionFromPaintInvalidationContainer, paintInvalidationState);
188 void RenderLayerModelObject::invalidateTreeIfNeeded(const PaintInvalidationState& paintInvalidationState)
190 // FIXME: SVG should probably also go through this unified paint invalidation system.
191 ASSERT(!needsLayout());
193 if (!shouldCheckForPaintInvalidation(paintInvalidationState))
196 bool establishesNewPaintInvalidationContainer = isPaintInvalidationContainer();
197 const RenderLayerModelObject& newPaintInvalidationContainer = *adjustCompositedContainerForSpecialAncestors(establishesNewPaintInvalidationContainer ? this : &paintInvalidationState.paintInvalidationContainer());
198 ASSERT(&newPaintInvalidationContainer == containerForPaintInvalidation());
200 InvalidationReason reason = invalidatePaintIfNeeded(paintInvalidationState, newPaintInvalidationContainer);
202 PaintInvalidationState childTreeWalkState(paintInvalidationState, *this, newPaintInvalidationContainer);
203 if (reason == InvalidationLocationChange || reason == InvalidationFull)
204 childTreeWalkState.setForceCheckForPaintInvalidation();
205 RenderObject::invalidateTreeIfNeeded(childTreeWalkState);