2 * This file is part of the DOM implementation for KDE.
4 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "render_br.h"
24 #include "dom_position.h"
25 #include "render_block.h"
26 #include "render_line.h"
28 using namespace khtml;
31 RenderBR::RenderBR(DOM::NodeImpl* node)
32 : RenderText(node, new DOM::DOMStringImpl(QChar('\n'))),
41 InlineBox* RenderBR::createInlineBox(bool makePlaceholder, bool isRootLineBox, bool isOnlyRun)
43 // We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
44 // (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
45 InlineTextBox* box = static_cast<InlineTextBox*>(RenderText::createInlineBox(makePlaceholder, isRootLineBox, isOnlyRun));
46 box->setIsText(isOnlyRun || document()->inStrictMode());
50 short RenderBR::baselinePosition( bool firstLine, bool isRootLineBox) const
52 if (firstTextBox() && !firstTextBox()->isText())
54 return RenderText::baselinePosition(firstLine, isRootLineBox);
57 short RenderBR::lineHeight(bool firstLine, bool isRootLineBox) const
59 if (firstTextBox() && !firstTextBox()->isText())
63 RenderStyle* s = style(firstLine);
64 Length lh = s->lineHeight();
67 if (m_lineHeight == -1)
68 m_lineHeight = RenderObject::lineHeight(false);
71 return s->fontMetrics().lineSpacing();
74 return lh.minWidth(s->font().pixelSize());
78 if (m_lineHeight == -1)
79 m_lineHeight = RenderObject::lineHeight(false);
83 void RenderBR::setStyle(RenderStyle* _style)
85 RenderText::setStyle(_style);
89 long RenderBR::caretMinOffset() const
94 long RenderBR::caretMaxOffset() const
99 unsigned long RenderBR::caretMaxRenderedOffset() const
104 Position RenderBR::positionForCoordinates(int _x, int _y, EAffinity *affinity)
107 *affinity = UPSTREAM;
108 return Position(element(), 0);
111 QRect RenderBR::caretRect(int offset, EAffinity affinity, int *extraWidthToEndOfLine)
113 // EDIT FIXME: This does not work yet. Some other changes are need before
114 // an accurate position can be determined.
117 absolutePosition(absx,absy);
119 if (extraWidthToEndOfLine)
120 *extraWidthToEndOfLine = containingBlockWidth() - xPos();
122 // FIXME: an older version of this code wasn't setting width at
123 // all, using the default of 1...
124 return QRect(xPos() + absx, yPos() + absy, 1, lineHeight(false));
127 InlineBox *RenderBR::inlineBox(long offset, EAffinity affinity)
129 return firstTextBox();