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 "core/rendering/RenderTextControlMultiLine.h" 24 25 #include "core/html/HTMLTextAreaElement.h" 26 #include "core/rendering/HitTestResult.h" 27 28 namespace WebCore { 29 30 RenderTextControlMultiLine::RenderTextControlMultiLine(HTMLTextAreaElement* element) 31 : RenderTextControl(element) 32 { 33 ASSERT(element); 34 } 35 36 RenderTextControlMultiLine::~RenderTextControlMultiLine() 37 { 38 if (node() && node()->inDocument()) 39 toHTMLTextAreaElement(node())->rendererWillBeDestroyed(); 40 } 41 42 bool RenderTextControlMultiLine::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction hitTestAction) 43 { 44 if (!RenderTextControl::nodeAtPoint(request, result, locationInContainer, accumulatedOffset, hitTestAction)) 45 return false; 46 47 if (result.innerNode() == node() || result.innerNode() == innerTextElement()) 48 hitInnerTextElement(result, locationInContainer.point(), accumulatedOffset); 49 50 return true; 51 } 52 53 float RenderTextControlMultiLine::getAvgCharWidth(AtomicString family) 54 { 55 // Since Lucida Grande is the default font, we want this to match the width 56 // of Courier New, the default font for textareas in IE, Firefox and Safari Win. 57 // 1229 is the avgCharWidth value in the OS/2 table for Courier New. 58 if (family == "Lucida Grande") 59 return scaleEmToUnits(1229); 60 61 return RenderTextControl::getAvgCharWidth(family); 62 } 63 64 LayoutUnit RenderTextControlMultiLine::preferredContentLogicalWidth(float charWidth) const 65 { 66 int factor = toHTMLTextAreaElement(node())->cols(); 67 return static_cast<LayoutUnit>(ceilf(charWidth * factor)) + scrollbarThickness(); 68 } 69 70 LayoutUnit RenderTextControlMultiLine::computeControlLogicalHeight(LayoutUnit lineHeight, LayoutUnit nonContentHeight) const 71 { 72 return lineHeight * toHTMLTextAreaElement(node())->rows() + nonContentHeight; 73 } 74 75 int RenderTextControlMultiLine::baselinePosition(FontBaseline baselineType, bool firstLine, LineDirectionMode direction, LinePositionMode linePositionMode) const 76 { 77 return RenderBox::baselinePosition(baselineType, firstLine, direction, linePositionMode); 78 } 79 80 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const 81 { 82 RefPtr<RenderStyle> textBlockStyle = RenderStyle::create(); 83 textBlockStyle->inheritFrom(startStyle); 84 adjustInnerTextStyle(textBlockStyle.get()); 85 textBlockStyle->setDisplay(BLOCK); 86 textBlockStyle->setUnique(); 87 88 return textBlockStyle.release(); 89 } 90 91 RenderObject* RenderTextControlMultiLine::layoutSpecialExcludedChild(bool relayoutChildren, SubtreeLayoutScope& layoutScope) 92 { 93 RenderObject* placeholderRenderer = RenderTextControl::layoutSpecialExcludedChild(relayoutChildren, layoutScope); 94 if (!placeholderRenderer) 95 return 0; 96 if (!placeholderRenderer->isBox()) 97 return placeholderRenderer; 98 RenderBox* placeholderBox = toRenderBox(placeholderRenderer); 99 placeholderBox->style()->setLogicalWidth(Length(contentLogicalWidth() - placeholderBox->borderAndPaddingLogicalWidth(), Fixed)); 100 placeholderBox->layoutIfNeeded(); 101 placeholderBox->setX(borderLeft() + paddingLeft()); 102 placeholderBox->setY(borderTop() + paddingTop()); 103 return placeholderRenderer; 104 } 105 106 } 107