summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/Source/core/layout/LayoutMenuList.h
blob: 808f6788a6d5b5de99b5a68e50e34f340a868fe8 (plain)
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
/*
 * This file is part of the select element layoutObject in WebCore.
 *
 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 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.
 *
 */

#ifndef LayoutMenuList_h
#define LayoutMenuList_h

#include "core/CoreExport.h"
#include "core/layout/LayoutFlexibleBox.h"
#include "platform/geometry/LayoutRect.h"

namespace blink {

class HTMLSelectElement;
class LayoutText;

class CORE_EXPORT LayoutMenuList final : public LayoutFlexibleBox {
public:
    explicit LayoutMenuList(Element*);
    ~LayoutMenuList() override;

    HTMLSelectElement* selectElement() const;
    void setOptionsChanged(bool changed) { m_optionsChanged = changed; }
    void didSetSelectedIndex(int optionIndex);
    String text() const;

    const char* name() const override { return "LayoutMenuList"; }

    LayoutUnit clientPaddingLeft() const;
    LayoutUnit clientPaddingRight() const;

private:
    bool isOfType(LayoutObjectType type) const override { return type == LayoutObjectMenuList || LayoutFlexibleBox::isOfType(type); }
    bool isChildAllowed(LayoutObject*, const ComputedStyle&) const override;

    void addChild(LayoutObject* newChild, LayoutObject* beforeChild = nullptr) override;
    void removeChild(LayoutObject*) override;
    bool createsAnonymousWrapper() const override { return true; }

    void updateFromElement() override;

    LayoutRect controlClipRect(const LayoutPoint&) const override;
    bool hasControlClip() const override { return true; }

    void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;

    void styleDidChange(StyleDifference, const ComputedStyle* oldStyle) 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.
    int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const override
    {
        return LayoutBlock::baselinePosition(baseline, firstLine, direction, position);
    }
    int firstLineBoxBaseline() const override { return LayoutBlock::firstLineBoxBaseline(); }
    int inlineBlockBaseline(LineDirectionMode direction) const override { return LayoutBlock::inlineBlockBaseline(direction); }

    void createInnerBlock();
    void adjustInnerStyle();
    void setText(const String&);
    void setTextFromOption(int optionIndex);
    void updateOptionsWidth();
    float computeTextWidth(const String&) const;
    void updateText();
    void setIndexToSelectOnCancel(int listIndex);

    void didUpdateActiveOption(int optionIndex);

    LayoutText* m_buttonText;
    LayoutBlock* m_innerBlock;

    bool m_optionsChanged : 1;
    bool m_isEmpty : 1;
    bool m_hasUpdatedActiveOption : 1;
    int m_optionsWidth;

    int m_lastActiveIndex;

    RefPtr<ComputedStyle> m_optionStyle;
};

DEFINE_LAYOUT_OBJECT_TYPE_CASTS(LayoutMenuList, isMenuList());

} // namespace blink

#endif