2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011 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 "InlineBox.h"
27 #include "RenderText.h" // so textRenderer() can be inline
29 #include <wtf/text/StringBuilder.h>
33 struct CompositionUnderline;
36 const unsigned short cNoTruncation = USHRT_MAX;
37 const unsigned short cFullTruncation = USHRT_MAX - 1;
39 class BufferForAppendingHyphen : public StringBuilder {
41 BufferForAppendingHyphen() { reserveCapacity(256); }
44 // Helper functions shared by InlineTextBox / SVGRootInlineBox
45 void updateGraphicsContext(GraphicsContext*, const Color& fillColor, const Color& strokeColor, float strokeThickness, ColorSpace);
46 Color correctedTextColor(Color textColor, Color backgroundColor);
48 class InlineTextBox : public InlineBox {
50 InlineTextBox(RenderObject* obj)
56 , m_truncation(cNoTruncation)
60 virtual void destroy(RenderArena*);
62 InlineTextBox* prevTextBox() const { return m_prevTextBox; }
63 InlineTextBox* nextTextBox() const { return m_nextTextBox; }
64 void setNextTextBox(InlineTextBox* n) { m_nextTextBox = n; }
65 void setPreviousTextBox(InlineTextBox* p) { m_prevTextBox = p; }
67 unsigned start() const { return m_start; }
68 unsigned end() const { return m_len ? m_start + m_len - 1 : m_start; }
69 unsigned len() const { return m_len; }
71 void setStart(unsigned start) { m_start = start; }
72 void setLen(unsigned len) { m_len = len; }
74 void offsetRun(int d) { m_start += d; }
76 unsigned short truncation() { return m_truncation; }
78 using InlineBox::hasHyphen;
79 using InlineBox::setHasHyphen;
80 using InlineBox::canHaveLeadingExpansion;
81 using InlineBox::setCanHaveLeadingExpansion;
83 static inline bool compareByStart(const InlineTextBox* first, const InlineTextBox* second) { return first->start() < second->start(); }
85 virtual LayoutUnit baselinePosition(FontBaseline) const;
86 virtual LayoutUnit lineHeight() const;
88 bool getEmphasisMarkPosition(RenderStyle*, TextEmphasisPosition&) const;
90 LayoutRect logicalOverflowRect() const;
91 void setLogicalOverflowRect(const LayoutRect&);
92 LayoutUnit logicalTopVisualOverflow() const { return logicalOverflowRect().y(); }
93 LayoutUnit logicalBottomVisualOverflow() const { return logicalOverflowRect().maxY(); }
94 LayoutUnit logicalLeftVisualOverflow() const { return logicalOverflowRect().x(); }
95 LayoutUnit logicalRightVisualOverflow() const { return logicalOverflowRect().maxX(); }
98 virtual void showBox(int = 0) const;
99 virtual const char* boxName() const;
102 LayoutUnit selectionTop();
103 LayoutUnit selectionBottom();
104 LayoutUnit selectionHeight();
106 TextRun constructTextRun(RenderStyle*, const Font&, BufferForAppendingHyphen* = 0) const;
107 TextRun constructTextRun(RenderStyle*, const Font&, const UChar*, int length, int maximumLength, BufferForAppendingHyphen* = 0) const;
110 virtual FloatRect calculateBoundaries() const { return FloatRect(x(), y(), width(), height()); }
112 virtual LayoutRect localSelectionRect(int startPos, int endPos);
113 bool isSelected(int startPos, int endPos) const;
114 void selectionStartEnd(int& sPos, int& ePos);
117 virtual void paint(PaintInfo&, const LayoutPoint&, LayoutUnit lineTop, LayoutUnit lineBottom);
118 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestPoint& pointInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit lineTop, LayoutUnit lineBottom) OVERRIDE;
121 RenderText* textRenderer() const;
124 virtual void deleteLine(RenderArena*);
125 virtual void extractLine();
126 virtual void attachLine();
129 virtual RenderObject::SelectionState selectionState();
132 virtual void clearTruncation() { m_truncation = cNoTruncation; }
133 virtual float placeEllipsisBox(bool flowIsLTR, float visibleLeftEdge, float visibleRightEdge, float ellipsisWidth, float &truncatedWidth, bool& foundBox) OVERRIDE;
136 virtual bool isLineBreak() const;
138 void setExpansion(int newExpansion)
140 m_logicalWidth -= expansion();
141 InlineBox::setExpansion(newExpansion);
142 m_logicalWidth += newExpansion;
146 virtual bool isInlineTextBox() const { return true; }
149 virtual int caretMinOffset() const;
150 virtual int caretMaxOffset() const;
153 float textPos() const; // returns the x position relative to the left start of the text line.
156 virtual int offsetForPosition(float x, bool includePartialGlyphs = true) const;
157 virtual float positionForOffset(int offset) const;
159 bool containsCaretOffset(int offset) const; // false for offset after line break
161 // Needs to be public, so the static paintTextWithShadows() function can use it.
162 static FloatSize applyShadowToGraphicsContext(GraphicsContext*, const ShadowData*, const FloatRect& textRect, bool stroked, bool opaque, bool horizontal);
165 InlineTextBox* m_prevTextBox; // The previous box that also uses our RenderObject
166 InlineTextBox* m_nextTextBox; // The next box that also uses our RenderObject
169 unsigned short m_len;
171 unsigned short m_truncation; // Where to truncate when text overflow is applied. We use special constants to
172 // denote no truncation (the whole run paints) and full truncation (nothing paints at all).
175 void paintCompositionBackground(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&, int startPos, int endPos);
176 #if ENABLE(TIZEN_WEBKIT2_SUPPORT_JAPANESE_IME)
177 void paintCompositionUnderlineBackground(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&, const CompositionUnderline);
179 void paintDocumentMarkers(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&, bool background);
180 void paintCompositionUnderline(GraphicsContext*, const FloatPoint& boxOrigin, const CompositionUnderline&);
182 void paintCustomHighlight(const LayoutPoint&, const AtomicString& type);
186 void paintDecoration(GraphicsContext*, const FloatPoint& boxOrigin, int decoration, const ShadowData*);
187 void paintSelection(GraphicsContext*, const FloatPoint& boxOrigin, RenderStyle*, const Font&, Color textColor);
188 void paintDocumentMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, RenderStyle*, const Font&, bool grammar);
189 void paintTextMatchMarker(GraphicsContext*, const FloatPoint& boxOrigin, DocumentMarker*, RenderStyle*, const Font&);
190 void computeRectForReplacementMarker(DocumentMarker*, RenderStyle*, const Font&);
192 TextRun::ExpansionBehavior expansionBehavior() const
194 return (canHaveLeadingExpansion() ? TextRun::AllowLeadingExpansion : TextRun::ForbidLeadingExpansion)
195 | (expansion() && nextLeafChild() ? TextRun::AllowTrailingExpansion : TextRun::ForbidTrailingExpansion);
199 inline InlineTextBox* toInlineTextBox(InlineBox* inlineBox)
201 ASSERT(!inlineBox || inlineBox->isInlineTextBox());
202 return static_cast<InlineTextBox*>(inlineBox);
205 inline const InlineTextBox* toInlineTextBox(const InlineBox* inlineBox)
207 ASSERT(!inlineBox || inlineBox->isInlineTextBox());
208 return static_cast<const InlineTextBox*>(inlineBox);
211 // This will catch anyone doing an unnecessary cast.
212 void toInlineTextBox(const InlineTextBox*);
214 inline RenderText* InlineTextBox::textRenderer() const
216 return toRenderText(renderer());
219 void alignSelectionRectToDevicePixels(FloatRect&);
221 } // namespace WebCore
223 #endif // InlineTextBox_h