| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ | |
| 6 #define CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ | |
| 7 | |
| 8 #include "base/timer.h" | |
| 9 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | |
| 10 #include "chrome/browser/bookmarks/bookmark_drop_info.h" | |
| 11 #include "chrome/browser/bookmarks/bookmark_folder_tree_model.h" | |
| 12 #include "views/controls/tree/tree_view.h" | |
| 13 | |
| 14 class BookmarkModel; | |
| 15 class BookmarkNode; | |
| 16 class OSExchangeData; | |
| 17 class Profile; | |
| 18 | |
| 19 // BookmarkFolderTreeView is used to show the contents of a | |
| 20 // BookmarkFolderTreeModel and provides drag and drop support. | |
| 21 class BookmarkFolderTreeView : public views::TreeView { | |
| 22 public: | |
| 23 BookmarkFolderTreeView(Profile* profile, BookmarkFolderTreeModel* model); | |
| 24 | |
| 25 // Drag and drop methods. | |
| 26 virtual bool CanDrop(const OSExchangeData& data); | |
| 27 virtual void OnDragEntered(const views::DropTargetEvent& event); | |
| 28 virtual int OnDragUpdated(const views::DropTargetEvent& event); | |
| 29 virtual void OnDragExited(); | |
| 30 virtual int OnPerformDrop(const views::DropTargetEvent& event); | |
| 31 | |
| 32 // Returns the selected node as a BookmarkNode. This returns NULL if the | |
| 33 // selected node is not of type BookmarkFolderTreeModel::BOOKMARK or | |
| 34 // nothing is selected. | |
| 35 const BookmarkNode* GetSelectedBookmarkNode(); | |
| 36 | |
| 37 protected: | |
| 38 // Overriden to start a drag. | |
| 39 virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); | |
| 40 | |
| 41 private: | |
| 42 // DropPosition identifies where the drop should occur. A DropPosition | |
| 43 // consists of the following: the parent FolderNode the drop is to occur at, | |
| 44 // whether the drop is on the parent, and the index into the parent the drop | |
| 45 // should occur at. | |
| 46 // | |
| 47 // WARNING: the index is in terms of the BookmarkFolderTreeModel, which is | |
| 48 // not the same as the BookmarkModel. | |
| 49 struct DropPosition { | |
| 50 DropPosition() : parent(NULL), index(-1), on(false) {} | |
| 51 DropPosition(FolderNode* parent, int index, bool on) | |
| 52 : parent(parent), | |
| 53 index(index), | |
| 54 on(on) {} | |
| 55 | |
| 56 // Returns true if |position| equals this. | |
| 57 bool equals(const DropPosition& position) const { | |
| 58 return (position.parent == parent && position.index == index && | |
| 59 position.on == on); | |
| 60 } | |
| 61 | |
| 62 FolderNode* parent; | |
| 63 int index; | |
| 64 bool on; | |
| 65 }; | |
| 66 | |
| 67 // Provides information used during a drop. | |
| 68 class DropInfo : public BookmarkDropInfo { | |
| 69 public: | |
| 70 explicit DropInfo(BookmarkFolderTreeView* view) | |
| 71 : BookmarkDropInfo(view->GetNativeControlHWND(), 0), | |
| 72 view_(view), | |
| 73 only_folders_(true) {} | |
| 74 | |
| 75 virtual void Scrolled(); | |
| 76 | |
| 77 // Does drag_data consists of folders only? | |
| 78 void set_only_folders(bool only_folders) { only_folders_ = only_folders; } | |
| 79 bool only_folders() const { return only_folders_; } | |
| 80 | |
| 81 // Position of the drop. | |
| 82 void set_position(const DropPosition& position) { position_ = position; } | |
| 83 const DropPosition& position() const { return position_; } | |
| 84 | |
| 85 private: | |
| 86 BookmarkFolderTreeView* view_; | |
| 87 DropPosition position_; | |
| 88 bool only_folders_; | |
| 89 | |
| 90 DISALLOW_COPY_AND_ASSIGN(DropInfo); | |
| 91 }; | |
| 92 friend class DropInfo; | |
| 93 | |
| 94 // Updates drop info. This is invoked both from OnDragUpdated and when we | |
| 95 // autoscroll during a drop. | |
| 96 int UpdateDropInfo(); | |
| 97 | |
| 98 // Starts a drag operation for the specified node. | |
| 99 void BeginDrag(const BookmarkNode* node); | |
| 100 | |
| 101 // Calculates the drop position. | |
| 102 DropPosition CalculateDropPosition(int y, bool only_folders); | |
| 103 | |
| 104 // Determines the appropriate drop operation. This returns DRAG_NONE | |
| 105 // if the position is not valid. | |
| 106 int CalculateDropOperation(const DropPosition& position); | |
| 107 | |
| 108 // Performs the drop operation. | |
| 109 void OnPerformDropImpl(); | |
| 110 | |
| 111 // Sets the drop position. | |
| 112 void SetDropPosition(const DropPosition& position); | |
| 113 | |
| 114 // Returns the model as a BookmarkFolderTreeModel. | |
| 115 BookmarkFolderTreeModel* folder_model() const; | |
| 116 | |
| 117 // Converts FolderNode into a BookmarkNode. | |
| 118 const BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node); | |
| 119 | |
| 120 // Converts the position in terms of the BookmarkFolderTreeModel to an index | |
| 121 // in terms of the BookmarkModel. The returned index is the index the drop | |
| 122 // should occur at in terms of the BookmarkModel. | |
| 123 int FolderIndexToBookmarkIndex(const DropPosition& position); | |
| 124 | |
| 125 Profile* profile_; | |
| 126 | |
| 127 // Non-null during a drop. | |
| 128 scoped_ptr<DropInfo> drop_info_; | |
| 129 | |
| 130 // Did we originate the drag? | |
| 131 bool is_dragging_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderTreeView); | |
| 134 }; | |
| 135 | |
| 136 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ | |
| OLD | NEW |