Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/Source/core/clipboard/DataTransfer.cpp

Issue 2393013002: reflow comments in core/{clipboard,streams,testing,timing} (Closed)
Patch Set: comments (heh!) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 30 matching lines...) Expand all
41 #include "core/layout/LayoutObject.h" 41 #include "core/layout/LayoutObject.h"
42 #include "platform/DragImage.h" 42 #include "platform/DragImage.h"
43 #include "platform/MIMETypeRegistry.h" 43 #include "platform/MIMETypeRegistry.h"
44 #include "platform/clipboard/ClipboardMimeTypes.h" 44 #include "platform/clipboard/ClipboardMimeTypes.h"
45 #include "platform/clipboard/ClipboardUtilities.h" 45 #include "platform/clipboard/ClipboardUtilities.h"
46 #include <memory> 46 #include <memory>
47 47
48 namespace blink { 48 namespace blink {
49 49
50 static DragOperation convertEffectAllowedToDragOperation(const String& op) { 50 static DragOperation convertEffectAllowedToDragOperation(const String& op) {
51 // Values specified in http://www.whatwg.org/specs/web-apps/current-work/multi page/dnd.html#dom-datatransfer-effectallowed 51 // Values specified in
52 // http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html#dom-da tatransfer-effectallowed
52 if (op == "uninitialized") 53 if (op == "uninitialized")
53 return DragOperationEvery; 54 return DragOperationEvery;
54 if (op == "none") 55 if (op == "none")
55 return DragOperationNone; 56 return DragOperationNone;
56 if (op == "copy") 57 if (op == "copy")
57 return DragOperationCopy; 58 return DragOperationCopy;
58 if (op == "link") 59 if (op == "link")
59 return DragOperationLink; 60 return DragOperationLink;
60 if (op == "move") 61 if (op == "move")
61 return (DragOperation)(DragOperationGeneric | DragOperationMove); 62 return (DragOperation)(DragOperationGeneric | DragOperationMove);
(...skipping 24 matching lines...) Expand all
86 return "copyLink"; 87 return "copyLink";
87 if (moveSet) 88 if (moveSet)
88 return "move"; 89 return "move";
89 if (op & DragOperationCopy) 90 if (op & DragOperationCopy)
90 return "copy"; 91 return "copy";
91 if (op & DragOperationLink) 92 if (op & DragOperationLink)
92 return "link"; 93 return "link";
93 return "none"; 94 return "none";
94 } 95 }
95 96
96 // We provide the IE clipboard types (URL and Text), and the clipboard types spe cified in the WHATWG Web Applications 1.0 draft 97 // We provide the IE clipboard types (URL and Text), and the clipboard types
97 // see http://www.whatwg.org/specs/web-apps/current-work/ Section 6.3.5.3 98 // specified in the WHATWG Web Applications 1.0 draft see
99 // http://www.whatwg.org/specs/web-apps/current-work/ Section 6.3.5.3
98 static String normalizeType(const String& type, bool* convertToURL = 0) { 100 static String normalizeType(const String& type, bool* convertToURL = 0) {
99 String cleanType = type.stripWhiteSpace().lower(); 101 String cleanType = type.stripWhiteSpace().lower();
100 if (cleanType == mimeTypeText || cleanType.startsWith(mimeTypeTextPlainEtc)) 102 if (cleanType == mimeTypeText || cleanType.startsWith(mimeTypeTextPlainEtc))
101 return mimeTypeTextPlain; 103 return mimeTypeTextPlain;
102 if (cleanType == mimeTypeURL) { 104 if (cleanType == mimeTypeURL) {
103 if (convertToURL) 105 if (convertToURL)
104 *convertToURL = true; 106 *convertToURL = true;
105 return mimeTypeTextURIList; 107 return mimeTypeTextURIList;
106 } 108 }
107 return cleanType; 109 return cleanType;
108 } 110 }
109 111
110 DataTransfer* DataTransfer::create(DataTransferType type, 112 DataTransfer* DataTransfer::create(DataTransferType type,
111 DataTransferAccessPolicy policy, 113 DataTransferAccessPolicy policy,
112 DataObject* dataObject) { 114 DataObject* dataObject) {
113 return new DataTransfer(type, policy, dataObject); 115 return new DataTransfer(type, policy, dataObject);
114 } 116 }
115 117
116 DataTransfer::~DataTransfer() {} 118 DataTransfer::~DataTransfer() {}
117 119
118 void DataTransfer::setDropEffect(const String& effect) { 120 void DataTransfer::setDropEffect(const String& effect) {
119 if (!isForDragAndDrop()) 121 if (!isForDragAndDrop())
120 return; 122 return;
121 123
122 // The attribute must ignore any attempts to set it to a value other than none , copy, link, and move. 124 // The attribute must ignore any attempts to set it to a value other than
125 // none, copy, link, and move.
123 if (effect != "none" && effect != "copy" && effect != "link" && 126 if (effect != "none" && effect != "copy" && effect != "link" &&
124 effect != "move") 127 effect != "move")
125 return; 128 return;
126 129
127 // FIXME: The spec actually allows this in all circumstances, even though ther e's no point in 130 // FIXME: The spec actually allows this in all circumstances, even though
128 // setting the drop effect when this condition is not true. 131 // there's no point in setting the drop effect when this condition is not
132 // true.
129 if (canReadTypes()) 133 if (canReadTypes())
130 m_dropEffect = effect; 134 m_dropEffect = effect;
131 } 135 }
132 136
133 void DataTransfer::setEffectAllowed(const String& effect) { 137 void DataTransfer::setEffectAllowed(const String& effect) {
134 if (!isForDragAndDrop()) 138 if (!isForDragAndDrop())
135 return; 139 return;
136 140
137 if (convertEffectAllowedToDragOperation(effect) == DragOperationPrivate) { 141 if (convertEffectAllowedToDragOperation(effect) == DragOperationPrivate) {
138 // This means that there was no conversion, and the effectAllowed that 142 // This means that there was no conversion, and the effectAllowed that
139 // we are passed isn't a valid effectAllowed, so we should ignore it, 143 // we are passed isn't a valid effectAllowed, so we should ignore it,
140 // and not set m_effectAllowed. 144 // and not set m_effectAllowed.
141 145
142 // The attribute must ignore any attempts to set it to a value other than 146 // The attribute must ignore any attempts to set it to a value other than
143 // none, copy, copyLink, copyMove, link, linkMove, move, all, and uninitiali zed. 147 // none, copy, copyLink, copyMove, link, linkMove, move, all, and
148 // uninitialized.
144 return; 149 return;
145 } 150 }
146 151
147 if (canWriteData()) 152 if (canWriteData())
148 m_effectAllowed = effect; 153 m_effectAllowed = effect;
149 } 154 }
150 155
151 void DataTransfer::clearData(const String& type) { 156 void DataTransfer::clearData(const String& type) {
152 if (!canWriteData()) 157 if (!canWriteData())
153 return; 158 return;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 283
279 // Determine the filename for the file contents of the image. 284 // Determine the filename for the file contents of the image.
280 String filename = cachedImage->response().suggestedFilename(); 285 String filename = cachedImage->response().suggestedFilename();
281 if (filename.isEmpty()) 286 if (filename.isEmpty())
282 filename = url.lastPathComponent(); 287 filename = url.lastPathComponent();
283 288
284 String fileExtension; 289 String fileExtension;
285 if (filename.isEmpty()) { 290 if (filename.isEmpty()) {
286 filename = element->getAttribute(HTMLNames::altAttr); 291 filename = element->getAttribute(HTMLNames::altAttr);
287 } else { 292 } else {
288 // Strip any existing extension. Assume that alt text is usually not a filen ame. 293 // Strip any existing extension. Assume that alt text is usually not a
294 // filename.
289 int extensionIndex = filename.reverseFind('.'); 295 int extensionIndex = filename.reverseFind('.');
290 if (extensionIndex != -1) { 296 if (extensionIndex != -1) {
291 fileExtension = filename.substring(extensionIndex + 1); 297 fileExtension = filename.substring(extensionIndex + 1);
292 filename.truncate(extensionIndex); 298 filename.truncate(extensionIndex);
293 } 299 }
294 } 300 }
295 301
296 if (!fileExtension.isEmpty() && fileExtension != imageExtension) { 302 if (!fileExtension.isEmpty() && fileExtension != imageExtension) {
297 String imageMimeType = 303 String imageMimeType =
298 MIMETypeRegistry::getMIMETypeForExtension(imageExtension); 304 MIMETypeRegistry::getMIMETypeForExtension(imageExtension);
299 ASSERT(imageMimeType.startsWith("image/")); 305 ASSERT(imageMimeType.startsWith("image/"));
300 // Use the file extension only if it has imageMimeType: it's untrustworthy o therwise. 306 // Use the file extension only if it has imageMimeType: it's untrustworthy
307 // otherwise.
301 if (imageMimeType == 308 if (imageMimeType ==
302 MIMETypeRegistry::getMIMETypeForExtension(fileExtension)) 309 MIMETypeRegistry::getMIMETypeForExtension(fileExtension))
303 imageExtension = fileExtension; 310 imageExtension = fileExtension;
304 } 311 }
305 312
306 imageExtension = "." + imageExtension; 313 imageExtension = "." + imageExtension;
307 validateFilename(filename, imageExtension); 314 validateFilename(filename, imageExtension);
308 315
309 dataObject->addSharedBuffer(filename + imageExtension, imageBuffer); 316 dataObject->addSharedBuffer(filename + imageExtension, imageBuffer);
310 } 317 }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 if (keyword.startsWith("file:")) 422 if (keyword.startsWith("file:"))
416 return hasFileOfType(keyword.substring(5)); 423 return hasFileOfType(keyword.substring(5));
417 424
418 if (keyword.startsWith("string:")) 425 if (keyword.startsWith("string:"))
419 return hasStringOfType(keyword.substring(7)); 426 return hasStringOfType(keyword.substring(7));
420 427
421 return false; 428 return false;
422 } 429 }
423 430
424 DataTransferItemList* DataTransfer::items() { 431 DataTransferItemList* DataTransfer::items() {
425 // FIXME: According to the spec, we are supposed to return the same collection of items each 432 // FIXME: According to the spec, we are supposed to return the same collection
426 // time. We now return a wrapper that always wraps the *same* set of items, so JS shouldn't be 433 // of items each time. We now return a wrapper that always wraps the *same*
427 // able to tell, but we probably still want to fix this. 434 // set of items, so JS shouldn't be able to tell, but we probably still want
435 // to fix this.
428 return DataTransferItemList::create(this, m_dataObject); 436 return DataTransferItemList::create(this, m_dataObject);
429 } 437 }
430 438
431 DataObject* DataTransfer::dataObject() const { 439 DataObject* DataTransfer::dataObject() const {
432 return m_dataObject; 440 return m_dataObject;
433 } 441 }
434 442
435 DataTransfer::DataTransfer(DataTransferType type, 443 DataTransfer::DataTransfer(DataTransferType type,
436 DataTransferAccessPolicy policy, 444 DataTransferAccessPolicy policy,
437 DataObject* dataObject) 445 DataObject* dataObject)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 506 }
499 } 507 }
500 508
501 DEFINE_TRACE(DataTransfer) { 509 DEFINE_TRACE(DataTransfer) {
502 visitor->trace(m_dataObject); 510 visitor->trace(m_dataObject);
503 visitor->trace(m_dragImage); 511 visitor->trace(m_dragImage);
504 visitor->trace(m_dragImageElement); 512 visitor->trace(m_dragImageElement);
505 } 513 }
506 514
507 } // namespace blink 515 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/clipboard/DataTransfer.h ('k') | third_party/WebKit/Source/core/clipboard/Pasteboard.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698