• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
37     HTMLElement* innerTextElement() const;
38 
lastChangeWasUserEdit()39     bool lastChangeWasUserEdit() const { return m_lastChangeWasUserEdit; }
40     void setLastChangeWasUserEdit(bool lastChangeWasUserEdit);
41 
42     int selectionStart() const;
43     int selectionEnd() const;
44     PassRefPtr<Range> selection(int start, int end) const;
45 
46     virtual void subtreeHasChanged();
47     String text();
48     String textWithHardLineBreaks();
49     void selectionChanged(bool userTriggered);
50 
51     VisiblePosition visiblePositionForIndex(int index) const;
52     static int indexForVisiblePosition(HTMLElement*, const VisiblePosition&);
53 
54     void updatePlaceholderVisibility(bool, bool);
55 
56 protected:
57     RenderTextControl(Node*, bool);
58 
59     int scrollbarThickness() const;
60     void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const;
61     void setInnerTextValue(const String&);
62 
63     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
64 
65     void createSubtreeIfNeeded(TextControlInnerElement* innerBlock);
66     void hitInnerTextElement(HitTestResult&, int x, int y, int tx, int ty);
67     void forwardEvent(Event*);
68 
69     int textBlockWidth() const;
70     int textBlockHeight() const;
71 
72     float scaleEmToUnits(int x) const;
73 
74     static bool hasValidAvgCharWidth(AtomicString family);
75     virtual float getAvgCharWidth(AtomicString family);
76     virtual int preferredContentWidth(float charWidth) const = 0;
77     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight) = 0;
78     virtual void cacheSelection(int start, int end) = 0;
79     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
80     virtual RenderStyle* textBaseStyle() const = 0;
81 
82     virtual void updateFromElement();
83     virtual void computeLogicalHeight();
84 
85     bool m_placeholderVisible;
86 
87 private:
renderName()88     virtual const char* renderName() const { return "RenderTextControl"; }
isTextControl()89     virtual bool isTextControl() const { return true; }
90     virtual void computePreferredLogicalWidths();
removeLeftoverAnonymousBlock(RenderBlock *)91     virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
canHaveChildren()92     virtual bool canHaveChildren() const { return false; }
avoidsFloats()93     virtual bool avoidsFloats() const { return true; }
94     void setInnerTextStyle(PassRefPtr<RenderStyle>);
95     virtual void paintObject(PaintInfo&, int tx, int ty);
96 
97     virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty);
98 
canBeProgramaticallyScrolled(bool)99     virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
100 
requiresForcedStyleRecalcPropagation()101     virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
102 
103     String finishText(Vector<UChar>&) const;
104 
105     bool hasVisibleTextArea() const;
106     friend void setSelectionRange(Node*, int start, int end);
107     static bool isSelectableElement(HTMLElement*, Node*);
108 
109     virtual int textBlockInsetLeft() const = 0;
110     virtual int textBlockInsetRight() const = 0;
111     virtual int textBlockInsetTop() const = 0;
112 
113     void paintPlaceholder(PaintInfo&, int tx, int ty);
114 
115     bool m_lastChangeWasUserEdit;
116     RefPtr<TextControlInnerTextElement> m_innerText;
117 };
118 
119 void setSelectionRange(Node*, int start, int end);
120 
toRenderTextControl(RenderObject * object)121 inline RenderTextControl* toRenderTextControl(RenderObject* object)
122 {
123     ASSERT(!object || object->isTextControl());
124     return static_cast<RenderTextControl*>(object);
125 }
126 
toRenderTextControl(const RenderObject * object)127 inline const RenderTextControl* toRenderTextControl(const RenderObject* object)
128 {
129     ASSERT(!object || object->isTextControl());
130     return static_cast<const RenderTextControl*>(object);
131 }
132 
133 // This will catch anyone doing an unnecessary cast.
134 void toRenderTextControl(const RenderTextControl*);
135 
136 } // namespace WebCore
137 
138 #endif // RenderTextControl_h
139