1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*
* This file is part of the select element renderer in WebCore.
*
* Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2015 Apple Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#pragma once
#include "LayoutRect.h"
#include "PopupMenu.h"
#include "PopupMenuClient.h"
#include "RenderFlexibleBox.h"
#if PLATFORM(COCOA)
#define POPUP_MENU_PULLS_DOWN 0
#else
#define POPUP_MENU_PULLS_DOWN 1
#endif
namespace WebCore {
class HTMLSelectElement;
class RenderText;
class RenderMenuList final : public RenderFlexibleBox, private PopupMenuClient {
WTF_MAKE_TZONE_OR_ISO_ALLOCATED(RenderMenuList);
WTF_OVERRIDE_DELETE_FOR_CHECKED_PTR(RenderMenuList);
public:
RenderMenuList(HTMLSelectElement&, RenderStyle&&);
virtual ~RenderMenuList();
HTMLSelectElement& selectElement() const;
// CheckedPtr interface.
uint32_t checkedPtrCount() const final { return RenderFlexibleBox::checkedPtrCount(); }
uint32_t checkedPtrCountWithoutThreadCheck() const final { return RenderFlexibleBox::checkedPtrCountWithoutThreadCheck(); }
void incrementCheckedPtrCount() const final { RenderFlexibleBox::incrementCheckedPtrCount(); }
void decrementCheckedPtrCount() const final { RenderFlexibleBox::decrementCheckedPtrCount(); }
#if !PLATFORM(IOS_FAMILY)
bool popupIsVisible() const { return m_popupIsVisible; }
#endif
void showPopup();
void hidePopup();
void setOptionsChanged(bool changed) { m_needsOptionsWidthUpdate = changed; }
void didSetSelectedIndex(int listIndex);
String text() const;
#if PLATFORM(IOS_FAMILY)
void layout() override;
#endif
RenderBlock* innerRenderer() const { return m_innerBlock.get(); }
void setInnerRenderer(RenderBlock&);
void didAttachChild(RenderObject& child, RenderObject* beforeChild);
private:
void willBeDestroyed() override;
void element() const = delete;
bool createsAnonymousWrapper() const override { return true; }
void updateFromElement() override;
LayoutRect controlClipRect(const LayoutPoint&) const override;
bool hasControlClip() const override { return true; }
bool canHaveGeneratedChildren() const override { return false; }
ASCIILiteral renderName() const override { return "RenderMenuList"_s; }
void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
void computePreferredLogicalWidths() override;
void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
// PopupMenuClient methods
void valueChanged(unsigned listIndex, bool fireOnChange = true) override;
void selectionChanged(unsigned, bool) override { }
void selectionCleared() override { }
String itemText(unsigned listIndex) const override;
String itemLabel(unsigned listIndex) const override;
String itemIcon(unsigned listIndex) const override;
String itemToolTip(unsigned listIndex) const override;
String itemAccessibilityText(unsigned listIndex) const override;
bool itemIsEnabled(unsigned listIndex) const override;
PopupMenuStyle itemStyle(unsigned listIndex) const override;
PopupMenuStyle menuStyle() const override;
int clientInsetLeft() const override;
int clientInsetRight() const override;
LayoutUnit clientPaddingLeft() const override;
LayoutUnit clientPaddingRight() const override;
int listSize() const override;
int selectedIndex() const override;
void popupDidHide() override;
bool itemIsSeparator(unsigned listIndex) const override;
bool itemIsLabel(unsigned listIndex) const override;
bool itemIsSelected(unsigned listIndex) const override;
bool shouldPopOver() const override { return !POPUP_MENU_PULLS_DOWN; }
void setTextFromItem(unsigned listIndex) override;
void listBoxSelectItem(int listIndex, bool allowMultiplySelections, bool shift, bool fireOnChangeNow = true) override;
bool multiple() const override;
FontSelector* fontSelector() const override;
HostWindow* hostWindow() const override;
Ref<Scrollbar> createScrollbar(ScrollableArea&, ScrollbarOrientation, ScrollbarWidth) override;
bool hasLineIfEmpty() const override { return true; }
// Flexbox defines baselines differently than regular blocks.
// For backwards compatibility, menulists need to do the regular block behavior.
LayoutUnit baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const override
{
return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
}
std::optional<LayoutUnit> firstLineBaseline() const override { return RenderBlock::firstLineBaseline(); }
std::optional<LayoutUnit> inlineBlockBaseline(LineDirectionMode direction) const override { return RenderBlock::inlineBlockBaseline(direction); }
void getItemBackgroundColor(unsigned listIndex, Color&, bool& itemHasCustomBackgroundColor) const;
void adjustInnerStyle();
void setText(const String&);
void setTextFromOption(int optionIndex);
void updateOptionsWidth();
void didUpdateActiveOption(int optionIndex);
bool isFlexibleBoxImpl() const override { return true; }
SingleThreadWeakPtr<RenderText> m_buttonText;
SingleThreadWeakPtr<RenderBlock> m_innerBlock;
bool m_needsOptionsWidthUpdate;
int m_optionsWidth;
std::optional<int> m_lastActiveIndex;
std::unique_ptr<RenderStyle> m_optionStyle;
#if !PLATFORM(IOS_FAMILY)
RefPtr<PopupMenu> m_popup;
bool m_popupIsVisible;
#endif
};
} // namespace WebCore
SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMenuList, isRenderMenuList())
|