Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: chrome/browser/gtk/bookmark_bubble_gtk.cc

Issue 160025: GTK Themes: Theme the bookmark bubble. (And first run bubble). (Closed)
Patch Set: Remove text_color for estade Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/bookmark_bubble_gtk.h" 5 #include "chrome/browser/gtk/bookmark_bubble_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gfx/gtk_util.h" 12 #include "base/gfx/gtk_util.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "chrome/browser/bookmarks/bookmark_editor.h" 15 #include "chrome/browser/bookmarks/bookmark_editor.h"
16 #include "chrome/browser/bookmarks/bookmark_model.h" 16 #include "chrome/browser/bookmarks/bookmark_model.h"
17 #include "chrome/browser/bookmarks/bookmark_utils.h" 17 #include "chrome/browser/bookmarks/bookmark_utils.h"
18 #include "chrome/browser/gtk/gtk_chrome_link_button.h" 18 #include "chrome/browser/gtk/gtk_chrome_link_button.h"
19 #include "chrome/browser/gtk/gtk_theme_provider.h"
19 #include "chrome/browser/gtk/info_bubble_gtk.h" 20 #include "chrome/browser/gtk/info_bubble_gtk.h"
20 #include "chrome/browser/metrics/user_metrics.h" 21 #include "chrome/browser/metrics/user_metrics.h"
21 #include "chrome/browser/profile.h" 22 #include "chrome/browser/profile.h"
22 #include "chrome/common/gtk_util.h" 23 #include "chrome/common/gtk_util.h"
23 #include "chrome/common/notification_service.h" 24 #include "chrome/common/notification_service.h"
24 #include "grit/generated_resources.h" 25 #include "grit/generated_resources.h"
25 26
26 namespace { 27 namespace {
27 28
28 // We basically have a singleton, since a bubble is sort of app-modal. This 29 // We basically have a singleton, since a bubble is sort of app-modal. This
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 remove_bookmark_ = newly_bookmarked_; 106 remove_bookmark_ = newly_bookmarked_;
106 apply_edits_ = false; 107 apply_edits_ = false;
107 } 108 }
108 109
109 NotificationService::current()->Notify( 110 NotificationService::current()->Notify(
110 NotificationType::BOOKMARK_BUBBLE_HIDDEN, 111 NotificationType::BOOKMARK_BUBBLE_HIDDEN,
111 Source<Profile>(profile_->GetOriginalProfile()), 112 Source<Profile>(profile_->GetOriginalProfile()),
112 NotificationService::NoDetails()); 113 NotificationService::NoDetails());
113 } 114 }
114 115
116 void BookmarkBubbleGtk::Observe(NotificationType type,
117 const NotificationSource& source,
118 const NotificationDetails& details) {
119 DCHECK(type == NotificationType::BROWSER_THEME_CHANGED);
120
121 if (theme_provider_->UseGtkTheme()) {
122 for (std::vector<GtkWidget*>::iterator it = labels_.begin();
123 it != labels_.end(); ++it) {
124 gtk_widget_modify_fg(*it, GTK_STATE_NORMAL, NULL);
125 }
126 } else {
127 for (std::vector<GtkWidget*>::iterator it = labels_.begin();
128 it != labels_.end(); ++it) {
129 gtk_widget_modify_fg(*it, GTK_STATE_NORMAL, &gfx::kGdkBlack);
130 }
131 }
132 }
133
115 BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel, 134 BookmarkBubbleGtk::BookmarkBubbleGtk(GtkWindow* transient_toplevel,
116 const gfx::Rect& rect, 135 const gfx::Rect& rect,
117 Profile* profile, 136 Profile* profile,
118 const GURL& url, 137 const GURL& url,
119 bool newly_bookmarked) 138 bool newly_bookmarked)
120 : url_(url), 139 : url_(url),
121 profile_(profile), 140 profile_(profile),
141 theme_provider_(GtkThemeProvider::GetFrom(profile_)),
122 transient_toplevel_(transient_toplevel), 142 transient_toplevel_(transient_toplevel),
123 content_(NULL), 143 content_(NULL),
124 name_entry_(NULL), 144 name_entry_(NULL),
125 folder_combo_(NULL), 145 folder_combo_(NULL),
126 bubble_(NULL), 146 bubble_(NULL),
127 factory_(this), 147 factory_(this),
128 newly_bookmarked_(newly_bookmarked), 148 newly_bookmarked_(newly_bookmarked),
129 apply_edits_(true), 149 apply_edits_(true),
130 remove_bookmark_(false) { 150 remove_bookmark_(false) {
131 GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8( 151 GtkWidget* label = gtk_label_new(l10n_util::GetStringUTF8(
132 newly_bookmarked_ ? IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED : 152 newly_bookmarked_ ? IDS_BOOMARK_BUBBLE_PAGE_BOOKMARKED :
133 IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK).c_str()); 153 IDS_BOOMARK_BUBBLE_PAGE_BOOKMARK).c_str());
134 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &gfx::kGdkBlack); 154 labels_.push_back(label);
135 GtkWidget* remove_button = gtk_chrome_link_button_new( 155 GtkWidget* remove_button = gtk_chrome_link_button_new(
136 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK).c_str()); 156 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_REMOVE_BOOKMARK).c_str());
137 GtkWidget* edit_button = gtk_button_new_with_label( 157 GtkWidget* edit_button = gtk_button_new_with_label(
138 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_OPTIONS).c_str()); 158 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_OPTIONS).c_str());
139 GtkWidget* close_button = gtk_button_new_with_label( 159 GtkWidget* close_button = gtk_button_new_with_label(
140 l10n_util::GetStringUTF8(IDS_CLOSE).c_str()); 160 l10n_util::GetStringUTF8(IDS_CLOSE).c_str());
141 161
142 // Our content is arrange in 3 rows. |top| contains a left justified 162 // Our content is arrange in 3 rows. |top| contains a left justified
143 // message, and a right justified remove link button. |table| is the middle 163 // message, and a right justified remove link button. |table| is the middle
144 // portion with the name entry and the folder combo. |bottom| is the final 164 // portion with the name entry and the folder combo. |bottom| is the final
(...skipping 14 matching lines...) Expand all
159 folder_nodes_ = PopulateFolderCombo(profile_->GetBookmarkModel(), 179 folder_nodes_ = PopulateFolderCombo(profile_->GetBookmarkModel(),
160 url_, folder_combo_); 180 url_, folder_combo_);
161 181
162 // Create the edit entry for updating the bookmark name / title. 182 // Create the edit entry for updating the bookmark name / title.
163 name_entry_ = gtk_entry_new(); 183 name_entry_ = gtk_entry_new();
164 gtk_entry_set_text(GTK_ENTRY(name_entry_), GetTitle().c_str()); 184 gtk_entry_set_text(GTK_ENTRY(name_entry_), GetTitle().c_str());
165 185
166 // We use a table to allow the labels to line up with each other, along 186 // We use a table to allow the labels to line up with each other, along
167 // with the entry and folder combo lining up. 187 // with the entry and folder combo lining up.
168 GtkWidget* table = gtk_util::CreateLabeledControlsGroup( 188 GtkWidget* table = gtk_util::CreateLabeledControlsGroup(
169 &gfx::kGdkBlack, 189 &labels_,
170 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_TITLE_TEXT).c_str(), 190 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_TITLE_TEXT).c_str(),
171 name_entry_, 191 name_entry_,
172 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_FOLDER_TEXT).c_str(), 192 l10n_util::GetStringUTF8(IDS_BOOMARK_BUBBLE_FOLDER_TEXT).c_str(),
173 folder_combo_, 193 folder_combo_,
174 NULL); 194 NULL);
175 195
176 GtkWidget* bottom = gtk_hbox_new(FALSE, 0); 196 GtkWidget* bottom = gtk_hbox_new(FALSE, 0);
177 // We want the buttons on the right, so just use an expanding label to fill 197 // We want the buttons on the right, so just use an expanding label to fill
178 // all of the extra space on the right. 198 // all of the extra space on the right.
179 gtk_box_pack_start(GTK_BOX(bottom), gtk_label_new(""), 199 gtk_box_pack_start(GTK_BOX(bottom), gtk_label_new(""),
180 TRUE, TRUE, 0); 200 TRUE, TRUE, 0);
181 gtk_box_pack_start(GTK_BOX(bottom), edit_button, 201 gtk_box_pack_start(GTK_BOX(bottom), edit_button,
182 FALSE, FALSE, 4); 202 FALSE, FALSE, 4);
183 gtk_box_pack_start(GTK_BOX(bottom), close_button, 203 gtk_box_pack_start(GTK_BOX(bottom), close_button,
184 FALSE, FALSE, 0); 204 FALSE, FALSE, 0);
185 205
186 gtk_box_pack_start(GTK_BOX(content), top, TRUE, TRUE, 0); 206 gtk_box_pack_start(GTK_BOX(content), top, TRUE, TRUE, 0);
187 gtk_box_pack_start(GTK_BOX(content), table, TRUE, TRUE, 0); 207 gtk_box_pack_start(GTK_BOX(content), table, TRUE, TRUE, 0);
188 gtk_box_pack_start(GTK_BOX(content), bottom, TRUE, TRUE, 0); 208 gtk_box_pack_start(GTK_BOX(content), bottom, TRUE, TRUE, 0);
189 // We want the focus to start on the entry, not on the remove button. 209 // We want the focus to start on the entry, not on the remove button.
190 gtk_container_set_focus_child(GTK_CONTAINER(content), table); 210 gtk_container_set_focus_child(GTK_CONTAINER(content), table);
191 211
192 bubble_ = InfoBubbleGtk::Show(transient_toplevel_, 212 bubble_ = InfoBubbleGtk::Show(transient_toplevel_,
193 rect, content, this); 213 rect, content, theme_provider_, this);
194 if (!bubble_) { 214 if (!bubble_) {
195 NOTREACHED(); 215 NOTREACHED();
196 return; 216 return;
197 } 217 }
198 218
199 g_signal_connect(content, "destroy", 219 g_signal_connect(content, "destroy",
200 G_CALLBACK(&HandleDestroyThunk), this); 220 G_CALLBACK(&HandleDestroyThunk), this);
201 g_signal_connect(name_entry_, "activate", 221 g_signal_connect(name_entry_, "activate",
202 G_CALLBACK(&HandleNameActivateThunk), this); 222 G_CALLBACK(&HandleNameActivateThunk), this);
203 g_signal_connect(folder_combo_, "changed", 223 g_signal_connect(folder_combo_, "changed",
204 G_CALLBACK(&HandleFolderChangedThunk), this); 224 G_CALLBACK(&HandleFolderChangedThunk), this);
205 g_signal_connect(edit_button, "clicked", 225 g_signal_connect(edit_button, "clicked",
206 G_CALLBACK(&HandleEditButtonThunk), this); 226 G_CALLBACK(&HandleEditButtonThunk), this);
207 g_signal_connect(close_button, "clicked", 227 g_signal_connect(close_button, "clicked",
208 G_CALLBACK(&HandleCloseButtonThunk), this); 228 G_CALLBACK(&HandleCloseButtonThunk), this);
209 g_signal_connect(remove_button, "clicked", 229 g_signal_connect(remove_button, "clicked",
210 G_CALLBACK(&HandleRemoveButtonThunk), this); 230 G_CALLBACK(&HandleRemoveButtonThunk), this);
231
232 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
233 NotificationService::AllSources());
234 theme_provider_->InitThemesFor(this);
211 } 235 }
212 236
213 BookmarkBubbleGtk::~BookmarkBubbleGtk() { 237 BookmarkBubbleGtk::~BookmarkBubbleGtk() {
214 DCHECK(!content_); // |content_| should have already been destroyed. 238 DCHECK(!content_); // |content_| should have already been destroyed.
215 239
216 DCHECK(g_bubble); 240 DCHECK(g_bubble);
217 g_bubble = NULL; 241 g_bubble = NULL;
218 242
219 if (apply_edits_) { 243 if (apply_edits_) {
220 ApplyEdits(); 244 ApplyEdits();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 GtkWidget* toplevel = GTK_WIDGET(transient_toplevel_); 346 GtkWidget* toplevel = GTK_WIDGET(transient_toplevel_);
323 347
324 // Close the bubble, deleting the C++ objects, etc. 348 // Close the bubble, deleting the C++ objects, etc.
325 bubble_->Close(); 349 bubble_->Close();
326 350
327 if (node) { 351 if (node) {
328 BookmarkEditor::Show(toplevel, profile, NULL, node, 352 BookmarkEditor::Show(toplevel, profile, NULL, node,
329 BookmarkEditor::SHOW_TREE, NULL); 353 BookmarkEditor::SHOW_TREE, NULL);
330 } 354 }
331 } 355 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/bookmark_bubble_gtk.h ('k') | chrome/browser/gtk/edit_search_engine_dialog.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698