Changeset 52944 in webkit


Ignore:
Timestamp:
Jan 7, 2010 1:32:13 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-07 Christian Sejersen <Christian Sejersen>

Reviewed by Darin Adler.

document.title does not replace or remove space characters
https://bugs.webkit.org/show_bug.cgi?id=27032

  • fast/dom/Document/document-title-get-expected.txt: Added.
  • fast/dom/Document/document-title-get.html: Added.
  • fast/dom/Document/script-tests/document-title-get.js: Added.

2010-01-07 Christian Sejersen <Christian Sejersen>

Reviewed by Darin Adler.

document.title does not replace or remove space characters
https://bugs.webkit.org/show_bug.cgi?id=27032

Test: fast/dom/Document/document-title-get.html

  • dom/Document.cpp: (WebCore::Document::Document): Initialization of m_rawTitle (WebCore::canonicalizedTitle): Moved from DocumentLoader.cpp with minor edits (WebCore::Document::updateTitle): Ensures the title is canonicalized (WebCore::Document::setTitle): Uses m_rawTitle instaed of m_title (WebCore::Document::removeTitle): Uses m_rawTitle instead of m_title
  • dom/Document.h: Added m_rawTitle that stores the passed in title, m_title now stores the canonicalized title
  • loader/DocumentLoader.cpp: (WebCore::DocumentLoader::setTitle): The title passed in is now canonicalized in Document.cpp
