- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / bookmarks / recently_used_folders_combo_model.h
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 "chrome/browser/bookmarks/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
24     : public ui::ComboboxModel,
25       public BookmarkModelObserver {
26  public:
27   RecentlyUsedFoldersComboModel(BookmarkModel* model, const BookmarkNode* node);
28   virtual ~RecentlyUsedFoldersComboModel();
29
30   // Overridden from ui::ComboboxModel:
31   virtual int GetItemCount() const OVERRIDE;
32   virtual string16 GetItemAt(int index) OVERRIDE;
33   virtual bool IsItemSeparatorAt(int index) OVERRIDE;
34   virtual int GetDefaultIndex() const OVERRIDE;
35   virtual void AddObserver(ui::ComboboxModelObserver* observer) OVERRIDE;
36   virtual void RemoveObserver(ui::ComboboxModelObserver* observer) OVERRIDE;
37
38   // Overriden from BaseBookmarkModelObserver:
39   virtual void Loaded(BookmarkModel* model, 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) OVERRIDE;
57   virtual void BookmarkNodeChanged(BookmarkModel* model,
58                                    const BookmarkNode* node) OVERRIDE;
59   virtual void BookmarkNodeFaviconChanged(BookmarkModel* model,
60                                           const BookmarkNode* node) OVERRIDE;
61   virtual void BookmarkNodeChildrenReordered(
62       BookmarkModel* model,
63       const BookmarkNode* node) OVERRIDE;
64   virtual void BookmarkAllNodesRemoved(BookmarkModel* model) OVERRIDE;
65
66   // If necessary this function moves |node| into the corresponding folder for
67   // the given |selected_index|.
68   void MaybeChangeParent(const BookmarkNode* node, int selected_index);
69
70  private:
71   // Returns the node at the specified |index|.
72   const BookmarkNode* GetNodeAt(int index);
73
74   // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
75   void RemoveNode(const BookmarkNode* node);
76
77   struct Item;
78   std::vector<Item> items_;
79
80   BookmarkModel* bookmark_model_;
81
82   // The index of the original parent folder.
83   int node_parent_index_;
84
85   ObserverList<ui::ComboboxModelObserver> observers_;
86
87   DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel);
88 };
89
90 #endif  // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_