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

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698