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

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

Issue 9371005: GTK: Do more GSEALing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/find_bar_gtk.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bookmarks/bookmark_bar_gtk.h" 5 #include "chrome/browser/ui/gtk/bookmarks/bookmark_bar_gtk.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 } else { 637 } else {
638 gtk_util::StopActingAsRoundedWindow(paint_box_); 638 gtk_util::StopActingAsRoundedWindow(paint_box_);
639 gtk_event_box_set_visible_window(GTK_EVENT_BOX(paint_box_), FALSE); 639 gtk_event_box_set_visible_window(GTK_EVENT_BOX(paint_box_), FALSE);
640 gtk_alignment_set_padding(GTK_ALIGNMENT(ntp_padding_box_), 0, 0, 0, 0); 640 gtk_alignment_set_padding(GTK_ALIGNMENT(ntp_padding_box_), 0, 0, 0, 0);
641 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), 0); 641 gtk_container_set_border_width(GTK_CONTAINER(bookmark_hbox_), 0);
642 } 642 }
643 643
644 UpdateEventBoxPaintability(); 644 UpdateEventBoxPaintability();
645 // |window_| can be NULL during testing. 645 // |window_| can be NULL during testing.
646 // Listen for parent size allocations. Only connect once. 646 // Listen for parent size allocations. Only connect once.
647 if (window_ && detached && widget()->parent && 647 if (window_ && detached) {
648 g_signal_handler_find(widget()->parent, G_SIGNAL_MATCH_FUNC, 648 GtkWidget* parent = gtk_widget_get_parent(widget());
649 0, 0, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocateThunk), 649 if (parent &&
650 NULL) == 0) { 650 g_signal_handler_find(parent, G_SIGNAL_MATCH_FUNC,
651 g_signal_connect(widget()->parent, "size-allocate", 651 0, 0, NULL, reinterpret_cast<gpointer>(OnParentSizeAllocateThunk),
652 G_CALLBACK(OnParentSizeAllocateThunk), this); 652 NULL) == 0) {
653 g_signal_connect(parent, "size-allocate",
654 G_CALLBACK(OnParentSizeAllocateThunk), this);
655 }
653 } 656 }
654 } 657 }
655 658
656 void BookmarkBarGtk::UpdateEventBoxPaintability() { 659 void BookmarkBarGtk::UpdateEventBoxPaintability() {
657 gtk_widget_set_app_paintable( 660 gtk_widget_set_app_paintable(
658 event_box_.get(), 661 event_box_.get(),
659 (!theme_service_->UsingNativeTheme() || 662 (!theme_service_->UsingNativeTheme() ||
660 bookmark_bar_state_ == BookmarkBar::DETACHED)); 663 bookmark_bar_state_ == BookmarkBar::DETACHED));
661 // When using the GTK+ theme, we need to have the event box be visible so 664 // When using the GTK+ theme, we need to have the event box be visible so
662 // buttons don't get a halo color from the background. When using Chromium 665 // buttons don't get a halo color from the background. When using Chromium
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 814
812 int BookmarkBarGtk::GetToolbarIndexForDragOverFolder(GtkWidget* button, 815 int BookmarkBarGtk::GetToolbarIndexForDragOverFolder(GtkWidget* button,
813 gint x) { 816 gint x) {
814 GtkAllocation allocation; 817 GtkAllocation allocation;
815 gtk_widget_get_allocation(button, &allocation); 818 gtk_widget_get_allocation(button, &allocation);
816 819
817 int margin = std::min(15, static_cast<int>(0.3 * allocation.width)); 820 int margin = std::min(15, static_cast<int>(0.3 * allocation.width));
818 if (x > margin && x < (allocation.width - margin)) 821 if (x > margin && x < (allocation.width - margin))
819 return -1; 822 return -1;
820 823
824 GtkWidget* parent = gtk_widget_get_parent(button);
821 gint index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()), 825 gint index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()),
822 GTK_TOOL_ITEM(button->parent)); 826 GTK_TOOL_ITEM(parent));
823 if (x > margin) 827 if (x > margin)
824 index++; 828 index++;
825 return index; 829 return index;
826 } 830 }
827 831
828 void BookmarkBarGtk::ClearToolbarDropHighlighting() { 832 void BookmarkBarGtk::ClearToolbarDropHighlighting() {
829 if (toolbar_drop_item_) { 833 if (toolbar_drop_item_) {
830 g_object_unref(toolbar_drop_item_); 834 g_object_unref(toolbar_drop_item_);
831 toolbar_drop_item_ = NULL; 835 toolbar_drop_item_ = NULL;
832 } 836 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 Profile* profile = browser_->profile(); 1143 Profile* profile = browser_->profile();
1140 RecordAppLaunch(profile, node->url()); 1144 RecordAppLaunch(profile, node->url());
1141 bookmark_utils::OpenAll(window_->GetNativeHandle(), profile, page_navigator_, 1145 bookmark_utils::OpenAll(window_->GetNativeHandle(), profile, page_navigator_,
1142 node, gtk_util::DispositionForCurrentButtonPressEvent()); 1146 node, gtk_util::DispositionForCurrentButtonPressEvent());
1143 1147
1144 content::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton")); 1148 content::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton"));
1145 } 1149 }
1146 1150
1147 void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button, 1151 void BookmarkBarGtk::OnButtonDragBegin(GtkWidget* button,
1148 GdkDragContext* drag_context) { 1152 GdkDragContext* drag_context) {
1153 GtkWidget* button_parent = gtk_widget_get_parent(button);
1154
1149 // The parent tool item might be removed during the drag. Ref it so |button| 1155 // The parent tool item might be removed during the drag. Ref it so |button|
1150 // won't get destroyed. 1156 // won't get destroyed.
1151 g_object_ref(button->parent); 1157 g_object_ref(button_parent);
1152 1158
1153 const BookmarkNode* node = GetNodeForToolButton(button); 1159 const BookmarkNode* node = GetNodeForToolButton(button);
1154 DCHECK(!dragged_node_); 1160 DCHECK(!dragged_node_);
1155 dragged_node_ = node; 1161 dragged_node_ = node;
1156 DCHECK(dragged_node_); 1162 DCHECK(dragged_node_);
1157 1163
1158 drag_icon_ = bookmark_utils::GetDragRepresentationForNode( 1164 drag_icon_ = bookmark_utils::GetDragRepresentationForNode(
1159 node, model_, theme_service_); 1165 node, model_, theme_service_);
1160 1166
1161 // We have to jump through some hoops to get the drag icon to line up because 1167 // We have to jump through some hoops to get the drag icon to line up because
1162 // it is a different size than the button. 1168 // it is a different size than the button.
1163 GtkRequisition req; 1169 GtkRequisition req;
1164 gtk_widget_size_request(drag_icon_, &req); 1170 gtk_widget_size_request(drag_icon_, &req);
1165 gfx::Rect button_rect = gtk_util::WidgetBounds(button); 1171 gfx::Rect button_rect = gtk_util::WidgetBounds(button);
1166 gfx::Point drag_icon_relative = 1172 gfx::Point drag_icon_relative =
1167 gfx::Rect(req.width, req.height).CenterPoint().Add( 1173 gfx::Rect(req.width, req.height).CenterPoint().Add(
1168 (last_pressed_coordinates_.Subtract(button_rect.CenterPoint()))); 1174 (last_pressed_coordinates_.Subtract(button_rect.CenterPoint())));
1169 gtk_drag_set_icon_widget(drag_context, drag_icon_, 1175 gtk_drag_set_icon_widget(drag_context, drag_icon_,
1170 drag_icon_relative.x(), 1176 drag_icon_relative.x(),
1171 drag_icon_relative.y()); 1177 drag_icon_relative.y());
1172 1178
1173 // Hide our node, but reserve space for it on the toolbar. 1179 // Hide our node, but reserve space for it on the toolbar.
1174 int index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()), 1180 int index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()),
1175 GTK_TOOL_ITEM(button->parent)); 1181 GTK_TOOL_ITEM(button_parent));
1176 gtk_widget_hide(button); 1182 gtk_widget_hide(button);
1177 toolbar_drop_item_ = CreateBookmarkToolItem(dragged_node_); 1183 toolbar_drop_item_ = CreateBookmarkToolItem(dragged_node_);
1178 g_object_ref_sink(GTK_OBJECT(toolbar_drop_item_)); 1184 g_object_ref_sink(GTK_OBJECT(toolbar_drop_item_));
1179 gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(bookmark_toolbar_.get()), 1185 gtk_toolbar_set_drop_highlight_item(GTK_TOOLBAR(bookmark_toolbar_.get()),
1180 GTK_TOOL_ITEM(toolbar_drop_item_), index); 1186 GTK_TOOL_ITEM(toolbar_drop_item_), index);
1181 // Make sure it stays hidden for the duration of the drag. 1187 // Make sure it stays hidden for the duration of the drag.
1182 gtk_widget_set_no_show_all(button, TRUE); 1188 gtk_widget_set_no_show_all(button, TRUE);
1183 } 1189 }
1184 1190
1185 void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button, 1191 void BookmarkBarGtk::OnButtonDragEnd(GtkWidget* button,
1186 GdkDragContext* drag_context) { 1192 GdkDragContext* drag_context) {
1187 gtk_widget_show(button); 1193 gtk_widget_show(button);
1188 gtk_widget_set_no_show_all(button, FALSE); 1194 gtk_widget_set_no_show_all(button, FALSE);
1189 1195
1190 ClearToolbarDropHighlighting(); 1196 ClearToolbarDropHighlighting();
1191 1197
1192 DCHECK(dragged_node_); 1198 DCHECK(dragged_node_);
1193 dragged_node_ = NULL; 1199 dragged_node_ = NULL;
1194 1200
1195 DCHECK(drag_icon_); 1201 DCHECK(drag_icon_);
1196 gtk_widget_destroy(drag_icon_); 1202 gtk_widget_destroy(drag_icon_);
1197 drag_icon_ = NULL; 1203 drag_icon_ = NULL;
1198 1204
1199 g_object_unref(button->parent); 1205 g_object_unref(gtk_widget_get_parent(button));
1200 } 1206 }
1201 1207
1202 void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget, 1208 void BookmarkBarGtk::OnButtonDragGet(GtkWidget* widget,
1203 GdkDragContext* context, 1209 GdkDragContext* context,
1204 GtkSelectionData* selection_data, 1210 GtkSelectionData* selection_data,
1205 guint target_type, 1211 guint target_type,
1206 guint time) { 1212 guint time) {
1207 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget); 1213 const BookmarkNode* node = bookmark_utils::BookmarkNodeForWidget(widget);
1208 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type, 1214 bookmark_utils::WriteBookmarkToSelection(node, selection_data, target_type,
1209 browser_->profile()); 1215 browser_->profile());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1273 } else { 1279 } else {
1274 index = GetToolbarIndexForDragOverFolder(widget, x); 1280 index = GetToolbarIndexForDragOverFolder(widget, x);
1275 if (index < 0) { 1281 if (index < 0) {
1276 dest_node = GetNodeForToolButton(widget); 1282 dest_node = GetNodeForToolButton(widget);
1277 index = dest_node->child_count(); 1283 index = dest_node->child_count();
1278 } 1284 }
1279 } 1285 }
1280 1286
1281 switch (target_type) { 1287 switch (target_type) {
1282 case ui::CHROME_BOOKMARK_ITEM: { 1288 case ui::CHROME_BOOKMARK_ITEM: {
1283 Pickle pickle(reinterpret_cast<char*>(selection_data->data), 1289 gint length = gtk_selection_data_get_length(selection_data);
1284 selection_data->length); 1290 Pickle pickle(reinterpret_cast<const char*>(
1291 gtk_selection_data_get_data(selection_data)), length);
1285 BookmarkNodeData drag_data; 1292 BookmarkNodeData drag_data;
1286 if (drag_data.ReadFromPickle(&pickle)) { 1293 if (drag_data.ReadFromPickle(&pickle)) {
1287 dnd_success = bookmark_utils::PerformBookmarkDrop( 1294 dnd_success = bookmark_utils::PerformBookmarkDrop(
1288 browser_->profile(), 1295 browser_->profile(),
1289 drag_data, 1296 drag_data,
1290 dest_node, 1297 dest_node,
1291 index) != ui::DragDropTypes::DRAG_NONE; 1298 index) != ui::DragDropTypes::DRAG_NONE;
1292 } 1299 }
1293 break; 1300 break;
1294 } 1301 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1376 TRACE_EVENT0("ui::gtk", "BookmarkBarGtk::OnEventBoxExpose"); 1383 TRACE_EVENT0("ui::gtk", "BookmarkBarGtk::OnEventBoxExpose");
1377 GtkThemeService* theme_provider = theme_service_; 1384 GtkThemeService* theme_provider = theme_service_;
1378 1385
1379 // We don't need to render the toolbar image in GTK mode, except when 1386 // We don't need to render the toolbar image in GTK mode, except when
1380 // detached. 1387 // detached.
1381 if (theme_provider->UsingNativeTheme() && 1388 if (theme_provider->UsingNativeTheme() &&
1382 bookmark_bar_state_ != BookmarkBar::DETACHED) 1389 bookmark_bar_state_ != BookmarkBar::DETACHED)
1383 return FALSE; 1390 return FALSE;
1384 1391
1385 if (bookmark_bar_state_ != BookmarkBar::DETACHED) { 1392 if (bookmark_bar_state_ != BookmarkBar::DETACHED) {
1386 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 1393 cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(widget));
1387 gdk_cairo_rectangle(cr, &event->area); 1394 gdk_cairo_rectangle(cr, &event->area);
1388 cairo_clip(cr); 1395 cairo_clip(cr);
1389 1396
1390 // Paint the background theme image. 1397 // Paint the background theme image.
1391 gfx::Point tabstrip_origin = 1398 gfx::Point tabstrip_origin =
1392 tabstrip_origin_provider_->GetTabStripOriginForWidget(widget); 1399 tabstrip_origin_provider_->GetTabStripOriginForWidget(widget);
1393 gtk_util::DrawThemedToolbarBackground(widget, cr, event, tabstrip_origin, 1400 gtk_util::DrawThemedToolbarBackground(widget, cr, event, tabstrip_origin,
1394 theme_provider); 1401 theme_provider);
1395 1402
1396 cairo_destroy(cr); 1403 cairo_destroy(cr);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1443 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { 1450 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() {
1444 GtkDestDefaults dest_defaults = 1451 GtkDestDefaults dest_defaults =
1445 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : 1452 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL :
1446 GTK_DEST_DEFAULT_DROP; 1453 GTK_DEST_DEFAULT_DROP;
1447 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); 1454 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction);
1448 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, 1455 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults,
1449 NULL, 0, kDragAction); 1456 NULL, 0, kDragAction);
1450 ui::SetDestTargetList(overflow_button_, kDestTargetList); 1457 ui::SetDestTargetList(overflow_button_, kDestTargetList);
1451 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); 1458 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList);
1452 } 1459 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/gtk/find_bar_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698