BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / bookmarks / recently_used_folders_combo_model.h
blobc46c548f7b9cc1b90ed4a20988deaf602e64eea7
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.
5 #ifndef CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
6 #define CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_
8 #include <vector>
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"
16 namespace bookmarks {
17 class BookmarkModel;
18 class BookmarkNode;
21 // Model for the combobox showing the list of folders to choose from. The
22 // list always contains the Bookmarks Bar, Other Bookmarks and the parent
23 // folder. The list also contains an extra item that shows the text
24 // "Choose Another Folder...".
25 class RecentlyUsedFoldersComboModel : public ui::ComboboxModel,
26 public bookmarks::BookmarkModelObserver {
27 public:
28 RecentlyUsedFoldersComboModel(bookmarks::BookmarkModel* model,
29 const bookmarks::BookmarkNode* node);
30 ~RecentlyUsedFoldersComboModel() override;
32 // Overridden from ui::ComboboxModel:
33 int GetItemCount() const override;
34 base::string16 GetItemAt(int index) override;
35 bool IsItemSeparatorAt(int index) override;
36 int GetDefaultIndex() const override;
37 void AddObserver(ui::ComboboxModelObserver* observer) override;
38 void RemoveObserver(ui::ComboboxModelObserver* observer) override;
40 // Overriden from bookmarks::BookmarkModelObserver:
41 void BookmarkModelLoaded(bookmarks::BookmarkModel* model,
42 bool ids_reassigned) override;
43 void BookmarkModelBeingDeleted(bookmarks::BookmarkModel* model) override;
44 void BookmarkNodeMoved(bookmarks::BookmarkModel* model,
45 const bookmarks::BookmarkNode* old_parent,
46 int old_index,
47 const bookmarks::BookmarkNode* new_parent,
48 int new_index) override;
49 void BookmarkNodeAdded(bookmarks::BookmarkModel* model,
50 const bookmarks::BookmarkNode* parent,
51 int index) override;
52 void OnWillRemoveBookmarks(bookmarks::BookmarkModel* model,
53 const bookmarks::BookmarkNode* parent,
54 int old_index,
55 const bookmarks::BookmarkNode* node) override;
56 void BookmarkNodeRemoved(bookmarks::BookmarkModel* model,
57 const bookmarks::BookmarkNode* parent,
58 int old_index,
59 const bookmarks::BookmarkNode* node,
60 const std::set<GURL>& removed_urls) override;
61 void BookmarkNodeChanged(bookmarks::BookmarkModel* model,
62 const bookmarks::BookmarkNode* node) override;
63 void BookmarkNodeFaviconChanged(bookmarks::BookmarkModel* model,
64 const bookmarks::BookmarkNode* node) override;
65 void BookmarkNodeChildrenReordered(
66 bookmarks::BookmarkModel* model,
67 const bookmarks::BookmarkNode* node) override;
68 void BookmarkAllUserNodesRemoved(bookmarks::BookmarkModel* model,
69 const std::set<GURL>& removed_urls) override;
71 // If necessary this function moves |node| into the corresponding folder for
72 // the given |selected_index|.
73 void MaybeChangeParent(const bookmarks::BookmarkNode* node,
74 int selected_index);
76 private:
77 // Returns the node at the specified |index|.
78 const bookmarks::BookmarkNode* GetNodeAt(int index);
80 // Removes |node| from |items_|. Does nothing if |node| is not in |items_|.
81 void RemoveNode(const bookmarks::BookmarkNode* node);
83 struct Item;
84 std::vector<Item> items_;
86 bookmarks::BookmarkModel* bookmark_model_;
88 // The index of the original parent folder.
89 int node_parent_index_;
91 base::ObserverList<ui::ComboboxModelObserver> observers_;
93 DISALLOW_COPY_AND_ASSIGN(RecentlyUsedFoldersComboModel);
96 #endif // CHROME_BROWSER_UI_BOOKMARKS_RECENTLY_USED_FOLDERS_COMBO_MODEL_H_