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 "InlineRunBox.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* context, const Color& fillColor, const Color& strokeColor, float strokeThickness);
38 Color correctedTextColor(Color textColor, Color backgroundColor);
40 class InlineTextBox : public InlineRunBox {
42 InlineTextBox(RenderObject* obj)
46 , m_truncation(cNoTruncation)
50 InlineTextBox* nextTextBox() const { return static_cast<InlineTextBox*>(nextLineBox()); }
51 InlineTextBox* prevTextBox() const { return static_cast<InlineTextBox*>(prevLineBox()); }
53 unsigned start() const { return m_start; }
54 unsigned end() const { return m_len ? m_start + m_len - 1 : m_start; }
55 unsigned len() const { return m_len; }
57 void setStart(unsigned start) { m_start = start; }
58 void setLen(unsigned len) { m_len = len; }
60 void offsetRun(int d) { m_start += d; }
62 void setFallbackFonts(const HashSet<const SimpleFontData*>&);
63 void takeFallbackFonts(Vector<const SimpleFontData*>&);
66 virtual int selectionTop();
67 virtual int selectionHeight();
70 virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos);
71 bool isSelected(int startPos, int endPos) const;
72 void selectionStartEnd(int& sPos, int& ePos);
75 virtual void paint(RenderObject::PaintInfo&, int tx, int ty);
76 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
79 RenderText* textRenderer() const;
82 virtual void deleteLine(RenderArena*);
83 virtual void extractLine();
84 virtual void attachLine();
87 virtual RenderObject::SelectionState selectionState();
90 virtual void clearTruncation() { m_truncation = cNoTruncation; }
91 virtual int placeEllipsisBox(bool flowIsLTR, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool& foundBox);
94 virtual bool isLineBreak() const;
96 void setSpaceAdd(int add) { m_width -= m_toAdd; m_toAdd = add; m_width += m_toAdd; }
99 virtual bool isInlineTextBox() { return true; }
102 virtual int caretMinOffset() const;
103 virtual int caretMaxOffset() const;
106 virtual unsigned caretMaxRenderedOffset() const;
111 virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const;
112 virtual int positionForOffset(int offset) const;
114 bool containsCaretOffset(int offset) const; // false for offset after line break
118 unsigned short m_len;
120 unsigned short m_truncation; // Where to truncate when text overflow is applied. We use special constants to
121 // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
124 void paintCompositionBackground(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, int startPos, int endPos);
125 void paintDocumentMarkers(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, bool background);
126 void paintCompositionUnderline(GraphicsContext*, int tx, int ty, const CompositionUnderline&);
128 void paintCustomHighlight(int tx, int ty, const AtomicString& type);
132 void paintDecoration(GraphicsContext*, int tx, int ty, int decoration, ShadowData*);
133 void paintSelection(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&);
134 void paintSpellingOrGrammarMarker(GraphicsContext*, int tx, int ty, DocumentMarker, RenderStyle*, const Font&, bool grammar);
135 void paintTextMatchMarker(GraphicsContext*, int tx, int ty, DocumentMarker, RenderStyle*, const Font&);
136 void computeRectForReplacementMarker(int tx, int ty, DocumentMarker, RenderStyle*, const Font&);
139 inline RenderText* InlineTextBox::textRenderer() const
141 return toRenderText(renderer());
144 } // namespace WebCore
146 #endif // InlineTextBox_h