The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 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 | |
| 33 | RenderBR::RenderBR(Node* node) |
| 34 | : RenderText(node, StringImpl::create("\n")) |
| 35 | , m_lineHeight(-1) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | RenderBR::~RenderBR() |
| 40 | { |
| 41 | } |
| 42 | |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 43 | 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 | |
The Android Open Source Project | 6358608 | 2009-03-05 14:34:32 -0800 | [diff] [blame] | 50 | int RenderBR::lineHeight(bool firstLine, bool /*isRootLineBox*/) const |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 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()) |
Steve Block | cac0f67 | 2009-11-05 09:23:40 +0000 | [diff] [blame] | 67 | return lh.calcMinValue(s->fontSize(), true); |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 68 | return lh.value(); |
| 69 | } |
| 70 | |
| 71 | if (m_lineHeight == -1) |
| 72 | m_lineHeight = RenderObject::lineHeight(false); |
| 73 | return m_lineHeight; |
| 74 | } |
| 75 | |
Feng Qian | 8f72e70 | 2009-04-10 18:11:29 -0700 | [diff] [blame] | 76 | void RenderBR::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 77 | { |
| 78 | RenderText::styleDidChange(diff, oldStyle); |
| 79 | m_lineHeight = -1; |
| 80 | } |
| 81 | |
| 82 | int RenderBR::caretMinOffset() const |
| 83 | { |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | int RenderBR::caretMaxOffset() const |
| 88 | { |
| 89 | return 1; |
| 90 | } |
| 91 | |
| 92 | unsigned RenderBR::caretMaxRenderedOffset() const |
| 93 | { |
| 94 | return 1; |
| 95 | } |
| 96 | |
Feng Qian | 8f72e70 | 2009-04-10 18:11:29 -0700 | [diff] [blame] | 97 | VisiblePosition RenderBR::positionForPoint(const IntPoint&) |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 98 | { |
Feng Qian | 8f72e70 | 2009-04-10 18:11:29 -0700 | [diff] [blame] | 99 | return createVisiblePosition(0, DOWNSTREAM); |
The Android Open Source Project | 8e35f3c | 2009-03-03 19:30:52 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | } // namespace WebCore |