initial import
[vuplus_webkit] / Source / WebCore / rendering / RenderTextControlMultiLine.cpp
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 #include "config.h"
23 #include "RenderTextControlMultiLine.h"
24
25 #include "Frame.h"
26 #include "HTMLNames.h"
27 #include "HTMLTextAreaElement.h"
28 #include "HitTestResult.h"
29 #include "ShadowRoot.h"
30 #include "TextControlInnerElements.h"
31
32 namespace WebCore {
33
34 RenderTextControlMultiLine::RenderTextControlMultiLine(Node* node)
35     : RenderTextControl(node)
36 {
37 }
38
39 RenderTextControlMultiLine::~RenderTextControlMultiLine()
40 {
41     if (node() && node()->inDocument())
42         static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
43 }
44
45 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const LayoutPoint& pointInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction)
46 {
47     if (!RenderTextControl::nodeAtPoint(request, result, pointInContainer, accumulatedOffset, hitTestAction))
48         return false;
49
50     if (result.innerNode() == node() || result.innerNode() == innerTextElement())
51         hitInnerTextElement(result, pointInContainer, accumulatedOffset);
52
53     return true;
54 }
55
56 float RenderTextControlMultiLine::getAvgCharWidth(AtomicString family)
57 {
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);
63
64     return RenderTextControl::getAvgCharWidth(family);
65 }
66
67 LayoutUnit RenderTextControlMultiLine::preferredContentWidth(float charWidth) const
68 {
69     int factor = static_cast<HTMLTextAreaElement*>(node())->cols();
70     return static_cast<LayoutUnit>(ceilf(charWidth * factor)) + scrollbarThickness();
71 }
72
73 void RenderTextControlMultiLine::adjustControlHeightBasedOnLineHeight(LayoutUnit lineHeight)
74 {
75     setHeight(height() + lineHeight * static_cast<HTMLTextAreaElement*>(node())->rows());
76 }
77
78 LayoutUnit RenderTextControlMultiLine::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const
79 {
80     return RenderBox::baselinePosition(baselineType, firstLine, direction, linePositionMode);
81 }
82
83 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
84 {
85     RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();
86     textBlockStyle->inheritFrom(startStyle);
87     adjustInnerTextStyle(startStyle, textBlockStyle.get());
88     textBlockStyle->setDisplay(BLOCK);
89
90     return textBlockStyle.release();
91 }
92
93 RenderStyle* RenderTextControlMultiLine::textBaseStyle() const
94 {
95     return style();
96 }
97
98 RenderObject* RenderTextControlMultiLine::layoutSpecialExcludedChild(bool relayoutChildren)
99 {
100     RenderObject* placeholderRenderer = RenderTextControl::layoutSpecialExcludedChild(relayoutChildren);
101     if (!placeholderRenderer)
102         return 0;
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;
111 }
112     
113 }