OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2008, 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, 2012 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 DataObjectItem* DataObject::Item(unsigned long index) { | 83 DataObjectItem* DataObject::Item(unsigned long index) { |
84 if (index >= length()) | 84 if (index >= length()) |
85 return nullptr; | 85 return nullptr; |
86 return item_list_[index]; | 86 return item_list_[index]; |
87 } | 87 } |
88 | 88 |
89 void DataObject::DeleteItem(unsigned long index) { | 89 void DataObject::DeleteItem(unsigned long index) { |
90 if (index >= length()) | 90 if (index >= length()) |
91 return; | 91 return; |
92 item_list_.erase(index); | 92 item_list_.erase(index); |
93 NotifyItemListChanged(); | |
93 } | 94 } |
94 | 95 |
95 void DataObject::ClearAll() { | 96 void DataObject::ClearAll() { |
97 const size_t old_length = item_list_.size(); | |
jsbell
2017/05/15 20:49:28
We don't care about the size specifically, just th
Raphael Kubo da Costa (rakuco)
2017/05/16 08:51:51
Done.
| |
96 item_list_.clear(); | 98 item_list_.clear(); |
99 if (old_length != item_list_.size()) | |
100 NotifyItemListChanged(); | |
97 } | 101 } |
98 | 102 |
99 DataObjectItem* DataObject::Add(const String& data, const String& type) { | 103 DataObjectItem* DataObject::Add(const String& data, const String& type) { |
100 DataObjectItem* item = DataObjectItem::CreateFromString(type, data); | 104 DataObjectItem* item = DataObjectItem::CreateFromString(type, data); |
101 if (!InternalAddStringItem(item)) | 105 if (!InternalAddStringItem(item)) |
102 return nullptr; | 106 return nullptr; |
103 return item; | 107 return item; |
104 } | 108 } |
105 | 109 |
106 DataObjectItem* DataObject::Add(File* file) { | 110 DataObjectItem* DataObject::Add(File* file) { |
(...skipping 14 matching lines...) Expand all Loading... | |
121 InternalAddFileItem(item); | 125 InternalAddFileItem(item); |
122 return item; | 126 return item; |
123 } | 127 } |
124 | 128 |
125 void DataObject::ClearData(const String& type) { | 129 void DataObject::ClearData(const String& type) { |
126 for (size_t i = 0; i < item_list_.size(); ++i) { | 130 for (size_t i = 0; i < item_list_.size(); ++i) { |
127 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && | 131 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && |
128 item_list_[i]->GetType() == type) { | 132 item_list_[i]->GetType() == type) { |
129 // Per the spec, type must be unique among all items of kind 'string'. | 133 // Per the spec, type must be unique among all items of kind 'string'. |
130 item_list_.erase(i); | 134 item_list_.erase(i); |
135 NotifyItemListChanged(); | |
131 return; | 136 return; |
132 } | 137 } |
133 } | 138 } |
134 } | 139 } |
135 | 140 |
136 Vector<String> DataObject::Types() const { | 141 Vector<String> DataObject::Types() const { |
137 Vector<String> results; | 142 Vector<String> results; |
138 #if DCHECK_IS_ON() | 143 #if DCHECK_IS_ON() |
139 HashSet<String> types_seen; | 144 HashSet<String> types_seen; |
140 #endif | 145 #endif |
(...skipping 25 matching lines...) Expand all Loading... | |
166 for (size_t i = 0; i < item_list_.size(); ++i) { | 171 for (size_t i = 0; i < item_list_.size(); ++i) { |
167 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && | 172 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && |
168 item_list_[i]->GetType() == type) | 173 item_list_[i]->GetType() == type) |
169 return item_list_[i]->GetAsString(); | 174 return item_list_[i]->GetAsString(); |
170 } | 175 } |
171 return String(); | 176 return String(); |
172 } | 177 } |
173 | 178 |
174 void DataObject::SetData(const String& type, const String& data) { | 179 void DataObject::SetData(const String& type, const String& data) { |
175 ClearData(type); | 180 ClearData(type); |
176 if (!Add(data, type)) | 181 if (!Add(data, type)) |
jsbell
2017/05/15 20:49:28
We'll get two calls to NotifyItemListChanged() for
Raphael Kubo da Costa (rakuco)
2017/05/16 08:51:51
It doesn't hurt either, so I've added a small comm
| |
177 NOTREACHED(); | 182 NOTREACHED(); |
178 } | 183 } |
179 | 184 |
180 void DataObject::UrlAndTitle(String& url, String* title) const { | 185 void DataObject::UrlAndTitle(String& url, String* title) const { |
181 DataObjectItem* item = FindStringItem(kMimeTypeTextURIList); | 186 DataObjectItem* item = FindStringItem(kMimeTypeTextURIList); |
182 if (!item) | 187 if (!item) |
183 return; | 188 return; |
184 url = ConvertURIListToURL(item->GetAsString()); | 189 url = ConvertURIListToURL(item->GetAsString()); |
185 if (title) | 190 if (title) |
186 *title = item->Title(); | 191 *title = item->Title(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 254 |
250 bool DataObject::InternalAddStringItem(DataObjectItem* item) { | 255 bool DataObject::InternalAddStringItem(DataObjectItem* item) { |
251 ASSERT(item->Kind() == DataObjectItem::kStringKind); | 256 ASSERT(item->Kind() == DataObjectItem::kStringKind); |
252 for (size_t i = 0; i < item_list_.size(); ++i) { | 257 for (size_t i = 0; i < item_list_.size(); ++i) { |
253 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && | 258 if (item_list_[i]->Kind() == DataObjectItem::kStringKind && |
254 item_list_[i]->GetType() == item->GetType()) | 259 item_list_[i]->GetType() == item->GetType()) |
255 return false; | 260 return false; |
256 } | 261 } |
257 | 262 |
258 item_list_.push_back(item); | 263 item_list_.push_back(item); |
264 NotifyItemListChanged(); | |
259 return true; | 265 return true; |
260 } | 266 } |
261 | 267 |
262 void DataObject::InternalAddFileItem(DataObjectItem* item) { | 268 void DataObject::InternalAddFileItem(DataObjectItem* item) { |
263 ASSERT(item->Kind() == DataObjectItem::kFileKind); | 269 ASSERT(item->Kind() == DataObjectItem::kFileKind); |
264 item_list_.push_back(item); | 270 item_list_.push_back(item); |
271 NotifyItemListChanged(); | |
272 } | |
273 | |
274 void DataObject::AddObserver(Observer* observer) { | |
275 DCHECK(!observers_.Contains(observer)); | |
276 observers_.insert(observer); | |
277 } | |
278 | |
279 void DataObject::NotifyItemListChanged() const { | |
280 for (const auto& observer : observers_) | |
281 observer->OnItemListChanged(); | |
265 } | 282 } |
266 | 283 |
267 DEFINE_TRACE(DataObject) { | 284 DEFINE_TRACE(DataObject) { |
268 visitor->Trace(item_list_); | 285 visitor->Trace(item_list_); |
286 visitor->Trace(observers_); | |
269 Supplementable<DataObject>::Trace(visitor); | 287 Supplementable<DataObject>::Trace(visitor); |
270 } | 288 } |
271 | 289 |
272 DataObject* DataObject::Create(WebDragData data) { | 290 DataObject* DataObject::Create(WebDragData data) { |
273 DataObject* data_object = Create(); | 291 DataObject* data_object = Create(); |
274 bool has_file_system = false; | 292 bool has_file_system = false; |
275 | 293 |
276 WebVector<WebDragData::Item> items = data.Items(); | 294 WebVector<WebDragData::Item> items = data.Items(); |
277 for (unsigned i = 0; i < items.size(); ++i) { | 295 for (unsigned i = 0; i < items.size(); ++i) { |
278 WebDragData::Item item = items[i]; | 296 WebDragData::Item item = items[i]; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 } else { | 387 } else { |
370 NOTREACHED(); | 388 NOTREACHED(); |
371 } | 389 } |
372 item_list[i] = item; | 390 item_list[i] = item; |
373 } | 391 } |
374 data.SwapItems(item_list); | 392 data.SwapItems(item_list); |
375 return data; | 393 return data; |
376 } | 394 } |
377 | 395 |
378 } // namespace blink | 396 } // namespace blink |
OLD | NEW |