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.
23 #include "RenderTextControlMultiLine.h"
26 #include "HTMLNames.h"
27 #include "HTMLTextAreaElement.h"
28 #include "HitTestResult.h"
29 #include "ShadowRoot.h"
30 #include "TextControlInnerElements.h"
34 RenderTextControlMultiLine::RenderTextControlMultiLine(Node* node)
35 : RenderTextControl(node)
39 RenderTextControlMultiLine::~RenderTextControlMultiLine()
41 if (node() && node()->inDocument())
42 static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
45 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
47 if (!RenderTextControl::nodeAtPoint(request, result, pointInContainer, accumulatedOffset, hitTestAction))
50 if (result.innerNode() == node() || result.innerNode() == innerTextElement())
51 hitInnerTextElement(result, pointInContainer, accumulatedOffset);
56 float RenderTextControlMultiLine::getAvgCharWidth(AtomicString family)
58 // Since Lucida Grande is the default font, we want this to match the width
59 // of Courier New, the default font for textareas in IE, Firefox and Safari Win.
60 // 1229 is the avgCharWidth value in the OS/2 table for Courier New.
61 if (family == AtomicString("Lucida Grande"))
62 return scaleEmToUnits(1229);
64 return RenderTextControl::getAvgCharWidth(family);
67 LayoutUnit RenderTextControlMultiLine::preferredContentWidth(float charWidth) const
69 int factor = static_cast<HTMLTextAreaElement*>(node())->cols();
70 return static_cast<LayoutUnit>(ceilf(charWidth * factor)) + scrollbarThickness();
73 void RenderTextControlMultiLine::adjustControlHeightBasedOnLineHeight(LayoutUnit lineHeight)
75 setHeight(height() + lineHeight * static_cast<HTMLTextAreaElement*>(node())->rows());
78 LayoutUnit RenderTextControlMultiLine::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
80 return RenderBox::baselinePosition(baselineType, firstLine, direction, linePositionMode);
83 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
85 RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();
86 textBlockStyle->inheritFrom(startStyle);
87 adjustInnerTextStyle(startStyle, textBlockStyle.get());
88 textBlockStyle->setDisplay(BLOCK);
90 return textBlockStyle.release();
93 RenderStyle* RenderTextControlMultiLine::textBaseStyle() const
98 RenderObject* RenderTextControlMultiLine::layoutSpecialExcludedChild(bool relayoutChildren)
100 RenderObject* placeholderRenderer = RenderTextControl::layoutSpecialExcludedChild(relayoutChildren);
101 if (!placeholderRenderer)
103 if (!placeholderRenderer->isBox())
104 return placeholderRenderer;
105 RenderBox* placeholderBox = toRenderBox(placeholderRenderer);
106 placeholderBox->style()->setWidth(Length(contentWidth() - placeholderBox->borderAndPaddingWidth(), Fixed));
107 placeholderBox->layoutIfNeeded();
108 placeholderBox->setX(borderLeft() + paddingLeft());
109 placeholderBox->setY(borderTop() + paddingTop());
110 return placeholderRenderer;