OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) | 3 * Copyright (C) 2000 Dirk Mueller (mueller@kde.org) |
4 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. | 4 * Copyright (C) 2004, 2006, 2009, 2010 Apple Inc. All rights reserved. |
5 * Copyright (C) 2013 Google Inc. All rights reserved. | 5 * Copyright (C) 2013 Google Inc. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
11 * | 11 * |
12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
16 * | 16 * |
17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
21 * | 21 * |
22 */ | 22 */ |
23 | 23 |
24 #include "config.h" | 24 #include "config.h" |
25 #include "core/rendering/RenderWidget.h" | 25 #include "core/rendering/RenderWidget.h" |
26 | 26 |
27 #include "core/accessibility/AXObjectCache.h" | 27 #include "core/accessibility/AXObjectCache.h" |
28 #include "core/frame/Frame.h" | 28 #include "core/frame/Frame.h" |
29 #include "core/html/HTMLPlugInElement.h" | |
29 #include "core/platform/graphics/GraphicsContext.h" | 30 #include "core/platform/graphics/GraphicsContext.h" |
30 #include "core/rendering/CompositedLayerMapping.h" | 31 #include "core/rendering/CompositedLayerMapping.h" |
31 #include "core/rendering/GraphicsContextAnnotator.h" | 32 #include "core/rendering/GraphicsContextAnnotator.h" |
32 #include "core/rendering/HitTestResult.h" | 33 #include "core/rendering/HitTestResult.h" |
33 #include "core/rendering/LayoutRectRecorder.h" | 34 #include "core/rendering/LayoutRectRecorder.h" |
34 #include "core/rendering/RenderLayer.h" | 35 #include "core/rendering/RenderLayer.h" |
35 #include "core/rendering/RenderView.h" | 36 #include "core/rendering/RenderView.h" |
36 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
37 | 38 |
38 using namespace std; | 39 using namespace std; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 clearNode(); | 121 clearNode(); |
121 deref(); | 122 deref(); |
122 } | 123 } |
123 | 124 |
124 RenderWidget::~RenderWidget() | 125 RenderWidget::~RenderWidget() |
125 { | 126 { |
126 ASSERT(m_refCount <= 0); | 127 ASSERT(m_refCount <= 0); |
127 clearWidget(); | 128 clearWidget(); |
128 } | 129 } |
129 | 130 |
131 Widget* RenderWidget::widget() const | |
132 { | |
133 if (m_widget.get()) | |
eseidel
2013/11/18 22:09:54
Can we just remove RenderWidget's m_widget pointer
wjmaclean
2013/11/25 17:51:56
I've taken a stab at this .. please take a look an
| |
134 return m_widget.get(); | |
135 | |
136 // Plugin widgets are now stored in their DOM node, so check there next. | |
137 Element* element = toElement(node()); | |
138 if (element && element->isPluginElement()) | |
139 return toHTMLPlugInElement(element)->plugin().get(); | |
140 | |
141 return 0; | |
142 } | |
143 | |
130 // Widgets are always placed on integer boundaries, so rounding the size is actu ally | 144 // Widgets are always placed on integer boundaries, so rounding the size is actu ally |
131 // the desired behavior. This function is here because it's otherwise seldom wha t we | 145 // the desired behavior. This function is here because it's otherwise seldom wha t we |
132 // want to do with a LayoutRect. | 146 // want to do with a LayoutRect. |
133 static inline IntRect roundedIntRect(const LayoutRect& rect) | 147 static inline IntRect roundedIntRect(const LayoutRect& rect) |
134 { | 148 { |
135 return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()) ); | 149 return IntRect(roundedIntPoint(rect.location()), roundedIntSize(rect.size()) ); |
136 } | 150 } |
137 | 151 |
138 bool RenderWidget::setWidgetGeometry(const LayoutRect& frame) | 152 bool RenderWidget::setWidgetGeometry(const LayoutRect& frame) |
139 { | 153 { |
140 if (!node()) | 154 if (!node()) |
141 return false; | 155 return false; |
142 | 156 |
157 Widget* widget = this->widget(); | |
158 ASSERT(widget); | |
159 | |
143 IntRect clipRect = roundedIntRect(enclosingLayer()->childrenClipRect()); | 160 IntRect clipRect = roundedIntRect(enclosingLayer()->childrenClipRect()); |
144 IntRect newFrame = roundedIntRect(frame); | 161 IntRect newFrame = roundedIntRect(frame); |
145 bool clipChanged = m_clipRect != clipRect; | 162 bool clipChanged = m_clipRect != clipRect; |
146 bool frameRectChanged = m_widget->frameRect() != newFrame; | 163 bool frameRectChanged = widget->frameRect() != newFrame; |
147 | 164 |
148 if (!frameRectChanged && !clipChanged) | 165 if (!frameRectChanged && !clipChanged) |
149 return false; | 166 return false; |
150 | 167 |
151 m_clipRect = clipRect; | 168 m_clipRect = clipRect; |
152 | 169 |
153 RefPtr<RenderWidget> protector(this); | 170 RefPtr<RenderWidget> protector(this); |
154 RefPtr<Node> protectedNode(node()); | 171 RefPtr<Node> protectedNode(node()); |
155 m_widget->setFrameRect(newFrame); | 172 widget->setFrameRect(newFrame); |
156 | 173 |
157 if (clipChanged && !frameRectChanged) | 174 if (clipChanged && !frameRectChanged) |
158 m_widget->clipRectChanged(); | 175 widget->clipRectChanged(); |
159 | 176 |
160 if (hasLayer() && layer()->compositingState() == PaintsIntoOwnBacking) | 177 if (hasLayer() && layer()->compositingState() == PaintsIntoOwnBacking) |
161 layer()->compositedLayerMapping()->updateAfterWidgetResize(); | 178 layer()->compositedLayerMapping()->updateAfterWidgetResize(); |
162 | 179 |
163 bool boundsChanged = m_widget->frameRect().size() != newFrame.size(); | 180 bool boundsChanged = widget->frameRect().size() != newFrame.size(); |
164 return boundsChanged; | 181 return boundsChanged; |
165 } | 182 } |
166 | 183 |
167 bool RenderWidget::updateWidgetGeometry() | 184 bool RenderWidget::updateWidgetGeometry() |
168 { | 185 { |
186 Widget* widget = this->widget(); | |
187 | |
169 LayoutRect contentBox = contentBoxRect(); | 188 LayoutRect contentBox = contentBoxRect(); |
170 LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).bou ndingBox()); | 189 LayoutRect absoluteContentBox(localToAbsoluteQuad(FloatQuad(contentBox)).bou ndingBox()); |
171 if (m_widget->isFrameView()) { | 190 if (widget->isFrameView()) { |
172 contentBox.setLocation(absoluteContentBox.location()); | 191 contentBox.setLocation(absoluteContentBox.location()); |
173 return setWidgetGeometry(contentBox); | 192 return setWidgetGeometry(contentBox); |
174 } | 193 } |
175 | 194 |
176 return setWidgetGeometry(absoluteContentBox); | 195 return setWidgetGeometry(absoluteContentBox); |
177 } | 196 } |
178 | 197 |
198 // FIXME: Once Frame/FrameElementBase/FrameOwnerElement and HTMLAppletElement | |
eseidel
2013/11/18 22:26:45
I see. The problem is there are multiple DOM clas
wjmaclean
2013/11/25 17:51:56
As per comment regarding removing widget pointer.
| |
199 // can be updated to own their own widgets, this function can be retired in | |
200 // favour of configureWidget(). | |
179 void RenderWidget::setWidget(PassRefPtr<Widget> widget) | 201 void RenderWidget::setWidget(PassRefPtr<Widget> widget) |
180 { | 202 { |
181 if (widget == m_widget) | 203 if (widget == m_widget) |
182 return; | 204 return; |
183 | 205 |
184 if (m_widget) { | 206 if (m_widget) { |
185 moveWidgetToParentSoon(m_widget.get(), 0); | 207 moveWidgetToParentSoon(m_widget.get(), 0); |
186 clearWidget(); | 208 clearWidget(); |
187 } | 209 } |
188 m_widget = widget; | 210 m_widget = widget; |
(...skipping 12 matching lines...) Expand all Loading... | |
201 repaint(); | 223 repaint(); |
202 } | 224 } |
203 } | 225 } |
204 moveWidgetToParentSoon(m_widget.get(), m_frameView); | 226 moveWidgetToParentSoon(m_widget.get(), m_frameView); |
205 } | 227 } |
206 | 228 |
207 if (AXObjectCache* cache = document().existingAXObjectCache()) | 229 if (AXObjectCache* cache = document().existingAXObjectCache()) |
208 cache->childrenChanged(this); | 230 cache->childrenChanged(this); |
209 } | 231 } |
210 | 232 |
233 void RenderWidget::configureWidget(ConfigureType type) | |
234 { | |
235 Widget* widget = this->widget(); | |
236 ASSERT(widget); | |
237 | |
238 if (type == ConfigureOnDetach) { | |
239 moveWidgetToParentSoon(widget, 0); | |
240 return; | |
241 } | |
242 | |
243 // type == ConfigureOnAttach. | |
eseidel
2013/11/18 22:26:45
confused. Which one of these is the old path vs.
wjmaclean
2013/11/25 17:51:56
It's not so much an old vs. new distinction as att
| |
244 if (widget) { | |
245 if (style()) { | |
246 if (!needsLayout()) | |
247 updateWidgetGeometry(); | |
248 | |
249 if (style()->visibility() != VISIBLE) { | |
250 widget->hide(); | |
251 } else { | |
252 widget->show(); | |
253 repaint(); | |
254 } | |
255 if (!widget->parent()) | |
256 moveWidgetToParentSoon(widget, m_frameView); | |
257 } | |
258 if (AXObjectCache* cache = document().existingAXObjectCache()) | |
259 cache->childrenChanged(this); | |
260 } | |
261 } | |
262 | |
211 void RenderWidget::layout() | 263 void RenderWidget::layout() |
212 { | 264 { |
213 ASSERT(needsLayout()); | 265 ASSERT(needsLayout()); |
214 | 266 |
215 LayoutRectRecorder recorder(*this); | 267 LayoutRectRecorder recorder(*this); |
216 clearNeedsLayout(); | 268 clearNeedsLayout(); |
217 } | 269 } |
218 | 270 |
219 void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldSt yle) | 271 void RenderWidget::styleDidChange(StyleDifference diff, const RenderStyle* oldSt yle) |
220 { | 272 { |
221 RenderReplaced::styleDidChange(diff, oldStyle); | 273 RenderReplaced::styleDidChange(diff, oldStyle); |
222 if (m_widget) { | 274 Widget* widget = this->widget(); |
275 | |
276 if (widget) { | |
223 if (style()->visibility() != VISIBLE) | 277 if (style()->visibility() != VISIBLE) |
224 m_widget->hide(); | 278 widget->hide(); |
225 else | 279 else |
226 m_widget->show(); | 280 widget->show(); |
227 } | 281 } |
228 } | 282 } |
229 | 283 |
230 void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO ffset) | 284 void RenderWidget::paintContents(PaintInfo& paintInfo, const LayoutPoint& paintO ffset) |
231 { | 285 { |
232 LayoutPoint adjustedPaintOffset = paintOffset + location(); | 286 LayoutPoint adjustedPaintOffset = paintOffset + location(); |
233 | 287 |
288 Widget* widget = this->widget(); | |
289 ASSERT(widget); | |
290 | |
234 // Tell the widget to paint now. This is the only time the widget is allowed | 291 // Tell the widget to paint now. This is the only time the widget is allowed |
235 // to paint itself. That way it will composite properly with z-indexed layer s. | 292 // to paint itself. That way it will composite properly with z-indexed layer s. |
236 IntPoint widgetLocation = m_widget->frameRect().location(); | 293 IntPoint widgetLocation = widget->frameRect().location(); |
237 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + p addingLeft()), | 294 IntPoint paintLocation(roundToInt(adjustedPaintOffset.x() + borderLeft() + p addingLeft()), |
238 roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop())); | 295 roundToInt(adjustedPaintOffset.y() + borderTop() + paddingTop())); |
239 IntRect paintRect = paintInfo.rect; | 296 IntRect paintRect = paintInfo.rect; |
240 | 297 |
241 IntSize widgetPaintOffset = paintLocation - widgetLocation; | 298 IntSize widgetPaintOffset = paintLocation - widgetLocation; |
242 // When painting widgets into compositing layers, tx and ty are relative to the enclosing compositing layer, | 299 // When painting widgets into compositing layers, tx and ty are relative to the enclosing compositing layer, |
243 // not the root. In this case, shift the CTM and adjust the paintRect to be root-relative to fix plug-in drawing. | 300 // not the root. In this case, shift the CTM and adjust the paintRect to be root-relative to fix plug-in drawing. |
244 if (!widgetPaintOffset.isZero()) { | 301 if (!widgetPaintOffset.isZero()) { |
245 paintInfo.context->translate(widgetPaintOffset); | 302 paintInfo.context->translate(widgetPaintOffset); |
246 paintRect.move(-widgetPaintOffset); | 303 paintRect.move(-widgetPaintOffset); |
247 } | 304 } |
248 m_widget->paint(paintInfo.context, paintRect); | 305 widget->paint(paintInfo.context, paintRect); |
249 | 306 |
250 if (!widgetPaintOffset.isZero()) | 307 if (!widgetPaintOffset.isZero()) |
251 paintInfo.context->translate(-widgetPaintOffset); | 308 paintInfo.context->translate(-widgetPaintOffset); |
252 | 309 |
253 if (m_widget->isFrameView()) { | 310 if (widget->isFrameView()) { |
254 FrameView* frameView = toFrameView(m_widget.get()); | 311 FrameView* frameView = toFrameView(widget); |
255 bool runOverlapTests = !frameView->useSlowRepaintsIfNotOverlapped() || f rameView->hasCompositedContent(); | 312 bool runOverlapTests = !frameView->useSlowRepaintsIfNotOverlapped() || f rameView->hasCompositedContent(); |
256 if (paintInfo.overlapTestRequests && runOverlapTests) { | 313 if (paintInfo.overlapTestRequests && runOverlapTests) { |
257 ASSERT(!paintInfo.overlapTestRequests->contains(this)); | 314 ASSERT(!paintInfo.overlapTestRequests->contains(this)); |
258 paintInfo.overlapTestRequests->set(this, m_widget->frameRect()); | 315 paintInfo.overlapTestRequests->set(this, widget->frameRect()); |
259 } | 316 } |
260 } | 317 } |
261 } | 318 } |
262 | 319 |
263 void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) | 320 void RenderWidget::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset) |
264 { | 321 { |
265 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this); | 322 ANNOTATE_GRAPHICS_CONTEXT(paintInfo, this); |
266 | 323 |
267 if (!shouldPaint(paintInfo, paintOffset)) | 324 if (!shouldPaint(paintInfo, paintOffset)) |
268 return; | 325 return; |
(...skipping 20 matching lines...) Expand all Loading... | |
289 if (borderRect.isEmpty()) | 346 if (borderRect.isEmpty()) |
290 return; | 347 return; |
291 | 348 |
292 // Push a clip if we have a border radius, since we want to round the fo reground content that gets painted. | 349 // Push a clip if we have a border radius, since we want to round the fo reground content that gets painted. |
293 paintInfo.context->save(); | 350 paintInfo.context->save(); |
294 RoundedRect roundedInnerRect = style()->getRoundedInnerBorderFor(borderR ect, | 351 RoundedRect roundedInnerRect = style()->getRoundedInnerBorderFor(borderR ect, |
295 paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddin gLeft() + borderLeft(), paddingRight() + borderRight(), true, true); | 352 paddingTop() + borderTop(), paddingBottom() + borderBottom(), paddin gLeft() + borderLeft(), paddingRight() + borderRight(), true, true); |
296 clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect); | 353 clipRoundedInnerRect(paintInfo.context, borderRect, roundedInnerRect); |
297 } | 354 } |
298 | 355 |
299 if (m_widget) | 356 Widget* widget = this->widget(); |
357 if (widget) | |
300 paintContents(paintInfo, paintOffset); | 358 paintContents(paintInfo, paintOffset); |
301 | 359 |
302 if (style()->hasBorderRadius()) | 360 if (style()->hasBorderRadius()) |
303 paintInfo.context->restore(); | 361 paintInfo.context->restore(); |
304 | 362 |
305 // Paint a partially transparent wash over selected widgets. | 363 // Paint a partially transparent wash over selected widgets. |
306 if (isSelected() && !document().printing()) { | 364 if (isSelected() && !document().printing()) { |
307 // FIXME: selectionRect() is in absolute, not painting coordinates. | 365 // FIXME: selectionRect() is in absolute, not painting coordinates. |
308 paintInfo.context->fillRect(pixelSnappedIntRect(selectionRect()), select ionBackgroundColor()); | 366 paintInfo.context->fillRect(pixelSnappedIntRect(selectionRect()), select ionBackgroundColor()); |
309 } | 367 } |
310 | 368 |
311 if (canResize()) | 369 if (canResize()) |
312 layer()->scrollableArea()->paintResizer(paintInfo.context, roundedIntPoi nt(adjustedPaintOffset), paintInfo.rect); | 370 layer()->scrollableArea()->paintResizer(paintInfo.context, roundedIntPoi nt(adjustedPaintOffset), paintInfo.rect); |
313 } | 371 } |
314 | 372 |
315 void RenderWidget::setIsOverlapped(bool isOverlapped) | 373 void RenderWidget::setIsOverlapped(bool isOverlapped) |
316 { | 374 { |
317 ASSERT(m_widget); | 375 Widget* widget = this->widget(); |
318 ASSERT(m_widget->isFrameView()); | 376 ASSERT(widget); |
319 toFrameView(m_widget.get())->setIsOverlapped(isOverlapped); | 377 ASSERT(widget->isFrameView()); |
378 toFrameView(widget)->setIsOverlapped(isOverlapped); | |
320 } | 379 } |
321 | 380 |
322 void RenderWidget::deref() | 381 void RenderWidget::deref() |
323 { | 382 { |
324 if (--m_refCount <= 0) | 383 if (--m_refCount <= 0) |
325 postDestroy(); | 384 postDestroy(); |
326 } | 385 } |
327 | 386 |
328 void RenderWidget::updateWidgetPosition() | 387 void RenderWidget::updateWidgetPosition() |
329 { | 388 { |
330 if (!m_widget || !node()) // Check the node in case destroy() has been calle d. | 389 Widget* widget = this->widget(); |
390 if (!widget || !node()) // Check the node in case destroy() has been called. | |
331 return; | 391 return; |
332 | 392 |
333 bool boundsChanged = updateWidgetGeometry(); | 393 bool boundsChanged = updateWidgetGeometry(); |
334 | 394 |
335 // if the frame bounds got changed, or if view needs layout (possibly indica ting | 395 // if the frame bounds got changed, or if view needs layout (possibly indica ting |
336 // content size is wrong) we have to do a layout to set the right widget siz e | 396 // content size is wrong) we have to do a layout to set the right widget siz e |
337 if (m_widget && m_widget->isFrameView()) { | 397 if (widget && widget->isFrameView()) { |
338 FrameView* frameView = toFrameView(m_widget.get()); | 398 FrameView* frameView = toFrameView(widget); |
339 // Check the frame's page to make sure that the frame isn't in the proce ss of being destroyed. | 399 // Check the frame's page to make sure that the frame isn't in the proce ss of being destroyed. |
340 if ((boundsChanged || frameView->needsLayout()) && frameView->frame().pa ge()) | 400 if ((boundsChanged || frameView->needsLayout()) && frameView->frame().pa ge()) |
341 frameView->layout(); | 401 frameView->layout(); |
342 } | 402 } |
343 } | 403 } |
344 | 404 |
345 void RenderWidget::widgetPositionsUpdated() | 405 void RenderWidget::widgetPositionsUpdated() |
346 { | 406 { |
347 if (!m_widget) | 407 Widget* widget = this->widget(); |
408 if (!widget) | |
348 return; | 409 return; |
349 m_widget->widgetPositionsUpdated(); | 410 widget->widgetPositionsUpdated(); |
350 } | 411 } |
351 | 412 |
352 IntRect RenderWidget::windowClipRect() const | 413 IntRect RenderWidget::windowClipRect() const |
353 { | 414 { |
354 if (!m_frameView) | 415 if (!m_frameView) |
355 return IntRect(); | 416 return IntRect(); |
356 | 417 |
357 return intersection(m_frameView->contentsToWindow(m_clipRect), m_frameView-> windowClipRect()); | 418 return intersection(m_frameView->contentsToWindow(m_clipRect), m_frameView-> windowClipRect()); |
358 } | 419 } |
359 | 420 |
(...skipping 16 matching lines...) Expand all Loading... | |
376 CursorDirective RenderWidget::getCursor(const LayoutPoint& point, Cursor& cursor ) const | 437 CursorDirective RenderWidget::getCursor(const LayoutPoint& point, Cursor& cursor ) const |
377 { | 438 { |
378 if (widget() && widget()->isPluginView()) { | 439 if (widget() && widget()->isPluginView()) { |
379 // A plug-in is responsible for setting the cursor when the pointer is o ver it. | 440 // A plug-in is responsible for setting the cursor when the pointer is o ver it. |
380 return DoNotSetCursor; | 441 return DoNotSetCursor; |
381 } | 442 } |
382 return RenderReplaced::getCursor(point, cursor); | 443 return RenderReplaced::getCursor(point, cursor); |
383 } | 444 } |
384 | 445 |
385 } // namespace WebCore | 446 } // namespace WebCore |
OLD | NEW |