| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 
| 3  *           (C) 1999 Antti Koivisto (koivisto@kde.org) | 3  *           (C) 1999 Antti Koivisto (koivisto@kde.org) | 
| 4  *           (C) 2001 Dirk Mueller (mueller@kde.org) | 4  *           (C) 2001 Dirk Mueller (mueller@kde.org) | 
| 5  *           (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 5  *           (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 
| 6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
      ights reserved. | 6  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r
      ights reserved. | 
| 7  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
      orchmobile.com/) | 7  * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t
      orchmobile.com/) | 
| 8  * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 8  * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. | 
| 9  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 9  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 
| 10  * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 10  * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. | 
| (...skipping 1220 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1231     return Range::create(this, rangeCompliantPosition, rangeCompliantPosition); | 1231     return Range::create(this, rangeCompliantPosition, rangeCompliantPosition); | 
| 1232 } | 1232 } | 
| 1233 | 1233 | 
| 1234 /* | 1234 /* | 
| 1235  * Performs three operations: | 1235  * Performs three operations: | 
| 1236  *  1. Convert control characters to spaces | 1236  *  1. Convert control characters to spaces | 
| 1237  *  2. Trim leading and trailing spaces | 1237  *  2. Trim leading and trailing spaces | 
| 1238  *  3. Collapse internal whitespace. | 1238  *  3. Collapse internal whitespace. | 
| 1239  */ | 1239  */ | 
| 1240 template <typename CharacterType> | 1240 template <typename CharacterType> | 
| 1241 static inline StringWithDirection canonicalizedTitle(Document* document, const S
      tringWithDirection& titleWithDirection) | 1241 static inline String canonicalizedTitle(Document* document, const String& title) | 
| 1242 { | 1242 { | 
| 1243     const String& title = titleWithDirection.string(); |  | 
| 1244     const CharacterType* characters = title.getCharacters<CharacterType>(); | 1243     const CharacterType* characters = title.getCharacters<CharacterType>(); | 
| 1245     unsigned length = title.length(); | 1244     unsigned length = title.length(); | 
| 1246     unsigned i; | 1245     unsigned i; | 
| 1247 | 1246 | 
| 1248     StringBuffer<CharacterType> buffer(length); | 1247     StringBuffer<CharacterType> buffer(length); | 
| 1249     unsigned builderIndex = 0; | 1248     unsigned builderIndex = 0; | 
| 1250 | 1249 | 
| 1251     // Skip leading spaces and leading characters that would convert to spaces | 1250     // Skip leading spaces and leading characters that would convert to spaces | 
| 1252     for (i = 0; i < length; ++i) { | 1251     for (i = 0; i < length; ++i) { | 
| 1253         CharacterType c = characters[i]; | 1252         CharacterType c = characters[i]; | 
| 1254         if (!(c <= 0x20 || c == 0x7F)) | 1253         if (!(c <= 0x20 || c == 0x7F)) | 
| 1255             break; | 1254             break; | 
| 1256     } | 1255     } | 
| 1257 | 1256 | 
| 1258     if (i == length) | 1257     if (i == length) | 
| 1259         return StringWithDirection(); | 1258         return String(); | 
| 1260 | 1259 | 
| 1261     // Replace control characters with spaces, and backslashes with currency sym
      bols, and collapse whitespace. | 1260     // Replace control characters with spaces, and backslashes with currency sym
      bols, and collapse whitespace. | 
| 1262     bool previousCharWasWS = false; | 1261     bool previousCharWasWS = false; | 
| 1263     for (; i < length; ++i) { | 1262     for (; i < length; ++i) { | 
| 1264         CharacterType c = characters[i]; | 1263         CharacterType c = characters[i]; | 
| 1265         if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode
      ::Separator_Line | WTF::Unicode::Separator_Paragraph))) { | 1264         if (c <= 0x20 || c == 0x7F || (WTF::Unicode::category(c) & (WTF::Unicode
      ::Separator_Line | WTF::Unicode::Separator_Paragraph))) { | 
| 1266             if (previousCharWasWS) | 1265             if (previousCharWasWS) | 
| 1267                 continue; | 1266                 continue; | 
| 1268             buffer[builderIndex++] = ' '; | 1267             buffer[builderIndex++] = ' '; | 
| 1269             previousCharWasWS = true; | 1268             previousCharWasWS = true; | 
| 1270         } else { | 1269         } else { | 
| 1271             buffer[builderIndex++] = c; | 1270             buffer[builderIndex++] = c; | 
| 1272             previousCharWasWS = false; | 1271             previousCharWasWS = false; | 
| 1273         } | 1272         } | 
| 1274     } | 1273     } | 
| 1275 | 1274 | 
| 1276     // Strip trailing spaces | 1275     // Strip trailing spaces | 
| 1277     while (builderIndex > 0) { | 1276     while (builderIndex > 0) { | 
| 1278         --builderIndex; | 1277         --builderIndex; | 
| 1279         if (buffer[builderIndex] != ' ') | 1278         if (buffer[builderIndex] != ' ') | 
| 1280             break; | 1279             break; | 
| 1281     } | 1280     } | 
| 1282 | 1281 | 
| 1283     if (!builderIndex && buffer[builderIndex] == ' ') | 1282     if (!builderIndex && buffer[builderIndex] == ' ') | 
| 1284         return StringWithDirection(); | 1283         return String(); | 
| 1285 | 1284 | 
| 1286     buffer.shrink(builderIndex + 1); | 1285     buffer.shrink(builderIndex + 1); | 
| 1287 | 1286 | 
| 1288     // Replace the backslashes with currency symbols if the encoding requires it
      . | 1287     // Replace the backslashes with currency symbols if the encoding requires it
      . | 
