| OLD | NEW |
| 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 "app/gfx/gtk_util.h" | 7 #include "app/gfx/gtk_util.h" |
| 8 #include "app/gfx/text_elider.h" | 8 #include "app/gfx/text_elider.h" |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 // Dictionary key used to store a BookmarkNode* on a GtkWidget. | 43 // Dictionary key used to store a BookmarkNode* on a GtkWidget. |
| 44 const char kBookmarkNode[] = "bookmark-node"; | 44 const char kBookmarkNode[] = "bookmark-node"; |
| 45 | 45 |
| 46 // Mime types for DnD. Used to synchronize across applications. | 46 // Mime types for DnD. Used to synchronize across applications. |
| 47 const char kInternalURIType[] = "application/x-chrome-bookmark-item"; | 47 const char kInternalURIType[] = "application/x-chrome-bookmark-item"; |
| 48 | 48 |
| 49 // Left-padding for the instructional text. | 49 // Left-padding for the instructional text. |
| 50 const int kInstructionsPadding = 6; | 50 const int kInstructionsPadding = 6; |
| 51 | 51 |
| 52 // Color of the button text, taken from TextButtonView. |
| 53 const GdkColor kEnabledColor = GDK_COLOR_RGB(6, 45, 117); |
| 54 const GdkColor kDisabledColor = GDK_COLOR_RGB(161, 161, 146); |
| 55 // TextButtonView uses 255, 255, 255 with opacity of 200. We don't support |
| 56 // transparent text though, so just use a slightly lighter version of |
| 57 // kEnabledColor. |
| 58 const GdkColor kHighlightColor = GDK_COLOR_RGB(56, 95, 167); |
| 59 |
| 52 // Color of the instructional text. | 60 // Color of the instructional text. |
| 53 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142); | 61 const GdkColor kInstructionsColor = GDK_COLOR_RGB(128, 128, 142); |
| 54 | 62 |
| 63 // Only used for the background of the drag widget. |
| 64 const GdkColor kBackgroundColor = GDK_COLOR_RGB(0xe6, 0xed, 0xf4); |
| 65 |
| 55 // Table of the mime types that we accept with their options. | 66 // Table of the mime types that we accept with their options. |
| 56 const GtkTargetEntry kTargetTable[] = { | 67 const GtkTargetEntry kTargetTable[] = { |
| 57 { const_cast<char*>(kInternalURIType), GTK_TARGET_SAME_APP, | 68 { const_cast<char*>(kInternalURIType), GTK_TARGET_SAME_APP, |
| 58 dnd::X_CHROME_BOOKMARK_ITEM } | 69 dnd::X_CHROME_BOOKMARK_ITEM } |
| 59 // TODO(erg): Add "text/uri-list" support. | 70 // TODO(erg): Add "text/uri-list" support. |
| 60 }; | 71 }; |
| 61 | 72 |
| 62 const int kTargetTableSize = G_N_ELEMENTS(kTargetTable); | 73 const int kTargetTableSize = G_N_ELEMENTS(kTargetTable); |
| 63 | 74 |
| 75 // Recursively search for label among the children of |widget|. |
| 76 void SearchForLabel(GtkWidget* widget, gpointer data) { |
| 77 if (GTK_IS_LABEL(widget)) { |
| 78 *reinterpret_cast<GtkWidget**>(data) = widget; |
| 79 } else if (GTK_IS_CONTAINER(widget)) { |
| 80 gtk_container_foreach(GTK_CONTAINER(widget), SearchForLabel, data); |
| 81 } |
| 82 } |
| 83 |
| 84 // This function is a temporary hack to fix fonts on dark system themes. |
| 85 // NOTE: this makes assumptions about GtkButton internals. Also, it only works |
| 86 // if you call it after the last time you edit the button. |
| 87 // TODO(estade): remove this function. |
| 88 void SetButtonTextColors(GtkWidget* button) { |
| 89 GtkWidget* label; |
| 90 gtk_container_foreach(GTK_CONTAINER(button), SearchForLabel, &label); |
| 91 if (label) { |
| 92 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &kEnabledColor); |
| 93 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &kEnabledColor); |
| 94 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &kHighlightColor); |
| 95 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &kDisabledColor); |
| 96 } |
| 97 } |
| 98 |
| 64 } // namespace | 99 } // namespace |
| 65 | 100 |
| 66 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser) | 101 BookmarkBarGtk::BookmarkBarGtk(Profile* profile, Browser* browser) |
| 67 : profile_(NULL), | 102 : profile_(NULL), |
| 68 page_navigator_(NULL), | 103 page_navigator_(NULL), |
| 69 browser_(browser), | 104 browser_(browser), |
| 70 model_(NULL), | 105 model_(NULL), |
| 71 instructions_(NULL), | 106 instructions_(NULL), |
| 72 show_instructions_(true) { | 107 show_instructions_(true) { |
| 73 Init(profile); | 108 Init(profile); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 G_CALLBACK(&OnButtonPressed), this); | 191 G_CALLBACK(&OnButtonPressed), this); |
| 157 | 192 |
| 158 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(), | 193 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), gtk_vseparator_new(), |
| 159 FALSE, FALSE, 0); | 194 FALSE, FALSE, 0); |
| 160 | 195 |
| 161 other_bookmarks_button_ = gtk_chrome_button_new(); | 196 other_bookmarks_button_ = gtk_chrome_button_new(); |
| 162 ConnectFolderButtonEvents(other_bookmarks_button_); | 197 ConnectFolderButtonEvents(other_bookmarks_button_); |
| 163 gtk_button_set_label( | 198 gtk_button_set_label( |
| 164 GTK_BUTTON(other_bookmarks_button_), | 199 GTK_BUTTON(other_bookmarks_button_), |
| 165 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str()); | 200 l10n_util::GetStringUTF8(IDS_BOOMARK_BAR_OTHER_BOOKMARKED).c_str()); |
| 201 |
| 166 gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_), | 202 gtk_button_set_image(GTK_BUTTON(other_bookmarks_button_), |
| 167 gtk_image_new_from_pixbuf(folder_icon)); | 203 gtk_image_new_from_pixbuf(folder_icon)); |
| 204 // Set the proper text colors. |
| 205 SetButtonTextColors(other_bookmarks_button_); |
| 168 | 206 |
| 169 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, | 207 gtk_box_pack_start(GTK_BOX(bookmark_hbox_.get()), other_bookmarks_button_, |
| 170 FALSE, FALSE, 0); | 208 FALSE, FALSE, 0); |
| 171 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0); | 209 gtk_widget_set_size_request(bookmark_hbox_.get(), -1, 0); |
| 172 | 210 |
| 173 slide_animation_.reset(new SlideAnimation(this)); | 211 slide_animation_.reset(new SlideAnimation(this)); |
| 174 } | 212 } |
| 175 | 213 |
| 176 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { | 214 void BookmarkBarGtk::AddBookmarkbarToBox(GtkWidget* box) { |
| 177 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0); | 215 gtk_box_pack_start(GTK_BOX(box), bookmark_hbox_.get(), FALSE, FALSE, 0); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 gtk_image_new_from_pixbuf(default_bookmark_icon)); | 416 gtk_image_new_from_pixbuf(default_bookmark_icon)); |
| 379 } | 417 } |
| 380 } else { | 418 } else { |
| 381 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 419 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 382 static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed( | 420 static GdkPixbuf* default_bookmark_icon = rb.GetPixbufNamed( |
| 383 IDR_BOOKMARK_BAR_FOLDER); | 421 IDR_BOOKMARK_BAR_FOLDER); |
| 384 gtk_button_set_image(GTK_BUTTON(button), | 422 gtk_button_set_image(GTK_BUTTON(button), |
| 385 gtk_image_new_from_pixbuf(default_bookmark_icon)); | 423 gtk_image_new_from_pixbuf(default_bookmark_icon)); |
| 386 } | 424 } |
| 387 | 425 |
| 426 SetButtonTextColors(button); |
| 388 g_object_set_data(G_OBJECT(button), kBookmarkNode, | 427 g_object_set_data(G_OBJECT(button), kBookmarkNode, |
| 389 reinterpret_cast<void*>(node)); | 428 reinterpret_cast<void*>(node)); |
| 390 } | 429 } |
| 391 | 430 |
| 392 GtkWidget* BookmarkBarGtk::CreateBookmarkButton( | 431 GtkWidget* BookmarkBarGtk::CreateBookmarkButton( |
| 393 BookmarkNode* node) { | 432 BookmarkNode* node) { |
| 394 GtkWidget* button = gtk_chrome_button_new(); | 433 GtkWidget* button = gtk_chrome_button_new(); |
| 395 ConfigureButtonForNode(node, button); | 434 ConfigureButtonForNode(node, button); |
| 396 | 435 |
| 397 // The tool item is also a source for dragging | 436 // The tool item is also a source for dragging |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 574 bar->ignore_button_release_ = true; | 613 bar->ignore_button_release_ = true; |
| 575 | 614 |
| 576 BookmarkNode* node = bar->GetNodeForToolButton(button); | 615 BookmarkNode* node = bar->GetNodeForToolButton(button); |
| 577 DCHECK(node); | 616 DCHECK(node); |
| 578 | 617 |
| 579 bar->dragged_node_ = node; | 618 bar->dragged_node_ = node; |
| 580 bar->toolbar_drop_item_ = NULL; | 619 bar->toolbar_drop_item_ = NULL; |
| 581 | 620 |
| 582 // Build a windowed representation for our button. | 621 // Build a windowed representation for our button. |
| 583 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); | 622 GtkWidget* window = gtk_window_new(GTK_WINDOW_POPUP); |
| 623 gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &kBackgroundColor); |
| 584 gtk_widget_realize(window); | 624 gtk_widget_realize(window); |
| 585 | 625 |
| 586 GtkWidget* frame = gtk_frame_new(NULL); | 626 GtkWidget* frame = gtk_frame_new(NULL); |
| 587 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); | 627 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); |
| 588 gtk_container_add(GTK_CONTAINER(window), frame); | 628 gtk_container_add(GTK_CONTAINER(window), frame); |
| 589 gtk_widget_show(frame); | 629 gtk_widget_show(frame); |
| 590 | 630 |
| 591 GtkWidget* floating_button = gtk_chrome_button_new(); | 631 GtkWidget* floating_button = gtk_chrome_button_new(); |
| 592 bar->ConfigureButtonForNode(node, floating_button); | 632 bar->ConfigureButtonForNode(node, floating_button); |
| 593 gtk_container_add(GTK_CONTAINER(frame), floating_button); | 633 gtk_container_add(GTK_CONTAINER(frame), floating_button); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 cairo_rectangle(cr, event->area.x, event->area.y, | 840 cairo_rectangle(cr, event->area.x, event->area.y, |
| 801 event->area.width, event->area.height); | 841 event->area.width, event->area.height); |
| 802 cairo_clip(cr); | 842 cairo_clip(cr); |
| 803 bar->InitBackground(); | 843 bar->InitBackground(); |
| 804 bar->background_ninebox_->RenderTopCenterStrip(cr, event->area.x, | 844 bar->background_ninebox_->RenderTopCenterStrip(cr, event->area.x, |
| 805 0, event->area.width); | 845 0, event->area.width); |
| 806 cairo_destroy(cr); | 846 cairo_destroy(cr); |
| 807 | 847 |
| 808 return FALSE; // Propagate expose to children. | 848 return FALSE; // Propagate expose to children. |
| 809 } | 849 } |
| OLD | NEW |