Changeset 95030 in webkit


Ignore:
Timestamp:
Sep 13, 2011 9:44:15 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Patch by Xianzhu Wang <wangxianzhu@chromium.org> on 2011-09-13
Reviewed by Darin Adler.

Source/WebCore:

Webkit wraps between hyphen-minus and numeric characters
https://bugs.webkit.org/show_bug.cgi?id=20677

Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
is not directly after a digit or a letter.

Test: fast/text/line-breaks-after-hyphen-before-number.html

  • rendering/break_lines.cpp:

(WebCore::asciiLineBreakTable): Disabled line-breaking after '-' and before '.', '0'-'9'. Note: the change for '0'-'9' doesn't really matter because the case is handled hard-coded in shouldBreakAfter().
(WebCore::shouldBreakAfter): Changed line-breaking behavior after '-'.
(WebCore::nextBreakablePosition): Passes lastLastCh to shouldBreakAfter.

LayoutTests:

Webkit wraps between hyphen-minus and numeric characters
https://bugs.webkit.org/show_bug.cgi?id=20677

Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
is not directly after a digit or a letter.

  • fast/text/line-breaks-after-hyphen-before-number-expected.txt: Added.
  • fast/text/line-breaks-after-hyphen-before-number.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r95028 r95030  
     12011-09-13  Xianzhu Wang  <wangxianzhu@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Webkit wraps between hyphen-minus and numeric characters
     6        https://bugs.webkit.org/show_bug.cgi?id=20677
     7
     8        Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
     9        is not directly after a digit or a letter.
     10
     11        * fast/text/line-breaks-after-hyphen-before-number-expected.txt: Added.
     12        * fast/text/line-breaks-after-hyphen-before-number.html: Added.
     13
    1142011-09-12  Sam Weinig  <sam@webkit.org>
    215
  • trunk/Source/WebCore/ChangeLog

    r95029 r95030  
     12011-09-13  Xianzhu Wang  <wangxianzhu@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Webkit wraps between hyphen-minus and numeric characters
     6        https://bugs.webkit.org/show_bug.cgi?id=20677
     7
     8        Disallow wrapping between a hyphen-minus and a digit if the hyphen-minus
     9        is not directly after a digit or a letter.
     10
     11        Test: fast/text/line-breaks-after-hyphen-before-number.html
     12
     13        * rendering/break_lines.cpp:
     14        (WebCore::asciiLineBreakTable): Disabled line-breaking after '-' and before '.', '0'-'9'. Note: the change for '0'-'9' doesn't really matter because the case is handled hard-coded in shouldBreakAfter().
     15        (WebCore::shouldBreakAfter): Changed line-breaking behavior after '-'.
     16        (WebCore::nextBreakablePosition): Passes lastLastCh to shouldBreakAfter.
     17
    1182011-09-13  Erik Wright  <erikwright@chromium.org>
    219
  • trunk/Source/WebCore/rendering/break_lines.cpp

    r85036 r95030  
    11/*
    22 * Copyright (C) 2005, 2007, 2010 Apple Inc. All rights reserved.
     3 * Copyright (C) 2011 Google Inc. All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2829
    2930#include "TextBreakIterator.h"
     31#include <wtf/ASCIICType.h>
    3032#include <wtf/StdLibExtras.h>
    3133#include <wtf/unicode/CharacterNames.h>
     
    6769
    6870// Line breaking table for printable ASCII characters. Line breaking opportunities in this table are as below:
    69 // - before openning punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
     71// - before opening punctuations such as '(', '<', '[', '{' after certain characters (compatible with Firefox 3.6);
    7072// - after '-' and '?' (backward-compatible, and compatible with Internet Explorer).
    7173// Please refer to <https://bugs.webkit.org/show_bug.cgi?id=37698> for line breaking matrixes of different browsers
     
    8587    { 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) }, // +
    8688    { 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) }, // ,
    87     { B(1, 1, 1, 1, 1, 1, 1, 1), B(1, 1, 1, 1, 1, 1, 1, 1), F, B(1, 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) }, // -
     89    { 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().
    8890    { 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) }, // .
    8991    { 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) }, // /
     
    118120COMPILE_ASSERT(WTF_ARRAY_LENGTH(asciiLineBreakTable) == asciiLineBreakTableLastChar - asciiLineBreakTableFirstChar + 1, TestLineBreakTableConsistency);
    119121
    120 static inline bool shouldBreakAfter(UChar ch, UChar nextCh)
     122static inline bool shouldBreakAfter(UChar lastCh, UChar ch, UChar nextCh)
    121123{
    122124    switch (ch) {
     
    127129        // We may want to remove or conditionalize this workaround at some point.
    128130        return true;
     131    case '-':
     132        if (isASCIIDigit(nextCh)) {
     133            // Don't allow line breaking between '-' and a digit if the '-' may mean a minus sign in the context,
     134            // while allow breaking in 'ABCD-1234' and '1234-5678' which may be in long URLs.
     135            return isASCIIAlphanumeric(lastCh);
     136        }
     137        // Fall through
    129138    default:
    130139        // If both ch and nextCh are ASCII characters, use a lookup table for enhanced speed and for compatibility
     
    152161    int nextBreak = -1;
    153162
     163    UChar lastLastCh = pos > 1 ? str[pos - 2] : 0;
    154164    UChar lastCh = pos > 0 ? str[pos - 1] : 0;
    155165    for (int i = pos; i < len; i++) {
    156166        UChar ch = str[i];
    157167
    158         if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastCh, ch))
     168        if (isBreakableSpace(ch, treatNoBreakSpaceAsBreak) || shouldBreakAfter(lastLastCh, lastCh, ch))
    159169            return i;
    160170
     
    169179        }
    170180
     181        lastLastCh = lastCh;
    171182        lastCh = ch;
    172183    }
Note: See TracChangeset for help on using the changeset viewer.