RenderLayer.h 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  1. /*
  2. * Copyright (C) 2003, 2009, 2012 Apple Inc. All rights reserved.
  3. *
  4. * Portions are Copyright (C) 1998 Netscape Communications Corporation.
  5. *
  6. * Other contributors:
  7. * Robert O'Callahan <roc+@cs.cmu.edu>
  8. * David Baron <dbaron@fas.harvard.edu>
  9. * Christian Biesinger <cbiesinger@web.de>
  10. * Randall Jesup <rjesup@wgate.com>
  11. * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
  12. * Josh Soref <timeless@mac.com>
  13. * Boris Zbarsky <bzbarsky@mit.edu>
  14. *
  15. * This library is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU Lesser General Public
  17. * License as published by the Free Software Foundation; either
  18. * version 2.1 of the License, or (at your option) any later version.
  19. *
  20. * This library is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * Lesser General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Lesser General Public
  26. * License along with this library; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. * Alternatively, the contents of this file may be used under the terms
  30. * of either the Mozilla Public License Version 1.1, found at
  31. * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
  32. * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
  33. * (the "GPL"), in which case the provisions of the MPL or the GPL are
  34. * applicable instead of those above. If you wish to allow use of your
  35. * version of this file only under the terms of one of those two
  36. * licenses (the MPL or the GPL) and not to allow others to use your
  37. * version of this file under the LGPL, indicate your decision by
  38. * deletingthe provisions above and replace them with the notice and
  39. * other provisions required by the MPL or the GPL, as the case may be.
  40. * If you do not delete the provisions above, a recipient may use your
  41. * version of this file under any of the LGPL, the MPL or the GPL.
  42. */
  43. #ifndef RenderLayer_h
  44. #define RenderLayer_h
  45. #include "PaintInfo.h"
  46. #include "RenderBox.h"
  47. #include "ScrollableArea.h"
  48. #include <wtf/OwnPtr.h>
  49. namespace WebCore {
  50. #if ENABLE(CSS_FILTERS)
  51. class FilterEffectRenderer;
  52. class FilterEffectRendererHelper;
  53. class FilterOperations;
  54. class RenderLayerFilterInfo;
  55. #endif
  56. class HitTestRequest;
  57. class HitTestResult;
  58. class HitTestingTransformState;
  59. class RenderFlowThread;
  60. class RenderGeometryMap;
  61. class RenderMarquee;
  62. class RenderReplica;
  63. class RenderScrollbarPart;
  64. class RenderStyle;
  65. class RenderView;
  66. class Scrollbar;
  67. class TransformationMatrix;
  68. #if USE(ACCELERATED_COMPOSITING)
  69. class RenderLayerBacking;
  70. class RenderLayerCompositor;
  71. #endif
  72. enum BorderRadiusClippingRule { IncludeSelfForBorderRadius, DoNotIncludeSelfForBorderRadius };
  73. enum IncludeSelfOrNot { IncludeSelf, ExcludeSelf };
  74. enum RepaintStatus {
  75. NeedsNormalRepaint,
  76. NeedsFullRepaint,
  77. NeedsFullRepaintForPositionedMovementLayout
  78. };
  79. class ClipRect {
  80. public:
  81. ClipRect()
  82. : m_hasRadius(false)
  83. { }
  84. ClipRect(const LayoutRect& rect)
  85. : m_rect(rect)
  86. , m_hasRadius(false)
  87. { }
  88. const LayoutRect& rect() const { return m_rect; }
  89. void setRect(const LayoutRect& rect) { m_rect = rect; }
  90. bool hasRadius() const { return m_hasRadius; }
  91. void setHasRadius(bool hasRadius) { m_hasRadius = hasRadius; }
  92. bool operator==(const ClipRect& other) const { return rect() == other.rect() && hasRadius() == other.hasRadius(); }
  93. bool operator!=(const ClipRect& other) const { return rect() != other.rect() || hasRadius() != other.hasRadius(); }
  94. bool operator!=(const LayoutRect& otherRect) const { return rect() != otherRect; }
  95. void intersect(const LayoutRect& other) { m_rect.intersect(other); }
  96. void intersect(const ClipRect& other)
  97. {
  98. m_rect.intersect(other.rect());
  99. if (other.hasRadius())
  100. m_hasRadius = true;
  101. }
  102. void move(LayoutUnit x, LayoutUnit y) { m_rect.move(x, y); }
  103. void move(const LayoutSize& size) { m_rect.move(size); }
  104. void moveBy(const LayoutPoint& point) { m_rect.moveBy(point); }
  105. bool isEmpty() const { return m_rect.isEmpty(); }
  106. bool intersects(const LayoutRect& rect) const { return m_rect.intersects(rect); }
  107. bool intersects(const HitTestLocation&) const;
  108. private:
  109. LayoutRect m_rect;
  110. bool m_hasRadius;
  111. };
  112. inline ClipRect intersection(const ClipRect& a, const ClipRect& b)
  113. {
  114. ClipRect c = a;
  115. c.intersect(b);
  116. return c;
  117. }
  118. class ClipRects {
  119. WTF_MAKE_FAST_ALLOCATED;
  120. public:
  121. static PassRefPtr<ClipRects> create()
  122. {
  123. return adoptRef(new ClipRects);
  124. }
  125. static PassRefPtr<ClipRects> create(const ClipRects& other)
  126. {
  127. return adoptRef(new ClipRects(other));
  128. }
  129. ClipRects()
  130. : m_refCnt(1)
  131. , m_fixed(false)
  132. {
  133. }
  134. void reset(const LayoutRect& r)
  135. {
  136. m_overflowClipRect = r;
  137. m_fixedClipRect = r;
  138. m_posClipRect = r;
  139. m_fixed = false;
  140. }
  141. const ClipRect& overflowClipRect() const { return m_overflowClipRect; }
  142. void setOverflowClipRect(const ClipRect& r) { m_overflowClipRect = r; }
  143. const ClipRect& fixedClipRect() const { return m_fixedClipRect; }
  144. void setFixedClipRect(const ClipRect&r) { m_fixedClipRect = r; }
  145. const ClipRect& posClipRect() const { return m_posClipRect; }
  146. void setPosClipRect(const ClipRect& r) { m_posClipRect = r; }
  147. bool fixed() const { return m_fixed; }
  148. void setFixed(bool fixed) { m_fixed = fixed; }
  149. void ref() { m_refCnt++; }
  150. void deref()
  151. {
  152. if (!--m_refCnt)
  153. delete this;
  154. }
  155. bool operator==(const ClipRects& other) const
  156. {
  157. return m_overflowClipRect == other.overflowClipRect() &&
  158. m_fixedClipRect == other.fixedClipRect() &&
  159. m_posClipRect == other.posClipRect() &&
  160. m_fixed == other.fixed();
  161. }
  162. ClipRects& operator=(const ClipRects& other)
  163. {
  164. m_overflowClipRect = other.overflowClipRect();
  165. m_fixedClipRect = other.fixedClipRect();
  166. m_posClipRect = other.posClipRect();
  167. m_fixed = other.fixed();
  168. return *this;
  169. }
  170. private:
  171. ClipRects(const LayoutRect& r)
  172. : m_overflowClipRect(r)
  173. , m_fixedClipRect(r)
  174. , m_posClipRect(r)
  175. , m_refCnt(1)
  176. , m_fixed(false)
  177. {
  178. }
  179. ClipRects(const ClipRects& other)
  180. : m_overflowClipRect(other.overflowClipRect())
  181. , m_fixedClipRect(other.fixedClipRect())
  182. , m_posClipRect(other.posClipRect())
  183. , m_refCnt(1)
  184. , m_fixed(other.fixed())
  185. {
  186. }
  187. ClipRect m_overflowClipRect;
  188. ClipRect m_fixedClipRect;
  189. ClipRect m_posClipRect;
  190. unsigned m_refCnt : 31;
  191. bool m_fixed : 1;
  192. };
  193. enum ClipRectsType {
  194. PaintingClipRects, // Relative to painting ancestor. Used for painting.
  195. RootRelativeClipRects, // Relative to the ancestor treated as the root (e.g. transformed layer). Used for hit testing.
  196. AbsoluteClipRects, // Relative to the RenderView's layer. Used for compositing overlap testing.
  197. NumCachedClipRectsTypes,
  198. AllClipRectTypes,
  199. TemporaryClipRects
  200. };
  201. enum ShouldRespectOverflowClip {
  202. IgnoreOverflowClip,
  203. RespectOverflowClip
  204. };
  205. struct ClipRectsCache {
  206. WTF_MAKE_FAST_ALLOCATED;
  207. public:
  208. ClipRectsCache()
  209. {
  210. #ifndef NDEBUG
  211. for (int i = 0; i < NumCachedClipRectsTypes; ++i) {
  212. m_clipRectsRoot[i] = 0;
  213. m_scrollbarRelevancy[i] = IgnoreOverlayScrollbarSize;
  214. }
  215. #endif
  216. }
  217. PassRefPtr<ClipRects> getClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow) { return m_clipRects[getIndex(clipRectsType, respectOverflow)]; }
  218. void setClipRects(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow, PassRefPtr<ClipRects> clipRects) { m_clipRects[getIndex(clipRectsType, respectOverflow)] = clipRects; }
  219. #ifndef NDEBUG
  220. const RenderLayer* m_clipRectsRoot[NumCachedClipRectsTypes];
  221. OverlayScrollbarSizeRelevancy m_scrollbarRelevancy[NumCachedClipRectsTypes];
  222. #endif
  223. private:
  224. int getIndex(ClipRectsType clipRectsType, ShouldRespectOverflowClip respectOverflow)
  225. {
  226. int index = static_cast<int>(clipRectsType);
  227. if (respectOverflow == RespectOverflowClip)
  228. index += static_cast<int>(NumCachedClipRectsTypes);
  229. return index;
  230. }
  231. RefPtr<ClipRects> m_clipRects[NumCachedClipRectsTypes * 2];
  232. };
  233. struct LayerFragment {
  234. public:
  235. LayerFragment()
  236. : shouldPaintContent(false)
  237. { }
  238. void setRects(const LayoutRect& bounds, const ClipRect& background, const ClipRect& foreground, const ClipRect& outline)
  239. {
  240. layerBounds = bounds;
  241. backgroundRect = background;
  242. foregroundRect = foreground;
  243. outlineRect = outline;
  244. }
  245. void moveBy(const LayoutPoint& offset)
  246. {
  247. layerBounds.moveBy(offset);
  248. backgroundRect.moveBy(offset);
  249. foregroundRect.moveBy(offset);
  250. outlineRect.moveBy(offset);
  251. paginationClip.moveBy(offset);
  252. }
  253. void intersect(const LayoutRect& rect)
  254. {
  255. backgroundRect.intersect(rect);
  256. foregroundRect.intersect(rect);
  257. outlineRect.intersect(rect);
  258. }
  259. bool shouldPaintContent;
  260. LayoutRect layerBounds;
  261. ClipRect backgroundRect;
  262. ClipRect foregroundRect;
  263. ClipRect outlineRect;
  264. // Unique to paginated fragments. The physical translation to apply to shift the layer when painting/hit-testing.
  265. LayoutPoint paginationOffset;
  266. // Also unique to paginated fragments. An additional clip that applies to the layer. It is in layer-local
  267. // (physical) coordinates.
  268. LayoutRect paginationClip;
  269. };
  270. typedef Vector<LayerFragment, 1> LayerFragments;
  271. class RenderLayer : public ScrollableArea {
  272. public:
  273. friend class RenderReplica;
  274. RenderLayer(RenderLayerModelObject*);
  275. ~RenderLayer();
  276. String name() const;
  277. RenderLayerModelObject* renderer() const { return m_renderer; }
  278. RenderBox* renderBox() const { return m_renderer && m_renderer->isBox() ? toRenderBox(m_renderer) : 0; }
  279. RenderLayer* parent() const { return m_parent; }
  280. RenderLayer* previousSibling() const { return m_previous; }
  281. RenderLayer* nextSibling() const { return m_next; }
  282. RenderLayer* firstChild() const { return m_first; }
  283. RenderLayer* lastChild() const { return m_last; }
  284. void addChild(RenderLayer* newChild, RenderLayer* beforeChild = 0);
  285. RenderLayer* removeChild(RenderLayer*);
  286. void removeOnlyThisLayer();
  287. void insertOnlyThisLayer();
  288. void repaintIncludingDescendants();
  289. #if USE(ACCELERATED_COMPOSITING)
  290. // Indicate that the layer contents need to be repainted. Only has an effect
  291. // if layer compositing is being used,
  292. void setBackingNeedsRepaint();
  293. void setBackingNeedsRepaintInRect(const LayoutRect&); // r is in the coordinate space of the layer's render object
  294. void repaintIncludingNonCompositingDescendants(RenderLayerModelObject* repaintContainer);
  295. #endif
  296. void styleChanged(StyleDifference, const RenderStyle* oldStyle);
  297. RenderMarquee* marquee() const { return m_marquee.get(); }
  298. bool isNormalFlowOnly() const { return m_isNormalFlowOnly; }
  299. bool isSelfPaintingLayer() const { return m_isSelfPaintingLayer; }
  300. bool cannotBlitToWindow() const;
  301. bool isTransparent() const;
  302. RenderLayer* transparentPaintingAncestor();
  303. void beginTransparencyLayers(GraphicsContext*, const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
  304. bool hasReflection() const { return renderer()->hasReflection(); }
  305. bool isReflection() const { return renderer()->isReplica(); }
  306. RenderReplica* reflection() const { return m_reflection; }
  307. RenderLayer* reflectionLayer() const;
  308. const RenderLayer* root() const
  309. {
  310. const RenderLayer* curr = this;
  311. while (curr->parent())
  312. curr = curr->parent();
  313. return curr;
  314. }
  315. const LayoutPoint& location() const { return m_topLeft; }
  316. void setLocation(const LayoutPoint& p) { m_topLeft = p; }
  317. const IntSize& size() const { return m_layerSize; }
  318. void setSize(const IntSize& size) { m_layerSize = size; }
  319. LayoutRect rect() const { return LayoutRect(location(), size()); }
  320. int scrollWidth() const;
  321. int scrollHeight() const;
  322. void panScrollFromPoint(const IntPoint&);
  323. enum ScrollOffsetClamping {
  324. ScrollOffsetUnclamped,
  325. ScrollOffsetClamped
  326. };
  327. // Scrolling methods for layers that can scroll their overflow.
  328. void scrollByRecursively(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped);
  329. void scrollToOffset(const IntSize&, ScrollOffsetClamping = ScrollOffsetUnclamped);
  330. void scrollToXOffset(int x, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(x, scrollYOffset()), clamp); }
  331. void scrollToYOffset(int y, ScrollOffsetClamping clamp = ScrollOffsetUnclamped) { scrollToOffset(IntSize(scrollXOffset(), y), clamp); }
  332. int scrollXOffset() const { return m_scrollOffset.width() + scrollOrigin().x(); }
  333. int scrollYOffset() const { return m_scrollOffset.height() + scrollOrigin().y(); }
  334. IntSize scrollOffset() const { return IntSize(scrollXOffset(), scrollYOffset()); }
  335. void scrollRectToVisible(const LayoutRect&, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
  336. LayoutRect getRectToExpose(const LayoutRect& visibleRect, const LayoutRect& visibleRectRelativeToDocument, const LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& alignY);
  337. bool scrollsOverflow() const;
  338. bool hasScrollbars() const { return m_hBar || m_vBar; }
  339. void setHasHorizontalScrollbar(bool);
  340. void setHasVerticalScrollbar(bool);
  341. PassRefPtr<Scrollbar> createScrollbar(ScrollbarOrientation);
  342. void destroyScrollbar(ScrollbarOrientation);
  343. bool hasHorizontalScrollbar() const { return horizontalScrollbar(); }
  344. bool hasVerticalScrollbar() const { return verticalScrollbar(); }
  345. // ScrollableArea overrides
  346. virtual Scrollbar* horizontalScrollbar() const { return m_hBar.get(); }
  347. virtual Scrollbar* verticalScrollbar() const { return m_vBar.get(); }
  348. virtual ScrollableArea* enclosingScrollableArea() const;
  349. int verticalScrollbarWidth(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
  350. int horizontalScrollbarHeight(OverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize) const;
  351. bool hasOverflowControls() const;
  352. bool isPointInResizeControl(const IntPoint& absolutePoint) const;
  353. bool hitTestOverflowControls(HitTestResult&, const IntPoint& localPoint);
  354. IntSize offsetFromResizeCorner(const IntPoint& absolutePoint) const;
  355. void paintOverflowControls(GraphicsContext*, const IntPoint&, const IntRect& damageRect, bool paintingOverlayControls = false);
  356. void paintScrollCorner(GraphicsContext*, const IntPoint&, const IntRect& damageRect);
  357. void paintResizer(GraphicsContext*, const IntPoint&, const IntRect& damageRect);
  358. void updateScrollInfoAfterLayout();
  359. bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1);
  360. void autoscroll(const IntPoint&);
  361. bool canResize() const;
  362. void resize(const PlatformMouseEvent&, const LayoutSize&);
  363. bool inResizeMode() const { return m_inResizeMode; }
  364. void setInResizeMode(bool b) { m_inResizeMode = b; }
  365. bool isRootLayer() const { return m_isRootLayer; }
  366. #if USE(ACCELERATED_COMPOSITING)
  367. RenderLayerCompositor* compositor() const;
  368. // Notification from the renderer that its content changed (e.g. current frame of image changed).
  369. // Allows updates of layer content without repainting.
  370. void contentChanged(ContentChangeType);
  371. #endif
  372. bool canRender3DTransforms() const;
  373. enum UpdateLayerPositionsFlag {
  374. CheckForRepaint = 1 << 0,
  375. NeedsFullRepaintInBacking = 1 << 1,
  376. IsCompositingUpdateRoot = 1 << 2,
  377. UpdateCompositingLayers = 1 << 3,
  378. UpdatePagination = 1 << 4
  379. };
  380. typedef unsigned UpdateLayerPositionsFlags;
  381. static const UpdateLayerPositionsFlags defaultFlags = CheckForRepaint | IsCompositingUpdateRoot | UpdateCompositingLayers;
  382. void updateLayerPositionsAfterLayout(const RenderLayer* rootLayer, UpdateLayerPositionsFlags);
  383. void updateLayerPositionsAfterOverflowScroll();
  384. void updateLayerPositionsAfterDocumentScroll();
  385. #if USE(ACCELERATED_COMPOSITING)
  386. void positionNewlyCreatedOverflowControls();
  387. #endif
  388. bool isPaginated() const { return m_isPaginated; }
  389. RenderLayer* enclosingPaginationLayer() const { return m_enclosingPaginationLayer; }
  390. void updateTransform();
  391. #if ENABLE(CSS_COMPOSITING)
  392. void updateBlendMode();
  393. #endif
  394. const LayoutSize& paintOffset() const { return m_paintOffset; }
  395. void clearClipRectsIncludingDescendants(ClipRectsType typeToClear = AllClipRectTypes);
  396. void clearClipRects(ClipRectsType typeToClear = AllClipRectTypes);
  397. void addBlockSelectionGapsBounds(const LayoutRect&);
  398. void clearBlockSelectionGapsBounds();
  399. void repaintBlockSelectionGaps();
  400. // A stacking context is a layer that has a non-auto z-index.
  401. bool isStackingContext() const { return isStackingContext(renderer()->style()); }
  402. // A stacking container can have z-order lists. All stacking contexts are
  403. // stacking containers, but the converse is not true. Layers that use
  404. // composited scrolling are stacking containers, but they may not
  405. // necessarily be stacking contexts.
  406. bool isStackingContainer() const { return isStackingContext() || needsCompositedScrolling(); }
  407. // Gets the enclosing stacking container for this layer, excluding this
  408. // layer itself.
  409. RenderLayer* stackingContainer() const;
  410. // Gets the enclosing stacking container for this layer, possibly the layer
  411. // itself, if it is a stacking container.
  412. RenderLayer* enclosingStackingContainer() { return isStackingContainer() ? this : stackingContainer(); }
  413. void dirtyZOrderLists();
  414. void dirtyStackingContainerZOrderLists();
  415. Vector<RenderLayer*>* posZOrderList() const
  416. {
  417. ASSERT(!m_zOrderListsDirty);
  418. ASSERT(isStackingContainer() || !m_posZOrderList);
  419. return m_posZOrderList.get();
  420. }
  421. bool hasNegativeZOrderList() const { return negZOrderList() && negZOrderList()->size(); }
  422. Vector<RenderLayer*>* negZOrderList() const
  423. {
  424. ASSERT(!m_zOrderListsDirty);
  425. ASSERT(isStackingContainer() || !m_negZOrderList);
  426. return m_negZOrderList.get();
  427. }
  428. void dirtyNormalFlowList();
  429. Vector<RenderLayer*>* normalFlowList() const { ASSERT(!m_normalFlowListDirty); return m_normalFlowList.get(); }
  430. // Update our normal and z-index lists.
  431. void updateLayerListsIfNeeded();
  432. // FIXME: We should ASSERT(!m_visibleContentStatusDirty) here, but see https://bugs.webkit.org/show_bug.cgi?id=71044
  433. // ditto for hasVisibleDescendant(), see https://bugs.webkit.org/show_bug.cgi?id=71277
  434. bool hasVisibleContent() const { return m_hasVisibleContent; }
  435. bool hasVisibleDescendant() const { return m_hasVisibleDescendant; }
  436. void setHasVisibleContent();
  437. void dirtyVisibleContentStatus();
  438. bool hasBoxDecorationsOrBackground() const;
  439. bool hasVisibleBoxDecorations() const;
  440. // Returns true if this layer has visible content (ignoring any child layers).
  441. bool isVisuallyNonEmpty() const;
  442. // True if this layer container renderers that paint.
  443. bool hasNonEmptyChildRenderers() const;
  444. // FIXME: We should ASSERT(!m_hasSelfPaintingLayerDescendantDirty); here but we hit the same bugs as visible content above.
  445. // Part of the issue is with subtree relayout: we don't check if our ancestors have some descendant flags dirty, missing some updates.
  446. bool hasSelfPaintingLayerDescendant() const { return m_hasSelfPaintingLayerDescendant; }
  447. // This returns true if we have an out of flow positioned descendant whose
  448. // containing block is not a descendant of ours. If this is true, we cannot
  449. // automatically opt into composited scrolling since this out of flow
  450. // positioned descendant would become clipped by us, possibly altering the
  451. // rendering of the page.
  452. // FIXME: We should ASSERT(!m_hasOutOfFlowPositionedDescendantDirty); here but we may hit the same bugs as visible content above.
  453. bool hasOutOfFlowPositionedDescendant() const { return m_hasOutOfFlowPositionedDescendant; }
  454. // Gets the nearest enclosing positioned ancestor layer (also includes
  455. // the <html> layer and the root layer).
  456. RenderLayer* enclosingPositionedAncestor() const;
  457. // Returns the nearest enclosing layer that is scrollable.
  458. RenderLayer* enclosingScrollableLayer() const;
  459. // The layer relative to which clipping rects for this layer are computed.
  460. RenderLayer* clippingRootForPainting() const;
  461. RenderLayer* enclosingOverflowClipLayer(IncludeSelfOrNot) const;
  462. #if USE(ACCELERATED_COMPOSITING)
  463. // Enclosing compositing layer; if includeSelf is true, may return this.
  464. RenderLayer* enclosingCompositingLayer(IncludeSelfOrNot = IncludeSelf) const;
  465. RenderLayer* enclosingCompositingLayerForRepaint(IncludeSelfOrNot = IncludeSelf) const;
  466. // Ancestor compositing layer, excluding this.
  467. RenderLayer* ancestorCompositingLayer() const { return enclosingCompositingLayer(ExcludeSelf); }
  468. #endif
  469. #if ENABLE(CSS_FILTERS)
  470. RenderLayer* enclosingFilterLayer(IncludeSelfOrNot = IncludeSelf) const;
  471. RenderLayer* enclosingFilterRepaintLayer() const;
  472. void setFilterBackendNeedsRepaintingInRect(const LayoutRect&, bool immediate);
  473. bool hasAncestorWithFilterOutsets() const;
  474. #endif
  475. bool canUseConvertToLayerCoords() const
  476. {
  477. // These RenderObject have an impact on their layers' without them knowing about it.
  478. return !renderer()->hasColumns() && !renderer()->hasTransform()
  479. #if ENABLE(SVG)
  480. && !renderer()->isSVGRoot()
  481. #endif
  482. ;
  483. }
  484. // FIXME: adjustForColumns allows us to position compositing layers in columns correctly, but eventually they need to be split across columns too.
  485. enum ColumnOffsetAdjustment { DontAdjustForColumns, AdjustForColumns };
  486. void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntPoint& location, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
  487. void convertToPixelSnappedLayerCoords(const RenderLayer* ancestorLayer, IntRect&, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
  488. void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutPoint&, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
  489. void convertToLayerCoords(const RenderLayer* ancestorLayer, LayoutRect&, ColumnOffsetAdjustment adjustForColumns = DontAdjustForColumns) const;
  490. int zIndex() const { return renderer()->style()->zIndex(); }
  491. enum PaintLayerFlag {
  492. PaintLayerHaveTransparency = 1,
  493. PaintLayerAppliedTransform = 1 << 1,
  494. PaintLayerTemporaryClipRects = 1 << 2,
  495. PaintLayerPaintingReflection = 1 << 3,
  496. PaintLayerPaintingOverlayScrollbars = 1 << 4,
  497. PaintLayerPaintingCompositingBackgroundPhase = 1 << 5,
  498. PaintLayerPaintingCompositingForegroundPhase = 1 << 6,
  499. PaintLayerPaintingCompositingMaskPhase = 1 << 7,
  500. PaintLayerPaintingCompositingScrollingPhase = 1 << 8,
  501. PaintLayerPaintingOverflowContents = 1 << 9,
  502. PaintLayerPaintingRootBackgroundOnly = 1 << 10,
  503. PaintLayerPaintingSkipRootBackground = 1 << 11,
  504. PaintLayerPaintingCompositingAllPhases = (PaintLayerPaintingCompositingBackgroundPhase | PaintLayerPaintingCompositingForegroundPhase | PaintLayerPaintingCompositingMaskPhase)
  505. };
  506. typedef unsigned PaintLayerFlags;
  507. // The two main functions that use the layer system. The paint method
  508. // paints the layers that intersect the damage rect from back to
  509. // front. The hitTest method looks for mouse events by walking
  510. // layers that intersect the point from front to back.
  511. void paint(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior = PaintBehaviorNormal, RenderObject* subtreePaintRoot = 0,
  512. RenderRegion* = 0, PaintLayerFlags = 0);
  513. bool hitTest(const HitTestRequest&, HitTestResult&);
  514. bool hitTest(const HitTestRequest&, const HitTestLocation&, HitTestResult&);
  515. void paintOverlayScrollbars(GraphicsContext*, const LayoutRect& damageRect, PaintBehavior, RenderObject* subtreePaintRoot = 0);
  516. struct ClipRectsContext {
  517. ClipRectsContext(const RenderLayer* inRootLayer, RenderRegion* inRegion, ClipRectsType inClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize, ShouldRespectOverflowClip inRespectOverflowClip = RespectOverflowClip)
  518. : rootLayer(inRootLayer)
  519. , region(inRegion)
  520. , clipRectsType(inClipRectsType)
  521. , overlayScrollbarSizeRelevancy(inOverlayScrollbarSizeRelevancy)
  522. , respectOverflowClip(inRespectOverflowClip)
  523. { }
  524. const RenderLayer* rootLayer;
  525. RenderRegion* region;
  526. ClipRectsType clipRectsType;
  527. OverlayScrollbarSizeRelevancy overlayScrollbarSizeRelevancy;
  528. ShouldRespectOverflowClip respectOverflowClip;
  529. };
  530. // This method figures out our layerBounds in coordinates relative to
  531. // |rootLayer}. It also computes our background and foreground clip rects
  532. // for painting/event handling.
  533. // Pass offsetFromRoot if known.
  534. void calculateRects(const ClipRectsContext&, const LayoutRect& paintDirtyRect, LayoutRect& layerBounds,
  535. ClipRect& backgroundRect, ClipRect& foregroundRect, ClipRect& outlineRect, const LayoutPoint* offsetFromRoot = 0) const;
  536. // Compute and cache clip rects computed with the given layer as the root
  537. void updateClipRects(const ClipRectsContext&);
  538. // Compute and return the clip rects. If useCached is true, will used previously computed clip rects on ancestors
  539. // (rather than computing them all from scratch up the parent chain).
  540. void calculateClipRects(const ClipRectsContext&, ClipRects&) const;
  541. ClipRects* clipRects(const ClipRectsContext& context) const
  542. {
  543. ASSERT(context.clipRectsType < NumCachedClipRectsTypes);
  544. return m_clipRectsCache ? m_clipRectsCache->getClipRects(context.clipRectsType, context.respectOverflowClip).get() : 0;
  545. }
  546. LayoutRect childrenClipRect() const; // Returns the foreground clip rect of the layer in the document's coordinate space.
  547. LayoutRect selfClipRect() const; // Returns the background clip rect of the layer in the document's coordinate space.
  548. LayoutRect localClipRect() const; // Returns the background clip rect of the layer in the local coordinate space.
  549. // Pass offsetFromRoot if known.
  550. bool intersectsDamageRect(const LayoutRect& layerBounds, const LayoutRect& damageRect, const RenderLayer* rootLayer, const LayoutPoint* offsetFromRoot = 0) const;
  551. enum CalculateLayerBoundsFlag {
  552. IncludeSelfTransform = 1 << 0,
  553. UseLocalClipRectIfPossible = 1 << 1,
  554. IncludeLayerFilterOutsets = 1 << 2,
  555. ExcludeHiddenDescendants = 1 << 3,
  556. DontConstrainForMask = 1 << 4,
  557. IncludeCompositedDescendants = 1 << 5,
  558. UseFragmentBoxes = 1 << 6,
  559. DefaultCalculateLayerBoundsFlags = IncludeSelfTransform | UseLocalClipRectIfPossible | IncludeLayerFilterOutsets | UseFragmentBoxes
  560. };
  561. typedef unsigned CalculateLayerBoundsFlags;
  562. // Bounding box relative to some ancestor layer. Pass offsetFromRoot if known.
  563. LayoutRect boundingBox(const RenderLayer* rootLayer, CalculateLayerBoundsFlags = 0, const LayoutPoint* offsetFromRoot = 0) const;
  564. // Bounding box in the coordinates of this layer.
  565. LayoutRect localBoundingBox(CalculateLayerBoundsFlags = 0) const;
  566. // Pixel snapped bounding box relative to the root.
  567. IntRect absoluteBoundingBox() const;
  568. // Bounds used for layer overlap testing in RenderLayerCompositor.
  569. LayoutRect overlapBounds() const { return overlapBoundsIncludeChildren() ? calculateLayerBounds(this) : localBoundingBox(); }
  570. #if ENABLE(CSS_FILTERS)
  571. // If true, this layer's children are included in its bounds for overlap testing.
  572. // We can't rely on the children's positions if this layer has a filter that could have moved the children's pixels around.
  573. bool overlapBoundsIncludeChildren() const { return hasFilter() && renderer()->style()->filter().hasFilterThatMovesPixels(); }
  574. #else
  575. bool overlapBoundsIncludeChildren() const { return false; }
  576. #endif
  577. // Can pass offsetFromRoot if known.
  578. IntRect calculateLayerBounds(const RenderLayer* ancestorLayer, const LayoutPoint* offsetFromRoot = 0, CalculateLayerBoundsFlags = DefaultCalculateLayerBoundsFlags) const;
  579. // WARNING: This method returns the offset for the parent as this is what updateLayerPositions expects.
  580. LayoutPoint computeOffsetFromRoot(bool& hasLayerOffset) const;
  581. // Return a cached repaint rect, computed relative to the layer renderer's containerForRepaint.
  582. LayoutRect repaintRect() const { return m_repaintRect; }
  583. LayoutRect repaintRectIncludingNonCompositingDescendants() const;
  584. void setRepaintStatus(RepaintStatus status) { m_repaintStatus = status; }
  585. LayoutUnit staticInlinePosition() const { return m_staticInlinePosition; }
  586. LayoutUnit staticBlockPosition() const { return m_staticBlockPosition; }
  587. void setStaticInlinePosition(LayoutUnit position) { m_staticInlinePosition = position; }
  588. void setStaticBlockPosition(LayoutUnit position) { m_staticBlockPosition = position; }
  589. bool hasTransform() const { return renderer()->hasTransform(); }
  590. // Note that this transform has the transform-origin baked in.
  591. TransformationMatrix* transform() const { return m_transform.get(); }
  592. // currentTransform computes a transform which takes accelerated animations into account. The
  593. // resulting transform has transform-origin baked in. If the layer does not have a transform,
  594. // returns the identity matrix.
  595. TransformationMatrix currentTransform(RenderStyle::ApplyTransformOrigin = RenderStyle::IncludeTransformOrigin) const;
  596. TransformationMatrix renderableTransform(PaintBehavior) const;
  597. // Get the perspective transform, which is applied to transformed sublayers.
  598. // Returns true if the layer has a -webkit-perspective.
  599. // Note that this transform has the perspective-origin baked in.
  600. TransformationMatrix perspectiveTransform() const;
  601. FloatPoint perspectiveOrigin() const;
  602. bool preserves3D() const { return renderer()->style()->transformStyle3D() == TransformStyle3DPreserve3D; }
  603. bool has3DTransform() const { return m_transform && !m_transform->isAffine(); }
  604. #if ENABLE(CSS_FILTERS)
  605. virtual void filterNeedsRepaint();
  606. bool hasFilter() const { return renderer()->hasFilter(); }
  607. #else
  608. bool hasFilter() const { return false; }
  609. #endif
  610. #if ENABLE(CSS_COMPOSITING)
  611. bool hasBlendMode() const { return renderer()->hasBlendMode(); }
  612. #else
  613. bool hasBlendMode() const { return false; }
  614. #endif
  615. // Overloaded new operator. Derived classes must override operator new
  616. // in order to allocate out of the RenderArena.
  617. void* operator new(size_t, RenderArena*);
  618. // Overridden to prevent the normal delete from being called.
  619. void operator delete(void*, size_t);
  620. #if USE(ACCELERATED_COMPOSITING)
  621. bool isComposited() const { return m_backing != 0; }
  622. bool hasCompositedMask() const;
  623. RenderLayerBacking* backing() const { return m_backing.get(); }
  624. RenderLayerBacking* ensureBacking();
  625. void clearBacking(bool layerBeingDestroyed = false);
  626. virtual GraphicsLayer* layerForScrolling() const;
  627. virtual GraphicsLayer* layerForHorizontalScrollbar() const;
  628. virtual GraphicsLayer* layerForVerticalScrollbar() const;
  629. virtual GraphicsLayer* layerForScrollCorner() const;
  630. virtual bool usesCompositedScrolling() const OVERRIDE;
  631. bool needsCompositedScrolling() const;
  632. bool needsCompositingLayersRebuiltForClip(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
  633. bool needsCompositingLayersRebuiltForOverflow(const RenderStyle* oldStyle, const RenderStyle* newStyle) const;
  634. #else
  635. bool isComposited() const { return false; }
  636. bool hasCompositedMask() const { return false; }
  637. bool usesCompositedScrolling() const { return false; }
  638. bool needsCompositedScrolling() const { return false; }
  639. #endif
  640. bool paintsWithTransparency(PaintBehavior paintBehavior) const
  641. {
  642. return isTransparent() && ((paintBehavior & PaintBehaviorFlattenCompositingLayers) || !isComposited());
  643. }
  644. bool paintsWithTransform(PaintBehavior) const;
  645. // Returns true if background phase is painted opaque in the given rect.
  646. // The query rect is given in local coordinates.
  647. bool backgroundIsKnownToBeOpaqueInRect(const LayoutRect&) const;
  648. bool containsDirtyOverlayScrollbars() const { return m_containsDirtyOverlayScrollbars; }
  649. void setContainsDirtyOverlayScrollbars(bool dirtyScrollbars) { m_containsDirtyOverlayScrollbars = dirtyScrollbars; }
  650. #if ENABLE(CSS_SHADERS)
  651. bool isCSSCustomFilterEnabled() const;
  652. #endif
  653. #if ENABLE(CSS_FILTERS)
  654. FilterOperations computeFilterOperations(const RenderStyle*);
  655. bool paintsWithFilters() const;
  656. bool requiresFullLayerImageForFilters() const;
  657. FilterEffectRenderer* filterRenderer() const;
  658. RenderLayerFilterInfo* filterInfo() const;
  659. RenderLayerFilterInfo* ensureFilterInfo();
  660. void removeFilterInfoIfNeeded();
  661. bool hasFilterInfo() const { return m_hasFilterInfo; }
  662. void setHasFilterInfo(bool hasFilterInfo) { m_hasFilterInfo = hasFilterInfo; }
  663. #endif
  664. #if !ASSERT_DISABLED
  665. bool layerListMutationAllowed() const { return m_layerListMutationAllowed; }
  666. void setLayerListMutationAllowed(bool flag) { m_layerListMutationAllowed = flag; }
  667. #endif
  668. Node* enclosingElement() const;
  669. #if ENABLE(DIALOG_ELEMENT)
  670. bool isInTopLayer() const;
  671. bool isInTopLayerSubtree() const;
  672. #endif
  673. #if USE(ACCELERATED_COMPOSITING)
  674. enum ViewportConstrainedNotCompositedReason {
  675. NoNotCompositedReason,
  676. NotCompositedForBoundsOutOfView,
  677. NotCompositedForNonViewContainer,
  678. NotCompositedForNoVisibleContent,
  679. };
  680. void setViewportConstrainedNotCompositedReason(ViewportConstrainedNotCompositedReason reason) { m_viewportConstrainedNotCompositedReason = reason; }
  681. ViewportConstrainedNotCompositedReason viewportConstrainedNotCompositedReason() const { return static_cast<ViewportConstrainedNotCompositedReason>(m_viewportConstrainedNotCompositedReason); }
  682. #endif
  683. bool isOutOfFlowRenderFlowThread() const { return renderer()->isOutOfFlowRenderFlowThread(); }
  684. private:
  685. enum CollectLayersBehavior { StopAtStackingContexts, StopAtStackingContainers };
  686. void updateZOrderLists();
  687. void rebuildZOrderLists();
  688. void rebuildZOrderLists(CollectLayersBehavior, OwnPtr<Vector<RenderLayer*> >&, OwnPtr<Vector<RenderLayer*> >&);
  689. void clearZOrderLists();
  690. void updateNormalFlowList();
  691. // Non-auto z-index always implies stacking context here, because StyleResolver::adjustRenderStyle already adjusts z-index
  692. // based on positioning and other criteria.
  693. bool isStackingContext(const RenderStyle* style) const { return !style->hasAutoZIndex() || isRootLayer(); }
  694. bool isDirtyStackingContainer() const { return m_zOrderListsDirty && isStackingContainer(); }
  695. void setAncestorChainHasSelfPaintingLayerDescendant();
  696. void dirtyAncestorChainHasSelfPaintingLayerDescendantStatus();
  697. bool acceleratedCompositingForOverflowScrollEnabled() const;
  698. void updateDescendantsAreContiguousInStackingOrder();
  699. void updateDescendantsAreContiguousInStackingOrderRecursive(const HashMap<const RenderLayer*, int>&, int& minIndex, int& maxIndex, int& count, bool firstIteration);
  700. void computeRepaintRects(const RenderLayerModelObject* repaintContainer, const RenderGeometryMap* = 0);
  701. void computeRepaintRectsIncludingDescendants();
  702. void clearRepaintRects();
  703. void clipToRect(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&,
  704. BorderRadiusClippingRule = IncludeSelfForBorderRadius);
  705. void restoreClip(GraphicsContext*, const LayoutRect& paintDirtyRect, const ClipRect&);
  706. bool shouldRepaintAfterLayout() const;
  707. void updateSelfPaintingLayer();
  708. void updateStackingContextsAfterStyleChange(const RenderStyle* oldStyle);
  709. void updateScrollbarsAfterStyleChange(const RenderStyle* oldStyle);
  710. void updateScrollbarsAfterLayout();
  711. void setAncestorChainHasOutOfFlowPositionedDescendant(RenderObject* containingBlock);
  712. void dirtyAncestorChainHasOutOfFlowPositionedDescendantStatus();
  713. void updateOutOfFlowPositioned(const RenderStyle* oldStyle);
  714. void updateNeedsCompositedScrolling();
  715. // Returns true if the position changed.
  716. bool updateLayerPosition();
  717. void updateLayerPositions(RenderGeometryMap* = 0, UpdateLayerPositionsFlags = defaultFlags);
  718. enum UpdateLayerPositionsAfterScrollFlag {
  719. NoFlag = 0,
  720. IsOverflowScroll = 1 << 0,
  721. HasSeenViewportConstrainedAncestor = 1 << 1,
  722. HasSeenAncestorWithOverflowClip = 1 << 2,
  723. HasChangedAncestor = 1 << 3
  724. };
  725. typedef unsigned UpdateLayerPositionsAfterScrollFlags;
  726. void updateLayerPositionsAfterScroll(RenderGeometryMap*, UpdateLayerPositionsAfterScrollFlags = NoFlag);
  727. friend IntSize RenderBox::scrolledContentOffset() const;
  728. IntSize scrolledContentOffset() const { return m_scrollOffset; }
  729. IntSize clampScrollOffset(const IntSize&) const;
  730. // The normal operator new is disallowed on all render objects.
  731. void* operator new(size_t) throw();
  732. void setNextSibling(RenderLayer* next) { m_next = next; }
  733. void setPreviousSibling(RenderLayer* prev) { m_previous = prev; }
  734. void setParent(RenderLayer* parent);
  735. void setFirstChild(RenderLayer* first) { m_first = first; }
  736. void setLastChild(RenderLayer* last) { m_last = last; }
  737. LayoutPoint renderBoxLocation() const { return renderer()->isBox() ? toRenderBox(renderer())->location() : LayoutPoint(); }
  738. void collectLayers(bool includeHiddenLayers, CollectLayersBehavior, OwnPtr<Vector<RenderLayer*> >&, OwnPtr<Vector<RenderLayer*> >&);
  739. void updateCompositingAndLayerListsIfNeeded();
  740. struct LayerPaintingInfo {
  741. LayerPaintingInfo(RenderLayer* inRootLayer, const LayoutRect& inDirtyRect, PaintBehavior inPaintBehavior, const LayoutSize& inSubPixelAccumulation, RenderObject* inSubtreePaintRoot = 0, RenderRegion*inRegion = 0, OverlapTestRequestMap* inOverlapTestRequests = 0)
  742. : rootLayer(inRootLayer)
  743. , subtreePaintRoot(inSubtreePaintRoot)
  744. , paintDirtyRect(inDirtyRect)
  745. , subPixelAccumulation(inSubPixelAccumulation)
  746. , region(inRegion)
  747. , overlapTestRequests(inOverlapTestRequests)
  748. , paintBehavior(inPaintBehavior)
  749. , clipToDirtyRect(true)
  750. { }
  751. RenderLayer* rootLayer;
  752. RenderObject* subtreePaintRoot; // only paint descendants of this object
  753. LayoutRect paintDirtyRect; // relative to rootLayer;
  754. LayoutSize subPixelAccumulation;
  755. RenderRegion* region; // May be null.
  756. OverlapTestRequestMap* overlapTestRequests; // May be null.
  757. PaintBehavior paintBehavior;
  758. bool clipToDirtyRect;
  759. };
  760. bool setupFontSubpixelQuantization(GraphicsContext*, bool& didQuantizeFonts);
  761. bool setupClipPath(GraphicsContext*, const LayerPaintingInfo&, const LayoutPoint& offsetFromRoot, IntRect& rootRelativeBounds, bool& rootRelativeBoundsComputed);
  762. #if ENABLE(CSS_FILTERS)
  763. PassOwnPtr<FilterEffectRendererHelper> setupFilters(GraphicsContext*, LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& offsetFromRoot, IntRect& rootRelativeBounds, bool& rootRelativeBoundsComputed);
  764. GraphicsContext* applyFilters(FilterEffectRendererHelper*, GraphicsContext* originalContext, LayerPaintingInfo&, LayerFragments&);
  765. #endif
  766. void paintLayer(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  767. void paintLayerContentsAndReflection(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  768. void paintLayerByApplyingTransform(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const LayoutPoint& translationOffset = LayoutPoint());
  769. void paintLayerContents(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  770. void paintList(Vector<RenderLayer*>*, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  771. void paintPaginatedChildLayer(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  772. void paintChildLayerIntoColumns(RenderLayer* childLayer, GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags, const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
  773. void collectFragments(LayerFragments&, const RenderLayer* rootLayer, RenderRegion*, const LayoutRect& dirtyRect,
  774. ClipRectsType, OverlayScrollbarSizeRelevancy inOverlayScrollbarSizeRelevancy = IgnoreOverlayScrollbarSize,
  775. ShouldRespectOverflowClip = RespectOverflowClip, const LayoutPoint* offsetFromRoot = 0, const LayoutRect* layerBoundingBox = 0);
  776. void updatePaintingInfoForFragments(LayerFragments&, const LayerPaintingInfo&, PaintLayerFlags, bool shouldPaintContent, const LayoutPoint* offsetFromRoot);
  777. void paintBackgroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
  778. const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
  779. void paintForegroundForFragments(const LayerFragments&, GraphicsContext*, GraphicsContext* transparencyLayerContext,
  780. const LayoutRect& transparencyPaintDirtyRect, bool haveTransparency, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer,
  781. bool selectionOnly, bool forceBlackText);
  782. void paintForegroundForFragmentsWithPhase(PaintPhase, const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
  783. void paintOutlineForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, PaintBehavior, RenderObject* paintingRootForRenderer);
  784. void paintOverflowControlsForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&);
  785. void paintMaskForFragments(const LayerFragments&, GraphicsContext*, const LayerPaintingInfo&, RenderObject* paintingRootForRenderer);
  786. void paintTransformedLayerIntoFragments(GraphicsContext*, const LayerPaintingInfo&, PaintLayerFlags);
  787. RenderLayer* hitTestLayer(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest& request, HitTestResult& result,
  788. const LayoutRect& hitTestRect, const HitTestLocation&, bool appliedTransform,
  789. const HitTestingTransformState* transformState = 0, double* zOffset = 0);
  790. RenderLayer* hitTestLayerByApplyingTransform(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
  791. const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0,
  792. const LayoutPoint& translationOffset = LayoutPoint());
  793. RenderLayer* hitTestList(Vector<RenderLayer*>*, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
  794. const LayoutRect& hitTestRect, const HitTestLocation&,
  795. const HitTestingTransformState* transformState, double* zOffsetForDescendants, double* zOffset,
  796. const HitTestingTransformState* unflattenedTransformState, bool depthSortDescendants);
  797. RenderLayer* hitTestPaginatedChildLayer(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
  798. const LayoutRect& hitTestRect, const HitTestLocation&,
  799. const HitTestingTransformState* transformState, double* zOffset);
  800. RenderLayer* hitTestChildLayerColumns(RenderLayer* childLayer, RenderLayer* rootLayer, const HitTestRequest& request, HitTestResult& result,
  801. const LayoutRect& hitTestRect, const HitTestLocation&,
  802. const HitTestingTransformState* transformState, double* zOffset,
  803. const Vector<RenderLayer*>& columnLayers, size_t columnIndex);
  804. PassRefPtr<HitTestingTransformState> createLocalTransformState(RenderLayer* rootLayer, RenderLayer* containerLayer,
  805. const LayoutRect& hitTestRect, const HitTestLocation&,
  806. const HitTestingTransformState* containerTransformState,
  807. const LayoutPoint& translationOffset = LayoutPoint()) const;
  808. bool hitTestContents(const HitTestRequest&, HitTestResult&, const LayoutRect& layerBounds, const HitTestLocation&, HitTestFilter) const;
  809. bool hitTestContentsForFragments(const LayerFragments&, const HitTestRequest&, HitTestResult&, const HitTestLocation&, HitTestFilter, bool& insideClipRect) const;
  810. bool hitTestResizerInFragments(const LayerFragments&, const HitTestLocation&) const;
  811. RenderLayer* hitTestTransformedLayerInFragments(RenderLayer* rootLayer, RenderLayer* containerLayer, const HitTestRequest&, HitTestResult&,
  812. const LayoutRect& hitTestRect, const HitTestLocation&, const HitTestingTransformState* = 0, double* zOffset = 0);
  813. bool listBackgroundIsKnownToBeOpaqueInRect(const Vector<RenderLayer*>*, const LayoutRect&) const;
  814. void computeScrollDimensions();
  815. bool hasHorizontalOverflow() const;
  816. bool hasVerticalOverflow() const;
  817. bool hasScrollableHorizontalOverflow() const;
  818. bool hasScrollableVerticalOverflow() const;
  819. bool shouldBeNormalFlowOnly() const;
  820. bool shouldBeSelfPaintingLayer() const;
  821. int scrollPosition(Scrollbar*) const;
  822. // ScrollableArea interface
  823. virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&);
  824. virtual void invalidateScrollCornerRect(const IntRect&);
  825. virtual bool isActive() const;
  826. virtual bool isScrollCornerVisible() const;
  827. virtual IntRect scrollCornerRect() const;
  828. virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const IntRect&) const;
  829. virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const IntRect&) const;
  830. virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, const IntPoint&) const;
  831. virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, const IntPoint&) const;
  832. virtual int scrollSize(ScrollbarOrientation) const;
  833. virtual void setScrollOffset(const IntPoint&);
  834. virtual IntPoint scrollPosition() const;
  835. virtual IntPoint minimumScrollPosition() const;
  836. virtual IntPoint maximumScrollPosition() const;
  837. virtual IntRect visibleContentRect(VisibleContentRectIncludesScrollbars) const;
  838. virtual int visibleHeight() const;
  839. virtual int visibleWidth() const;
  840. virtual IntSize contentsSize() const;
  841. virtual IntSize overhangAmount() const;
  842. virtual IntPoint lastKnownMousePosition() const;
  843. virtual bool isHandlingWheelEvent() const OVERRIDE;
  844. virtual bool shouldSuspendScrollAnimations() const;
  845. virtual bool scrollbarsCanBeActive() const;
  846. virtual IntRect scrollableAreaBoundingBox() const OVERRIDE;
  847. virtual bool scrollbarAnimationsAreSuppressed() const OVERRIDE;
  848. // Rectangle encompassing the scroll corner and resizer rect.
  849. IntRect scrollCornerAndResizerRect() const;
  850. // NOTE: This should only be called by the overriden setScrollOffset from ScrollableArea.
  851. void scrollTo(int, int);
  852. void updateCompositingLayersAfterScroll();
  853. IntSize scrollbarOffset(const Scrollbar*) const;
  854. void updateScrollableAreaSet(bool hasOverflow);
  855. void dirtyAncestorChainVisibleDescendantStatus();
  856. void setAncestorChainHasVisibleDescendant();
  857. void updateDescendantDependentFlags(HashSet<const RenderObject*>* outOfFlowDescendantContainingBlocks = 0);
  858. // This flag is computed by RenderLayerCompositor, which knows more about 3d hierarchies than we do.
  859. void setHas3DTransformedDescendant(bool b) { m_has3DTransformedDescendant = b; }
  860. bool has3DTransformedDescendant() const { return m_has3DTransformedDescendant; }
  861. void dirty3DTransformedDescendantStatus();
  862. // Both updates the status, and returns true if descendants of this have 3d.
  863. bool update3DTransformedDescendantStatus();
  864. void createReflection();
  865. void removeReflection();
  866. void updateReflectionStyle();
  867. bool paintingInsideReflection() const { return m_paintingInsideReflection; }
  868. void setPaintingInsideReflection(bool b) { m_paintingInsideReflection = b; }
  869. #if ENABLE(CSS_FILTERS)
  870. void updateOrRemoveFilterClients();
  871. void updateOrRemoveFilterEffectRenderer();
  872. #endif
  873. void parentClipRects(const ClipRectsContext&, ClipRects&) const;
  874. ClipRect backgroundClipRect(const ClipRectsContext&) const;
  875. LayoutRect paintingExtent(const RenderLayer* rootLayer, const LayoutRect& paintDirtyRect, PaintBehavior);
  876. RenderLayer* enclosingTransformedAncestor() const;
  877. // Convert a point in absolute coords into layer coords, taking transforms into account
  878. LayoutPoint absoluteToContents(const LayoutPoint&) const;
  879. void positionOverflowControls(const IntSize&);
  880. void updateScrollCornerStyle();
  881. void updateResizerStyle();
  882. void drawPlatformResizerImage(GraphicsContext*, IntRect resizerCornerRect);
  883. void updatePagination();
  884. // FIXME: Temporary. Remove when new columns come online.
  885. bool useRegionBasedColumns() const;
  886. #if USE(ACCELERATED_COMPOSITING)
  887. bool hasCompositingDescendant() const { return m_hasCompositingDescendant; }
  888. void setHasCompositingDescendant(bool b) { m_hasCompositingDescendant = b; }
  889. enum IndirectCompositingReason {
  890. NoIndirectCompositingReason,
  891. IndirectCompositingForStacking,
  892. IndirectCompositingForOverlap,
  893. IndirectCompositingForBackgroundLayer,
  894. IndirectCompositingForGraphicalEffect, // opacity, mask, filter, transform etc.
  895. IndirectCompositingForPerspective,
  896. IndirectCompositingForPreserve3D
  897. };
  898. void setIndirectCompositingReason(IndirectCompositingReason reason) { m_indirectCompositingReason = reason; }
  899. IndirectCompositingReason indirectCompositingReason() const { return static_cast<IndirectCompositingReason>(m_indirectCompositingReason); }
  900. bool mustCompositeForIndirectReasons() const { return m_indirectCompositingReason; }
  901. #endif
  902. // Returns true if z ordering would not change if this layer were a stacking container.
  903. bool canBeStackingContainer() const;
  904. friend class RenderLayerBacking;
  905. friend class RenderLayerCompositor;
  906. friend class RenderLayerModelObject;
  907. // Only safe to call from RenderBoxModelObject::destroyLayer(RenderArena*)
  908. void destroy(RenderArena*);
  909. LayoutUnit overflowTop() const;
  910. LayoutUnit overflowBottom() const;
  911. LayoutUnit overflowLeft() const;
  912. LayoutUnit overflowRight() const;
  913. IntRect rectForHorizontalScrollbar(const IntRect& borderBoxRect) const;
  914. IntRect rectForVerticalScrollbar(const IntRect& borderBoxRect) const;
  915. LayoutUnit verticalScrollbarStart(int minX, int maxX) const;
  916. LayoutUnit horizontalScrollbarStart(int minX) const;
  917. bool overflowControlsIntersectRect(const IntRect& localRect) const;
  918. protected:
  919. // The bitfields are up here so they will fall into the padding from ScrollableArea on 64-bit.
  920. // Keeps track of whether the layer is currently resizing, so events can cause resizing to start and stop.
  921. bool m_inResizeMode : 1;
  922. bool m_scrollDimensionsDirty : 1;
  923. bool m_zOrderListsDirty : 1;
  924. bool m_normalFlowListDirty: 1;
  925. bool m_isNormalFlowOnly : 1;
  926. bool m_isSelfPaintingLayer : 1;
  927. // If have no self-painting descendants, we don't have to walk our children during painting. This can lead to
  928. // significant savings, especially if the tree has lots of non-self-painting layers grouped together (e.g. table cells).
  929. bool m_hasSelfPaintingLayerDescendant : 1;
  930. bool m_hasSelfPaintingLayerDescendantDirty : 1;
  931. // If we have no out of flow positioned descendants and no non-descendant
  932. // appears between our descendants in stacking order, then we may become a
  933. // stacking context.
  934. bool m_hasOutOfFlowPositionedDescendant : 1;
  935. bool m_hasOutOfFlowPositionedDescendantDirty : 1;
  936. bool m_needsCompositedScrolling : 1;
  937. // If this is true, then no non-descendant appears between any of our
  938. // descendants in stacking order. This is one of the requirements of being
  939. // able to safely become a stacking context.
  940. bool m_descendantsAreContiguousInStackingOrder : 1;
  941. const bool m_isRootLayer : 1;
  942. bool m_usedTransparency : 1; // Tracks whether we need to close a transparent layer, i.e., whether
  943. // we ended up painting this layer or any descendants (and therefore need to
  944. // blend).
  945. bool m_paintingInsideReflection : 1; // A state bit tracking if we are painting inside a replica.
  946. bool m_inOverflowRelayout : 1;
  947. unsigned m_repaintStatus : 2; // RepaintStatus
  948. bool m_visibleContentStatusDirty : 1;
  949. bool m_hasVisibleContent : 1;
  950. bool m_visibleDescendantStatusDirty : 1;
  951. bool m_hasVisibleDescendant : 1;
  952. bool m_isPaginated : 1; // If we think this layer is split by a multi-column ancestor, then this bit will be set.
  953. bool m_3DTransformedDescendantStatusDirty : 1;
  954. bool m_has3DTransformedDescendant : 1; // Set on a stacking context layer that has 3D descendants anywhere
  955. // in a preserves3D hierarchy. Hint to do 3D-aware hit testing.
  956. #if USE(ACCELERATED_COMPOSITING)
  957. bool m_hasCompositingDescendant : 1; // In the z-order tree.
  958. unsigned m_indirectCompositingReason : 3;
  959. unsigned m_viewportConstrainedNotCompositedReason : 2;
  960. #endif
  961. bool m_containsDirtyOverlayScrollbars : 1;
  962. bool m_updatingMarqueePosition : 1;
  963. #if !ASSERT_DISABLED
  964. bool m_layerListMutationAllowed : 1;
  965. #endif
  966. #if ENABLE(CSS_FILTERS)
  967. bool m_hasFilterInfo : 1;
  968. #endif
  969. #if ENABLE(CSS_COMPOSITING)
  970. BlendMode m_blendMode;
  971. #endif
  972. RenderLayerModelObject* m_renderer;
  973. RenderLayer* m_parent;
  974. RenderLayer* m_previous;
  975. RenderLayer* m_next;
  976. RenderLayer* m_first;
  977. RenderLayer* m_last;
  978. LayoutRect m_repaintRect; // Cached repaint rects. Used by layout.
  979. LayoutRect m_outlineBox;
  980. // Paint time offset only, it is used for properly paint relative / sticky positioned elements and exclusion boxes on floats.
  981. LayoutSize m_paintOffset;
  982. // Our (x,y) coordinates are in our parent layer's coordinate space.
  983. LayoutPoint m_topLeft;
  984. // The layer's width/height
  985. IntSize m_layerSize;
  986. // This is the (scroll) offset from scrollOrigin().
  987. IntSize m_scrollOffset;
  988. // The width/height of our scrolled area.
  989. LayoutSize m_scrollSize;
  990. // For layers with overflow, we have a pair of scrollbars.
  991. RefPtr<Scrollbar> m_hBar;
  992. RefPtr<Scrollbar> m_vBar;
  993. // For layers that establish stacking contexts, m_posZOrderList holds a sorted list of all the
  994. // descendant layers within the stacking context that have z-indices of 0 or greater
  995. // (auto will count as 0). m_negZOrderList holds descendants within our stacking context with negative
  996. // z-indices.
  997. OwnPtr<Vector<RenderLayer*> > m_posZOrderList;
  998. OwnPtr<Vector<RenderLayer*> > m_negZOrderList;
  999. // This list contains child layers that cannot create stacking contexts. For now it is just
  1000. // overflow layers, but that may change in the future.
  1001. OwnPtr<Vector<RenderLayer*> > m_normalFlowList;
  1002. OwnPtr<ClipRectsCache> m_clipRectsCache;
  1003. IntPoint m_cachedOverlayScrollbarOffset;
  1004. OwnPtr<RenderMarquee> m_marquee; // Used by layers with overflow:marquee
  1005. // Cached normal flow values for absolute positioned elements with static left/top values.
  1006. LayoutUnit m_staticInlinePosition;
  1007. LayoutUnit m_staticBlockPosition;
  1008. OwnPtr<TransformationMatrix> m_transform;
  1009. // May ultimately be extended to many replicas (with their own paint order).
  1010. RenderReplica* m_reflection;
  1011. // Renderers to hold our custom scroll corner and resizer.
  1012. RenderScrollbarPart* m_scrollCorner;
  1013. RenderScrollbarPart* m_resizer;
  1014. // Pointer to the enclosing RenderLayer that caused us to be paginated. It is 0 if we are not paginated.
  1015. RenderLayer* m_enclosingPaginationLayer;
  1016. private:
  1017. IntRect m_blockSelectionGapsBounds;
  1018. #if USE(ACCELERATED_COMPOSITING)
  1019. OwnPtr<RenderLayerBacking> m_backing;
  1020. #endif
  1021. };
  1022. inline void RenderLayer::clearZOrderLists()
  1023. {
  1024. ASSERT(!isStackingContainer());
  1025. m_posZOrderList.clear();
  1026. m_negZOrderList.clear();
  1027. }
  1028. inline void RenderLayer::updateZOrderLists()
  1029. {
  1030. if (!m_zOrderListsDirty)
  1031. return;
  1032. if (!isStackingContainer()) {
  1033. clearZOrderLists();
  1034. m_zOrderListsDirty = false;
  1035. return;
  1036. }
  1037. rebuildZOrderLists();
  1038. }
  1039. #if !ASSERT_DISABLED
  1040. class LayerListMutationDetector {
  1041. public:
  1042. LayerListMutationDetector(RenderLayer* layer)
  1043. : m_layer(layer)
  1044. , m_previousMutationAllowedState(layer->layerListMutationAllowed())
  1045. {
  1046. m_layer->setLayerListMutationAllowed(false);
  1047. }
  1048. ~LayerListMutationDetector()
  1049. {
  1050. m_layer->setLayerListMutationAllowed(m_previousMutationAllowedState);
  1051. }
  1052. private:
  1053. RenderLayer* m_layer;
  1054. bool m_previousMutationAllowedState;
  1055. };
  1056. #endif
  1057. void makeMatrixRenderable(TransformationMatrix&, bool has3DRendering);
  1058. } // namespace WebCore
  1059. #ifndef NDEBUG
  1060. // Outside the WebCore namespace for ease of invocation from gdb.
  1061. void showLayerTree(const WebCore::RenderLayer*);
  1062. void showLayerTree(const WebCore::RenderObject*);
  1063. #endif
  1064. #endif // RenderLayer_h