1 /* 2 * Copyright (C) 2000 Lars Knoll (knoll (at) 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) 2014 Adobe Systems 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 #ifndef TrailingObjects_h 25 #define TrailingObjects_h 26 27 #include "wtf/Vector.h" 28 29 namespace blink { 30 31 class InlineIterator; 32 class RenderObject; 33 class RenderText; 34 35 struct BidiRun; 36 37 template <class Iterator, class Run> class BidiResolver; 38 template <class Iterator> class MidpointState; 39 typedef BidiResolver<InlineIterator, BidiRun> InlineBidiResolver; 40 typedef MidpointState<InlineIterator> LineMidpointState; 41 42 // This class allows us to ensure lineboxes are created in the right place on the line when 43 // an out-of-flow positioned object or an empty inline is encountered between a trailing space 44 // and subsequent spaces and we want to ignore (i.e. collapse) surplus whitespace. So for example: 45 // <div>X <span></span> Y</div> 46 // or 47 // <div>X <div style="position: absolute"></div> Y</div> 48 // In both of the above snippets the inline and the positioned object occur after a trailing space 49 // and before a space that will cause our line breaking algorithm to start ignoring spaces. When it 50 // does that we want to ensure that the inline/positioned object gets a linebox and that it is part 51 // of the collapsed whitespace. So to achieve this we use appendObjectIfNeeded() to keep track of 52 // objects encountered after a trailing whitespace and updateMidpointsForTrailingObjects() to put 53 // them in the right place when we start ignoring surplus whitespace. 54 55 class TrailingObjects { 56 public: 57 TrailingObjects() 58 : m_whitespace(0) 59 { 60 } 61 62 void setTrailingWhitespace(RenderText* whitespace) 63 { 64 ASSERT(whitespace); 65 m_whitespace = whitespace; 66 } 67 68 void clear() 69 { 70 m_whitespace = 0; 71 // Using resize(0) rather than clear() here saves 2% on 72 // PerformanceTests/Layout/line-layout.html because we avoid freeing and 73 // re-allocating the underlying buffer repeatedly. 74 m_objects.resize(0); 75 } 76 77 void appendObjectIfNeeded(RenderObject* object) 78 { 79 if (m_whitespace) 80 m_objects.append(object); 81 } 82 83 enum CollapseFirstSpaceOrNot { DoNotCollapseFirstSpace, CollapseFirstSpace }; 84 85 void updateMidpointsForTrailingObjects(LineMidpointState&, const InlineIterator& lBreak, CollapseFirstSpaceOrNot); 86 87 private: 88 RenderText* m_whitespace; 89 Vector<RenderObject*, 4> m_objects; 90 }; 91 92 } 93 94 #endif // TrailingObjects_h 95