| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "app/gfx/canvas_paint.h" |
| 9 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
| 10 #include "app/gtk_dnd_util.h" | 11 #include "app/gtk_dnd_util.h" |
| 11 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 12 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 13 #include "base/gfx/gtk_util.h" | 14 #include "base/gfx/gtk_util.h" |
| 14 #include "base/pickle.h" | 15 #include "base/pickle.h" |
| 15 #include "chrome/browser/bookmarks/bookmark_drag_data.h" | 16 #include "chrome/browser/bookmarks/bookmark_drag_data.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 17 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_utils.h" | 18 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 18 #include "chrome/browser/browser.h" | 19 #include "chrome/browser/browser.h" |
| 19 #include "chrome/browser/gtk/bookmark_context_menu.h" | 20 #include "chrome/browser/gtk/bookmark_context_menu.h" |
| 20 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" | 21 #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" |
| 21 #include "chrome/browser/gtk/bookmark_tree_model.h" | 22 #include "chrome/browser/gtk/bookmark_tree_model.h" |
| 22 #include "chrome/browser/gtk/bookmark_utils_gtk.h" | 23 #include "chrome/browser/gtk/bookmark_utils_gtk.h" |
| 23 #include "chrome/browser/gtk/browser_window_gtk.h" | 24 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 24 #include "chrome/browser/gtk/cairo_cached_surface.h" | 25 #include "chrome/browser/gtk/cairo_cached_surface.h" |
| 25 #include "chrome/browser/gtk/custom_button.h" | 26 #include "chrome/browser/gtk/custom_button.h" |
| 26 #include "chrome/browser/gtk/gtk_chrome_button.h" | 27 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 27 #include "chrome/browser/gtk/gtk_theme_provider.h" | 28 #include "chrome/browser/gtk/gtk_theme_provider.h" |
| 28 #include "chrome/browser/gtk/rounded_window.h" | 29 #include "chrome/browser/gtk/rounded_window.h" |
| 29 #include "chrome/browser/gtk/tabstrip_origin_provider.h" | 30 #include "chrome/browser/gtk/tabstrip_origin_provider.h" |
| 30 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | 31 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
| 31 #include "chrome/browser/gtk/view_id_util.h" | 32 #include "chrome/browser/gtk/view_id_util.h" |
| 32 #include "chrome/browser/metrics/user_metrics.h" | 33 #include "chrome/browser/metrics/user_metrics.h" |
| 34 #include "chrome/browser/ntp_background_util.h" |
| 33 #include "chrome/browser/profile.h" | 35 #include "chrome/browser/profile.h" |
| 34 #include "chrome/browser/tab_contents/tab_contents.h" | 36 #include "chrome/browser/tab_contents/tab_contents.h" |
| 37 #include "chrome/browser/tab_contents/tab_contents_view.h" |
| 35 #include "chrome/common/gtk_util.h" | 38 #include "chrome/common/gtk_util.h" |
| 36 #include "chrome/common/notification_service.h" | 39 #include "chrome/common/notification_service.h" |
| 37 #include "chrome/common/pref_names.h" | 40 #include "chrome/common/pref_names.h" |
| 38 #include "chrome/common/pref_service.h" | 41 #include "chrome/common/pref_service.h" |
| 39 #include "grit/app_resources.h" | 42 #include "grit/app_resources.h" |
| 40 #include "grit/generated_resources.h" | 43 #include "grit/generated_resources.h" |
| 41 #include "grit/theme_resources.h" | 44 #include "grit/theme_resources.h" |
| 42 | 45 |
| 43 namespace { | 46 namespace { |
| 44 | 47 |
| (...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, | 1013 gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget, |
| 1011 GdkEventExpose* event, | 1014 GdkEventExpose* event, |
| 1012 BookmarkBarGtk* bar) { | 1015 BookmarkBarGtk* bar) { |
| 1013 GtkThemeProvider* theme_provider = bar->theme_provider_; | 1016 GtkThemeProvider* theme_provider = bar->theme_provider_; |
| 1014 | 1017 |
| 1015 // We don't need to render the toolbar image in GTK mode, except when | 1018 // We don't need to render the toolbar image in GTK mode, except when |
| 1016 // detached. | 1019 // detached. |
| 1017 if (theme_provider->UseGtkTheme() && !bar->floating_) | 1020 if (theme_provider->UseGtkTheme() && !bar->floating_) |
| 1018 return FALSE; | 1021 return FALSE; |
| 1019 | 1022 |
| 1020 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 1023 if (!bar->floating_) { |
| 1021 cairo_rectangle(cr, event->area.x, event->area.y, | 1024 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 1022 event->area.width, event->area.height); | 1025 cairo_rectangle(cr, event->area.x, event->area.y, |
| 1023 cairo_clip(cr); | 1026 event->area.width, event->area.height); |
| 1027 cairo_clip(cr); |
| 1024 | 1028 |
| 1025 if (!bar->floating_) { | |
| 1026 // Paint the background theme image. | 1029 // Paint the background theme image. |
| 1027 gfx::Point tabstrip_origin = | 1030 gfx::Point tabstrip_origin = |
| 1028 bar->tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); | 1031 bar->tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); |
| 1029 | 1032 |
| 1030 CairoCachedSurface* background = theme_provider->GetSurfaceNamed( | 1033 CairoCachedSurface* background = theme_provider->GetSurfaceNamed( |
| 1031 IDR_THEME_TOOLBAR, widget); | 1034 IDR_THEME_TOOLBAR, widget); |
| 1032 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); | 1035 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); |
| 1033 // We tile the toolbar background in both directions. | 1036 // We tile the toolbar background in both directions. |
| 1034 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 1037 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
| 1035 cairo_rectangle(cr, | 1038 cairo_rectangle(cr, |
| 1036 tabstrip_origin.x(), | 1039 tabstrip_origin.x(), |
| 1037 tabstrip_origin.y(), | 1040 tabstrip_origin.y(), |
| 1038 event->area.x + event->area.width - tabstrip_origin.x(), | 1041 event->area.x + event->area.width - tabstrip_origin.x(), |
| 1039 event->area.y + event->area.height - tabstrip_origin.y()); | 1042 event->area.y + event->area.height - tabstrip_origin.y()); |
| 1040 cairo_fill(cr); | 1043 cairo_fill(cr); |
| 1044 |
| 1045 cairo_destroy(cr); |
| 1041 } else { | 1046 } else { |
| 1042 // Paint the NTP background. First set the background color. | 1047 gfx::Size tab_contents_size; |
| 1043 GdkColor bg_color = theme_provider->UseGtkTheme() ? gfx::kGdkWhite : | 1048 Browser* browser = bar->browser_; |
| 1044 theme_provider->GetGdkColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND); | 1049 if (!browser) { |
| 1045 double bg_color_rgb[] = { | 1050 NOTREACHED(); |
| 1046 static_cast<double>(bg_color.red / 257) / 255.0, | 1051 return FALSE; |
| 1047 static_cast<double>(bg_color.green / 257) / 255.0, | |
| 1048 static_cast<double>(bg_color.blue / 257) / 255.0, }; | |
| 1049 cairo_set_source_rgb(cr, bg_color_rgb[0], bg_color_rgb[1], bg_color_rgb[2]); | |
| 1050 cairo_rectangle(cr, | |
| 1051 event->area.x, | |
| 1052 event->area.y, | |
| 1053 event->area.width, | |
| 1054 event->area.height); | |
| 1055 cairo_fill(cr); | |
| 1056 | |
| 1057 // Now paint the image, if it exists. | |
| 1058 // TODO(estade): handle different alignments. | |
| 1059 if (theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { | |
| 1060 CairoCachedSurface* background = theme_provider->GetSurfaceNamed( | |
| 1061 IDR_THEME_NTP_BACKGROUND, widget); | |
| 1062 background->SetSource(cr, widget->allocation.x, widget->allocation.y); | |
| 1063 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | |
| 1064 cairo_rectangle(cr, | |
| 1065 event->area.x, | |
| 1066 event->area.y, | |
| 1067 event->area.width, | |
| 1068 event->area.height); | |
| 1069 cairo_fill(cr); | |
| 1070 } | 1052 } |
| 1053 TabContents* tab_contents = browser->GetSelectedTabContents(); |
| 1054 if (!tab_contents) { |
| 1055 NOTREACHED(); |
| 1056 return FALSE; |
| 1057 } |
| 1058 if (!tab_contents->view()) { |
| 1059 NOTREACHED(); |
| 1060 return FALSE; |
| 1061 } |
| 1062 tab_contents_size = tab_contents->view()->GetContainerSize(); |
| 1063 gfx::CanvasPaint canvas(event, true); |
| 1064 NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas, |
| 1065 gfx::Rect(widget->allocation), tab_contents_size.height()); |
| 1071 } | 1066 } |
| 1072 | 1067 |
| 1073 cairo_destroy(cr); | |
| 1074 | |
| 1075 return FALSE; // Propagate expose to children. | 1068 return FALSE; // Propagate expose to children. |
| 1076 } | 1069 } |
| 1077 | 1070 |
| 1078 // static | 1071 // static |
| 1079 gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, | 1072 gboolean BookmarkBarGtk::OnSeparatorExpose(GtkWidget* widget, |
| 1080 GdkEventExpose* event, | 1073 GdkEventExpose* event, |
| 1081 BookmarkBarGtk* bar) { | 1074 BookmarkBarGtk* bar) { |
| 1082 if (bar->theme_provider_->UseGtkTheme()) | 1075 if (bar->theme_provider_->UseGtkTheme()) |
| 1083 return FALSE; | 1076 return FALSE; |
| 1084 | 1077 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 break; | 1169 break; |
| 1177 } | 1170 } |
| 1178 } | 1171 } |
| 1179 DCHECK_NE(button_idx, -1); | 1172 DCHECK_NE(button_idx, -1); |
| 1180 | 1173 |
| 1181 // Find the GtkWidget* for the actual target button. | 1174 // Find the GtkWidget* for the actual target button. |
| 1182 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1; | 1175 int shift = dir == GTK_MENU_DIR_PARENT ? -1 : 1; |
| 1183 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); | 1176 button_idx = (button_idx + shift + folder_list.size()) % folder_list.size(); |
| 1184 PopupForButton(folder_list[button_idx]); | 1177 PopupForButton(folder_list[button_idx]); |
| 1185 } | 1178 } |
| OLD | NEW |