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();
53 virtual bool hasControlClip() const;
54 virtual LayoutRect controlClipRect(const LayoutPoint&) const;
55 virtual bool isTextField() const { return true; }
57 virtual void paint(PaintInfo&, const LayoutPoint&);
58 virtual void layout();
60 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction);
62 virtual void autoscroll();
64 // Subclassed to forward to our inner div.
65 virtual int scrollLeft() const;
66 virtual int scrollTop() const;
67 virtual int scrollWidth() const;
68 virtual int scrollHeight() const;
69 virtual void setScrollLeft(int);
70 virtual void setScrollTop(int);
71 virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
72 virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
74 int textBlockWidth() const;
75 virtual float getAvgCharWidth(AtomicString family);
76 virtual LayoutUnit preferredContentWidth(float charWidth) const;
77 virtual LayoutUnit computeControlHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const OVERRIDE;
79 virtual void updateFromElement();
80 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
82 virtual RenderStyle* textBaseStyle() const;
84 EVisibility visibilityForCancelButton() const;
85 bool textShouldBeTruncated() const;
86 const AtomicString& autosaveName() const;
88 // PopupMenuClient methods
89 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRIDE;
90 virtual void selectionChanged(unsigned, bool) OVERRIDE { }
91 virtual void selectionCleared() OVERRIDE { }
92 virtual String itemText(unsigned listIndex) const OVERRIDE;
93 virtual String itemLabel(unsigned listIndex) const OVERRIDE;
94 virtual String itemIcon(unsigned listIndex) const OVERRIDE;
95 virtual String itemToolTip(unsigned) const OVERRIDE { return String(); }
96 virtual String itemAccessibilityText(unsigned) const OVERRIDE { return String(); }
97 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
98 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
99 virtual PopupMenuStyle menuStyle() const OVERRIDE;
100 virtual int clientInsetLeft() const OVERRIDE;
101 virtual int clientInsetRight() const OVERRIDE;
102 virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
103 virtual LayoutUnit clientPaddingRight() const OVERRIDE;
104 virtual int listSize() const OVERRIDE;
105 virtual int selectedIndex() const OVERRIDE;
106 virtual void popupDidHide() OVERRIDE;
107 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
108 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
109 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
110 virtual bool shouldPopOver() const OVERRIDE { return false; }
111 virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return false; }
112 virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
113 virtual FontSelector* fontSelector() const OVERRIDE;
114 virtual HostWindow* hostWindow() const OVERRIDE;
115 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE;
117 HTMLInputElement* inputElement() const;
119 HTMLElement* containerElement() const;
120 HTMLElement* innerBlockElement() const;
121 HTMLElement* innerSpinButtonElement() const;
122 HTMLElement* resultsButtonElement() const;
123 HTMLElement* cancelButtonElement() const;
125 bool m_searchPopupIsVisible;
126 bool m_shouldDrawCapsLockIndicator;
127 LayoutUnit m_desiredInnerTextHeight;
128 RefPtr<SearchPopupMenu> m_searchPopup;
129 Vector<String> m_recentSearches;
132 inline RenderTextControlSingleLine* toRenderTextControlSingleLine(RenderObject* object)
134 ASSERT(!object || object->isTextField());
135 return static_cast<RenderTextControlSingleLine*>(object);
138 // This will catch anyone doing an unnecessary cast.
139 void toRenderTextControlSingleLine(const RenderTextControlSingleLine*);
141 // ----------------------------
143 class RenderTextControlInnerBlock : public RenderBlock {
145 RenderTextControlInnerBlock(Node* node, bool isMultiLine) : RenderBlock(node), m_multiLine(isMultiLine) { }
148 virtual bool hasLineIfEmpty() const { return true; }
149 virtual VisiblePosition positionForPoint(const LayoutPoint&);