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"
25 #include "EventNames.h"
27 #include "HitTestResult.h"
28 #include "HTMLTextAreaElement.h"
32 RenderTextControlMultiLine::RenderTextControlMultiLine(Node* node)
33 : RenderTextControl(node)
37 RenderTextControlMultiLine::~RenderTextControlMultiLine()
40 static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
43 void RenderTextControlMultiLine::subtreeHasChanged()
45 RenderTextControl::subtreeHasChanged();
46 static_cast<Element*>(node())->setFormControlValueMatchesRenderer(false);
48 if (!node()->focused())
51 // Fire the "input" DOM event
52 node()->dispatchEvent(eventNames().inputEvent, true, false);
54 if (Frame* frame = document()->frame())
55 frame->textDidChangeInTextArea(static_cast<Element*>(node()));
58 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction hitTestAction)
60 if (!RenderTextControl::nodeAtPoint(request, result, x, y, tx, ty, hitTestAction))
63 if (result.innerNode() == node() || result.innerNode() == innerTextElement())
64 hitInnerTextElement(result, x, y, tx, ty);
69 void RenderTextControlMultiLine::forwardEvent(Event* event)
71 RenderTextControl::forwardEvent(event);
74 int RenderTextControlMultiLine::preferredContentWidth(float charWidth) const
76 int factor = static_cast<HTMLTextAreaElement*>(node())->cols();
77 return static_cast<int>(ceilf(charWidth * factor)) + scrollbarThickness();
80 void RenderTextControlMultiLine::adjustControlHeightBasedOnLineHeight(int lineHeight)
82 setHeight(height() + lineHeight * static_cast<HTMLTextAreaElement*>(node())->rows());
85 int RenderTextControlMultiLine::baselinePosition(bool, bool) const
87 return height() + marginTop() + marginBottom();
90 void RenderTextControlMultiLine::updateFromElement()
92 createSubtreeIfNeeded(0);
93 RenderTextControl::updateFromElement();
95 setInnerTextValue(static_cast<HTMLTextAreaElement*>(node())->value());
98 void RenderTextControlMultiLine::cacheSelection(int start, int end)
100 static_cast<HTMLTextAreaElement*>(node())->cacheSelection(start, end);
103 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
105 RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();
106 textBlockStyle->inheritFrom(startStyle);
108 adjustInnerTextStyle(startStyle, textBlockStyle.get());
110 // FIXME: This code should just map wrap into CSS in the DOM code.
111 // Then here we should set the textBlockStyle appropriately based off this
112 // object's style()->whiteSpace() and style->wordWrap().
113 // Set word wrap property based on wrap attribute.
114 if (static_cast<HTMLTextAreaElement*>(node())->shouldWrapText()) {
115 textBlockStyle->setWhiteSpace(PRE_WRAP);
116 textBlockStyle->setWordWrap(BreakWordWrap);
118 textBlockStyle->setWhiteSpace(PRE);
119 textBlockStyle->setWordWrap(NormalWordWrap);
122 textBlockStyle->setDisplay(BLOCK);
124 return textBlockStyle.release();