OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/dragdrop/drag_utils.h" | 5 #include "ui/base/dragdrop/drag_utils.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 // Maximum width of the link drag image in pixels. | 23 // Maximum width of the link drag image in pixels. |
24 static const int kLinkDragImageVPadding = 3; | 24 static const int kLinkDragImageVPadding = 3; |
25 | 25 |
26 // File dragging pixel measurements | 26 // File dragging pixel measurements |
27 static const int kFileDragImageMaxWidth = 200; | 27 static const int kFileDragImageMaxWidth = 200; |
28 static const SkColor kFileDragImageTextColor = SK_ColorBLACK; | 28 static const SkColor kFileDragImageTextColor = SK_ColorBLACK; |
29 | 29 |
30 class FileDragImageSource : public gfx::CanvasImageSource { | 30 class FileDragImageSource : public gfx::CanvasImageSource { |
31 public: | 31 public: |
32 FileDragImageSource(const FilePath& file_name, const gfx::ImageSkia& icon) | 32 FileDragImageSource(const base::FilePath& file_name, |
| 33 const gfx::ImageSkia& icon) |
33 : CanvasImageSource(CalculateSize(icon), false), | 34 : CanvasImageSource(CalculateSize(icon), false), |
34 file_name_(file_name), | 35 file_name_(file_name), |
35 icon_(icon) { | 36 icon_(icon) { |
36 } | 37 } |
37 | 38 |
38 virtual ~FileDragImageSource() { | 39 virtual ~FileDragImageSource() { |
39 } | 40 } |
40 | 41 |
41 // Overridden from gfx::CanvasImageSource. | 42 // Overridden from gfx::CanvasImageSource. |
42 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { | 43 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { |
(...skipping 25 matching lines...) Expand all Loading... |
68 gfx::Size CalculateSize(const gfx::ImageSkia& icon) const { | 69 gfx::Size CalculateSize(const gfx::ImageSkia& icon) const { |
69 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 70 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
70 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); | 71 gfx::Font font = rb.GetFont(ResourceBundle::BaseFont); |
71 const int width = kFileDragImageMaxWidth; | 72 const int width = kFileDragImageMaxWidth; |
72 // Add +2 here to allow room for the halo. | 73 // Add +2 here to allow room for the halo. |
73 const int height = font.GetHeight() + icon.height() + | 74 const int height = font.GetHeight() + icon.height() + |
74 kLinkDragImageVPadding + 2; | 75 kLinkDragImageVPadding + 2; |
75 return gfx::Size(width, height); | 76 return gfx::Size(width, height); |
76 } | 77 } |
77 | 78 |
78 const FilePath file_name_; | 79 const base::FilePath file_name_; |
79 const gfx::ImageSkia icon_; | 80 const gfx::ImageSkia icon_; |
80 | 81 |
81 DISALLOW_COPY_AND_ASSIGN(FileDragImageSource); | 82 DISALLOW_COPY_AND_ASSIGN(FileDragImageSource); |
82 }; | 83 }; |
83 | 84 |
84 } // namespace | 85 } // namespace |
85 | 86 |
86 void CreateDragImageForFile(const FilePath& file_name, | 87 void CreateDragImageForFile(const base::FilePath& file_name, |
87 const gfx::ImageSkia* icon, | 88 const gfx::ImageSkia* icon, |
88 ui::OSExchangeData* data_object) { | 89 ui::OSExchangeData* data_object) { |
89 DCHECK(icon); | 90 DCHECK(icon); |
90 DCHECK(data_object); | 91 DCHECK(data_object); |
91 gfx::CanvasImageSource* source = new FileDragImageSource(file_name, *icon); | 92 gfx::CanvasImageSource* source = new FileDragImageSource(file_name, *icon); |
92 gfx::Size size = source->size(); | 93 gfx::Size size = source->size(); |
93 // ImageSkia takes ownership of |source|. | 94 // ImageSkia takes ownership of |source|. |
94 gfx::ImageSkia image = gfx::ImageSkia(source, size); | 95 gfx::ImageSkia image = gfx::ImageSkia(source, size); |
95 | 96 |
96 gfx::Vector2d cursor_offset(size.width() / 2, kLinkDragImageVPadding); | 97 gfx::Vector2d cursor_offset(size.width() / 2, kLinkDragImageVPadding); |
97 SetDragImageOnDataObject(image, size, cursor_offset, data_object); | 98 SetDragImageOnDataObject(image, size, cursor_offset, data_object); |
98 } | 99 } |
99 | 100 |
100 void SetDragImageOnDataObject(const gfx::Canvas& canvas, | 101 void SetDragImageOnDataObject(const gfx::Canvas& canvas, |
101 const gfx::Size& size, | 102 const gfx::Size& size, |
102 const gfx::Vector2d& cursor_offset, | 103 const gfx::Vector2d& cursor_offset, |
103 ui::OSExchangeData* data_object) { | 104 ui::OSExchangeData* data_object) { |
104 gfx::ImageSkia image = gfx::ImageSkia(canvas.ExtractImageRep()); | 105 gfx::ImageSkia image = gfx::ImageSkia(canvas.ExtractImageRep()); |
105 SetDragImageOnDataObject(image, size, cursor_offset, data_object); | 106 SetDragImageOnDataObject(image, size, cursor_offset, data_object); |
106 } | 107 } |
107 | 108 |
108 } // namespace drag_utils | 109 } // namespace drag_utils |
OLD | NEW |