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 "StyleInheritedData.h"
31
#include "TextControlInnerElements.h"
35
RenderTextControlMultiLine::RenderTextControlMultiLine(Node* node)
36
: RenderTextControl(node)
40
RenderTextControlMultiLine::~RenderTextControlMultiLine()
42
if (node() && node()->inDocument())
43
static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
46
bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
48
if (!RenderTextControl::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction))
51
if (result.innerNode() == node() || result.innerNode() == innerTextElement())
52
hitInnerTextElement(result, locationInContainer.point(), accumulatedOffset);
57
float RenderTextControlMultiLine::getAvgCharWidth(AtomicString family)
59
// Since Lucida Grande is the default font, we want this to match the width
60
// of Courier New, the default font for textareas in IE, Firefox and Safari Win.
61
// 1229 is the avgCharWidth value in the OS/2 table for Courier New.
62
if (family == "Lucida Grande")
63
return scaleEmToUnits(1229);
65
return RenderTextControl::getAvgCharWidth(family);
68
LayoutUnit RenderTextControlMultiLine::preferredContentWidth(float charWidth) const
70
int factor = static_cast<HTMLTextAreaElement*>(node())->cols();
71
return static_cast<LayoutUnit>(ceilf(charWidth * factor)) + scrollbarThickness();
74
LayoutUnit RenderTextControlMultiLine::computeControlHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const
76
return lineHeight * static_cast<HTMLTextAreaElement*>(node())->rows() + nonContentHeight;
79
int RenderTextControlMultiLine::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
81
return RenderBox::baselinePosition(baselineType, firstLine, direction, linePositionMode);
84
PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
86
RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();
87
textBlockStyle->inheritFrom(startStyle);
88
adjustInnerTextStyle(startStyle, textBlockStyle.get());
89
textBlockStyle->setDisplay(BLOCK);
91
return textBlockStyle.release();
94
RenderStyle* RenderTextControlMultiLine::textBaseStyle() const
99
RenderObject* RenderTextControlMultiLine::layoutSpecialExcludedChild(bool relayoutChildren)
101
RenderObject* placeholderRenderer = RenderTextControl::layoutSpecialExcludedChild(relayoutChildren);
102
if (!placeholderRenderer)
104
if (!placeholderRenderer->isBox())
105
return placeholderRenderer;
106
RenderBox* placeholderBox = toRenderBox(placeholderRenderer);
107
placeholderBox->style()->setWidth(Length(contentWidth() - placeholderBox->borderAndPaddingWidth(), Fixed));
108
placeholderBox->layoutIfNeeded();
109
placeholderBox->setX(borderLeft() + paddingLeft());
110
placeholderBox->setY(borderTop() + paddingTop());
111
return placeholderRenderer;