#ifndef RenderText_h
#define RenderText_h
#include "core/rendering/RenderObject.h"
#include "platform/LengthFunctions.h"
#include "platform/text/TextPath.h"
#include "wtf/Forward.h"
#include "wtf/PassRefPtr.h"
namespace WebCore {
class AbstractInlineTextBox;
class InlineTextBox;
class RenderText : public RenderObject {
public:
    
    
    
    RenderText(Node*, PassRefPtr<StringImpl>);
#ifndef NDEBUG
    virtual ~RenderText();
#endif
    virtual const char* renderName() const OVERRIDE;
    virtual bool isTextFragment() const;
    virtual bool isWordBreak() const;
    virtual PassRefPtr<StringImpl> originalText() const;
    void extractTextBox(InlineTextBox*);
    void attachTextBox(InlineTextBox*);
    void removeTextBox(InlineTextBox*);
    const String& text() const { return m_text; }
    virtual unsigned textStartOffset() const { return 0; }
    String plainText() const;
    InlineTextBox* createInlineTextBox();
    void dirtyLineBoxes(bool fullLayout);
    virtual void absoluteRects(Vector<IntRect>&, const LayoutPoint& accumulatedOffset) const OVERRIDE FINAL;
    void absoluteRectsForRange(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = INT_MAX, bool useSelectionHeight = false, bool* wasFixed = 0);
    virtual void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed) const OVERRIDE FINAL;
    void absoluteQuadsForRange(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = INT_MAX, bool useSelectionHeight = false, bool* wasFixed = 0);
    enum ClippingOption { NoClipping, ClipToEllipsis };
    void absoluteQuads(Vector<FloatQuad>&, bool* wasFixed = 0, ClippingOption = NoClipping) const;
    virtual PositionWithAffinity positionForPoint(const LayoutPoint&) OVERRIDE;
    bool is8Bit() const { return m_text.is8Bit(); }
    const LChar* characters8() const { return m_text.impl()->characters8(); }
    const UChar* characters16() const { return m_text.impl()->characters16(); }
    bool hasEmptyText() const { return m_text.isEmpty(); }
    String substring(unsigned position, unsigned length) const { return m_text.substring(position, length); }
    UChar characterAt(unsigned) const;
    UChar uncheckedCharacterAt(unsigned) const;
    UChar operator[](unsigned i) const { return uncheckedCharacterAt(i); }
    unsigned textLength() const { return m_text.length(); } 
    void positionLineBox(InlineBox*);
    virtual float width(unsigned from, unsigned len, const Font&, float xPos, TextDirection, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
    virtual float width(unsigned from, unsigned len, float xPos, TextDirection, bool firstLine = false, HashSet<const SimpleFontData*>* fallbackFonts = 0, GlyphOverflow* = 0) const;
    float minLogicalWidth() const;
    float maxLogicalWidth() const;
    void trimmedPrefWidths(float leadWidth,
        float& firstLineMinWidth, bool& hasBreakableStart,
        float& lastLineMinWidth, bool& hasBreakableEnd,
        bool& hasBreakableChar, bool& hasBreak,
        float& firstLineMaxWidth, float& lastLineMaxWidth,
        float& minWidth, float& maxWidth, bool& stripFrontSpaces,
        TextDirection);
    virtual IntRect linesBoundingBox() const;
    LayoutRect linesVisualOverflowBoundingBox() const;
    FloatPoint firstRunOrigin() const;
    float firstRunX() const;
    float firstRunY() const;
    virtual void setText(PassRefPtr<StringImpl>, bool force = false);
    void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
    virtual void transformText();
    virtual bool canBeSelectionLeaf() const OVERRIDE { return true; }
    virtual void setSelectionState(SelectionState s) OVERRIDE FINAL;
    virtual LayoutRect selectionRectForRepaint(const RenderLayerModelObject* repaintContainer, bool clipToVisibleContent = true) OVERRIDE;
    virtual LayoutRect localCaretRect(InlineBox*, int caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) OVERRIDE;
    LayoutUnit marginLeft() const { return minimumValueForLength(style()->marginLeft(), 0); }
    LayoutUnit marginRight() const { return minimumValueForLength(style()->marginRight(), 0); }
    virtual LayoutRect clippedOverflowRectForRepaint(const RenderLayerModelObject* repaintContainer) const OVERRIDE FINAL;
    InlineTextBox* firstTextBox() const { return m_firstTextBox; }
    InlineTextBox* lastTextBox() const { return m_lastTextBox; }
    virtual int caretMinOffset() const OVERRIDE;
    virtual int caretMaxOffset() const OVERRIDE;
    unsigned renderedTextLength() const;
    virtual int previousOffset(int current) const OVERRIDE FINAL;
    virtual int previousOffsetForBackwardDeletion(int current) const OVERRIDE FINAL;
    virtual int nextOffset(int current) const OVERRIDE FINAL;
    bool containsReversedText() const { return m_containsReversedText; }
    bool isSecure() const { return style()->textSecurity() != TSNONE; }
    void momentarilyRevealLastTypedCharacter(unsigned lastTypedCharacterOffset);
    InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
    void checkConsistency() const;
    bool isAllCollapsibleWhitespace() const;
    bool canUseSimpleFontCodePath() const { return m_canUseSimpleFontCodePath; }
    bool knownToHaveNoOverflowAndNoFallbackFonts() const { return m_knownToHaveNoOverflowAndNoFallbackFonts; }
    void removeAndDestroyTextBoxes();
    PassRefPtr<AbstractInlineTextBox> firstAbstractInlineTextBox();
protected:
    virtual void computePreferredLogicalWidths(float leadWidth);
    virtual void willBeDestroyed() OVERRIDE;
    virtual void styleWillChange(StyleDifference, const RenderStyle&) OVERRIDE FINAL { }
    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
    virtual void setTextInternal(PassRefPtr<StringImpl>);
    virtual UChar previousCharacter() const;
    virtual void addLayerHitTestRects(LayerHitTestRects&, const RenderLayer* currentLayer, const LayoutPoint& layerOffset, const LayoutRect& containerRect) const OVERRIDE;
    virtual InlineTextBox* createTextBox(); 
private:
    void computePreferredLogicalWidths(float leadWidth, HashSet<const SimpleFontData*>& fallbackFonts, GlyphOverflow&);
    bool computeCanUseSimpleFontCodePath() const;
    
    
    
    virtual unsigned length() const OVERRIDE FINAL { return textLength(); }
    virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE FINAL { ASSERT_NOT_REACHED(); }
    virtual void layout() OVERRIDE FINAL { ASSERT_NOT_REACHED(); }
    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation&, const LayoutPoint&, HitTestAction) OVERRIDE FINAL { ASSERT_NOT_REACHED(); return false; }
    void deleteTextBoxes();
    bool containsOnlyWhitespace(unsigned from, unsigned len) const;
    float widthFromCache(const Font&, int start, int len, float xPos, TextDirection, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow*) const;
    bool isAllASCII() const { return m_isAllASCII; }
    void secureText(UChar mask);
    
