OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 } | 289 } |
290 BookmarkBar::State old_state = bookmark_bar_state_; | 290 BookmarkBar::State old_state = bookmark_bar_state_; |
291 bookmark_bar_state_ = state; | 291 bookmark_bar_state_ = state; |
292 if (state == BookmarkBar::SHOW || state == BookmarkBar::DETACHED) | 292 if (state == BookmarkBar::SHOW || state == BookmarkBar::DETACHED) |
293 Show(old_state, animate_type); | 293 Show(old_state, animate_type); |
294 else | 294 else |
295 Hide(old_state, animate_type); | 295 Hide(old_state, animate_type); |
296 } | 296 } |
297 | 297 |
298 int BookmarkBarGtk::GetHeight() { | 298 int BookmarkBarGtk::GetHeight() { |
299 return event_box_->allocation.height - kBookmarkBarMinimumHeight; | 299 GtkAllocation allocation; |
| 300 gtk_widget_get_allocation(event_box_.get(), &allocation); |
| 301 return allocation.height - kBookmarkBarMinimumHeight; |
300 } | 302 } |
301 | 303 |
302 bool BookmarkBarGtk::IsAnimating() { | 304 bool BookmarkBarGtk::IsAnimating() { |
303 return slide_animation_.is_animating(); | 305 return slide_animation_.is_animating(); |
304 } | 306 } |
305 | 307 |
306 void BookmarkBarGtk::CalculateMaxHeight() { | 308 void BookmarkBarGtk::CalculateMaxHeight() { |
307 | |
308 if (theme_service_->UsingNativeTheme()) { | 309 if (theme_service_->UsingNativeTheme()) { |
309 // Get the requisition of our single child instead of the event box itself | 310 // Get the requisition of our single child instead of the event box itself |
310 // because the event box probably already has a size request. | 311 // because the event box probably already has a size request. |
311 GtkRequisition req; | 312 GtkRequisition req; |
312 gtk_widget_size_request(ntp_padding_box_, &req); | 313 gtk_widget_size_request(ntp_padding_box_, &req); |
313 max_height_ = req.height; | 314 max_height_ = req.height; |
314 } else { | 315 } else { |
315 max_height_ = (bookmark_bar_state_ == BookmarkBar::DETACHED) ? | 316 max_height_ = (bookmark_bar_state_ == BookmarkBar::DETACHED) ? |
316 kBookmarkBarNTPHeight : kBookmarkBarHeight; | 317 kBookmarkBarNTPHeight : kBookmarkBarHeight; |
317 } | 318 } |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 void BookmarkBarGtk::SetChevronState() { | 482 void BookmarkBarGtk::SetChevronState() { |
482 if (!gtk_widget_get_visible(bookmark_hbox_)) | 483 if (!gtk_widget_get_visible(bookmark_hbox_)) |
483 return; | 484 return; |
484 | 485 |
485 if (show_instructions_) { | 486 if (show_instructions_) { |
486 gtk_widget_hide(overflow_button_); | 487 gtk_widget_hide(overflow_button_); |
487 return; | 488 return; |
488 } | 489 } |
489 | 490 |
490 int extra_space = 0; | 491 int extra_space = 0; |
491 if (gtk_widget_get_visible(overflow_button_)) | 492 if (gtk_widget_get_visible(overflow_button_)) { |
492 extra_space = overflow_button_->allocation.width; | 493 GtkAllocation allocation; |
| 494 gtk_widget_get_allocation(overflow_button_, &allocation); |
| 495 extra_space = allocation.width; |
| 496 } |
493 | 497 |
494 int overflow_idx = GetFirstHiddenBookmark(extra_space, NULL); | 498 int overflow_idx = GetFirstHiddenBookmark(extra_space, NULL); |
495 if (overflow_idx == -1) | 499 if (overflow_idx == -1) |
496 gtk_widget_hide(overflow_button_); | 500 gtk_widget_hide(overflow_button_); |
497 else | 501 else |
498 gtk_widget_show_all(overflow_button_); | 502 gtk_widget_show_all(overflow_button_); |
499 } | 503 } |
500 | 504 |
501 void BookmarkBarGtk::UpdateOtherBookmarksVisibility() { | 505 void BookmarkBarGtk::UpdateOtherBookmarksVisibility() { |
502 bool has_other_children = !model_->other_node()->empty(); | 506 bool has_other_children = !model_->other_node()->empty(); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 std::vector<GtkWidget*>* showing_folders) { | 568 std::vector<GtkWidget*>* showing_folders) { |
565 int rv = 0; | 569 int rv = 0; |
566 // We're going to keep track of how much width we've used as we move along | 570 // We're going to keep track of how much width we've used as we move along |
567 // the bookmark bar. If we ever surpass the width of the bookmark bar, we'll | 571 // the bookmark bar. If we ever surpass the width of the bookmark bar, we'll |
568 // know that's the first hidden bookmark. | 572 // know that's the first hidden bookmark. |
569 int width_used = 0; | 573 int width_used = 0; |
570 // GTK appears to require one pixel of padding to the side of the first and | 574 // GTK appears to require one pixel of padding to the side of the first and |
571 // last buttons on the bar. | 575 // last buttons on the bar. |
572 // TODO(gideonwald): figure out the precise source of these extra two pixels | 576 // TODO(gideonwald): figure out the precise source of these extra two pixels |
573 // and make this calculation more reliable. | 577 // and make this calculation more reliable. |
574 int total_width = bookmark_toolbar_.get()->allocation.width - 2; | 578 GtkAllocation allocation; |
| 579 gtk_widget_get_allocation(bookmark_toolbar_.get(), &allocation); |
| 580 int total_width = allocation.width - 2; |
575 bool overflow = false; | 581 bool overflow = false; |
576 GtkRequisition requested_size_; | 582 GtkRequisition requested_size_; |
577 GList* toolbar_items = | 583 GList* toolbar_items = |
578 gtk_container_get_children(GTK_CONTAINER(bookmark_toolbar_.get())); | 584 gtk_container_get_children(GTK_CONTAINER(bookmark_toolbar_.get())); |
579 for (GList* iter = toolbar_items; iter; iter = g_list_next(iter)) { | 585 for (GList* iter = toolbar_items; iter; iter = g_list_next(iter)) { |
580 GtkWidget* tool_item = reinterpret_cast<GtkWidget*>(iter->data); | 586 GtkWidget* tool_item = reinterpret_cast<GtkWidget*>(iter->data); |
581 gtk_widget_size_request(tool_item, &requested_size_); | 587 gtk_widget_size_request(tool_item, &requested_size_); |
582 width_used += requested_size_.width; | 588 width_used += requested_size_.width; |
583 // |extra_space| is available if we can remove the chevron, which happens | 589 // |extra_space| is available if we can remove the chevron, which happens |
584 // only if there are no more potential overflow bookmarks after this one. | 590 // only if there are no more potential overflow bookmarks after this one. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 index); | 793 index); |
788 if (target_type == ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM)) { | 794 if (target_type == ui::GetAtomForTarget(ui::CHROME_BOOKMARK_ITEM)) { |
789 gdk_drag_status(context, GDK_ACTION_MOVE, time); | 795 gdk_drag_status(context, GDK_ACTION_MOVE, time); |
790 } else { | 796 } else { |
791 gdk_drag_status(context, GDK_ACTION_COPY, time); | 797 gdk_drag_status(context, GDK_ACTION_COPY, time); |
792 } | 798 } |
793 | 799 |
794 return TRUE; | 800 return TRUE; |
795 } | 801 } |
796 | 802 |
797 int BookmarkBarGtk::GetToolbarIndexForDragOverFolder( | 803 int BookmarkBarGtk::GetToolbarIndexForDragOverFolder(GtkWidget* button, |
798 GtkWidget* button, gint x) { | 804 gint x) { |
799 int margin = std::min(15, static_cast<int>(0.3 * button->allocation.width)); | 805 GtkAllocation allocation; |
800 if (x > margin && x < (button->allocation.width - margin)) | 806 gtk_widget_get_allocation(button, &allocation); |
| 807 |
| 808 int margin = std::min(15, static_cast<int>(0.3 * allocation.width)); |
| 809 if (x > margin && x < (allocation.width - margin)) |
801 return -1; | 810 return -1; |
802 | 811 |
803 gint index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()), | 812 gint index = gtk_toolbar_get_item_index(GTK_TOOLBAR(bookmark_toolbar_.get()), |
804 GTK_TOOL_ITEM(button->parent)); | 813 GTK_TOOL_ITEM(button->parent)); |
805 if (x > margin) | 814 if (x > margin) |
806 index++; | 815 index++; |
807 return index; | 816 return index; |
808 } | 817 } |
809 | 818 |
810 void BookmarkBarGtk::ClearToolbarDropHighlighting() { | 819 void BookmarkBarGtk::ClearToolbarDropHighlighting() { |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1212 GdkDragContext* context, | 1221 GdkDragContext* context, |
1213 gint x, | 1222 gint x, |
1214 gint y, | 1223 gint y, |
1215 guint time) { | 1224 guint time) { |
1216 gint index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(toolbar), x, y); | 1225 gint index = gtk_toolbar_get_drop_index(GTK_TOOLBAR(toolbar), x, y); |
1217 return ItemDraggedOverToolbar(context, index, time); | 1226 return ItemDraggedOverToolbar(context, index, time); |
1218 } | 1227 } |
1219 | 1228 |
1220 void BookmarkBarGtk::OnToolbarSizeAllocate(GtkWidget* widget, | 1229 void BookmarkBarGtk::OnToolbarSizeAllocate(GtkWidget* widget, |
1221 GtkAllocation* allocation) { | 1230 GtkAllocation* allocation) { |
1222 if (bookmark_toolbar_.get()->allocation.width == | 1231 if (allocation->width == last_allocation_width_) { |
1223 last_allocation_width_) { | |
1224 // If the width hasn't changed, then the visibility of the chevron | 1232 // If the width hasn't changed, then the visibility of the chevron |
1225 // doesn't need to change. This check prevents us from getting stuck in a | 1233 // doesn't need to change. This check prevents us from getting stuck in a |
1226 // loop where allocates are queued indefinitely while the visibility of | 1234 // loop where allocates are queued indefinitely while the visibility of |
1227 // overflow chevron toggles without actual resizes of the toolbar. | 1235 // overflow chevron toggles without actual resizes of the toolbar. |
1228 return; | 1236 return; |
1229 } | 1237 } |
1230 last_allocation_width_ = bookmark_toolbar_.get()->allocation.width; | 1238 last_allocation_width_ = allocation->width; |
1231 | 1239 |
1232 SetChevronState(); | 1240 SetChevronState(); |
1233 } | 1241 } |
1234 | 1242 |
1235 void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, | 1243 void BookmarkBarGtk::OnDragReceived(GtkWidget* widget, |
1236 GdkDragContext* context, | 1244 GdkDragContext* context, |
1237 gint x, gint y, | 1245 gint x, gint y, |
1238 GtkSelectionData* selection_data, | 1246 GtkSelectionData* selection_data, |
1239 guint target_type, guint time) { | 1247 guint target_type, guint time) { |
1240 if (!edit_bookmarks_enabled_.GetValue()) { | 1248 if (!edit_bookmarks_enabled_.GetValue()) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 gtk_util::DrawThemedToolbarBackground(widget, cr, event, tabstrip_origin, | 1385 gtk_util::DrawThemedToolbarBackground(widget, cr, event, tabstrip_origin, |
1378 theme_provider); | 1386 theme_provider); |
1379 | 1387 |
1380 cairo_destroy(cr); | 1388 cairo_destroy(cr); |
1381 } else { | 1389 } else { |
1382 gfx::Size tab_contents_size; | 1390 gfx::Size tab_contents_size; |
1383 if (!GetTabContentsSize(&tab_contents_size)) | 1391 if (!GetTabContentsSize(&tab_contents_size)) |
1384 return FALSE; | 1392 return FALSE; |
1385 gfx::CanvasSkiaPaint canvas(event, true); | 1393 gfx::CanvasSkiaPaint canvas(event, true); |
1386 | 1394 |
| 1395 GtkAllocation allocation; |
| 1396 gtk_widget_get_allocation(widget, &allocation); |
| 1397 |
1387 gfx::Rect area = GTK_WIDGET_NO_WINDOW(widget) ? | 1398 gfx::Rect area = GTK_WIDGET_NO_WINDOW(widget) ? |
1388 gfx::Rect(widget->allocation) : | 1399 gfx::Rect(allocation) : |
1389 gfx::Rect(0, 0, widget->allocation.width, widget->allocation.height); | 1400 gfx::Rect(0, 0, allocation.width, allocation.height); |
1390 NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas, | 1401 NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas, |
1391 area, tab_contents_size.height()); | 1402 area, tab_contents_size.height()); |
1392 } | 1403 } |
1393 | 1404 |
1394 return FALSE; // Propagate expose to children. | 1405 return FALSE; // Propagate expose to children. |
1395 } | 1406 } |
1396 | 1407 |
1397 void BookmarkBarGtk::OnEventBoxDestroy(GtkWidget* widget) { | 1408 void BookmarkBarGtk::OnEventBoxDestroy(GtkWidget* widget) { |
1398 if (model_) | 1409 if (model_) |
1399 model_->RemoveObserver(this); | 1410 model_->RemoveObserver(this); |
(...skipping 24 matching lines...) Expand all Loading... |
1424 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { | 1435 void BookmarkBarGtk::OnEditBookmarksEnabledChanged() { |
1425 GtkDestDefaults dest_defaults = | 1436 GtkDestDefaults dest_defaults = |
1426 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : | 1437 *edit_bookmarks_enabled_ ? GTK_DEST_DEFAULT_ALL : |
1427 GTK_DEST_DEFAULT_DROP; | 1438 GTK_DEST_DEFAULT_DROP; |
1428 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); | 1439 gtk_drag_dest_set(overflow_button_, dest_defaults, NULL, 0, kDragAction); |
1429 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, | 1440 gtk_drag_dest_set(other_bookmarks_button_, dest_defaults, |
1430 NULL, 0, kDragAction); | 1441 NULL, 0, kDragAction); |
1431 ui::SetDestTargetList(overflow_button_, kDestTargetList); | 1442 ui::SetDestTargetList(overflow_button_, kDestTargetList); |
1432 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); | 1443 ui::SetDestTargetList(other_bookmarks_button_, kDestTargetList); |
1433 } | 1444 } |
OLD | NEW |