initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderTextControlSingleLine.h
1 /*
2  * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
3  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
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 RenderTextControlSingleLine_h
24 #define RenderTextControlSingleLine_h
25
26 #include "PopupMenuClient.h"
27 #include "RenderTextControl.h"
28
29 namespace WebCore {
30
31 class HTMLInputElement;
32 class SearchPopupMenu;
33
34 class RenderTextControlSingleLine : public RenderTextControl, private PopupMenuClient {
35 public:
36     RenderTextControlSingleLine(Node*);
37     virtual ~RenderTextControlSingleLine();
38     // FIXME: Move create*Style() to their classes.
39     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const;
40     PassRefPtr<RenderStyle> createInnerBlockStyle(const RenderStyle* startStyle) const;
41     void updateCancelButtonVisibility() const;
42
43     void addSearchResult();
44     void stopSearchEventTimer();
45
46     bool popupIsVisible() const { return m_searchPopupIsVisible; }
47     void showPopup();
48     void hidePopup();
49
50     void capsLockStateMayHaveChanged();
51
52 #if ENABLE(INPUT_SPEECH)
53     HTMLElement* speechButtonElement() const;
54 #endif
55
56 private:
57     virtual bool hasControlClip() const;
58     virtual LayoutRect controlClipRect(const LayoutPoint&) const;
59     virtual bool isTextField() const { return true; }
60
61     virtual void paint(PaintInfo&, const LayoutPoint&);
62     virtual void layout();
63
64     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
65
66     virtual void autoscroll();
67
68     // Subclassed to forward to our inner div.
69     virtual LayoutUnit scrollLeft() const;
70     virtual LayoutUnit scrollTop() const;
71     virtual LayoutUnit scrollWidth() const;
72     virtual LayoutUnit scrollHeight() const;
73     virtual void setScrollLeft(LayoutUnit);
74     virtual void setScrollTop(LayoutUnit);
75     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
76     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
77
78     int textBlockWidth() const;
79     virtual float getAvgCharWidth(AtomicString family);
80     virtual LayoutUnit preferredContentWidth(float charWidth) const;
81     virtual void adjustControlHeightBasedOnLineHeight(LayoutUnit lineHeight);
82
83     virtual void updateFromElement();
84     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
85
86     virtual RenderStyle* textBaseStyle() const;
87
88     EVisibility visibilityForCancelButton() const;
89     const AtomicString& autosaveName() const;
90
91     // PopupMenuClient methods
92     virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
93     virtual void selectionChanged(unsigned, bool) {}
94     virtual void selectionCleared() {}
95     virtual String itemText(unsigned listIndex) const;
96     virtual String itemLabel(unsigned listIndex) const;
97     virtual String itemIcon(unsigned listIndex) const;
98     virtual String itemToolTip(unsigned) const { return String(); }
99     virtual String itemAccessibilityText(unsigned) const { return String(); }
100     virtual bool itemIsEnabled(unsigned listIndex) const;
101     virtual PopupMenuStyle itemStyle(unsigned listIndex) const;
102     virtual PopupMenuStyle menuStyle() const;
103     virtual int clientInsetLeft() const;
104     virtual int clientInsetRight() const;
105     virtual int clientPaddingLeft() const;
106     virtual int clientPaddingRight() const;
107     virtual int listSize() const;
108     virtual int selectedIndex() const;
109     virtual void popupDidHide();
110     virtual bool itemIsSeparator(unsigned listIndex) const;
111     virtual bool itemIsLabel(unsigned listIndex) const;
112     virtual bool itemIsSelected(unsigned listIndex) const;
113     virtual bool shouldPopOver() const { return false; }
114     virtual bool valueShouldChangeOnHotTrack() const { return false; }
115     virtual void setTextFromItem(unsigned listIndex);
116     virtual FontSelector* fontSelector() const;
117     virtual HostWindow* hostWindow() const;
118     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize);
119
120     HTMLInputElement* inputElement() const;
121
122     HTMLElement* containerElement() const;
123     HTMLElement* innerBlockElement() const;
124     HTMLElement* innerSpinButtonElement() const;
125     HTMLElement* resultsButtonElement() const;
126     HTMLElement* cancelButtonElement() const;
127
128     bool m_searchPopupIsVisible;
129     bool m_shouldDrawCapsLockIndicator;
130     LayoutUnit m_desiredInnerTextHeight;
131     RefPtr<SearchPopupMenu> m_searchPopup;
132     Vector<String> m_recentSearches;
133 };
134
135 inline RenderTextControlSingleLine* toRenderTextControlSingleLine(RenderObject* object)
136 {
137     ASSERT(!object || object->isTextField());
138     return static_cast<RenderTextControlSingleLine*>(object);
139 }
140
141 // This will catch anyone doing an unnecessary cast.
142 void toRenderTextControlSingleLine(const RenderTextControlSingleLine*);
143
144 // ----------------------------
145
146 class RenderTextControlInnerBlock : public RenderBlock {
147 public:
148     RenderTextControlInnerBlock(Node* node, bool isMultiLine) : RenderBlock(node), m_multiLine(isMultiLine) { }
149
150 private:
151     virtual bool hasLineIfEmpty() const { return true; }
152     virtual VisiblePosition positionForPoint(const LayoutPoint&);
153
154     bool m_multiLine;
155 };
156
157 }
158
159 #endif