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 23#ifndef RenderInline_h 24#define RenderInline_h 25 26#include "InlineFlowBox.h" 27#include "RenderBoxModelObject.h" 28#include "RenderLineBoxList.h" 29 30namespace WebCore { 31 32class Position; 33 34class RenderInline : public RenderBoxModelObject { 35public: 36 explicit RenderInline(Element*); 37 38 static RenderInline* createAnonymous(Document*); 39 40 RenderObject* firstChild() const { ASSERT(children() == virtualChildren()); return children()->firstChild(); } 41 RenderObject* lastChild() const { ASSERT(children() == virtualChildren()); return children()->lastChild(); } 42 43 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0); 44 45 Element* node() const { return toElement(RenderBoxModelObject::node()); } 46 47 virtual LayoutUnit marginLeft() const; 48 virtual LayoutUnit marginRight() const; 49 virtual LayoutUnit marginTop() const; 50 virtual LayoutUnit marginBottom() const; 51 virtual LayoutUnit marginBefore(const RenderStyle* otherStyle = 0) const; 52 virtual LayoutUnit marginAfter(const RenderStyle* otherStyle = 0) const; 53 virtual LayoutUnit marginStart(const RenderStyle* otherStyle = 0) const; 54 virtual LayoutUnit marginEnd(const RenderStyle* otherStyle = 0) const; 55 56 virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const; 57 virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const; 58 59 virtual LayoutSize offsetFromContainer(RenderObject*, const LayoutPoint&, bool* offsetDependsOnPoint = 0) const; 60 61 IntRect linesBoundingBox() const; 62 LayoutRect linesVisualOverflowBoundingBox() const; 63 64 InlineFlowBox* createAndAppendInlineFlowBox(); 65 66 void dirtyLineBoxes(bool fullLayout); 67 void deleteLineBoxTree(); 68 69 RenderLineBoxList* lineBoxes() { return &m_lineBoxes; } 70 const RenderLineBoxList* lineBoxes() const { return &m_lineBoxes; } 71 72 InlineFlowBox* firstLineBox() const { return m_lineBoxes.firstLineBox(); } 73 InlineFlowBox* lastLineBox() const { return m_lineBoxes.lastLineBox(); } 74 InlineBox* firstLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? firstLineBox() : culledInlineFirstLineBox(); } 75 InlineBox* lastLineBoxIncludingCulling() const { return alwaysCreateLineBoxes() ? lastLineBox() : culledInlineLastLineBox(); } 76 77 virtual RenderBoxModelObject* virtualContinuation() const { return continuation(); } 78 RenderInline* inlineElementContinuation() const; 79 80 virtual void updateDragState(bool dragOn); 81 82 LayoutSize offsetForInFlowPositionedInline(const RenderBox* child) const; 83 84 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint&); 85 void paintOutline(GraphicsContext*, const LayoutPoint&); 86 87 using RenderBoxModelObject::continuation; 88 using RenderBoxModelObject::setContinuation; 89 90 bool alwaysCreateLineBoxes() const { return m_alwaysCreateLineBoxes; } 91 void setAlwaysCreateLineBoxes() { m_alwaysCreateLineBoxes = true; } 92 void updateAlwaysCreateLineBoxes(bool fullLayout); 93 94 virtual LayoutRect localCaretRect(InlineBox*, int, LayoutUnit* extraWidthToEndOfLine) OVERRIDE; 95 96 bool hitTestCulledInline(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset); 97 98protected: 99 virtual void willBeDestroyed(); 100 101 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE; 102 103private: 104 virtual RenderObjectChildList* virtualChildren() { return children(); } 105 virtual const RenderObjectChildList* virtualChildren() const { return children(); } 106 const RenderObjectChildList* children() const { return &m_children; } 107 RenderObjectChildList* children() { return &m_children; } 108 109 virtual const char* renderName() const; 110 111 virtual bool isRenderInline() const { return true; } 112 113 LayoutRect culledInlineVisualOverflowBoundingBox() const; 114 InlineBox* culledInlineFirstLineBox() const; 115 InlineBox* culledInlineLastLineBox() const; 116 117 template<typename GeneratorContext> 118 void generateLineBoxRects(GeneratorContext& yield) const; 119 template<typename GeneratorContext> 120 void generateCulledLineBoxRects(GeneratorContext& yield, const RenderInline* container) const; 121 122 void addChildToContinuation(RenderObject* newChild, RenderObject* beforeChild); 123 virtual void addChildIgnoringContinuation(RenderObject* newChild, RenderObject* beforeChild = 0); 124 125 void splitInlines(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock, 126 RenderObject* beforeChild, RenderBoxModelObject* oldCont); 127 void splitFlow(RenderObject* beforeChild, RenderBlock* newBlockBox, 128 RenderObject* newChild, RenderBoxModelObject* oldCont); 129 130 virtual void layout() { ASSERT_NOT_REACHED(); } // Do nothing for layout() 131 132 virtual void paint(PaintInfo&, const LayoutPoint&); 133 134 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE; 135 136 virtual bool requiresLayer() const { return isInFlowPositioned() || createsGroup() || hasClipPath(); } 137 138 virtual LayoutUnit offsetLeft() const; 139 virtual LayoutUnit offsetTop() const; 140 virtual LayoutUnit offsetWidth() const { return linesBoundingBox().width(); } 141 virtual LayoutUnit offsetHeight() const { return linesBoundingBox().height(); } 142 143 virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE; 144 virtual LayoutRect rectWithOutlineForRepaint(const RenderLayerModelObject* repaintContainer, LayoutUnit outlineWidth) const OVERRIDE; 145 virtual void computeRectForRepaint(const RenderLayerModelObject* repaintContainer, LayoutRect&, bool fixed) const OVERRIDE; 146 147 virtual void mapLocalToContainer(const RenderLayerModelObject* repaintContainer, TransformState&, MapCoordinatesFlags = ApplyContainerFlip, bool* wasFixed = 0) const OVERRIDE; 148 virtual const RenderObject* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const OVERRIDE; 149 150 virtual VisiblePosition positionForPoint(const LayoutPoint&); 151 152 virtual LayoutRect frameRectForStickyPositioning() const OVERRIDE { return linesBoundingBox(); } 153 154 virtual IntRect borderBoundingBox() const 155 { 156 IntRect boundingBox = linesBoundingBox(); 157 return IntRect(0, 0, boundingBox.width(), boundingBox.height()); 158 } 159 160 virtual InlineFlowBox* createInlineFlowBox(); // Subclassed by SVG and Ruby 161 162 virtual void dirtyLinesFromChangedChild(RenderObject* child) { m_lineBoxes.dirtyLinesFromChangedChild(this, child); } 163 164 virtual LayoutUnit lineHeight(bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; 165 virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const; 166 167 virtual void childBecameNonInline(RenderObject* child); 168 169 virtual void updateHitTestResult(HitTestResult&, const LayoutPoint&); 170 171 virtual void imageChanged(WrappedImagePtr, const IntRect* = 0); 172 173#if ENABLE(DASHBOARD_SUPPORT) || ENABLE(DRAGGABLE_REGION) 174 virtual void addAnnotatedRegions(Vector<AnnotatedRegionValue>&); 175#endif 176 177 virtual void updateFromStyle() OVERRIDE; 178 179 RenderInline* clone() const; 180 181 void paintOutlineForLine(GraphicsContext*, const LayoutPoint&, const LayoutRect& prevLine, const LayoutRect& thisLine, 182 const LayoutRect& nextLine, const Color); 183 RenderBoxModelObject* continuationBefore(RenderObject* beforeChild); 184 185 RenderObjectChildList m_children; 186 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. 187 188 bool m_alwaysCreateLineBoxes : 1; 189}; 190 191inline RenderInline* toRenderInline(RenderObject* object) 192{ 193 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderInline()); 194 return static_cast<RenderInline*>(object); 195} 196 197inline const RenderInline* toRenderInline(const RenderObject* object) 198{ 199 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isRenderInline()); 200 return static_cast<const RenderInline*>(object); 201} 202 203// This will catch anyone doing an unnecessary cast. 204void toRenderInline(const RenderInline*); 205 206} // namespace WebCore 207 208#endif // RenderInline_h 209