• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *
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 RenderTextControlSingleLine_h
23 #define RenderTextControlSingleLine_h
24 
25 #include "PopupMenuClient.h"
26 #include "RenderTextControl.h"
27 #include "Timer.h"
28 
29 namespace WebCore {
30 
31 class InputElement;
32 class SearchFieldCancelButtonElement;
33 class SearchFieldResultsButtonElement;
34 class SearchPopupMenu;
35 class TextControlInnerElement;
36 
37 class RenderTextControlSingleLine : public RenderTextControl, private PopupMenuClient {
38 public:
39     RenderTextControlSingleLine(Node*, bool);
40     virtual ~RenderTextControlSingleLine();
41 
placeholderIsVisible()42     bool placeholderIsVisible() const { return m_placeholderVisible; }
43     bool placeholderShouldBeVisible() const;
44 
45     void addSearchResult();
46     void stopSearchEventTimer();
47 
popupIsVisible()48     bool popupIsVisible() const { return m_searchPopupIsVisible; }
49     void showPopup();
50     void hidePopup();
51 
52     void forwardEvent(Event*);
53 
54     void capsLockStateMayHaveChanged();
55 
56 private:
hasControlClip()57     virtual bool hasControlClip() const { return m_cancelButton; }
isTextField()58     virtual bool isTextField() const { return true; }
59 
60     virtual void subtreeHasChanged();
61     virtual void paint(PaintInfo&, int tx, int ty);
62     virtual void layout();
63 
64     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
65 
66     virtual void autoscroll();
67 
68     // Subclassed to forward to our inner div.
69     virtual int scrollLeft() const;
70     virtual int scrollTop() const;
71     virtual int scrollWidth() const;
72     virtual int scrollHeight() const;
73     virtual void setScrollLeft(int);
74     virtual void setScrollTop(int);
75     virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f, Node** stopNode = 0);
76 
77     int textBlockWidth() const;
78     virtual int preferredContentWidth(float charWidth) const;
79     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight);
80 
81     void createSubtreeIfNeeded();
82     virtual void updateFromElement();
83     virtual void cacheSelection(int start, int end);
84     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
85 
86     virtual RenderStyle* textBaseStyle() const;
87     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const;
88     PassRefPtr<RenderStyle> createInnerBlockStyle(const RenderStyle* startStyle) const;
89     PassRefPtr<RenderStyle> createResultsButtonStyle(const RenderStyle* startStyle) const;
90     PassRefPtr<RenderStyle> createCancelButtonStyle(const RenderStyle* startStyle) const;
91 
92     void updateCancelButtonVisibility() const;
93     EVisibility visibilityForCancelButton() const;
94     const AtomicString& autosaveName() const;
95 
96     void startSearchEventTimer();
97     void searchEventTimerFired(Timer<RenderTextControlSingleLine>*);
98 
99     // PopupMenuClient methods
100     virtual void valueChanged(unsigned listIndex, bool fireEvents = true);
101     virtual String itemText(unsigned listIndex) const;
itemToolTip(unsigned)102     virtual String itemToolTip(unsigned) const { return String(); }
103     virtual bool itemIsEnabled(unsigned listIndex) const;
104     virtual PopupMenuStyle itemStyle(unsigned listIndex) const;
105     virtual PopupMenuStyle menuStyle() const;
106     virtual int clientInsetLeft() const;
107     virtual int clientInsetRight() const;
108     virtual int clientPaddingLeft() const;
109     virtual int clientPaddingRight() const;
110     virtual int listSize() const;
111     virtual int selectedIndex() const;
112     virtual void popupDidHide();
113     virtual bool itemIsSeparator(unsigned listIndex) const;
114     virtual bool itemIsLabel(unsigned listIndex) const;
115     virtual bool itemIsSelected(unsigned listIndex) const;
shouldPopOver()116     virtual bool shouldPopOver() const { return false; }
valueShouldChangeOnHotTrack()117     virtual bool valueShouldChangeOnHotTrack() const { return false; }
118     virtual void setTextFromItem(unsigned listIndex);
119     virtual FontSelector* fontSelector() const;
120     virtual HostWindow* hostWindow() const;
121     virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize);
122 
123     InputElement* inputElement() const;
124 
125     bool m_searchPopupIsVisible;
126     bool m_shouldDrawCapsLockIndicator;
127 
128     RefPtr<TextControlInnerElement> m_innerBlock;
129     RefPtr<SearchFieldResultsButtonElement> m_resultsButton;
130     RefPtr<SearchFieldCancelButtonElement> m_cancelButton;
131 
132     Timer<RenderTextControlSingleLine> m_searchEventTimer;
133     RefPtr<SearchPopupMenu> m_searchPopup;
134     Vector<String> m_recentSearches;
135 };
136 
toRenderTextControlSingleLine(RenderObject * object)137 inline RenderTextControlSingleLine* toRenderTextControlSingleLine(RenderObject* object)
138 {
139     ASSERT(!object || object->isTextField());
140     return static_cast<RenderTextControlSingleLine*>(object);
141 }
142 
143 // This will catch anyone doing an unnecessary cast.
144 void toRenderTextControlSingleLine(const RenderTextControlSingleLine*);
145 
146 }
147 
148 #endif
149