1/*
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#pragma once
23
24#include "RenderBlockFlow.h"
25#include "RenderFlexibleBox.h"
26
27namespace WebCore {
28
29class TextControlInnerTextElement;
30class HTMLTextFormControlElement;
31
32class RenderTextControl : public RenderBlockFlow {
33 WTF_MAKE_ISO_ALLOCATED(RenderTextControl);
34public:
35 virtual ~RenderTextControl();
36
37 WEBCORE_EXPORT HTMLTextFormControlElement& textFormControlElement() const;
38
39#if PLATFORM(IOS_FAMILY)
40 bool canScroll() const;
41
42 // Returns the line height of the inner renderer.
43 int innerLineHeight() const override;
44#endif
45
46protected:
47 RenderTextControl(HTMLTextFormControlElement&, RenderStyle&&);
48
49 // This convenience function should not be made public because innerTextElement may outlive the render tree.
50 RefPtr<TextControlInnerTextElement> innerTextElement() const;
51
52 int scrollbarThickness() const;
53
54 void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override;
55
56 void hitInnerTextElement(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
57
58 int textBlockLogicalWidth() const;
59 int textBlockLogicalHeight() const;
60
61 float scaleEmToUnits(int x) const;
62
63 virtual float getAverageCharWidth();
64 virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const = 0;
65 virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const = 0;
66
67 LogicalExtentComputedValues computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const override;
68 void layoutExcludedChildren(bool relayoutChildren) override;
69
70private:
71 void element() const = delete;
72
73 const char* renderName() const override { return "RenderTextControl"; }
74 bool isTextControl() const final { return true; }
75 void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;
76 void computePreferredLogicalWidths() override;
77 bool avoidsFloats() const override { return true; }
78 bool canHaveGeneratedChildren() const override { return false; }
79
80 void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) override;
81
82 bool canBeProgramaticallyScrolled() const override { return true; }
83};
84
85// Renderer for our inner container, for <search> and others.
86// We can't use RenderFlexibleBox directly, because flexboxes have a different
87// baseline definition, and then inputs of different types wouldn't line up
88// anymore.
89class RenderTextControlInnerContainer final : public RenderFlexibleBox {
90 WTF_MAKE_ISO_ALLOCATED(RenderTextControlInnerContainer);
91public:
92 explicit RenderTextControlInnerContainer(Element& element, RenderStyle&& style)
93 : RenderFlexibleBox(element, WTFMove(style))
94 { }
95 virtual ~RenderTextControlInnerContainer() = default;
96
97 int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const override
98 {
99 return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
100 }
101 Optional<int> firstLineBaseline() const override { return RenderBlock::firstLineBaseline(); }
102 Optional<int> inlineBlockBaseline(LineDirectionMode direction) const override { return RenderBlock::inlineBlockBaseline(direction); }
103
104private:
105 bool isFlexibleBoxImpl() const override { return true; }
106};
107
108} // namespace WebCore
109
110SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderTextControl, isTextControl())
111