RenderMenuList.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * This file is part of the select element renderer in WebCore.
  3. *
  4. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
  5. * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public License
  18. * along with this library; see the file COPYING.LIB. If not, write to
  19. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. *
  22. */
  23. #ifndef RenderMenuList_h
  24. #define RenderMenuList_h
  25. #include "LayoutRect.h"
  26. #include "PopupMenu.h"
  27. #include "PopupMenuClient.h"
  28. #include "RenderFlexibleBox.h"
  29. #if PLATFORM(MAC)
  30. #define POPUP_MENU_PULLS_DOWN 0
  31. #else
  32. #define POPUP_MENU_PULLS_DOWN 1
  33. #endif
  34. namespace WebCore {
  35. class HTMLSelectElement;
  36. class RenderText;
  37. class RenderMenuList : public RenderFlexibleBox, private PopupMenuClient {
  38. public:
  39. RenderMenuList(Element*);
  40. virtual ~RenderMenuList();
  41. public:
  42. bool popupIsVisible() const { return m_popupIsVisible; }
  43. void showPopup();
  44. void hidePopup();
  45. void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
  46. void didSetSelectedIndex(int listIndex);
  47. String text() const;
  48. private:
  49. HTMLSelectElement* selectElement() const;
  50. virtual bool isMenuList() const { return true; }
  51. virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
  52. virtual void removeChild(RenderObject*);
  53. virtual bool createsAnonymousWrapper() const { return true; }
  54. virtual void updateFromElement();
  55. virtual LayoutRect controlClipRect(const LayoutPoint&) const;
  56. virtual bool hasControlClip() const { return true; }
  57. virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; }
  58. virtual bool canBeReplacedWithInlineRunIn() const OVERRIDE;
  59. virtual const char* renderName() const { return "RenderMenuList"; }
  60. virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE;
  61. virtual void computePreferredLogicalWidths() OVERRIDE;
  62. virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
  63. virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
  64. // PopupMenuClient methods
  65. virtual void valueChanged(unsigned listIndex, bool fireOnChange = true) OVERRIDE;
  66. virtual void selectionChanged(unsigned, bool) OVERRIDE { }
  67. virtual void selectionCleared() OVERRIDE { }
  68. virtual String itemText(unsigned listIndex) const OVERRIDE;
  69. virtual String itemLabel(unsigned listIndex) const OVERRIDE;
  70. virtual String itemIcon(unsigned listIndex) const OVERRIDE;
  71. virtual String itemToolTip(unsigned listIndex) const OVERRIDE;
  72. virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE;
  73. virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE;
  74. virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE;
  75. virtual PopupMenuStyle menuStyle() const OVERRIDE;
  76. virtual int clientInsetLeft() const OVERRIDE;
  77. virtual int clientInsetRight() const OVERRIDE;
  78. virtual LayoutUnit clientPaddingLeft() const OVERRIDE;
  79. virtual LayoutUnit clientPaddingRight() const OVERRIDE;
  80. virtual int listSize() const OVERRIDE;
  81. virtual int selectedIndex() const OVERRIDE;
  82. virtual void popupDidHide() OVERRIDE;
  83. virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE;
  84. virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE;
  85. virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE;
  86. virtual bool shouldPopOver() const OVERRIDE { return !POPUP_MENU_PULLS_DOWN; }
  87. virtual bool valueShouldChangeOnHotTrack() const OVERRIDE { return true; }
  88. virtual void setTextFromItem(unsigned listIndex) OVERRIDE;
  89. virtual void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) OVERRIDE;
  90. virtual bool multiple() const OVERRIDE;
  91. virtual FontSelector* fontSelector() const OVERRIDE;
  92. virtual HostWindow* hostWindow() const OVERRIDE;
  93. virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize) OVERRIDE;
  94. virtual bool hasLineIfEmpty() const { return true; }
  95. // Flexbox defines baselines differently than regular blocks.
  96. // For backwards compatibility, menulists need to do the regular block behavior.
  97. virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE
  98. {
  99. return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
  100. }
  101. virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); }
  102. virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return RenderBlock::inlineBlockBaseline(direction); }
  103. void getItemBackgroundColor(unsigned listIndex, Color&, bool& itemHasCustomBackgroundColor) const;
  104. void createInnerBlock();
  105. void adjustInnerStyle();
  106. void setText(const String&);
  107. void setTextFromOption(int optionIndex);
  108. void updateOptionsWidth();
  109. void didUpdateActiveOption(int optionIndex);
  110. RenderText* m_buttonText;
  111. RenderBlock* m_innerBlock;
  112. bool m_optionsChanged;
  113. int m_optionsWidth;
  114. int m_lastActiveIndex;
  115. RefPtr<RenderStyle> m_optionStyle;
  116. RefPtr<PopupMenu> m_popup;
  117. bool m_popupIsVisible;
  118. };
  119. inline RenderMenuList* toRenderMenuList(RenderObject* object)
  120. {
  121. ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isMenuList());
  122. return static_cast<RenderMenuList*>(object);
  123. }
  124. // This will catch anyone doing an unnecessary cast.
  125. void toRenderMenuList(const RenderMenuList*);
  126. }
  127. #endif