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/views/bookmarks/bookmark_bar_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 browser_(browser), | 353 browser_(browser), |
354 infobar_visible_(false), | 354 infobar_visible_(false), |
355 throbbing_view_(NULL) { | 355 throbbing_view_(NULL) { |
356 if (profile->GetProfileSyncService()) { | 356 if (profile->GetProfileSyncService()) { |
357 // Obtain a pointer to the profile sync service and add our instance as an | 357 // Obtain a pointer to the profile sync service and add our instance as an |
358 // observer. | 358 // observer. |
359 sync_service_ = profile->GetProfileSyncService(); | 359 sync_service_ = profile->GetProfileSyncService(); |
360 sync_service_->AddObserver(this); | 360 sync_service_->AddObserver(this); |
361 } | 361 } |
362 | 362 |
363 SetID(VIEW_ID_BOOKMARK_BAR); | 363 set_id(VIEW_ID_BOOKMARK_BAR); |
364 Init(); | 364 Init(); |
365 SetProfile(profile); | 365 SetProfile(profile); |
366 | 366 |
367 size_animation_->Reset(IsAlwaysShown() ? 1 : 0); | 367 size_animation_->Reset(IsAlwaysShown() ? 1 : 0); |
368 } | 368 } |
369 | 369 |
370 BookmarkBarView::~BookmarkBarView() { | 370 BookmarkBarView::~BookmarkBarView() { |
371 NotifyModelChanged(); | 371 NotifyModelChanged(); |
372 if (model_) | 372 if (model_) |
373 model_->RemoveObserver(this); | 373 model_->RemoveObserver(this); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (index == GetBookmarkButtonCount()) { | 496 if (index == GetBookmarkButtonCount()) { |
497 if (index == 0) { | 497 if (index == 0) { |
498 x = kLeftMargin; | 498 x = kLeftMargin; |
499 } else { | 499 } else { |
500 x = GetBookmarkButton(index - 1)->x() + | 500 x = GetBookmarkButton(index - 1)->x() + |
501 GetBookmarkButton(index - 1)->width(); | 501 GetBookmarkButton(index - 1)->width(); |
502 } | 502 } |
503 } else { | 503 } else { |
504 x = GetBookmarkButton(index)->x(); | 504 x = GetBookmarkButton(index)->x(); |
505 } | 505 } |
506 if (GetBookmarkButtonCount() > 0 && GetBookmarkButton(0)->IsVisible()) { | 506 if (GetBookmarkButtonCount() > 0 && GetBookmarkButton(0)->visible()) { |
507 y = GetBookmarkButton(0)->y(); | 507 y = GetBookmarkButton(0)->y(); |
508 h = GetBookmarkButton(0)->height(); | 508 h = GetBookmarkButton(0)->height(); |
509 } | 509 } |
510 | 510 |
511 // Since the drop indicator is painted directly onto the canvas, we must | 511 // Since the drop indicator is painted directly onto the canvas, we must |
512 // make sure it is painted in the right location if the locale is RTL. | 512 // make sure it is painted in the right location if the locale is RTL. |
513 gfx::Rect indicator_bounds(x - kDropIndicatorWidth / 2, | 513 gfx::Rect indicator_bounds(x - kDropIndicatorWidth / 2, |
514 y, | 514 y, |
515 kDropIndicatorWidth, | 515 kDropIndicatorWidth, |
516 h); | 516 h); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 *start_index = 0; | 787 *start_index = 0; |
788 | 788 |
789 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) | 789 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) |
790 return NULL; | 790 return NULL; |
791 | 791 |
792 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); | 792 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); |
793 | 793 |
794 // Check the buttons first. | 794 // Check the buttons first. |
795 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 795 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
796 views::View* child = GetChildViewAt(i); | 796 views::View* child = GetChildViewAt(i); |
797 if (!child->IsVisible()) | 797 if (!child->visible()) |
798 break; | 798 break; |
799 if (child->bounds().Contains(adjusted_loc)) | 799 if (child->bounds().Contains(adjusted_loc)) |
800 return model_->GetBookmarkBarNode()->GetChild(i); | 800 return model_->GetBookmarkBarNode()->GetChild(i); |
801 } | 801 } |
802 | 802 |
803 // Then the overflow button. | 803 // Then the overflow button. |
804 if (overflow_button_->IsVisible() && | 804 if (overflow_button_->visible() && |
805 overflow_button_->bounds().Contains(adjusted_loc)) { | 805 overflow_button_->bounds().Contains(adjusted_loc)) { |
806 *start_index = GetFirstHiddenNodeIndex(); | 806 *start_index = GetFirstHiddenNodeIndex(); |
807 return model_->GetBookmarkBarNode(); | 807 return model_->GetBookmarkBarNode(); |
808 } | 808 } |
809 | 809 |
810 // And finally the other folder. | 810 // And finally the other folder. |
811 if (other_bookmarked_button_->IsVisible() && | 811 if (other_bookmarked_button_->visible() && |
812 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { | 812 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { |
813 return model_->other_node(); | 813 return model_->other_node(); |
814 } | 814 } |
815 | 815 |
816 return NULL; | 816 return NULL; |
817 } | 817 } |
818 | 818 |
819 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( | 819 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
820 const BookmarkNode* node) { | 820 const BookmarkNode* node) { |
821 if (node == model_->other_node()) | 821 if (node == model_->other_node()) |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 | 887 |
888 size_animation_.reset(new ui::SlideAnimation(this)); | 888 size_animation_.reset(new ui::SlideAnimation(this)); |
889 } | 889 } |
890 | 890 |
891 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 891 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
892 MenuButton* button = new BookmarkFolderButton( | 892 MenuButton* button = new BookmarkFolderButton( |
893 this, | 893 this, |
894 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)), | 894 UTF16ToWide(l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)), |
895 this, | 895 this, |
896 false); | 896 false); |
897 button->SetID(VIEW_ID_OTHER_BOOKMARKS); | 897 button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
898 button->SetIcon(GetFolderIcon()); | 898 button->SetIcon(GetFolderIcon()); |
899 button->SetContextMenuController(this); | 899 button->SetContextMenuController(this); |
900 button->set_tag(kOtherFolderButtonTag); | 900 button->set_tag(kOtherFolderButtonTag); |
901 button->SetAccessibleName( | 901 button->SetAccessibleName( |
902 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); | 902 l10n_util::GetStringUTF16(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); |
903 return button; | 903 return button; |
904 } | 904 } |
905 | 905 |
906 MenuButton* BookmarkBarView::CreateOverflowButton() { | 906 MenuButton* BookmarkBarView::CreateOverflowButton() { |
907 MenuButton* button = new OverFlowButton(this); | 907 MenuButton* button = new OverFlowButton(this); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1040 } | 1040 } |
1041 int index = model_->GetBookmarkBarNode()->GetIndexOf(node); | 1041 int index = model_->GetBookmarkBarNode()->GetIndexOf(node); |
1042 DCHECK_NE(-1, index); | 1042 DCHECK_NE(-1, index); |
1043 views::TextButton* button = GetBookmarkButton(index); | 1043 views::TextButton* button = GetBookmarkButton(index); |
1044 gfx::Size old_pref = button->GetPreferredSize(); | 1044 gfx::Size old_pref = button->GetPreferredSize(); |
1045 ConfigureButton(node, button); | 1045 ConfigureButton(node, button); |
1046 gfx::Size new_pref = button->GetPreferredSize(); | 1046 gfx::Size new_pref = button->GetPreferredSize(); |
1047 if (old_pref.width() != new_pref.width()) { | 1047 if (old_pref.width() != new_pref.width()) { |
1048 Layout(); | 1048 Layout(); |
1049 SchedulePaint(); | 1049 SchedulePaint(); |
1050 } else if (button->IsVisible()) { | 1050 } else if (button->visible()) { |
1051 button->SchedulePaint(); | 1051 button->SchedulePaint(); |
1052 } | 1052 } |
1053 } | 1053 } |
1054 | 1054 |
1055 void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, | 1055 void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, |
1056 const BookmarkNode* node) { | 1056 const BookmarkNode* node) { |
1057 NotifyModelChanged(); | 1057 NotifyModelChanged(); |
1058 if (node != model_->GetBookmarkBarNode()) | 1058 if (node != model_->GetBookmarkBarNode()) |
1059 return; // We only care about reordering of the bookmark bar node. | 1059 return; // We only care about reordering of the bookmark bar node. |
1060 | 1060 |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1254 button->SetIcon(GetFolderIcon()); | 1254 button->SetIcon(GetFolderIcon()); |
1255 ConfigureButton(node, button); | 1255 ConfigureButton(node, button); |
1256 return button; | 1256 return button; |
1257 } | 1257 } |
1258 } | 1258 } |
1259 | 1259 |
1260 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, | 1260 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
1261 views::TextButton* button) { | 1261 views::TextButton* button) { |
1262 button->SetText(UTF16ToWide(node->GetTitle())); | 1262 button->SetText(UTF16ToWide(node->GetTitle())); |
1263 button->SetAccessibleName(node->GetTitle()); | 1263 button->SetAccessibleName(node->GetTitle()); |
1264 button->SetID(VIEW_ID_BOOKMARK_BAR_ELEMENT); | 1264 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
1265 // We don't always have a theme provider (ui tests, for example). | 1265 // We don't always have a theme provider (ui tests, for example). |
1266 if (GetThemeProvider()) { | 1266 if (GetThemeProvider()) { |
1267 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1267 button->SetEnabledColor(GetThemeProvider()->GetColor( |
1268 ThemeService::COLOR_BOOKMARK_TEXT)); | 1268 ThemeService::COLOR_BOOKMARK_TEXT)); |
1269 } | 1269 } |
1270 | 1270 |
1271 button->ClearMaxTextSize(); | 1271 button->ClearMaxTextSize(); |
1272 button->SetContextMenuController(this); | 1272 button->SetContextMenuController(this); |
1273 button->SetDragController(this); | 1273 button->SetDragController(this); |
1274 if (node->is_url()) { | 1274 if (node->is_url()) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 // coordinates calculation works, we mirror the event's X coordinate if the | 1389 // coordinates calculation works, we mirror the event's X coordinate if the |
1390 // locale is RTL. | 1390 // locale is RTL. |
1391 int mirrored_x = GetMirroredXInView(event.x()); | 1391 int mirrored_x = GetMirroredXInView(event.x()); |
1392 | 1392 |
1393 *index = -1; | 1393 *index = -1; |
1394 *drop_on = false; | 1394 *drop_on = false; |
1395 *is_over_other = *is_over_overflow = false; | 1395 *is_over_other = *is_over_overflow = false; |
1396 | 1396 |
1397 bool found = false; | 1397 bool found = false; |
1398 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); | 1398 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); |
1399 if (other_bookmarked_button_->IsVisible() && other_delta_x >= 0 && | 1399 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && |
1400 other_delta_x < other_bookmarked_button_->width()) { | 1400 other_delta_x < other_bookmarked_button_->width()) { |
1401 // Mouse is over 'other' folder. | 1401 // Mouse is over 'other' folder. |
1402 *is_over_other = true; | 1402 *is_over_other = true; |
1403 *drop_on = true; | 1403 *drop_on = true; |
1404 found = true; | 1404 found = true; |
1405 } else if (!GetBookmarkButtonCount()) { | 1405 } else if (!GetBookmarkButtonCount()) { |
1406 // No bookmarks, accept the drop. | 1406 // No bookmarks, accept the drop. |
1407 *index = 0; | 1407 *index = 0; |
1408 int ops = data.GetFirstNode(profile_) | 1408 int ops = data.GetFirstNode(profile_) |
1409 ? ui::DragDropTypes::DRAG_MOVE | 1409 ? ui::DragDropTypes::DRAG_MOVE |
1410 : ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1410 : ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
1411 return bookmark_utils::PreferredDropOperation(event.source_operations(), | 1411 return bookmark_utils::PreferredDropOperation(event.source_operations(), |
1412 ops); | 1412 ops); |
1413 } | 1413 } |
1414 | 1414 |
1415 for (int i = 0; i < GetBookmarkButtonCount() && | 1415 for (int i = 0; i < GetBookmarkButtonCount() && |
1416 GetBookmarkButton(i)->IsVisible() && !found; i++) { | 1416 GetBookmarkButton(i)->visible() && !found; i++) { |
1417 views::TextButton* button = GetBookmarkButton(i); | 1417 views::TextButton* button = GetBookmarkButton(i); |
1418 int button_x = mirrored_x - button->x(); | 1418 int button_x = mirrored_x - button->x(); |
1419 int button_w = button->width(); | 1419 int button_w = button->width(); |
1420 if (button_x < button_w) { | 1420 if (button_x < button_w) { |
1421 found = true; | 1421 found = true; |
1422 const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i); | 1422 const BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(i); |
1423 if (node->is_folder()) { | 1423 if (node->is_folder()) { |
1424 if (button_x <= views::kDropBetweenPixels) { | 1424 if (button_x <= views::kDropBetweenPixels) { |
1425 *index = i; | 1425 *index = i; |
1426 } else if (button_x < button_w - views::kDropBetweenPixels) { | 1426 } else if (button_x < button_w - views::kDropBetweenPixels) { |
1427 *index = i; | 1427 *index = i; |
1428 *drop_on = true; | 1428 *drop_on = true; |
1429 } else { | 1429 } else { |
1430 *index = i + 1; | 1430 *index = i + 1; |
1431 } | 1431 } |
1432 } else if (button_x < button_w / 2) { | 1432 } else if (button_x < button_w / 2) { |
1433 *index = i; | 1433 *index = i; |
1434 } else { | 1434 } else { |
1435 *index = i + 1; | 1435 *index = i + 1; |
1436 } | 1436 } |
1437 break; | 1437 break; |
1438 } | 1438 } |
1439 } | 1439 } |
1440 | 1440 |
1441 if (!found) { | 1441 if (!found) { |
1442 if (overflow_button_->IsVisible()) { | 1442 if (overflow_button_->visible()) { |
1443 // Are we over the overflow button? | 1443 // Are we over the overflow button? |
1444 int overflow_delta_x = mirrored_x - overflow_button_->x(); | 1444 int overflow_delta_x = mirrored_x - overflow_button_->x(); |
1445 if (overflow_delta_x >= 0 && | 1445 if (overflow_delta_x >= 0 && |
1446 overflow_delta_x < overflow_button_->width()) { | 1446 overflow_delta_x < overflow_button_->width()) { |
1447 // Mouse is over overflow button. | 1447 // Mouse is over overflow button. |
1448 *index = GetFirstHiddenNodeIndex(); | 1448 *index = GetFirstHiddenNodeIndex(); |
1449 *is_over_overflow = true; | 1449 *is_over_overflow = true; |
1450 } else if (overflow_delta_x < 0) { | 1450 } else if (overflow_delta_x < 0) { |
1451 // Mouse is after the last visible button but before overflow button; | 1451 // Mouse is after the last visible button but before overflow button; |
1452 // use the last visible index. | 1452 // use the last visible index. |
1453 *index = GetFirstHiddenNodeIndex(); | 1453 *index = GetFirstHiddenNodeIndex(); |
1454 } else { | 1454 } else { |
1455 return ui::DragDropTypes::DRAG_NONE; | 1455 return ui::DragDropTypes::DRAG_NONE; |
1456 } | 1456 } |
1457 } else if (!other_bookmarked_button_->IsVisible() || | 1457 } else if (!other_bookmarked_button_->visible() || |
1458 mirrored_x < other_bookmarked_button_->x()) { | 1458 mirrored_x < other_bookmarked_button_->x()) { |
1459 // Mouse is after the last visible button but before more recently | 1459 // Mouse is after the last visible button but before more recently |
1460 // bookmarked; use the last visible index. | 1460 // bookmarked; use the last visible index. |
1461 *index = GetFirstHiddenNodeIndex(); | 1461 *index = GetFirstHiddenNodeIndex(); |
1462 } else { | 1462 } else { |
1463 return ui::DragDropTypes::DRAG_NONE; | 1463 return ui::DragDropTypes::DRAG_NONE; |
1464 } | 1464 } |
1465 } | 1465 } |
1466 | 1466 |
1467 if (*drop_on) { | 1467 if (*drop_on) { |
(...skipping 12 matching lines...) Expand all Loading... |
1480 return operation; | 1480 return operation; |
1481 } | 1481 } |
1482 return bookmark_utils::BookmarkDropOperation(profile_, event, data, | 1482 return bookmark_utils::BookmarkDropOperation(profile_, event, data, |
1483 model_->GetBookmarkBarNode(), | 1483 model_->GetBookmarkBarNode(), |
1484 *index); | 1484 *index); |
1485 } | 1485 } |
1486 | 1486 |
1487 int BookmarkBarView::GetFirstHiddenNodeIndex() { | 1487 int BookmarkBarView::GetFirstHiddenNodeIndex() { |
1488 const int bb_count = GetBookmarkButtonCount(); | 1488 const int bb_count = GetBookmarkButtonCount(); |
1489 for (int i = 0; i < bb_count; ++i) { | 1489 for (int i = 0; i < bb_count; ++i) { |
1490 if (!GetBookmarkButton(i)->IsVisible()) | 1490 if (!GetBookmarkButton(i)->visible()) |
1491 return i; | 1491 return i; |
1492 } | 1492 } |
1493 return bb_count; | 1493 return bb_count; |
1494 } | 1494 } |
1495 | 1495 |
1496 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, | 1496 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
1497 bool overflow_only) { | 1497 bool overflow_only) { |
1498 DCHECK(!throbbing_view_); | 1498 DCHECK(!throbbing_view_); |
1499 | 1499 |
1500 // Determine which visible button is showing the bookmark (or is an ancestor | 1500 // Determine which visible button is showing the bookmark (or is an ancestor |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1610 return; | 1610 return; |
1611 SkColor text_color = | 1611 SkColor text_color = |
1612 theme_provider->GetColor(ThemeService::COLOR_BOOKMARK_TEXT); | 1612 theme_provider->GetColor(ThemeService::COLOR_BOOKMARK_TEXT); |
1613 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1613 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1614 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1614 GetBookmarkButton(i)->SetEnabledColor(text_color); |
1615 other_bookmarked_button()->SetEnabledColor(text_color); | 1615 other_bookmarked_button()->SetEnabledColor(text_color); |
1616 } | 1616 } |
1617 | 1617 |
1618 void BookmarkBarView::UpdateOtherBookmarksVisibility() { | 1618 void BookmarkBarView::UpdateOtherBookmarksVisibility() { |
1619 bool has_other_children = model_->other_node()->child_count() > 0; | 1619 bool has_other_children = model_->other_node()->child_count() > 0; |
1620 if (has_other_children == other_bookmarked_button_->IsVisible()) | 1620 if (has_other_children == other_bookmarked_button_->visible()) |
1621 return; | 1621 return; |
1622 other_bookmarked_button_->SetVisible(has_other_children); | 1622 other_bookmarked_button_->SetVisible(has_other_children); |
1623 bookmarks_separator_view_->SetVisible(has_other_children); | 1623 bookmarks_separator_view_->SetVisible(has_other_children); |
1624 Layout(); | 1624 Layout(); |
1625 SchedulePaint(); | 1625 SchedulePaint(); |
1626 } | 1626 } |
1627 | 1627 |
1628 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { | 1628 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
1629 gfx::Size prefsize; | 1629 gfx::Size prefsize; |
1630 if (!parent() && !compute_bounds_only) | 1630 if (!parent() && !compute_bounds_only) |
(...skipping 16 matching lines...) Expand all Loading... |
1647 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); | 1647 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); |
1648 } else { | 1648 } else { |
1649 // For the attached appearance, pin the content to the bottom of the bar | 1649 // For the attached appearance, pin the content to the bottom of the bar |
1650 // when animating in/out, as shrinking its height instead looks weird. This | 1650 // when animating in/out, as shrinking its height instead looks weird. This |
1651 // also matches how we layout infobars. | 1651 // also matches how we layout infobars. |
1652 y += View::height() - kBarHeight; | 1652 y += View::height() - kBarHeight; |
1653 height += kBarHeight; | 1653 height += kBarHeight; |
1654 } | 1654 } |
1655 | 1655 |
1656 gfx::Size other_bookmarked_pref = | 1656 gfx::Size other_bookmarked_pref = |
1657 other_bookmarked_button_->IsVisible() ? | 1657 other_bookmarked_button_->visible() ? |
1658 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); | 1658 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); |
1659 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 1659 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
1660 gfx::Size bookmarks_separator_pref = | 1660 gfx::Size bookmarks_separator_pref = |
1661 bookmarks_separator_view_->GetPreferredSize(); | 1661 bookmarks_separator_view_->GetPreferredSize(); |
1662 | 1662 |
1663 int sync_error_total_width = 0; | 1663 int sync_error_total_width = 0; |
1664 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize(); | 1664 gfx::Size sync_error_button_pref = sync_error_button_->GetPreferredSize(); |
1665 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { | 1665 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { |
1666 sync_error_total_width += kButtonPadding + sync_error_button_pref.width(); | 1666 sync_error_total_width += kButtonPadding + sync_error_button_pref.width(); |
1667 } | 1667 } |
1668 int max_x = width - overflow_pref.width() - kButtonPadding - | 1668 int max_x = width - overflow_pref.width() - kButtonPadding - |
1669 bookmarks_separator_pref.width() - sync_error_total_width; | 1669 bookmarks_separator_pref.width() - sync_error_total_width; |
1670 if (other_bookmarked_button_->IsVisible()) | 1670 if (other_bookmarked_button_->visible()) |
1671 max_x -= other_bookmarked_pref.width() + kButtonPadding; | 1671 max_x -= other_bookmarked_pref.width() + kButtonPadding; |
1672 | 1672 |
1673 // Next, layout out the buttons. Any buttons that are placed beyond the | 1673 // Next, layout out the buttons. Any buttons that are placed beyond the |
1674 // visible region and made invisible. | 1674 // visible region and made invisible. |
1675 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { | 1675 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { |
1676 gfx::Size pref = instructions_->GetPreferredSize(); | 1676 gfx::Size pref = instructions_->GetPreferredSize(); |
1677 if (!compute_bounds_only) { | 1677 if (!compute_bounds_only) { |
1678 instructions_->SetBounds( | 1678 instructions_->SetBounds( |
1679 x + kInstructionsPadding, y, | 1679 x + kInstructionsPadding, y, |
1680 std::min(static_cast<int>(pref.width()), | 1680 std::min(static_cast<int>(pref.width()), |
(...skipping 13 matching lines...) Expand all Loading... |
1694 child->SetVisible(next_x < max_x); | 1694 child->SetVisible(next_x < max_x); |
1695 child->SetBounds(x, y, pref.width(), height); | 1695 child->SetBounds(x, y, pref.width(), height); |
1696 } | 1696 } |
1697 x = next_x; | 1697 x = next_x; |
1698 } | 1698 } |
1699 } | 1699 } |
1700 | 1700 |
1701 // Layout the right side of the bar. | 1701 // Layout the right side of the bar. |
1702 const bool all_visible = | 1702 const bool all_visible = |
1703 (GetBookmarkButtonCount() == 0 || | 1703 (GetBookmarkButtonCount() == 0 || |
1704 GetChildViewAt(GetBookmarkButtonCount() - 1)->IsVisible()); | 1704 GetChildViewAt(GetBookmarkButtonCount() - 1)->visible()); |
1705 | 1705 |
1706 // Layout the right side buttons. | 1706 // Layout the right side buttons. |
1707 if (!compute_bounds_only) | 1707 if (!compute_bounds_only) |
1708 x = max_x + kButtonPadding; | 1708 x = max_x + kButtonPadding; |
1709 else | 1709 else |
1710 x += kButtonPadding; | 1710 x += kButtonPadding; |
1711 | 1711 |
1712 // The overflow button. | 1712 // The overflow button. |
1713 if (!compute_bounds_only) { | 1713 if (!compute_bounds_only) { |
1714 overflow_button_->SetBounds(x, y, overflow_pref.width(), height); | 1714 overflow_button_->SetBounds(x, y, overflow_pref.width(), height); |
1715 overflow_button_->SetVisible(!all_visible); | 1715 overflow_button_->SetVisible(!all_visible); |
1716 } | 1716 } |
1717 x += overflow_pref.width(); | 1717 x += overflow_pref.width(); |
1718 | 1718 |
1719 // Separator. | 1719 // Separator. |
1720 if (bookmarks_separator_view_->IsVisible()) { | 1720 if (bookmarks_separator_view_->visible()) { |
1721 if (!compute_bounds_only) { | 1721 if (!compute_bounds_only) { |
1722 bookmarks_separator_view_->SetBounds(x, | 1722 bookmarks_separator_view_->SetBounds(x, |
1723 y - top_margin, | 1723 y - top_margin, |
1724 bookmarks_separator_pref.width(), | 1724 bookmarks_separator_pref.width(), |
1725 height + top_margin + kBottomMargin - | 1725 height + top_margin + kBottomMargin - |
1726 separator_margin); | 1726 separator_margin); |
1727 } | 1727 } |
1728 | 1728 |
1729 x += bookmarks_separator_pref.width(); | 1729 x += bookmarks_separator_pref.width(); |
1730 } | 1730 } |
1731 | 1731 |
1732 // The other bookmarks button. | 1732 // The other bookmarks button. |
1733 if (other_bookmarked_button_->IsVisible()) { | 1733 if (other_bookmarked_button_->visible()) { |
1734 if (!compute_bounds_only) { | 1734 if (!compute_bounds_only) { |
1735 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), | 1735 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), |
1736 height); | 1736 height); |
1737 } | 1737 } |
1738 x += other_bookmarked_pref.width() + kButtonPadding; | 1738 x += other_bookmarked_pref.width() + kButtonPadding; |
1739 } | 1739 } |
1740 | 1740 |
1741 // Set the real bounds of the sync error button only if it needs to appear on | 1741 // Set the real bounds of the sync error button only if it needs to appear on |
1742 // the bookmarks bar. | 1742 // the bookmarks bar. |
1743 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { | 1743 if (sync_ui_util::ShouldShowSyncErrorButton(sync_service_)) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 // The tooltip is the only way we have to display text explaining the error | 1780 // The tooltip is the only way we have to display text explaining the error |
1781 // to the user. | 1781 // to the user. |
1782 sync_error_button->SetTooltipText( | 1782 sync_error_button->SetTooltipText( |
1783 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); | 1783 UTF16ToWide(l10n_util::GetStringUTF16(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC))); |
1784 sync_error_button->SetAccessibleName( | 1784 sync_error_button->SetAccessibleName( |
1785 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); | 1785 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); |
1786 sync_error_button->SetIcon( | 1786 sync_error_button->SetIcon( |
1787 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); | 1787 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); |
1788 return sync_error_button; | 1788 return sync_error_button; |
1789 } | 1789 } |
OLD | NEW |