Diff
Modified: trunk/Source/WTF/wtf/text/TextBreakIterator.h (204530 => 204531)
--- trunk/Source/WTF/wtf/text/TextBreakIterator.h 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WTF/wtf/text/TextBreakIterator.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -78,8 +78,8 @@
resetPriorContext();
}
- LazyLineBreakIterator(String string, const AtomicString& locale = AtomicString(), LineBreakIteratorMode mode = LineBreakIteratorModeUAX14)
- : m_string(string)
+ LazyLineBreakIterator(StringView stringView, const AtomicString& locale = AtomicString(), LineBreakIteratorMode mode = LineBreakIteratorModeUAX14)
+ : m_stringView(stringView)
, m_locale(locale)
, m_iterator(nullptr)
, m_cachedPriorContext(nullptr)
@@ -96,7 +96,7 @@
releaseLineBreakIterator(m_iterator);
}
- String string() const { return m_string; }
+ StringView stringView() const { return m_stringView; }
bool isLooseCJKMode() const { return m_isCJK && m_mode == LineBreakIteratorModeUAX14Loose; }
UChar lastCharacter() const
@@ -152,21 +152,21 @@
ASSERT(priorContextLength <= priorContextCapacity);
const UChar* priorContext = priorContextLength ? &m_priorContext[priorContextCapacity - priorContextLength] : 0;
if (!m_iterator) {
- m_iterator = acquireLineBreakIterator(m_string, m_locale, priorContext, priorContextLength, m_mode, m_isCJK);
+ m_iterator = acquireLineBreakIterator(m_stringView, m_locale, priorContext, priorContextLength, m_mode, m_isCJK);
m_cachedPriorContext = priorContext;
m_cachedPriorContextLength = priorContextLength;
} else if (priorContext != m_cachedPriorContext || priorContextLength != m_cachedPriorContextLength) {
- resetStringAndReleaseIterator(m_string, m_locale, m_mode);
+ resetStringAndReleaseIterator(m_stringView, m_locale, m_mode);
return this->get(priorContextLength);
}
return m_iterator;
}
- void resetStringAndReleaseIterator(String string, const AtomicString& locale, LineBreakIteratorMode mode)
+ void resetStringAndReleaseIterator(StringView stringView, const AtomicString& locale, LineBreakIteratorMode mode)
{
if (m_iterator)
releaseLineBreakIterator(m_iterator);
- m_string = string;
+ m_stringView = stringView;
m_locale = locale;
m_iterator = nullptr;
m_cachedPriorContext = nullptr;
@@ -177,7 +177,7 @@
private:
static const unsigned priorContextCapacity = 2;
- String m_string;
+ StringView m_stringView;
AtomicString m_locale;
TextBreakIterator* m_iterator;
const UChar* m_cachedPriorContext;
Modified: trunk/Source/WebCore/CMakeLists.txt (204530 => 204531)
--- trunk/Source/WebCore/CMakeLists.txt 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/CMakeLists.txt 2016-08-16 22:39:10 UTC (rev 204531)
@@ -2412,6 +2412,7 @@
rendering/AutoTableLayout.cpp
rendering/BidiRun.cpp
rendering/BorderEdge.cpp
+ rendering/BreakLines.cpp
rendering/ClipRect.cpp
rendering/CounterNode.cpp
rendering/EllipsisBox.cpp
@@ -2530,7 +2531,6 @@
rendering/TextDecorationPainter.cpp
rendering/TextPaintStyle.cpp
rendering/TextPainter.cpp
- rendering/break_lines.cpp
rendering/line/LineBreaker.cpp
rendering/line/LineInfo.cpp
Modified: trunk/Source/WebCore/ChangeLog (204530 => 204531)
--- trunk/Source/WebCore/ChangeLog 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/ChangeLog 2016-08-16 22:39:10 UTC (rev 204531)
@@ -1,3 +1,65 @@
+2016-08-16 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ Migrate line breaking code from ints to Optional<unsigned>s
+ https://bugs.webkit.org/show_bug.cgi?id=160859
+
+ Reviewed by Darin Adler.
+
+ Previously, we were using -1 to mean "before the beginning of the string". Now,
+ Nullopt means that.
+
+ This patch also renames break_lines.{h,cpp} to BreakLines.{h.cpp}. This file was
+ originally named during the KHTML days.
+
+ No new tests because there is no behavior change.
+
+ * CMakeLists.txt:
+ * WebCore.xcodeproj/project.pbxproj:
+ * rendering/BreakLines.cpp: Renamed from Source/WebCore/rendering/break_lines.cpp.
+ * rendering/BreakLines.h: Renamed from Source/WebCore/rendering/break_lines.h.
+ (WebCore::isBreakableSpace):
+ (WebCore::shouldBreakAfter):
+ (WebCore::needsLineBreakIterator):
+ (WebCore::nextBreakablePositionNonLoosely):
+ (WebCore::nextBreakablePositionLoosely):
+ (WebCore::nextBreakablePositionKeepingAllWords):
+ (WebCore::nextBreakablePositionKeepingAllWordsIgnoringNBSP):
+ (WebCore::nextBreakablePosition):
+ (WebCore::nextBreakablePositionIgnoringNBSP):
+ (WebCore::nextBreakablePositionLoose):
+ (WebCore::nextBreakablePositionIgnoringNBSPLoose):
+ (WebCore::isBreakable):
+ * rendering/InlineIterator.h:
+ (WebCore::InlineIterator::moveTo):
+ (WebCore::InlineIterator::nextBreakablePosition):
+ (WebCore::InlineIterator::setNextBreakablePosition):
+ (WebCore::InlineIterator::InlineIterator): Deleted.
+ * rendering/InlineTextBox.cpp:
+ * rendering/RenderText.cpp:
+ (WebCore::RenderText::computePreferredLogicalWidths):
+ * rendering/RenderingAllInOne.cpp:
+ * rendering/SimpleLineLayoutTextFragmentIterator.h:
+ * rendering/break_lines.h:
+ (WebCore::isBreakableSpace): Deleted.
+ (WebCore::shouldBreakAfter): Deleted.
+ (WebCore::needsLineBreakIterator): Deleted.
+ (WebCore::nextBreakablePositionNonLoosely): Deleted.
+ (WebCore::nextBreakablePositionLoosely): Deleted.
+ (WebCore::nextBreakablePositionKeepingAllWords): Deleted.
+ (WebCore::nextBreakablePositionKeepingAllWordsIgnoringNBSP): Deleted.
+ (WebCore::nextBreakablePosition): Deleted.
+ (WebCore::nextBreakablePositionIgnoringNBSP): Deleted.
+ (WebCore::nextBreakablePositionLoose): Deleted.
+ (WebCore::nextBreakablePositionIgnoringNBSPLoose): Deleted.
+ (WebCore::isBreakable): Deleted.
+ * rendering/line/BreakingContext.h:
+ (WebCore::BreakingContext::commitLineBreakAtCurrentWidth):
+ (WebCore::BreakingContext::InlineIteratorHistory::nextBreakablePosition):
+ (WebCore::BreakingContext::InlineIteratorHistory::moveTo):
+ (WebCore::tryHyphenating):
+ (WebCore::BreakingContext::handleText):
+ (WebCore::BreakingContext::optimalLineBreakLocationForTrailingWord):
+
2016-08-16 Chris Dumez <cdu...@apple.com>
DOM4: getElementsByClassName should include non StyledElements
Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (204530 => 204531)
--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj 2016-08-16 22:39:10 UTC (rev 204531)
@@ -5671,8 +5671,7 @@
BCEA478F097CAAC80094C9E4 /* CSSComputedStyleDeclaration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA477C097CAAC80094C9E4 /* CSSComputedStyleDeclaration.cpp */; };
BCEA4790097CAAC80094C9E4 /* CSSComputedStyleDeclaration.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA477D097CAAC80094C9E4 /* CSSComputedStyleDeclaration.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCEA4852097D93020094C9E4 /* RenderBlockLineLayout.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4813097D93020094C9E4 /* RenderBlockLineLayout.cpp */; };
- BCEA4854097D93020094C9E4 /* break_lines.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4815097D93020094C9E4 /* break_lines.cpp */; };
- BCEA4855097D93020094C9E4 /* break_lines.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4816097D93020094C9E4 /* break_lines.h */; settings = {ATTRIBUTES = (Private, ); }; };
+ BCEA4854097D93020094C9E4 /* BreakLines.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4815097D93020094C9E4 /* BreakLines.cpp */; };
BCEA4859097D93020094C9E4 /* InlineTextBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA481A097D93020094C9E4 /* InlineTextBox.cpp */; };
BCEA485A097D93020094C9E4 /* InlineTextBox.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA481B097D93020094C9E4 /* InlineTextBox.h */; settings = {ATTRIBUTES = (Private, ); }; };
BCEA485F097D93020094C9E4 /* RenderBlock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEA4820097D93020094C9E4 /* RenderBlock.cpp */; };
@@ -5791,6 +5790,7 @@
C280833F1C6DC26F001451B6 /* JSFontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = C280833E1C6DC22C001451B6 /* JSFontFace.h */; };
C28083401C6DC275001451B6 /* JSFontFace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C280833D1C6DC22C001451B6 /* JSFontFace.cpp */; };
C28083421C6DC96A001451B6 /* JSFontFaceCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C28083411C6DC96A001451B6 /* JSFontFaceCustom.cpp */; };
+ C2E1F43F1D6254E10094625C /* BreakLines.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEA4816097D93020094C9E4 /* BreakLines.h */; settings = {ATTRIBUTES = (Private, ); }; };
C330A22313EC196B0000B45B /* ColorChooser.h in Headers */ = {isa = PBXBuildFile; fileRef = C330A22113EC196B0000B45B /* ColorChooser.h */; settings = {ATTRIBUTES = (Private, ); }; };
C33EE5C414FB49610002095A /* BaseClickableWithKeyInputType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C33EE5C214FB49610002095A /* BaseClickableWithKeyInputType.cpp */; };
C33EE5C514FB49610002095A /* BaseClickableWithKeyInputType.h in Headers */ = {isa = PBXBuildFile; fileRef = C33EE5C314FB49610002095A /* BaseClickableWithKeyInputType.h */; };
@@ -13490,8 +13490,8 @@
BCEA4789097CAAC80094C9E4 /* CSSPropertyNames.in */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CSSPropertyNames.in; sourceTree = "<group>"; };
BCEA478C097CAAC80094C9E4 /* CSSValueKeywords.in */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CSSValueKeywords.in; sourceTree = "<group>"; };
BCEA4813097D93020094C9E4 /* RenderBlockLineLayout.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderBlockLineLayout.cpp; sourceTree = "<group>"; };
- BCEA4815097D93020094C9E4 /* break_lines.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = break_lines.cpp; sourceTree = "<group>"; };
- BCEA4816097D93020094C9E4 /* break_lines.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = break_lines.h; sourceTree = "<group>"; };
+ BCEA4815097D93020094C9E4 /* BreakLines.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = BreakLines.cpp; sourceTree = "<group>"; };
+ BCEA4816097D93020094C9E4 /* BreakLines.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = BreakLines.h; sourceTree = "<group>"; };
BCEA481A097D93020094C9E4 /* InlineTextBox.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InlineTextBox.cpp; sourceTree = "<group>"; };
BCEA481B097D93020094C9E4 /* InlineTextBox.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = InlineTextBox.h; sourceTree = "<group>"; };
BCEA4820097D93020094C9E4 /* RenderBlock.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = RenderBlock.cpp; sourceTree = "<group>"; };
@@ -23634,8 +23634,8 @@
BCE789851120E7A60060ECE5 /* BidiRun.h */,
58AEE2F318D4BCCF0022E7FE /* BorderEdge.cpp */,
589556EC18D4A44000764B03 /* BorderEdge.h */,
- BCEA4815097D93020094C9E4 /* break_lines.cpp */,
- BCEA4816097D93020094C9E4 /* break_lines.h */,
+ BCEA4815097D93020094C9E4 /* BreakLines.cpp */,
+ BCEA4816097D93020094C9E4 /* BreakLines.h */,
FB92DF4915FED08700994433 /* ClipPathOperation.h */,
5803715F1A66F00A00BAF519 /* ClipRect.cpp */,
580371601A66F00A00BAF519 /* ClipRect.h */,
@@ -24918,7 +24918,6 @@
589556ED18D4A44000764B03 /* BorderEdge.h in Headers */,
BC5EB5DB0E81B7EA00B25965 /* BorderValue.h in Headers */,
6ED8C37A183BFF8C009E53BD /* BoxShape.h in Headers */,
- BCEA4855097D93020094C9E4 /* break_lines.h in Headers */,
93309DDB099E64920056E581 /* BreakBlockquoteCommand.h in Headers */,
599E759011055A1F00D904FA /* Bridge.h in Headers */,
59B5977511086579007159E8 /* BridgeJSC.h in Headers */,
@@ -26119,6 +26118,7 @@
FDF09DC91399B62200688E5B /* JSBiquadFilterNode.h in Headers */,
2E2D99CE10E2BBDA00496337 /* JSBlob.h in Headers */,
14DCF3B31B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h in Headers */,
+ C2E1F43F1D6254E10094625C /* BreakLines.h in Headers */,
1449E24C107D4A8400B5793F /* JSCallbackData.h in Headers */,
65DF323A09D1DE65000BE325 /* JSCanvasGradient.h in Headers */,
65DF323C09D1DE65000BE325 /* JSCanvasPattern.h in Headers */,
@@ -28809,7 +28809,7 @@
976D6C7E122B8A3D001FD1F7 /* BlobURL.cpp in Sources */,
58AEE2F418D4BCCF0022E7FE /* BorderEdge.cpp in Sources */,
6ED8C379183BFF8C009E53BD /* BoxShape.cpp in Sources */,
- BCEA4854097D93020094C9E4 /* break_lines.cpp in Sources */,
+ BCEA4854097D93020094C9E4 /* BreakLines.cpp in Sources */,
93309DDA099E64920056E581 /* BreakBlockquoteCommand.cpp in Sources */,
59B597731108656B007159E8 /* BridgeJSC.cpp in Sources */,
7A45032F18DB717200377B34 /* BufferedLineReader.cpp in Sources */,
Copied: trunk/Source/WebCore/rendering/BreakLines.cpp (from rev 204530, trunk/Source/WebCore/rendering/break_lines.cpp) (0 => 204531)
--- trunk/Source/WebCore/rendering/BreakLines.cpp (rev 0)
+++ trunk/Source/WebCore/rendering/BreakLines.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2005, 2007, 2010 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "BreakLines.h"
+
+#include <wtf/ASCIICType.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/unicode/CharacterNames.h>
+
+namespace WebCore {
+
+// Pack 8 bits into one byte
+#define B(a, b, c, d, e, f, g, h) \
+ ((a) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))
+
+// Line breaking table row for each digit (0-9)
+#define DI { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+
+// Line breaking table row for ascii letters (a-z A-Z)
+#define AL { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
+
+#define F 0xFF
+
+// Line breaking table for printable ASCII characters. Line breaking opportunities in this table are as below:
+// - before opening punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
+// - after '-' and '?' (backward-compatible, and compatible with Internet Explorer).
+// Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line breaking matrixes of different browsers
+// and the ICU standard.
+WEBCORE_EXPORT const unsigned char lineBreakTable[][lineBreakTableColumnCount] = {
+ // ! " # $ % & ' ( ) * + , - . / 0 1-8 9 : ; < = > ? @ A-X Y Z [ \ ] ^ _ ` a-x y z { | } ~ DEL
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // !
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // "
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // #
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // $
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // %
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // &
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // '
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // (
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // )
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // *
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // +
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ,
+ { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 0, 1, 0), 0, B(0, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1) }, // - Note: breaking before '0'-'9' is handled hard-coded in shouldBreakAfter().
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // .
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // /
+ DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, // 0-9
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // :
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ;
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // <
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // =
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // >
+ { B(0, 0, 1, 1, 1, 1, 0, 1), B(0, 1, 1, 0, 1, 0, 0, 1), F, B(1, 0, 0, 1, 1, 1, 0, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 0) }, // ?
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // @
+ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // A-Z
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // [
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // '\'
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ]
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ^
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // _
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // `
+ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // a-z
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // {
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // |
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // }
+ { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ~
+ { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // DEL
+};
+
+#undef B
+#undef F
+#undef DI
+#undef AL
+
+COMPILE_ASSERT(WTF_ARRAY_LENGTH(lineBreakTable) == lineBreakTableLastCharacter - lineBreakTableFirstCharacter + 1, TestLineBreakTableConsistency);
+
+} // namespace WebCore
Added: trunk/Source/WebCore/rendering/BreakLines.h (0 => 204531)
--- trunk/Source/WebCore/rendering/BreakLines.h (rev 0)
+++ trunk/Source/WebCore/rendering/BreakLines.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -0,0 +1,255 @@
+/*
+ * Copyright (C) 2005, 2007, 2010, 2013, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2011 Google Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#pragma once
+
+#include <unicode/ubrk.h>
+#include <wtf/ASCIICType.h>
+#include <wtf/StdLibExtras.h>
+#include <wtf/text/TextBreakIterator.h>
+#include <wtf/unicode/CharacterNames.h>
+
+namespace WebCore {
+
+static const UChar lineBreakTableFirstCharacter = '!';
+static const UChar lineBreakTableLastCharacter = 127;
+static const unsigned lineBreakTableColumnCount = (lineBreakTableLastCharacter - lineBreakTableFirstCharacter) / 8 + 1;
+
+WEBCORE_EXPORT extern const unsigned char lineBreakTable[][lineBreakTableColumnCount];
+
+enum class NonBreakingSpaceBehavior {
+ IgnoreNonBreakingSpace,
+ TreatNonBreakingSpaceAsBreak,
+};
+
+template<NonBreakingSpaceBehavior nonBreakingSpaceBehavior>
+static inline bool isBreakableSpace(UChar character)
+{
+ switch (character) {
+ case ' ':
+ case '\n':
+ case '\t':
+ return true;
+ case noBreakSpace:
+ return nonBreakingSpaceBehavior == NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak;
+ default:
+ return false;
+ }
+}
+
+inline bool shouldBreakAfter(UChar lastCharacter, UChar character, UChar nextCharacter)
+{
+ // Don't allow line breaking between '-' and a digit if the '-' may mean a minus sign in the context,
+ // while allow breaking in 'ABCD-1234' and '1234-5678' which may be in long URLs.
+ if (character == '-' && isASCIIDigit(nextCharacter))
+ return isASCIIAlphanumeric(lastCharacter);
+
+ // If both ch and nextCh are ASCII characters, use a lookup table for enhanced speed and for compatibility
+ // with other browsers (see comments for asciiLineBreakTable for details).
+ if (character >= lineBreakTableFirstCharacter && character <= lineBreakTableLastCharacter && nextCharacter >= lineBreakTableFirstCharacter && nextCharacter <= lineBreakTableLastCharacter) {
+ const unsigned char* tableRow = lineBreakTable[character - lineBreakTableFirstCharacter];
+ unsigned nextCharacterIndex = nextCharacter - lineBreakTableFirstCharacter;
+ return tableRow[nextCharacterIndex / 8] & (1 << (nextCharacterIndex % 8));
+ }
+ // Otherwise defer to the Unicode algorithm by returning false.
+ return false;
+}
+
+template<NonBreakingSpaceBehavior nonBreakingSpaceBehavior>
+inline bool needsLineBreakIterator(UChar character)
+{
+ if (nonBreakingSpaceBehavior == NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak)
+ return character > lineBreakTableLastCharacter;
+ return character > lineBreakTableLastCharacter && character != noBreakSpace;
+}
+
+// When in non-loose mode, we can use the ASCII shortcut table.
+template<typename CharacterType, NonBreakingSpaceBehavior nonBreakingSpaceBehavior>
+inline unsigned nextBreakablePositionNonLoosely(LazyLineBreakIterator& lazyBreakIterator, const CharacterType* string, unsigned length, unsigned startPosition)
+{
+ Optional<unsigned> nextBreak;
+
+ CharacterType lastLastCharacter = startPosition > 1 ? string[startPosition - 2] : static_cast<CharacterType>(lazyBreakIterator.secondToLastCharacter());
+ CharacterType lastCharacter = startPosition > 0 ? string[startPosition - 1] : static_cast<CharacterType>(lazyBreakIterator.lastCharacter());
+ unsigned priorContextLength = lazyBreakIterator.priorContextLength();
+ for (unsigned i = startPosition; i < length; i++) {
+ CharacterType character = string[i];
+
+ // Non-loose mode, so use ASCII shortcut (shouldBreakAfter) if not breakable space.
+ if (isBreakableSpace<nonBreakingSpaceBehavior>(character) || shouldBreakAfter(lastLastCharacter, lastCharacter, character))
+ return i;
+
+ // Non-loose mode, so conditionally use break iterator.
+ if (needsLineBreakIterator<nonBreakingSpaceBehavior>(character) || needsLineBreakIterator<nonBreakingSpaceBehavior>(lastCharacter)) {
+ if (!nextBreak || nextBreak.value() < i) {
+ // Don't break if positioned at start of primary context and there is no prior context.
+ if (i || priorContextLength) {
+ TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
+ if (breakIterator) {
+ int candidate = textBreakFollowing(breakIterator, i - 1 + priorContextLength);
+ if (candidate == TextBreakDone)
+ nextBreak = Nullopt;
+ else {
+ unsigned result = candidate;
+ ASSERT(result >= priorContextLength);
+ nextBreak = result - priorContextLength;
+ }
+ }
+ }
+ }
+ if (i == nextBreak && !isBreakableSpace<nonBreakingSpaceBehavior>(lastCharacter))
+ return i;
+ }
+
+ lastLastCharacter = lastCharacter;
+ lastCharacter = character;
+ }
+
+ return length;
+}
+
+// When in loose mode, we can't use the ASCII shortcut table since loose mode allows "$100" to break after '$' in content marked as CJK.
+// N.B. It should be possible to combine the following with the non-loose version above by adding a LooseBehavior template parameter;
+// however, when doing this, a 10% performance regression appeared on chromium-win (https://bugs.webkit.org/show_bug.cgi?id=89235#c112).
+template<typename CharacterType, NonBreakingSpaceBehavior nonBreakingSpaceBehavior>
+static inline unsigned nextBreakablePositionLoosely(LazyLineBreakIterator& lazyBreakIterator, const CharacterType* string, unsigned length, unsigned startPosition)
+{
+ Optional<unsigned> nextBreak;
+
+ CharacterType lastCharacter = startPosition > 0 ? string[startPosition - 1] : static_cast<CharacterType>(lazyBreakIterator.lastCharacter());
+ unsigned priorContextLength = lazyBreakIterator.priorContextLength();
+ for (unsigned i = startPosition; i < length; i++) {
+ CharacterType character = string[i];
+
+ // Always loose mode, so don't use ASCII shortcut (shouldBreakAfter).
+ if (isBreakableSpace<nonBreakingSpaceBehavior>(character))
+ return i;
+
+ // Always use line break iterator in loose mode.
+ if (!nextBreak || nextBreak.value() < i) {
+ // Don't break if positioned at start of primary context and there is no prior context.
+ if (i || priorContextLength) {
+ TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
+ if (breakIterator) {
+ ASSERT(i + priorContextLength >= 1);
+ int candidate = textBreakFollowing(breakIterator, i + priorContextLength - 1);
+ if (candidate == TextBreakDone)
+ nextBreak = Nullopt;
+ else {
+ unsigned result = candidate;
+ ASSERT(result > priorContextLength);
+ nextBreak = result - priorContextLength;
+ }
+ }
+ }
+ }
+ if (i == nextBreak && !isBreakableSpace<nonBreakingSpaceBehavior>(lastCharacter))
+ return i;
+
+ lastCharacter = character;
+ }
+
+ return length;
+}
+
+template<typename CharacterType, NonBreakingSpaceBehavior nonBreakingSpaceBehavior>
+inline unsigned nextBreakablePositionKeepingAllWords(const CharacterType* string, unsigned length, unsigned startPosition)
+{
+ for (unsigned i = startPosition; i < length; i++) {
+ if (isBreakableSpace<nonBreakingSpaceBehavior>(string[i]))
+ return i;
+ }
+ return length;
+}
+
+inline unsigned nextBreakablePositionKeepingAllWords(LazyLineBreakIterator& lazyBreakIterator, unsigned startPosition)
+{
+ auto stringView = lazyBreakIterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionKeepingAllWords<LChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionKeepingAllWords<UChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline unsigned nextBreakablePositionKeepingAllWordsIgnoringNBSP(LazyLineBreakIterator& iterator, unsigned startPosition)
+{
+ auto stringView = iterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionKeepingAllWords<LChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionKeepingAllWords<UChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline unsigned nextBreakablePosition(LazyLineBreakIterator& iterator, unsigned startPosition)
+{
+ auto stringView = iterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionNonLoosely<LChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(iterator, stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionNonLoosely<UChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(iterator, stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline unsigned nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, unsigned startPosition)
+{
+ auto stringView = lazyBreakIterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionNonLoosely<LChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(lazyBreakIterator, stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionNonLoosely<UChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(lazyBreakIterator, stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline unsigned nextBreakablePositionLoose(LazyLineBreakIterator& lazyBreakIterator, unsigned startPosition)
+{
+ auto stringView = lazyBreakIterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionLoosely<LChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(lazyBreakIterator, stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionLoosely<UChar, NonBreakingSpaceBehavior::TreatNonBreakingSpaceAsBreak>(lazyBreakIterator, stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline unsigned nextBreakablePositionIgnoringNBSPLoose(LazyLineBreakIterator& lazyBreakIterator, unsigned startPosition)
+{
+ auto stringView = lazyBreakIterator.stringView();
+ if (stringView.is8Bit())
+ return nextBreakablePositionLoosely<LChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(lazyBreakIterator, stringView.characters8(), stringView.length(), startPosition);
+ return nextBreakablePositionLoosely<UChar, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(lazyBreakIterator, stringView.characters16(), stringView.length(), startPosition);
+}
+
+inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, unsigned startPosition, Optional<unsigned>& nextBreakable, bool breakNBSP, bool isLooseMode, bool keepAllWords)
+{
+ if (nextBreakable && nextBreakable.value() >= startPosition)
+ return startPosition == nextBreakable;
+
+ if (keepAllWords) {
+ if (breakNBSP)
+ nextBreakable = nextBreakablePositionKeepingAllWords(lazyBreakIterator, startPosition);
+ else
+ nextBreakable = nextBreakablePositionKeepingAllWordsIgnoringNBSP(lazyBreakIterator, startPosition);
+ } else if (isLooseMode) {
+ if (breakNBSP)
+ nextBreakable = nextBreakablePositionLoose(lazyBreakIterator, startPosition);
+ else
+ nextBreakable = nextBreakablePositionIgnoringNBSPLoose(lazyBreakIterator, startPosition);
+ } else {
+ if (breakNBSP)
+ nextBreakable = nextBreakablePosition(lazyBreakIterator, startPosition);
+ else
+ nextBreakable = nextBreakablePositionIgnoringNBSP(lazyBreakIterator, startPosition);
+ }
+ return startPosition == nextBreakable;
+}
+
+} // namespace WebCore
Modified: trunk/Source/WebCore/rendering/InlineIterator.h (204530 => 204531)
--- trunk/Source/WebCore/rendering/InlineIterator.h 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/InlineIterator.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -53,11 +53,6 @@
class InlineIterator {
public:
InlineIterator()
- : m_root(nullptr)
- , m_renderer(nullptr)
- , m_nextBreakablePosition(-1)
- , m_pos(0)
- , m_refersToEndOfPreviousNode(false)
{
}
@@ -64,7 +59,6 @@
InlineIterator(RenderElement* root, RenderObject* o, unsigned p)
: m_root(root)
, m_renderer(o)
- , m_nextBreakablePosition(-1)
, m_pos(p)
, m_refersToEndOfPreviousNode(false)
{
@@ -77,7 +71,7 @@
moveTo(object, 0);
}
- void moveTo(RenderObject* object, unsigned offset, int nextBreak = -1)
+ void moveTo(RenderObject* object, unsigned offset, Optional<unsigned> nextBreak = Nullopt)
{
setRenderer(object);
setOffset(offset);
@@ -89,8 +83,8 @@
unsigned offset() const { return m_pos; }
void setOffset(unsigned position);
RenderElement* root() const { return m_root; }
- int nextBreakablePosition() const { return m_nextBreakablePosition; }
- void setNextBreakablePosition(int position) { m_nextBreakablePosition = position; }
+ Optional<unsigned> nextBreakablePosition() const { return m_nextBreakablePosition; }
+ void setNextBreakablePosition(Optional<unsigned> position) { m_nextBreakablePosition = position; }
bool refersToEndOfPreviousNode() const { return m_refersToEndOfPreviousNode; }
void setRefersToEndOfPreviousNode();
@@ -118,11 +112,11 @@
UCharDirection surrogateTextDirection(UChar currentCodeUnit) const;
- RenderElement* m_root;
- RenderObject* m_renderer;
+ RenderElement* m_root { nullptr };
+ RenderObject* m_renderer { nullptr };
- int m_nextBreakablePosition;
- unsigned m_pos;
+ Optional<unsigned> m_nextBreakablePosition;
+ unsigned m_pos { 0 };
// There are a couple places where we want to decrement an InlineIterator.
// Usually this take the form of decrementing m_pos; however, m_pos might be 0.
@@ -129,7 +123,7 @@
// However, we shouldn't ever need to decrement an InlineIterator more than
// once, so rather than implementing a decrement() function which traverses
// nodes, we can simply keep track of this state and handle it.
- bool m_refersToEndOfPreviousNode;
+ bool m_refersToEndOfPreviousNode { false };
};
inline bool operator==(const InlineIterator& it1, const InlineIterator& it2)
Modified: trunk/Source/WebCore/rendering/InlineTextBox.cpp (204530 => 204531)
--- trunk/Source/WebCore/rendering/InlineTextBox.cpp 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/InlineTextBox.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -23,6 +23,7 @@
#include "config.h"
#include "InlineTextBox.h"
+#include "BreakLines.h"
#include "Chrome.h"
#include "ChromeClient.h"
#include "DashArray.h"
@@ -50,7 +51,6 @@
#include "TextDecorationPainter.h"
#include "TextPaintStyle.h"
#include "TextPainter.h"
-#include "break_lines.h"
#include <stdio.h>
#include <wtf/text/CString.h>
Modified: trunk/Source/WebCore/rendering/RenderText.cpp (204530 => 204531)
--- trunk/Source/WebCore/rendering/RenderText.cpp 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/RenderText.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -26,6 +26,7 @@
#include "RenderText.h"
#include "AXObjectCache.h"
+#include "BreakLines.h"
#include "BreakingContext.h"
#include "CharacterProperties.h"
#include "EllipsisBox.h"
@@ -46,7 +47,6 @@
#include <wtf/text/TextBreakIterator.h>
#include "TextResourceDecoder.h"
#include "VisiblePosition.h"
-#include "break_lines.h"
#include <wtf/NeverDestroyed.h>
#include <wtf/text/StringBuffer.h>
#include <wtf/text/StringBuilder.h>
@@ -791,7 +791,7 @@
const RenderStyle& style = this->style();
const FontCascade& font = style.fontCascade(); // FIXME: This ignores first-line.
float wordSpacing = font.wordSpacing();
- int len = textLength();
+ unsigned len = textLength();
LazyLineBreakIterator breakIterator(m_text, style.locale(), mapLineBreakToIteratorMode(style.lineBreak()));
bool needsWordSpacing = false;
bool ignoringSpaces = false;
@@ -798,8 +798,8 @@
bool isSpace = false;
bool firstWord = true;
bool firstLine = true;
- int nextBreakable = -1;
- int lastWordBoundary = 0;
+ Optional<unsigned> nextBreakable;
+ unsigned lastWordBoundary = 0;
// Non-zero only when kerning is enabled, in which case we measure words with their trailing
// space, then subtract its width.
@@ -833,7 +833,7 @@
bool keepAllWords = style.wordBreak() == KeepAllWordBreak;
bool isLooseCJKMode = breakIterator.isLooseCJKMode();
- for (int i = 0; i < len; i++) {
+ for (unsigned i = 0; i < len; i++) {
UChar c = uncheckedCharacterAt(i);
bool previousCharacterIsSpace = isSpace;
@@ -869,6 +869,7 @@
lastWordBoundary++;
continue;
} else if (c == softHyphen && style.hyphens() != HyphensNone) {
+ ASSERT(i >= lastWordBoundary);
currMaxWidth += widthFromCache(font, lastWordBoundary, i - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
if (!firstGlyphLeftOverflow)
firstGlyphLeftOverflow = glyphOverflow.left;
@@ -878,7 +879,7 @@
bool hasBreak = breakAll || isBreakable(breakIterator, i, nextBreakable, breakNBSP, isLooseCJKMode, keepAllWords);
bool betweenWords = true;
- int j = i;
+ unsigned j = i;
while (c != '\n' && !isSpaceAccordingToStyle(c, style) && c != '\t' && (c != softHyphen || style.hyphens() == HyphensNone)) {
j++;
if (j == len)
@@ -892,7 +893,7 @@
}
}
- int wordLen = j - i;
+ unsigned wordLen = j - i;
if (wordLen) {
float currMinWidth = 0;
bool isSpace = (j < len) && isSpaceAccordingToStyle(c, style);
@@ -936,8 +937,10 @@
if (betweenWords) {
if (lastWordBoundary == i)
currMaxWidth += w;
- else
+ else {
+ ASSERT(j >= lastWordBoundary);
currMaxWidth += widthFromCache(font, lastWordBoundary, j - lastWordBoundary, leadWidth + currMaxWidth, &fallbackFonts, &glyphOverflow, style);
+ }
lastWordBoundary = j;
}
Modified: trunk/Source/WebCore/rendering/RenderingAllInOne.cpp (204530 => 204531)
--- trunk/Source/WebCore/rendering/RenderingAllInOne.cpp 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/RenderingAllInOne.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -28,6 +28,7 @@
#include "AutoTableLayout.cpp"
#include "BidiRun.cpp"
#include "BorderEdge.cpp"
+#include "BreakLines.cpp"
#include "ClipRect.cpp"
#include "CounterNode.cpp"
#include "EllipsisBox.cpp"
@@ -149,4 +150,3 @@
#include "TextDecorationPainter.cpp"
#include "TextPaintStyle.cpp"
#include "TextPainter.cpp"
-#include "break_lines.cpp"
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp (204530 => 204531)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -114,8 +114,9 @@
unsigned TextFragmentIterator::nextBreakablePosition(const FlowContents::Segment& segment, unsigned startPosition)
{
ASSERT(startPosition < segment.end);
- if (segment.text.impl() != m_lineBreakIterator.string().impl()) {
- const String& currentText = m_lineBreakIterator.string();
+ StringView currentText = m_lineBreakIterator.stringView();
+ StringView segmentText = StringView(segment.text);
+ if (segmentText != currentText) {
unsigned textLength = currentText.length();
UChar lastCharacter = textLength > 0 ? currentText[textLength - 1] : 0;
UChar secondToLastCharacter = textLength > 1 ? currentText[textLength - 2] : 0;
@@ -125,7 +126,7 @@
const auto* characters = segment.text.characters<CharacterType>();
unsigned segmentLength = segment.end - segment.start;
unsigned segmentPosition = startPosition - segment.start;
- return segment.start + nextBreakablePositionNonLoosely<CharacterType, NBSPBehavior::IgnoreNBSP>(m_lineBreakIterator, characters, segmentLength, segmentPosition);
+ return segment.start + nextBreakablePositionNonLoosely<CharacterType, NonBreakingSpaceBehavior::IgnoreNonBreakingSpace>(m_lineBreakIterator, characters, segmentLength, segmentPosition);
}
template <typename CharacterType>
Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h (204530 => 204531)
--- trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutTextFragmentIterator.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -23,13 +23,12 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef SimpleLineLayoutTextFragmentIterator_h
-#define SimpleLineLayoutTextFragmentIterator_h
+#pragma once
+#include "BreakLines.h"
#include "RenderLineBreak.h"
#include "SimpleLineLayoutFlowContents.h"
#include <wtf/text/TextBreakIterator.h>
-#include "break_lines.h"
namespace WebCore {
@@ -166,5 +165,3 @@
}
}
-
-#endif
Deleted: trunk/Source/WebCore/rendering/break_lines.cpp (204530 => 204531)
--- trunk/Source/WebCore/rendering/break_lines.cpp 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/break_lines.cpp 2016-08-16 22:39:10 UTC (rev 204531)
@@ -1,100 +0,0 @@
-/*
- * Copyright (C) 2005, 2007, 2010 Apple Inc. All rights reserved.
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "break_lines.h"
-
-#include <wtf/ASCIICType.h>
-#include <wtf/StdLibExtras.h>
-#include <wtf/unicode/CharacterNames.h>
-
-namespace WebCore {
-
-// Pack 8 bits into one byte
-#define B(a, b, c, d, e, f, g, h) \
- ((a) | ((b) << 1) | ((c) << 2) | ((d) << 3) | ((e) << 4) | ((f) << 5) | ((g) << 6) | ((h) << 7))
-
-// Line breaking table row for each digit (0-9)
-#define DI { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-// Line breaking table row for ascii letters (a-z A-Z)
-#define AL { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
-
-#define F 0xFF
-
-// Line breaking table for printable ASCII characters. Line breaking opportunities in this table are as below:
-// - before opening punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
-// - after '-' and '?' (backward-compatible, and compatible with Internet Explorer).
-// Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line breaking matrixes of different browsers
-// and the ICU standard.
-WEBCORE_EXPORT const unsigned char asciiLineBreakTable[][asciiLineBreakTableColumnCount] = {
- // ! " # $ % & ' ( ) * + , - . / 0 1-8 9 : ; < = > ? @ A-X Y Z [ \ ] ^ _ ` a-x y z { | } ~ DEL
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // !
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // "
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // #
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // $
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // %
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // &
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // '
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // (
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // )
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // *
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // +
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ,
- { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 0, 1, 0), 0, B(0, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 1, 1, 1, 1) }, // - Note: breaking before '0'-'9' is handled hard-coded in shouldBreakAfter().
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // .
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // /
- DI, DI, DI, DI, DI, DI, DI, DI, DI, DI, // 0-9
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // :
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ;
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // <
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // =
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // >
- { B(0, 0, 1, 1, 1, 1, 0, 1), B(0, 1, 1, 0, 1, 0, 0, 1), F, B(1, 0, 0, 1, 1, 1, 0, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 1), F, F, F, B(1, 1, 1, 1, 0, 1, 1, 0) }, // ?
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // @
- AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // A-Z
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // [
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // '\'
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ]
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // ^
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // _
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // `
- AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, // a-z
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // {
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // |
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // }
- { B(0, 0, 0, 0, 0, 0, 0, 1), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 1, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 1, 0, 0, 0, 0, 0) }, // ~
- { B(0, 0, 0, 0, 0, 0, 0, 0), B(0, 0, 0, 0, 0, 0, 0, 0), 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0), 0, 0, 0, B(0, 0, 0, 0, 0, 0, 0, 0) }, // DEL
-};
-
-#undef B
-#undef F
-#undef DI
-#undef AL
-
-COMPILE_ASSERT(WTF_ARRAY_LENGTH(asciiLineBreakTable) == asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar + 1, TestLineBreakTableConsistency);
-
-} // namespace WebCore
Deleted: trunk/Source/WebCore/rendering/break_lines.h (204530 => 204531)
--- trunk/Source/WebCore/rendering/break_lines.h 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/break_lines.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -1,248 +0,0 @@
-/*
- * Copyright (C) 2005, 2007, 2010, 2013 Apple Inc. All rights reserved.
- * Copyright (C) 2011 Google Inc. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * along with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef break_lines_h
-#define break_lines_h
-
-#include <wtf/ASCIICType.h>
-#include <wtf/StdLibExtras.h>
-#include <wtf/text/TextBreakIterator.h>
-#include <wtf/unicode/CharacterNames.h>
-
-namespace WebCore {
-
-static const UChar asciiLineBreakTableFirstChar = '!';
-static const UChar asciiLineBreakTableLastChar = 127;
-static const unsigned asciiLineBreakTableColumnCount = (asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar) / 8 + 1;
-
-WEBCORE_EXPORT extern const unsigned char asciiLineBreakTable[][asciiLineBreakTableColumnCount];
-
-enum class NBSPBehavior {
- IgnoreNBSP,
- TreatNBSPAsBreak,
-};
-
-template<NBSPBehavior nbspBehavior>
-static inline bool isBreakableSpace(UChar ch)
-{
- switch (ch) {
- case ' ':
- case '\n':
- case '\t':
- return true;
- case noBreakSpace:
- return nbspBehavior == NBSPBehavior::TreatNBSPAsBreak;
- default:
- return false;
- }
-}
-
-inline bool shouldBreakAfter(UChar lastCh, UChar ch, UChar nextCh)
-{
- // Don't allow line breaking between '-' and a digit if the '-' may mean a minus sign in the context,
- // while allow breaking in 'ABCD-1234' and '1234-5678' which may be in long URLs.
- if (ch == '-' && isASCIIDigit(nextCh))
- return isASCIIAlphanumeric(lastCh);
-
- // If both ch and nextCh are ASCII characters, use a lookup table for enhanced speed and for compatibility
- // with other browsers (see comments for asciiLineBreakTable for details).
- if (ch >= asciiLineBreakTableFirstChar && ch <= asciiLineBreakTableLastChar && nextCh >= asciiLineBreakTableFirstChar && nextCh <= asciiLineBreakTableLastChar) {
- const unsigned char* tableRow = asciiLineBreakTable[ch - asciiLineBreakTableFirstChar];
- int nextChIndex = nextCh - asciiLineBreakTableFirstChar;
- return tableRow[nextChIndex / 8] & (1 << (nextChIndex % 8));
- }
- // Otherwise defer to the Unicode algorithm by returning false.
- return false;
-}
-
-template<NBSPBehavior nbspBehavior>
-inline bool needsLineBreakIterator(UChar ch)
-{
- if (nbspBehavior == NBSPBehavior::TreatNBSPAsBreak)
- return ch > asciiLineBreakTableLastChar;
- return ch > asciiLineBreakTableLastChar && ch != noBreakSpace;
-}
-
-// When in non-loose mode, we can use the ASCII shortcut table.
-template<typename CharacterType, NBSPBehavior nbspBehavior>
-inline int nextBreakablePositionNonLoosely(LazyLineBreakIterator& lazyBreakIterator, const CharacterType* str, unsigned length, int pos)
-{
- int len = static_cast<int>(length);
- int nextBreak = -1;
-
- CharacterType lastLastCh = pos > 1 ? str[pos - 2] : static_cast<CharacterType>(lazyBreakIterator.secondToLastCharacter());
- CharacterType lastCh = pos > 0 ? str[pos - 1] : static_cast<CharacterType>(lazyBreakIterator.lastCharacter());
- unsigned priorContextLength = lazyBreakIterator.priorContextLength();
- for (int i = pos; i < len; i++) {
- CharacterType ch = str[i];
-
- // Non-loose mode, so use ASCII shortcut (shouldBreakAfter) if not breakable space.
- if (isBreakableSpace<nbspBehavior>(ch) || shouldBreakAfter(lastLastCh, lastCh, ch))
- return i;
-
- // Non-loose mode, so conditionally use break iterator.
- if (needsLineBreakIterator<nbspBehavior>(ch) || needsLineBreakIterator<nbspBehavior>(lastCh)) {
- if (nextBreak < i) {
- // Don't break if positioned at start of primary context and there is no prior context.
- if (i || priorContextLength) {
- TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
- if (breakIterator) {
- nextBreak = textBreakFollowing(breakIterator, i - 1 + priorContextLength);
- if (nextBreak >= 0)
- nextBreak -= priorContextLength;
- }
- }
- }
- if (i == nextBreak && !isBreakableSpace<nbspBehavior>(lastCh))
- return i;
- }
-
- lastLastCh = lastCh;
- lastCh = ch;
- }
-
- return len;
-}
-
-// When in loose mode, we can't use the ASCII shortcut table since loose mode allows "$100" to break after '$' in content marked as CJK.
-// N.B. It should be possible to combine the following with the non-loose version above by adding a LooseBehavior template parameter;
-// however, when doing this, a 10% performance regression appeared on chromium-win (https://bugs.webkit.org/show_bug.cgi?id=89235#c112).
-template<typename CharacterType, NBSPBehavior nbspBehavior>
-static inline int nextBreakablePositionLoosely(LazyLineBreakIterator& lazyBreakIterator, const CharacterType* str, unsigned length, int pos)
-{
- int len = static_cast<int>(length);
- int nextBreak = -1;
-
- CharacterType lastCh = pos > 0 ? str[pos - 1] : static_cast<CharacterType>(lazyBreakIterator.lastCharacter());
- unsigned priorContextLength = lazyBreakIterator.priorContextLength();
- for (int i = pos; i < len; i++) {
- CharacterType ch = str[i];
-
- // Always loose mode, so don't use ASCII shortcut (shouldBreakAfter).
- if (isBreakableSpace<nbspBehavior>(ch))
- return i;
-
- // Always use line break iterator in loose mode.
- if (nextBreak < i) {
- // Don't break if positioned at start of primary context and there is no prior context.
- if (i || priorContextLength) {
- TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
- if (breakIterator) {
- nextBreak = textBreakFollowing(breakIterator, i - 1 + priorContextLength);
- if (nextBreak >= 0)
- nextBreak -= priorContextLength;
- }
- }
- }
- if (i == nextBreak && !isBreakableSpace<nbspBehavior>(lastCh))
- return i;
-
- lastCh = ch;
- }
-
- return len;
-}
-
-template<typename CharacterType, NBSPBehavior nbspBehavior>
-inline unsigned nextBreakablePositionKeepingAllWords(const CharacterType* string, unsigned length, unsigned startPosition)
-{
- for (unsigned i = startPosition; i < length; i++) {
- if (isBreakableSpace<nbspBehavior>(string[i]))
- return i;
- }
- return length;
-}
-
-inline unsigned nextBreakablePositionKeepingAllWords(LazyLineBreakIterator& lazyBreakIterator, int startPosition)
-{
- String string = lazyBreakIterator.string();
- if (string.is8Bit())
- return nextBreakablePositionKeepingAllWords<LChar, NBSPBehavior::TreatNBSPAsBreak>(string.characters8(), string.length(), startPosition);
- return nextBreakablePositionKeepingAllWords<UChar, NBSPBehavior::TreatNBSPAsBreak>(string.characters16(), string.length(), startPosition);
-}
-
-inline unsigned nextBreakablePositionKeepingAllWordsIgnoringNBSP(LazyLineBreakIterator& iterator, int startPosition)
-{
- String string = iterator.string();
- if (string.is8Bit())
- return nextBreakablePositionKeepingAllWords<LChar, NBSPBehavior::IgnoreNBSP>(string.characters8(), string.length(), startPosition);
- return nextBreakablePositionKeepingAllWords<UChar, NBSPBehavior::IgnoreNBSP>(string.characters16(), string.length(), startPosition);
-}
-
-inline int nextBreakablePosition(LazyLineBreakIterator& iterator, int pos)
-{
- String string = iterator.string();
- if (string.is8Bit())
- return nextBreakablePositionNonLoosely<LChar, NBSPBehavior::TreatNBSPAsBreak>(iterator, string.characters8(), string.length(), pos);
- return nextBreakablePositionNonLoosely<UChar, NBSPBehavior::TreatNBSPAsBreak>(iterator, string.characters16(), string.length(), pos);
-}
-
-inline int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, int pos)
-{
- String string = lazyBreakIterator.string();
- if (string.is8Bit())
- return nextBreakablePositionNonLoosely<LChar, NBSPBehavior::IgnoreNBSP>(lazyBreakIterator, string.characters8(), string.length(), pos);
- return nextBreakablePositionNonLoosely<UChar, NBSPBehavior::IgnoreNBSP>(lazyBreakIterator, string.characters16(), string.length(), pos);
-}
-
-inline int nextBreakablePositionLoose(LazyLineBreakIterator& lazyBreakIterator, int pos)
-{
- String string = lazyBreakIterator.string();
- if (string.is8Bit())
- return nextBreakablePositionLoosely<LChar, NBSPBehavior::TreatNBSPAsBreak>(lazyBreakIterator, string.characters8(), string.length(), pos);
- return nextBreakablePositionLoosely<UChar, NBSPBehavior::TreatNBSPAsBreak>(lazyBreakIterator, string.characters16(), string.length(), pos);
-}
-
-inline int nextBreakablePositionIgnoringNBSPLoose(LazyLineBreakIterator& lazyBreakIterator, int pos)
-{
- String string = lazyBreakIterator.string();
- if (string.is8Bit())
- return nextBreakablePositionLoosely<LChar, NBSPBehavior::IgnoreNBSP>(lazyBreakIterator, string.characters8(), string.length(), pos);
- return nextBreakablePositionLoosely<UChar, NBSPBehavior::IgnoreNBSP>(lazyBreakIterator, string.characters16(), string.length(), pos);
-}
-
-inline bool isBreakable(LazyLineBreakIterator& lazyBreakIterator, int pos, int& nextBreakable, bool breakNBSP, bool isLooseMode, bool keepAllWords)
-{
- if (pos <= nextBreakable)
- return pos == nextBreakable;
-
- if (keepAllWords) {
- if (breakNBSP)
- nextBreakable = static_cast<int>(nextBreakablePositionKeepingAllWords(lazyBreakIterator, pos));
- else
- nextBreakable = static_cast<int>(nextBreakablePositionKeepingAllWordsIgnoringNBSP(lazyBreakIterator, pos));
- } else if (isLooseMode) {
- if (breakNBSP)
- nextBreakable = nextBreakablePositionLoose(lazyBreakIterator, pos);
- else
- nextBreakable = nextBreakablePositionIgnoringNBSPLoose(lazyBreakIterator, pos);
- } else {
- if (breakNBSP)
- nextBreakable = nextBreakablePosition(lazyBreakIterator, pos);
- else
- nextBreakable = nextBreakablePositionIgnoringNBSP(lazyBreakIterator, pos);
- }
- return pos == nextBreakable;
-}
-
-} // namespace WebCore
-
-#endif // break_lines_h
Modified: trunk/Source/WebCore/rendering/line/BreakingContext.h (204530 => 204531)
--- trunk/Source/WebCore/rendering/line/BreakingContext.h 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebCore/rendering/line/BreakingContext.h 2016-08-16 22:39:10 UTC (rev 204531)
@@ -22,9 +22,9 @@
*
*/
-#ifndef BreakingContext_h
-#define BreakingContext_h
+#pragma once
+#include "BreakLines.h"
#include "Hyphenation.h"
#include "LineBreaker.h"
#include "LineInfo.h"
@@ -38,7 +38,6 @@
#include "RenderRubyRun.h"
#include "RenderSVGInlineText.h"
#include "TrailingObjects.h"
-#include "break_lines.h"
#include <wtf/Optional.h>
#include <wtf/text/StringView.h>
#include <wtf/unicode/CharacterNames.h>
@@ -167,7 +166,7 @@
m_hangsAtEnd = false;
}
- void commitLineBreakAtCurrentWidth(RenderObject& object, unsigned offset = 0, int nextBreak = -1)
+ void commitLineBreakAtCurrentWidth(RenderObject& object, unsigned offset = 0, Optional<unsigned> nextBreak = Nullopt)
{
m_width.commit();
m_lineBreakHistory.moveTo(&object, offset, nextBreak);
@@ -204,7 +203,7 @@
RenderObject* renderer() const { return this->at(0).renderer(); }
unsigned offset() const { return this->at(0).offset(); }
- int nextBreakablePosition() const { return this->at(0).nextBreakablePosition(); }
+ Optional<unsigned> nextBreakablePosition() const { return this->at(0).nextBreakablePosition(); }
bool atTextParagraphSeparator() const { return this->at(0).atTextParagraphSeparator(); }
UChar previousInSameNode() const { return this->at(0).previousInSameNode(); }
const InlineIterator& get(size_t i) const { return this->at(i); };
@@ -211,7 +210,7 @@
const InlineIterator& current() const { return get(0); }
size_t historyLength() const { return this->size(); }
- void moveTo(RenderObject* object, unsigned offset, int nextBreak = -1)
+ void moveTo(RenderObject* object, unsigned offset, Optional<unsigned> nextBreak = Nullopt)
{
push([&](InlineIterator& modifyMe) {
modifyMe.moveTo(object, offset, nextBreak);
@@ -650,7 +649,7 @@
lineWhitespaceCollapsingState.stopIgnoringSpaces(InlineIterator(0, textParagraphSeparator.renderer(), textParagraphSeparator.offset()));
}
-inline void tryHyphenating(RenderText& text, const FontCascade& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLimit, int minimumSuffixLimit, unsigned lastSpace, unsigned pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, int nextBreakable, bool& hyphenated)
+inline void tryHyphenating(RenderText& text, const FontCascade& font, const AtomicString& localeIdentifier, unsigned consecutiveHyphenatedLines, int consecutiveHyphenatedLinesLimit, int minimumPrefixLimit, int minimumSuffixLimit, unsigned lastSpace, unsigned pos, float xPos, int availableWidth, bool isFixedPitch, bool collapseWhiteSpace, int lastSpaceWordSpacing, InlineIterator& lineBreak, Optional<unsigned> nextBreakable, bool& hyphenated)
{
// Map 'hyphenate-limit-{before,after}: auto;' to 2.
unsigned minimumPrefixLength;
@@ -857,7 +856,7 @@
midWordBreak = m_width.committedWidth() + wrapW + charWidth > m_width.availableWidth();
}
- int nextBreakablePosition = m_current.nextBreakablePosition();
+ Optional<unsigned> nextBreakablePosition = m_current.nextBreakablePosition();
bool betweenWords = c == '\n' || (m_currWS != PRE && !m_atStart && isBreakable(m_renderTextInfo.lineBreakIterator, m_current.offset(), nextBreakablePosition, breakNBSP, isLooseCJKMode, keepAllWords)
&& (style.hyphens() != HyphensNone || (m_current.previousInSameNode() != softHyphen)));
m_current.setNextBreakablePosition(nextBreakablePosition);
@@ -959,14 +958,14 @@
}
// Check if the last breaking position is a soft-hyphen.
if (!hyphenated && style.hyphens() != HyphensNone) {
- Optional<int> lastBreakingPositon;
+ Optional<unsigned> lastBreakingPositon;
const RenderObject* rendererAtBreakingPosition = nullptr;
- if (m_lineBreakHistory.offset() || m_lineBreakHistory.nextBreakablePosition() > -1) {
+ if (m_lineBreakHistory.offset() || m_lineBreakHistory.nextBreakablePosition()) {
lastBreakingPositon = m_lineBreakHistory.offset();
rendererAtBreakingPosition = m_lineBreakHistory.renderer();
- } else if (m_current.nextBreakablePosition() > -1 && (unsigned)m_current.nextBreakablePosition() <= m_current.offset()) {
+ } else if (m_current.nextBreakablePosition() && m_current.nextBreakablePosition().value() <= m_current.offset()) {
// We might just be right after the soft-hyphen
- lastBreakingPositon = m_current.nextBreakablePosition();
+ lastBreakingPositon = m_current.nextBreakablePosition().value();
rendererAtBreakingPosition = m_current.renderer();
}
if (lastBreakingPositon) {
@@ -977,7 +976,7 @@
characterBeforeBreakingPosition = lastCharacterFromPreviousRenderText;
else if (is<RenderText>(rendererAtBreakingPosition)) {
const auto& textRenderer = downcast<RenderText>(*rendererAtBreakingPosition);
- ASSERT(textRenderer.textLength() > (unsigned)(lastBreakingPositon.value() - 1));
+ ASSERT(lastBreakingPositon.value() >= 1 && textRenderer.textLength() > (lastBreakingPositon.value() - 1));
characterBeforeBreakingPosition = textRenderer.characterAt(lastBreakingPositon.value() - 1);
}
if (characterBeforeBreakingPosition)
@@ -1315,9 +1314,9 @@
return lineBreak;
bool isLooseCJKMode = m_renderTextInfo.text != &renderText && m_renderTextInfo.lineBreakIterator.isLooseCJKMode();
bool breakNBSP = m_autoWrap && m_currentStyle->nbspMode() == SPACE;
- int nextBreakablePosition = lineBreak.nextBreakablePosition();
+ Optional<unsigned> nextBreakablePosition = lineBreak.nextBreakablePosition();
isBreakable(m_renderTextInfo.lineBreakIterator, lineBreak.offset() + 1, nextBreakablePosition, breakNBSP, isLooseCJKMode, m_currentStyle->wordBreak() == KeepAllWordBreak);
- if (nextBreakablePosition < 0 || static_cast<unsigned>(nextBreakablePosition) != renderText.textLength())
+ if (!nextBreakablePosition || nextBreakablePosition.value() != renderText.textLength())
return lineBreak;
const RenderStyle& style = lineStyle(renderText, m_lineInfo);
const FontCascade& font = style.fontCascade();
@@ -1339,5 +1338,3 @@
#endif
}
-
-#endif // BreakingContext_h
Modified: trunk/Source/WebKit/ios/ChangeLog (204530 => 204531)
--- trunk/Source/WebKit/ios/ChangeLog 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebKit/ios/ChangeLog 2016-08-16 22:39:10 UTC (rev 204531)
@@ -1,3 +1,13 @@
+2016-08-16 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ Migrate line breaking code from ints to Optional<unsigned>s
+ https://bugs.webkit.org/show_bug.cgi?id=160859
+
+ Reviewed by Darin Adler.
+
+ * Misc/WebUIKitSupport.mm:
+ (WebKitGetLastLineBreakInBuffer):
+
2016-08-15 Joseph Pecoraro <pecor...@apple.com>
Remove unused includes of wtf headers
Modified: trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm (204530 => 204531)
--- trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm 2016-08-16 22:33:32 UTC (rev 204530)
+++ trunk/Source/WebKit/ios/Misc/WebUIKitSupport.mm 2016-08-16 22:39:10 UTC (rev 204531)
@@ -33,12 +33,12 @@
#import "WebPlatformStrategies.h"
#import "WebSystemInterface.h"
#import "WebViewPrivate.h"
+#import <WebCore/BreakLines.h>
#import <WebCore/PathUtilities.h>
#import <WebCore/ResourceRequest.h>
#import <WebCore/Settings.h>
#import <WebCore/WebCoreSystemInterface.h>
#import <WebCore/WebCoreThreadSystemInterface.h>
-#import <WebCore/break_lines.h>
#import <wtf/spi/darwin/dyldSPI.h>
#import <wtf/text/TextBreakIterator.h>
@@ -89,12 +89,12 @@
int WebKitGetLastLineBreakInBuffer(UChar *characters, int position, int length)
{
- int lastBreakPos = position;
- int breakPos = 0;
- LazyLineBreakIterator breakIterator(String(characters, length));
- while ((breakPos = nextBreakablePosition(breakIterator, breakPos)) < position)
+ unsigned lastBreakPos = position;
+ unsigned breakPos = 0;
+ LazyLineBreakIterator breakIterator(StringView(characters, length));
+ while (static_cast<int>(breakPos = nextBreakablePosition(breakIterator, breakPos)) < position)
lastBreakPos = breakPos++;
- return lastBreakPos < position ? (NSUInteger)lastBreakPos : INT_MAX;
+ return static_cast<int>(lastBreakPos) < position ? lastBreakPos : INT_MAX;
}
const char *WebKitPlatformSystemRootDirectory(void)