Location:
trunk
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r52943 r52944  
     12010-01-07  Christian Sejersen  <christian.webkit@gmail.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        document.title does not replace or remove space characters
     6        https://bugs.webkit.org/show_bug.cgi?id=27032
     7
     8        * fast/dom/Document/document-title-get-expected.txt: Added.
     9        * fast/dom/Document/document-title-get.html: Added.
     10        * fast/dom/Document/script-tests/document-title-get.js: Added.
     11
    1122010-01-07  Yuzo Fujishima  <yuzo@google.com>
    213
  • trunk/WebCore/ChangeLog

    r52943 r52944  
     12010-01-07  Christian Sejersen  <christian.webkit@gmail.com>
     2
     3        Reviewed by Darin Adler.
     4
     5        document.title does not replace or remove space characters
     6        https://bugs.webkit.org/show_bug.cgi?id=27032
     7
     8        Test: fast/dom/Document/document-title-get.html
     9
     10        * dom/Document.cpp:
     11        (WebCore::Document::Document):
     12        Initialization of m_rawTitle
     13        (WebCore::canonicalizedTitle):
     14        Moved from DocumentLoader.cpp with minor edits
     15        (WebCore::Document::updateTitle):
     16        Ensures the title is canonicalized
     17        (WebCore::Document::setTitle):
     18        Uses m_rawTitle instaed of m_title
     19        (WebCore::Document::removeTitle):
     20        Uses m_rawTitle instead of m_title
     21       
     22        * dom/Document.h:
     23        Added m_rawTitle that stores the passed in title, m_title now stores the
     24        canonicalized title
     25       
     26        * loader/DocumentLoader.cpp:
     27        (WebCore::DocumentLoader::setTitle):
     28        The title passed in is now canonicalized in Document.cpp
     29
    1302010-01-07  Yuzo Fujishima  <yuzo@google.com>
    231
  • trunk/WebCore/dom/Document.cpp

    r52919 r52944  
    115115#include "SelectionController.h"
    116116#include "Settings.h"
     117#include "StringBuffer.h"
    117118#include "StyleSheetList.h"
    118119#include "TextEvent.h"
     
    324325    , m_frameElementsShouldIgnoreScrolling(false)
    325326    , m_title("")
     327    , m_rawTitle("")
    326328    , m_titleSetExplicitly(false)
    327329    , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired)
     
    10651067}
    10661068
     1069/*
     1070 * Performs three operations:
     1071 *  1. Convert control characters to spaces
     1072 *  2. Trim leading and trailing spaces
     1073 *  3. Collapse internal whitespace.
     1074 */
     1075static inline String canonicalizedTitle(Document* document, const String& title)
     1076{
     1077    const UChar* characters = title.characters();
     1078    unsigned length = title.length();
     1079    unsigned i;
     1080
     1081    StringBuffer buffer(length);
     1082    unsigned builderIndex = 0;
     1083
     1084    // Skip leading spaces and leading characters that would convert to spaces
     1085    for (i = 0; i < length; ++i) {
     1086        UChar c = characters[i];
     1087        if (!(c <= 0x20 || c == 0x7F))
     1088            break;
     1089    }
     1090
     1091    if (i == length)
     1092        return "";
     1093
     1094    // Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace.
     1095    bool previousCharWasWS = false;
     1096    for (; i < length; ++i) {
     1097        UChar c = characters[i];
     1098        if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
     1099            if (previousCharWasWS)
     1100                continue;
     1101            buffer[builderIndex++] = ' ';
     1102            previousCharWasWS = true;
     1103        } else {
     1104            buffer[builderIndex++] = c;
     1105            previousCharWasWS = false;
     1106        }
     1107    }
     1108
     1109    // Strip trailing spaces
     1110    while (builderIndex > 0) {
     1111        --builderIndex;
     1112        if (buffer[builderIndex] != ' ')
     1113            break;
     1114    }
     1115
     1116    if (!builderIndex && buffer[builderIndex] == ' ')
     1117        return "";
     1118
     1119    buffer.shrink(builderIndex + 1);
     1120
     1121    // Replace the backslashes with currency symbols if the encoding requires it.
     1122    document->displayBufferModifiedByEncoding(buffer.characters(), buffer.length());
     1123   
     1124    return String::adopt(buffer);
     1125}
     1126
    10671127void Document::updateTitle()
    10681128{
     1129    m_title = canonicalizedTitle(this, m_rawTitle);
    10691130    if (Frame* f = frame())
    10701131        f->loader()->setTitle(m_title);
     
    10931154    }
    10941155
    1095     if (m_title == title)
    1096         return;
    1097 
    1098     m_title = title;
     1156    if (m_rawTitle == title)
     1157        return;
     1158
     1159    m_rawTitle = title;
    10991160    updateTitle();
    11001161
     
    11211182    }
    11221183
    1123     if (!m_titleElement && !m_title.isEmpty()) {
    1124         m_title = "";
     1184    if (!m_titleElement && !m_rawTitle.isEmpty()) {
     1185        m_rawTitle = "";
    11251186        updateTitle();
    11261187    }
  • trunk/WebCore/dom/Document.h

    r52919 r52944  
    10741074
    10751075    String m_title;
     1076    String m_rawTitle;
    10761077    bool m_titleSetExplicitly;
    10771078    RefPtr<Element> m_titleElement;
  • trunk/WebCore/loader/DocumentLoader.cpp

    r52860 r52944  
    4747#include "Settings.h"
    4848#include "SharedBuffer.h"
    49 #include "StringBuffer.h"
    5049#include "XMLTokenizer.h"
    5150
     
    5453
    5554namespace WebCore {
    56 
    57 /*
    58  * Performs four operations:
    59  *  1. Convert backslashes to currency symbols
    60  *  2. Convert control characters to spaces
    61  *  3. Trim leading and trailing spaces
    62  *  4. Collapse internal whitespace.
    63  */
    64 static inline String canonicalizedTitle(const String& title, Frame* frame)
    65 {
    66     ASSERT(!title.isEmpty());
    67 
    68     const UChar* characters = title.characters();
    69     unsigned length = title.length();
    70     unsigned i;
    71 
    72     StringBuffer buffer(length);
    73     unsigned builderIndex = 0;
    74 
    75     // Skip leading spaces and leading characters that would convert to spaces
    76     for (i = 0; i < length; ++i) {
    77         UChar c = characters[i];
    78         if (!(c <= 0x20 || c == 0x7F))
    79             break;
    80     }
    81 
    82     if (i == length)
    83         return "";
    84 
    85     // Replace control characters with spaces, and backslashes with currency symbols, and collapse whitespace.
    86     bool previousCharWasWS = false;
    87     for (; i < length; ++i) {
    88         UChar c = characters[i];
    89         if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode::Separator_Line | WTF::Unicode::Separator_Paragraph))) {
    90             if (previousCharWasWS)
    91                 continue;
    92             buffer[builderIndex++] = ' ';
    93             previousCharWasWS = true;
    94         } else {
    95             buffer[builderIndex++] = c;
    96             previousCharWasWS = false;
    97         }
    98     }
    99 
    100     // Strip trailing spaces
    101     while (builderIndex > 0) {
    102         --builderIndex;
    103         if (buffer[builderIndex] != ' ')
    104             break;
    105     }
    106 
    107     if (!builderIndex && buffer[builderIndex] == ' ')
    108         return "";
    109 
    110     buffer.shrink(builderIndex + 1);
    111    
    112     // Replace the backslashes with currency symbols if the encoding requires it.
    113     frame->document()->displayBufferModifiedByEncoding(buffer.characters(), buffer.length());
    114 
    115     return String::adopt(buffer);
    116 }
    11755
    11856static void cancelAll(const ResourceLoaderSet& loaders)
     
    663601        return;
    664602
    665     String trimmed = canonicalizedTitle(title, m_frame);
    666     if (!trimmed.isEmpty() && m_pageTitle != trimmed) {
     603    if (m_pageTitle != title) {
    667604        frameLoader()->willChangeTitle(this);
    668         m_pageTitle = trimmed;
     605        m_pageTitle = title;
    669606        frameLoader()->didChangeTitle(this);
    670607    }
Note: See TracChangeset for help on using the changeset viewer.