• 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 // This is the GTK implementation of the bookmark bubble, the dialog box
6 // presented to create or edit a bookmark.  There can only ever be a single
7 // bubble open, so the class presents only static methods, and handles the
8 // singleton behavior for you.  It also handles the object and widget
9 // lifetimes, destroying everything and possibly committing any changes when
10 // the bubble is closed.
11 
12 #ifndef CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_
13 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_
14 #pragma once
15 
16 #include <string>
17 #include <vector>
18 
19 #include "base/basictypes.h"
20 #include "base/memory/scoped_ptr.h"
21 #include "base/task.h"
22 #include "chrome/browser/ui/gtk/info_bubble_gtk.h"
23 #include "content/common/notification_observer.h"
24 #include "content/common/notification_registrar.h"
25 #include "googleurl/src/gurl.h"
26 #include "ui/base/gtk/gtk_signal.h"
27 
28 class BookmarkNode;
29 class Profile;
30 class RecentlyUsedFoldersComboModel;
31 
32 typedef struct _GtkWidget GtkWidget;
33 typedef struct _GParamSpec GParamSpec;
34 
35 class BookmarkBubbleGtk : public InfoBubbleGtkDelegate,
36                           public NotificationObserver {
37  public:
38   // Shows the bookmark bubble, pointing at |anchor_widget|.
39   static void Show(GtkWidget* anchor_widget,
40                    Profile* profile,
41                    const GURL& url,
42                    bool newly_bookmarked);
43 
44   // Implements the InfoBubbleGtkDelegate.  We are notified when the bubble
45   // is about to be closed, so we have a chance to save any state / input in
46   // our widgets before they are destroyed.
47   virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble,
48                                  bool closed_by_escape);
49 
50   // Overridden from NotificationObserver:
51   virtual void Observe(NotificationType type,
52                        const NotificationSource& source,
53                        const NotificationDetails& details);
54 
55  private:
56   BookmarkBubbleGtk(GtkWidget* anchor,
57                     Profile* profile,
58                     const GURL& url,
59                     bool newly_bookmarked);
60   ~BookmarkBubbleGtk();
61 
62   // Notified when |content_| is destroyed so we can delete our instance.
63   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnDestroy);
64   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnNameActivate);
65   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnFolderChanged);
66   CHROMEGTK_CALLBACK_1(BookmarkBubbleGtk, void, OnFolderPopupShown,
67                        GParamSpec*);
68   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnEditClicked);
69   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnCloseClicked);
70   CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnRemoveClicked);
71 
72   // Update the bookmark with any edits that have been made.
73   void ApplyEdits();
74 
75   // Open the bookmark editor for the current url and close the bubble.
76   void ShowEditor();
77 
78   // Return the UTF8 encoded title for the current |url_|.
79   std::string GetTitle();
80 
81   void InitFolderComboModel();
82 
83   // The URL of the bookmark.
84   GURL url_;
85   // Our current profile (used to access the bookmark system).
86   Profile* profile_;
87 
88   // Provides colors and stuff.
89   GtkThemeService* theme_service_;
90 
91   // The widget relative to which we are positioned.
92   GtkWidget* anchor_;
93 
94   // We let the InfoBubble own our content, and then we delete ourself
95   // when the widget is destroyed (when the InfoBubble is destroyed).
96   GtkWidget* content_;
97 
98   // The button that removes the bookmark.
99   GtkWidget* remove_button_;
100 
101   // The various labels in the interface. We keep track of them for theme
102   // changes.
103   std::vector<GtkWidget*> labels_;
104 
105   // The GtkEntry for editing the bookmark name / title.
106   GtkWidget* name_entry_;
107 
108   // The combo box for selecting the bookmark folder.
109   GtkWidget* folder_combo_;
110   scoped_ptr<RecentlyUsedFoldersComboModel> folder_combo_model_;
111 
112   InfoBubbleGtk* bubble_;
113 
114   // We need to push some things on the back of the message loop, so we have
115   // a factory attached to our instance to manage task lifetimes.
116   ScopedRunnableMethodFactory<BookmarkBubbleGtk> factory_;
117 
118   // Whether the bubble is creating or editing an existing bookmark.
119   bool newly_bookmarked_;
120   // When closing the window, whether we should update or remove the bookmark.
121   bool apply_edits_;
122   bool remove_bookmark_;
123 
124   NotificationRegistrar registrar_;
125 
126   DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleGtk);
127 };
128 
129 #endif  // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_
130