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 // 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.
12 #ifndef CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_
13 #define CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_
18 #include "base/basictypes.h"
19 #include "base/compiler_specific.h"
20 #include "base/gtest_prod_util.h"
21 #include "base/memory/scoped_ptr.h"
22 #include "base/memory/weak_ptr.h"
23 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
24 #include "content/public/browser/notification_observer.h"
25 #include "content/public/browser/notification_registrar.h"
26 #include "ui/base/gtk/gtk_signal.h"
31 class RecentlyUsedFoldersComboModel
;
33 typedef struct _GtkWidget GtkWidget
;
34 typedef struct _GParamSpec GParamSpec
;
36 class BookmarkBubbleGtk
: public BubbleDelegateGtk
,
37 public content::NotificationObserver
{
39 // Shows the bookmark bubble, pointing at |anchor_widget|.
40 static void Show(GtkWidget
* anchor_widget
,
43 bool newly_bookmarked
);
46 virtual void BubbleClosing(BubbleGtk
* bubble
, bool closed_by_escape
) OVERRIDE
;
48 // content::NotificationObserver:
49 virtual void Observe(int type
,
50 const content::NotificationSource
& source
,
51 const content::NotificationDetails
& details
) OVERRIDE
;
54 friend class BookmarkBubbleGtkBrowserTest
;
55 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleGtkBrowserTest
, SyncPromoSignedIn
);
56 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleGtkBrowserTest
, SyncPromoNotSignedIn
);
57 FRIEND_TEST_ALL_PREFIXES(BookmarkBubbleGtkBrowserTest
, SyncPromoLink
);
59 BookmarkBubbleGtk(GtkWidget
* anchor
,
62 bool newly_bookmarked
);
63 virtual ~BookmarkBubbleGtk();
65 // Notified when the content is destroyed so we can delete our instance.
66 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnDestroy
);
67 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnNameActivate
);
68 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnFolderChanged
);
69 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnEditClicked
);
70 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnCloseClicked
);
71 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnRemoveClicked
);
72 CHROMEGTK_CALLBACK_1(BookmarkBubbleGtk
,
76 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk
, void, OnSyncPromoRealize
);
77 CHROMEGTK_CALLBACK_1(BookmarkBubbleGtk
,
82 // Sets the colors used in the sync promo according to the current theme.
83 void UpdatePromoColors();
85 // Update the bookmark with any edits that have been made.
88 // Open the bookmark editor for the current url and close the bubble.
91 // Return the UTF8 encoded title for the current |url_|.
92 std::string
GetTitle();
94 void InitFolderComboModel();
96 // We basically have a singleton, since a bubble is sort of app-modal. This
97 // keeps track of the currently open bubble, or NULL if none is open.
98 static BookmarkBubbleGtk
* bookmark_bubble_
;
100 // The URL of the bookmark.
103 // Our current profile (used to access the bookmark system).
106 // This is owned by the Profile.
107 BookmarkModel
* model_
;
109 // Provides colors and stuff.
110 GtkThemeService
* theme_service_
;
112 // The widget relative to which we are positioned.
115 // The button that removes the bookmark.
116 GtkWidget
* remove_button_
;
118 // The bookmark sync promo, if shown.
121 // The label in the bookmark sync promo, if shown.
122 GtkWidget
* promo_label_
;
124 // The various labels in the interface. We keep track of them for theme
126 std::vector
<GtkWidget
*> labels_
;
128 // The GtkEntry for editing the bookmark name / title.
129 GtkWidget
* name_entry_
;
131 // The combo box for selecting the bookmark folder.
132 GtkWidget
* folder_combo_
;
133 scoped_ptr
<RecentlyUsedFoldersComboModel
> folder_combo_model_
;
137 // Whether the bubble is creating or editing an existing bookmark.
138 bool newly_bookmarked_
;
139 // When closing the window, whether we should update or remove the bookmark.
141 bool remove_bookmark_
;
143 content::NotificationRegistrar registrar_
;
145 // We need to push some things on the back of the message loop, so we have
146 // a factory attached to our instance to manage task lifetimes.
147 base::WeakPtrFactory
<BookmarkBubbleGtk
> factory_
;
149 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleGtk
);
152 #endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_