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

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

Issue 150176: GTK: First draft of using native themes, partially based on evan's CL 118358. (Closed)
Patch Set: And the codereview tool is back. 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_bar_gtk.h" 5 #include "chrome/browser/gtk/bookmark_bar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/gfx/text_elider.h" 9 #include "app/gfx/text_elider.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/gfx/gtk_util.h" 12 #include "base/gfx/gtk_util.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 #include "chrome/browser/bookmarks/bookmark_drag_data.h" 14 #include "chrome/browser/bookmarks/bookmark_drag_data.h"
15 #include "chrome/browser/bookmarks/bookmark_utils.h" 15 #include "chrome/browser/bookmarks/bookmark_utils.h"
16 #include "chrome/browser/browser.h" 16 #include "chrome/browser/browser.h"
17 #include "chrome/browser/gtk/bookmark_context_menu.h" 17 #include "chrome/browser/gtk/bookmark_context_menu.h"
18 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" 18 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h"
19 #include "chrome/browser/gtk/bookmark_tree_model.h" 19 #include "chrome/browser/gtk/bookmark_tree_model.h"
20 #include "chrome/browser/gtk/bookmark_utils_gtk.h" 20 #include "chrome/browser/gtk/bookmark_utils_gtk.h"
21 #include "chrome/browser/gtk/browser_window_gtk.h" 21 #include "chrome/browser/gtk/browser_window_gtk.h"
22 #include "chrome/browser/gtk/custom_button.h" 22 #include "chrome/browser/gtk/custom_button.h"
23 #include "chrome/browser/gtk/gtk_chrome_button.h" 23 #include "chrome/browser/gtk/gtk_chrome_button.h"
24 #include "chrome/browser/gtk/gtk_dnd_util.h" 24 #include "chrome/browser/gtk/gtk_dnd_util.h"
25 #include "chrome/browser/gtk/gtk_theme_provider.h"
25 #include "chrome/browser/gtk/nine_box.h" 26 #include "chrome/browser/gtk/nine_box.h"
26 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" 27 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
27 #include "chrome/browser/metrics/user_metrics.h" 28 #include "chrome/browser/metrics/user_metrics.h"
28 #include "chrome/browser/profile.h" 29 #include "chrome/browser/profile.h"
29 #include "chrome/browser/tab_contents/tab_contents.h" 30 #include "chrome/browser/tab_contents/tab_contents.h"
30 #include "chrome/common/gtk_util.h" 31 #include "chrome/common/gtk_util.h"
31 #include "chrome/common/pref_names.h" 32 #include "chrome/common/pref_names.h"
32 #include "chrome/common/pref_service.h" 33 #include "chrome/common/pref_service.h"
33 #include "grit/app_resources.h" 34 #include "grit/app_resources.h"
34 #include "grit/generated_resources.h" 35 #include "grit/generated_resources.h"
35 #include "grit/theme_resources.h" 36 #include "grit/theme_resources.h"
36 37
37 namespace { 38 namespace {
38 39
39 // The height of the bar. 40 // The height of the bar.
40 const int kBookmarkBarHeight = 33; 41 const int kBookmarkBarHeight = 33;
41 42
42 // Left-padding for the instructional text. 43 // Left-padding for the instructional text.
43 const int kInstructionsPadding = 6; 44 const int kInstructionsPadding = 6;
44 45
45 // Color of the instructional text. 46 // Color of the instructional text.
46 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142); 47 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142);
47 48
49 void SetUseSystemThemeGraphicsOnToolbarItems(GtkToolItem* item, bool use_gtk) {
50 GtkWidget* child = gtk_bin_get_child(GTK_BIN(item));
51 if (GTK_IS_CHROME_BUTTON(child)) {
52 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(child), use_gtk);
53 }
54 }
55
48 } // namespace 56 } // namespace
49 57
50 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser, 58 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser,
51 BrowserWindowGtk* window) 59 BrowserWindowGtk* window)
52 : profile_(NULL), 60 : profile_(NULL),
53 page_navigator_(NULL), 61 page_navigator_(NULL),
54 browser_(browser), 62 browser_(browser),
55 window_(window), 63 window_(window),
56 model_(NULL), 64 model_(NULL),
57 instructions_(NULL), 65 instructions_(NULL),
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 gtk_button_set_label( 163 gtk_button_set_label(
156 GTK_BUTTON(other_bookmarks_button_), 164 GTK_BUTTON(other_bookmarks_button_),
157 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str()); 165 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str());
158 gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_), 166 gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_),
159 gtk_image_new_from_pixbuf(folder_icon)); 167 gtk_image_new_from_pixbuf(folder_icon));
160 // Set the proper text colors. 168 // Set the proper text colors.
161 bookmark_utils::SetButtonTextColors(other_bookmarks_button_); 169 bookmark_utils::SetButtonTextColors(other_bookmarks_button_);
162 170
163 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, 171 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_,
164 FALSE, FALSE, 0); 172 FALSE, FALSE, 0);
173
174 // Set the current theme state for all the buttons.
175 UserChangedTheme(profile);
165 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0); 176 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0);
166 177
167 slide_animation_.reset(new SlideAnimation(this)); 178 slide_animation_.reset(new SlideAnimation(this));
168 } 179 }
169 180
170 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { 181 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) {
171 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0); 182 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0);
172 } 183 }
173 184
174 void BookmarkBarGtk::Show(bool animate) { 185 void BookmarkBarGtk::Show(bool animate) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 259
249 void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model, 260 void BookmarkBarGtk::BookmarkNodeAdded(BookmarkModel* model,
250 const BookmarkNode* parent, 261 const BookmarkNode* parent,
251 int index) { 262 int index) {
252 if (parent != model_->GetBookmarkBarNode()) { 263 if (parent != model_->GetBookmarkBarNode()) {
253 // We only care about nodes on the bookmark bar. 264 // We only care about nodes on the bookmark bar.
254 return; 265 return;
255 } 266 }
256 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 267 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
257 268
269 GtkToolItem* item = CreateBookmarkToolItem(parent->GetChild(index));
258 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), 270 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()),
259 CreateBookmarkToolItem(parent->GetChild(index)), 271 item, index);
260 index); 272 bool use_gtk = GtkThemeProvider::UseSystemThemeGraphics(profile_);
273 SetUseSystemThemeGraphicsOnToolbarItems(item, use_gtk);
261 274
262 SetInstructionState(parent); 275 SetInstructionState(parent);
263 } 276 }
264 277
265 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model, 278 void BookmarkBarGtk::BookmarkNodeRemoved(BookmarkModel* model,
266 const BookmarkNode* parent, 279 const BookmarkNode* parent,
267 int index) { 280 int index) {
268 if (parent != model_->GetBookmarkBarNode()) { 281 if (parent != model_->GetBookmarkBarNode()) {
269 // We only care about nodes on the bookmark bar. 282 // We only care about nodes on the bookmark bar.
270 return; 283 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 CreateAllBookmarkButtons(node); 322 CreateAllBookmarkButtons(node);
310 } 323 }
311 324
312 void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) { 325 void BookmarkBarGtk::CreateAllBookmarkButtons(const BookmarkNode* node) {
313 // Create a button for each of the children on the bookmark bar. 326 // Create a button for each of the children on the bookmark bar.
314 for (int i = 0; i < node->GetChildCount(); ++i) { 327 for (int i = 0; i < node->GetChildCount(); ++i) {
315 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i)); 328 GtkToolItem* item = CreateBookmarkToolItem(node->GetChild(i));
316 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1); 329 gtk_toolbar_insert(GTK_TOOLBAR(bookmark_toolbar_.get()), item, -1);
317 } 330 }
318 331
332 // Now that we've made a bunch of toolbar items, we need to make sure they
333 // have the correct theme state.
334 UserChangedTheme(profile_);
335
319 SetInstructionState(node); 336 SetInstructionState(node);
320 } 337 }
321 338
322 void BookmarkBarGtk::SetInstructionState( 339 void BookmarkBarGtk::SetInstructionState(
323 const BookmarkNode* boomarks_bar_node) { 340 const BookmarkNode* boomarks_bar_node) {
324 show_instructions_ = (boomarks_bar_node->GetChildCount() == 0); 341 show_instructions_ = (boomarks_bar_node->GetChildCount() == 0);
325 if (show_instructions_) { 342 if (show_instructions_) {
326 gtk_widget_show_all(instructions_); 343 gtk_widget_show_all(instructions_);
327 } else { 344 } else {
328 gtk_widget_hide(instructions_); 345 gtk_widget_hide(instructions_);
329 } 346 }
330 } 347 }
331 348
332 void BookmarkBarGtk::RemoveAllBookmarkButtons() { 349 void BookmarkBarGtk::RemoveAllBookmarkButtons() {
333 gtk_util::RemoveAllChildren(bookmark_toolbar_.get()); 350 gtk_util::RemoveAllChildren(bookmark_toolbar_.get());
334 } 351 }
335 352
336 int BookmarkBarGtk::GetBookmarkButtonCount() { 353 int BookmarkBarGtk::GetBookmarkButtonCount() {
337 GList* children = gtk_container_get_children( 354 GList* children = gtk_container_get_children(
338 GTK_CONTAINER(bookmark_toolbar_.get())); 355 GTK_CONTAINER(bookmark_toolbar_.get()));
339 int count = g_list_length(children); 356 int count = g_list_length(children);
340 g_list_free(children); 357 g_list_free(children);
341 return count; 358 return count;
342 } 359 }
343 360
344 bool BookmarkBarGtk::IsAlwaysShown() { 361 bool BookmarkBarGtk::IsAlwaysShown() {
345 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); 362 return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar);
346 } 363 }
347 364
365 void BookmarkBarGtk::UserChangedTheme(Profile* profile) {
366 bool use_gtk = GtkThemeProvider::UseSystemThemeGraphics(profile);
367
368 gtk_chrome_button_set_use_gtk_rendering(
369 GTK_CHROME_BUTTON(other_bookmarks_button_), use_gtk);
370
371 gtk_container_foreach(
372 GTK_CONTAINER(bookmark_toolbar_.get()),
373 reinterpret_cast<void (*)(GtkWidget*, void*)>(
374 SetUseSystemThemeGraphicsOnToolbarItems),
375 reinterpret_cast<void*>(use_gtk));
376 }
377
348 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) { 378 void BookmarkBarGtk::AnimationProgressed(const Animation* animation) {
349 DCHECK_EQ(animation, slide_animation_.get()); 379 DCHECK_EQ(animation, slide_animation_.get());
350 380
351 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 381 gtk_widget_set_size_request(bookmark_hbox_.get(), -1,
352 animation->GetCurrentValue() * 382 animation->GetCurrentValue() *
353 kBookmarkBarHeight); 383 kBookmarkBarHeight);
354 } 384 }
355 385
356 void BookmarkBarGtk::AnimationEnded(const Animation* animation) { 386 void BookmarkBarGtk::AnimationEnded(const Animation* animation) {
357 DCHECK_EQ(animation, slide_animation_.get()); 387 DCHECK_EQ(animation, slide_animation_.get());
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 bar->InitBackground(); 771 bar->InitBackground();
742 gfx::Point tabstrip_origin = 772 gfx::Point tabstrip_origin =
743 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); 773 bar->window_->tabstrip()->GetTabStripOriginForWidget(widget);
744 bar->background_ninebox_->RenderTopCenterStrip( 774 bar->background_ninebox_->RenderTopCenterStrip(
745 cr, tabstrip_origin.x(), tabstrip_origin.y(), 775 cr, tabstrip_origin.x(), tabstrip_origin.y(),
746 event->area.x + event->area.width - tabstrip_origin.x()); 776 event->area.x + event->area.width - tabstrip_origin.x());
747 cairo_destroy(cr); 777 cairo_destroy(cr);
748 778
749 return FALSE; // Propagate expose to children. 779 return FALSE; // Propagate expose to children.
750 } 780 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698