OLD | NEW |
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 |
(...skipping 10 matching lines...) Expand all Loading... |
21 * Boston, MA 02110-1301, USA. | 21 * Boston, MA 02110-1301, USA. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 #include "core/layout/LayoutPart.h" | 25 #include "core/layout/LayoutPart.h" |
26 | 26 |
27 #include "core/dom/AXObjectCache.h" | 27 #include "core/dom/AXObjectCache.h" |
28 #include "core/frame/FrameView.h" | 28 #include "core/frame/FrameView.h" |
29 #include "core/frame/LocalFrame.h" | 29 #include "core/frame/LocalFrame.h" |
30 #include "core/html/HTMLFrameElementBase.h" | 30 #include "core/html/HTMLFrameElementBase.h" |
| 31 #include "core/html/HTMLPlugInElement.h" |
31 #include "core/layout/HitTestResult.h" | 32 #include "core/layout/HitTestResult.h" |
32 #include "core/layout/LayoutAnalyzer.h" | 33 #include "core/layout/LayoutAnalyzer.h" |
33 #include "core/layout/LayoutView.h" | 34 #include "core/layout/LayoutView.h" |
34 #include "core/layout/api/LayoutAPIShim.h" | 35 #include "core/layout/api/LayoutAPIShim.h" |
35 #include "core/layout/api/LayoutViewItem.h" | 36 #include "core/layout/api/LayoutViewItem.h" |
36 #include "core/paint/PartPainter.h" | 37 #include "core/paint/PartPainter.h" |
37 #include "core/plugins/PluginView.h" | 38 #include "core/plugins/PluginView.h" |
38 | 39 |
39 namespace blink { | 40 namespace blink { |
40 | 41 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 FrameViewBase* LayoutPart::frameViewBase() const { | 92 FrameViewBase* LayoutPart::frameViewBase() const { |
92 // Plugin FrameViewBases are stored in their DOM node. | 93 // Plugin FrameViewBases are stored in their DOM node. |
93 Element* element = toElement(node()); | 94 Element* element = toElement(node()); |
94 | 95 |
95 if (element && element->isFrameOwnerElement()) | 96 if (element && element->isFrameOwnerElement()) |
96 return toHTMLFrameOwnerElement(element)->ownedWidget(); | 97 return toHTMLFrameOwnerElement(element)->ownedWidget(); |
97 | 98 |
98 return nullptr; | 99 return nullptr; |
99 } | 100 } |
100 | 101 |
| 102 PluginView* LayoutPart::plugin() const { |
| 103 // Plugins are stored in their DOM node. |
| 104 return node() && isHTMLPlugInElement(node()) |
| 105 ? toHTMLPlugInElement(node())->plugin() |
| 106 : nullptr; |
| 107 } |
| 108 |
101 PaintLayerType LayoutPart::layerTypeRequired() const { | 109 PaintLayerType LayoutPart::layerTypeRequired() const { |
102 PaintLayerType type = LayoutReplaced::layerTypeRequired(); | 110 PaintLayerType type = LayoutReplaced::layerTypeRequired(); |
103 if (type != NoPaintLayer) | 111 if (type != NoPaintLayer) |
104 return type; | 112 return type; |
105 return ForcedPaintLayer; | 113 return ForcedPaintLayer; |
106 } | 114 } |
107 | 115 |
108 bool LayoutPart::requiresAcceleratedCompositing() const { | 116 bool LayoutPart::requiresAcceleratedCompositing() const { |
109 // There are two general cases in which we can return true. First, if this is | 117 // There are two general cases in which we can return true. First, if this is |
110 // a plugin LayoutObject and the plugin has a layer, then we need a layer. | 118 // a plugin LayoutObject and the plugin has a layer, then we need a layer. |
111 // Second, if this is a LayoutObject with a contentDocument and that document | 119 // Second, if this is a LayoutObject with a contentDocument and that document |
112 // needs a layer, then we need a layer. | 120 // needs a layer, then we need a layer. |
113 if (frameViewBase() && frameViewBase()->isPluginView() && | 121 PluginView* pluginView = plugin(); |
114 toPluginView(frameViewBase())->platformLayer()) | 122 if (pluginView && pluginView->platformLayer()) |
115 return true; | 123 return true; |
116 | 124 |
117 if (!node() || !node()->isFrameOwnerElement()) | 125 if (!node() || !node()->isFrameOwnerElement()) |
118 return false; | 126 return false; |
119 | 127 |
120 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); | 128 HTMLFrameOwnerElement* element = toHTMLFrameOwnerElement(node()); |
121 if (element->contentFrame() && element->contentFrame()->isRemoteFrame()) | 129 if (element->contentFrame() && element->contentFrame()->isRemoteFrame()) |
122 return true; | 130 return true; |
123 | 131 |
124 if (Document* contentDocument = element->contentDocument()) { | 132 if (Document* contentDocument = element->contentDocument()) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 LayoutReplaced::styleDidChange(diff, oldStyle); | 248 LayoutReplaced::styleDidChange(diff, oldStyle); |
241 FrameViewBase* frameViewBase = this->frameViewBase(); | 249 FrameViewBase* frameViewBase = this->frameViewBase(); |
242 | 250 |
243 if (!frameViewBase) | 251 if (!frameViewBase) |
244 return; | 252 return; |
245 | 253 |
246 // If the iframe has custom scrollbars, recalculate their style. | 254 // If the iframe has custom scrollbars, recalculate their style. |
247 if (frameViewBase && frameViewBase->isFrameView()) | 255 if (frameViewBase && frameViewBase->isFrameView()) |
248 toFrameView(frameViewBase)->recalculateCustomScrollbarStyle(); | 256 toFrameView(frameViewBase)->recalculateCustomScrollbarStyle(); |
249 | 257 |
| 258 // TODO(joelhockey): Does this need separate code for plugins? |
250 if (style()->visibility() != EVisibility::kVisible) { | 259 if (style()->visibility() != EVisibility::kVisible) { |
251 frameViewBase->hide(); | 260 frameViewBase->hide(); |
252 } else { | 261 } else { |
253 frameViewBase->show(); | 262 frameViewBase->show(); |
254 } | 263 } |
255 } | 264 } |
256 | 265 |
257 void LayoutPart::layout() { | 266 void LayoutPart::layout() { |
258 ASSERT(needsLayout()); | 267 ASSERT(needsLayout()); |
259 LayoutAnalyzer::Scope analyzer(*this); | 268 LayoutAnalyzer::Scope analyzer(*this); |
260 clearNeedsLayout(); | 269 clearNeedsLayout(); |
261 } | 270 } |
262 | 271 |
263 void LayoutPart::paint(const PaintInfo& paintInfo, | 272 void LayoutPart::paint(const PaintInfo& paintInfo, |
264 const LayoutPoint& paintOffset) const { | 273 const LayoutPoint& paintOffset) const { |
265 PartPainter(*this).paint(paintInfo, paintOffset); | 274 PartPainter(*this).paint(paintInfo, paintOffset); |
266 } | 275 } |
267 | 276 |
268 void LayoutPart::paintContents(const PaintInfo& paintInfo, | 277 void LayoutPart::paintContents(const PaintInfo& paintInfo, |
269 const LayoutPoint& paintOffset) const { | 278 const LayoutPoint& paintOffset) const { |
270 PartPainter(*this).paintContents(paintInfo, paintOffset); | 279 PartPainter(*this).paintContents(paintInfo, paintOffset); |
271 } | 280 } |
272 | 281 |
273 CursorDirective LayoutPart::getCursor(const LayoutPoint& point, | 282 CursorDirective LayoutPart::getCursor(const LayoutPoint& point, |
274 Cursor& cursor) const { | 283 Cursor& cursor) const { |
275 if (frameViewBase() && frameViewBase()->isPluginView()) { | 284 if (plugin()) { |
276 // A plugin is responsible for setting the cursor when the pointer is over | 285 // A plugin is responsible for setting the cursor when the pointer is over |
277 // it. | 286 // it. |
278 return DoNotSetCursor; | 287 return DoNotSetCursor; |
279 } | 288 } |
280 return LayoutReplaced::getCursor(point, cursor); | 289 return LayoutReplaced::getCursor(point, cursor); |
281 } | 290 } |
282 | 291 |
283 LayoutRect LayoutPart::replacedContentRect() const { | 292 LayoutRect LayoutPart::replacedContentRect() const { |
284 // We don't propagate sub-pixel into sub-frame layout, in other words, the | 293 // We don't propagate sub-pixel into sub-frame layout, in other words, the |
285 // rect is snapped at the document boundary, and sub-pixel movement could | 294 // rect is snapped at the document boundary, and sub-pixel movement could |
286 // cause the sub-frame to layout due to the 1px snap difference. In order to | 295 // cause the sub-frame to layout due to the 1px snap difference. In order to |
287 // avoid that, the size of sub-frame is rounded in advance. | 296 // avoid that, the size of sub-frame is rounded in advance. |
288 LayoutRect sizeRoundedRect = contentBoxRect(); | 297 LayoutRect sizeRoundedRect = contentBoxRect(); |
289 sizeRoundedRect.setSize(LayoutSize(roundedIntSize(sizeRoundedRect.size()))); | 298 sizeRoundedRect.setSize(LayoutSize(roundedIntSize(sizeRoundedRect.size()))); |
290 return sizeRoundedRect; | 299 return sizeRoundedRect; |
291 } | 300 } |
292 | 301 |
293 void LayoutPart::updateOnWidgetChange() { | 302 void LayoutPart::updateOnWidgetChange() { |
294 FrameViewBase* frameViewBase = this->frameViewBase(); | 303 // Check if this is a plugin or frame. |
| 304 // TODO(joelhockey): When plugin no longer inherits from FrameViewBase, make |
| 305 // separate versions of this function for plugins and frames. |
| 306 FrameViewBase* frameViewBase = this->plugin(); |
| 307 if (!frameViewBase) |
| 308 frameViewBase = this->frameViewBase(); |
295 if (!frameViewBase) | 309 if (!frameViewBase) |
296 return; | 310 return; |
297 | 311 |
298 if (!style()) | 312 if (!style()) |
299 return; | 313 return; |
300 | 314 |
301 if (!needsLayout()) | 315 if (!needsLayout()) |
302 updateGeometryInternal(); | 316 updateGeometryInternal(*frameViewBase); |
303 | 317 |
| 318 // TODO(joelhockey): Does this need special handling for plugin? |
304 if (style()->visibility() != EVisibility::kVisible) { | 319 if (style()->visibility() != EVisibility::kVisible) { |
305 frameViewBase->hide(); | 320 frameViewBase->hide(); |
306 } else { | 321 } else { |
307 frameViewBase->show(); | 322 frameViewBase->show(); |
308 // FIXME: Why do we issue a full paint invalidation in this case, but not | 323 // FIXME: Why do we issue a full paint invalidation in this case, but not |
309 // the other? | 324 // the other? |
310 setShouldDoFullPaintInvalidation(); | 325 setShouldDoFullPaintInvalidation(); |
311 } | 326 } |
312 } | 327 } |
313 | 328 |
314 void LayoutPart::updateGeometry() { | 329 void LayoutPart::updateGeometry() { |
315 FrameViewBase* frameViewBase = this->frameViewBase(); | 330 // Check if this is a plugin or frame. |
| 331 // TODO(joelhockey): When plugin no longer inherits from FrameViewBase, make |
| 332 // separate versions of this function for plugins and frames. |
| 333 FrameViewBase* frameViewBase = this->plugin(); |
| 334 if (!frameViewBase) |
| 335 frameViewBase = this->frameViewBase(); |
316 if (!frameViewBase || | 336 if (!frameViewBase || |
317 !node()) // Check the node in case destroy() has been called. | 337 !node()) // Check the node in case destroy() has been called. |
318 return; | 338 return; |
319 | 339 |
320 LayoutRect newFrame = replacedContentRect(); | 340 LayoutRect newFrame = replacedContentRect(); |
321 DCHECK(newFrame.size() == roundedIntSize(newFrame.size())); | 341 DCHECK(newFrame.size() == roundedIntSize(newFrame.size())); |
| 342 // TODO(joelhockey): Does this need special handling for plugin? |
322 bool boundsWillChange = | 343 bool boundsWillChange = |
323 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size(); | 344 LayoutSize(frameViewBase->frameRect().size()) != newFrame.size(); |
324 | 345 |
325 FrameView* frameView = | 346 FrameView* frameView = |
326 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr; | 347 frameViewBase->isFrameView() ? toFrameView(frameViewBase) : nullptr; |
327 | 348 |
328 // If frame bounds are changing mark the view for layout. Also check the | 349 // If frame bounds are changing mark the view for layout. Also check the |
329 // frame's page to make sure that the frame isn't in the process of being | 350 // frame's page to make sure that the frame isn't in the process of being |
330 // destroyed. If iframe scrollbars needs reconstruction from native to custom | 351 // destroyed. If iframe scrollbars needs reconstruction from native to custom |
331 // scrollbar, then also we need to layout the frameview. | 352 // scrollbar, then also we need to layout the frameview. |
332 if (frameView && frameView->frame().page() && | 353 if (frameView && frameView->frame().page() && |
333 (boundsWillChange || frameView->needsScrollbarReconstruction())) | 354 (boundsWillChange || frameView->needsScrollbarReconstruction())) |
334 frameView->setNeedsLayout(); | 355 frameView->setNeedsLayout(); |
335 | 356 |
336 updateGeometryInternal(); | 357 updateGeometryInternal(*frameViewBase); |
337 | 358 |
338 // If view needs layout, either because bounds have changed or possibly | 359 // If view needs layout, either because bounds have changed or possibly |
339 // indicating content size is wrong, we have to do a layout to set the right | 360 // indicating content size is wrong, we have to do a layout to set the right |
340 // FrameViewBase size. | 361 // FrameViewBase size. |
341 if (frameView && frameView->needsLayout() && frameView->frame().page()) | 362 if (frameView && frameView->needsLayout() && frameView->frame().page()) |
342 frameView->layout(); | 363 frameView->layout(); |
343 | 364 |
344 frameViewBase->geometryMayHaveChanged(); | 365 frameViewBase->geometryMayHaveChanged(); |
345 } | 366 } |
346 | 367 |
347 void LayoutPart::updateGeometryInternal() { | 368 void LayoutPart::updateGeometryInternal(FrameViewBase& frameViewBase) { |
348 FrameViewBase* frameViewBase = this->frameViewBase(); | |
349 DCHECK(frameViewBase); | |
350 | |
351 // Ignore transform here, as we only care about the sub-pixel accumulation. | 369 // Ignore transform here, as we only care about the sub-pixel accumulation. |
352 // TODO(trchen): What about multicol? Need a LayoutBox function to query | 370 // TODO(trchen): What about multicol? Need a LayoutBox function to query |
353 // sub-pixel accumulation. | 371 // sub-pixel accumulation. |
354 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint())); | 372 LayoutPoint absoluteLocation(localToAbsolute(FloatPoint())); |
355 LayoutRect absoluteReplacedRect = replacedContentRect(); | 373 LayoutRect absoluteReplacedRect = replacedContentRect(); |
356 absoluteReplacedRect.moveBy(absoluteLocation); | 374 absoluteReplacedRect.moveBy(absoluteLocation); |
357 | 375 |
358 IntRect frameRect(IntPoint(), | 376 IntRect frameRect(IntPoint(), |
359 pixelSnappedIntRect(absoluteReplacedRect).size()); | 377 pixelSnappedIntRect(absoluteReplacedRect).size()); |
360 // Normally the location of the frame rect is ignored by the painter, but | 378 // Normally the location of the frame rect is ignored by the painter, but |
361 // currently it is still used by a family of coordinate conversion function in | 379 // currently it is still used by a family of coordinate conversion function in |
362 // FrameViewBase/FrameView. This is incorrect because coordinate conversion | 380 // FrameViewBase/FrameView. This is incorrect because coordinate conversion |
363 // needs to take transform and into account. A few callers still use the | 381 // needs to take transform and into account. A few callers still use the |
364 // family of conversion function, including but not exhaustive: | 382 // family of conversion function, including but not exhaustive: |
365 // FrameView::updateViewportIntersectionIfNeeded() | 383 // FrameView::updateViewportIntersectionIfNeeded() |
366 // RemoteFrameView::frameRectsChanged(). | 384 // RemoteFrameView::frameRectsChanged(). |
367 // WebPluginContainerImpl::reportGeometry() | 385 // WebPluginContainerImpl::reportGeometry() |
368 // TODO(trchen): Remove this hack once we fixed all callers. | 386 // TODO(trchen): Remove this hack once we fixed all callers. |
369 FloatRect absoluteBoundingBox = | 387 FloatRect absoluteBoundingBox = |
370 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox(); | 388 localToAbsoluteQuad(FloatRect(replacedContentRect())).boundingBox(); |
371 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location())); | 389 frameRect.setLocation(roundedIntPoint(absoluteBoundingBox.location())); |
372 | 390 |
373 // Why is the protector needed? | 391 // Why is the protector needed? |
374 RefPtr<LayoutPart> protector(this); | 392 RefPtr<LayoutPart> protector(this); |
375 frameViewBase->setFrameRect(frameRect); | 393 // TODO(joelhockey): Does this need special handling for plugin? |
| 394 frameViewBase.setFrameRect(frameRect); |
376 } | 395 } |
377 | 396 |
378 void LayoutPart::invalidatePaintOfSubtreesIfNeeded( | 397 void LayoutPart::invalidatePaintOfSubtreesIfNeeded( |
379 const PaintInvalidationState& paintInvalidationState) { | 398 const PaintInvalidationState& paintInvalidationState) { |
380 if (frameViewBase() && frameViewBase()->isFrameView() && | 399 if (frameViewBase() && frameViewBase()->isFrameView() && |
381 !isThrottledFrameView()) { | 400 !isThrottledFrameView()) { |
382 FrameView* childFrameView = toFrameView(frameViewBase()); | 401 FrameView* childFrameView = toFrameView(frameViewBase()); |
383 // |childFrameView| is in another document, which could be | 402 // |childFrameView| is in another document, which could be |
384 // missing its LayoutView. TODO(jchaffraix): Ideally we should | 403 // missing its LayoutView. TODO(jchaffraix): Ideally we should |
385 // not need this code. | 404 // not need this code. |
(...skipping 10 matching lines...) Expand all Loading... |
396 } | 415 } |
397 | 416 |
398 bool LayoutPart::isThrottledFrameView() const { | 417 bool LayoutPart::isThrottledFrameView() const { |
399 if (!frameViewBase() || !frameViewBase()->isFrameView()) | 418 if (!frameViewBase() || !frameViewBase()->isFrameView()) |
400 return false; | 419 return false; |
401 const FrameView* frameView = toFrameView(frameViewBase()); | 420 const FrameView* frameView = toFrameView(frameViewBase()); |
402 return frameView->shouldThrottleRendering(); | 421 return frameView->shouldThrottleRendering(); |
403 } | 422 } |
404 | 423 |
405 } // namespace blink | 424 } // namespace blink |
OLD | NEW |