OSDN Git Service

Merge WebKit at r73109: Initial merge by git.
[android-x86/external-webkit.git] / WebCore / rendering / InlineTextBox.h
1 /*
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.
5  *
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.
10  *
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.
15  *
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.
20  *
21  */
22
23 #ifndef InlineTextBox_h
24 #define InlineTextBox_h
25
26 #include "InlineBox.h"
27 #include "RenderText.h" // so textRenderer() can be inline
28
29 namespace WebCore {
30
31 struct CompositionUnderline;
32
33 const unsigned short cNoTruncation = USHRT_MAX;
34 const unsigned short cFullTruncation = USHRT_MAX - 1;
35
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);
39
40 class InlineTextBox : public InlineBox {
41 public:
42     InlineTextBox(RenderObject* obj)
43         : InlineBox(obj)
44         , m_prevTextBox(0)
45         , m_nextTextBox(0)
46         , m_start(0)
47         , m_len(0)
48         , m_truncation(cNoTruncation)
49     {
50     }
51
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; }
56
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; }
60
61     void setStart(unsigned start) { m_start = start; }
62     void setLen(unsigned len) { m_len = len; }
63
64     void offsetRun(int d) { m_start += d; }
65
66     unsigned short truncation() { return m_truncation; }
67
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(); }
71
72     
73     virtual int baselinePosition(FontBaseline) const;
74     virtual int lineHeight() const;
75
76 private:
77     int selectionTop();
78     int selectionBottom();
79     int selectionHeight();
80
81 public:
82     virtual IntRect calculateBoundaries() const { return IntRect(x(), y(), logicalWidth(), logicalHeight()); }
83
84     virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos);
85     bool isSelected(int startPos, int endPos) const;
86     void selectionStartEnd(int& sPos, int& ePos);
87
88 protected:
89     virtual void paint(PaintInfo&, int tx, int ty);
90     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
91
92 public:
93     RenderText* textRenderer() const;
94
95 private:
96     virtual void deleteLine(RenderArena*);
97     virtual void extractLine();
98     virtual void attachLine();
99
100 public:
101     virtual RenderObject::SelectionState selectionState();
102
103 private:
104     virtual void clearTruncation() { m_truncation = cNoTruncation; }
105     virtual int placeEllipsisBox(bool flowIsLTR, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool& foundBox);
106
107 public:
108     virtual bool isLineBreak() const;
109
110     void setSpaceAdd(int add) { m_logicalWidth -= m_toAdd; m_toAdd = add; m_logicalWidth += m_toAdd; }
111
112 private:
113     virtual bool isInlineTextBox() const { return true; }    
114
115 public:
116     virtual int caretMinOffset() const;
117     virtual int caretMaxOffset() const;
118
119 private:
120     virtual unsigned caretMaxRenderedOffset() const;
121
122     int textPos() const; // returns the x position relative to the left start of the text line.
123
124 public:
125     virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const;
126     virtual int positionForOffset(int offset) const;
127
128     bool containsCaretOffset(int offset) const; // false for offset after line break
129
130     // Needs to be public, so the static paintTextWithShadows() function can use it.
131     static FloatSize applyShadowToGraphicsContext(GraphicsContext*, const ShadowData*, const FloatRect& textRect, bool stroked, bool opaque, bool horizontal);
132
133 private:
134     InlineTextBox* m_prevTextBox; // The previous box that also uses our RenderObject
135     InlineTextBox* m_nextTextBox; // The next box that also uses our RenderObject
136
137     int m_start;
138     unsigned short m_len;
139
140     unsigned short m_truncation; // Where to truncate when text overflow is applied.  We use special constants to
141                       // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
142
143 protected:
144     void paintCompositionBackground(GraphicsContext*, const IntPoint& boxOrigin, RenderStyle*, const Font&, int startPos, int endPos);
145     void paintDocumentMarkers(GraphicsContext*, const IntPoint& boxOrigin, RenderStyle*, const Font&, bool background);
146     void paintCompositionUnderline(GraphicsContext*, const IntPoint& boxOrigin, const CompositionUnderline&);
147 #if PLATFORM(MAC)
148     void paintCustomHighlight(int tx, int ty, const AtomicString& type);
149 #endif
150
151 private:
152     void paintDecoration(GraphicsContext*, const IntPoint& boxOrigin, int decoration, const ShadowData*);
153     void paintSelection(GraphicsContext*, const IntPoint& boxOrigin, RenderStyle*, const Font&);
154     void paintSpellingOrGrammarMarker(GraphicsContext*, const IntPoint& boxOrigin, const DocumentMarker&, RenderStyle*, const Font&, bool grammar);
155     void paintTextMatchMarker(GraphicsContext*, const IntPoint& boxOrigin, const DocumentMarker&, RenderStyle*, const Font&);
156     void computeRectForReplacementMarker(const DocumentMarker&, RenderStyle*, const Font&);
157 };
158
159 inline RenderText* InlineTextBox::textRenderer() const
160 {
161     return toRenderText(renderer());
162 }
163
164 } // namespace WebCore
165
166 #endif // InlineTextBox_h