Refactor hyphen measurement
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Sep 2011 19:18:43 +0000 (19:18 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 8 Sep 2011 19:18:43 +0000 (19:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=67728

Patch by Ned Holbrook <nholbrook@apple.com> on 2011-09-08
Reviewed by Darin Adler.

No new tests, purely refactoring.

* rendering/RenderBlockLineLayout.cpp:
(WebCore::measureHyphenWidth): Added.
(WebCore::setLogicalWidthForTextRun): Use measureHyphenWidth().
(WebCore::tryHyphenating): Ditto.
(WebCore::RenderBlock::LineBreaker::nextLineBreak): Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@94778 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBlockLineLayout.cpp

index ce51abf..2bdc7b6 100644 (file)
@@ -1,3 +1,18 @@
+2011-09-08  Ned Holbrook  <nholbrook@apple.com>
+
+        Refactor hyphen measurement
+        https://bugs.webkit.org/show_bug.cgi?id=67728
+
+        Reviewed by Darin Adler.
+
+        No new tests, purely refactoring.
+
+        * rendering/RenderBlockLineLayout.cpp:
+        (WebCore::measureHyphenWidth): Added.
+        (WebCore::setLogicalWidthForTextRun): Use measureHyphenWidth().
+        (WebCore::tryHyphenating): Ditto.
+        (WebCore::RenderBlock::LineBreaker::nextLineBreak): Ditto.
+
 2011-09-08  Julien Chaffraix  <jchaffraix@webkit.org>
 
         Remove LayoutStateDisabler instances from RenderLayer
index d9b6932..d3d7f30 100644 (file)
@@ -478,6 +478,12 @@ void RenderBlock::setMarginsForRubyRun(BidiRun* run, RenderRubyRun* renderer, Re
     setMarginEndForChild(renderer, -endOverhang);
 }
 
+static inline float measureHyphenWidth(RenderText* renderer, const Font& font)
+{
+    RenderStyle* style = renderer->style();
+    return font.width(RenderBlock::constructTextRun(renderer, font, style->hyphenString().string(), style));
+}
+
 static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText* renderer, float xPos, const LineInfo& lineInfo,
                                    GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache)
 {
@@ -500,9 +506,8 @@ static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* ru
     
     int hyphenWidth = 0;
     if (toInlineTextBox(run->m_box)->hasHyphen()) {
-        const AtomicString& hyphenString = renderer->style()->hyphenString();
         const Font& font = renderer->style(lineInfo.isFirstLine())->font();
-        hyphenWidth = font.width(RenderBlock::constructTextRun(renderer, font, hyphenString.string(), renderer->style()));
+        hyphenWidth = measureHyphenWidth(renderer, font);
     }
     run->m_box->setLogicalWidth(renderer->width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow) + hyphenWidth);
     if (!fallbackFonts.isEmpty()) {
@@ -1753,8 +1758,7 @@ static void tryHyphenating(RenderText* text, const Font& font, const AtomicStrin
     if (consecutiveHyphenatedLinesLimit >= 0 && consecutiveHyphenatedLines >= static_cast<unsigned>(consecutiveHyphenatedLinesLimit))
         return;
 
-    const AtomicString& hyphenString = text->style()->hyphenString();
-    int hyphenWidth = font.width(RenderBlock::constructTextRun(text, font, hyphenString.string(), text->style()));
+    int hyphenWidth = measureHyphenWidth(text, font);
 
     float maxPrefixWidth = availableWidth - xPos - hyphenWidth - lastSpaceWordSpacing;
     // If the maximum width available for the prefix before the hyphen is small, then it is very unlikely
@@ -2254,8 +2258,7 @@ InlineIterator RenderBlock::LineBreaker::nextLineBreak(InlineBidiResolver& resol
                     lineInfo.setEmpty(false);
 
                 if (c == softHyphen && autoWrap && !hyphenWidth && style->hyphens() != HyphensNone) {
-                    const AtomicString& hyphenString = style->hyphenString();
-                    hyphenWidth = f.width(constructTextRun(t, f, hyphenString.string(), current.m_obj->style()));
+                    hyphenWidth = measureHyphenWidth(t, f);
                     width.addUncommittedWidth(hyphenWidth);
                 }