OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/attributes.h" |
| 6 |
| 7 namespace views { |
| 8 |
| 9 AttributeId Attribute::Identity() const { |
| 10 return GetAttributeId<Attribute>(); |
| 11 } |
| 12 |
| 13 AttributeContainer::AttributeContainer(View* view) : view_(view) {} |
| 14 |
| 15 AttributeContainer::AttributeContainer() : view_(nullptr) {} |
| 16 |
| 17 AttributeContainer::~AttributeContainer() {} |
| 18 |
| 19 bool AttributeContainer::Remove(const AttributeId attributeId) { |
| 20 AttributeMap::const_iterator it = map_.find(attributeId); |
| 21 bool canRemove = it != map_.cend(); |
| 22 if (canRemove) { |
| 23 Notification(Attribute::NotifyType::AttributeRemoved, it->second.get()); |
| 24 it->second.get()->RemovedFromView(); |
| 25 map_.erase(it); |
| 26 } |
| 27 return canRemove; |
| 28 } |
| 29 |
| 30 void AttributeContainer::Notification(Attribute::NotifyType type, |
| 31 Attribute* attribute) { |
| 32 for (AttributeMap::const_iterator a = map_.cbegin(); a != map_.cend(); a++) { |
| 33 Attribute* attr = a->second.get(); |
| 34 if (attr != attribute) |
| 35 attr->Notification(type, attribute); |
| 36 } |
| 37 } |
| 38 |
| 39 void AttributeContainer::ViewNotification(View* view) { |
| 40 for (AttributeMap::const_iterator a = map_.cbegin(); a != map_.cend(); a++) |
| 41 a->second.get()->ViewNotification(view); |
| 42 } |
| 43 |
| 44 AttributeIdFactory::AttributeIdMap AttributeIdFactory::map_; |
| 45 |
| 46 AttributeId AttributeIdFactory::GetAttributeId(const char* typeName) { |
| 47 std::string type_name = typeName; |
| 48 AttributeIdMap::const_iterator it = map_.find(type_name); |
| 49 if (it == map_.cend()) { |
| 50 std::unique_ptr<AttributeIdHolder> holder = |
| 51 base::WrapUnique(new AttributeIdHolder()); |
| 52 it = map_.insert(AttributeIdMap::value_type(type_name, std::move(holder))) |
| 53 .first; |
| 54 } |
| 55 return it->second.get()->GetAttributeId(); |
| 56 } |
| 57 |
| 58 } // namespace views |
OLD | NEW |