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 30namespace WebCore { 31 32void TrailingObjects::updateMidpointsForTrailingBoxes(LineMidpointState& lineMidpointState, 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 midpoint, 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 (lineMidpointState.numMidpoints() % 2) { 40 // Find the trailing space object's midpoint. 41 int trailingSpaceMidpoint = lineMidpointState.numMidpoints() - 1; 42 for ( ; trailingSpaceMidpoint > 0 && lineMidpointState.midpoints()[trailingSpaceMidpoint].renderer() != m_whitespace; --trailingSpaceMidpoint) { } 43 ASSERT(trailingSpaceMidpoint >= 0); 44 if (collapseFirstSpace == CollapseFirstSpace) 45 lineMidpointState.midpoints()[trailingSpaceMidpoint].fastDecrement(); 46 47 // Now make sure every single trailingPositionedBox following the trailingSpaceMidpoint properly stops and starts 48 // ignoring spaces. 49 size_t currentMidpoint = trailingSpaceMidpoint + 1; 50 for (size_t i = 0; i < m_boxes.size(); ++i) { 51 if (currentMidpoint >= lineMidpointState.numMidpoints()) { 52 // We don't have a midpoint for this box yet. 53 lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]); 54 } else { 55 ASSERT(lineMidpointState.midpoints()[currentMidpoint].renderer() == m_boxes[i]); 56 ASSERT(lineMidpointState.midpoints()[currentMidpoint + 1].renderer() == m_boxes[i]); 57 } 58 currentMidpoint += 2; 59 } 60 } else if (!lBreak.renderer()) { 61 ASSERT(m_whitespace->isText()); 62 ASSERT(collapseFirstSpace == CollapseFirstSpace); 63 // Add a new end midpoint that stops right at the very end. 64 unsigned length = m_whitespace->textLength(); 65 unsigned pos = length >= 2 ? length - 2 : UINT_MAX; 66 InlineIterator endMid(0, m_whitespace, pos); 67 lineMidpointState.startIgnoringSpaces(endMid); 68 for (size_t i = 0; i < m_boxes.size(); ++i) 69 lineMidpointState.ensureLineBoxInsideIgnoredSpaces(m_boxes[i]); 70 } 71} 72 73} 74