| OLD | NEW |
| (Empty) |
| 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. | |
| 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 | |
| 15 #include <string> | |
| 16 #include <vector> | |
| 17 | |
| 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" | |
| 27 #include "url/gurl.h" | |
| 28 | |
| 29 class BookmarkModel; | |
| 30 class Profile; | |
| 31 class RecentlyUsedFoldersComboModel; | |
| 32 | |
| 33 typedef struct _GtkWidget GtkWidget; | |
| 34 typedef struct _GParamSpec GParamSpec; | |
| 35 | |
| 36 class BookmarkBubbleGtk : public BubbleDelegateGtk, | |
| 37 public content::NotificationObserver { | |
| 38 public: | |
| 39 // Shows the bookmark bubble, pointing at |anchor_widget|. | |
| 40 static void Show(GtkWidget* anchor_widget, | |
| 41 Profile* profile, | |
| 42 const GURL& url, | |
| 43 bool newly_bookmarked); | |
| 44 | |
| 45 // BubbleDelegateGtk: | |
| 46 virtual void BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) OVERRIDE; | |
| 47 | |
| 48 // content::NotificationObserver: | |
| 49 virtual void Observe(int type, | |
| 50 const content::NotificationSource& source, | |
| 51 const content::NotificationDetails& details) OVERRIDE; | |
| 52 | |
| 53 private: | |
| 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); | |
| 58 | |
| 59 BookmarkBubbleGtk(GtkWidget* anchor, | |
| 60 Profile* profile, | |
| 61 const GURL& url, | |
| 62 bool newly_bookmarked); | |
| 63 virtual ~BookmarkBubbleGtk(); | |
| 64 | |
| 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, | |
| 73 gboolean, | |
| 74 OnSignInClicked, | |
| 75 gchar*); | |
| 76 CHROMEGTK_CALLBACK_0(BookmarkBubbleGtk, void, OnSyncPromoRealize); | |
| 77 CHROMEGTK_CALLBACK_1(BookmarkBubbleGtk, | |
| 78 gboolean, | |
| 79 OnSyncPromoExpose, | |
| 80 GdkEventExpose*); | |
| 81 | |
| 82 // Sets the colors used in the sync promo according to the current theme. | |
| 83 void UpdatePromoColors(); | |
| 84 | |
| 85 // Update the bookmark with any edits that have been made. | |
| 86 void ApplyEdits(); | |
| 87 | |
| 88 // Open the bookmark editor for the current url and close the bubble. | |
| 89 void ShowEditor(); | |
| 90 | |
| 91 // Return the UTF8 encoded title for the current |url_|. | |
| 92 std::string GetTitle(); | |
| 93 | |
| 94 void InitFolderComboModel(); | |
| 95 | |
| 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_; | |
| 99 | |
| 100 // The URL of the bookmark. | |
| 101 GURL url_; | |
| 102 | |
| 103 // Our current profile (used to access the bookmark system). | |
| 104 Profile* profile_; | |
| 105 | |
| 106 // This is owned by the Profile. | |
| 107 BookmarkModel* model_; | |
| 108 | |
| 109 // Provides colors and stuff. | |
| 110 GtkThemeService* theme_service_; | |
| 111 | |
| 112 // The widget relative to which we are positioned. | |
| 113 GtkWidget* anchor_; | |
| 114 | |
| 115 // The button that removes the bookmark. | |
| 116 GtkWidget* remove_button_; | |
| 117 | |
| 118 // The bookmark sync promo, if shown. | |
| 119 GtkWidget* promo_; | |
| 120 | |
| 121 // The label in the bookmark sync promo, if shown. | |
| 122 GtkWidget* promo_label_; | |
| 123 | |
| 124 // The various labels in the interface. We keep track of them for theme | |
| 125 // changes. | |
| 126 std::vector<GtkWidget*> labels_; | |
| 127 | |
| 128 // The GtkEntry for editing the bookmark name / title. | |
| 129 GtkWidget* name_entry_; | |
| 130 | |
| 131 // The combo box for selecting the bookmark folder. | |
| 132 GtkWidget* folder_combo_; | |
| 133 scoped_ptr<RecentlyUsedFoldersComboModel> folder_combo_model_; | |
| 134 | |
| 135 BubbleGtk* bubble_; | |
| 136 | |
| 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. | |
| 140 bool apply_edits_; | |
| 141 bool remove_bookmark_; | |
| 142 | |
| 143 content::NotificationRegistrar registrar_; | |
| 144 | |
| 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_; | |
| 148 | |
| 149 DISALLOW_COPY_AND_ASSIGN(BookmarkBubbleGtk); | |
| 150 }; | |
| 151 | |
| 152 #endif // CHROME_BROWSER_UI_GTK_BOOKMARKS_BOOKMARK_BUBBLE_GTK_H_ | |
| OLD | NEW |