• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
31 namespace WebCore {
32 
RenderBR(Node * node)33 RenderBR::RenderBR(Node* node)
34     : RenderText(node, StringImpl::create("\n"))
35     , m_lineHeight(-1)
36 {
37 }
38 
~RenderBR()39 RenderBR::~RenderBR()
40 {
41 }
42 
baselinePosition(bool firstLine,bool isRootLineBox) const43 int RenderBR::baselinePosition(bool firstLine, bool isRootLineBox) const
44 {
45     if (firstTextBox() && !firstTextBox()->isText())
46         return 0;
47     return RenderText::baselinePosition(firstLine, isRootLineBox);
48 }
49 
lineHeight(bool firstLine,bool) const50 int RenderBR::lineHeight(bool firstLine, bool /*isRootLineBox*/) const
51 {
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())
67             return lh.calcMinValue(s->fontSize());
68         return lh.value();
69     }
70 
71     if (m_lineHeight == -1)
72         m_lineHeight = RenderObject::lineHeight(false);
73     return m_lineHeight;
74 }
75 
styleDidChange(StyleDifference diff,const RenderStyle * oldStyle)76 void RenderBR::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
77 {
78     RenderText::styleDidChange(diff, oldStyle);
79     m_lineHeight = -1;
80 }
81 
caretMinOffset() const82 int RenderBR::caretMinOffset() const
83 {
84     return 0;
85 }
86 
caretMaxOffset() const87 int RenderBR::caretMaxOffset() const
88 {
89     return 1;
90 }
91 
caretMaxRenderedOffset() const92 unsigned RenderBR::caretMaxRenderedOffset() const
93 {
94     return 1;
95 }
96 
positionForPoint(const IntPoint &)97 VisiblePosition RenderBR::positionForPoint(const IntPoint&)
98 {
99     return createVisiblePosition(0, DOWNSTREAM);
100 }
101 
102 } // namespace WebCore
103