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).
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.
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.
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.
23 #ifndef RenderTextControlSingleLine_h
24 #define RenderTextControlSingleLine_h
26 #include "PopupMenuClient.h"
27 #include "RenderTextControl.h"
31 class HTMLInputElement;
32 class SearchPopupMenu;
34 class RenderTextControlSingleLine : public RenderTextControl, private PopupMenuClient {
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;
43 void addSearchResult();
44 void stopSearchEventTimer();
46 bool popupIsVisible() const { return m_searchPopupIsVisible; }
50 void capsLockStateMayHaveChanged();
52 #if ENABLE(INPUT_SPEECH)
53 HTMLElement* speechButtonElement() const;
57 virtual bool hasControlClip() const;
58 virtual LayoutRect controlClipRect(const LayoutPoint&) const;
59 virtual bool isTextField() const { return true; }
61 virtual void paint(PaintInfo&, const LayoutPoint&);
62 virtual void layout();
64 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
66 virtual void autoscroll();
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);
78 int textBlockWidth() const;
79 virtual float getAvgCharWidth(AtomicString family);
80 virtual LayoutUnit preferredContentWidth(float charWidth) const;
81 virtual void adjustControlHeightBasedOnLineHeight(LayoutUnit lineHeight);
83 virtual void updateFromElement();
84 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
86 virtual RenderStyle* textBaseStyle() const;
88 EVisibility visibilityForCancelButton() const;
89 const AtomicString& autosaveName() const;
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);
120 HTMLInputElement* inputElement() const;
122 HTMLElement* containerElement() const;
123 HTMLElement* innerBlockElement() const;
124 HTMLElement* innerSpinButtonElement() const;
125 HTMLElement* resultsButtonElement() const;
126 HTMLElement* cancelButtonElement() const;
128 bool m_searchPopupIsVisible;
129 bool m_shouldDrawCapsLockIndicator;
130 LayoutUnit m_desiredInnerTextHeight;
131 RefPtr<SearchPopupMenu> m_searchPopup;
132 Vector<String> m_recentSearches;
135 inline RenderTextControlSingleLine* toRenderTextControlSingleLine(RenderObject* object)
137 ASSERT(!object || object->isTextField());
138 return static_cast<RenderTextControlSingleLine*>(object);
141 // This will catch anyone doing an unnecessary cast.
142 void toRenderTextControlSingleLine(const RenderTextControlSingleLine*);
144 // ----------------------------
146 class RenderTextControlInnerBlock : public RenderBlock {
148 RenderTextControlInnerBlock(Node* node, bool isMultiLine) : RenderBlock(node), m_multiLine(isMultiLine) { }
151 virtual bool hasLineIfEmpty() const { return true; }
152 virtual VisiblePosition positionForPoint(const LayoutPoint&);