1/** 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 3 * Copyright (C) 2006 Apple Computer, Inc. 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 "RenderBR.h" 24 25#include "Document.h" 26#include "InlineTextBox.h" 27#include "VisiblePosition.h" 28 29namespace WebCore { 30 31RenderBR::RenderBR(Node* node) 32 : RenderText(node, StringImpl::create("\n")) 33 , m_lineHeight(-1) 34{ 35} 36 37RenderBR::~RenderBR() 38{ 39} 40 41int RenderBR::baselinePosition(bool firstLine, bool isRootLineBox) const 42{ 43 if (firstTextBox() && !firstTextBox()->isText()) 44 return 0; 45 return RenderText::baselinePosition(firstLine, isRootLineBox); 46} 47 48int RenderBR::lineHeight(bool firstLine, bool /*isRootLineBox*/) const 49{ 50 if (firstTextBox() && !firstTextBox()->isText()) 51 return 0; 52 53 if (firstLine) { 54 RenderStyle* s = style(firstLine); 55 Length lh = s->lineHeight(); 56 if (lh.isNegative()) { 57 if (s == style()) { 58 if (m_lineHeight == -1) 59 m_lineHeight = RenderObject::lineHeight(false); 60 return m_lineHeight; 61 } 62 return s->font().lineSpacing(); 63 } 64 if (lh.isPercent()) 65 return lh.calcMinValue(s->fontSize()); 66 return lh.value(); 67 } 68 69 if (m_lineHeight == -1) 70 m_lineHeight = RenderObject::lineHeight(false); 71 return m_lineHeight; 72} 73 74void RenderBR::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) 75{ 76 RenderText::styleDidChange(diff, oldStyle); 77 m_lineHeight = -1; 78} 79 80int RenderBR::caretMinOffset() const 81{ 82 return 0; 83} 84 85int RenderBR::caretMaxOffset() const 86{ 87 return 1; 88} 89 90unsigned RenderBR::caretMaxRenderedOffset() const 91{ 92 return 1; 93} 94 95VisiblePosition RenderBR::positionForPoint(const IntPoint&) 96{ 97 return createVisiblePosition(0, DOWNSTREAM); 98} 99 100} // namespace WebCore 101