    bool m_hasBreakableChar : 1; 
    bool m_hasBreak : 1; 
    bool m_hasTab : 1; 
    bool m_hasBreakableStart : 1;
    bool m_hasBreakableEnd : 1;
    bool m_hasEndWhiteSpace : 1;
    bool m_linesDirty : 1; 
                           
                           
                           
    bool m_containsReversedText : 1;
    bool m_isAllASCII : 1;
    bool m_canUseSimpleFontCodePath : 1;
    mutable bool m_knownToHaveNoOverflowAndNoFallbackFonts : 1;
    float m_minWidth;
    float m_maxWidth;
    float m_firstLineMinWidth;
    float m_lastLineLineMinWidth;
    String m_text;
    InlineTextBox* m_firstTextBox;
    InlineTextBox* m_lastTextBox;
};
inline UChar RenderText::uncheckedCharacterAt(unsigned i) const
{
    ASSERT_WITH_SECURITY_IMPLICATION(i < textLength());
    return is8Bit() ? characters8()[i] : characters16()[i];
}
inline UChar RenderText::characterAt(unsigned i) const
{
    if (i >= textLength())
        return 0;
    return uncheckedCharacterAt(i);
}
DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderText, isText());
#ifdef NDEBUG
inline void RenderText::checkConsistency() const
{
}
#endif
void applyTextTransform(const RenderStyle*, String&, UChar);
} 
#endif