Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: chrome/browser/ui/gtk/bookmark_sub_menu_model_gtk.h

Issue 8775029: Makes gtk show the 'mobile' bookmark folder where appropriate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/bookmark_sub_menu_model_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_GTK_BOOKMARK_SUB_MENU_MODEL_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_BOOKMARK_SUB_MENU_MODEL_GTK_H_
7 #pragma once
8
9 #include <vector>
10
11 #include "chrome/browser/bookmarks/base_bookmark_model_observer.h"
12 #include "ui/base/models/simple_menu_model.h"
13 #include "webkit/glue/window_open_disposition.h"
14
15 class Browser;
16 class BookmarkModel;
17 class BookmarkNode;
18 class MenuGtk; // See below for why we need this.
19 class PageNavigator;
20
21 // BookmarkNodeMenuModel builds a SimpleMenuModel on demand when the menu is
22 // shown, and automatically destroys child models when the menu is closed.
23 class BookmarkNodeMenuModel : public ui::SimpleMenuModel {
24 public:
25 BookmarkNodeMenuModel(ui::SimpleMenuModel::Delegate* delegate,
26 BookmarkModel* model,
27 const BookmarkNode* node,
28 PageNavigator* page_navigator);
29 virtual ~BookmarkNodeMenuModel();
30
31 // From SimpleMenuModel. Takes care of deleting submenus.
32 // Note that this is not virtual. That's OK for our use.
33 void Clear();
34
35 // From MenuModel via SimpleMenuModel.
36 virtual void MenuWillShow() OVERRIDE;
37 virtual void MenuClosed() OVERRIDE;
38 virtual void ActivatedAt(int index) OVERRIDE;
39 virtual void ActivatedAt(int index, int event_flags) OVERRIDE;
40
41 protected:
42 // Adds all bookmark items to the model. Does not clear the model first.
43 void PopulateMenu();
44
45 // Add a submenu for the given bookmark folder node.
46 void AddSubMenuForNode(const BookmarkNode* node);
47
48 BookmarkModel* model() const { return model_; }
49 void set_model(BookmarkModel* model) { model_ = model; }
50
51 const BookmarkNode* node() const { return node_; }
52 void set_node(const BookmarkNode* node) { node_ = node; }
53
54 private:
55 // Uses the page navigator to open the bookmark at the given index.
56 void NavigateToMenuItem(int index, WindowOpenDisposition disposition);
57
58 // The bookmark model whose bookmarks we will show. Note that in the top-level
59 // bookmark menu, this may be null. (It is set only when the menu is shown.)
60 BookmarkModel* model_;
61
62 // The bookmark node for the folder that this model will show. Note that in
63 // the top-level bookmark menu, this may be null, as above.
64 const BookmarkNode* node_;
65
66 // The page navigator used to open bookmarks in ActivatedAt().
67 PageNavigator* page_navigator_;
68
69 // A list of the submenus we own and will need to delete.
70 std::vector<BookmarkNodeMenuModel*> submenus_;
71
72 DISALLOW_COPY_AND_ASSIGN(BookmarkNodeMenuModel);
73 };
74
75 // This is the top-level bookmark menu model. It handles prepending a few fixed
76 // items before the bookmarks. Child menus are all plain BookmarkNodeMenuModels.
77 // This class also handles watching the bookmark model and forcing the menu to
78 // close if it changes while the menu is open.
79 class BookmarkSubMenuModel : public BookmarkNodeMenuModel,
80 public BaseBookmarkModelObserver {
81 public:
82 BookmarkSubMenuModel(ui::SimpleMenuModel::Delegate* delegate,
83 Browser* browser);
84
85 virtual ~BookmarkSubMenuModel();
86
87 // See below; this is used to allow closing the menu when bookmarks change.
88 void SetMenuGtk(MenuGtk* menu) { menu_ = menu; }
89
90 // From BaseBookmarkModelObserver.
91 virtual void BookmarkModelChanged() OVERRIDE;
92 virtual void BookmarkModelBeingDeleted(BookmarkModel* model) OVERRIDE;
93
94 // From MenuModel via BookmarkNodeMenuModel, SimpleMenuModel.
95 virtual void MenuWillShow() OVERRIDE;
96 virtual void ActivatedAt(int index) OVERRIDE;
97 virtual void ActivatedAt(int index, int event_flags) OVERRIDE;
98 virtual bool IsEnabledAt(int index) const OVERRIDE;
99 virtual bool IsVisibleAt(int index) const OVERRIDE;
100
101 // Returns true if the command id is for a bookmark item.
102 static bool IsBookmarkItemCommandId(int command_id);
103
104 private:
105 Browser* browser_;
106
107 // The number of fixed items shown before the bookmarks.
108 int fixed_items_;
109 // The index of the first non-bookmark item after the bookmarks.
110 int bookmark_end_;
111
112 // We need to be able to call Cancel() on the menu when bookmarks change. This
113 // is a bit of an abstraction violation but it could be converted to an
114 // interface with just a Cancel() method if necessary.
115 MenuGtk* menu_;
116
117 DISALLOW_COPY_AND_ASSIGN(BookmarkSubMenuModel);
118 };
119
120 #endif // CHROME_BROWSER_UI_GTK_BOOKMARK_SUB_MENU_MODEL_GTK_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/bookmark_sub_menu_model_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698