OSDN Git Service

merge from open-source master
[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 "InlineRunBox.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* context, const Color& fillColor, const Color& strokeColor, float strokeThickness);
38 Color correctedTextColor(Color textColor, Color backgroundColor);
39
40 class InlineTextBox : public InlineRunBox {
41 public:
42     InlineTextBox(RenderObject* obj)
43         : InlineRunBox(obj)
44         , m_start(0)
45         , m_len(0)
46         , m_truncation(cNoTruncation)
47     {
48     }
49
50     InlineTextBox* nextTextBox() const { return static_cast<InlineTextBox*>(nextLineBox()); }
51     InlineTextBox* prevTextBox() const { return static_cast<InlineTextBox*>(prevLineBox()); }
52
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; }
56
57     void setStart(unsigned start) { m_start = start; }
58     void setLen(unsigned len) { m_len = len; }
59
60     void offsetRun(int d) { m_start += d; }
61
62     void setFallbackFonts(const HashSet<const SimpleFontData*>&);
63     void takeFallbackFonts(Vector<const SimpleFontData*>&);
64
65 private:
66     virtual int selectionTop();
67     virtual int selectionHeight();
68
69 public:
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);
73
74 private:
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);
77
78 public:
79     RenderText* textRenderer() const;
80
81 private:
82     virtual void deleteLine(RenderArena*);
83     virtual void extractLine();
84     virtual void attachLine();
85
86 public:
87     virtual RenderObject::SelectionState selectionState();
88
89 private:
90     virtual void clearTruncation() { m_truncation = cNoTruncation; }
91     virtual int placeEllipsisBox(bool flowIsLTR, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool& foundBox);
92
93 public:
94     virtual bool isLineBreak() const;
95
96     void setSpaceAdd(int add) { m_width -= m_toAdd; m_toAdd = add; m_width += m_toAdd; }
97
98 private:
99     virtual bool isInlineTextBox() { return true; }    
100
101 public:
102     virtual int caretMinOffset() const;
103     virtual int caretMaxOffset() const;
104
105 private:
106     virtual unsigned caretMaxRenderedOffset() const;
107
108     int textPos() const;
109
110 public:
111     virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const;
112     virtual int positionForOffset(int offset) const;
113
114     bool containsCaretOffset(int offset) const; // false for offset after line break
115
116 private:
117     int m_start;
118     unsigned short m_len;
119
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).
122
123 protected:
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&);
127 #if PLATFORM(MAC)
128     void paintCustomHighlight(int tx, int ty, const AtomicString& type);
129 #endif
130
131 private:
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&);
137 };
138
139 inline RenderText* InlineTextBox::textRenderer() const
140 {
141     return toRenderText(renderer());
142 }
143
144 } // namespace WebCore
145
146 #endif // InlineTextBox_h