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