• 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 textObject() 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:
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 private:
63     virtual int selectionTop();
64     virtual int selectionHeight();
65 
66 public:
67     virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos);
68     bool isSelected(int startPos, int endPos) const;
69     void selectionStartEnd(int& sPos, int& ePos);
70 
71 private:
72     virtual void paint(RenderObject::PaintInfo&, int tx, int ty);
73     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty);
74 
75 public:
76     RenderText* textObject() const;
77 
78 private:
79     virtual void deleteLine(RenderArena*);
80     virtual void extractLine();
81     virtual void attachLine();
82 
83 public:
84     virtual RenderObject::SelectionState selectionState();
85 
86 private:
clearTruncation()87     virtual void clearTruncation() { m_truncation = cNoTruncation; }
88     virtual int placeEllipsisBox(bool ltr, int blockEdge, int ellipsisWidth, bool& foundBox);
89 
90 public:
91     virtual bool isLineBreak() const;
92 
setSpaceAdd(int add)93     void setSpaceAdd(int add) { m_width -= m_toAdd; m_toAdd = add; m_width += m_toAdd; }
94 
95 private:
isInlineTextBox()96     virtual bool isInlineTextBox() { return true; }
97 
98 public:
isText()99     virtual bool isText() const { return m_treatAsText; }
setIsText(bool b)100     void setIsText(bool b) { m_treatAsText = b; }
101 
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 };
137 
textObject()138 inline RenderText* InlineTextBox::textObject() const
139 {
140     return toRenderText(m_object);
141 }
142 
143 } // namespace WebCore
144 
145 #endif // InlineTextBox_h
146