• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);
38 Color correctedTextColor(Color textColor, Color backgroundColor);
39 
40 class InlineTextBox : public InlineRunBox {
41 public:
InlineTextBox(RenderObject * obj)42     InlineTextBox(RenderObject* obj)
43         : InlineRunBox(obj)
44         , m_start(0)
45         , m_len(0)
46         , m_truncation(cNoTruncation)
47     {
48     }
49 
nextTextBox()50     InlineTextBox* nextTextBox() const { return static_cast<InlineTextBox*>(nextLineBox()); }
prevTextBox()51     InlineTextBox* prevTextBox() const { return static_cast<InlineTextBox*>(prevLineBox()); }
52 
start()53     unsigned start() const { return m_start; }
end()54     unsigned end() const { return m_len ? m_start + m_len - 1 : m_start; }
len()55     unsigned len() const { return m_len; }
56 
setStart(unsigned start)57     void setStart(unsigned start) { m_start = start; }
setLen(unsigned len)58     void setLen(unsigned len) { m_len = len; }
59 
offsetRun(int d)60     void offsetRun(int d) { m_start += d; }
61 
62     void setFallbackFonts(const HashSet<const SimpleFontData*>&);
63     void takeFallbackFonts(Vector<const SimpleFontData*>&);
64 
truncation()65     unsigned short truncation() { return m_truncation; }
66 
67 private:
68     virtual int selectionTop();
69     virtual int selectionHeight();
70 
71 public:
72     virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos);
73     bool isSelected(int startPos, int endPos) const;
74     void selectionStartEnd(int& sPos, int& ePos);
75 
76 private:
77     virtual void paint(RenderObject::PaintInfo&, int tx, int ty);
78     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
79 
80 public:
81     RenderText* textRenderer() const;
82 
83 private:
84     virtual void deleteLine(RenderArena*);
85     virtual void extractLine();
86     virtual void attachLine();
87 
88 public:
89     virtual RenderObject::SelectionState selectionState();
90 
91 private:
clearTruncation()92     virtual void clearTruncation() { m_truncation = cNoTruncation; }
93     virtual int placeEllipsisBox(bool flowIsLTR, int visibleLeftEdge, int visibleRightEdge, int ellipsisWidth, bool& foundBox);
94 
95 public:
96     virtual bool isLineBreak() const;
97 
setSpaceAdd(int add)98     void setSpaceAdd(int add) { m_width -= m_toAdd; m_toAdd = add; m_width += m_toAdd; }
99 
100 private:
isInlineTextBox()101     virtual bool isInlineTextBox() { return true; }
102 
103 public:
104     virtual int caretMinOffset() const;
105     virtual int caretMaxOffset() const;
106 
107 private:
108     virtual unsigned caretMaxRenderedOffset() const;
109 
110     int textPos() const;
111 
112 public:
113     virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const;
114     virtual int positionForOffset(int offset) const;
115 
116     bool containsCaretOffset(int offset) const; // false for offset after line break
117 
118 private:
119     int m_start;
120     unsigned short m_len;
121 
122     unsigned short m_truncation; // Where to truncate when text overflow is applied.  We use special constants to
123                       // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
124 
125 protected:
126     void paintCompositionBackground(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, int startPos, int endPos);
127     void paintDocumentMarkers(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&, bool background);
128     void paintCompositionUnderline(GraphicsContext*, int tx, int ty, const CompositionUnderline&);
129 #if PLATFORM(MAC)
130     void paintCustomHighlight(int tx, int ty, const AtomicString& type);
131 #endif
132 
133 private:
134     void paintDecoration(GraphicsContext*, int tx, int ty, int decoration, ShadowData*);
135     void paintSelection(GraphicsContext*, int tx, int ty, RenderStyle*, const Font&);
136     void paintSpellingOrGrammarMarker(GraphicsContext*, int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&, bool grammar);
137     void paintTextMatchMarker(GraphicsContext*, int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&);
138     void computeRectForReplacementMarker(int tx, int ty, const DocumentMarker&, RenderStyle*, const Font&);
139 };
140 
textRenderer()141 inline RenderText* InlineTextBox::textRenderer() const
142 {
143     return toRenderText(renderer());
144 }
145 
146 } // namespace WebCore
147 
148 #endif // InlineTextBox_h
149