Changeset 52944 in webkit
- Timestamp:
- Jan 7, 2010 1:32:13 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r52943 r52944 1 2010-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 1 12 2010-01-07 Yuzo Fujishima <yuzo@google.com> 2 13 -
trunk/WebCore/ChangeLog
r52943 r52944 1 2010-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 1 30 2010-01-07 Yuzo Fujishima <yuzo@google.com> 2 31 -
trunk/WebCore/dom/Document.cpp
r52919 r52944 115 115 #include "SelectionController.h" 116 116 #include "Settings.h" 117 #include "StringBuffer.h" 117 118 #include "StyleSheetList.h" 118 119 #include "TextEvent.h" … … 324 325 , m_frameElementsShouldIgnoreScrolling(false) 325 326 , m_title("") 327 , m_rawTitle("") 326 328 , m_titleSetExplicitly(false) 327 329 , m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired) … … 1065 1067 } 1066 1068 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 */ 1075 static 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 1067 1127 void Document::updateTitle() 1068 1128 { 1129 m_title = canonicalizedTitle(this, m_rawTitle); 1069 1130 if (Frame* f = frame()) 1070 1131 f->loader()->setTitle(m_title); … … 1093 1154 } 1094 1155 1095 if (m_ title == title)1096 return; 1097 1098 m_ title = title;1156 if (m_rawTitle == title) 1157 return; 1158 1159 m_rawTitle = title; 1099 1160 updateTitle(); 1100 1161 … … 1121 1182 } 1122 1183 1123 if (!m_titleElement && !m_ title.isEmpty()) {1124 m_ title = "";1184 if (!m_titleElement && !m_rawTitle.isEmpty()) { 1185 m_rawTitle = ""; 1125 1186 updateTitle(); 1126 1187 } -
trunk/WebCore/dom/Document.h
r52919 r52944 1074 1074 1075 1075 String m_title; 1076 String m_rawTitle; 1076 1077 bool m_titleSetExplicitly; 1077 1078 RefPtr<Element> m_titleElement; -
trunk/WebCore/loader/DocumentLoader.cpp
r52860 r52944 47 47 #include "Settings.h" 48 48 #include "SharedBuffer.h" 49 #include "StringBuffer.h"50 49 #include "XMLTokenizer.h" 51 50 … … 54 53 55 54 namespace WebCore { 56 57 /*58 * Performs four operations:59 * 1. Convert backslashes to currency symbols60 * 2. Convert control characters to spaces61 * 3. Trim leading and trailing spaces62 * 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 spaces76 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 spaces101 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 }117 55 118 56 static void cancelAll(const ResourceLoaderSet& loaders) … … 663 601 return; 664 602 665 String trimmed = canonicalizedTitle(title, m_frame); 666 if (!trimmed.isEmpty() && m_pageTitle != trimmed) { 603 if (m_pageTitle != title) { 667 604 frameLoader()->willChangeTitle(this); 668 m_pageTitle = t rimmed;605 m_pageTitle = title; 669 606 frameLoader()->didChangeTitle(this); 670 607 }
Note: See TracChangeset
for help on using the changeset viewer.