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#ifndef RenderTextControlSingleLine_h
24#define RenderTextControlSingleLine_h
25
26#include "HTMLInputElement.h"
27#include "RenderTextControl.h"
28
29namespace WebCore {
30
31class HTMLInputElement;
32
33class RenderTextControlSingleLine : public RenderTextControl {
34public:
35    RenderTextControlSingleLine(Element*);
36    virtual ~RenderTextControlSingleLine();
37    // FIXME: Move create*Style() to their classes.
38    virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const;
39    PassRefPtr<RenderStyle> createInnerBlockStyle(const RenderStyle* startStyle) const;
40
41    void capsLockStateMayHaveChanged();
42
43protected:
44    virtual void centerContainerIfNeeded(RenderBox*) const { }
45    virtual LayoutUnit computeLogicalHeightLimit() const;
46    HTMLElement* containerElement() const;
47    HTMLElement* innerBlockElement() const;
48    HTMLInputElement* inputElement() const;
49    virtual void updateFromElement() OVERRIDE;
50
51private:
52    virtual bool hasControlClip() const;
53    virtual LayoutRect controlClipRect(const LayoutPoint&) const;
54    virtual bool isTextField() const { return true; }
55
56    virtual void paint(PaintInfo&, const LayoutPoint&);
57    virtual void layout();
58
59    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
60
61    virtual void autoscroll(const IntPoint&);
62
63    // Subclassed to forward to our inner div.
64    virtual int scrollLeft() const;
65    virtual int scrollTop() const;
66    virtual int scrollWidth() const;
67    virtual int scrollHeight() const;
68    virtual void setScrollLeft(int);
69    virtual void setScrollTop(int);
70    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
71    virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Node** stopNode = 0);
72
73    int textBlockWidth() const;
74    virtual float getAvgCharWidth(AtomicString family);
75    virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const;
76    virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const OVERRIDE;
77
78    virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
79
80    virtual RenderStyle* textBaseStyle() const;
81
82    bool textShouldBeTruncated() const;
83
84    HTMLElement* innerSpinButtonElement() const;
85
86    bool m_shouldDrawCapsLockIndicator;
87    LayoutUnit m_desiredInnerTextLogicalHeight;
88};
89
90inline HTMLElement* RenderTextControlSingleLine::containerElement() const
91{
92    return inputElement()->containerElement();
93}
94
95inline HTMLElement* RenderTextControlSingleLine::innerBlockElement() const
96{
97    return inputElement()->innerBlockElement();
98}
99
100inline RenderTextControlSingleLine* toRenderTextControlSingleLine(RenderObject* object)
101{
102    ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTextField());
103    return static_cast<RenderTextControlSingleLine*>(object);
104}
105
106// This will catch anyone doing an unnecessary cast.
107void toRenderTextControlSingleLine(const RenderTextControlSingleLine*);
108
109// ----------------------------
110
111class RenderTextControlInnerBlock : public RenderBlock {
112public:
113    RenderTextControlInnerBlock(Element* element) : RenderBlock(element) { }
114
115private:
116    virtual bool hasLineIfEmpty() const { return true; }
117};
118
119}
120
121#endif
122