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

Side by Side Diff: Source/core/layout/LayoutPart.cpp

Issue 931003002: Move and rename RenderPart to LayoutPart. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
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
« no previous file with comments | « Source/core/layout/LayoutPart.h ('k') | Source/core/layout/LayoutPartTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Simon Hausmann <hausmann@kde.org> 3 * (C) 2000 Simon Hausmann <hausmann@kde.org>
4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de) 4 * (C) 2000 Stefan Schimanski (1Stein@gmx.de)
5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "core/rendering/RenderPart.h" 26 #include "core/layout/LayoutPart.h"
27 27
28 #include "core/dom/AXObjectCache.h" 28 #include "core/dom/AXObjectCache.h"
29 #include "core/frame/FrameView.h" 29 #include "core/frame/FrameView.h"
30 #include "core/frame/LocalFrame.h" 30 #include "core/frame/LocalFrame.h"
31 #include "core/html/HTMLFrameElementBase.h" 31 #include "core/html/HTMLFrameElementBase.h"
32 #include "core/layout/HitTestResult.h" 32 #include "core/layout/HitTestResult.h"
33 #include "core/layout/Layer.h" 33 #include "core/layout/Layer.h"
34 #include "core/paint/BoxPainter.h" 34 #include "core/paint/BoxPainter.h"
35 #include "core/paint/PartPainter.h" 35 #include "core/paint/PartPainter.h"
36 #include "core/plugins/PluginView.h" 36 #include "core/plugins/PluginView.h"
37 #include "core/rendering/RenderView.h" 37 #include "core/rendering/RenderView.h"
38 #include "core/rendering/svg/RenderSVGRoot.h" 38 #include "core/rendering/svg/RenderSVGRoot.h"
39 39
40 namespace blink { 40 namespace blink {
41 41
42 RenderPart::RenderPart(Element* element) 42 LayoutPart::LayoutPart(Element* element)
43 : LayoutReplaced(element) 43 : LayoutReplaced(element)
44 // Reference counting is used to prevent the part from being destroyed 44 // Reference counting is used to prevent the part from being destroyed
45 // while inside the Widget code, which might not be able to handle that. 45 // while inside the Widget code, which might not be able to handle that.
46 , m_refCount(1) 46 , m_refCount(1)
47 { 47 {
48 ASSERT(element); 48 ASSERT(element);
49 frameView()->addPart(this); 49 frameView()->addPart(this);
50 setInline(false); 50 setInline(false);
51 } 51 }
52 52
53 void RenderPart::deref() 53 void LayoutPart::deref()
54 { 54 {
55 if (--m_refCount <= 0) 55 if (--m_refCount <= 0)
56 postDestroy(); 56 postDestroy();
57 } 57 }
58 58
59 void RenderPart::willBeDestroyed() 59 void LayoutPart::willBeDestroyed()
60 { 60 {
61 frameView()->removePart(this); 61 frameView()->removePart(this);
62 62
63 if (AXObjectCache* cache = document().existingAXObjectCache()) { 63 if (AXObjectCache* cache = document().existingAXObjectCache()) {
64 cache->childrenChanged(this->parent()); 64 cache->childrenChanged(this->parent());
65 cache->remove(this); 65 cache->remove(this);
66 } 66 }
67 67
68 Element* element = toElement(node()); 68 Element* element = toElement(node());
69 if (element && element->isFrameOwnerElement()) 69 if (element && element->isFrameOwnerElement())
70 toHTMLFrameOwnerElement(element)->setWidget(nullptr); 70 toHTMLFrameOwnerElement(element)->setWidget(nullptr);
71 71
72 LayoutReplaced::willBeDestroyed(); 72 LayoutReplaced::willBeDestroyed();
73 } 73 }
74 74
75 void RenderPart::destroy() 75 void LayoutPart::destroy()
76 { 76 {
77 willBeDestroyed(); 77 willBeDestroyed();
78 clearNode(); 78 clearNode();
79 deref(); 79 deref();
80 } 80 }
81 81
82 RenderPart::~RenderPart() 82 LayoutPart::~LayoutPart()
83 { 83 {
84 ASSERT(m_refCount <= 0); 84 ASSERT(m_refCount <= 0);
85 } 85 }
86 86
87 Widget* RenderPart::widget() const 87 Widget* LayoutPart::widget() const
88 { 88 {
89 // Plugin widgets are stored in their DOM node. This includes HTMLAppletElem ent. 89 // Plugin widgets are stored in their DOM node. This includes HTMLAppletElem ent.
90 Element* element = toElement(node()); 90 Element* element = toElement(node());
91 91
92 if (element && element->isFrameOwnerElement()) 92 if (element && element->isFrameOwnerElement())
93 return toHTMLFrameOwnerElement(element)->ownedWidget(); 93 return toHTMLFrameOwnerElement(element)->ownedWidget();
94 94
95 return 0; 95 return 0;
96 } 96 }
97 97
98 LayerType RenderPart::layerTypeRequired() const 98 LayerType LayoutPart::layerTypeRequired() const
99 { 99 {
100 LayerType type = LayoutReplaced::layerTypeRequired(); 100 LayerType type = LayoutReplaced::layerTypeRequired();
101 if (type != NoLayer) 101 if (type != NoLayer)
102 return type; 102 return type;
103 return ForcedLayer; 103 return ForcedLayer;
104 } 104 }
105 105
106 bool RenderPart::requiresAcceleratedCompositing() const 106 bool LayoutPart::requiresAcceleratedCompositing() const
107 { 107 {
108 // There are two general cases in which we can return true. First, if this i s a plugin 108 // There are two general cases in which we can return true. First, if this i s a plugin
109 // renderer and the plugin has a layer, then we need a layer. Second, if thi s is 109 // renderer and the plugin has a layer, then we need a layer. Second, if thi s is
110 // a renderer with a contentDocument and that document needs a layer, then w e need 110 // a renderer with a contentDocument and that document needs a layer, then w e need
111 // a layer. 111 // a layer.
112 if (widget() && widget()->isPluginView() && toPluginView(widget())->platform Layer()) 112 if (widget() && widget()->isPluginView() && toPluginView(widget())->platform Layer())
113 return true; 113 return true;
114 114
115 if (!node() || !node()->isFrameOwnerElement()) 115 if (!node() || !node()->isFrameOwnerElement())
116 return false; 116 return false;
117 117
118 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); 118 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node());
119 if (element->contentFrame() && element->contentFrame()->isRemoteFrame()) 119 if (element->contentFrame() && element->contentFrame()->isRemoteFrame())
120 return true; 120 return true;
121 121
122 if (Document* contentDocument = element->contentDocument()) { 122 if (Document* contentDocument = element->contentDocument()) {
123 if (RenderView* view = contentDocument->renderView()) 123 if (RenderView* view = contentDocument->renderView())
124 return view->usesCompositing(); 124 return view->usesCompositing();
125 } 125 }
126 126
127 return false; 127 return false;
128 } 128 }
129 129
130 bool RenderPart::needsPreferredWidthsRecalculation() const 130 bool LayoutPart::needsPreferredWidthsRecalculation() const
131 { 131 {
132 if (LayoutReplaced::needsPreferredWidthsRecalculation()) 132 if (LayoutReplaced::needsPreferredWidthsRecalculation())
133 return true; 133 return true;
134 return embeddedContentBox(); 134 return embeddedContentBox();
135 } 135 }
136 136
137 bool RenderPart::nodeAtPointOverWidget(const HitTestRequest& request, HitTestRes ult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accu mulatedOffset, HitTestAction action) 137 bool LayoutPart::nodeAtPointOverWidget(const HitTestRequest& request, HitTestRes ult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accu mulatedOffset, HitTestAction action)
138 { 138 {
139 bool hadResult = result.innerNode(); 139 bool hadResult = result.innerNode();
140 bool inside = LayoutReplaced::nodeAtPoint(request, result, locationInContain er, accumulatedOffset, action); 140 bool inside = LayoutReplaced::nodeAtPoint(request, result, locationInContain er, accumulatedOffset, action);
141 141
142 // Check to see if we are really over the widget itself (and not just in the border/padding area). 142 // Check to see if we are really over the widget itself (and not just in the border/padding area).
143 if ((inside || result.isRectBasedTest()) && !hadResult && result.innerNode() == node()) 143 if ((inside || result.isRectBasedTest()) && !hadResult && result.innerNode() == node())
144 result.setIsOverWidget(contentBoxRect().contains(result.localPoint())); 144 result.setIsOverWidget(contentBoxRect().contains(result.localPoint()));
145 return inside; 145 return inside;
146 } 146 }
147 147
148 bool RenderPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& resul t, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOff set, HitTestAction action) 148 bool LayoutPart::nodeAtPoint(const HitTestRequest& request, HitTestResult& resul t, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOff set, HitTestAction action)
149 { 149 {
150 if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameConten t()) 150 if (!widget() || !widget()->isFrameView() || !request.allowsChildFrameConten t())
151 return nodeAtPointOverWidget(request, result, locationInContainer, accum ulatedOffset, action); 151 return nodeAtPointOverWidget(request, result, locationInContainer, accum ulatedOffset, action);
152 152
153 FrameView* childFrameView = toFrameView(widget()); 153 FrameView* childFrameView = toFrameView(widget());
154 RenderView* childRoot = childFrameView->renderView(); 154 RenderView* childRoot = childFrameView->renderView();
155 155
156 if (visibleToHitTestRequest(request) && childRoot) { 156 if (visibleToHitTestRequest(request) && childRoot) {
157 LayoutPoint adjustedLocation = accumulatedOffset + location(); 157 LayoutPoint adjustedLocation = accumulatedOffset + location();
158 LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), bo rderTop() + paddingTop()) - LayoutSize(childFrameView->scrollOffset()); 158 LayoutPoint contentOffset = LayoutPoint(borderLeft() + paddingLeft(), bo rderTop() + paddingTop()) - LayoutSize(childFrameView->scrollOffset());
159 HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocatio n - contentOffset); 159 HitTestLocation newHitTestLocation(locationInContainer, -adjustedLocatio n - contentOffset);
160 HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildF rameHitTest); 160 HitTestRequest newHitTestRequest(request.type() | HitTestRequest::ChildF rameHitTest);
161 HitTestResult childFrameResult(newHitTestLocation); 161 HitTestResult childFrameResult(newHitTestLocation);
162 162
163 bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTe stLocation, childFrameResult); 163 bool isInsideChildFrame = childRoot->hitTest(newHitTestRequest, newHitTe stLocation, childFrameResult);
164 164
165 if (newHitTestLocation.isRectBasedTest()) 165 if (newHitTestLocation.isRectBasedTest())
166 result.append(childFrameResult); 166 result.append(childFrameResult);
167 else if (isInsideChildFrame) 167 else if (isInsideChildFrame)
168 result = childFrameResult; 168 result = childFrameResult;
169 169
170 if (isInsideChildFrame) 170 if (isInsideChildFrame)
171 return true; 171 return true;
172 } 172 }
173 173
174 return nodeAtPointOverWidget(request, result, locationInContainer, accumulat edOffset, action); 174 return nodeAtPointOverWidget(request, result, locationInContainer, accumulat edOffset, action);
175 } 175 }
176 176
177 CompositingReasons RenderPart::additionalCompositingReasons() const 177 CompositingReasons LayoutPart::additionalCompositingReasons() const
178 { 178 {
179 if (requiresAcceleratedCompositing()) 179 if (requiresAcceleratedCompositing())
180 return CompositingReasonIFrame; 180 return CompositingReasonIFrame;
181 return CompositingReasonNone; 181 return CompositingReasonNone;
182 } 182 }
183 183
184 void RenderPart::styleDidChange(StyleDifference diff, const LayoutStyle* oldStyl e) 184 void LayoutPart::styleDidChange(StyleDifference diff, const LayoutStyle* oldStyl e)
185 { 185 {
186 LayoutReplaced::styleDidChange(diff, oldStyle); 186 LayoutReplaced::styleDidChange(diff, oldStyle);
187 Widget* widget = this->widget(); 187 Widget* widget = this->widget();
188 188
189 if (!widget) 189 if (!widget)
190 return; 190 return;
191 191
192 // If the iframe has custom scrollbars, recalculate their style. 192 // If the iframe has custom scrollbars, recalculate their style.
193 if (widget && widget->isFrameView()) 193 if (widget && widget->isFrameView())
194 toFrameView(widget)->recalculateCustomScrollbarStyle(); 194 toFrameView(widget)->recalculateCustomScrollbarStyle();
195 195
196 if (style()->visibility() != VISIBLE) { 196 if (style()->visibility() != VISIBLE) {
197 widget->hide(); 197 widget->hide();
198 } else { 198 } else {
199 widget->show(); 199 widget->show();
200 } 200 }
201 } 201 }
202 202
203 void RenderPart::layout() 203 void LayoutPart::layout()
204 { 204 {
205 ASSERT(needsLayout()); 205 ASSERT(needsLayout());
206 206
207 clearNeedsLayout(); 207 clearNeedsLayout();
208 } 208 }
209 209
210 void RenderPart::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffse t) 210 void LayoutPart::paint(const PaintInfo& paintInfo, const LayoutPoint& paintOffse t)
211 { 211 {
212 PartPainter(*this).paint(paintInfo, paintOffset); 212 PartPainter(*this).paint(paintInfo, paintOffset);
213 } 213 }
214 214
215 void RenderPart::paintContents(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset) 215 void LayoutPart::paintContents(const PaintInfo& paintInfo, const LayoutPoint& pa intOffset)
216 { 216 {
217 PartPainter(*this).paintContents(paintInfo, paintOffset); 217 PartPainter(*this).paintContents(paintInfo, paintOffset);
218 } 218 }
219 219
220 CursorDirective RenderPart::getCursor(const LayoutPoint& point, Cursor& cursor) const 220 CursorDirective LayoutPart::getCursor(const LayoutPoint& point, Cursor& cursor) const
221 { 221 {
222 if (widget() && widget()->isPluginView()) { 222 if (widget() && widget()->isPluginView()) {
223 // A plug-in is responsible for setting the cursor when the pointer is o ver it. 223 // A plug-in is responsible for setting the cursor when the pointer is o ver it.
224 return DoNotSetCursor; 224 return DoNotSetCursor;
225 } 225 }
226 return LayoutReplaced::getCursor(point, cursor); 226 return LayoutReplaced::getCursor(point, cursor);
227 } 227 }
228 228
229 void RenderPart::updateOnWidgetChange() 229 void LayoutPart::updateOnWidgetChange()
230 { 230 {
231 Widget* widget = this->widget(); 231 Widget* widget = this->widget();
232 if (!widget) 232 if (!widget)
233 return; 233 return;
234 234
235 if (!style()) 235 if (!style())
236 return; 236 return;
237 237
238 if (!needsLayout()) 238 if (!needsLayout())
239 updateWidgetGeometry(); 239 updateWidgetGeometry();
240 240
241 if (style()->visibility() != VISIBLE) { 241 if (style()->visibility() != VISIBLE) {
242 widget->hide(); 242 widget->hide();
243 } else { 243 } else {
244 widget->show(); 244 widget->show();
245 // FIXME: Why do we issue a full paint invalidation in this case, but no t the other? 245 // FIXME: Why do we issue a full paint invalidation in this case, but no t the other?
246 setShouldDoFullPaintInvalidation(); 246 setShouldDoFullPaintInvalidation();
247 } 247 }
248 } 248 }
249 249
250 void RenderPart::updateWidgetPosition() 250 void LayoutPart::updateWidgetPosition()
251 { 251 {
252 Widget* widget = this->widget(); 252 Widget* widget = this->widget();
253 if (!widget || !node()) // Check the node in case destroy() has been called. 253 if (!widget || !node()) // Check the node in case destroy() has been called.
254 return; 254 return;
255 255
256 bool boundsChanged = updateWidgetGeometry(); 256 bool boundsChanged = updateWidgetGeometry();
257 257
258 // If the frame bounds got changed, or if view needs layout (possibly indica ting 258 // If the frame bounds got changed, or if view needs layout (possibly indica ting
259 // content size is wrong) we have to do a layout to set the right widget siz e. 259 // content size is wrong) we have to do a layout to set the right widget siz e.
260 if (widget && widget->isFrameView()) { 260 if (widget && widget->isFrameView()) {
261 FrameView* frameView = toFrameView(widget); 261 FrameView* frameView = toFrameView(widget);
262 // Check the frame's page to make sure that the frame isn't in the proce ss of being destroyed. 262 // Check the frame's page to make sure that the frame isn't in the proce ss of being destroyed.
263 if ((boundsChanged || frameView->needsLayout()) && frameView->frame().pa ge()) 263 if ((boundsChanged || frameView->needsLayout()) && frameView->frame().pa ge())
264 frameView->layout(); 264 frameView->layout();
265 } 265 }
266 } 266 }
267 267
268 void RenderPart::widgetPositionsUpdated() 268 void LayoutPart::widgetPositionsUpdated()
269 { 269 {
270 Widget* widget = this->widget(); 270 Widget* widget = this->widget();
271 if (!widget) 271 if (!widget)
272 return; 272 return;
273 widget->widgetPositionsUpdated(); 273 widget->widgetPositionsUpdated();
274 } 274 }
275 275
276 bool RenderPart::updateWidgetGeometry() 276 bool LayoutPart::updateWidgetGeometry()
277 { 277 {
278 Widget* widget = this->widget(); 278 Widget* widget = this->widget();
279 ASSERT(widget); 279 ASSERT(widget);
280 280
281 LayoutRect contentBox = contentBoxRect(); 281 LayoutRect contentBox = contentBoxRect();
282 LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).bou ndingBox()); 282 LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).bou ndingBox());
283 if (widget->isFrameView()) { 283 if (widget->isFrameView()) {
284 contentBox.setLocation(absoluteContentBox.location()); 284 contentBox.setLocation(absoluteContentBox.location());
285 return setWidgetGeometry(contentBox); 285 return setWidgetGeometry(contentBox);
286 } 286 }
287 287
288 return setWidgetGeometry(absoluteContentBox); 288 return setWidgetGeometry(absoluteContentBox);
289 } 289 }
290 290
291 // Widgets are always placed on integer boundaries, so rounding the size is actu ally 291 // Widgets are always placed on integer boundaries, so rounding the size is actu ally
292 // the desired behavior. This function is here because it's otherwise seldom wha t we 292 // the desired behavior. This function is here because it's otherwise seldom wha t we
293 // want to do with a LayoutRect. 293 // want to do with a LayoutRect.
294 static inline IntRect roundedIntRect(const LayoutRect& rect) 294 static inline IntRect roundedIntRect(const LayoutRect& rect)
295 { 295 {
296 return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()) ); 296 return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()) );
297 } 297 }
298 298
299 bool RenderPart::setWidgetGeometry(const LayoutRect& frame) 299 bool LayoutPart::setWidgetGeometry(const LayoutRect& frame)
300 { 300 {
301 if (!node()) 301 if (!node())
302 return false; 302 return false;
303 303
304 Widget* widget = this->widget(); 304 Widget* widget = this->widget();
305 ASSERT(widget); 305 ASSERT(widget);
306 306
307 IntRect newFrame = roundedIntRect(frame); 307 IntRect newFrame = roundedIntRect(frame);
308 308
309 if (widget->frameRect() == newFrame) 309 if (widget->frameRect() == newFrame)
310 return false; 310 return false;
311 311
312 RefPtrWillBeRawPtr<RenderPart> protector(this); 312 RefPtrWillBeRawPtr<LayoutPart> protector(this);
313 RefPtrWillBeRawPtr<Node> protectedNode(node()); 313 RefPtrWillBeRawPtr<Node> protectedNode(node());
314 widget->setFrameRect(newFrame); 314 widget->setFrameRect(newFrame);
315 return widget->frameRect().size() != newFrame.size(); 315 return widget->frameRect().size() != newFrame.size();
316 } 316 }
317 317
318 } 318 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutPart.h ('k') | Source/core/layout/LayoutPartTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698