WebCore/rendering/InlineBox.h
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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_hasEllipsisBoxOrHyphen(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_hasEllipsisBoxOrHyphen(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(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 isInlineFlowBox() const { return false; }
       
   137     virtual bool isInlineTextBox() const { return false; }
       
   138     virtual bool isRootInlineBox() const { return false; }
       
   139 #if ENABLE(SVG)
       
   140     virtual bool isSVGInlineTextBox() const { return false; }
       
   141     virtual bool isSVGRootInlineBox() const { return false; }
       
   142 
       
   143     bool hasVirtualHeight() const { return m_hasVirtualHeight; }
       
   144     void setHasVirtualHeight() { m_hasVirtualHeight = true; }
       
   145     virtual int virtualHeight() const
       
   146     {
       
   147         ASSERT_NOT_REACHED();
       
   148         return 0;
       
   149     }
       
   150 #endif
       
   151 
       
   152     virtual IntRect calculateBoundaries() const
       
   153     {
       
   154         ASSERT_NOT_REACHED();
       
   155         return IntRect();
       
   156     }
       
   157 
       
   158     bool isConstructed() { return m_constructed; }
       
   159     virtual void setConstructed()
       
   160     {
       
   161         m_constructed = true;
       
   162         if (m_next)
       
   163             m_next->setConstructed();
       
   164     }
       
   165 
       
   166     void setExtracted(bool b = true) { m_extracted = b; }
       
   167     
       
   168     void setFirstLineStyleBit(bool f) { m_firstLine = f; }
       
   169     bool isFirstLineStyle() const { return m_firstLine; }
       
   170 
       
   171     void remove();
       
   172 
       
   173     InlineBox* nextOnLine() const { return m_next; }
       
   174     InlineBox* prevOnLine() const { return m_prev; }
       
   175     void setNextOnLine(InlineBox* next)
       
   176     {
       
   177         ASSERT(m_parent || !next);
       
   178         m_next = next;
       
   179     }
       
   180     void setPrevOnLine(InlineBox* prev)
       
   181     {
       
   182         ASSERT(m_parent || !prev);
       
   183         m_prev = prev;
       
   184     }
       
   185     bool nextOnLineExists() const;
       
   186     bool prevOnLineExists() const;
       
   187 
       
   188     virtual bool isLeaf() const { return true; }
       
   189     
       
   190     InlineBox* nextLeafChild() const;
       
   191     InlineBox* prevLeafChild() const;
       
   192         
       
   193     RenderObject* renderer() const { return m_renderer; }
       
   194 
       
   195     InlineFlowBox* parent() const
       
   196     {
       
   197         ASSERT(!m_hasBadParent);
       
   198         return m_parent;
       
   199     }
       
   200     void setParent(InlineFlowBox* par) { m_parent = par; }
       
   201 
       
   202     const RootInlineBox* root() const;
       
   203     RootInlineBox* root();
       
   204 
       
   205     void setWidth(int w) { m_width = w; }
       
   206     int width() const { return m_width; }
       
   207 
       
   208     // x() is the left side of the box in the parent's coordinate system.
       
   209     void setX(int x) { m_x = x; }
       
   210     int x() const { return m_x; }
       
   211 
       
   212     // y() is the top of the box in the parent's coordinate system.
       
   213     void setY(int y) { m_y = y; }
       
   214     int y() const { return m_y; }
       
   215 
       
   216     int height() const;
       
   217 
       
   218     inline int baselinePosition(bool isRootLineBox) const { return renderer()->baselinePosition(m_firstLine, isRootLineBox); }
       
   219     inline int lineHeight(bool isRootLineBox) const { return renderer()->lineHeight(m_firstLine, isRootLineBox); }
       
   220 
       
   221     virtual int caretMinOffset() const;
       
   222     virtual int caretMaxOffset() const;
       
   223     virtual unsigned caretMaxRenderedOffset() const;
       
   224 
       
   225     unsigned char bidiLevel() const { return m_bidiEmbeddingLevel; }
       
   226     void setBidiLevel(unsigned char level) { m_bidiEmbeddingLevel = level; }
       
   227     TextDirection direction() const { return m_bidiEmbeddingLevel % 2 ? RTL : LTR; }
       
   228     int caretLeftmostOffset() const { return direction() == LTR ? caretMinOffset() : caretMaxOffset(); }
       
   229     int caretRightmostOffset() const { return direction() == LTR ? caretMaxOffset() : caretMinOffset(); }
       
   230 
       
   231     virtual void clearTruncation() { }
       
   232 
       
   233     bool isDirty() const { return m_dirty; }
       
   234     void markDirty(bool dirty = true) { m_dirty = dirty; }
       
   235 
       
   236     void dirtyLineBoxes();
       
   237     
       
   238     virtual RenderObject::SelectionState selectionState();
       
   239 
       
   240     virtual bool canAccommodateEllipsis(bool ltr, int blockEdge, int ellipsisWidth);
       
   241     // visibleLeftEdge, visibleRightEdge are in the parent's coordinate system.
       
   242     virtual int placeEllipsisBox(bool ltr, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool&);
       
   243 
       
   244     void setHasBadParent();
       
   245 
       
   246     int toAdd() const { return m_toAdd; }
       
   247     
       
   248     bool visibleToHitTesting() const { return renderer()->style()->visibility() == VISIBLE && renderer()->style()->pointerEvents() != PE_NONE; }
       
   249     
       
   250     // Use with caution! The type is not checked!
       
   251     RenderBoxModelObject* boxModelObject() const
       
   252     { 
       
   253         if (!m_renderer->isText())
       
   254             return toRenderBoxModelObject(m_renderer);
       
   255         return 0;
       
   256     }
       
   257 
       
   258 private:
       
   259     InlineBox* m_next; // The next element on the same line as us.
       
   260     InlineBox* m_prev; // The previous element on the same line as us.
       
   261 
       
   262     InlineFlowBox* m_parent; // The box that contains us.
       
   263 
       
   264 public:
       
   265     RenderObject* m_renderer;
       
   266 
       
   267     int m_x;
       
   268     int m_y;
       
   269     int m_width;
       
   270     
       
   271     // Some of these bits are actually for subclasses and moved here to compact the structures.
       
   272 
       
   273     // for this class
       
   274 protected:
       
   275     bool m_firstLine : 1;
       
   276 private:
       
   277     bool m_constructed : 1;
       
   278     unsigned char m_bidiEmbeddingLevel : 6;
       
   279 protected:
       
   280     bool m_dirty : 1;
       
   281     bool m_extracted : 1;
       
   282     bool m_hasVirtualHeight : 1;
       
   283 
       
   284     // for RootInlineBox
       
   285     bool m_endsWithBreak : 1;  // Whether the line ends with a <br>.
       
   286     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).
       
   287     bool m_hasEllipsisBoxOrHyphen : 1; 
       
   288 
       
   289     // for InlineTextBox
       
   290 public:
       
   291     bool m_dirOverride : 1;
       
   292     bool m_isText : 1; // Whether or not this object represents text with a non-zero height. Includes non-image list markers, text boxes.
       
   293 protected:
       
   294     mutable bool m_determinedIfNextOnLineExists : 1;
       
   295     mutable bool m_determinedIfPrevOnLineExists : 1;
       
   296     mutable bool m_nextOnLineExists : 1;
       
   297     mutable bool m_prevOnLineExists : 1;
       
   298     int m_toAdd : 12; // for justified text
       
   299 
       
   300 #ifndef NDEBUG
       
   301 private:
       
   302     bool m_hasBadParent;
       
   303 #endif
       
   304 };
       
   305 
       
   306 #ifdef NDEBUG
       
   307 inline InlineBox::~InlineBox()
       
   308 {
       
   309 }
       
   310 #endif
       
   311 
       
   312 inline void InlineBox::setHasBadParent()
       
   313 {
       
   314 #ifndef NDEBUG
       
   315     m_hasBadParent = true;
       
   316 #endif
       
   317 }
       
   318 
       
   319 } // namespace WebCore
       
   320 
       
   321 #ifndef NDEBUG
       
   322 // Outside the WebCore namespace for ease of invocation from gdb.
       
   323 void showTree(const WebCore::InlineBox*);
       
   324 #endif
       
   325 
       
   326 #endif // InlineBox_h