1 /*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22 #ifndef RenderTextControl_h
23 #define RenderTextControl_h
24
25 #include "RenderBlock.h"
26
27 namespace WebCore {
28
29 class VisibleSelection;
30 class TextControlInnerElement;
31 class TextControlInnerTextElement;
32
33 class RenderTextControl : public RenderBlock {
34 public:
35 virtual ~RenderTextControl();
36
isEdited()37 bool isEdited() const { return m_edited; }
setEdited(bool isEdited)38 void setEdited(bool isEdited) { m_edited = isEdited; }
39
isUserEdited()40 bool isUserEdited() const { return m_userEdited; }
41 void setUserEdited(bool isUserEdited);
42
43 int selectionStart();
44 int selectionEnd();
45 void setSelectionStart(int);
46 void setSelectionEnd(int);
47 void select();
48 void setSelectionRange(int start, int end);
49 VisibleSelection selection(int start, int end) const;
50
51 virtual void subtreeHasChanged();
52 String text();
53 String textWithHardLineBreaks();
54 void selectionChanged(bool userTriggered);
55
56 VisiblePosition visiblePositionForIndex(int index);
57 int indexForVisiblePosition(const VisiblePosition&);
58
59 protected:
60 RenderTextControl(Node*);
61
62 int scrollbarThickness() const;
63 void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const;
64 void setInnerTextValue(const String&);
65
66 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
67
68 void createSubtreeIfNeeded(TextControlInnerElement* innerBlock);
69 void hitInnerTextElement(HitTestResult&, int x, int y, int tx, int ty);
70 void forwardEvent(Event*);
71
72 int textBlockWidth() const;
73 int textBlockHeight() const;
74
75 virtual int preferredContentWidth(float charWidth) const = 0;
76 virtual void adjustControlHeightBasedOnLineHeight(int lineHeight) = 0;
77 virtual void cacheSelection(int start, int end) = 0;
78 virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
79
80 virtual void updateFromElement();
81 virtual void calcHeight();
82
83 friend class TextIterator;
84 HTMLElement* innerTextElement() const;
85
86 private:
renderName()87 virtual const char* renderName() const { return "RenderTextControl"; }
isTextControl()88 virtual bool isTextControl() const { return true; }
hasControlClip()89 virtual bool hasControlClip() const { return false; }
90 virtual IntRect controlClipRect(int tx, int ty) const;
91 virtual void calcPrefWidths();
removeLeftoverAnonymousBlock(RenderBlock *)92 virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
canHaveChildren()93 virtual bool canHaveChildren() const { return false; }
avoidsFloats()94 virtual bool avoidsFloats() const { return true; }
95
96 virtual void addFocusRingRects(GraphicsContext*, int tx, int ty);
97
canBeProgramaticallyScrolled(bool)98 virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
99
100 String finishText(Vector<UChar>&) const;
101
102 bool m_edited;
103 bool m_userEdited;
104 RefPtr<TextControlInnerTextElement> m_innerText;
105 };
106
toRenderTextControl(RenderObject * object)107 inline RenderTextControl* toRenderTextControl(RenderObject* object)
108 {
109 ASSERT(!object || object->isTextControl());
110 return static_cast<RenderTextControl*>(object);
111 }
112
toRenderTextControl(const RenderObject * object)113 inline const RenderTextControl* toRenderTextControl(const RenderObject* object)
114 {
115 ASSERT(!object || object->isTextControl());
116 return static_cast<const RenderTextControl*>(object);
117 }
118
119 // This will catch anyone doing an unnecessary cast.
120 void toRenderTextControl(const RenderTextControl*);
121
122 } // namespace WebCore
123
124 #endif // RenderTextControl_h
125