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

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

Issue 2469873002: [ImageResource 4] Split ImageResource into Resource and Image parts (Closed)
Patch Set: style Created 4 years 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 14 matching lines...) Expand all
25 25
26 #include "core/clipboard/DataTransfer.h" 26 #include "core/clipboard/DataTransfer.h"
27 27
28 #include "core/HTMLNames.h" 28 #include "core/HTMLNames.h"
29 #include "core/clipboard/DataObject.h" 29 #include "core/clipboard/DataObject.h"
30 #include "core/clipboard/DataTransferItem.h" 30 #include "core/clipboard/DataTransferItem.h"
31 #include "core/clipboard/DataTransferItemList.h" 31 #include "core/clipboard/DataTransferItemList.h"
32 #include "core/editing/EphemeralRange.h" 32 #include "core/editing/EphemeralRange.h"
33 #include "core/editing/FrameSelection.h" 33 #include "core/editing/FrameSelection.h"
34 #include "core/editing/serializers/Serialization.h" 34 #include "core/editing/serializers/Serialization.h"
35 #include "core/fetch/ImageResource.h" 35 #include "core/fetch/ImageResourceContent.h"
36 #include "core/fileapi/FileList.h" 36 #include "core/fileapi/FileList.h"
37 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
38 #include "core/html/HTMLImageElement.h" 38 #include "core/html/HTMLImageElement.h"
39 #include "core/html/TextControlElement.h" 39 #include "core/html/TextControlElement.h"
40 #include "core/layout/LayoutImage.h" 40 #include "core/layout/LayoutImage.h"
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/clipboard/ClipboardMimeTypes.h" 43 #include "platform/clipboard/ClipboardMimeTypes.h"
44 #include "platform/clipboard/ClipboardUtilities.h" 44 #include "platform/clipboard/ClipboardUtilities.h"
45 #include "platform/network/mime/MIMETypeRegistry.h" 45 #include "platform/network/mime/MIMETypeRegistry.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 221
222 void DataTransfer::clearDragImage() { 222 void DataTransfer::clearDragImage() {
223 if (!canSetDragImage()) 223 if (!canSetDragImage())
224 return; 224 return;
225 225
226 m_dragImage = nullptr; 226 m_dragImage = nullptr;
227 m_dragLoc = IntPoint(); 227 m_dragLoc = IntPoint();
228 m_dragImageElement = nullptr; 228 m_dragImageElement = nullptr;
229 } 229 }
230 230
231 void DataTransfer::setDragImageResource(ImageResource* img, 231 void DataTransfer::setDragImageResource(ImageResourceContent* img,
232 const IntPoint& loc) { 232 const IntPoint& loc) {
233 setDragImage(img, 0, loc); 233 setDragImage(img, 0, loc);
234 } 234 }
235 235
236 void DataTransfer::setDragImageElement(Node* node, const IntPoint& loc) { 236 void DataTransfer::setDragImageElement(Node* node, const IntPoint& loc) {
237 setDragImage(0, node, loc); 237 setDragImage(0, node, loc);
238 } 238 }
239 239
240 std::unique_ptr<DragImage> DataTransfer::createDragImage( 240 std::unique_ptr<DragImage> DataTransfer::createDragImage(
241 IntPoint& loc, 241 IntPoint& loc,
242 LocalFrame* frame) const { 242 LocalFrame* frame) const {
243 if (m_dragImageElement) { 243 if (m_dragImageElement) {
244 loc = m_dragLoc; 244 loc = m_dragLoc;
245 245
246 return frame->nodeImage(*m_dragImageElement); 246 return frame->nodeImage(*m_dragImageElement);
247 } 247 }
248 if (m_dragImage) { 248 if (m_dragImage) {
249 loc = m_dragLoc; 249 loc = m_dragLoc;
250 return DragImage::create(m_dragImage->getImage()); 250 return DragImage::create(m_dragImage->getImage());
251 } 251 }
252 return nullptr; 252 return nullptr;
253 } 253 }
254 254
255 static ImageResource* getImageResource(Element* element) { 255 static ImageResourceContent* getImageResourceContent(Element* element) {
256 // Attempt to pull ImageResource from element 256 // Attempt to pull ImageResourceContent from element
257 ASSERT(element); 257 ASSERT(element);
258 LayoutObject* layoutObject = element->layoutObject(); 258 LayoutObject* layoutObject = element->layoutObject();
259 if (!layoutObject || !layoutObject->isImage()) 259 if (!layoutObject || !layoutObject->isImage())
260 return 0; 260 return 0;
261 261
262 LayoutImage* image = toLayoutImage(layoutObject); 262 LayoutImage* image = toLayoutImage(layoutObject);
263 if (image->cachedImage() && !image->cachedImage()->errorOccurred()) 263 if (image->cachedImage() && !image->cachedImage()->errorOccurred())
264 return image->cachedImage(); 264 return image->cachedImage();
265 265
266 return 0; 266 return 0;
267 } 267 }
268 268
269 static void writeImageToDataObject(DataObject* dataObject, 269 static void writeImageToDataObject(DataObject* dataObject,
270 Element* element, 270 Element* element,
271 const KURL& url) { 271 const KURL& url) {
272 // Shove image data into a DataObject for use as a file 272 // Shove image data into a DataObject for use as a file
273 ImageResource* cachedImage = getImageResource(element); 273 ImageResourceContent* cachedImage = getImageResourceContent(element);
274 if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded()) 274 if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded())
275 return; 275 return;
276 276
277 RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data(); 277 RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data();
278 if (!imageBuffer || !imageBuffer->size()) 278 if (!imageBuffer || !imageBuffer->size())
279 return; 279 return;
280 280
281 String imageExtension = cachedImage->getImage()->filenameExtension(); 281 String imageExtension = cachedImage->getImage()->filenameExtension();
282 ASSERT(!imageExtension.isEmpty()); 282 ASSERT(!imageExtension.isEmpty());
283 283
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 DataTransfer::DataTransfer(DataTransferType type, 443 DataTransfer::DataTransfer(DataTransferType type,
444 DataTransferAccessPolicy policy, 444 DataTransferAccessPolicy policy,
445 DataObject* dataObject) 445 DataObject* dataObject)
446 : m_policy(policy), 446 : m_policy(policy),
447 m_dropEffect("uninitialized"), 447 m_dropEffect("uninitialized"),
448 m_effectAllowed("uninitialized"), 448 m_effectAllowed("uninitialized"),
449 m_transferType(type), 449 m_transferType(type),
450 m_dataObject(dataObject) {} 450 m_dataObject(dataObject) {}
451 451
452 void DataTransfer::setDragImage(ImageResource* image, 452 void DataTransfer::setDragImage(ImageResourceContent* image,
453 Node* node, 453 Node* node,
454 const IntPoint& loc) { 454 const IntPoint& loc) {
455 if (!canSetDragImage()) 455 if (!canSetDragImage())
456 return; 456 return;
457 457
458 m_dragImage = image; 458 m_dragImage = image;
459 m_dragLoc = loc; 459 m_dragLoc = loc;
460 m_dragImageElement = node; 460 m_dragImageElement = node;
461 } 461 }
462 462
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } 506 }
507 } 507 }
508 508
509 DEFINE_TRACE(DataTransfer) { 509 DEFINE_TRACE(DataTransfer) {
510 visitor->trace(m_dataObject); 510 visitor->trace(m_dataObject);
511 visitor->trace(m_dragImage); 511 visitor->trace(m_dragImage);
512 visitor->trace(m_dragImageElement); 512 visitor->trace(m_dragImageElement);
513 } 513 }
514 514
515 } // 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/css/CSSCrossfadeValue.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698