| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/dom/custom/CustomElementObserver.h" | 32 #include "core/dom/custom/CustomElementObserver.h" |
| 33 | 33 |
| 34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 // Maps elements to the observer watching them. At most one per | 38 // Maps elements to the observer watching them. At most one per |
| 39 // element at a time. | 39 // element at a time. |
| 40 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<Element>, RawPtrWillBeMember<Cu
stomElementObserver> > ElementObserverMap; | 40 typedef WillBeHeapHashMap<RawPtrWillBeWeakMember<Element>, RawPtrWillBeMember<Cu
stomElementObserver>> ElementObserverMap; |
| 41 | 41 |
| 42 static ElementObserverMap& elementObservers() | 42 static ElementObserverMap& elementObservers() |
| 43 { | 43 { |
| 44 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ElementObserverMap>, map, (adoptP
trWillBeNoop(new ElementObserverMap()))); | 44 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<ElementObserverMap>, map, (adoptP
trWillBeNoop(new ElementObserverMap()))); |
| 45 return *map; | 45 return *map; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void CustomElementObserver::notifyElementWasDestroyed(Element* element) | 48 void CustomElementObserver::notifyElementWasDestroyed(Element* element) |
| 49 { | 49 { |
| 50 ElementObserverMap::iterator it = elementObservers().find(element); | 50 ElementObserverMap::iterator it = elementObservers().find(element); |
| 51 if (it == elementObservers().end()) | 51 if (it == elementObservers().end()) |
| 52 return; | 52 return; |
| 53 it->value->elementWasDestroyed(element); | 53 it->value->elementWasDestroyed(element); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void CustomElementObserver::observe(Element* element) | 56 void CustomElementObserver::observe(Element* element) |
| 57 { | 57 { |
| 58 ElementObserverMap::AddResult result = elementObservers().add(element, this)
; | 58 ElementObserverMap::AddResult result = elementObservers().add(element, this)
; |
| 59 ASSERT_UNUSED(result, result.isNewEntry); | 59 ASSERT_UNUSED(result, result.isNewEntry); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void CustomElementObserver::unobserve(Element* element) | 62 void CustomElementObserver::unobserve(Element* element) |
| 63 { | 63 { |
| 64 CustomElementObserver* observer = elementObservers().take(element); | 64 CustomElementObserver* observer = elementObservers().take(element); |
| 65 ASSERT_UNUSED(observer, observer == this); | 65 ASSERT_UNUSED(observer, observer == this); |
| 66 } | 66 } |
| 67 | 67 |
| 68 } // namespace blink | 68 } // namespace blink |
| OLD | NEW |