RenderBR.cpp revision 8e35f3cfc7fba1d1c829dc557ebad6409cbe16a2
1/** 2 * This file is part of the DOM implementation for KDE. 3 * 4 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 5 * Copyright (C) 2006 Apple Computer, Inc. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 * 22 */ 23 24#include "config.h" 25#include "RenderBR.h" 26 27#include "Document.h" 28#include "InlineTextBox.h" 29#include "VisiblePosition.h" 30 31namespace WebCore { 32 33RenderBR::RenderBR(Node* node) 34 : RenderText(node, StringImpl::create("\n")) 35 , m_lineHeight(-1) 36{ 37} 38 39RenderBR::~RenderBR() 40{ 41} 42 43InlineBox* RenderBR::createInlineBox(bool makePlaceholder, bool isRootLineBox, bool isOnlyRun) 44{ 45 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode 46 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.) 47 InlineTextBox* box = static_cast<InlineTextBox*>(RenderText::createInlineBox(makePlaceholder, isRootLineBox, isOnlyRun)); 48 box->setIsText(isOnlyRun || document()->inStrictMode()); 49 return box; 50} 51 52int RenderBR::baselinePosition(bool firstLine, bool isRootLineBox) const 53{ 54 if (firstTextBox() && !firstTextBox()->isText()) 55 return 0; 56 return RenderText::baselinePosition(firstLine, isRootLineBox); 57} 58 59int RenderBR::lineHeight(bool firstLine, bool isRootLineBox) const 60{ 61 if (firstTextBox() && !firstTextBox()->isText()) 62 return 0; 63 64 if (firstLine) { 65 RenderStyle* s = style(firstLine); 66 Length lh = s->lineHeight(); 67 if (lh.isNegative()) { 68 if (s == style()) { 69 if (m_lineHeight == -1) 70 m_lineHeight = RenderObject::lineHeight(false); 71 return m_lineHeight; 72 } 73 return s->font().lineSpacing(); 74 } 75 if (lh.isPercent()) 76 return lh.calcMinValue(s->fontSize()); 77 return lh.value(); 78 } 79 80 if (m_lineHeight == -1) 81 m_lineHeight = RenderObject::lineHeight(false); 82 return m_lineHeight; 83} 84 85void RenderBR::styleDidChange(RenderStyle::Diff diff, const RenderStyle* oldStyle) 86{ 87 RenderText::styleDidChange(diff, oldStyle); 88 m_lineHeight = -1; 89} 90 91int RenderBR::caretMinOffset() const 92{ 93 return 0; 94} 95 96int RenderBR::caretMaxOffset() const 97{ 98 return 1; 99} 100 101unsigned RenderBR::caretMaxRenderedOffset() const 102{ 103 return 1; 104} 105 106VisiblePosition RenderBR::positionForCoordinates(int /*x*/, int /*y*/) 107{ 108 return VisiblePosition(element(), 0, DOWNSTREAM); 109} 110 111} // namespace WebCore 112