RenderTextControlSingleLine.h revision 635860845790a19bf50bbc51ba8fb66a96dde068
1/* 2 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 * 19 */ 20 21#ifndef RenderTextControlSingleLine_h 22#define RenderTextControlSingleLine_h 23 24#include "PopupMenuClient.h" 25#include "RenderTextControl.h" 26#include "Timer.h" 27 28namespace WebCore { 29 30class InputElement; 31class SearchFieldCancelButtonElement; 32class SearchFieldResultsButtonElement; 33class SearchPopupMenu; 34class TextControlInnerElement; 35 36class RenderTextControlSingleLine : public RenderTextControl, private PopupMenuClient { 37public: 38 RenderTextControlSingleLine(Node*); 39 virtual ~RenderTextControlSingleLine(); 40 41 virtual bool hasControlClip() const { return m_cancelButton; } 42 virtual bool isTextField() const { return true; } 43 44 bool placeholderIsVisible() const { return m_placeholderVisible; } 45 bool placeholderShouldBeVisible() const; 46 void updatePlaceholderVisibility(); 47 48 void addSearchResult(); 49 void stopSearchEventTimer(); 50 51 bool popupIsVisible() const { return m_searchPopupIsVisible; } 52 void showPopup(); 53 virtual void hidePopup(); // PopupMenuClient method 54 55 virtual void subtreeHasChanged(); 56 virtual void paint(PaintInfo&, int tx, int ty); 57 virtual void layout(); 58 59 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction); 60 void forwardEvent(Event*); 61 62private: 63 virtual void capsLockStateMayHaveChanged(); 64 65 int textBlockWidth() const; 66 virtual int preferredContentWidth(float charWidth) const; 67 virtual void adjustControlHeightBasedOnLineHeight(int lineHeight); 68 69 void createSubtreeIfNeeded(); 70 virtual void updateFromElement(); 71 virtual void cacheSelection(int start, int end); 72 virtual void styleDidChange(RenderStyle::Diff, const RenderStyle* oldStyle); 73 74 virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const; 75 PassRefPtr<RenderStyle> createInnerBlockStyle(const RenderStyle* startStyle) const; 76 PassRefPtr<RenderStyle> createResultsButtonStyle(const RenderStyle* startStyle) const; 77 PassRefPtr<RenderStyle> createCancelButtonStyle(const RenderStyle* startStyle) const; 78 79 void updateCancelButtonVisibility(RenderStyle*) const; 80 const AtomicString& autosaveName() const; 81 82 void startSearchEventTimer(); 83 void searchEventTimerFired(Timer<RenderTextControlSingleLine>*); 84 85private: 86 // PopupMenuClient methods 87 virtual void valueChanged(unsigned listIndex, bool fireEvents = true); 88 virtual String itemText(unsigned listIndex) const; 89 virtual bool itemIsEnabled(unsigned listIndex) const; 90 virtual PopupMenuStyle itemStyle(unsigned listIndex) const; 91 virtual PopupMenuStyle menuStyle() const; 92 virtual int clientInsetLeft() const; 93 virtual int clientInsetRight() const; 94 virtual int clientPaddingLeft() const; 95 virtual int clientPaddingRight() const; 96 virtual int listSize() const; 97 virtual int selectedIndex() const; 98 virtual bool itemIsSeparator(unsigned listIndex) const; 99 virtual bool itemIsLabel(unsigned listIndex) const; 100 virtual bool itemIsSelected(unsigned listIndex) const; 101 virtual bool shouldPopOver() const { return false; } 102 virtual bool valueShouldChangeOnHotTrack() const { return false; } 103 virtual void setTextFromItem(unsigned listIndex); 104 virtual FontSelector* fontSelector() const; 105 virtual HostWindow* hostWindow() const; 106 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize); 107 108 InputElement* inputElement() const; 109 110private: 111 bool m_placeholderVisible; 112 bool m_searchPopupIsVisible; 113 bool m_shouldDrawCapsLockIndicator; 114 115 RefPtr<TextControlInnerElement> m_innerBlock; 116 RefPtr<SearchFieldResultsButtonElement> m_resultsButton; 117 RefPtr<SearchFieldCancelButtonElement> m_cancelButton; 118 119 Timer<RenderTextControlSingleLine> m_searchEventTimer; 120 RefPtr<SearchPopupMenu> m_searchPopup; 121 Vector<String> m_recentSearches; 122}; 123 124} 125 126#endif 127