| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/gtk/global_bookmark_menu.h" | 5 #include "chrome/browser/ui/gtk/global_bookmark_menu.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/bookmarks/bookmark_model.h" | 12 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/themes/theme_service_factory.h" | 14 #include "chrome/browser/themes/theme_service_factory.h" |
| 15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" | 16 #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" |
| 17 #include "chrome/browser/ui/gtk/global_bookmark_menu.h" | 17 #include "chrome/browser/ui/gtk/global_bookmark_menu.h" |
| 18 #include "chrome/browser/ui/gtk/global_menu_bar.h" | 18 #include "chrome/browser/ui/gtk/global_menu_bar.h" |
| 19 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 19 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 20 #include "chrome/browser/ui/gtk/gtk_util.h" | 20 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 21 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/gtk_util.h" | 25 #include "ui/gfx/gtk_util.h" |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 // We need to know whether we're using a newer GTK at run time because we need | 29 // We need to know whether we're using a newer GTK at run time because we need |
| 29 // to prevent. | 30 // to prevent. |
| 30 // | 31 // |
| (...skipping 22 matching lines...) Expand all Loading... |
| 53 | 54 |
| 54 GlobalBookmarkMenu::GlobalBookmarkMenu(Browser* browser) | 55 GlobalBookmarkMenu::GlobalBookmarkMenu(Browser* browser) |
| 55 : browser_(browser), | 56 : browser_(browser), |
| 56 profile_(browser->profile()), | 57 profile_(browser->profile()), |
| 57 default_favicon_(NULL), | 58 default_favicon_(NULL), |
| 58 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { | 59 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| 59 DCHECK(profile_); | 60 DCHECK(profile_); |
| 60 | 61 |
| 61 default_favicon_ = GtkThemeService::GetDefaultFavicon(true); | 62 default_favicon_ = GtkThemeService::GetDefaultFavicon(true); |
| 62 default_folder_ = GtkThemeService::GetFolderIcon(true); | 63 default_folder_ = GtkThemeService::GetFolderIcon(true); |
| 63 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, | 64 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 64 Source<ThemeService>( | 65 Source<ThemeService>( |
| 65 ThemeServiceFactory::GetForProfile(profile_))); | 66 ThemeServiceFactory::GetForProfile(profile_))); |
| 66 } | 67 } |
| 67 | 68 |
| 68 GlobalBookmarkMenu::~GlobalBookmarkMenu() { | 69 GlobalBookmarkMenu::~GlobalBookmarkMenu() { |
| 69 profile_->GetBookmarkModel()->RemoveObserver(this); | 70 profile_->GetBookmarkModel()->RemoveObserver(this); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void GlobalBookmarkMenu::Init(GtkWidget* bookmark_menu, | 73 void GlobalBookmarkMenu::Init(GtkWidget* bookmark_menu, |
| 73 GtkWidget* bookmark_menu_item) { | 74 GtkWidget* bookmark_menu_item) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 219 } |
| 219 | 220 |
| 220 // static | 221 // static |
| 221 void GlobalBookmarkMenu::ClearBookmarkItemCallback(GtkWidget* menu_item, | 222 void GlobalBookmarkMenu::ClearBookmarkItemCallback(GtkWidget* menu_item, |
| 222 void* unused) { | 223 void* unused) { |
| 223 int tag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "type-tag")); | 224 int tag = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "type-tag")); |
| 224 if (tag == GlobalMenuBar::TAG_BOOKMARK_CLEARABLE) | 225 if (tag == GlobalMenuBar::TAG_BOOKMARK_CLEARABLE) |
| 225 gtk_widget_destroy(menu_item); | 226 gtk_widget_destroy(menu_item); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void GlobalBookmarkMenu::Observe(NotificationType type, | 229 void GlobalBookmarkMenu::Observe(int type, |
| 229 const NotificationSource& source, | 230 const NotificationSource& source, |
| 230 const NotificationDetails& details) { | 231 const NotificationDetails& details) { |
| 231 DCHECK(type.value == NotificationType::BROWSER_THEME_CHANGED); | 232 DCHECK(type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED); |
| 232 | 233 |
| 233 // Change the icon and invalidate the menu. | 234 // Change the icon and invalidate the menu. |
| 234 default_favicon_ = GtkThemeService::GetDefaultFavicon(true); | 235 default_favicon_ = GtkThemeService::GetDefaultFavicon(true); |
| 235 default_folder_ = GtkThemeService::GetFolderIcon(true); | 236 default_folder_ = GtkThemeService::GetFolderIcon(true); |
| 236 RebuildMenuInFuture(); | 237 RebuildMenuInFuture(); |
| 237 } | 238 } |
| 238 | 239 |
| 239 void GlobalBookmarkMenu::Loaded(BookmarkModel* model) { | 240 void GlobalBookmarkMenu::Loaded(BookmarkModel* model) { |
| 240 // If we have a Loaded() event, then we need to build the menu immediately | 241 // If we have a Loaded() event, then we need to build the menu immediately |
| 241 // for the first time. | 242 // for the first time. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 void GlobalBookmarkMenu::OnBookmarkItemActivated(GtkWidget* menu_item) { | 295 void GlobalBookmarkMenu::OnBookmarkItemActivated(GtkWidget* menu_item) { |
| 295 // The actual mouse event that generated this activated event was in a | 296 // The actual mouse event that generated this activated event was in a |
| 296 // different process. Go with something default. | 297 // different process. Go with something default. |
| 297 const BookmarkNode* node = static_cast<const BookmarkNode*>( | 298 const BookmarkNode* node = static_cast<const BookmarkNode*>( |
| 298 g_object_get_data(G_OBJECT(menu_item), "bookmark-node")); | 299 g_object_get_data(G_OBJECT(menu_item), "bookmark-node")); |
| 299 | 300 |
| 300 browser_->OpenURL(node->GetURL(), GURL(), NEW_FOREGROUND_TAB, | 301 browser_->OpenURL(node->GetURL(), GURL(), NEW_FOREGROUND_TAB, |
| 301 PageTransition::AUTO_BOOKMARK); | 302 PageTransition::AUTO_BOOKMARK); |
| 302 } | 303 } |
| 303 | 304 |
| OLD | NEW |