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 "core/rendering/RenderBlock.h" 26 #include "core/rendering/RenderFlexibleBox.h" 27 28 namespace WebCore { 29 30 class HTMLTextFormControlElement; 31 32 class RenderTextControl : public RenderBlock { 33 public: 34 virtual ~RenderTextControl(); 35 36 HTMLTextFormControlElement* textFormControlElement() const; 37 virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0; 38 39 protected: 40 RenderTextControl(HTMLTextFormControlElement*); 41 42 // This convenience function should not be made public because innerTextElement may outlive the render tree. 43 HTMLElement* innerTextElement() const; 44 45 int scrollbarThickness() const; 46 void adjustInnerTextStyle(RenderStyle* textBlockStyle) const; 47 48 virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle); 49 50 void hitInnerTextElement(HitTestResult&, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset); 51 52 int textBlockLogicalWidth() const; 53 int textBlockLogicalHeight() const; 54 55 float scaleEmToUnits(int x) const; 56 57 static bool hasValidAvgCharWidth(AtomicString family); 58 virtual float getAvgCharWidth(AtomicString family); 59 virtual LayoutUnit preferredContentLogicalWidth(float charWidth) const = 0; 60 virtual LayoutUnit computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const = 0; 61 virtual RenderStyle* textBaseStyle() const = 0; 62 63 virtual void updateFromElement(); 64 virtual void computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop, LogicalExtentComputedValues&) const OVERRIDE; 65 virtual RenderObject* layoutSpecialExcludedChild(bool relayoutChildren); 66 67 private: 68 virtual const char* renderName() const { return "RenderTextControl"; } 69 virtual bool isTextControl() const { return true; } 70 virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const OVERRIDE; 71 virtual void computePreferredLogicalWidths() OVERRIDE; 72 virtual void removeLeftoverAnonymousBlock(RenderBlock*) { } 73 virtual bool avoidsFloats() const { return true; } 74 virtual bool canHaveGeneratedChildren() const OVERRIDE { return false; } 75 virtual bool canBeReplacedWithInlineRunIn() const OVERRIDE; 76 77 virtual void addFocusRingRects(Vector<IntRect>&, const LayoutPoint& additionalOffset, const RenderLayerModelObject* paintContainer = 0) OVERRIDE; 78 79 virtual bool canBeProgramaticallyScrolled() const { return true; } 80 81 virtual bool requiresForcedStyleRecalcPropagation() const { return true; } 82 }; 83 84 inline RenderTextControl* toRenderTextControl(RenderObject* object) 85 { 86 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTextControl()); 87 return static_cast<RenderTextControl*>(object); 88 } 89 90 inline const RenderTextControl* toRenderTextControl(const RenderObject* object) 91 { 92 ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isTextControl()); 93 return static_cast<const RenderTextControl*>(object); 94 } 95 96 // This will catch anyone doing an unnecessary cast. 97 void toRenderTextControl(const RenderTextControl*); 98 99 // Renderer for our inner container, for <search> and others. 100 // We can't use RenderFlexibleBox directly, because flexboxes have a different 101 // baseline definition, and then inputs of different types wouldn't line up 102 // anymore. 103 class RenderTextControlInnerContainer FINAL : public RenderFlexibleBox { 104 public: 105 explicit RenderTextControlInnerContainer(Element* element) 106 : RenderFlexibleBox(element) 107 { } 108 virtual ~RenderTextControlInnerContainer() { } 109 110 virtual int baselinePosition(FontBaseline baseline, bool firstLine, LineDirectionMode direction, LinePositionMode position) const OVERRIDE 111 { 112 return RenderBlock::baselinePosition(baseline, firstLine, direction, position); 113 } 114 virtual int firstLineBoxBaseline() const OVERRIDE { return RenderBlock::firstLineBoxBaseline(); } 115 virtual int inlineBlockBaseline(LineDirectionMode direction) const OVERRIDE { return lastLineBoxBaseline(direction); } 116 117 }; 118 119 120 } // namespace WebCore 121 122 #endif // RenderTextControl_h 123