OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_ | |
6 #define APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_ | |
7 #pragma once | |
8 | |
9 #include <gtk/gtk.h> | |
10 #include <map> | |
11 #include <set> | |
12 #include <string> | |
13 | |
14 #include "app/os_exchange_data.h" | |
15 #include "base/pickle.h" | |
16 #include "base/string16.h" | |
17 #include "gfx/point.h" | |
18 #include "googleurl/src/gurl.h" | |
19 | |
20 // OSExchangeData::Provider implementation for Gtk. OSExchangeDataProviderGtk | |
21 // is created with a set of known data types. In addition specific data | |
22 // types can be set on OSExchangeDataProviderGtk by way of the various setters. | |
23 // The various has methods return true if the format was supplied to the | |
24 // constructor, or explicitly set. | |
25 class OSExchangeDataProviderGtk : public OSExchangeData::Provider { | |
26 public: | |
27 OSExchangeDataProviderGtk(int known_formats, | |
28 const std::set<GdkAtom>& known_custom_formats_); | |
29 OSExchangeDataProviderGtk(); | |
30 | |
31 virtual ~OSExchangeDataProviderGtk(); | |
32 | |
33 int known_formats() const { return known_formats_; } | |
34 const std::set<GdkAtom>& known_custom_formats() const { | |
35 return known_custom_formats_; | |
36 } | |
37 | |
38 // Returns true if all the formats and custom formats identified by |formats| | |
39 // and |custom_formats| have been set in this provider. | |
40 // | |
41 // NOTE: this is NOT the same as whether a format may be provided (as is | |
42 // returned by the various HasXXX methods), but rather if the data for the | |
43 // formats has been set on this provider by way of the various Setter | |
44 // methods. | |
45 bool HasDataForAllFormats(int formats, | |
46 const std::set<GdkAtom>& custom_formats) const; | |
47 | |
48 // Returns the set of formats available as a GtkTargetList. It is up to the | |
49 // caller to free (gtk_target_list_unref) the returned list. | |
50 GtkTargetList* GetTargetList() const; | |
51 | |
52 // Writes the data to |selection|. |format| is any combination of | |
53 // OSExchangeData::Formats. | |
54 void WriteFormatToSelection(int format, | |
55 GtkSelectionData* selection) const; | |
56 | |
57 // Provider methods. | |
58 virtual void SetString(const std::wstring& data); | |
59 virtual void SetURL(const GURL& url, const std::wstring& title); | |
60 virtual void SetFilename(const std::wstring& full_path); | |
61 virtual void SetPickledData(OSExchangeData::CustomFormat format, | |
62 const Pickle& data); | |
63 virtual bool GetString(std::wstring* data) const; | |
64 virtual bool GetURLAndTitle(GURL* url, std::wstring* title) const; | |
65 virtual bool GetFilename(std::wstring* full_path) const; | |
66 virtual bool GetPickledData(OSExchangeData::CustomFormat format, | |
67 Pickle* data) const; | |
68 virtual bool HasString() const; | |
69 virtual bool HasURL() const; | |
70 virtual bool HasFile() const; | |
71 virtual bool HasCustomFormat(OSExchangeData::CustomFormat format) const; | |
72 | |
73 // Set the image and cursor offset data for this drag. Will | |
74 // increment the ref count of pixbuf. | |
75 void SetDragImage(GdkPixbuf* pixbuf, const gfx::Point& cursor_offset); | |
76 GdkPixbuf* drag_image() const { return drag_image_; } | |
77 gfx::Point cursor_offset() const { return cursor_offset_; } | |
78 | |
79 private: | |
80 typedef std::map<OSExchangeData::CustomFormat, Pickle> PickleData; | |
81 | |
82 // Returns true if |formats_| contains a string format and the string can be | |
83 // parsed as a URL. | |
84 bool GetPlainTextURL(GURL* url) const; | |
85 | |
86 // These are the possible formats the OSExchangeData may contain. Don't | |
87 // confuse this with the actual formats that have been set, which are | |
88 // |formats_| and |custom_formats_|. | |
89 const int known_formats_; | |
90 const std::set<GdkAtom> known_custom_formats_; | |
91 | |
92 // Actual formats that have been set. See comment above |known_formats_| | |
93 // for details. | |
94 int formats_; | |
95 | |
96 // String contents. | |
97 string16 string_; | |
98 | |
99 // URL contents. | |
100 GURL url_; | |
101 string16 title_; | |
102 | |
103 // File name. | |
104 std::string filename_; | |
105 | |
106 // PICKLED_DATA contents. | |
107 PickleData pickle_data_; | |
108 | |
109 // Drag image and offset data. | |
110 GdkPixbuf* drag_image_; | |
111 gfx::Point cursor_offset_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(OSExchangeDataProviderGtk); | |
114 }; | |
115 | |
116 #endif // APP_OS_EXCHANGE_DATA_PROVIDER_GTK_H_ | |
OLD | NEW |