#ifndef RENDERTEXT_H
#define RENDERTEXT_H
#include "dom/dom_string.h"
#include "xml/dom_stringimpl.h"
#include "xml/dom_textimpl.h"
#include "rendering/render_object.h"
#include "rendering/render_flow.h"
#include <qptrvector.h>
#include <assert.h>
class QPainter;
class QFontMetrics;
namespace khtml
{
class RenderText;
class RenderStyle;
class TextRun : public InlineBox
{
public:
TextRun(RenderObject* obj)
:InlineBox(obj)
{
m_start = 0;
m_len = 0;
m_reversed = false;
m_toAdd = 0;
}
void detach(RenderArena* renderArena);
void* operator new(size_t sz, RenderArena* renderArena) throw();
void operator delete(void* ptr, size_t sz);
private:
void* operator new(size_t sz) throw();
public:
void setSpaceAdd(int add) { m_width -= m_toAdd; m_toAdd = add; m_width += m_toAdd; }
int spaceAdd() { return m_toAdd; }
virtual bool isTextRun() { return true; }
void paintDecoration( QPainter *pt, int _tx, int _ty, int decoration);
void paintSelection(const Font *f, RenderText *text, QPainter *p, RenderStyle* style, int tx, int ty, int startPos, int endPos);
FindSelectionResult checkSelectionPoint(int _x, int _y, int _tx, int _ty, const Font *f, RenderText *text, int & offset, short lineheight);
bool checkVerticalPoint(int _y, int _ty, int _h)
{ if((_ty + m_y > _y + _h) || (_ty + m_y + m_baseline + height() < _y)) return false; return true; }
int m_start;
unsigned short m_len;
bool m_reversed : 1;
int m_toAdd : 14; private:
TextRun(int _x, int _y)
:InlineBox(0)
{
m_x = _x;
m_y = _y;
m_reversed = false;
};
friend class RenderText;
};
class TextRunArray : public QPtrVector<TextRun>
{
public:
TextRunArray();
TextRun* first();
int findFirstMatching( Item ) const;
virtual int compareItems( Item, Item );
};
class RenderText : public RenderObject
{
friend class TextRun;
public:
RenderText(DOM::NodeImpl* node, DOM::DOMStringImpl *_str);
virtual ~RenderText();
virtual const char *renderName() const { return "RenderText"; }
virtual void setStyle(RenderStyle *style);
virtual void paint(QPainter *, int x, int y, int w, int h,
int tx, int ty, PaintAction paintAction);
virtual void paintObject(QPainter *, int x, int y, int w, int h,
int tx, int ty, PaintAction paintAction);
void deleteRuns(RenderArena *renderArena = 0);
virtual void detach(RenderArena* renderArena);
DOM::DOMString data() const { return str; }
DOM::DOMStringImpl *string() const { return str; }
virtual InlineBox* createInlineBox(bool);
virtual void layout() {assert(false);}
virtual bool nodeAtPoint(NodeInfo& info, int x, int y, int tx, int ty, bool inside = false);
virtual FindSelectionResult checkSelectionPointIgnoringContinuations
(int _x, int _y, int _tx, int _ty, DOM::NodeImpl*& node, int & offset);
unsigned int length() const { return str->l; }
QChar *text() const { return str->s; }
unsigned int stringLength() const { return str->l; } virtual void position(InlineBox* box, int from, int len, bool reverse);
virtual unsigned int width(unsigned int from, unsigned int len, const Font *f) const;
virtual unsigned int width(unsigned int from, unsigned int len, bool firstLine = false) const;
virtual short width() const;
virtual int height() const;
virtual short lineHeight( bool firstLine ) const;
virtual short baselinePosition( bool firstLine ) const;
virtual void calcMinMaxWidth();
virtual short minWidth() const { return m_minWidth; }
virtual short maxWidth() const { return m_maxWidth; }
virtual void trimmedMinMaxWidth(short& beginMinW, bool& beginWS,
short& endMinW, bool& endWS,
bool& hasBreakableChar, bool& hasBreak,
short& beginMaxW, short& endMaxW,
short& minW, short& maxW, bool& stripFrontSpaces);
bool containsOnlyWhitespace(unsigned int from, unsigned int len) const;
int minXPos() const;
virtual int xPos() const;
virtual int yPos() const;
virtual const QFont &font();
virtual short verticalPositionHint( bool firstLine ) const;
bool isFixedWidthFont() const;
void setText(DOM::DOMStringImpl *text, bool force=false);
virtual SelectionState selectionState() const {return m_selectionState;}
virtual void setSelectionState(SelectionState s) {m_selectionState = s; }
virtual void cursorPos(int offset, int &_x, int &_y, int &height);
virtual bool absolutePosition(int &, int &, bool f = false);
void posOfChar(int ch, int &x, int &y);
virtual short marginLeft() const { return style()->marginLeft().minWidth(0); }
virtual short marginRight() const { return style()->marginRight().minWidth(0); }
virtual int rightmostPosition() const;
virtual void repaint(bool immediate=false);
const QFontMetrics &metrics(bool firstLine) const;
const Font *htmlFont(bool firstLine) const;
DOM::TextImpl *element() const
{ return static_cast<DOM::TextImpl*>(RenderObject::element()); }
#if APPLE_CHANGES
TextRunArray textRuns() const { return m_lines; }
int widthFromCache(const Font *, int start, int len) const;
bool shouldUseMonospaceCache(const Font *) const;
void cacheWidths();
bool allAscii() const;
#endif
protected:
void paintTextOutline(QPainter *p, int tx, int ty, const QRect &prevLine, const QRect &thisLine, const QRect &nextLine);
#if APPLE_CHANGES
public:
#endif
TextRun * findTextRun( int offset, int &pos );
protected: TextRunArray m_lines;
DOM::DOMStringImpl *str;
short m_lineHeight;
short m_minWidth;
short m_maxWidth;
short m_beginMinWidth;
short m_endMinWidth;
SelectionState m_selectionState : 3 ;
bool m_hasBreakableChar : 1; bool m_hasBreak : 1; bool m_hasBeginWS : 1; bool m_hasEndWS : 1;
#if APPLE_CHANGES
mutable bool m_allAsciiChecked:1;
mutable bool m_allAscii:1;
int m_monospaceCharacterWidth;
#endif
};
};
#endif