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 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. | 4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All r
ights reserved. |
5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. | 5 * Copyright (C) 2014 Samsung Electronics. All rights reserved. |
6 * | 6 * |
7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta
te&) | 435 void HTMLCollection::namedPropertyEnumerator(Vector<String>& names, ExceptionSta
te&) |
436 { | 436 { |
437 supportedPropertyNames(names); | 437 supportedPropertyNames(names); |
438 } | 438 } |
439 | 439 |
440 void HTMLCollection::updateIdNameCache() const | 440 void HTMLCollection::updateIdNameCache() const |
441 { | 441 { |
442 if (hasValidIdNameCache()) | 442 if (hasValidIdNameCache()) |
443 return; | 443 return; |
444 | 444 |
445 NamedItemCache& cache = createNamedItemCache(); | 445 OwnPtr<NamedItemCache> cache = NamedItemCache::create(); |
446 for (Element* element = traverseToFirstElement(); element; element = travers
eNextElement(*element)) { | 446 for (Element* element = traverseToFirstElement(); element; element = travers
eNextElement(*element)) { |
447 const AtomicString& idAttrVal = element->getIdAttribute(); | 447 const AtomicString& idAttrVal = element->getIdAttribute(); |
448 if (!idAttrVal.isEmpty()) | 448 if (!idAttrVal.isEmpty()) |
449 cache.addElementWithId(idAttrVal, element); | 449 cache->addElementWithId(idAttrVal, element); |
450 if (!element->isHTMLElement()) | 450 if (!element->isHTMLElement()) |
451 continue; | 451 continue; |
452 const AtomicString& nameAttrVal = element->getNameAttribute(); | 452 const AtomicString& nameAttrVal = element->getNameAttribute(); |
453 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc
All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) | 453 if (!nameAttrVal.isEmpty() && idAttrVal != nameAttrVal && (type() != Doc
All || nameShouldBeVisibleInDocumentAll(toHTMLElement(*element)))) |
454 cache.addElementWithName(nameAttrVal, element); | 454 cache->addElementWithName(nameAttrVal, element); |
455 } | 455 } |
| 456 // Set the named item cache last as traversing the tree may cause cache inva
lidation. |
| 457 setNamedItemCache(cache.release()); |
456 } | 458 } |
457 | 459 |
458 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
>& result) const | 460 void HTMLCollection::namedItems(const AtomicString& name, Vector<RefPtr<Element>
>& result) const |
459 { | 461 { |
460 ASSERT(result.isEmpty()); | 462 ASSERT(result.isEmpty()); |
461 if (name.isEmpty()) | 463 if (name.isEmpty()) |
462 return; | 464 return; |
463 | 465 |
464 updateIdNameCache(); | 466 updateIdNameCache(); |
465 | 467 |
466 const NamedItemCache& cache = namedItemCache(); | 468 const NamedItemCache& cache = namedItemCache(); |
467 Vector<Element*>* idResults = cache.getElementsById(name); | 469 Vector<Element*>* idResults = cache.getElementsById(name); |
468 Vector<Element*>* nameResults = cache.getElementsByName(name); | 470 Vector<Element*>* nameResults = cache.getElementsByName(name); |
469 | 471 |
470 for (unsigned i = 0; idResults && i < idResults->size(); ++i) | 472 for (unsigned i = 0; idResults && i < idResults->size(); ++i) |
471 result.append(idResults->at(i)); | 473 result.append(idResults->at(i)); |
472 | 474 |
473 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i) | 475 for (unsigned i = 0; nameResults && i < nameResults->size(); ++i) |
474 result.append(nameResults->at(i)); | 476 result.append(nameResults->at(i)); |
475 } | 477 } |
476 | 478 |
| 479 HTMLCollection::NamedItemCache::NamedItemCache() |
| 480 { |
| 481 } |
| 482 |
477 } // namespace WebCore | 483 } // namespace WebCore |
OLD | NEW |