RenderInline.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*
  2. * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
  3. * (C) 1999 Antti Koivisto (koivisto@kde.org)
  4. * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Library General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Library General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Library General Public License
  17. * along with this library; see the file COPYING.LIB. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. *
  21. */
  22. #ifndef RenderInline_h
  23. #define RenderInline_h
  24. #include "InlineFlowBox.h"
  25. #include "RenderBoxModelObject.h"
  26. #include "RenderLineBoxList.h"
  27. namespace WebCore {
  28. class Position;
  29. class RenderInline : public RenderBoxModelObject {
  30. public:
  31. explicit RenderInline(Element*);
  32. static RenderInline* createAnonymous(Document*);
  33. RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); }
  34. RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); }
  35. virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
  36. Element* node() const { return toElement(RenderBoxModelObject::node()); }
  37. virtual LayoutUnit marginLeft() const;
  38. virtual LayoutUnit marginRight() const;
  39. virtual LayoutUnit marginTop() const;
  40. virtual LayoutUnit marginBottom() const;
  41. virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const;
  42. virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const;
  43. virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const;
  44. virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const;
  45. virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const;
  46. virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const;
  47. virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const;
  48. IntRect linesBoundingBox() const;
  49. LayoutRect linesVisualOverflowBoundingBox() const;
  50. InlineFlowBox* createAndAppendInlineFlowBox();
  51. void dirtyLineBoxes(bool fullLayout);
  52. void deleteLineBoxTree();
  53. RenderLineBoxList* lineBoxes() { return &m_lineBoxes; }
  54. const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; }
  55. InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); }
  56. InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); }
  57. InlineBox* firstLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? firstLineBox() : culledInlineFirstLineBox(); }
  58. InlineBox* lastLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? lastLineBox() : culledInlineLastLineBox(); }
  59. virtual RenderBoxModelObject* virtualContinuation() const { return continuation(); }
  60. RenderInline* inlineElementContinuation() const;
  61. virtual void updateDragState(bool dragOn);
  62. LayoutSize offsetForInFlowPositionedInline(const RenderBox* child) const;
  63. virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&);
  64. void paintOutline(GraphicsContext*, const LayoutPoint&);
  65. using RenderBoxModelObject::continuation;
  66. using RenderBoxModelObject::setContinuation;
  67. bool alwaysCreateLineBoxes() const { return m_alwaysCreateLineBoxes; }
  68. void setAlwaysCreateLineBoxes() { m_alwaysCreateLineBoxes = true; }
  69. void updateAlwaysCreateLineBoxes(bool fullLayout);
  70. virtual LayoutRect localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine) OVERRIDE;
  71. bool hitTestCulledInline(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset);
  72. protected:
  73. virtual void willBeDestroyed();
  74. virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
  75. private:
  76. virtual RenderObjectChildList* virtualChildren() { return children(); }
  77. virtual const RenderObjectChildList* virtualChildren() const { return children(); }
  78. const RenderObjectChildList* children() const { return &m_children; }
  79. RenderObjectChildList* children() { return &m_children; }
  80. virtual const char* renderName() const;
  81. virtual bool isRenderInline() const { return true; }
  82. LayoutRect culledInlineVisualOverflowBoundingBox() const;
  83. InlineBox* culledInlineFirstLineBox() const;
  84. InlineBox* culledInlineLastLineBox() const;
  85. template<typename GeneratorContext>
  86. void generateLineBoxRects(GeneratorContext& yield) const;
  87. template<typename GeneratorContext>
  88. void generateCulledLineBoxRects(GeneratorContext& yield, const RenderInline* container) const;
  89. void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild);
  90. virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0);
  91. void splitInlines(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock,
  92. RenderObject* beforeChild, RenderBoxModelObject* oldCont);
  93. void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox,
  94. RenderObject* newChild, RenderBoxModelObject* oldCont);
  95. virtual void layout() { ASSERT_NOT_REACHED(); } // Do nothing for layout()
  96. virtual void paint(PaintInfo&, const LayoutPoint&);
  97. virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
  98. virtual bool requiresLayer() const { return isInFlowPositioned() || createsGroup() || hasClipPath(); }
  99. virtual LayoutUnit offsetLeft() const;
  100. virtual LayoutUnit offsetTop() const;
  101. virtual LayoutUnit offsetWidth() const { return linesBoundingBox().width(); }
  102. virtual LayoutUnit offsetHeight() const { return linesBoundingBox().height(); }
  103. virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE;
  104. virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE;
  105. virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed) const OVERRIDE;
  106. virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE;
  107. virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE;
  108. virtual VisiblePosition positionForPoint(const LayoutPoint&);
  109. virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE { return linesBoundingBox(); }
  110. virtual IntRect borderBoundingBox() const
  111. {
  112. IntRect boundingBox = linesBoundingBox();
  113. return IntRect(0, 0, boundingBox.width(), boundingBox.height());
  114. }
  115. virtual InlineFlowBox* createInlineFlowBox(); // Subclassed by SVG and Ruby
  116. virtual void dirtyLinesFromChangedChild(RenderObject* child) { m_lineBoxes.dirtyLinesFromChangedChild(this, child); }
  117. virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
  118. virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
  119. virtual void childBecameNonInline(RenderObject* child);
  120. virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&);
  121. virtual void imageChanged(WrappedImagePtr, const IntRect* = 0);
  122. #if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION)
  123. virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&);
  124. #endif
  125. virtual void updateFromStyle() OVERRIDE;
  126. RenderInline* clone() const;
  127. void paintOutlineForLine(GraphicsContext*, const LayoutPoint&, const LayoutRect& prevLine, const LayoutRect& thisLine,
  128. const LayoutRect& nextLine, const Color);
  129. RenderBoxModelObject* continuationBefore(RenderObject* beforeChild);
  130. RenderObjectChildList m_children;
  131. RenderLineBoxList m_lineBoxes; // All of the line boxes created for this inline flow. For example, <i>Hello<br>world.</i> will have two <i> line boxes.
  132. bool m_alwaysCreateLineBoxes : 1;
  133. };
  134. inline RenderInline* toRenderInline(RenderObject* object)
  135. {
  136. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderInline());
  137. return static_cast<RenderInline*>(object);
  138. }
  139. inline const RenderInline* toRenderInline(const RenderObject* object)
  140. {
  141. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderInline());
  142. return static_cast<const RenderInline*>(object);
  143. }
  144. // This will catch anyone doing an unnecessary cast.
  145. void toRenderInline(const RenderInline*);
  146. } // namespace WebCore
  147. #endif // RenderInline_h