| 1 | /* |
| 2 | * Copyright (C) 2000 Lars Knoll (knoll@kde.org) |
| 3 | * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved. |
| 4 | * Copyright (C) 2010 Google Inc. All rights reserved. |
| 5 | * Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com> |
| 6 | * Copyright (C) 2013 Adobe Systems Inc. All right reserved. |
| 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public License |
| 19 | * along with this library; see the file COPYING.LIB. If not, write to |
| 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "TrailingObjects.h" |
| 27 | |
| 28 | #include "InlineIterator.h" |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | void TrailingObjects::updateWhitespaceCollapsingTransitionsForTrailingBoxes(LineWhitespaceCollapsingState& lineWhitespaceCollapsingState, const InlineIterator& lBreak, CollapseFirstSpaceOrNot collapseFirstSpace) |
| 33 | { |
| 34 | if (!m_whitespace) |
| 35 | return; |
| 36 | |
| 37 | // This object is either going to be part of the last transition, or it is going to be the actual endpoint. |
| 38 | // In both cases we just decrease our pos by 1 level to exclude the space, allowing it to - in effect - collapse into the newline. |
| 39 | if (lineWhitespaceCollapsingState.numTransitions() % 2) { |
| 40 | // Find the trailing space object's transition. |
| 41 | int trailingSpaceTransition = lineWhitespaceCollapsingState.numTransitions() - 1; |
| 42 | for ( ; trailingSpaceTransition > 0 && lineWhitespaceCollapsingState.transitions()[trailingSpaceTransition].renderer() != m_whitespace; --trailingSpaceTransition) { } |
| 43 | ASSERT(trailingSpaceTransition >= 0); |
| 44 | if (collapseFirstSpace == CollapseFirstSpace) |
| 45 | lineWhitespaceCollapsingState.decrementTransitionAt(trailingSpaceTransition); |
| 46 | |
| 47 | // Now make sure every single trailingPositionedBox following the trailingSpaceTransition properly stops and starts |
| 48 | // ignoring spaces. |
| 49 | size_t currentTransition = trailingSpaceTransition + 1; |
| 50 | for (size_t i = 0; i < m_boxes.size(); ++i) { |
| 51 | if (currentTransition >= lineWhitespaceCollapsingState.numTransitions()) { |
| 52 | // We don't have a transition for this box yet. |
| 53 | lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]); |
| 54 | } else { |
| 55 | ASSERT(lineWhitespaceCollapsingState.transitions()[currentTransition].renderer() == &(m_boxes[i].get())); |
| 56 | ASSERT(lineWhitespaceCollapsingState.transitions()[currentTransition + 1].renderer() == &(m_boxes[i].get())); |
| 57 | } |
| 58 | currentTransition += 2; |
| 59 | } |
| 60 | } else if (!lBreak.renderer()) { |
| 61 | ASSERT(m_whitespace->isText()); |
| 62 | ASSERT(collapseFirstSpace == CollapseFirstSpace); |
| 63 | // Add a new end transition that stops right at the very end. |
| 64 | unsigned length = m_whitespace->text().length(); |
| 65 | unsigned pos = length >= 2 ? length - 2 : UINT_MAX; |
| 66 | InlineIterator endMid(0, m_whitespace, pos); |
| 67 | lineWhitespaceCollapsingState.startIgnoringSpaces(endMid); |
| 68 | for (size_t i = 0; i < m_boxes.size(); ++i) |
| 69 | lineWhitespaceCollapsingState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | } |
| 74 | |