1 /* 2 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21 #ifndef InlineBox_h 22 #define InlineBox_h 23 24 #include "RenderBoxModelObject.h" 25 #include "TextDirection.h" 26 27 namespace WebCore { 28 29 class HitTestRequest; 30 class HitTestResult; 31 class RootInlineBox; 32 33 34 // InlineBox represents a rectangle that occurs on a line. It corresponds to 35 // some RenderObject (i.e., it represents a portion of that RenderObject). 36 class InlineBox { 37 public: 38 InlineBox(RenderObject* obj) 39 : m_next(0) 40 , m_prev(0) 41 , m_parent(0) 42 , m_renderer(obj) 43 , m_x(0) 44 , m_y(0) 45 , m_width(0) 46 , m_firstLine(false) 47 , m_constructed(false) 48 , m_bidiEmbeddingLevel(0) 49 , m_dirty(false) 50 , m_extracted(false) 51 #if ENABLE(SVG) 52 , m_hasVirtualHeight(false) 53 #endif 54 , m_endsWithBreak(false) 55 , m_hasSelectedChildren(false) 56 , m_hasEllipsisBox(false) 57 , m_dirOverride(false) 58 , m_isText(false) 59 , m_determinedIfNextOnLineExists(false) 60 , m_determinedIfPrevOnLineExists(false) 61 , m_nextOnLineExists(false) 62 , m_prevOnLineExists(false) 63 , m_toAdd(0) 64 #ifndef NDEBUG 65 , m_hasBadParent(false) 66 #endif 67 { 68 } 69 70 InlineBox(RenderObject* obj, int x, int y, int width, bool firstLine, bool constructed, 71 bool dirty, bool extracted, InlineBox* next, InlineBox* prev, InlineFlowBox* parent) 72 : m_next(next) 73 , m_prev(prev) 74 , m_parent(parent) 75 , m_renderer(obj) 76 , m_x(x) 77 , m_y(y) 78 , m_width(width) 79 , m_firstLine(firstLine) 80 , m_constructed(constructed) 81 , m_bidiEmbeddingLevel(0) 82 , m_dirty(dirty) 83 , m_extracted(extracted) 84 #if ENABLE(SVG) 85 , m_hasVirtualHeight(false) 86 #endif 87 , m_endsWithBreak(false) 88 , m_hasSelectedChildren(false) 89 , m_hasEllipsisBox(false) 90 , m_dirOverride(false) 91 , m_isText(false) 92 , m_determinedIfNextOnLineExists(false) 93 , m_determinedIfPrevOnLineExists(false) 94 , m_nextOnLineExists(false) 95 , m_prevOnLineExists(false) 96 , m_toAdd(0) 97 #ifndef NDEBUG 98 , m_hasBadParent(false) 99 #endif 100 { 101 } 102 103 virtual ~InlineBox(); 104 105 virtual void destroy(RenderArena*); 106 107 virtual void deleteLine(RenderArena*); 108 virtual void extractLine(); 109 virtual void attachLine(); 110 111 virtual bool isLineBreak() const { return false; } 112 113 virtual void adjustPosition(int dx, int dy); 114 115 virtual void paint(RenderObject::PaintInfo&, int tx, int ty); 116 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty); 117 118 // Overloaded new operator. 119 void* operator new(size_t, RenderArena*) throw(); 120 121 // Overridden to prevent the normal delete from being called. 122 void operator delete(void*, size_t); 123 124 private: 125 // The normal operator new is disallowed. 126 void* operator new(size_t) throw(); 127 128 public: 129 #ifndef NDEBUG 130 void showTreeForThis() const; 131 #endif 132 133 bool isText() const { return m_isText; } 134 void setIsText(bool b) { m_isText = b; } 135 136 virtual bool isInlineBox() { return false; } 137 virtual bool isInlineFlowBox() const { return false; } 138 virtual bool isInlineTextBox() { return false; } 139 virtual bool isRootInlineBox() const { return false; } 140 #if ENABLE(SVG) 141 virtual bool isSVGRootInlineBox() { return false; } 142 143 bool hasVirtualHeight() const { return m_hasVirtualHeight; } 144 void setHasVirtualHeight() { m_hasVirtualHeight = true; } 145 virtual int virtualHeight() const { ASSERT_NOT_REACHED(); return 0; } 146 #endif 147 148 bool isConstructed() { return m_constructed; } 149 virtual void setConstructed() 150 { 151 m_constructed = true; 152 if (m_next) 153 m_next->setConstructed(); 154 } 155 156 void setExtracted(bool b = true) { m_extracted = b; } 157 158 void setFirstLineStyleBit(bool f) { m_firstLine = f; } 159 bool isFirstLineStyle() const { return m_firstLine; } 160 161 void remove(); 162 163 InlineBox* nextOnLine() const { return m_next; } 164 InlineBox* prevOnLine() const { return m_prev; } 165 void setNextOnLine(InlineBox* next) 166 { 167 ASSERT(m_parent || !next); 168 m_next = next; 169 } 170 void setPrevOnLine(InlineBox* prev) 171 { 172 ASSERT(m_parent || !prev); 173 m_prev = prev; 174 } 175 bool nextOnLineExists() const; 176 bool prevOnLineExists() const; 177 178 virtual bool isLeaf() const { return true; } 179 180 InlineBox* nextLeafChild() const; 181 InlineBox* prevLeafChild() const; 182 183 RenderObject* renderer() const { return m_renderer; } 184 185 InlineFlowBox* parent() const 186 { 187 ASSERT(!m_hasBadParent); 188 return m_parent; 189 } 190 void setParent(InlineFlowBox* par) { m_parent = par; } 191 192 const RootInlineBox* root() const; 193 RootInlineBox* root(); 194 195 void setWidth(int w) { m_width = w; } 196 int width() const { return m_width; } 197 198 // x() is the left side of the box in the parent's coordinate system. 199 void setX(int x) { m_x = x; } 200 int x() const { return m_x; } 201 202 // y() is the top of the box in the parent's coordinate system. 203 void setY(int y) { m_y = y; } 204 int y() const { return m_y; } 205 206 int height() const; 207 208 inline int baselinePosition(bool isRootLineBox) const { return renderer()->baselinePosition(m_firstLine, isRootLineBox); } 209 inline int lineHeight(bool isRootLineBox) const { return renderer()->lineHeight(m_firstLine, isRootLineBox); } 210 211 virtual int caretMinOffset() const; 212 virtual int caretMaxOffset() const; 213 virtual unsigned caretMaxRenderedOffset() const; 214 215 unsigned char bidiLevel() const { return m_bidiEmbeddingLevel; } 216 void setBidiLevel(unsigned char level) { m_bidiEmbeddingLevel = level; } 217 TextDirection direction() const { return m_bidiEmbeddingLevel % 2 ? RTL : LTR; } 218 int caretLeftmostOffset() const { return direction() == LTR ? caretMinOffset() : caretMaxOffset(); } 219 int caretRightmostOffset() const { return direction() == LTR ? caretMaxOffset() : caretMinOffset(); } 220 221 virtual void clearTruncation() { } 222 223 bool isDirty() const { return m_dirty; } 224 void markDirty(bool dirty = true) { m_dirty = dirty; } 225 226 void dirtyLineBoxes(); 227 228 virtual RenderObject::SelectionState selectionState(); 229 230 virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth); 231 // visibleLeftEdge, visibleRightEdge are in the parent's coordinate system. 232 virtual int placeEllipsisBox(bool ltr, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool&); 233 234 void setHasBadParent(); 235 236 int toAdd() const { return m_toAdd; } 237 238 bool visibleToHitTesting() const { return renderer()->style()->visibility() == VISIBLE && renderer()->style()->pointerEvents() != PE_NONE; } 239 240 // Use with caution! The type is not checked! 241 RenderBoxModelObject* boxModelObject() const 242 { 243 if (!m_renderer->isText()) 244 return toRenderBoxModelObject(m_renderer); 245 return 0; 246 } 247 248 private: 249 InlineBox* m_next; // The next element on the same line as us. 250 InlineBox* m_prev; // The previous element on the same line as us. 251 252 InlineFlowBox* m_parent; // The box that contains us. 253 254 public: 255 RenderObject* m_renderer; 256 257 int m_x; 258 int m_y; 259 int m_width; 260 261 // Some of these bits are actually for subclasses and moved here to compact the structures. 262 263 // for this class 264 protected: 265 bool m_firstLine : 1; 266 private: 267 bool m_constructed : 1; 268 unsigned char m_bidiEmbeddingLevel : 6; 269 protected: 270 bool m_dirty : 1; 271 bool m_extracted : 1; 272 bool m_hasVirtualHeight : 1; 273 274 // for RootInlineBox 275 bool m_endsWithBreak : 1; // Whether the line ends with a <br>. 276 bool m_hasSelectedChildren : 1; // Whether we have any children selected (this bit will also be set if the <br> that terminates our line is selected). 277 bool m_hasEllipsisBox : 1; 278 279 // for InlineTextBox 280 public: 281 bool m_dirOverride : 1; 282 bool m_isText : 1; // Whether or not this object represents text with a non-zero height. Includes non-image list markers, text boxes. 283 protected: 284 mutable bool m_determinedIfNextOnLineExists : 1; 285 mutable bool m_determinedIfPrevOnLineExists : 1; 286 mutable bool m_nextOnLineExists : 1; 287 mutable bool m_prevOnLineExists : 1; 288 int m_toAdd : 12; // for justified text 289 290 #ifndef NDEBUG 291 private: 292 bool m_hasBadParent; 293 #endif 294 }; 295 296 #ifdef NDEBUG 297 inline InlineBox::~InlineBox() 298 { 299 } 300 #endif 301 302 inline void InlineBox::setHasBadParent() 303 { 304 #ifndef NDEBUG 305 m_hasBadParent = true; 306 #endif 307 } 308 309 } // namespace WebCore 310 311 #ifndef NDEBUG 312 // Outside the WebCore namespace for ease of invocation from gdb. 313 void showTree(const WebCore::InlineBox*); 314 #endif 315 316 #endif // InlineBox_h 317