OLD | NEW |
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/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 <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // Tag for the 'Apps Shortcut' button. | 150 // Tag for the 'Apps Shortcut' button. |
151 static const int kAppsShortcutButtonTag = 2; | 151 static const int kAppsShortcutButtonTag = 2; |
152 | 152 |
153 // Preferred padding between text and edge. | 153 // Preferred padding between text and edge. |
154 static const int kButtonPaddingHorizontal = 6; | 154 static const int kButtonPaddingHorizontal = 6; |
155 static const int kButtonPaddingVertical = 4; | 155 static const int kButtonPaddingVertical = 4; |
156 | 156 |
157 // Tag for the 'Managed bookmarks' button. | 157 // Tag for the 'Managed bookmarks' button. |
158 static const int kManagedFolderButtonTag = 3; | 158 static const int kManagedFolderButtonTag = 3; |
| 159 // Tag for the 'Supervised bookmarks' button. |
| 160 static const int kSupervisedFolderButtonTag = 4; |
159 | 161 |
160 #if !defined(OS_WIN) | 162 #if !defined(OS_WIN) |
161 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; | 163 static const gfx::ElideBehavior kElideBehavior = gfx::FADE_TAIL; |
162 #else | 164 #else |
163 // Windows fade eliding causes text to darken; see http://crbug.com/388084 | 165 // Windows fade eliding causes text to darken; see http://crbug.com/388084 |
164 static const gfx::ElideBehavior kElideBehavior = gfx::ELIDE_TAIL; | 166 static const gfx::ElideBehavior kElideBehavior = gfx::ELIDE_TAIL; |
165 #endif | 167 #endif |
166 | 168 |
167 namespace { | 169 namespace { |
168 | 170 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 // static | 495 // static |
494 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; | 496 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; |
495 | 497 |
496 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 498 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
497 : page_navigator_(NULL), | 499 : page_navigator_(NULL), |
498 client_(NULL), | 500 client_(NULL), |
499 bookmark_menu_(NULL), | 501 bookmark_menu_(NULL), |
500 bookmark_drop_menu_(NULL), | 502 bookmark_drop_menu_(NULL), |
501 other_bookmarks_button_(NULL), | 503 other_bookmarks_button_(NULL), |
502 managed_bookmarks_button_(NULL), | 504 managed_bookmarks_button_(NULL), |
| 505 supervised_bookmarks_button_(NULL), |
503 apps_page_shortcut_(NULL), | 506 apps_page_shortcut_(NULL), |
504 overflow_button_(NULL), | 507 overflow_button_(NULL), |
505 instructions_(NULL), | 508 instructions_(NULL), |
506 bookmarks_separator_view_(NULL), | 509 bookmarks_separator_view_(NULL), |
507 browser_(browser), | 510 browser_(browser), |
508 browser_view_(browser_view), | 511 browser_view_(browser_view), |
509 infobar_visible_(false), | 512 infobar_visible_(false), |
510 throbbing_view_(NULL), | 513 throbbing_view_(NULL), |
511 bookmark_bar_state_(BookmarkBar::SHOW), | 514 bookmark_bar_state_(BookmarkBar::SHOW), |
512 animating_detached_(false), | 515 animating_detached_(false), |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 return NULL; | 597 return NULL; |
595 | 598 |
596 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); | 599 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); |
597 | 600 |
598 // Check the managed button first. | 601 // Check the managed button first. |
599 if (managed_bookmarks_button_->visible() && | 602 if (managed_bookmarks_button_->visible() && |
600 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 603 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
601 return client_->managed_node(); | 604 return client_->managed_node(); |
602 } | 605 } |
603 | 606 |
| 607 // Then check the supervised button. |
| 608 if (supervised_bookmarks_button_->visible() && |
| 609 supervised_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
| 610 return client_->supervised_node(); |
| 611 } |
| 612 |
604 // Then check the bookmark buttons. | 613 // Then check the bookmark buttons. |
605 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 614 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
606 views::View* child = child_at(i); | 615 views::View* child = child_at(i); |
607 if (!child->visible()) | 616 if (!child->visible()) |
608 break; | 617 break; |
609 if (child->bounds().Contains(adjusted_loc)) | 618 if (child->bounds().Contains(adjusted_loc)) |
610 return model_->bookmark_bar_node()->GetChild(i); | 619 return model_->bookmark_bar_node()->GetChild(i); |
611 } | 620 } |
612 | 621 |
613 // Then the overflow button. | 622 // Then the overflow button. |
614 if (overflow_button_->visible() && | 623 if (overflow_button_->visible() && |
615 overflow_button_->bounds().Contains(adjusted_loc)) { | 624 overflow_button_->bounds().Contains(adjusted_loc)) { |
616 *model_start_index = GetFirstHiddenNodeIndex(); | 625 *model_start_index = GetFirstHiddenNodeIndex(); |
617 return model_->bookmark_bar_node(); | 626 return model_->bookmark_bar_node(); |
618 } | 627 } |
619 | 628 |
620 // And finally the other folder. | 629 // And finally the other folder. |
621 if (other_bookmarks_button_->visible() && | 630 if (other_bookmarks_button_->visible() && |
622 other_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 631 other_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
623 return model_->other_node(); | 632 return model_->other_node(); |
624 } | 633 } |
625 | 634 |
626 return NULL; | 635 return NULL; |
627 } | 636 } |
628 | 637 |
629 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( | 638 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
630 const BookmarkNode* node) { | 639 const BookmarkNode* node) { |
631 if (node == client_->managed_node()) | 640 if (node == client_->managed_node()) |
632 return managed_bookmarks_button_; | 641 return managed_bookmarks_button_; |
| 642 if (node == client_->supervised_node()) |
| 643 return supervised_bookmarks_button_; |
633 if (node == model_->other_node()) | 644 if (node == model_->other_node()) |
634 return other_bookmarks_button_; | 645 return other_bookmarks_button_; |
635 if (node == model_->bookmark_bar_node()) | 646 if (node == model_->bookmark_bar_node()) |
636 return overflow_button_; | 647 return overflow_button_; |
637 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 648 int index = model_->bookmark_bar_node()->GetIndexOf(node); |
638 if (index == -1 || !node->is_folder()) | 649 if (index == -1 || !node->is_folder()) |
639 return NULL; | 650 return NULL; |
640 return static_cast<views::MenuButton*>(child_at(index)); | 651 return static_cast<views::MenuButton*>(child_at(index)); |
641 } | 652 } |
642 | 653 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 popup_model()->IsOpen()) { | 777 popup_model()->IsOpen()) { |
767 return false; | 778 return false; |
768 } | 779 } |
769 return true; | 780 return true; |
770 } | 781 } |
771 | 782 |
772 gfx::Size BookmarkBarView::GetMinimumSize() const { | 783 gfx::Size BookmarkBarView::GetMinimumSize() const { |
773 // The minimum width of the bookmark bar should at least contain the overflow | 784 // The minimum width of the bookmark bar should at least contain the overflow |
774 // button, by which one can access all the Bookmark Bar items, and the "Other | 785 // button, by which one can access all the Bookmark Bar items, and the "Other |
775 // Bookmarks" folder, along with appropriate margins and button padding. | 786 // Bookmarks" folder, along with appropriate margins and button padding. |
776 // It should also contain the Managed Bookmarks folder, if it's visible. | 787 // It should also contain the Managed and/or Supervised Bookmarks folders, |
| 788 // if they are visible. |
777 int width = kLeftMargin; | 789 int width = kLeftMargin; |
778 | 790 |
779 int height = chrome::kBookmarkBarHeight; | 791 int height = chrome::kBookmarkBarHeight; |
780 if (IsDetached()) { | 792 if (IsDetached()) { |
781 double current_state = 1 - size_animation_->GetCurrentValue(); | 793 double current_state = 1 - size_animation_->GetCurrentValue(); |
782 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); | 794 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); |
783 height += static_cast<int>( | 795 height += static_cast<int>( |
784 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 796 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * |
785 current_state); | 797 current_state); |
786 } | 798 } |
787 | 799 |
788 if (managed_bookmarks_button_->visible()) { | 800 if (managed_bookmarks_button_->visible()) { |
789 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); | 801 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
790 width += size.width() + kButtonPadding; | 802 width += size.width() + kButtonPadding; |
791 } | 803 } |
| 804 if (supervised_bookmarks_button_->visible()) { |
| 805 gfx::Size size = supervised_bookmarks_button_->GetPreferredSize(); |
| 806 width += size.width() + kButtonPadding; |
| 807 } |
792 if (other_bookmarks_button_->visible()) { | 808 if (other_bookmarks_button_->visible()) { |
793 gfx::Size size = other_bookmarks_button_->GetPreferredSize(); | 809 gfx::Size size = other_bookmarks_button_->GetPreferredSize(); |
794 width += size.width() + kButtonPadding; | 810 width += size.width() + kButtonPadding; |
795 } | 811 } |
796 if (overflow_button_->visible()) { | 812 if (overflow_button_->visible()) { |
797 gfx::Size size = overflow_button_->GetPreferredSize(); | 813 gfx::Size size = overflow_button_->GetPreferredSize(); |
798 width += size.width() + kButtonPadding; | 814 width += size.width() + kButtonPadding; |
799 } | 815 } |
800 if (bookmarks_separator_view_->visible()) { | 816 if (bookmarks_separator_view_->visible()) { |
801 gfx::Size size = bookmarks_separator_view_->GetPreferredSize(); | 817 gfx::Size size = bookmarks_separator_view_->GetPreferredSize(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 | 865 |
850 // Start with the apps page shortcut button. | 866 // Start with the apps page shortcut button. |
851 if (apps_page_shortcut_->visible()) { | 867 if (apps_page_shortcut_->visible()) { |
852 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), | 868 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), |
853 height); | 869 height); |
854 x += apps_page_shortcut_pref.width() + kButtonPadding; | 870 x += apps_page_shortcut_pref.width() + kButtonPadding; |
855 } | 871 } |
856 | 872 |
857 // Then comes the managed bookmarks folder, if visible. | 873 // Then comes the managed bookmarks folder, if visible. |
858 if (managed_bookmarks_button_->visible()) { | 874 if (managed_bookmarks_button_->visible()) { |
859 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? | 875 gfx::Size managed_bookmarks_pref = |
860 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); | 876 managed_bookmarks_button_->GetPreferredSize(); |
861 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), | 877 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), |
862 height); | 878 height); |
863 x += managed_bookmarks_pref.width() + kButtonPadding; | 879 x += managed_bookmarks_pref.width() + kButtonPadding; |
864 } | 880 } |
865 | 881 |
| 882 // Then the supervised bookmarks folder, if visible. |
| 883 if (supervised_bookmarks_button_->visible()) { |
| 884 gfx::Size supervised_bookmarks_pref = |
| 885 supervised_bookmarks_button_->GetPreferredSize(); |
| 886 supervised_bookmarks_button_->SetBounds( |
| 887 x, y, supervised_bookmarks_pref.width(), height); |
| 888 x += supervised_bookmarks_pref.width() + kButtonPadding; |
| 889 } |
| 890 |
866 const bool show_instructions = | 891 const bool show_instructions = |
867 model_ && model_->loaded() && | 892 model_ && model_->loaded() && |
868 model_->bookmark_bar_node()->child_count() == 0; | 893 model_->bookmark_bar_node()->child_count() == 0; |
869 instructions_->SetVisible(show_instructions); | 894 instructions_->SetVisible(show_instructions); |
870 if (show_instructions) { | 895 if (show_instructions) { |
871 gfx::Size pref = instructions_->GetPreferredSize(); | 896 gfx::Size pref = instructions_->GetPreferredSize(); |
872 instructions_->SetBounds( | 897 instructions_->SetBounds( |
873 x + kInstructionsPadding, y, | 898 x + kInstructionsPadding, y, |
874 std::min(static_cast<int>(pref.width()), | 899 std::min(static_cast<int>(pref.width()), |
875 max_x - x), | 900 max_x - x), |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 // There should be no buttons. If non-zero it means Load was invoked more than | 1224 // There should be no buttons. If non-zero it means Load was invoked more than |
1200 // once, or we didn't properly clear things. Either of which shouldn't happen. | 1225 // once, or we didn't properly clear things. Either of which shouldn't happen. |
1201 // The actual bookmark buttons are added from Layout(). | 1226 // The actual bookmark buttons are added from Layout(). |
1202 DCHECK_EQ(0, GetBookmarkButtonCount()); | 1227 DCHECK_EQ(0, GetBookmarkButtonCount()); |
1203 DCHECK(model->other_node()); | 1228 DCHECK(model->other_node()); |
1204 other_bookmarks_button_->SetAccessibleName(model->other_node()->GetTitle()); | 1229 other_bookmarks_button_->SetAccessibleName(model->other_node()->GetTitle()); |
1205 other_bookmarks_button_->SetText(model->other_node()->GetTitle()); | 1230 other_bookmarks_button_->SetText(model->other_node()->GetTitle()); |
1206 managed_bookmarks_button_->SetAccessibleName( | 1231 managed_bookmarks_button_->SetAccessibleName( |
1207 client_->managed_node()->GetTitle()); | 1232 client_->managed_node()->GetTitle()); |
1208 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1233 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
| 1234 supervised_bookmarks_button_->SetAccessibleName( |
| 1235 client_->supervised_node()->GetTitle()); |
| 1236 supervised_bookmarks_button_->SetText(client_->supervised_node()->GetTitle()); |
1209 UpdateColors(); | 1237 UpdateColors(); |
1210 UpdateOtherAndManagedButtonsVisibility(); | 1238 UpdateOtherAndManagedButtonsVisibility(); |
1211 other_bookmarks_button_->SetEnabled(true); | 1239 other_bookmarks_button_->SetEnabled(true); |
1212 managed_bookmarks_button_->SetEnabled(true); | 1240 managed_bookmarks_button_->SetEnabled(true); |
| 1241 supervised_bookmarks_button_->SetEnabled(true); |
1213 LayoutAndPaint(); | 1242 LayoutAndPaint(); |
1214 } | 1243 } |
1215 | 1244 |
1216 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1245 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
1217 NOTREACHED(); | 1246 NOTREACHED(); |
1218 // Do minimal cleanup, presumably we'll be deleted shortly. | 1247 // Do minimal cleanup, presumably we'll be deleted shortly. |
1219 model_->RemoveObserver(this); | 1248 model_->RemoveObserver(this); |
1220 model_ = NULL; | 1249 model_ = NULL; |
1221 } | 1250 } |
1222 | 1251 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1377 | 1406 |
1378 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1407 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
1379 const gfx::Point& point) { | 1408 const gfx::Point& point) { |
1380 const BookmarkNode* node; | 1409 const BookmarkNode* node; |
1381 | 1410 |
1382 int start_index = 0; | 1411 int start_index = 0; |
1383 if (view == other_bookmarks_button_) { | 1412 if (view == other_bookmarks_button_) { |
1384 node = model_->other_node(); | 1413 node = model_->other_node(); |
1385 } else if (view == managed_bookmarks_button_) { | 1414 } else if (view == managed_bookmarks_button_) { |
1386 node = client_->managed_node(); | 1415 node = client_->managed_node(); |
| 1416 } else if (view == supervised_bookmarks_button_) { |
| 1417 node = client_->supervised_node(); |
1387 } else if (view == overflow_button_) { | 1418 } else if (view == overflow_button_) { |
1388 node = model_->bookmark_bar_node(); | 1419 node = model_->bookmark_bar_node(); |
1389 start_index = GetFirstHiddenNodeIndex(); | 1420 start_index = GetFirstHiddenNodeIndex(); |
1390 } else { | 1421 } else { |
1391 int button_index = GetIndexOf(view); | 1422 int button_index = GetIndexOf(view); |
1392 DCHECK_NE(-1, button_index); | 1423 DCHECK_NE(-1, button_index); |
1393 node = model_->bookmark_bar_node()->GetChild(button_index); | 1424 node = model_->bookmark_bar_node()->GetChild(button_index); |
1394 } | 1425 } |
1395 | 1426 |
1396 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1427 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
(...skipping 17 matching lines...) Expand all Loading... |
1414 page_navigator_->OpenURL(params); | 1445 page_navigator_->OpenURL(params); |
1415 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1446 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
1416 return; | 1447 return; |
1417 } | 1448 } |
1418 | 1449 |
1419 const BookmarkNode* node; | 1450 const BookmarkNode* node; |
1420 if (sender->tag() == kOtherFolderButtonTag) { | 1451 if (sender->tag() == kOtherFolderButtonTag) { |
1421 node = model_->other_node(); | 1452 node = model_->other_node(); |
1422 } else if (sender->tag() == kManagedFolderButtonTag) { | 1453 } else if (sender->tag() == kManagedFolderButtonTag) { |
1423 node = client_->managed_node(); | 1454 node = client_->managed_node(); |
| 1455 } else if (sender->tag() == kSupervisedFolderButtonTag) { |
| 1456 node = client_->supervised_node(); |
1424 } else { | 1457 } else { |
1425 int index = GetIndexOf(sender); | 1458 int index = GetIndexOf(sender); |
1426 DCHECK_NE(-1, index); | 1459 DCHECK_NE(-1, index); |
1427 node = model_->bookmark_bar_node()->GetChild(index); | 1460 node = model_->bookmark_bar_node()->GetChild(index); |
1428 } | 1461 } |
1429 DCHECK(page_navigator_); | 1462 DCHECK(page_navigator_); |
1430 | 1463 |
1431 if (node->is_url()) { | 1464 if (node->is_url()) { |
1432 RecordAppLaunch(browser_->profile(), node->url()); | 1465 RecordAppLaunch(browser_->profile(), node->url()); |
1433 OpenURLParams params( | 1466 OpenURLParams params( |
(...skipping 19 matching lines...) Expand all Loading... |
1453 const BookmarkNode* parent = NULL; | 1486 const BookmarkNode* parent = NULL; |
1454 std::vector<const BookmarkNode*> nodes; | 1487 std::vector<const BookmarkNode*> nodes; |
1455 if (source == other_bookmarks_button_) { | 1488 if (source == other_bookmarks_button_) { |
1456 parent = model_->other_node(); | 1489 parent = model_->other_node(); |
1457 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1490 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
1458 // sure the user can't edit/delete the node in this case. | 1491 // sure the user can't edit/delete the node in this case. |
1459 nodes.push_back(parent); | 1492 nodes.push_back(parent); |
1460 } else if (source == managed_bookmarks_button_) { | 1493 } else if (source == managed_bookmarks_button_) { |
1461 parent = client_->managed_node(); | 1494 parent = client_->managed_node(); |
1462 nodes.push_back(parent); | 1495 nodes.push_back(parent); |
| 1496 } else if (source == supervised_bookmarks_button_) { |
| 1497 parent = client_->supervised_node(); |
| 1498 nodes.push_back(parent); |
1463 } else if (source != this && source != apps_page_shortcut_) { | 1499 } else if (source != this && source != apps_page_shortcut_) { |
1464 // User clicked on one of the bookmark buttons, find which one they | 1500 // User clicked on one of the bookmark buttons, find which one they |
1465 // clicked on, except for the apps page shortcut, which must behave as if | 1501 // clicked on, except for the apps page shortcut, which must behave as if |
1466 // the user clicked on the bookmark bar background. | 1502 // the user clicked on the bookmark bar background. |
1467 int bookmark_button_index = GetIndexOf(source); | 1503 int bookmark_button_index = GetIndexOf(source); |
1468 DCHECK(bookmark_button_index != -1 && | 1504 DCHECK(bookmark_button_index != -1 && |
1469 bookmark_button_index < GetBookmarkButtonCount()); | 1505 bookmark_button_index < GetBookmarkButtonCount()); |
1470 const BookmarkNode* node = | 1506 const BookmarkNode* node = |
1471 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1507 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
1472 nodes.push_back(node); | 1508 nodes.push_back(node); |
(...skipping 26 matching lines...) Expand all Loading... |
1499 other_bookmarks_button_ = CreateOtherBookmarksButton(); | 1535 other_bookmarks_button_ = CreateOtherBookmarksButton(); |
1500 // We'll re-enable when the model is loaded. | 1536 // We'll re-enable when the model is loaded. |
1501 other_bookmarks_button_->SetEnabled(false); | 1537 other_bookmarks_button_->SetEnabled(false); |
1502 AddChildView(other_bookmarks_button_); | 1538 AddChildView(other_bookmarks_button_); |
1503 | 1539 |
1504 managed_bookmarks_button_ = CreateManagedBookmarksButton(); | 1540 managed_bookmarks_button_ = CreateManagedBookmarksButton(); |
1505 // Also re-enabled when the model is loaded. | 1541 // Also re-enabled when the model is loaded. |
1506 managed_bookmarks_button_->SetEnabled(false); | 1542 managed_bookmarks_button_->SetEnabled(false); |
1507 AddChildView(managed_bookmarks_button_); | 1543 AddChildView(managed_bookmarks_button_); |
1508 | 1544 |
| 1545 supervised_bookmarks_button_ = CreateSupervisedBookmarksButton(); |
| 1546 // Also re-enabled when the model is loaded. |
| 1547 supervised_bookmarks_button_->SetEnabled(false); |
| 1548 AddChildView(supervised_bookmarks_button_); |
| 1549 |
1509 apps_page_shortcut_ = CreateAppsPageShortcutButton(); | 1550 apps_page_shortcut_ = CreateAppsPageShortcutButton(); |
1510 AddChildView(apps_page_shortcut_); | 1551 AddChildView(apps_page_shortcut_); |
1511 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | 1552 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
1512 profile_pref_registrar_.Add( | 1553 profile_pref_registrar_.Add( |
1513 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | 1554 bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
1514 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged, | 1555 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged, |
1515 base::Unretained(this))); | 1556 base::Unretained(this))); |
1516 profile_pref_registrar_.Add( | 1557 profile_pref_registrar_.Add( |
1517 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar, | 1558 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar, |
1518 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged, | 1559 base::Bind(&BookmarkBarView::OnShowManagedBookmarksPrefChanged, |
(...skipping 18 matching lines...) Expand all Loading... |
1537 if (model_) { | 1578 if (model_) { |
1538 model_->AddObserver(this); | 1579 model_->AddObserver(this); |
1539 if (model_->loaded()) | 1580 if (model_->loaded()) |
1540 BookmarkModelLoaded(model_, false); | 1581 BookmarkModelLoaded(model_, false); |
1541 // else case: we'll receive notification back from the BookmarkModel when | 1582 // else case: we'll receive notification back from the BookmarkModel when |
1542 // done loading, then we'll populate the bar. | 1583 // done loading, then we'll populate the bar. |
1543 } | 1584 } |
1544 } | 1585 } |
1545 | 1586 |
1546 int BookmarkBarView::GetBookmarkButtonCount() const { | 1587 int BookmarkBarView::GetBookmarkButtonCount() const { |
1547 // We contain six non-bookmark button views: managed bookmarks, | 1588 // We contain seven non-bookmark button views: managed bookmarks, supervised |
1548 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, | 1589 // bookmarks, other bookmarks, bookmarks separator, chevrons (for overflow), |
1549 // and the instruction label. | 1590 // apps page, and the instruction label. |
1550 return child_count() - 6; | 1591 return child_count() - 7; |
1551 } | 1592 } |
1552 | 1593 |
1553 views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) { | 1594 views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) { |
1554 // CHECK as otherwise we may do the wrong cast. | 1595 // CHECK as otherwise we may do the wrong cast. |
1555 CHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1596 CHECK(index >= 0 && index < GetBookmarkButtonCount()); |
1556 return static_cast<views::LabelButton*>(child_at(index)); | 1597 return static_cast<views::LabelButton*>(child_at(index)); |
1557 } | 1598 } |
1558 | 1599 |
1559 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { | 1600 BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { |
1560 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : | 1601 return IsDetached() ? BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR : |
(...skipping 26 matching lines...) Expand all Loading... |
1587 MenuButton* button = | 1628 MenuButton* button = |
1588 new BookmarkFolderButton(this, base::string16(), this, false); | 1629 new BookmarkFolderButton(this, base::string16(), this, false); |
1589 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); | 1630 button->set_id(VIEW_ID_MANAGED_BOOKMARKS); |
1590 button->SetImage(views::Button::STATE_NORMAL, | 1631 button->SetImage(views::Button::STATE_NORMAL, |
1591 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED)); | 1632 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_MANAGED)); |
1592 button->set_context_menu_controller(this); | 1633 button->set_context_menu_controller(this); |
1593 button->set_tag(kManagedFolderButtonTag); | 1634 button->set_tag(kManagedFolderButtonTag); |
1594 return button; | 1635 return button; |
1595 } | 1636 } |
1596 | 1637 |
| 1638 MenuButton* BookmarkBarView::CreateSupervisedBookmarksButton() { |
| 1639 // Title is set in Loaded. |
| 1640 MenuButton* button = |
| 1641 new BookmarkFolderButton(this, base::string16(), this, false); |
| 1642 button->set_id(VIEW_ID_SUPERVISED_BOOKMARKS); |
| 1643 button->SetImage(views::Button::STATE_NORMAL, |
| 1644 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER_SUPERVISED)); |
| 1645 button->set_context_menu_controller(this); |
| 1646 button->set_tag(kSupervisedFolderButtonTag); |
| 1647 return button; |
| 1648 } |
| 1649 |
1597 MenuButton* BookmarkBarView::CreateOverflowButton() { | 1650 MenuButton* BookmarkBarView::CreateOverflowButton() { |
1598 MenuButton* button = new OverFlowButton(this); | 1651 MenuButton* button = new OverFlowButton(this); |
1599 button->SetImage(views::Button::STATE_NORMAL, | 1652 button->SetImage(views::Button::STATE_NORMAL, |
1600 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 1653 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
1601 | 1654 |
1602 // The overflow button's image contains an arrow and therefore it is a | 1655 // The overflow button's image contains an arrow and therefore it is a |
1603 // direction sensitive image and we need to flip it if the UI layout is | 1656 // direction sensitive image and we need to flip it if the UI layout is |
1604 // right-to-left. | 1657 // right-to-left. |
1605 // | 1658 // |
1606 // By default, menu buttons are not flipped because they generally contain | 1659 // By default, menu buttons are not flipped because they generally contain |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1707 | 1760 |
1708 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1761 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
1709 const BookmarkNode* node) { | 1762 const BookmarkNode* node) { |
1710 if (node == client_->managed_node()) { | 1763 if (node == client_->managed_node()) { |
1711 // The managed node may have its title updated. | 1764 // The managed node may have its title updated. |
1712 managed_bookmarks_button_->SetAccessibleName( | 1765 managed_bookmarks_button_->SetAccessibleName( |
1713 client_->managed_node()->GetTitle()); | 1766 client_->managed_node()->GetTitle()); |
1714 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1767 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
1715 return; | 1768 return; |
1716 } | 1769 } |
| 1770 if (node == client_->supervised_node()) { |
| 1771 // The supervised node may have its title updated. |
| 1772 supervised_bookmarks_button_->SetAccessibleName( |
| 1773 client_->supervised_node()->GetTitle()); |
| 1774 supervised_bookmarks_button_->SetText( |
| 1775 client_->supervised_node()->GetTitle()); |
| 1776 return; |
| 1777 } |
1717 | 1778 |
1718 if (node->parent() != model->bookmark_bar_node()) { | 1779 if (node->parent() != model->bookmark_bar_node()) { |
1719 // We only care about nodes on the bookmark bar. | 1780 // We only care about nodes on the bookmark bar. |
1720 return; | 1781 return; |
1721 } | 1782 } |
1722 int index = model->bookmark_bar_node()->GetIndexOf(node); | 1783 int index = model->bookmark_bar_node()->GetIndexOf(node); |
1723 DCHECK_NE(-1, index); | 1784 DCHECK_NE(-1, index); |
1724 if (index >= GetBookmarkButtonCount()) | 1785 if (index >= GetBookmarkButtonCount()) |
1725 return; // Buttons are created as needed. | 1786 return; // Buttons are created as needed. |
1726 views::LabelButton* button = GetBookmarkButton(index); | 1787 views::LabelButton* button = GetBookmarkButton(index); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1904 if (parent_on_bb) { | 1965 if (parent_on_bb) { |
1905 int index = bbn->GetIndexOf(parent_on_bb); | 1966 int index = bbn->GetIndexOf(parent_on_bb); |
1906 if (index >= GetFirstHiddenNodeIndex()) { | 1967 if (index >= GetFirstHiddenNodeIndex()) { |
1907 // Node is hidden, animate the overflow button. | 1968 // Node is hidden, animate the overflow button. |
1908 throbbing_view_ = overflow_button_; | 1969 throbbing_view_ = overflow_button_; |
1909 } else if (!overflow_only) { | 1970 } else if (!overflow_only) { |
1910 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1971 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
1911 } | 1972 } |
1912 } else if (client_->IsDescendantOfManagedNode(node)) { | 1973 } else if (client_->IsDescendantOfManagedNode(node)) { |
1913 throbbing_view_ = managed_bookmarks_button_; | 1974 throbbing_view_ = managed_bookmarks_button_; |
| 1975 } else if (client_->IsDescendantOfSupervisedNode(node)) { |
| 1976 throbbing_view_ = supervised_bookmarks_button_; |
1914 } else if (!overflow_only) { | 1977 } else if (!overflow_only) { |
1915 throbbing_view_ = other_bookmarks_button_; | 1978 throbbing_view_ = other_bookmarks_button_; |
1916 } | 1979 } |
1917 | 1980 |
1918 // Use a large number so that the button continues to throb. | 1981 // Use a large number so that the button continues to throb. |
1919 if (throbbing_view_) | 1982 if (throbbing_view_) |
1920 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1983 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
1921 } | 1984 } |
1922 | 1985 |
1923 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( | 1986 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
(...skipping 12 matching lines...) Expand all Loading... |
1936 } | 1999 } |
1937 if (old_node) { | 2000 if (old_node) { |
1938 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { | 2001 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { |
1939 // Node is hidden, animate the overflow button. | 2002 // Node is hidden, animate the overflow button. |
1940 return overflow_button_; | 2003 return overflow_button_; |
1941 } | 2004 } |
1942 return static_cast<CustomButton*>(child_at(old_index_on_bb)); | 2005 return static_cast<CustomButton*>(child_at(old_index_on_bb)); |
1943 } | 2006 } |
1944 if (client_->IsDescendantOfManagedNode(parent)) | 2007 if (client_->IsDescendantOfManagedNode(parent)) |
1945 return managed_bookmarks_button_; | 2008 return managed_bookmarks_button_; |
| 2009 if (client_->IsDescendantOfSupervisedNode(parent)) |
| 2010 return supervised_bookmarks_button_; |
1946 // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. | 2011 // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. |
1947 return other_bookmarks_button_; | 2012 return other_bookmarks_button_; |
1948 } | 2013 } |
1949 | 2014 |
1950 void BookmarkBarView::UpdateColors() { | 2015 void BookmarkBarView::UpdateColors() { |
1951 // We don't always have a theme provider (ui tests, for example). | 2016 // We don't always have a theme provider (ui tests, for example). |
1952 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 2017 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
1953 if (!theme_provider) | 2018 if (!theme_provider) |
1954 return; | 2019 return; |
1955 SkColor color = | 2020 SkColor color = |
1956 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 2021 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
1957 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 2022 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1958 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color); | 2023 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color); |
1959 other_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 2024 other_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
1960 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 2025 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
| 2026 supervised_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, |
| 2027 color); |
1961 if (apps_page_shortcut_->visible()) | 2028 if (apps_page_shortcut_->visible()) |
1962 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color); | 2029 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color); |
1963 } | 2030 } |
1964 | 2031 |
1965 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { | 2032 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { |
1966 bool has_other_children = !model_->other_node()->empty(); | 2033 bool has_other_children = !model_->other_node()->empty(); |
1967 bool update_other = has_other_children != other_bookmarks_button_->visible(); | 2034 bool update_other = has_other_children != other_bookmarks_button_->visible(); |
1968 if (update_other) { | 2035 if (update_other) { |
1969 other_bookmarks_button_->SetVisible(has_other_children); | 2036 other_bookmarks_button_->SetVisible(has_other_children); |
1970 UpdateBookmarksSeparatorVisibility(); | 2037 UpdateBookmarksSeparatorVisibility(); |
1971 } | 2038 } |
1972 | 2039 |
1973 bool show_managed = !client_->managed_node()->empty() && | 2040 bool show_managed = !client_->managed_node()->empty() && |
1974 browser_->profile()->GetPrefs()->GetBoolean( | 2041 browser_->profile()->GetPrefs()->GetBoolean( |
1975 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); | 2042 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
1976 bool update_managed = show_managed != managed_bookmarks_button_->visible(); | 2043 bool update_managed = show_managed != managed_bookmarks_button_->visible(); |
1977 if (update_managed) | 2044 if (update_managed) |
1978 managed_bookmarks_button_->SetVisible(show_managed); | 2045 managed_bookmarks_button_->SetVisible(show_managed); |
1979 | 2046 |
1980 return update_other || update_managed; | 2047 bool show_supervised = !client_->supervised_node()->empty(); |
| 2048 bool update_supervised = |
| 2049 show_supervised != supervised_bookmarks_button_->visible(); |
| 2050 if (update_supervised) |
| 2051 supervised_bookmarks_button_->SetVisible(show_supervised); |
| 2052 |
| 2053 return update_other || update_managed || update_supervised; |
1981 } | 2054 } |
1982 | 2055 |
1983 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { | 2056 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { |
1984 // Ash does not paint the bookmarks separator line because it looks odd on | 2057 // Ash does not paint the bookmarks separator line because it looks odd on |
1985 // the flat background. We keep it present for layout, but don't draw it. | 2058 // the flat background. We keep it present for layout, but don't draw it. |
1986 bookmarks_separator_view_->SetVisible( | 2059 bookmarks_separator_view_->SetVisible( |
1987 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && | 2060 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && |
1988 other_bookmarks_button_->visible()); | 2061 other_bookmarks_button_->visible()); |
1989 } | 2062 } |
1990 | 2063 |
1991 void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() { | 2064 void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() { |
1992 DCHECK(apps_page_shortcut_); | 2065 DCHECK(apps_page_shortcut_); |
1993 // Only perform layout if required. | 2066 // Only perform layout if required. |
1994 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 2067 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1995 browser_->profile(), browser_->host_desktop_type()); | 2068 browser_->profile(), browser_->host_desktop_type()); |
1996 if (apps_page_shortcut_->visible() == visible) | 2069 if (apps_page_shortcut_->visible() == visible) |
1997 return; | 2070 return; |
1998 apps_page_shortcut_->SetVisible(visible); | 2071 apps_page_shortcut_->SetVisible(visible); |
1999 UpdateBookmarksSeparatorVisibility(); | 2072 UpdateBookmarksSeparatorVisibility(); |
2000 LayoutAndPaint(); | 2073 LayoutAndPaint(); |
2001 } | 2074 } |
2002 | 2075 |
2003 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 2076 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
2004 if (UpdateOtherAndManagedButtonsVisibility()) | 2077 if (UpdateOtherAndManagedButtonsVisibility()) |
2005 LayoutAndPaint(); | 2078 LayoutAndPaint(); |
2006 } | 2079 } |
OLD | NEW |