blob: e05c8b4733c157fd43786ccec99cf08c1d89e772 [file] [log] [blame]
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -08001/**
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
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -080043int RenderBR::baselinePosition(bool firstLine, bool isRootLineBox) const
44{
45 if (firstTextBox() && !firstTextBox()->isText())
46 return 0;
47 return RenderText::baselinePosition(firstLine, isRootLineBox);
48}
49
The Android Open Source Project63586082009-03-05 14:34:32 -080050int RenderBR::lineHeight(bool firstLine, bool /*isRootLineBox*/) const
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -080051{
52 if (firstTextBox() && !firstTextBox()->isText())
53 return 0;
54
55 if (firstLine) {
56 RenderStyle* s = style(firstLine);
57 Length lh = s->lineHeight();
58 if (lh.isNegative()) {
59 if (s == style()) {
60 if (m_lineHeight == -1)
61 m_lineHeight = RenderObject::lineHeight(false);
62 return m_lineHeight;
63 }
64 return s->font().lineSpacing();
65 }
66 if (lh.isPercent())
Steve Blockcac0f672009-11-05 09:23:40 +000067 return lh.calcMinValue(s->fontSize(), true);
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -080068 return lh.value();
69 }
70
71 if (m_lineHeight == -1)
72 m_lineHeight = RenderObject::lineHeight(false);
73 return m_lineHeight;
74}
75
Feng Qian8f72e702009-04-10 18:11:29 -070076void RenderBR::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -080077{
78 RenderText::styleDidChange(diff, oldStyle);
79 m_lineHeight = -1;
80}
81
82int RenderBR::caretMinOffset() const
83{
84 return 0;
85}
86
87int RenderBR::caretMaxOffset() const
88{
89 return 1;
90}
91
92unsigned RenderBR::caretMaxRenderedOffset() const
93{
94 return 1;
95}
96
Feng Qian8f72e702009-04-10 18:11:29 -070097VisiblePosition RenderBR::positionForPoint(const IntPoint&)
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -080098{
Feng Qian8f72e702009-04-10 18:11:29 -070099 return createVisiblePosition(0, DOWNSTREAM);
The Android Open Source Project8e35f3c2009-03-03 19:30:52 -0800100}
101
102} // namespace WebCore