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 | |
23 | #pragma once |
24 | |
25 | #include "HTMLInputElement.h" |
26 | #include "RenderTextControl.h" |
27 | |
28 | namespace WebCore { |
29 | |
30 | class RenderTextControlSingleLine : public RenderTextControl { |
31 | WTF_MAKE_ISO_ALLOCATED(RenderTextControlSingleLine); |
32 | public: |
33 | RenderTextControlSingleLine(HTMLInputElement&, RenderStyle&&); |
34 | virtual ~RenderTextControlSingleLine(); |
35 | |
36 | protected: |
37 | void centerRenderer(RenderBox& renderer) const; |
38 | HTMLElement* containerElement() const; |
39 | HTMLElement* innerBlockElement() const; |
40 | HTMLInputElement& inputElement() const; |
41 | |
42 | private: |
43 | void textFormControlElement() const = delete; |
44 | |
45 | bool hasControlClip() const override; |
46 | LayoutRect controlClipRect(const LayoutPoint&) const override; |
47 | bool isTextField() const final { return true; } |
48 | |
49 | void layout() override; |
50 | |
51 | bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) override; |
52 | |
53 | void autoscroll(const IntPoint&) override; |
54 | |
55 | // Subclassed to forward to our inner div. |
56 | int scrollLeft() const override; |
57 | int scrollTop() const override; |
58 | int scrollWidth() const override; |
59 | int scrollHeight() const override; |
60 | void setScrollLeft(int, ScrollType, ScrollClamping) override; |
61 | void setScrollTop(int, ScrollType, ScrollClamping) override; |
62 | bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) final; |
63 | bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) final; |
64 | |
65 | int textBlockWidth() const; |
66 | float getAverageCharWidth() override; |
67 | LayoutUnit preferredContentLogicalWidth(float charWidth) const override; |
68 | LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const override; |
69 | |
70 | void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; |
71 | |
72 | HTMLElement* innerSpinButtonElement() const; |
73 | }; |
74 | |
75 | inline HTMLElement* RenderTextControlSingleLine::containerElement() const |
76 | { |
77 | return inputElement().containerElement(); |
78 | } |
79 | |
80 | inline HTMLElement* RenderTextControlSingleLine::innerBlockElement() const |
81 | { |
82 | return inputElement().innerBlockElement(); |
83 | } |
84 | |
85 | // ---------------------------- |
86 | |
87 | class RenderTextControlInnerBlock final : public RenderBlockFlow { |
88 | WTF_MAKE_ISO_ALLOCATED(RenderTextControlInnerBlock); |
89 | public: |
90 | RenderTextControlInnerBlock(Element& element, RenderStyle&& style) |
91 | : RenderBlockFlow(element, WTFMove(style)) |
92 | { |
93 | } |
94 | |
95 | private: |
96 | bool hasLineIfEmpty() const override { return true; } |
97 | bool isTextControlInnerBlock() const override { return true; } |
98 | bool canBeProgramaticallyScrolled() const override |
99 | { |
100 | auto* shadowHost = element()->shadowHost(); |
101 | if (is<HTMLInputElement>(shadowHost)) |
102 | return !downcast<HTMLInputElement>(*shadowHost).hasAutoFillStrongPasswordButton(); |
103 | return true; |
104 | } |
105 | }; |
106 | |
107 | } // namespace WebCore |
108 | |
109 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderTextControlSingleLine, isTextField()) |
110 | SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderTextControlInnerBlock, isTextControlInnerBlock()) |
111 | |