2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
3 * (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
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.
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.
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.
22 #ifndef RenderTextControl_h
23 #define RenderTextControl_h
25 #include "core/rendering/RenderBlockFlow.h"
26 #include "core/rendering/RenderFlexibleBox.h"
30 class HTMLTextFormControlElement;
32 class RenderTextControl : public RenderBlockFlow {
34 virtual ~RenderTextControl();
36 HTMLTextFormControlElement* textFormControlElement() const;
37 virtual PassRefPtr<RenderStyle> createInnerEditorStyle(const RenderStyle* startStyle) const = 0;
40 RenderTextControl(HTMLTextFormControlElement*);
42 // This convenience function should not be made public because
43 // innerEditorElement may outlive the render tree.
44 HTMLElement* innerEditorElement() const;
46 int scrollbarThickness() const;
47 void adjustInnerEditorStyle(RenderStyle* textBlockStyle) const;
49 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE;
51 void hitInnerEditorElement(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset);
53 int textBlockLogicalWidth() const;
54 int textBlockLogicalHeight() const;
56 float scaleEmToUnits(int x) const;
58 static bool hasValidAvgCharWidth(AtomicString family);
59 virtual float getAvgCharWidth(AtomicString family);
60 virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const = 0;
61 virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const = 0;
63 virtual void updateFromElement() OVERRIDE;
64 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE;
65 virtual RenderObject* layoutSpecialExcludedChild(bool relayoutChildren, SubtreeLayoutScope&) OVERRIDE;
67 // We need to override this function because we don't want overflow:hidden on an <input>
68 // to affect the baseline calculation. This is necessary because we are an inline-block
69 // element as an implementation detail which would normally be affected by this.
70 virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return lastLineBoxBaseline(direction); }
73 virtual const char* renderName() const OVERRIDE { return "RenderTextControl"; }
74 virtual bool isTextControl() const OVERRIDE FINAL { return true; }
75 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE FINAL;
76 virtual void computePreferredLogicalWidths() OVERRIDE FINAL;
77 virtual void removeLeftoverAnonymousBlock(RenderBlock*) OVERRIDE FINAL { }
78 virtual bool avoidsFloats() const OVERRIDE FINAL { return true; }
79 virtual bool canHaveGeneratedChildren() const OVERRIDE FINAL { return false; }
81 virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0) OVERRIDE FINAL;
83 virtual void addFocusRingRects(Vector<LayoutRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer) const OVERRIDE FINAL;
85 virtual bool canBeProgramaticallyScrolled() const OVERRIDE FINAL { return true; }
88 DEFINE_RENDER_OBJECT_TYPE_CASTS(RenderTextControl, isTextControl());
90 // Renderer for our inner container, for <search> and others.
91 // We can't use RenderFlexibleBox directly, because flexboxes have a different
92 // baseline definition, and then inputs of different types wouldn't line up
94 class RenderTextControlInnerContainer FINAL : public RenderFlexibleBox {
96 explicit RenderTextControlInnerContainer(Element* element)
97 : RenderFlexibleBox(element)
99 virtual ~RenderTextControlInnerContainer() { }
101 virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE
103 return RenderBlock::baselinePosition(baseline, firstLine, direction, position);
105 virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); }
106 virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return lastLineBoxBaseline(direction); }
112 #endif // RenderTextControl_h