• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_
7 #pragma once
8 
9 #include "base/gtest_prod_util.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "base/string16.h"
12 #include "chrome/browser/bookmarks/bookmark_editor.h"
13 #include "chrome/browser/bookmarks/bookmark_model_observer.h"
14 #include "ui/base/gtk/gtk_integers.h"
15 #include "ui/base/gtk/gtk_signal.h"
16 
17 class GURL;
18 
19 typedef union  _GdkEvent GdkEvent;
20 typedef struct _GdkEventButton GdkEventButton;
21 typedef struct _GtkTreeIter GtkTreeIter;
22 typedef struct _GtkTreeSelection GtkTreeSelection;
23 typedef struct _GtkTreeStore GtkTreeStore;
24 typedef struct _GtkWidget GtkWidget;
25 
26 namespace gfx {
27 class Point;
28 }  // namespace gfx
29 
30 // GTK version of the bookmark editor dialog.
31 class BookmarkEditorGtk : public BookmarkEditor,
32                           public BookmarkModelObserver {
33  public:
34   BookmarkEditorGtk(GtkWindow* window,
35                     Profile* profile,
36                     const BookmarkNode* parent,
37                     const EditDetails& details,
38                     BookmarkEditor::Configuration configuration);
39 
40   virtual ~BookmarkEditorGtk();
41 
42   void Show();
43   void Close();
44 
45  private:
46   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParent);
47   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeParentAndURL);
48   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLToExistingURL);
49   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditTitleKeepsPosition);
50   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, EditURLKeepsPosition);
51   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ModelsMatch);
52   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, MoveToNewParent);
53   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, NewURL);
54   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeURLNoTree);
55   FRIEND_TEST_ALL_PREFIXES(BookmarkEditorGtkTest, ChangeTitleNoTree);
56 
57   class ContextMenuController;
58   friend class ContextMenuController;
59 
60   void Init(GtkWindow* parent_window);
61 
62   // BookmarkModel observer methods. Any structural change results in
63   // resetting the tree model.
Loaded(BookmarkModel * model)64   virtual void Loaded(BookmarkModel* model) { }
65   virtual void BookmarkNodeMoved(BookmarkModel* model,
66                                  const BookmarkNode* old_parent,
67                                  int old_index,
68                                  const BookmarkNode* new_parent,
69                                  int new_index);
70   virtual void BookmarkNodeAdded(BookmarkModel* model,
71                                  const BookmarkNode* parent,
72                                  int index);
73   virtual void BookmarkNodeRemoved(BookmarkModel* model,
74                                    const BookmarkNode* parent,
75                                    int old_index,
76                                    const BookmarkNode* node);
BookmarkNodeChanged(BookmarkModel * model,const BookmarkNode * node)77   virtual void BookmarkNodeChanged(BookmarkModel* model,
78                                    const BookmarkNode* node) {}
79   virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
80                                              const BookmarkNode* node);
BookmarkNodeFaviconLoaded(BookmarkModel * model,const BookmarkNode * node)81   virtual void BookmarkNodeFaviconLoaded(BookmarkModel* model,
82                                          const BookmarkNode* node) {}
83 
84   // Resets the model of the tree and updates the various buttons appropriately.
85   void Reset();
86 
87   // Returns the current url the user has input.
88   GURL GetInputURL() const;
89 
90   // Returns the title the user has input.
91   string16 GetInputTitle() const;
92 
93   // Invokes ApplyEdits with the selected node.
94   //
95   // TODO(erg): This was copied from the windows version. Both should be
96   // cleaned up so that we don't overload ApplyEdits.
97   void ApplyEdits();
98 
99   // Applies the edits done by the user. |selected_parent| gives the parent of
100   // the URL being edited.
101   void ApplyEdits(GtkTreeIter* selected_parent);
102 
103   // Adds a new folder parented on |parent| and sets |child| to point to this
104   // new folder.
105   void AddNewFolder(GtkTreeIter* parent, GtkTreeIter* child);
106 
107   CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnSelectionChanged);
108   CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, void, OnResponse, int);
109   CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnWindowDeleteEvent,
110                        GdkEvent*);
111 
112   CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnWindowDestroy);
113   CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnEntryChanged);
114 
115   CHROMEGTK_CALLBACK_0(BookmarkEditorGtk, void, OnNewFolderClicked);
116 
117   CHROMEGTK_CALLBACK_1(BookmarkEditorGtk, gboolean, OnTreeViewButtonPressEvent,
118                        GdkEventButton*);
119 
120   void NewFolder();
121 
122   // Profile the entry is from.
123   Profile* profile_;
124 
125   // The dialog to display on screen.
126   GtkWidget* dialog_;
127   GtkWidget* name_entry_;
128   GtkWidget* url_entry_;  // This is NULL if IsEditingFolder.
129   GtkWidget* tree_view_;
130   GtkWidget* new_folder_button_;
131 
132   // Helper object that manages the currently selected item in |tree_view_|.
133   GtkTreeSelection* tree_selection_;
134 
135   // Our local copy of the bookmark data that we make from the BookmarkModel
136   // that we can modify as much as we want and still discard when the user
137   // clicks Cancel.
138   GtkTreeStore* tree_store_;
139 
140   // TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert
141   // that into a GObject that implements the interface GtkTreeModel.
142 
143   // Initial parent to select. Is only used if node_ is NULL.
144   const BookmarkNode* parent_;
145 
146   // Details about the node we're editing.
147   const EditDetails details_;
148 
149   // Mode used to create nodes from.
150   BookmarkModel* bb_model_;
151 
152   // If true, we're running the menu for the bookmark bar or other bookmarks
153   // nodes.
154   bool running_menu_for_root_;
155 
156   // Is the tree shown?
157   bool show_tree_;
158 
159   // The context menu controller.
160   scoped_ptr<ContextMenuController> menu_controller_;
161 
162   DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk);
163 };
164 
165 #endif  // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_EDITOR_GTK_H_
166