diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-29 23:38:06 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-29 23:38:06 +0000 |
commit | 7f856bee73ffdccdbbbbbab4cb79185290d38359 (patch) | |
tree | a837328e08a113abdc70b2fc0ae2f2a4a3f804eb /chrome/browser/views/bookmark_folder_tree_view.h | |
parent | 281fe14063dd8fb81cea102f5abb7b82f407c3d1 (diff) | |
download | chromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.zip chromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.tar.gz chromium_src-7f856bee73ffdccdbbbbbab4cb79185290d38359.tar.bz2 |
First cut at the bookmark manager. There are still a fair number of
rough edges, but I'm at a good point where I want to land what I
have. Here's what is left:
. Flicker on show, likely the result of restoring window placement.
. tree flickers when dragging splitter.
. table/tree need to autoscroll when drop cursor held at bottom of view.
. prompts for deleting.
. When you move an item the table snaps to the top, this is because
I'm sending out model changed. need a better notification.
. Operations in menu to add need to change selection.
. Remember split location.
I would have preferred to split this up into a couple of reviews, but
everything is intertwined now. Sorry.
BUG=674
TEST=don't test the bookmark manager yet, but make sure bookmark bar
still works.
Review URL: http://codereview.chromium.org/8197
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4191 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/bookmark_folder_tree_view.h')
-rw-r--r-- | chrome/browser/views/bookmark_folder_tree_view.h | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/chrome/browser/views/bookmark_folder_tree_view.h b/chrome/browser/views/bookmark_folder_tree_view.h new file mode 100644 index 0000000..ae12b2c --- /dev/null +++ b/chrome/browser/views/bookmark_folder_tree_view.h @@ -0,0 +1,117 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ +#define CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ + +#include "chrome/browser/bookmarks/bookmark_drag_data.h" +#include "chrome/browser/bookmarks/bookmark_folder_tree_model.h" +#include "chrome/views/tree_view.h" + +class BookmarkModel; +class BookmarkNode; +class OSExchangeData; +class Profile; + +// BookmarkFolderTreeView is used to show the contents of a +// BookmarkFolderTreeModel and provides drag and drop support. +class BookmarkFolderTreeView : public views::TreeView { + public: + BookmarkFolderTreeView(Profile* profile, BookmarkFolderTreeModel* model); + + // Drag and drop methods. + virtual bool CanDrop(const OSExchangeData& data); + virtual void OnDragEntered(const views::DropTargetEvent& event); + virtual int OnDragUpdated(const views::DropTargetEvent& event); + virtual void OnDragExited(); + virtual int OnPerformDrop(const views::DropTargetEvent& event); + + // Returns the selected node as a BookmarkNode. This returns NULL if the + // selected node is not of type BookmarkFolderTreeModel::BOOKMARK or + // nothing is selected. + BookmarkNode* GetSelectedBookmarkNode(); + + protected: + // Overriden to start a drag. + virtual LRESULT OnNotify(int w_param, LPNMHDR l_param); + + private: + // Provides information used during a drop. + struct DropInfo { + DropInfo() + : drop_parent(NULL), + only_folders(true), + drop_index(-1), + drop_operation(0), + drop_on(false) {} + + // Parent the mouse is over. + FolderNode* drop_parent; + + // Drag data. + BookmarkDragData drag_data; + + // Does drag_data consists of folders only. + bool only_folders; + + // If drop_on is false, this is the index to add the child. + // WARNING: this index is in terms of the BookmarkFolderTreeModel, which is + // not the same as the BookmarkModel. + int drop_index; + + // Operation for the drop. + int drop_operation; + + // Is the user dropping on drop_parent? If false, the mouse is positioned + // such that the drop should insert the data at position drop_index in + // drop_parent. + bool drop_on; + }; + + // Starts a drag operation for the specified node. + void BeginDrag(BookmarkNode* node); + + // Calculates the drop parent. Returns NULL if not over a valid drop + // location. See DropInfos documentation for a description of |drop_index| + // and |drop_on|. + FolderNode* CalculateDropParent(int y, + bool only_folders, + int* drop_index, + bool* drop_on); + + // Determines the appropriate drop operation. This returns DRAG_NONE + // if the location is not valid. + int CalculateDropOperation(const views::DropTargetEvent& event, + FolderNode* drop_parent, + int drop_index, + bool drop_on); + + // Performs the drop operation. + void OnPerformDropImpl(); + + // Sets the parent of the drop operation. + void SetDropParent(FolderNode* node, int drop_index, bool drop_on); + + // Returns the model as a BookmarkFolderTreeModel. + BookmarkFolderTreeModel* folder_model() const; + + // Converts FolderNode into a BookmarkNode. + BookmarkNode* TreeNodeAsBookmarkNode(FolderNode* node); + + // Converts an index in terms of the BookmarkFolderTreeModel to an index + // in terms of the BookmarkModel. + int FolderIndexToBookmarkIndex(FolderNode* node, int index, bool drop_on); + + Profile* profile_; + + // Non-null during a drop. + scoped_ptr<DropInfo> drop_info_; + + // Did we originate the drag? + bool is_dragging_; + + DISALLOW_COPY_AND_ASSIGN(BookmarkFolderTreeView); +}; + +#endif // CHROME_BROWSER_VIEWS_BOOKMARK_FOLDER_TREE_VIEW_H_ |