• 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*);
40      virtual ~RenderTextControlSingleLine();
41  
placeholderIsVisible()42      bool placeholderIsVisible() const { return m_placeholderVisible; }
43      bool placeholderShouldBeVisible() const;
44      void updatePlaceholderVisibility();
45  
46      void addSearchResult();
47      void stopSearchEventTimer();
48  
popupIsVisible()49      bool popupIsVisible() const { return m_searchPopupIsVisible; }
50      void showPopup();
51      virtual void hidePopup(); // PopupMenuClient method
52  
53      void forwardEvent(Event*);
54  
55      void capsLockStateMayHaveChanged();
56  
57  private:
hasControlClip()58      virtual bool hasControlClip() const { return m_cancelButton; }
isTextField()59      virtual bool isTextField() const { return true; }
60  
61      virtual void subtreeHasChanged();
62      virtual void paint(PaintInfo&, int tx, int ty);
63      virtual void layout();
64  
65      virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty, HitTestAction);
66  
67      virtual void autoscroll();
68  
69      // Subclassed to forward to our inner div.
70      virtual int scrollLeft() const;
71      virtual int scrollTop() const;
72      virtual int scrollWidth() const;
73      virtual int scrollHeight() const;
74      virtual void setScrollLeft(int);
75      virtual void setScrollTop(int);
76      virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f);
77  
78      int textBlockWidth() const;
79      virtual int preferredContentWidth(float charWidth) const;
80      virtual void adjustControlHeightBasedOnLineHeight(int lineHeight);
81  
82      void createSubtreeIfNeeded();
83      virtual void updateFromElement();
84      virtual void cacheSelection(int start, int end);
85      virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
86  
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 bool itemIsSeparator(unsigned listIndex) const;
113      virtual bool itemIsLabel(unsigned listIndex) const;
114      virtual bool itemIsSelected(unsigned listIndex) const;
shouldPopOver()115      virtual bool shouldPopOver() const { return false; }
valueShouldChangeOnHotTrack()116      virtual bool valueShouldChangeOnHotTrack() const { return false; }
117      virtual void setTextFromItem(unsigned listIndex);
118      virtual FontSelector* fontSelector() const;
119      virtual HostWindow* hostWindow() const;
120      virtual PassRefPtr<Scrollbar> createScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize);
121  
122      InputElement* inputElement() const;
123  
124      bool m_placeholderVisible;
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