RenderSearchField.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  5. *
  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.
  10. *
  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.
  15. *
  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.
  20. *
  21. */
  22. #ifndef RenderSearchField_h
  23. #define RenderSearchField_h
  24. #include "PopupMenuClient.h"
  25. #include "RenderTextControlSingleLine.h"
  26. namespace WebCore {
  27. class HTMLInputElement;
  28. class SearchPopupMenu;
  29. class RenderSearchField : public RenderTextControlSingleLine, private PopupMenuClient {
  30. public:
  31. RenderSearchField(Element*);
  32. virtual ~RenderSearchField();
  33. void updateCancelButtonVisibility() const;
  34. void addSearchResult();
  35. void stopSearchEventTimer();
  36. bool popupIsVisible() const { return m_searchPopupIsVisible; }
  37. void showPopup();
  38. void hidePopup();
  39. private:
  40. virtual void centerContainerIfNeeded(RenderBox*) const OVERRIDE;
  41. virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const OVERRIDE;
  42. virtual LayoutUnit computeLogicalHeightLimit() const OVERRIDE;
  43. virtual void updateFromElement() OVERRIDE;
  44. EVisibility visibilityForCancelButton() const;
  45. const AtomicString& autosaveName() const;
  46. // PopupMenuClient methods
  47. virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRIDE;
  48. virtual void selectionChanged(unsigned, bool) OVERRIDE { }
  49. virtual void selectionCleared() OVERRIDE { }
  50. virtual String itemText(unsigned listIndex) const OVERRIDE;
  51. virtual String itemLabel(unsigned listIndex) const OVERRIDE;
  52. virtual String itemIcon(unsigned listIndex) const OVERRIDE;
  53. virtual String itemToolTip(unsigned) const OVERRIDE { return String(); }
  54. virtual String itemAccessibilityText(unsigned) const OVERRIDE { return String(); }
  55. virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
  56. virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
  57. virtual PopupMenuStyle menuStyle() const OVERRIDE;
  58. virtual int clientInsetLeft() const OVERRIDE;
  59. virtual int clientInsetRight() const OVERRIDE;
  60. virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
  61. virtual LayoutUnit clientPaddingRight() const OVERRIDE;
  62. virtual int listSize() const OVERRIDE;
  63. virtual int selectedIndex() const OVERRIDE;
  64. virtual void popupDidHide() OVERRIDE;
  65. virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
  66. virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
  67. virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
  68. virtual bool shouldPopOver() const OVERRIDE { return false; }
  69. virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return false; }
  70. virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
  71. virtual FontSelector* fontSelector() const OVERRIDE;
  72. virtual HostWindow* hostWindow() const OVERRIDE;
  73. virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE;
  74. HTMLElement* resultsButtonElement() const;
  75. HTMLElement* cancelButtonElement() const;
  76. bool m_searchPopupIsVisible;
  77. RefPtr<SearchPopupMenu> m_searchPopup;
  78. Vector<String> m_recentSearches;
  79. };
  80. inline RenderSearchField* toRenderSearchField(RenderObject* object)
  81. {
  82. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTextField());
  83. return static_cast<RenderSearchField*>(object);
  84. }
  85. // This will catch anyone doing an unnecessary cast.
  86. void toRenderSearchField(const RenderSearchField*);
  87. }
  88. #endif