2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef InlineTextBox_h
24 #define InlineTextBox_h
26 #include "InlineBox.h"
27 #include "RenderText.h" // so textRenderer() can be inline
31 struct CompositionUnderline;
33 const unsigned short cNoTruncation = USHRT_MAX;
34 const unsigned short cFullTruncation = USHRT_MAX - 1;
36 // Helper functions shared by InlineTextBox / SVGRootInlineBox
37 void updateGraphicsContext(GraphicsContext*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);
38 Color correctedTextColor(Color textColor, Color backgroundColor);
40 class InlineTextBox : public InlineBox {
42 InlineTextBox(RenderObject* obj)
48 , m_truncation(cNoTruncation)
52 InlineTextBox* prevTextBox() const { return m_prevTextBox; }
53 InlineTextBox* nextTextBox() const { return m_nextTextBox; }
54 void setNextTextBox(InlineTextBox* n) { m_nextTextBox = n; }
55 void setPreviousTextBox(InlineTextBox* p) { m_prevTextBox = p; }
57 unsigned start() const { return m_start; }
58 unsigned end() const { return m_len ? m_start + m_len - 1 : m_start; }
59 unsigned len() const { return m_len; }
61 void setStart(unsigned start) { m_start = start; }
62 void setLen(unsigned len) { m_len = len; }
64 void offsetRun(int d) { m_start += d; }
66 unsigned short truncation() { return m_truncation; }
68 bool hasHyphen() const { return m_hasEllipsisBoxOrHyphen; }
69 void setHasHyphen(bool hasHyphen) { m_hasEllipsisBoxOrHyphen = hasHyphen; }
70 static inline bool compareByStart(const InlineTextBox* first, const InlineTextBox* second) { return first->start() < second->start(); }
73 virtual int selectionTop();
74 virtual int selectionHeight();
77 virtual IntRect calculateBoundaries() const { return IntRect(x(), y(), logicalWidth(), logicalHeight()); }
79 virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos);
80 bool isSelected(int startPos, int endPos) const;
81 virtual void selectionStartEnd(int& sPos, int& ePos);
84 virtual void paint(PaintInfo&, int tx, int ty);
85 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
88 RenderText* textRenderer() const;
91 virtual void deleteLine(RenderArena*);
92 virtual void extractLine();
93 virtual void attachLine();
96 virtual RenderObject::SelectionState selectionState();
99 virtual void clearTruncation() { m_truncation = cNoTruncation; }
100 virtual int placeEllipsisBox(bool flowIsLTR, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool& foundBox);
103 virtual bool isLineBreak() const;
105 void setSpaceAdd(int add) { m_logicalWidth -= m_toAdd; m_toAdd = add; m_logicalWidth += m_toAdd; }
108 virtual bool isInlineTextBox() const { return true; }
111 virtual int caretMinOffset() const;
112 virtual int caretMaxOffset() const;
115 virtual unsigned caretMaxRenderedOffset() const;
120 virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const;
121 virtual int positionForOffset(int offset) const;
123 bool containsCaretOffset(int offset) const; // false for offset after line break
125 // Needs to be public, so the static paintTextWithShadows() function can use it.
126 static FloatSize applyShadowToGraphicsContext(GraphicsContext*, const ShadowData*, const FloatRect& textRect, bool stroked, bool opaque);
129 InlineTextBox* m_prevTextBox; // The previous box that also uses our RenderObject
130 InlineTextBox* m_nextTextBox; // The next box that also uses our RenderObject
133 unsigned short m_len;
135 unsigned short m_truncation; // Where to truncate when text overflow is applied. We use special constants to
136 // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
139 void paintCompositionBackground(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, int startPos, int endPos);
140 void paintDocumentMarkers(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, bool background);
141 void paintCompositionUnderline(GraphicsContext*, int tx, int ty, const CompositionUnderline&);
143 void paintCustomHighlight(int tx, int ty, const AtomicString& type);
147 void paintDecoration(GraphicsContext*, int tx, int ty, int decoration, const ShadowData*);
148 void paintSelection(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&);
149 void paintSpellingOrGrammarMarker(GraphicsContext*, int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&, bool grammar);
150 void paintTextMatchMarker(GraphicsContext*, int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&);
151 void computeRectForReplacementMarker(int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&);
154 inline RenderText* InlineTextBox::textRenderer() const
156 return toRenderText(renderer());
159 } // namespace WebCore
161 #endif // InlineTextBox_h