| 1289     document->displayBufferModifiedByEncoding(buffer.characters(), buffer.length
      ()); | 1288     document->displayBufferModifiedByEncoding(buffer.characters(), buffer.length
      ()); | 
| 1290 | 1289 | 
| 1291     return StringWithDirection(String::adopt(buffer), titleWithDirection.directi
      on()); | 1290     return String::adopt(buffer); | 
| 1292 } | 1291 } | 
| 1293 | 1292 | 
| 1294 void Document::updateTitle(const StringWithDirection& title) | 1293 void Document::updateTitle(const String& title) | 
| 1295 { | 1294 { | 
| 1296     if (m_rawTitle == title) | 1295     if (m_rawTitle == title) | 
| 1297         return; | 1296         return; | 
| 1298 | 1297 | 
| 1299     m_rawTitle = title; | 1298     m_rawTitle = title; | 
| 1300 | 1299 | 
| 1301     StringWithDirection oldTitle = m_title; | 1300     String oldTitle = m_title; | 
| 1302     if (m_rawTitle.string().isEmpty()) | 1301     if (m_rawTitle.isEmpty()) | 
| 1303         m_title = StringWithDirection(); | 1302         m_title = String(); | 
| 1304     else { | 1303     else if (m_rawTitle.is8Bit()) | 
| 1305         if (m_rawTitle.string().is8Bit()) | 1304         m_title = canonicalizedTitle<LChar>(this, m_rawTitle); | 
| 1306             m_title = canonicalizedTitle<LChar>(this, m_rawTitle); | 1305     else | 
| 1307         else | 1306         m_title = canonicalizedTitle<UChar>(this, m_rawTitle); | 
| 1308             m_title = canonicalizedTitle<UChar>(this, m_rawTitle); |  | 
| 1309     } |  | 
| 1310 | 1307 | 
| 1311     if (!m_frame || oldTitle == m_title) | 1308     if (!m_frame || oldTitle == m_title) | 
| 1312         return; | 1309         return; | 
| 1313     m_frame->loader()->history()->setCurrentItemTitle(m_title); | 1310     m_frame->loader()->history()->setCurrentItemTitle(m_title); | 
| 1314     m_frame->loader()->client()->dispatchDidReceiveTitle(m_title); | 1311     m_frame->loader()->client()->dispatchDidReceiveTitle(m_title); | 
| 1315 } | 1312 } | 
| 1316 | 1313 | 
| 1317 void Document::setTitle(const String& title) | 1314 void Document::setTitle(const String& title) | 
| 1318 { | 1315 { | 
| 1319     // Title set by JavaScript -- overrides any title elements. | 1316     // Title set by JavaScript -- overrides any title elements. | 
| 1320     m_titleSetExplicitly = true; | 1317     m_titleSetExplicitly = true; | 
| 1321     if (!isHTMLDocument() && !isXHTMLDocument()) | 1318     if (!isHTMLDocument() && !isXHTMLDocument()) | 
| 1322         m_titleElement = 0; | 1319         m_titleElement = 0; | 
| 1323     else if (!m_titleElement) { | 1320     else if (!m_titleElement) { | 
| 1324         if (HTMLElement* headElement = head()) { | 1321         if (HTMLElement* headElement = head()) { | 
| 1325             m_titleElement = createElement(titleTag, false); | 1322             m_titleElement = createElement(titleTag, false); | 
| 1326             headElement->appendChild(m_titleElement); | 1323             headElement->appendChild(m_titleElement); | 
| 1327         } | 1324         } | 
| 1328     } | 1325     } | 
| 1329 | 1326 | 
| 1330     // The DOM API has no method of specifying direction, so assume LTR. | 1327     updateTitle(title); | 
| 1331     updateTitle(StringWithDirection(title, LTR)); |  | 
| 1332 | 1328 | 
| 1333     if (m_titleElement) { | 1329     if (m_titleElement) { | 
| 1334         ASSERT(isHTMLTitleElement(m_titleElement.get())); | 1330         ASSERT(isHTMLTitleElement(m_titleElement.get())); | 
| 1335         if (isHTMLTitleElement(m_titleElement.get())) | 1331         if (isHTMLTitleElement(m_titleElement.get())) | 
| 1336             toHTMLTitleElement(m_titleElement.get())->setText(title); | 1332             toHTMLTitleElement(m_titleElement.get())->setText(title); | 
| 1337     } | 1333     } | 
| 1338 } | 1334 } | 
| 1339 | 1335 | 
| 1340 void Document::setTitleElement(const StringWithDirection& title, Element* titleE
      lement) | 1336 void Document::setTitleElement(const String& title, Element* titleElement) | 
