| 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 CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_ | |
| 6 #define CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_ | |
| 7 | |
| 8 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | |
| 9 #include "chrome/browser/bookmarks/bookmark_drop_info.h" | |
| 10 #include "views/controls/table/table_view.h" | |
| 11 | |
| 12 class BookmarkModel; | |
| 13 class BookmarkNode; | |
| 14 class BookmarkTableModel; | |
| 15 class OSExchangeData; | |
| 16 class PrefService; | |
| 17 class Profile; | |
| 18 | |
| 19 // A TableView implementation that shows a BookmarkTableModel. | |
| 20 // BookmarkTableView provides drag and drop support as well as showing a | |
| 21 // separate set of columns when showing search results. | |
| 22 class BookmarkTableView : public views::TableView { | |
| 23 public: | |
| 24 BookmarkTableView(Profile* profile, BookmarkTableModel* model); | |
| 25 | |
| 26 // Drag and drop methods. | |
| 27 virtual bool CanDrop(const OSExchangeData& data); | |
| 28 virtual void OnDragEntered(const views::DropTargetEvent& event); | |
| 29 virtual int OnDragUpdated(const views::DropTargetEvent& event); | |
| 30 virtual void OnDragExited(); | |
| 31 virtual int OnPerformDrop(const views::DropTargetEvent& event); | |
| 32 | |
| 33 // Sets the parent of the nodes being displayed. For search and recently | |
| 34 // found results |parent| is NULL. | |
| 35 void set_parent_node(const BookmarkNode* parent) { parent_node_ = parent; } | |
| 36 | |
| 37 // Sets whether the path column should be shown. The path column is shown | |
| 38 // for search results and recently bookmarked. | |
| 39 void SetShowPathColumn(bool show_path_column); | |
| 40 | |
| 41 // The model as a BookmarkTableModel. | |
| 42 BookmarkTableModel* bookmark_table_model() const; | |
| 43 | |
| 44 // Saves the widths of the table columns. | |
| 45 void SaveColumnConfiguration(); | |
| 46 | |
| 47 protected: | |
| 48 // Overriden to draw a drop indicator when dropping between rows. | |
| 49 virtual void PostPaint(); | |
| 50 | |
| 51 // Overriden to start a drag. | |
| 52 virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); | |
| 53 | |
| 54 private: | |
| 55 // DropPosition identifies where the drop should occur. | |
| 56 struct DropPosition { | |
| 57 DropPosition() : index(-1), on(false) {} | |
| 58 DropPosition(int index, bool on) : index(index), on(on) {} | |
| 59 | |
| 60 bool equals(const DropPosition& position) const { | |
| 61 return index == position.index && on == position.on; | |
| 62 } | |
| 63 | |
| 64 // The index into the table model as to where the drop should occur. This | |
| 65 // may == the row count of the table. | |
| 66 int index; | |
| 67 | |
| 68 // Whether drop is on the item at the specified index. If false, the drop | |
| 69 // is at the specified index. | |
| 70 bool on; | |
| 71 }; | |
| 72 | |
| 73 // Information used when we're the drop target of a drag and drop operation. | |
| 74 class DropInfo : public BookmarkDropInfo { | |
| 75 public: | |
| 76 explicit DropInfo(BookmarkTableView* view) | |
| 77 : BookmarkDropInfo(view->GetNativeControlHWND(), | |
| 78 view->content_offset()), | |
| 79 view_(view) {} | |
| 80 | |
| 81 // Overriden to invoke UpdateDropInfo. | |
| 82 virtual void Scrolled(); | |
| 83 | |
| 84 // The position the drop is to occur at. | |
| 85 void set_position(const DropPosition& position) { | |
| 86 position_ = position; | |
| 87 } | |
| 88 const DropPosition& position() { return position_; } | |
| 89 | |
| 90 private: | |
| 91 DropPosition position_; | |
| 92 BookmarkTableView* view_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(DropInfo); | |
| 95 }; | |
| 96 friend class DropInfo; | |
| 97 | |
| 98 // Updates drop info. This is invoked both from OnDragUpdated and when we | |
| 99 // autoscroll during a drop. | |
| 100 int UpdateDropInfo(); | |
| 101 | |
| 102 // Starts a drop operation. | |
| 103 void BeginDrag(); | |
| 104 | |
| 105 // Returns the drop operation for the specified position. | |
| 106 int CalculateDropOperation(const DropPosition& position); | |
| 107 | |
| 108 // Performs the drop operation. | |
| 109 void OnPerformDropImpl(); | |
| 110 | |
| 111 // Sets the position of the drop. If this differs from the current position | |
| 112 // UpdateDropIndicator is invoked for old and new values. | |
| 113 void SetDropPosition(const DropPosition& position); | |
| 114 | |
| 115 // Invoked from SetDropPosition to update the visual indicator. |turn_on| | |
| 116 // indicates whether the indicator is to be turned on or off. | |
| 117 void UpdateDropIndicator(const DropPosition& position, bool turn_on); | |
| 118 | |
| 119 // Determines the drop position for the specified location. | |
| 120 DropPosition CalculateDropPosition(int y); | |
| 121 | |
| 122 // Returns the BookmarkNode the drop should occur on. | |
| 123 const BookmarkNode* GetDropParentAndIndex(const DropPosition& position, | |
| 124 int* index); | |
| 125 | |
| 126 // Returns the bounds of drop indicator shown when the drop is to occur | |
| 127 // between rows (drop_on is false). | |
| 128 RECT GetDropBetweenHighlightRect(int index); | |
| 129 | |
| 130 // Resets the columns. BookmarkTableView shows different sets of columns. | |
| 131 // See ShowPathColumn for details. | |
| 132 void UpdateColumns(); | |
| 133 | |
| 134 Profile* profile_; | |
| 135 | |
| 136 const BookmarkNode* parent_node_; | |
| 137 | |
| 138 scoped_ptr<DropInfo> drop_info_; | |
| 139 | |
| 140 bool show_path_column_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(BookmarkTableView); | |
| 143 }; | |
| 144 | |
| 145 #endif // CHROME_BROWSER_VIEWS_BOOKMARK_TABLE_VIEW_H_ | |
| OLD | NEW |