OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008, 2009 Google Inc. | 3 * Copyright (C) 2008, 2009 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
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 17 matching lines...) Expand all Loading... |
28 #include "core/clipboard/DataTransferItemList.h" | 28 #include "core/clipboard/DataTransferItemList.h" |
29 | 29 |
30 #include "bindings/core/v8/ExceptionState.h" | 30 #include "bindings/core/v8/ExceptionState.h" |
31 #include "core/clipboard/DataObject.h" | 31 #include "core/clipboard/DataObject.h" |
32 #include "core/clipboard/DataTransfer.h" | 32 #include "core/clipboard/DataTransfer.h" |
33 #include "core/clipboard/DataTransferItem.h" | 33 #include "core/clipboard/DataTransferItem.h" |
34 #include "core/dom/ExceptionCode.h" | 34 #include "core/dom/ExceptionCode.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(DataTransferItemList); | 38 DataTransferItemList* DataTransferItemList::create(DataTransfer* dataTransfer, D
ataObject* list) |
39 | |
40 PassRefPtrWillBeRawPtr<DataTransferItemList> DataTransferItemList::create(PassRe
fPtrWillBeRawPtr<DataTransfer> dataTransfer, PassRefPtrWillBeRawPtr<DataObject>
list) | |
41 { | 39 { |
42 return adoptRefWillBeNoop(new DataTransferItemList(dataTransfer, list)); | 40 return new DataTransferItemList(dataTransfer, list); |
43 } | 41 } |
44 | 42 |
45 size_t DataTransferItemList::length() const | 43 size_t DataTransferItemList::length() const |
46 { | 44 { |
47 if (!m_dataTransfer->canReadTypes()) | 45 if (!m_dataTransfer->canReadTypes()) |
48 return 0; | 46 return 0; |
49 return m_dataObject->length(); | 47 return m_dataObject->length(); |
50 } | 48 } |
51 | 49 |
52 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::item(unsigned lon
g index) | 50 DataTransferItem* DataTransferItemList::item(unsigned long index) |
53 { | 51 { |
54 if (!m_dataTransfer->canReadTypes()) | 52 if (!m_dataTransfer->canReadTypes()) |
55 return nullptr; | 53 return nullptr; |
56 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->item(index); | 54 DataObjectItem* item = m_dataObject->item(index); |
57 if (!item) | 55 if (!item) |
58 return nullptr; | 56 return nullptr; |
59 | 57 |
60 return DataTransferItem::create(m_dataTransfer, item); | 58 return DataTransferItem::create(m_dataTransfer, item); |
61 } | 59 } |
62 | 60 |
63 void DataTransferItemList::deleteItem(unsigned long index, ExceptionState& excep
tionState) | 61 void DataTransferItemList::deleteItem(unsigned long index, ExceptionState& excep
tionState) |
64 { | 62 { |
65 if (!m_dataTransfer->canWriteData()) { | 63 if (!m_dataTransfer->canWriteData()) { |
66 exceptionState.throwDOMException(InvalidStateError, "The list is not wri
table."); | 64 exceptionState.throwDOMException(InvalidStateError, "The list is not wri
table."); |
67 return; | 65 return; |
68 } | 66 } |
69 m_dataObject->deleteItem(index); | 67 m_dataObject->deleteItem(index); |
70 } | 68 } |
71 | 69 |
72 void DataTransferItemList::clear() | 70 void DataTransferItemList::clear() |
73 { | 71 { |
74 if (!m_dataTransfer->canWriteData()) | 72 if (!m_dataTransfer->canWriteData()) |
75 return; | 73 return; |
76 m_dataObject->clearAll(); | 74 m_dataObject->clearAll(); |
77 } | 75 } |
78 | 76 |
79 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::add(const String&
data, const String& type, ExceptionState& exceptionState) | 77 DataTransferItem* DataTransferItemList::add(const String& data, const String& ty
pe, ExceptionState& exceptionState) |
80 { | 78 { |
81 if (!m_dataTransfer->canWriteData()) | 79 if (!m_dataTransfer->canWriteData()) |
82 return nullptr; | 80 return nullptr; |
83 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->add(data, type); | 81 DataObjectItem* item = m_dataObject->add(data, type); |
84 if (!item) { | 82 if (!item) { |
85 exceptionState.throwDOMException(NotSupportedError, "An item already exi
sts for type '" + type + "'."); | 83 exceptionState.throwDOMException(NotSupportedError, "An item already exi
sts for type '" + type + "'."); |
86 return nullptr; | 84 return nullptr; |
87 } | 85 } |
88 return DataTransferItem::create(m_dataTransfer, item); | 86 return DataTransferItem::create(m_dataTransfer, item); |
89 } | 87 } |
90 | 88 |
91 PassRefPtrWillBeRawPtr<DataTransferItem> DataTransferItemList::add(File* file) | 89 DataTransferItem* DataTransferItemList::add(File* file) |
92 { | 90 { |
93 if (!m_dataTransfer->canWriteData()) | 91 if (!m_dataTransfer->canWriteData()) |
94 return nullptr; | 92 return nullptr; |
95 RefPtrWillBeRawPtr<DataObjectItem> item = m_dataObject->add(file); | 93 DataObjectItem* item = m_dataObject->add(file); |
96 if (!item) | 94 if (!item) |
97 return nullptr; | 95 return nullptr; |
98 return DataTransferItem::create(m_dataTransfer, item); | 96 return DataTransferItem::create(m_dataTransfer, item); |
99 } | 97 } |
100 | 98 |
101 DataTransferItemList::DataTransferItemList(PassRefPtrWillBeRawPtr<DataTransfer>
dataTransfer, PassRefPtrWillBeRawPtr<DataObject> dataObject) | 99 DataTransferItemList::DataTransferItemList(DataTransfer* dataTransfer, DataObjec
t* dataObject) |
102 : m_dataTransfer(dataTransfer) | 100 : m_dataTransfer(dataTransfer) |
103 , m_dataObject(dataObject) | 101 , m_dataObject(dataObject) |
104 { | 102 { |
105 } | 103 } |
106 | 104 |
107 DEFINE_TRACE(DataTransferItemList) | 105 DEFINE_TRACE(DataTransferItemList) |
108 { | 106 { |
109 visitor->trace(m_dataTransfer); | 107 visitor->trace(m_dataTransfer); |
110 visitor->trace(m_dataObject); | 108 visitor->trace(m_dataObject); |
111 } | 109 } |
112 | 110 |
113 } // namespace blink | 111 } // namespace blink |
OLD | NEW |