| 1341 { | 1337 { | 
| 1342     if (titleElement != m_titleElement) { | 1338     if (titleElement != m_titleElement) { | 
| 1343         if (m_titleElement || m_titleSetExplicitly) | 1339         if (m_titleElement || m_titleSetExplicitly) | 
| 1344             // Only allow the first title element to change the title -- others 
      have no effect. | 1340             // Only allow the first title element to change the title -- others 
      have no effect. | 
| 1345             return; | 1341             return; | 
| 1346         m_titleElement = titleElement; | 1342         m_titleElement = titleElement; | 
| 1347     } | 1343     } | 
| 1348 | 1344 | 
| 1349     updateTitle(title); | 1345     updateTitle(title); | 
| 1350 } | 1346 } | 
| 1351 | 1347 | 
| 1352 void Document::removeTitle(Element* titleElement) | 1348 void Document::removeTitle(Element* titleElement) | 
| 1353 { | 1349 { | 
| 1354     if (m_titleElement != titleElement) | 1350     if (m_titleElement != titleElement) | 
| 1355         return; | 1351         return; | 
| 1356 | 1352 | 
| 1357     m_titleElement = 0; | 1353     m_titleElement = 0; | 
| 1358     m_titleSetExplicitly = false; | 1354     m_titleSetExplicitly = false; | 
| 1359 | 1355 | 
|  | 1356     // FIXME: This is broken for SVG. | 
| 1360     // Update title based on first title element in the head, if one exists. | 1357     // Update title based on first title element in the head, if one exists. | 
| 1361     if (HTMLElement* headElement = head()) { | 1358     if (HTMLElement* headElement = head()) { | 
| 1362         for (Node* e = headElement->firstChild(); e; e = e->nextSibling()) { | 1359         for (Element* element = headElement->firstElementChild(); element; eleme
      nt = element->nextElementSibling()) { | 
| 1363             if (isHTMLTitleElement(e)) { | 1360             if (!isHTMLTitleElement(element)) | 
| 1364                 HTMLTitleElement* titleElement = toHTMLTitleElement(e); | 1361                 continue; | 
| 1365                 setTitleElement(titleElement->textWithDirection(), titleElement)
      ; | 1362             HTMLTitleElement* title = toHTMLTitleElement(element); | 
| 1366                 break; | 1363             setTitleElement(title->text(), title); | 
| 1367             } | 1364             break; | 
| 1368         } | 1365         } | 
| 1369     } | 1366     } | 
| 1370 | 1367 | 
| 1371     if (!m_titleElement) | 1368     if (!m_titleElement) | 
| 1372         updateTitle(StringWithDirection()); | 1369         updateTitle(String()); | 
| 1373 } | 1370 } | 
| 1374 | 1371 | 
| 1375 PageVisibilityState Document::visibilityState() const | 1372 PageVisibilityState Document::visibilityState() const | 
| 1376 { | 1373 { | 
| 1377     // The visibility of the document is inherited from the visibility of the | 1374     // The visibility of the document is inherited from the visibility of the | 
| 1378     // page. If there is no page associated with the document, we will assume | 1375     // page. If there is no page associated with the document, we will assume | 
| 1379     // that the page is hidden, as specified by the spec: | 1376     // that the page is hidden, as specified by the spec: | 
| 1380     // http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.
      html#dom-document-hidden | 1377     // http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.
      html#dom-document-hidden | 
| 1381     if (!m_frame || !m_frame->page()) | 1378     if (!m_frame || !m_frame->page()) | 
| 1382         return PageVisibilityStateHidden; | 1379         return PageVisibilityStateHidden; | 
| (...skipping 3859 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 5242 { | 5239 { | 
| 5243     return DocumentLifecycleNotifier::create(this); | 5240     return DocumentLifecycleNotifier::create(this); | 
| 5244 } | 5241 } | 
| 5245 | 5242 | 
| 5246 DocumentLifecycleNotifier* Document::lifecycleNotifier() | 5243 DocumentLifecycleNotifier* Document::lifecycleNotifier() | 
| 5247 { | 5244 { | 
| 5248     return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec
      ycleNotifier()); | 5245     return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec
      ycleNotifier()); | 
| 5249 } | 5246 } | 
| 5250 | 5247 | 
| 5251 } // namespace WebCore | 5248 } // namespace WebCore | 
| OLD | NEW | 
|---|