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#ifndef RenderTextControl_h 23#define RenderTextControl_h 24 25#include "RenderBlockFlow.h" 26#include "RenderFlexibleBox.h" 27 28namespace WebCore { 29 30class TextControlInnerTextElement; 31class HTMLTextFormControlElement; 32 33class RenderTextControl : public RenderBlockFlow { 34public: 35 virtual ~RenderTextControl(); 36 37 HTMLTextFormControlElement& textFormControlElement() const; 38 virtual PassRef<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0; 39 40#if PLATFORM(IOS) 41 bool canScroll() const; 42 43 // Returns the line height of the inner renderer. 44 virtual int innerLineHeight() const override; 45#endif 46 47protected: 48 RenderTextControl(HTMLTextFormControlElement&, PassRef<RenderStyle>); 49 50 // This convenience function should not be made public because innerTextElement may outlive the render tree. 51 TextControlInnerTextElement* innerTextElement() const; 52 53 int scrollbarThickness() const; 54 void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const; 55 56 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) override; 57 58 void hitInnerTextElement(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset); 59 60 int textBlockLogicalWidth() const; 61 int textBlockLogicalHeight() const; 62 63 float scaleEmToUnits(int x) const; 64 65 virtual float getAverageCharWidth(); 66 virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const = 0; 67 virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const = 0; 68 69 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const override; 70 virtual RenderObject* layoutSpecialExcludedChild(bool relayoutChildren) override; 71 72private: 73 void element() const = delete; 74 75 virtual const char* renderName() const override { return "RenderTextControl"; } 76 virtual bool isTextControl() const override final { return true; } 77 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override; 78 virtual void computePreferredLogicalWidths() override; 79 virtual void removeLeftoverAnonymousBlock(RenderBlock*) override { } 80 virtual bool avoidsFloats() const override { return true; } 81 virtual bool canHaveGeneratedChildren() const override { return false; } 82 83 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) override; 84 85 virtual bool canBeProgramaticallyScrolled() const override { return true; } 86 87 virtual bool requiresForcedStyleRecalcPropagation() const override { return true; } 88}; 89 90RENDER_OBJECT_TYPE_CASTS(RenderTextControl, isTextControl()) 91 92// Renderer for our inner container, for <search> and others. 93// We can't use RenderFlexibleBox directly, because flexboxes have a different 94// baseline definition, and then inputs of different types wouldn't line up 95// anymore. 96class RenderTextControlInnerContainer final : public RenderFlexibleBox { 97public: 98 explicit RenderTextControlInnerContainer(Element& element, PassRef<RenderStyle> style) 99 : RenderFlexibleBox(element, WTF::move(style)) 100 { } 101 virtual ~RenderTextControlInnerContainer() { } 102 103 virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const override 104 { 105 return RenderBlock::baselinePosition(baseline, firstLine, direction, position); 106 } 107 virtual int firstLineBaseline() const override { return RenderBlock::firstLineBaseline(); } 108 virtual int inlineBlockBaseline(LineDirectionMode direction) const override { return RenderBlock::inlineBlockBaseline(direction); } 109 110}; 111 112 113} // namespace WebCore 114 115#endif // RenderTextControl_h 116