Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple 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 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (CanWriteData()) | 163 if (CanWriteData()) |
| 164 effect_allowed_ = effect; | 164 effect_allowed_ = effect; |
| 165 } | 165 } |
| 166 | 166 |
| 167 void DataTransfer::clearData(const String& type) { | 167 void DataTransfer::clearData(const String& type) { |
| 168 if (!CanWriteData()) | 168 if (!CanWriteData()) |
| 169 return; | 169 return; |
| 170 | 170 |
| 171 const size_t old_length = data_object_->length(); | |
| 172 | |
| 171 if (type.IsNull()) | 173 if (type.IsNull()) |
| 172 data_object_->ClearAll(); | 174 data_object_->ClearAll(); |
| 173 else | 175 else |
| 174 data_object_->ClearData(NormalizeType(type)); | 176 data_object_->ClearData(NormalizeType(type)); |
| 177 | |
| 178 if (old_length != data_object_->length()) | |
| 179 data_store_item_list_changed_ = true; | |
| 175 } | 180 } |
| 176 | 181 |
| 177 String DataTransfer::getData(const String& type) const { | 182 String DataTransfer::getData(const String& type) const { |
| 178 if (!CanReadData()) | 183 if (!CanReadData()) |
| 179 return String(); | 184 return String(); |
| 180 | 185 |
| 181 bool convert_to_url = false; | 186 bool convert_to_url = false; |
| 182 String data = data_object_->GetData(NormalizeType(type, &convert_to_url)); | 187 String data = data_object_->GetData(NormalizeType(type, &convert_to_url)); |
| 183 if (!convert_to_url) | 188 if (!convert_to_url) |
| 184 return data; | 189 return data; |
| 185 return ConvertURIListToURL(data); | 190 return ConvertURIListToURL(data); |
| 186 } | 191 } |
| 187 | 192 |
| 188 void DataTransfer::setData(const String& type, const String& data) { | 193 void DataTransfer::setData(const String& type, const String& data) { |
| 189 if (!CanWriteData()) | 194 if (!CanWriteData()) |
| 190 return; | 195 return; |
| 191 | 196 |
| 192 data_object_->SetData(NormalizeType(type), data); | 197 data_object_->SetData(NormalizeType(type), data); |
| 198 data_store_item_list_changed_ = true; | |
| 193 } | 199 } |
| 194 | 200 |
| 195 // extensions beyond IE's API | 201 bool DataTransfer::hasDataStoreItemListChanged() const { |
| 196 Vector<String> DataTransfer::types() const { | 202 return data_store_item_list_changed_ || !CanReadTypes(); |
|
foolip
2017/05/15 15:11:02
Is there a test that would fail if the CanReadType
Raphael Kubo da Costa (rakuco)
2017/05/15 15:17:59
Yes; the previous iterations of this CL didn't hav
| |
| 203 } | |
| 204 | |
| 205 Vector<String> DataTransfer::types() { | |
| 197 Vector<String> types; | 206 Vector<String> types; |
| 198 if (!CanReadTypes()) | 207 if (!CanReadTypes()) |
| 199 return types; | 208 return types; |
| 200 | 209 |
| 210 data_store_item_list_changed_ = false; | |
| 201 return data_object_->Types(); | 211 return data_object_->Types(); |
| 202 } | 212 } |
| 203 | 213 |
| 204 FileList* DataTransfer::files() const { | 214 FileList* DataTransfer::files() const { |
| 205 FileList* files = FileList::Create(); | 215 FileList* files = FileList::Create(); |
| 206 if (!CanReadData()) | 216 if (!CanReadData()) |
| 207 return files; | 217 return files; |
| 208 | 218 |
| 209 for (size_t i = 0; i < data_object_->length(); ++i) { | 219 for (size_t i = 0; i < data_object_->length(); ++i) { |
| 210 if (data_object_->Item(i)->Kind() == DataObjectItem::kFileKind) { | 220 if (data_object_->Item(i)->Kind() == DataObjectItem::kFileKind) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 return data_object_; | 432 return data_object_; |
| 423 } | 433 } |
| 424 | 434 |
| 425 DataTransfer::DataTransfer(DataTransferType type, | 435 DataTransfer::DataTransfer(DataTransferType type, |
| 426 DataTransferAccessPolicy policy, | 436 DataTransferAccessPolicy policy, |
| 427 DataObject* data_object) | 437 DataObject* data_object) |
| 428 : policy_(policy), | 438 : policy_(policy), |
| 429 drop_effect_("uninitialized"), | 439 drop_effect_("uninitialized"), |
| 430 effect_allowed_("uninitialized"), | 440 effect_allowed_("uninitialized"), |
| 431 transfer_type_(type), | 441 transfer_type_(type), |
| 432 data_object_(data_object) {} | 442 data_object_(data_object), |
| 443 data_store_item_list_changed_(true) {} | |
| 433 | 444 |
| 434 void DataTransfer::setDragImage(ImageResourceContent* image, | 445 void DataTransfer::setDragImage(ImageResourceContent* image, |
| 435 Node* node, | 446 Node* node, |
| 436 const IntPoint& loc) { | 447 const IntPoint& loc) { |
| 437 if (!CanSetDragImage()) | 448 if (!CanSetDragImage()) |
| 438 return; | 449 return; |
| 439 | 450 |
| 440 drag_image_ = image; | 451 drag_image_ = image; |
| 441 drag_loc_ = loc; | 452 drag_loc_ = loc; |
| 442 drag_image_element_ = node; | 453 drag_image_element_ = node; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 454 return true; | 465 return true; |
| 455 } | 466 } |
| 456 } | 467 } |
| 457 return false; | 468 return false; |
| 458 } | 469 } |
| 459 | 470 |
| 460 bool DataTransfer::HasStringOfType(const String& type) const { | 471 bool DataTransfer::HasStringOfType(const String& type) const { |
| 461 if (!CanReadTypes()) | 472 if (!CanReadTypes()) |
| 462 return false; | 473 return false; |
| 463 | 474 |
| 464 return types().Contains(type); | 475 return data_object_->Types().Contains(type); |
| 465 } | 476 } |
| 466 | 477 |
| 467 DragOperation ConvertDropZoneOperationToDragOperation( | 478 DragOperation ConvertDropZoneOperationToDragOperation( |
| 468 const String& drag_operation) { | 479 const String& drag_operation) { |
| 469 if (drag_operation == "copy") | 480 if (drag_operation == "copy") |
| 470 return kDragOperationCopy; | 481 return kDragOperationCopy; |
| 471 if (drag_operation == "move") | 482 if (drag_operation == "move") |
| 472 return kDragOperationMove; | 483 return kDragOperationMove; |
| 473 if (drag_operation == "link") | 484 if (drag_operation == "link") |
| 474 return kDragOperationLink; | 485 return kDragOperationLink; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 488 } | 499 } |
| 489 } | 500 } |
| 490 | 501 |
| 491 DEFINE_TRACE(DataTransfer) { | 502 DEFINE_TRACE(DataTransfer) { |
| 492 visitor->Trace(data_object_); | 503 visitor->Trace(data_object_); |
| 493 visitor->Trace(drag_image_); | 504 visitor->Trace(drag_image_); |
| 494 visitor->Trace(drag_image_element_); | 505 visitor->Trace(drag_image_element_); |
| 495 } | 506 } |
| 496 | 507 |
| 497 } // namespace blink | 508 } // namespace blink |
| OLD | NEW |