root/trunk/WebCore/rendering/RenderText.h

Revision 38346, 7.1 KB (checked in by simon.fraser@apple.com, 3 weeks ago)

2008-11-12 Simon Fraser <simon.fraser@apple.com>

Reviewed by Dave Hyatt

https://bugs.webkit.org/show_bug.cgi?id=21942
https://bugs.webkit.org/show_bug.cgi?id=18557

Add methods which can be used to map renderer-local rectangles
to quads in absolute coordinates, taking transforms into account:

localToAbsoluteQuad() converts a local rect into an absolute quad.
collectAbsoluteLineBoxQuads() is an analogue of addLineBoxRects()

that works with quads.

absoluteQuads() is an analogue of absoluteRects(), for quads.

Use the quad methods to fix the inspector highlight for transformed
elements.

  • Property svn:eol-style set to native
Line 
1/*
2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 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 RenderText_h
24#define RenderText_h
25
26#include "RenderObject.h"
27
28namespace WebCore {
29
30class InlineTextBox;
31class StringImpl;
32
33class RenderText : public RenderObject {
34public:
35    RenderText(Node*, PassRefPtr<StringImpl>);
36#ifndef NDEBUG
37    virtual ~RenderText();
38#endif
39
40    virtual const char* renderName() const;
41
42    virtual bool isTextFragment() const;
43    virtual bool isWordBreak() const;
44
45    virtual PassRefPtr<StringImpl> originalText() const;
46
47    void extractTextBox(InlineTextBox*);
48    void attachTextBox(InlineTextBox*);
49    void removeTextBox(InlineTextBox*);
50
51    virtual void destroy();
52
53    StringImpl* text() const { return m_text.get(); }
54
55    virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
56    virtual InlineTextBox* createInlineTextBox();
57    virtual void dirtyLineBoxes(bool fullLayout, bool isRootInlineBox = false);
58
59    virtual void paint(PaintInfo&, int tx, int ty) { ASSERT_NOT_REACHED(); }
60    virtual void layout() { ASSERT_NOT_REACHED(); }
61
62    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int, int, int, int, HitTestAction) { ASSERT_NOT_REACHED(); return false; }
63
64    virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
65    virtual void addLineBoxRects(Vector<IntRect>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
66
67    virtual void absoluteQuads(Vector<FloatQuad>&, bool topLevel = true);
68    virtual void collectAbsoluteLineBoxQuads(Vector<FloatQuad>&, unsigned startOffset = 0, unsigned endOffset = UINT_MAX, bool useSelectionHeight = false);
69
70    virtual VisiblePosition positionForCoordinates(int x, int y);
71
72    const UChar* characters() const { return m_text->characters(); }
73    unsigned textLength() const { return m_text->length(); } // non virtual implementation of length()
74    virtual void position(InlineBox*);
75
76    virtual unsigned width(unsigned from, unsigned len, const Font&, int xPos) const;
77    virtual unsigned width(unsigned from, unsigned len, int xPos, bool firstLine = false) const;
78    virtual int width() const;
79    virtual int height() const;
80
81    virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
82
83    virtual int minPrefWidth() const;
84    virtual int maxPrefWidth() const;
85
86    void trimmedPrefWidths(int leadWidth,
87                           int& beginMinW, bool& beginWS,
88                           int& endMinW, bool& endWS,
89                           bool& hasBreakableChar, bool& hasBreak,
90                           int& beginMaxW, int& endMaxW,
91                           int& minW, int& maxW, bool& stripFrontSpaces);
92
93    // returns the minimum x position of all runs relative to the parent.
94    // defaults to 0.
95    int minXPos() const;
96
97    virtual int xPos() const;
98    virtual int yPos() const;
99
100    virtual int verticalPositionHint(bool firstLine) const;
101
102    void setText(PassRefPtr<StringImpl>, bool force = false);
103    void setTextWithOffset(PassRefPtr<StringImpl>, unsigned offset, unsigned len, bool force = false);
104
105    virtual bool canBeSelectionLeaf() const { return true; }
106    virtual SelectionState selectionState() const { return static_cast<SelectionState>(m_selectionState); }
107    virtual void setSelectionState(SelectionState s);
108    virtual IntRect selectionRect(bool clipToVisibleContent = true);
109    virtual IntRect caretRect(InlineBox*, int caretOffset, int* extraWidthToEndOfLine = 0);
110
111    virtual int marginLeft() const { return style()->marginLeft().calcMinValue(0); }
112    virtual int marginRight() const { return style()->marginRight().calcMinValue(0); }
113
114    virtual IntRect absoluteClippedOverflowRect();
115
116    InlineTextBox* firstTextBox() const { return m_firstTextBox; }
117    InlineTextBox* lastTextBox() const { return m_lastTextBox; }
118
119    virtual int caretMinOffset() const;
120    virtual int caretMaxOffset() const;
121    virtual unsigned caretMaxRenderedOffset() const;
122
123    virtual int previousOffset(int current) const;
124    virtual int nextOffset(int current) const;
125
126    bool containsReversedText() const { return m_containsReversedText; }
127
128    InlineTextBox* findNextInlineTextBox(int offset, int& pos) const;
129
130    bool allowTabs() const { return !style()->collapseWhiteSpace(); }
131
132    void checkConsistency() const;
133
134protected:
135    virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
136
137    virtual void setTextInternal(PassRefPtr<StringImpl>);
138    virtual void calcPrefWidths(int leadWidth);
139    virtual UChar previousCharacter();
140
141private:
142    // Make length() private so that callers that have a RenderText*
143    // will use the more efficient textLength() instead, while
144    // callers with a RenderObject* can continue to use length().
145    virtual unsigned length() const { return textLength(); }
146
147    void deleteTextBoxes();
148    bool containsOnlyWhitespace(unsigned from, unsigned len) const;
149    int widthFromCache(const Font&, int start, int len, int xPos) const;
150    bool isAllASCII() const { return m_isAllASCII; }
151
152    RefPtr<StringImpl> m_text;
153
154    InlineTextBox* m_firstTextBox;
155    InlineTextBox* m_lastTextBox;
156
157    int m_minWidth;
158    int m_maxWidth;
159    int m_beginMinWidth;
160    int m_endMinWidth;
161
162    unsigned m_selectionState : 3; // enums on Windows are signed, so this needs to be unsigned to prevent it turning negative.
163    bool m_hasBreakableChar : 1; // Whether or not we can be broken into multiple lines.
164    bool m_hasBreak : 1; // Whether or not we have a hard break (e.g., <pre> with '\n').
165    bool m_hasTab : 1; // Whether or not we have a variable width tab character (e.g., <pre> with '\t').
166    bool m_hasBeginWS : 1; // Whether or not we begin with WS (only true if we aren't pre)
167    bool m_hasEndWS : 1; // Whether or not we end with WS (only true if we aren't pre)
168    bool m_linesDirty : 1; // This bit indicates that the text run has already dirtied specific
169                           // line boxes, and this hint will enable layoutInlineChildren to avoid
170                           // just dirtying everything when character data is modified (e.g., appended/inserted
171                           // or removed).
172    bool m_containsReversedText : 1;
173    bool m_isAllASCII : 1;
174};
175
176#ifdef NDEBUG
177inline void RenderText::checkConsistency() const
178{
179}
180#endif
181
182} // namespace WebCore
183
184#endif // RenderText_h
Note: See TracBrowser for help on using the browser.