Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 2003, 2006, 2007, 2008 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 RootInlineBox_h
     22 #define RootInlineBox_h
     23 
     24 #include "BidiContext.h"
     25 #include "InlineFlowBox.h"
     26 
     27 namespace WebCore {
     28 
     29 class EllipsisBox;
     30 class HitTestResult;
     31 
     32 struct BidiStatus;
     33 struct GapRects;
     34 
     35 class RootInlineBox : public InlineFlowBox {
     36 public:
     37     RootInlineBox(RenderObject* obj)
     38         : InlineFlowBox(obj)
     39         , m_lineBreakObj(0)
     40         , m_lineBreakPos(0)
     41         , m_lineTop(0)
     42         , m_lineBottom(0)
     43     {
     44     }
     45 
     46     virtual void destroy(RenderArena*);
     47 
     48     virtual bool isRootInlineBox() const { return true; }
     49 
     50     void detachEllipsisBox(RenderArena*);
     51 
     52     RootInlineBox* nextRootBox() const { return static_cast<RootInlineBox*>(m_nextLine); }
     53     RootInlineBox* prevRootBox() const { return static_cast<RootInlineBox*>(m_prevLine); }
     54 
     55     virtual void adjustPosition(int dx, int dy);
     56 
     57     int lineTop() const { return m_lineTop; }
     58     int lineBottom() const { return m_lineBottom; }
     59 
     60     int selectionTop() const;
     61     int selectionBottom() const { return lineBottom(); }
     62     int selectionHeight() const { return max(0, selectionBottom() - selectionTop()); }
     63 
     64     virtual int verticallyAlignBoxes(int heightOfBlock);
     65     void setLineTopBottomPositions(int top, int bottom);
     66 
     67     virtual RenderLineBoxList* rendererLineBoxes() const;
     68 
     69 #if ENABLE(SVG)
     70     virtual void computePerCharacterLayoutInformation() { }
     71 #endif
     72 
     73     RenderObject* lineBreakObj() const { return m_lineBreakObj; }
     74     BidiStatus lineBreakBidiStatus() const;
     75     void setLineBreakInfo(RenderObject*, unsigned breakPos, const BidiStatus&);
     76 
     77     unsigned lineBreakPos() const { return m_lineBreakPos; }
     78     void setLineBreakPos(unsigned p) { m_lineBreakPos = p; }
     79 
     80     int blockHeight() const { return m_blockHeight; }
     81     void setBlockHeight(int h) { m_blockHeight = h; }
     82 
     83     bool endsWithBreak() const { return m_endsWithBreak; }
     84     void setEndsWithBreak(bool b) { m_endsWithBreak = b; }
     85 
     86     void childRemoved(InlineBox* box);
     87 
     88     bool canAccommodateEllipsis(bool ltr, int blockEdge, int lineBoxEdge, int ellipsisWidth);
     89     void placeEllipsis(const AtomicString& ellipsisStr, bool ltr, int blockLeftEdge, int blockRightEdge, int ellipsisWidth, InlineBox* markupBox = 0);
     90     virtual int placeEllipsisBox(bool ltr, int blockLeftEdge, int blockRightEdge, int ellipsisWidth, bool& foundBox);
     91 
     92     EllipsisBox* ellipsisBox() const;
     93 
     94     void paintEllipsisBox(RenderObject::PaintInfo&, int tx, int ty) const;
     95     bool hitTestEllipsisBox(HitTestResult&, int x, int y, int tx, int ty, HitTestAction, bool);
     96 
     97     virtual void clearTruncation();
     98 
     99 #if PLATFORM(MAC)
    100     void addHighlightOverflow();
    101     void paintCustomHighlight(RenderObject::PaintInfo&, int tx, int ty, const AtomicString& highlightType);
    102 #endif
    103 
    104     virtual void paint(RenderObject::PaintInfo&, int tx, int ty);
    105     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int);
    106 
    107     bool hasSelectedChildren() const { return m_hasSelectedChildren; }
    108     void setHasSelectedChildren(bool);
    109 
    110     virtual RenderObject::SelectionState selectionState();
    111     InlineBox* firstSelectedBox();
    112     InlineBox* lastSelectedBox();
    113 
    114     GapRects fillLineSelectionGap(int selTop, int selHeight, RenderBlock* rootBlock, int blockX, int blockY,
    115                                   int tx, int ty, const RenderObject::PaintInfo*);
    116 
    117     RenderBlock* block() const;
    118 
    119     InlineBox* closestLeafChildForXPos(int x, bool onlyEditableLeaves = false);
    120 
    121     Vector<RenderBox*>& floats()
    122     {
    123         ASSERT(!isDirty());
    124         if (!m_floats)
    125             m_floats.set(new Vector<RenderBox*>());
    126         return *m_floats;
    127     }
    128 
    129     Vector<RenderBox*>* floatsPtr() { ASSERT(!isDirty()); return m_floats.get(); }
    130 
    131     virtual void extractLineBoxFromRenderObject();
    132     virtual void attachLineBoxToRenderObject();
    133     virtual void removeLineBoxFromRenderObject();
    134 
    135 protected:
    136     // Where this line ended.  The exact object and the position within that object are stored so that
    137     // we can create an InlineIterator beginning just after the end of this line.
    138     RenderObject* m_lineBreakObj;
    139     unsigned m_lineBreakPos;
    140     RefPtr<BidiContext> m_lineBreakContext;
    141 
    142     int m_lineTop;
    143     int m_lineBottom;
    144 
    145     // Floats hanging off the line are pushed into this vector during layout. It is only
    146     // good for as long as the line has not been marked dirty.
    147     OwnPtr<Vector<RenderBox*> > m_floats;
    148 
    149     // The height of the block at the end of this line.  This is where the next line starts.
    150     int m_blockHeight;
    151 
    152     WTF::Unicode::Direction m_lineBreakBidiStatusEor : 5;
    153     WTF::Unicode::Direction m_lineBreakBidiStatusLastStrong : 5;
    154     WTF::Unicode::Direction m_lineBreakBidiStatusLast : 5;
    155 };
    156 
    157 inline void RootInlineBox::setLineTopBottomPositions(int top, int bottom)
    158 {
    159     m_lineTop = top;
    160     m_lineBottom = bottom;
    161 }
    162 
    163 } // namespace WebCore
    164 
    165 #endif // RootInlineBox_h
    166