Home | History | Annotate | Download | only in bookmarks
      1 // Copyright (c) 2012 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_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
      6 #define CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
      7 
      8 #include <vector>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/compiler_specific.h"
     12 #include "base/observer_list.h"
     13 #include "components/bookmarks/browser/bookmark_model_observer.h"
     14 #include "ui/base/models/combobox_model.h"
     15 
     16 class BookmarkModel;
     17 class BookmarkNode;
     18 
     19 // Model for the combobox showing the list of folders to choose from. The
     20 // list always contains the Bookmarks Bar, Other Bookmarks and the parent
     21 // folder. The list also contains an extra item that shows the text
     22 // "Choose Another Folder...".
     23 class RecentlyUsedFoldersComboModel : public ui::ComboboxModel,
     24                                       public BookmarkModelObserver {
     25  public:
     26   RecentlyUsedFoldersComboModel(BookmarkModel* model, const BookmarkNode* node);
     27   virtual ~RecentlyUsedFoldersComboModel();
     28 
     29   // Overridden from ui::ComboboxModel:
     30   virtual int GetItemCount() const OVERRIDE;
     31   virtual base::string16 GetItemAt(int index) OVERRIDE;
     32   virtual bool IsItemSeparatorAt(int index) OVERRIDE;
     33   virtual int GetDefaultIndex() const OVERRIDE;
     34   virtual void AddObserver(ui::ComboboxModelObserver* observer) OVERRIDE;
     35   virtual void RemoveObserver(ui::ComboboxModelObserver* observer) OVERRIDE;
     36 
     37   // Overriden from BookmarkModelObserver:
     38   virtual void BookmarkModelLoaded(BookmarkModel* model,
     39                                    bool ids_reassigned) OVERRIDE;
     40   virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
     41   virtual void BookmarkNodeMoved(BookmarkModel* model,
     42                                  const BookmarkNode* old_parent,
     43                                  int old_index,
     44                                  const BookmarkNode* new_parent,
     45                                  int new_index) OVERRIDE;
     46   virtual void BookmarkNodeAdded(BookmarkModel* model,
     47                                  const BookmarkNode* parent,
     48                                  int index) OVERRIDE;
     49   virtual void OnWillRemoveBookmarks(BookmarkModel* model,
     50                                      const BookmarkNode* parent,
     51                                      int old_index,
     52                                      const BookmarkNode* node) OVERRIDE;
     53   virtual void BookmarkNodeRemoved(BookmarkModel* model,
     54                                    const BookmarkNode* parent,
     55                                    int old_index,
     56                                    const BookmarkNode* node,
     57                                    const std::set<GURL>& removed_urls) OVERRIDE;
     58   virtual void BookmarkNodeChanged(BookmarkModel* model,
     59                                    const BookmarkNode* node) OVERRIDE;
     60   virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
     61                                           const BookmarkNode* node) OVERRIDE;
     62   virtual void BookmarkNodeChildrenReordered(
     63       BookmarkModel* model,
     64       const BookmarkNode* node) OVERRIDE;
     65   virtual void BookmarkAllUserNodesRemoved(
     66       BookmarkModel* model,
     67       const std::set<GURL>& removed_urls) OVERRIDE;
     68 
     69   // If necessary this function moves |node| into the corresponding folder for
     70   // the given |selected_index|.
     71   void MaybeChangeParent(const BookmarkNode* node, int selected_index);
     72 
     73  private:
     74   // Returns the node at the specified |index|.
     75   const BookmarkNode* GetNodeAt(int index);
     76 
     77   // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
     78   void RemoveNode(const BookmarkNode* node);
     79 
     80   struct Item;
     81   std::vector<Item> items_;
     82 
     83   BookmarkModel* bookmark_model_;
     84 
     85   // The index of the original parent folder.
     86   int node_parent_index_;
     87 
     88   ObserverList<ui::ComboboxModelObserver> observers_;
     89 
     90   DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel);
     91 };
     92 
     93 #endif  // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
     94