• 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 FormControlElement;
30 class Selection;
31 class TextControlInnerElement;
32 class TextControlInnerTextElement;
33 
34 class RenderTextControl : public RenderBlock {
35 public:
36     virtual ~RenderTextControl();
37 
renderName()38     virtual const char* renderName() const { return "RenderTextControl"; }
hasControlClip()39     virtual bool hasControlClip() const { return false; }
40     virtual IntRect controlClipRect(int tx, int ty) const;
41     virtual void calcHeight();
42     virtual void calcPrefWidths();
removeLeftoverAnonymousBlock(RenderBlock *)43     virtual void removeLeftoverAnonymousBlock(RenderBlock*) { }
44     virtual void updateFromElement();
canHaveChildren()45     virtual bool canHaveChildren() const { return false; }
avoidsFloats()46     virtual bool avoidsFloats() const { return true; }
47 
isEdited()48     virtual bool isEdited() const { return m_edited; }
setEdited(bool isEdited)49     virtual void setEdited(bool isEdited) { m_edited = isEdited; }
50 
isUserEdited()51     bool isUserEdited() const { return m_userEdited; }
52     void setUserEdited(bool isUserEdited);
53 
54     int selectionStart();
55     int selectionEnd();
56     void setSelectionStart(int);
57     void setSelectionEnd(int);
58     void select();
59     void setSelectionRange(int start, int end);
60     Selection selection(int start, int end) const;
61 
62     virtual void subtreeHasChanged();
63     String text();
64     String textWithHardLineBreaks();
65     void selectionChanged(bool userTriggered);
66 
67     virtual void addFocusRingRects(GraphicsContext*, int tx, int ty);
68 
canBeProgramaticallyScrolled(bool)69     virtual bool canBeProgramaticallyScrolled(bool) const { return true; }
70     virtual void autoscroll();
71 
72     // Subclassed to forward to our inner div.
73     virtual int scrollLeft() const;
74     virtual int scrollTop() const;
75     virtual int scrollWidth() const;
76     virtual int scrollHeight() const;
77     virtual void setScrollLeft(int);
78     virtual void setScrollTop(int);
79     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f);
80 
81     VisiblePosition visiblePositionForIndex(int index);
82     int indexForVisiblePosition(const VisiblePosition&);
83 
84 protected:
85     RenderTextControl(Node*);
86 
87     int scrollbarThickness() const;
88     void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const;
89     void setInnerTextValue(const String&);
90 
91     virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle);
92 
93     void createSubtreeIfNeeded(TextControlInnerElement* innerBlock);
94     void hitInnerTextBlock(HitTestResult&, int x, int y, int tx, int ty);
95     void forwardEvent(Event*);
96 
97     int textBlockWidth() const;
98     int textBlockHeight() const;
99 
100     virtual int preferredContentWidth(float charWidth) const = 0;
101     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight) = 0;
102     virtual void cacheSelection(int start, int end) = 0;
103     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
104 
105     friend class TextIterator;
106     HTMLElement* innerTextElement() const;
107 
108     FormControlElement* formControlElement() const;
109 
110 private:
111     String finishText(Vector<UChar>&) const;
112 
113     bool m_edited;
114     bool m_userEdited;
115     RefPtr<TextControlInnerTextElement> m_innerText;
116 };
117 
118 } // namespace WebCore
119 
120 #endif // RenderTextControl_h
121