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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 owner_->StopThrobbing(true); | 336 owner_->StopThrobbing(true); |
337 return views::MenuButton::OnMousePressed(e); | 337 return views::MenuButton::OnMousePressed(e); |
338 } | 338 } |
339 | 339 |
340 private: | 340 private: |
341 BookmarkBarView* owner_; | 341 BookmarkBarView* owner_; |
342 | 342 |
343 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); | 343 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); |
344 }; | 344 }; |
345 | 345 |
346 void RecordAppLaunch(Profile* profile, GURL url) { | 346 void RecordAppLaunch(Profile* profile, const GURL& url) { |
347 const extensions::Extension* extension = | 347 const extensions::Extension* extension = |
348 extensions::ExtensionRegistry::Get(profile) | 348 extensions::ExtensionRegistry::Get(profile) |
349 ->enabled_extensions().GetAppByURL(url); | 349 ->enabled_extensions().GetAppByURL(url); |
350 if (!extension) | 350 if (!extension) |
351 return; | 351 return; |
352 | 352 |
353 extensions::RecordAppLaunchType(extension_misc::APP_LAUNCH_BOOKMARK_BAR, | 353 extensions::RecordAppLaunchType(extension_misc::APP_LAUNCH_BOOKMARK_BAR, |
354 extension->GetType()); | 354 extension->GetType()); |
355 } | 355 } |
356 | 356 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 // BookmarkBarView ------------------------------------------------------------ | 445 // BookmarkBarView ------------------------------------------------------------ |
446 | 446 |
447 // static | 447 // static |
448 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; | 448 const char BookmarkBarView::kViewClassName[] = "BookmarkBarView"; |
449 | 449 |
450 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 450 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
451 : page_navigator_(NULL), | 451 : page_navigator_(NULL), |
452 client_(NULL), | 452 client_(NULL), |
453 bookmark_menu_(NULL), | 453 bookmark_menu_(NULL), |
454 bookmark_drop_menu_(NULL), | 454 bookmark_drop_menu_(NULL), |
455 other_bookmarked_button_(NULL), | 455 other_bookmarks_button_(NULL), |
456 managed_bookmarks_button_(NULL), | 456 managed_bookmarks_button_(NULL), |
457 apps_page_shortcut_(NULL), | 457 apps_page_shortcut_(NULL), |
458 overflow_button_(NULL), | 458 overflow_button_(NULL), |
459 instructions_(NULL), | 459 instructions_(NULL), |
460 bookmarks_separator_view_(NULL), | 460 bookmarks_separator_view_(NULL), |
461 browser_(browser), | 461 browser_(browser), |
462 browser_view_(browser_view), | 462 browser_view_(browser_view), |
463 infobar_visible_(false), | 463 infobar_visible_(false), |
464 throbbing_view_(NULL), | 464 throbbing_view_(NULL), |
465 bookmark_bar_state_(BookmarkBar::SHOW), | 465 bookmark_bar_state_(BookmarkBar::SHOW), |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 } | 565 } |
566 | 566 |
567 // Then the overflow button. | 567 // Then the overflow button. |
568 if (overflow_button_->visible() && | 568 if (overflow_button_->visible() && |
569 overflow_button_->bounds().Contains(adjusted_loc)) { | 569 overflow_button_->bounds().Contains(adjusted_loc)) { |
570 *model_start_index = GetFirstHiddenNodeIndex(); | 570 *model_start_index = GetFirstHiddenNodeIndex(); |
571 return model_->bookmark_bar_node(); | 571 return model_->bookmark_bar_node(); |
572 } | 572 } |
573 | 573 |
574 // And finally the other folder. | 574 // And finally the other folder. |
575 if (other_bookmarked_button_->visible() && | 575 if (other_bookmarks_button_->visible() && |
576 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { | 576 other_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
577 return model_->other_node(); | 577 return model_->other_node(); |
578 } | 578 } |
579 | 579 |
580 return NULL; | 580 return NULL; |
581 } | 581 } |
582 | 582 |
583 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( | 583 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
584 const BookmarkNode* node) { | 584 const BookmarkNode* node) { |
585 if (node == client_->managed_node()) | 585 if (node == client_->managed_node()) |
586 return managed_bookmarks_button_; | 586 return managed_bookmarks_button_; |
587 if (node == model_->other_node()) | 587 if (node == model_->other_node()) |
588 return other_bookmarked_button_; | 588 return other_bookmarks_button_; |
589 if (node == model_->bookmark_bar_node()) | 589 if (node == model_->bookmark_bar_node()) |
590 return overflow_button_; | 590 return overflow_button_; |
591 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 591 int index = model_->bookmark_bar_node()->GetIndexOf(node); |
592 if (index == -1 || !node->is_folder()) | 592 if (index == -1 || !node->is_folder()) |
593 return NULL; | 593 return NULL; |
594 return static_cast<views::MenuButton*>(child_at(index)); | 594 return static_cast<views::MenuButton*>(child_at(index)); |
595 } | 595 } |
596 | 596 |
597 void BookmarkBarView::GetAnchorPositionForButton( | 597 void BookmarkBarView::GetAnchorPositionForButton( |
598 views::MenuButton* button, | 598 views::MenuButton* button, |
599 views::MenuAnchorPosition* anchor) { | 599 views::MenuAnchorPosition* anchor) { |
600 if (button == other_bookmarked_button_ || button == overflow_button_) | 600 if (button == other_bookmarks_button_ || button == overflow_button_) |
601 *anchor = views::MENU_ANCHOR_TOPRIGHT; | 601 *anchor = views::MENU_ANCHOR_TOPRIGHT; |
602 else | 602 else |
603 *anchor = views::MENU_ANCHOR_TOPLEFT; | 603 *anchor = views::MENU_ANCHOR_TOPLEFT; |
604 } | 604 } |
605 | 605 |
606 views::MenuItemView* BookmarkBarView::GetMenu() { | 606 views::MenuItemView* BookmarkBarView::GetMenu() { |
607 return bookmark_menu_ ? bookmark_menu_->menu() : NULL; | 607 return bookmark_menu_ ? bookmark_menu_->menu() : NULL; |
608 } | 608 } |
609 | 609 |
610 views::MenuItemView* BookmarkBarView::GetContextMenu() { | 610 views::MenuItemView* BookmarkBarView::GetContextMenu() { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
736 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); | 736 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); |
737 height += static_cast<int>( | 737 height += static_cast<int>( |
738 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * | 738 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * |
739 current_state); | 739 current_state); |
740 } | 740 } |
741 | 741 |
742 if (managed_bookmarks_button_->visible()) { | 742 if (managed_bookmarks_button_->visible()) { |
743 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); | 743 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); |
744 width += size.width() + kButtonPadding; | 744 width += size.width() + kButtonPadding; |
745 } | 745 } |
746 if (other_bookmarked_button_->visible()) { | 746 if (other_bookmarks_button_->visible()) { |
747 gfx::Size size = other_bookmarked_button_->GetPreferredSize(); | 747 gfx::Size size = other_bookmarks_button_->GetPreferredSize(); |
748 width += size.width() + kButtonPadding; | 748 width += size.width() + kButtonPadding; |
749 } | 749 } |
750 if (overflow_button_->visible()) { | 750 if (overflow_button_->visible()) { |
751 gfx::Size size = overflow_button_->GetPreferredSize(); | 751 gfx::Size size = overflow_button_->GetPreferredSize(); |
752 width += size.width() + kButtonPadding; | 752 width += size.width() + kButtonPadding; |
753 } | 753 } |
754 if (bookmarks_separator_view_->visible()) { | 754 if (bookmarks_separator_view_->visible()) { |
755 gfx::Size size = bookmarks_separator_view_->GetPreferredSize(); | 755 gfx::Size size = bookmarks_separator_view_->GetPreferredSize(); |
756 width += size.width(); | 756 width += size.width(); |
757 } | 757 } |
(...skipping 23 matching lines...) Expand all Loading... |
781 y += (View::height() - chrome::kBookmarkBarHeight) / 2; | 781 y += (View::height() - chrome::kBookmarkBarHeight) / 2; |
782 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); | 782 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); |
783 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); | 783 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); |
784 } else { | 784 } else { |
785 // For the attached appearance, pin the content to the bottom of the bar | 785 // For the attached appearance, pin the content to the bottom of the bar |
786 // when animating in/out, as shrinking its height instead looks weird. This | 786 // when animating in/out, as shrinking its height instead looks weird. This |
787 // also matches how we layout infobars. | 787 // also matches how we layout infobars. |
788 y += View::height() - chrome::kBookmarkBarHeight; | 788 y += View::height() - chrome::kBookmarkBarHeight; |
789 } | 789 } |
790 | 790 |
791 gfx::Size other_bookmarked_pref = other_bookmarked_button_->visible() ? | 791 gfx::Size other_bookmarks_pref = other_bookmarks_button_->visible() ? |
792 other_bookmarked_button_->GetPreferredSize() : gfx::Size(); | 792 other_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
793 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); | 793 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
794 gfx::Size bookmarks_separator_pref = | 794 gfx::Size bookmarks_separator_pref = |
795 bookmarks_separator_view_->GetPreferredSize(); | 795 bookmarks_separator_view_->GetPreferredSize(); |
796 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? | 796 gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? |
797 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); | 797 apps_page_shortcut_->GetPreferredSize() : gfx::Size(); |
798 | 798 |
799 int max_x = width - overflow_pref.width() - kButtonPadding - | 799 int max_x = width - overflow_pref.width() - kButtonPadding - |
800 bookmarks_separator_pref.width(); | 800 bookmarks_separator_pref.width(); |
801 if (other_bookmarked_button_->visible()) | 801 if (other_bookmarks_button_->visible()) |
802 max_x -= other_bookmarked_pref.width() + kButtonPadding; | 802 max_x -= other_bookmarks_pref.width() + kButtonPadding; |
803 | 803 |
804 // Start with the apps page shortcut button. | 804 // Start with the apps page shortcut button. |
805 if (apps_page_shortcut_->visible()) { | 805 if (apps_page_shortcut_->visible()) { |
806 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), | 806 apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), |
807 height); | 807 height); |
808 x += apps_page_shortcut_pref.width() + kButtonPadding; | 808 x += apps_page_shortcut_pref.width() + kButtonPadding; |
809 } | 809 } |
810 | 810 |
811 // Then comes the managed bookmarks folder, if visible. | 811 // Then comes the managed bookmarks folder, if visible. |
812 if (managed_bookmarks_button_->visible()) { | 812 if (managed_bookmarks_button_->visible()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
871 if (bookmarks_separator_view_->visible()) { | 871 if (bookmarks_separator_view_->visible()) { |
872 bookmarks_separator_view_->SetBounds(x, | 872 bookmarks_separator_view_->SetBounds(x, |
873 y - top_margin, | 873 y - top_margin, |
874 bookmarks_separator_pref.width(), | 874 bookmarks_separator_pref.width(), |
875 height + top_margin + kBottomMargin - | 875 height + top_margin + kBottomMargin - |
876 separator_margin); | 876 separator_margin); |
877 | 877 |
878 x += bookmarks_separator_pref.width(); | 878 x += bookmarks_separator_pref.width(); |
879 } | 879 } |
880 | 880 |
881 // The other bookmarks button. | 881 // The "Other Bookmarks" button. |
882 if (other_bookmarked_button_->visible()) { | 882 if (other_bookmarks_button_->visible()) { |
883 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), | 883 other_bookmarks_button_->SetBounds(x, y, other_bookmarks_pref.width(), |
884 height); | 884 height); |
885 x += other_bookmarked_pref.width() + kButtonPadding; | 885 x += other_bookmarks_pref.width() + kButtonPadding; |
886 } | 886 } |
887 } | 887 } |
888 | 888 |
889 void BookmarkBarView::ViewHierarchyChanged( | 889 void BookmarkBarView::ViewHierarchyChanged( |
890 const ViewHierarchyChangedDetails& details) { | 890 const ViewHierarchyChangedDetails& details) { |
891 if (details.is_add && details.child == this) { | 891 if (details.is_add && details.child == this) { |
892 // We may get inserted into a hierarchy with a profile - this typically | 892 // We may get inserted into a hierarchy with a profile - this typically |
893 // occurs when the bar's contents get populated fast enough that the | 893 // occurs when the bar's contents get populated fast enough that the |
894 // buttons are created before the bar is attached to a frame. | 894 // buttons are created before the bar is attached to a frame. |
895 UpdateColors(); | 895 UpdateColors(); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1148 StopThrobbing(false); | 1148 StopThrobbing(false); |
1149 } | 1149 } |
1150 | 1150 |
1151 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, | 1151 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, |
1152 bool ids_reassigned) { | 1152 bool ids_reassigned) { |
1153 // There should be no buttons. If non-zero it means Load was invoked more than | 1153 // There should be no buttons. If non-zero it means Load was invoked more than |
1154 // once, or we didn't properly clear things. Either of which shouldn't happen. | 1154 // once, or we didn't properly clear things. Either of which shouldn't happen. |
1155 // The actual bookmark buttons are added from Layout(). | 1155 // The actual bookmark buttons are added from Layout(). |
1156 DCHECK_EQ(0, GetBookmarkButtonCount()); | 1156 DCHECK_EQ(0, GetBookmarkButtonCount()); |
1157 DCHECK(model->other_node()); | 1157 DCHECK(model->other_node()); |
1158 other_bookmarked_button_->SetAccessibleName(model->other_node()->GetTitle()); | 1158 other_bookmarks_button_->SetAccessibleName(model->other_node()->GetTitle()); |
1159 other_bookmarked_button_->SetText(model->other_node()->GetTitle()); | 1159 other_bookmarks_button_->SetText(model->other_node()->GetTitle()); |
1160 managed_bookmarks_button_->SetAccessibleName( | 1160 managed_bookmarks_button_->SetAccessibleName( |
1161 client_->managed_node()->GetTitle()); | 1161 client_->managed_node()->GetTitle()); |
1162 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1162 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
1163 UpdateColors(); | 1163 UpdateColors(); |
1164 UpdateOtherAndManagedButtonsVisibility(); | 1164 UpdateOtherAndManagedButtonsVisibility(); |
1165 other_bookmarked_button_->SetEnabled(true); | 1165 other_bookmarks_button_->SetEnabled(true); |
1166 managed_bookmarks_button_->SetEnabled(true); | 1166 managed_bookmarks_button_->SetEnabled(true); |
1167 LayoutAndPaint(); | 1167 LayoutAndPaint(); |
1168 } | 1168 } |
1169 | 1169 |
1170 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1170 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
1171 NOTREACHED(); | 1171 NOTREACHED(); |
1172 // Do minimal cleanup, presumably we'll be deleted shortly. | 1172 // Do minimal cleanup, presumably we'll be deleted shortly. |
1173 model_->RemoveObserver(this); | 1173 model_->RemoveObserver(this); |
1174 model_ = NULL; | 1174 model_ = NULL; |
1175 } | 1175 } |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1327 } | 1327 } |
1328 } | 1328 } |
1329 return true; | 1329 return true; |
1330 } | 1330 } |
1331 | 1331 |
1332 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1332 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
1333 const gfx::Point& point) { | 1333 const gfx::Point& point) { |
1334 const BookmarkNode* node; | 1334 const BookmarkNode* node; |
1335 | 1335 |
1336 int start_index = 0; | 1336 int start_index = 0; |
1337 if (view == other_bookmarked_button_) { | 1337 if (view == other_bookmarks_button_) { |
1338 node = model_->other_node(); | 1338 node = model_->other_node(); |
1339 } else if (view == managed_bookmarks_button_) { | 1339 } else if (view == managed_bookmarks_button_) { |
1340 node = client_->managed_node(); | 1340 node = client_->managed_node(); |
1341 } else if (view == overflow_button_) { | 1341 } else if (view == overflow_button_) { |
1342 node = model_->bookmark_bar_node(); | 1342 node = model_->bookmark_bar_node(); |
1343 start_index = GetFirstHiddenNodeIndex(); | 1343 start_index = GetFirstHiddenNodeIndex(); |
1344 } else { | 1344 } else { |
1345 int button_index = GetIndexOf(view); | 1345 int button_index = GetIndexOf(view); |
1346 DCHECK_NE(-1, button_index); | 1346 DCHECK_NE(-1, button_index); |
1347 node = model_->bookmark_bar_node()->GetChild(button_index); | 1347 node = model_->bookmark_bar_node()->GetChild(button_index); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 void BookmarkBarView::ShowContextMenuForView(views::View* source, | 1399 void BookmarkBarView::ShowContextMenuForView(views::View* source, |
1400 const gfx::Point& point, | 1400 const gfx::Point& point, |
1401 ui::MenuSourceType source_type) { | 1401 ui::MenuSourceType source_type) { |
1402 if (!model_->loaded()) { | 1402 if (!model_->loaded()) { |
1403 // Don't do anything if the model isn't loaded. | 1403 // Don't do anything if the model isn't loaded. |
1404 return; | 1404 return; |
1405 } | 1405 } |
1406 | 1406 |
1407 const BookmarkNode* parent = NULL; | 1407 const BookmarkNode* parent = NULL; |
1408 std::vector<const BookmarkNode*> nodes; | 1408 std::vector<const BookmarkNode*> nodes; |
1409 if (source == other_bookmarked_button_) { | 1409 if (source == other_bookmarks_button_) { |
1410 parent = model_->other_node(); | 1410 parent = model_->other_node(); |
1411 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1411 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
1412 // sure the user can't edit/delete the node in this case. | 1412 // sure the user can't edit/delete the node in this case. |
1413 nodes.push_back(parent); | 1413 nodes.push_back(parent); |
1414 } else if (source == managed_bookmarks_button_) { | 1414 } else if (source == managed_bookmarks_button_) { |
1415 parent = client_->managed_node(); | 1415 parent = client_->managed_node(); |
1416 nodes.push_back(parent); | 1416 nodes.push_back(parent); |
1417 } else if (source != this && source != apps_page_shortcut_) { | 1417 } else if (source != this && source != apps_page_shortcut_) { |
1418 // User clicked on one of the bookmark buttons, find which one they | 1418 // User clicked on one of the bookmark buttons, find which one they |
1419 // clicked on, except for the apps page shortcut, which must behave as if | 1419 // clicked on, except for the apps page shortcut, which must behave as if |
(...skipping 23 matching lines...) Expand all Loading... |
1443 // Note that at this point we're not in a hierarchy so GetThemeProvider() will | 1443 // Note that at this point we're not in a hierarchy so GetThemeProvider() will |
1444 // return NULL. When we're inserted into a hierarchy, we'll call | 1444 // return NULL. When we're inserted into a hierarchy, we'll call |
1445 // UpdateColors(), which will set the appropriate colors for all the objects | 1445 // UpdateColors(), which will set the appropriate colors for all the objects |
1446 // added in this function. | 1446 // added in this function. |
1447 | 1447 |
1448 // Child views are traversed in the order they are added. Make sure the order | 1448 // Child views are traversed in the order they are added. Make sure the order |
1449 // they are added matches the visual order. | 1449 // they are added matches the visual order. |
1450 overflow_button_ = CreateOverflowButton(); | 1450 overflow_button_ = CreateOverflowButton(); |
1451 AddChildView(overflow_button_); | 1451 AddChildView(overflow_button_); |
1452 | 1452 |
1453 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 1453 other_bookmarks_button_ = CreateOtherBookmarksButton(); |
1454 // We'll re-enable when the model is loaded. | 1454 // We'll re-enable when the model is loaded. |
1455 other_bookmarked_button_->SetEnabled(false); | 1455 other_bookmarks_button_->SetEnabled(false); |
1456 AddChildView(other_bookmarked_button_); | 1456 AddChildView(other_bookmarks_button_); |
1457 | 1457 |
1458 managed_bookmarks_button_ = CreateManagedBookmarksButton(); | 1458 managed_bookmarks_button_ = CreateManagedBookmarksButton(); |
1459 // Also re-enabled when the model is loaded. | 1459 // Also re-enabled when the model is loaded. |
1460 managed_bookmarks_button_->SetEnabled(false); | 1460 managed_bookmarks_button_->SetEnabled(false); |
1461 AddChildView(managed_bookmarks_button_); | 1461 AddChildView(managed_bookmarks_button_); |
1462 | 1462 |
1463 apps_page_shortcut_ = CreateAppsPageShortcutButton(); | 1463 apps_page_shortcut_ = CreateAppsPageShortcutButton(); |
1464 AddChildView(apps_page_shortcut_); | 1464 AddChildView(apps_page_shortcut_); |
1465 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); | 1465 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
1466 profile_pref_registrar_.Add( | 1466 profile_pref_registrar_.Add( |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 | 1517 |
1518 int BookmarkBarView::GetFirstHiddenNodeIndex() { | 1518 int BookmarkBarView::GetFirstHiddenNodeIndex() { |
1519 const int bb_count = GetBookmarkButtonCount(); | 1519 const int bb_count = GetBookmarkButtonCount(); |
1520 for (int i = 0; i < bb_count; ++i) { | 1520 for (int i = 0; i < bb_count; ++i) { |
1521 if (!GetBookmarkButton(i)->visible()) | 1521 if (!GetBookmarkButton(i)->visible()) |
1522 return i; | 1522 return i; |
1523 } | 1523 } |
1524 return bb_count; | 1524 return bb_count; |
1525 } | 1525 } |
1526 | 1526 |
1527 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 1527 MenuButton* BookmarkBarView::CreateOtherBookmarksButton() { |
1528 // Title is set in Loaded. | 1528 // Title is set in Loaded. |
1529 MenuButton* button = | 1529 MenuButton* button = |
1530 new BookmarkFolderButton(this, base::string16(), this, false); | 1530 new BookmarkFolderButton(this, base::string16(), this, false); |
1531 button->set_id(VIEW_ID_OTHER_BOOKMARKS); | 1531 button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
1532 button->SetImage(views::Button::STATE_NORMAL, | 1532 button->SetImage(views::Button::STATE_NORMAL, |
1533 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER)); | 1533 *GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER)); |
1534 button->set_context_menu_controller(this); | 1534 button->set_context_menu_controller(this); |
1535 button->set_tag(kOtherFolderButtonTag); | 1535 button->set_tag(kOtherFolderButtonTag); |
1536 return button; | 1536 return button; |
1537 } | 1537 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1738 *location = DropLocation(); | 1738 *location = DropLocation(); |
1739 | 1739 |
1740 // The drop event uses the screen coordinates while the child Views are | 1740 // The drop event uses the screen coordinates while the child Views are |
1741 // always laid out from left to right (even though they are rendered from | 1741 // always laid out from left to right (even though they are rendered from |
1742 // right-to-left on RTL locales). Thus, in order to make sure the drop | 1742 // right-to-left on RTL locales). Thus, in order to make sure the drop |
1743 // coordinates calculation works, we mirror the event's X coordinate if the | 1743 // coordinates calculation works, we mirror the event's X coordinate if the |
1744 // locale is RTL. | 1744 // locale is RTL. |
1745 int mirrored_x = GetMirroredXInView(event.x()); | 1745 int mirrored_x = GetMirroredXInView(event.x()); |
1746 | 1746 |
1747 bool found = false; | 1747 bool found = false; |
1748 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); | 1748 const int other_delta_x = mirrored_x - other_bookmarks_button_->x(); |
1749 Profile* profile = browser_->profile(); | 1749 Profile* profile = browser_->profile(); |
1750 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && | 1750 if (other_bookmarks_button_->visible() && other_delta_x >= 0 && |
1751 other_delta_x < other_bookmarked_button_->width()) { | 1751 other_delta_x < other_bookmarks_button_->width()) { |
1752 // Mouse is over 'other' folder. | 1752 // Mouse is over 'other' folder. |
1753 location->button_type = DROP_OTHER_FOLDER; | 1753 location->button_type = DROP_OTHER_FOLDER; |
1754 location->on = true; | 1754 location->on = true; |
1755 found = true; | 1755 found = true; |
1756 } else if (!GetBookmarkButtonCount()) { | 1756 } else if (!GetBookmarkButtonCount()) { |
1757 // No bookmarks, accept the drop. | 1757 // No bookmarks, accept the drop. |
1758 location->index = 0; | 1758 location->index = 0; |
1759 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); | 1759 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); |
1760 int ops = node && client_->CanBeEditedByUser(node) ? | 1760 int ops = node && client_->CanBeEditedByUser(node) ? |
1761 ui::DragDropTypes::DRAG_MOVE : | 1761 ui::DragDropTypes::DRAG_MOVE : |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 // Mouse is over overflow button. | 1800 // Mouse is over overflow button. |
1801 location->index = GetFirstHiddenNodeIndex(); | 1801 location->index = GetFirstHiddenNodeIndex(); |
1802 location->button_type = DROP_OVERFLOW; | 1802 location->button_type = DROP_OVERFLOW; |
1803 } else if (overflow_delta_x < 0) { | 1803 } else if (overflow_delta_x < 0) { |
1804 // Mouse is after the last visible button but before overflow button; | 1804 // Mouse is after the last visible button but before overflow button; |
1805 // use the last visible index. | 1805 // use the last visible index. |
1806 location->index = GetFirstHiddenNodeIndex(); | 1806 location->index = GetFirstHiddenNodeIndex(); |
1807 } else { | 1807 } else { |
1808 return; | 1808 return; |
1809 } | 1809 } |
1810 } else if (!other_bookmarked_button_->visible() || | 1810 } else if (!other_bookmarks_button_->visible() || |
1811 mirrored_x < other_bookmarked_button_->x()) { | 1811 mirrored_x < other_bookmarks_button_->x()) { |
1812 // Mouse is after the last visible button but before more recently | 1812 // Mouse is after the last visible button but before more recently |
1813 // bookmarked; use the last visible index. | 1813 // bookmarked; use the last visible index. |
1814 location->index = GetFirstHiddenNodeIndex(); | 1814 location->index = GetFirstHiddenNodeIndex(); |
1815 } else { | 1815 } else { |
1816 return; | 1816 return; |
1817 } | 1817 } |
1818 } | 1818 } |
1819 | 1819 |
1820 if (location->on) { | 1820 if (location->on) { |
1821 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? | 1821 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 int index = bbn->GetIndexOf(parent_on_bb); | 1859 int index = bbn->GetIndexOf(parent_on_bb); |
1860 if (index >= GetFirstHiddenNodeIndex()) { | 1860 if (index >= GetFirstHiddenNodeIndex()) { |
1861 // Node is hidden, animate the overflow button. | 1861 // Node is hidden, animate the overflow button. |
1862 throbbing_view_ = overflow_button_; | 1862 throbbing_view_ = overflow_button_; |
1863 } else if (!overflow_only) { | 1863 } else if (!overflow_only) { |
1864 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1864 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
1865 } | 1865 } |
1866 } else if (client_->IsDescendantOfManagedNode(node)) { | 1866 } else if (client_->IsDescendantOfManagedNode(node)) { |
1867 throbbing_view_ = managed_bookmarks_button_; | 1867 throbbing_view_ = managed_bookmarks_button_; |
1868 } else if (!overflow_only) { | 1868 } else if (!overflow_only) { |
1869 throbbing_view_ = other_bookmarked_button_; | 1869 throbbing_view_ = other_bookmarks_button_; |
1870 } | 1870 } |
1871 | 1871 |
1872 // Use a large number so that the button continues to throb. | 1872 // Use a large number so that the button continues to throb. |
1873 if (throbbing_view_) | 1873 if (throbbing_view_) |
1874 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1874 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
1875 } | 1875 } |
1876 | 1876 |
1877 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( | 1877 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
1878 const BookmarkNode* parent, | 1878 const BookmarkNode* parent, |
1879 int old_index) { | 1879 int old_index) { |
(...skipping 10 matching lines...) Expand all Loading... |
1890 } | 1890 } |
1891 if (old_node) { | 1891 if (old_node) { |
1892 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { | 1892 if (old_index_on_bb >= GetFirstHiddenNodeIndex()) { |
1893 // Node is hidden, animate the overflow button. | 1893 // Node is hidden, animate the overflow button. |
1894 return overflow_button_; | 1894 return overflow_button_; |
1895 } | 1895 } |
1896 return static_cast<CustomButton*>(child_at(old_index_on_bb)); | 1896 return static_cast<CustomButton*>(child_at(old_index_on_bb)); |
1897 } | 1897 } |
1898 if (client_->IsDescendantOfManagedNode(parent)) | 1898 if (client_->IsDescendantOfManagedNode(parent)) |
1899 return managed_bookmarks_button_; | 1899 return managed_bookmarks_button_; |
1900 // Node wasn't on the bookmark bar, use the other bookmark button. | 1900 // Node wasn't on the bookmark bar, use the "Other Bookmarks" button. |
1901 return other_bookmarked_button_; | 1901 return other_bookmarks_button_; |
1902 } | 1902 } |
1903 | 1903 |
1904 void BookmarkBarView::UpdateColors() { | 1904 void BookmarkBarView::UpdateColors() { |
1905 // We don't always have a theme provider (ui tests, for example). | 1905 // We don't always have a theme provider (ui tests, for example). |
1906 const ui::ThemeProvider* theme_provider = GetThemeProvider(); | 1906 const ui::ThemeProvider* theme_provider = GetThemeProvider(); |
1907 if (!theme_provider) | 1907 if (!theme_provider) |
1908 return; | 1908 return; |
1909 SkColor color = | 1909 SkColor color = |
1910 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1910 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
1911 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1911 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1912 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color); | 1912 GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color); |
1913 other_bookmarked_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 1913 other_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
1914 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 1914 managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
1915 if (apps_page_shortcut_->visible()) | 1915 if (apps_page_shortcut_->visible()) |
1916 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color); | 1916 apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color); |
1917 } | 1917 } |
1918 | 1918 |
1919 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { | 1919 bool BookmarkBarView::UpdateOtherAndManagedButtonsVisibility() { |
1920 bool has_other_children = !model_->other_node()->empty(); | 1920 bool has_other_children = !model_->other_node()->empty(); |
1921 bool update_other = has_other_children != other_bookmarked_button_->visible(); | 1921 bool update_other = has_other_children != other_bookmarks_button_->visible(); |
1922 if (update_other) { | 1922 if (update_other) { |
1923 other_bookmarked_button_->SetVisible(has_other_children); | 1923 other_bookmarks_button_->SetVisible(has_other_children); |
1924 UpdateBookmarksSeparatorVisibility(); | 1924 UpdateBookmarksSeparatorVisibility(); |
1925 } | 1925 } |
1926 | 1926 |
1927 bool show_managed = !client_->managed_node()->empty() && | 1927 bool show_managed = !client_->managed_node()->empty() && |
1928 browser_->profile()->GetPrefs()->GetBoolean( | 1928 browser_->profile()->GetPrefs()->GetBoolean( |
1929 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); | 1929 bookmarks::prefs::kShowManagedBookmarksInBookmarkBar); |
1930 bool update_managed = show_managed != managed_bookmarks_button_->visible(); | 1930 bool update_managed = show_managed != managed_bookmarks_button_->visible(); |
1931 if (update_managed) | 1931 if (update_managed) |
1932 managed_bookmarks_button_->SetVisible(show_managed); | 1932 managed_bookmarks_button_->SetVisible(show_managed); |
1933 | 1933 |
1934 return update_other || update_managed; | 1934 return update_other || update_managed; |
1935 } | 1935 } |
1936 | 1936 |
1937 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { | 1937 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { |
1938 // Ash does not paint the bookmarks separator line because it looks odd on | 1938 // Ash does not paint the bookmarks separator line because it looks odd on |
1939 // the flat background. We keep it present for layout, but don't draw it. | 1939 // the flat background. We keep it present for layout, but don't draw it. |
1940 bookmarks_separator_view_->SetVisible( | 1940 bookmarks_separator_view_->SetVisible( |
1941 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && | 1941 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && |
1942 other_bookmarked_button_->visible()); | 1942 other_bookmarks_button_->visible()); |
1943 } | 1943 } |
1944 | 1944 |
1945 void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() { | 1945 void BookmarkBarView::OnAppsPageShortcutVisibilityPrefChanged() { |
1946 DCHECK(apps_page_shortcut_); | 1946 DCHECK(apps_page_shortcut_); |
1947 // Only perform layout if required. | 1947 // Only perform layout if required. |
1948 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1948 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1949 browser_->profile(), browser_->host_desktop_type()); | 1949 browser_->profile(), browser_->host_desktop_type()); |
1950 if (apps_page_shortcut_->visible() == visible) | 1950 if (apps_page_shortcut_->visible() == visible) |
1951 return; | 1951 return; |
1952 apps_page_shortcut_->SetVisible(visible); | 1952 apps_page_shortcut_->SetVisible(visible); |
1953 UpdateBookmarksSeparatorVisibility(); | 1953 UpdateBookmarksSeparatorVisibility(); |
1954 LayoutAndPaint(); | 1954 LayoutAndPaint(); |
1955 } | 1955 } |
1956 | 1956 |
1957 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { | 1957 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { |
1958 if (UpdateOtherAndManagedButtonsVisibility()) | 1958 if (UpdateOtherAndManagedButtonsVisibility()) |
1959 LayoutAndPaint(); | 1959 LayoutAndPaint(); |
1960 } | 1960 } |
OLD | NEW |