OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ | 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ |
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ | 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "chrome/browser/history/history.h" | 10 #include "chrome/browser/history/history.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 | 12 |
13 class BookmarkBarModel; | 13 class BookmarkModel; |
14 class BookmarkBarNode; | 14 class BookmarkNode; |
15 class OSExchangeData; | 15 class OSExchangeData; |
16 class Pickle; | 16 class Pickle; |
17 | 17 |
18 // BookmarkDragData is used by the bookmark bar to represent a dragged | 18 // BookmarkDragData is used by the bookmark bar to represent a dragged |
19 // URL or starred group on the clipboard during drag and drop. | 19 // URL or starred group on the clipboard during drag and drop. |
20 // | 20 // |
21 // Typical usage when writing data for a drag is: | 21 // Typical usage when writing data for a drag is: |
22 // BookmarkDragData data(node_user_is_dragging); | 22 // BookmarkDragData data(node_user_is_dragging); |
23 // data.profile_id = profile_id; | 23 // data.profile_id = profile_id; |
24 // data.Write(os_exchange_data_for_drag); | 24 // data.Write(os_exchange_data_for_drag); |
25 // | 25 // |
26 // Typical usage to read is: | 26 // Typical usage to read is: |
27 // BookmarkDragData data; | 27 // BookmarkDragData data; |
28 // if (data.Read(os_exchange_data)) | 28 // if (data.Read(os_exchange_data)) |
29 // // data is valid | 29 // // data is valid |
30 | 30 |
31 struct BookmarkDragData { | 31 struct BookmarkDragData { |
32 BookmarkDragData(); | 32 BookmarkDragData(); |
33 | 33 |
34 // Created a BookmarkDragData populated from node. | 34 // Created a BookmarkDragData populated from node. |
35 explicit BookmarkDragData(BookmarkBarNode* node); | 35 explicit BookmarkDragData(BookmarkNode* node); |
36 | 36 |
37 // Writes this BookmarkDragData to data. If BookmarkDragData is a URL, | 37 // Writes this BookmarkDragData to data. If BookmarkDragData is a URL, |
38 // this writes out the URL and URL title clipboard data as well. | 38 // this writes out the URL and URL title clipboard data as well. |
39 void Write(OSExchangeData* data) const; | 39 void Write(OSExchangeData* data) const; |
40 | 40 |
41 // Restores this data from the clipboard, returning true on success. | 41 // Restores this data from the clipboard, returning true on success. |
42 bool Read(const OSExchangeData& data); | 42 bool Read(const OSExchangeData& data); |
43 | 43 |
44 // Returns the node represented by this drag data from root. If the | 44 // Returns the node represented by this drag data from root. If the |
45 // path can not be found, NULL is returned. | 45 // path can not be found, NULL is returned. |
46 // | 46 // |
47 // This is only valid for groups. | 47 // This is only valid for groups. |
48 BookmarkBarNode* BookmarkDragData::GetNode(BookmarkBarModel* model) const; | 48 BookmarkNode* BookmarkDragData::GetNode(BookmarkModel* model) const; |
49 | 49 |
50 // If true, this entry represents a StarredEntry of type URL. | 50 // If true, this entry represents a StarredEntry of type URL. |
51 bool is_url; | 51 bool is_url; |
52 | 52 |
53 // ID of the profile we originated from. | 53 // ID of the profile we originated from. |
54 std::wstring profile_id; | 54 std::wstring profile_id; |
55 | 55 |
56 // The URL, only valid if is_url is true. | 56 // The URL, only valid if is_url is true. |
57 GURL url; | 57 GURL url; |
58 | 58 |
59 // Title of the entry | 59 // Title of the entry |
60 std::wstring title; | 60 std::wstring title; |
61 | 61 |
62 // Children, only used for non-URL nodes. | 62 // Children, only used for non-URL nodes. |
63 std::vector<BookmarkDragData> children; | 63 std::vector<BookmarkDragData> children; |
64 | 64 |
65 // If true our data is valid. | 65 // If true our data is valid. |
66 bool is_valid; | 66 bool is_valid; |
67 | 67 |
68 private: | 68 private: |
69 // Writes the data to a Pickle. | 69 // Writes the data to a Pickle. |
70 void WriteToPickle(Pickle* pickle) const; | 70 void WriteToPickle(Pickle* pickle) const; |
71 | 71 |
72 bool ReadFromPickle(Pickle* pickle, void** iterator); | 72 bool ReadFromPickle(Pickle* pickle, void** iterator); |
73 | 73 |
74 // Adds to children an entry for each child of node. | 74 // Adds to children an entry for each child of node. |
75 void AddChildren(BookmarkBarNode* node); | 75 void AddChildren(BookmarkNode* node); |
76 | 76 |
77 // ID (node->id()) of the node this BookmarkDragData was created from. | 77 // ID (node->id()) of the node this BookmarkDragData was created from. |
78 int id_; | 78 int id_; |
79 }; | 79 }; |
80 | 80 |
81 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ | 81 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_DRAG_DATA_ |
OLD | NEW |