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 RenderSearchField_h
24 #define RenderSearchField_h
26 #include "PopupMenuClient.h"
27 #include "RenderTextControlSingleLine.h"
31 class HTMLInputElement;
32 class SearchPopupMenu;
34 class RenderSearchField : public RenderTextControlSingleLine, private PopupMenuClient {
36 RenderSearchField(Node*);
37 virtual ~RenderSearchField();
39 void updateCancelButtonVisibility() const;
41 void addSearchResult();
42 void stopSearchEventTimer();
44 bool popupIsVisible() const { return m_searchPopupIsVisible; }
49 virtual void centerContainerIfNeeded(RenderBox*) const OVERRIDE;
50 virtual LayoutUnit computeControlHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const OVERRIDE;
51 virtual LayoutUnit computeHeightLimit() const OVERRIDE;
52 virtual void updateFromElement() OVERRIDE;
53 EVisibility visibilityForCancelButton() const;
54 const AtomicString& autosaveName() const;
56 // PopupMenuClient methods
57 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRIDE;
58 virtual void selectionChanged(unsigned, bool) OVERRIDE { }
59 virtual void selectionCleared() OVERRIDE { }
60 virtual String itemText(unsigned listIndex) const OVERRIDE;
61 virtual String itemLabel(unsigned listIndex) const OVERRIDE;
62 virtual String itemIcon(unsigned listIndex) const OVERRIDE;
63 virtual String itemToolTip(unsigned) const OVERRIDE { return String(); }
64 virtual String itemAccessibilityText(unsigned) const OVERRIDE { return String(); }
65 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
66 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
67 virtual PopupMenuStyle menuStyle() const OVERRIDE;
68 virtual int clientInsetLeft() const OVERRIDE;
69 virtual int clientInsetRight() const OVERRIDE;
70 virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
71 virtual LayoutUnit clientPaddingRight() const OVERRIDE;
72 virtual int listSize() const OVERRIDE;
73 virtual int selectedIndex() const OVERRIDE;
74 virtual void popupDidHide() OVERRIDE;
75 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
76 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
77 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
78 virtual bool shouldPopOver() const OVERRIDE { return false; }
79 virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return false; }
80 virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
81 virtual FontSelector* fontSelector() const OVERRIDE;
82 virtual HostWindow* hostWindow() const OVERRIDE;
83 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE;
85 HTMLElement* resultsButtonElement() const;
86 HTMLElement* cancelButtonElement() const;
88 bool m_searchPopupIsVisible;
89 RefPtr<SearchPopupMenu> m_searchPopup;
90 Vector<String> m_recentSearches;
93 inline RenderSearchField* toRenderSearchField(RenderObject* object)
95 ASSERT(!object || object->isTextField());
96 return static_cast<RenderSearchField*>(object);
99 // This will catch anyone doing an unnecessary cast.
100 void toRenderSearchField(const RenderSearchField*);