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 <set> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
19 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
20 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
22 #include "chrome/browser/defaults.h" | 21 #include "chrome/browser/defaults.h" |
23 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/search/search.h" | 23 #include "chrome/browser/search/search.h" |
25 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
26 #include "chrome/browser/sync/profile_sync_service_factory.h" | 25 #include "chrome/browser/sync/profile_sync_service_factory.h" |
27 #include "chrome/browser/themes/theme_properties.h" | 26 #include "chrome/browser/themes/theme_properties.h" |
28 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" | 27 #include "chrome/browser/ui/bookmarks/bookmark_bar_constants.h" |
29 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" | 28 #include "chrome/browser/ui/bookmarks/bookmark_drag_drop.h" |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
432 static const gfx::ImageSkia& GetFolderIcon() { | 431 static const gfx::ImageSkia& GetFolderIcon() { |
433 if (!kFolderIcon) { | 432 if (!kFolderIcon) { |
434 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 433 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
435 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); | 434 kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); |
436 } | 435 } |
437 return *kFolderIcon; | 436 return *kFolderIcon; |
438 } | 437 } |
439 | 438 |
440 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) | 439 BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
441 : page_navigator_(NULL), | 440 : page_navigator_(NULL), |
442 model_(NULL), | |
443 client_(NULL), | 441 client_(NULL), |
444 bookmark_menu_(NULL), | 442 bookmark_menu_(NULL), |
445 bookmark_drop_menu_(NULL), | 443 bookmark_drop_menu_(NULL), |
446 other_bookmarked_button_(NULL), | 444 other_bookmarked_button_(NULL), |
447 managed_bookmarks_button_(NULL), | 445 managed_bookmarks_button_(NULL), |
448 apps_page_shortcut_(NULL), | 446 apps_page_shortcut_(NULL), |
449 show_folder_method_factory_(this), | 447 show_folder_method_factory_(this), |
450 overflow_button_(NULL), | 448 overflow_button_(NULL), |
451 instructions_(NULL), | 449 instructions_(NULL), |
452 bookmarks_separator_view_(NULL), | 450 bookmarks_separator_view_(NULL), |
453 browser_(browser), | 451 browser_(browser), |
454 browser_view_(browser_view), | 452 browser_view_(browser_view), |
455 infobar_visible_(false), | 453 infobar_visible_(false), |
456 throbbing_view_(NULL), | 454 throbbing_view_(NULL), |
457 bookmark_bar_state_(BookmarkBar::SHOW), | 455 bookmark_bar_state_(BookmarkBar::SHOW), |
458 animating_detached_(false) { | 456 animating_detached_(false) { |
459 set_id(VIEW_ID_BOOKMARK_BAR); | 457 set_id(VIEW_ID_BOOKMARK_BAR); |
460 Init(); | 458 Init(); |
461 | 459 |
462 size_animation_->Reset(1); | 460 size_animation_->Reset(1); |
463 } | 461 } |
464 | 462 |
465 BookmarkBarView::~BookmarkBarView() { | 463 BookmarkBarView::~BookmarkBarView() { |
466 if (model_) | 464 if (client_) |
467 model_->RemoveObserver(this); | 465 model()->RemoveObserver(this); |
468 | 466 |
469 // It's possible for the menu to outlive us, reset the observer to make sure | 467 // It's possible for the menu to outlive us, reset the observer to make sure |
470 // it doesn't have a reference to us. | 468 // it doesn't have a reference to us. |
471 if (bookmark_menu_) { | 469 if (bookmark_menu_) { |
472 bookmark_menu_->set_observer(NULL); | 470 bookmark_menu_->set_observer(NULL); |
473 bookmark_menu_->SetPageNavigator(NULL); | 471 bookmark_menu_->SetPageNavigator(NULL); |
474 bookmark_menu_->clear_bookmark_bar(); | 472 bookmark_menu_->clear_bookmark_bar(); |
475 } | 473 } |
476 if (context_menu_.get()) | 474 if (context_menu_.get()) |
477 context_menu_->SetPageNavigator(NULL); | 475 context_menu_->SetPageNavigator(NULL); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { | 535 managed_bookmarks_button_->bounds().Contains(adjusted_loc)) { |
538 return client_->managed_node(); | 536 return client_->managed_node(); |
539 } | 537 } |
540 | 538 |
541 // Check the buttons first. | 539 // Check the buttons first. |
542 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 540 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
543 views::View* child = child_at(i); | 541 views::View* child = child_at(i); |
544 if (!child->visible()) | 542 if (!child->visible()) |
545 break; | 543 break; |
546 if (child->bounds().Contains(adjusted_loc)) | 544 if (child->bounds().Contains(adjusted_loc)) |
547 return model_->bookmark_bar_node()->GetChild(i); | 545 return model()->bookmark_bar_node()->GetChild(i); |
548 } | 546 } |
549 | 547 |
550 // Then the overflow button. | 548 // Then the overflow button. |
551 if (overflow_button_->visible() && | 549 if (overflow_button_->visible() && |
552 overflow_button_->bounds().Contains(adjusted_loc)) { | 550 overflow_button_->bounds().Contains(adjusted_loc)) { |
553 *model_start_index = GetFirstHiddenNodeIndex(); | 551 *model_start_index = GetFirstHiddenNodeIndex(); |
554 return model_->bookmark_bar_node(); | 552 return model()->bookmark_bar_node(); |
555 } | 553 } |
556 | 554 |
557 // And finally the other folder. | 555 // And finally the other folder. |
558 if (other_bookmarked_button_->visible() && | 556 if (other_bookmarked_button_->visible() && |
559 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { | 557 other_bookmarked_button_->bounds().Contains(adjusted_loc)) { |
560 return model_->other_node(); | 558 return model()->other_node(); |
561 } | 559 } |
562 | 560 |
563 return NULL; | 561 return NULL; |
564 } | 562 } |
565 | 563 |
566 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( | 564 views::MenuButton* BookmarkBarView::GetMenuButtonForNode( |
567 const BookmarkNode* node) { | 565 const BookmarkNode* node) { |
568 if (node == client_->managed_node()) | 566 if (node == client_->managed_node()) |
569 return managed_bookmarks_button_; | 567 return managed_bookmarks_button_; |
570 if (node == model_->other_node()) | 568 if (node == model()->other_node()) |
571 return other_bookmarked_button_; | 569 return other_bookmarked_button_; |
572 if (node == model_->bookmark_bar_node()) | 570 if (node == model()->bookmark_bar_node()) |
573 return overflow_button_; | 571 return overflow_button_; |
574 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 572 int index = model()->bookmark_bar_node()->GetIndexOf(node); |
575 if (index == -1 || !node->is_folder()) | 573 if (index == -1 || !node->is_folder()) |
576 return NULL; | 574 return NULL; |
577 return static_cast<views::MenuButton*>(child_at(index)); | 575 return static_cast<views::MenuButton*>(child_at(index)); |
578 } | 576 } |
579 | 577 |
580 void BookmarkBarView::GetAnchorPositionForButton( | 578 void BookmarkBarView::GetAnchorPositionForButton( |
581 views::MenuButton* button, | 579 views::MenuButton* button, |
582 views::MenuAnchorPosition* anchor) { | 580 views::MenuAnchorPosition* anchor) { |
583 if (button == other_bookmarked_button_ || button == overflow_button_) | 581 if (button == other_bookmarked_button_ || button == overflow_button_) |
584 *anchor = views::MENU_ANCHOR_TOPRIGHT; | 582 *anchor = views::MENU_ANCHOR_TOPRIGHT; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds)); | 802 indicator_bounds.set_x(GetMirroredXForRect(indicator_bounds)); |
805 | 803 |
806 // TODO(sky/glen): make me pretty! | 804 // TODO(sky/glen): make me pretty! |
807 canvas->FillRect(indicator_bounds, kDropIndicatorColor); | 805 canvas->FillRect(indicator_bounds, kDropIndicatorColor); |
808 } | 806 } |
809 } | 807 } |
810 | 808 |
811 bool BookmarkBarView::GetDropFormats( | 809 bool BookmarkBarView::GetDropFormats( |
812 int* formats, | 810 int* formats, |
813 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) { | 811 std::set<ui::OSExchangeData::CustomFormat>* custom_formats) { |
814 if (!model_ || !model_->loaded()) | 812 if (!client_ || !model()->loaded()) |
815 return false; | 813 return false; |
816 *formats = ui::OSExchangeData::URL; | 814 *formats = ui::OSExchangeData::URL; |
817 custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat()); | 815 custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat()); |
818 return true; | 816 return true; |
819 } | 817 } |
820 | 818 |
821 bool BookmarkBarView::AreDropTypesRequired() { | 819 bool BookmarkBarView::AreDropTypesRequired() { |
822 return true; | 820 return true; |
823 } | 821 } |
824 | 822 |
825 bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) { | 823 bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) { |
826 if (!model_ || !model_->loaded() || | 824 if (!client_ || !model()->loaded() || |
827 !browser_->profile()->GetPrefs()->GetBoolean( | 825 !browser_->profile()->GetPrefs()->GetBoolean( |
828 prefs::kEditBookmarksEnabled)) | 826 prefs::kEditBookmarksEnabled)) |
829 return false; | 827 return false; |
830 | 828 |
831 if (!drop_info_.get()) | 829 if (!drop_info_.get()) |
832 drop_info_.reset(new DropInfo()); | 830 drop_info_.reset(new DropInfo()); |
833 | 831 |
834 // Only accept drops of 1 node, which is the case for all data dragged from | 832 // Only accept drops of 1 node, which is the case for all data dragged from |
835 // bookmark bar and menus. | 833 // bookmark bar and menus. |
836 return drop_info_->data.Read(data) && drop_info_->data.size() == 1; | 834 return drop_info_->data.Read(data) && drop_info_->data.size() == 1; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 if (drop_info_->is_menu_showing) { | 871 if (drop_info_->is_menu_showing) { |
874 if (bookmark_drop_menu_) | 872 if (bookmark_drop_menu_) |
875 bookmark_drop_menu_->Cancel(); | 873 bookmark_drop_menu_->Cancel(); |
876 drop_info_->is_menu_showing = false; | 874 drop_info_->is_menu_showing = false; |
877 } | 875 } |
878 | 876 |
879 if (location.on || location.button_type == DROP_OVERFLOW || | 877 if (location.on || location.button_type == DROP_OVERFLOW || |
880 location.button_type == DROP_OTHER_FOLDER) { | 878 location.button_type == DROP_OTHER_FOLDER) { |
881 const BookmarkNode* node; | 879 const BookmarkNode* node; |
882 if (location.button_type == DROP_OTHER_FOLDER) | 880 if (location.button_type == DROP_OTHER_FOLDER) |
883 node = model_->other_node(); | 881 node = model()->other_node(); |
884 else if (location.button_type == DROP_OVERFLOW) | 882 else if (location.button_type == DROP_OVERFLOW) |
885 node = model_->bookmark_bar_node(); | 883 node = model()->bookmark_bar_node(); |
886 else | 884 else |
887 node = model_->bookmark_bar_node()->GetChild(location.index); | 885 node = model()->bookmark_bar_node()->GetChild(location.index); |
888 StartShowFolderDropMenuTimer(node); | 886 StartShowFolderDropMenuTimer(node); |
889 } | 887 } |
890 | 888 |
891 return drop_info_->location.operation; | 889 return drop_info_->location.operation; |
892 } | 890 } |
893 | 891 |
894 void BookmarkBarView::OnDragExited() { | 892 void BookmarkBarView::OnDragExited() { |
895 StopShowFolderDropMenuTimer(); | 893 StopShowFolderDropMenuTimer(); |
896 | 894 |
897 // NOTE: we don't hide the menu on exit as it's possible the user moved the | 895 // NOTE: we don't hide the menu on exit as it's possible the user moved the |
(...skipping 12 matching lines...) Expand all Loading... | |
910 StopShowFolderDropMenuTimer(); | 908 StopShowFolderDropMenuTimer(); |
911 | 909 |
912 if (bookmark_drop_menu_) | 910 if (bookmark_drop_menu_) |
913 bookmark_drop_menu_->Cancel(); | 911 bookmark_drop_menu_->Cancel(); |
914 | 912 |
915 if (!drop_info_.get() || !drop_info_->location.operation) | 913 if (!drop_info_.get() || !drop_info_->location.operation) |
916 return ui::DragDropTypes::DRAG_NONE; | 914 return ui::DragDropTypes::DRAG_NONE; |
917 | 915 |
918 const BookmarkNode* root = | 916 const BookmarkNode* root = |
919 (drop_info_->location.button_type == DROP_OTHER_FOLDER) ? | 917 (drop_info_->location.button_type == DROP_OTHER_FOLDER) ? |
920 model_->other_node() : model_->bookmark_bar_node(); | 918 model()->other_node() : model()->bookmark_bar_node(); |
921 int index = drop_info_->location.index; | 919 int index = drop_info_->location.index; |
922 | 920 |
923 if (index != -1) { | 921 if (index != -1) { |
924 // TODO(sky): optimize the SchedulePaint region. | 922 // TODO(sky): optimize the SchedulePaint region. |
925 SchedulePaint(); | 923 SchedulePaint(); |
926 } | 924 } |
927 const BookmarkNode* parent_node; | 925 const BookmarkNode* parent_node; |
928 if (drop_info_->location.button_type == DROP_OTHER_FOLDER) { | 926 if (drop_info_->location.button_type == DROP_OTHER_FOLDER) { |
929 parent_node = root; | 927 parent_node = root; |
930 index = parent_node->child_count(); | 928 index = parent_node->child_count(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
987 } else if (bookmark_bar_state_ == BookmarkBar::DETACHED) { | 985 } else if (bookmark_bar_state_ == BookmarkBar::DETACHED) { |
988 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView", | 986 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView", |
989 time_from_install); | 987 time_from_install); |
990 } | 988 } |
991 | 989 |
992 chrome::ShowImportDialog(browser_); | 990 chrome::ShowImportDialog(browser_); |
993 } | 991 } |
994 | 992 |
995 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { | 993 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { |
996 StopThrobbing(true); | 994 StopThrobbing(true); |
997 const BookmarkNode* node = model_->GetMostRecentlyAddedUserNodeForURL(url); | 995 const BookmarkNode* node = model()->GetMostRecentlyAddedUserNodeForURL(url); |
998 if (!node) | 996 if (!node) |
999 return; // Generally shouldn't happen. | 997 return; // Generally shouldn't happen. |
1000 StartThrobbing(node, false); | 998 StartThrobbing(node, false); |
1001 } | 999 } |
1002 | 1000 |
1003 void BookmarkBarView::OnBookmarkBubbleHidden() { | 1001 void BookmarkBarView::OnBookmarkBubbleHidden() { |
1004 StopThrobbing(false); | 1002 StopThrobbing(false); |
1005 } | 1003 } |
1006 | 1004 |
1007 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, | 1005 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, |
1008 bool ids_reassigned) { | 1006 bool ids_reassigned) { |
1009 // There should be no buttons. If non-zero it means Load was invoked more than | 1007 // There should be no buttons. If non-zero it means Load was invoked more than |
1010 // once, or we didn't properly clear things. Either of which shouldn't happen. | 1008 // once, or we didn't properly clear things. Either of which shouldn't happen. |
1011 DCHECK_EQ(0, GetBookmarkButtonCount()); | 1009 DCHECK_EQ(0, GetBookmarkButtonCount()); |
1012 const BookmarkNode* node = model_->bookmark_bar_node(); | 1010 const BookmarkNode* node = model->bookmark_bar_node(); |
1013 DCHECK(node); | 1011 DCHECK(node); |
1014 // Create a button for each of the children on the bookmark bar. | 1012 // Create a button for each of the children on the bookmark bar. |
1015 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) | 1013 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) |
1016 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); | 1014 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); |
1017 DCHECK(model_->other_node()); | 1015 DCHECK(model->other_node()); |
1018 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); | 1016 other_bookmarked_button_->SetAccessibleName(model->other_node()->GetTitle()); |
1019 other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); | 1017 other_bookmarked_button_->SetText(model->other_node()->GetTitle()); |
1020 managed_bookmarks_button_->SetAccessibleName( | 1018 managed_bookmarks_button_->SetAccessibleName( |
1021 client_->managed_node()->GetTitle()); | 1019 client_->managed_node()->GetTitle()); |
1022 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); | 1020 managed_bookmarks_button_->SetText(client_->managed_node()->GetTitle()); |
1023 UpdateColors(); | 1021 UpdateColors(); |
1024 UpdateButtonsVisibility(); | 1022 UpdateButtonsVisibility(); |
1025 other_bookmarked_button_->SetEnabled(true); | 1023 other_bookmarked_button_->SetEnabled(true); |
1026 managed_bookmarks_button_->SetEnabled(true); | 1024 managed_bookmarks_button_->SetEnabled(true); |
1027 | 1025 |
1028 Layout(); | 1026 Layout(); |
1029 SchedulePaint(); | 1027 SchedulePaint(); |
1030 } | 1028 } |
1031 | 1029 |
1032 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1030 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
1033 NOTREACHED(); | 1031 NOTREACHED(); |
1034 // Do minimal cleanup, presumably we'll be deleted shortly. | 1032 // Do minimal cleanup, presumably we'll be deleted shortly. |
1035 model_->RemoveObserver(this); | 1033 model->RemoveObserver(this); |
1036 model_ = NULL; | |
1037 client_ = NULL; | 1034 client_ = NULL; |
1038 } | 1035 } |
1039 | 1036 |
1040 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, | 1037 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
1041 const BookmarkNode* old_parent, | 1038 const BookmarkNode* old_parent, |
1042 int old_index, | 1039 int old_index, |
1043 const BookmarkNode* new_parent, | 1040 const BookmarkNode* new_parent, |
1044 int new_index) { | 1041 int new_index) { |
1045 bool was_throbbing = throbbing_view_ && | 1042 bool was_throbbing = throbbing_view_ && |
1046 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); | 1043 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 SchedulePaint(); | 1082 SchedulePaint(); |
1086 } | 1083 } |
1087 | 1084 |
1088 void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, | 1085 void BookmarkBarView::BookmarkNodeChanged(BookmarkModel* model, |
1089 const BookmarkNode* node) { | 1086 const BookmarkNode* node) { |
1090 BookmarkNodeChangedImpl(model, node); | 1087 BookmarkNodeChangedImpl(model, node); |
1091 } | 1088 } |
1092 | 1089 |
1093 void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, | 1090 void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, |
1094 const BookmarkNode* node) { | 1091 const BookmarkNode* node) { |
1095 if (node != model_->bookmark_bar_node()) | 1092 if (node != model->bookmark_bar_node()) |
1096 return; // We only care about reordering of the bookmark bar node. | 1093 return; // We only care about reordering of the bookmark bar node. |
1097 | 1094 |
1098 // Remove the existing buttons. | 1095 // Remove the existing buttons. |
1099 while (GetBookmarkButtonCount()) { | 1096 while (GetBookmarkButtonCount()) { |
1100 views::View* button = child_at(0); | 1097 views::View* button = child_at(0); |
1101 RemoveChildView(button); | 1098 RemoveChildView(button); |
1102 base::MessageLoop::current()->DeleteSoon(FROM_HERE, button); | 1099 base::MessageLoop::current()->DeleteSoon(FROM_HERE, button); |
1103 } | 1100 } |
1104 | 1101 |
1105 // Create the new buttons. | 1102 // Create the new buttons. |
(...skipping 17 matching lines...) Expand all Loading... | |
1123 | 1120 |
1124 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1121 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
1125 if (sender == GetBookmarkButton(i)) { | 1122 if (sender == GetBookmarkButton(i)) { |
1126 views::TextButton* button = GetBookmarkButton(i); | 1123 views::TextButton* button = GetBookmarkButton(i); |
1127 scoped_ptr<gfx::Canvas> canvas( | 1124 scoped_ptr<gfx::Canvas> canvas( |
1128 views::GetCanvasForDragImage(button->GetWidget(), button->size())); | 1125 views::GetCanvasForDragImage(button->GetWidget(), button->size())); |
1129 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); | 1126 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); |
1130 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), | 1127 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), |
1131 press_pt.OffsetFromOrigin(), | 1128 press_pt.OffsetFromOrigin(), |
1132 data); | 1129 data); |
1133 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); | 1130 WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data); |
1134 return; | 1131 return; |
1135 } | 1132 } |
1136 } | 1133 } |
1137 NOTREACHED(); | 1134 NOTREACHED(); |
1138 } | 1135 } |
1139 | 1136 |
1140 int BookmarkBarView::GetDragOperationsForView(View* sender, | 1137 int BookmarkBarView::GetDragOperationsForView(View* sender, |
1141 const gfx::Point& p) { | 1138 const gfx::Point& p) { |
1142 if (size_animation_->is_animating() || | 1139 if (size_animation_->is_animating() || |
1143 (size_animation_->GetCurrentValue() == 0 && | 1140 (size_animation_->GetCurrentValue() == 0 && |
1144 bookmark_bar_state_ != BookmarkBar::DETACHED)) { | 1141 bookmark_bar_state_ != BookmarkBar::DETACHED)) { |
1145 // Don't let the user drag while animating open or we're closed (and not | 1142 // Don't let the user drag while animating open or we're closed (and not |
1146 // detached, when detached size_animation_ is always 0). This typically is | 1143 // detached, when detached size_animation_ is always 0). This typically is |
1147 // only hit if the user does something to inadvertently trigger DnD such as | 1144 // only hit if the user does something to inadvertently trigger DnD such as |
1148 // pressing the mouse and hitting control-b. | 1145 // pressing the mouse and hitting control-b. |
1149 return ui::DragDropTypes::DRAG_NONE; | 1146 return ui::DragDropTypes::DRAG_NONE; |
1150 } | 1147 } |
1151 | 1148 |
1152 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1149 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
1153 if (sender == GetBookmarkButton(i)) { | 1150 if (sender == GetBookmarkButton(i)) { |
1154 return chrome::GetBookmarkDragOperation( | 1151 return chrome::GetBookmarkDragOperation( |
1155 browser_->profile(), model_->bookmark_bar_node()->GetChild(i)); | 1152 browser_->profile(), model()->bookmark_bar_node()->GetChild(i)); |
1156 } | 1153 } |
1157 } | 1154 } |
1158 NOTREACHED(); | 1155 NOTREACHED(); |
1159 return ui::DragDropTypes::DRAG_NONE; | 1156 return ui::DragDropTypes::DRAG_NONE; |
1160 } | 1157 } |
1161 | 1158 |
1162 bool BookmarkBarView::CanStartDragForView(views::View* sender, | 1159 bool BookmarkBarView::CanStartDragForView(views::View* sender, |
1163 const gfx::Point& press_pt, | 1160 const gfx::Point& press_pt, |
1164 const gfx::Point& p) { | 1161 const gfx::Point& p) { |
1165 // Check if we have not moved enough horizontally but we have moved downward | 1162 // Check if we have not moved enough horizontally but we have moved downward |
1166 // vertically - downward drag. | 1163 // vertically - downward drag. |
1167 gfx::Vector2d move_offset = p - press_pt; | 1164 gfx::Vector2d move_offset = p - press_pt; |
1168 gfx::Vector2d horizontal_offset(move_offset.x(), 0); | 1165 gfx::Vector2d horizontal_offset(move_offset.x(), 0); |
1169 if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { | 1166 if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { |
1170 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1167 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
1171 if (sender == GetBookmarkButton(i)) { | 1168 if (sender == GetBookmarkButton(i)) { |
1172 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); | 1169 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); |
1173 // If the folder button was dragged, show the menu instead. | 1170 // If the folder button was dragged, show the menu instead. |
1174 if (node && node->is_folder()) { | 1171 if (node && node->is_folder()) { |
1175 views::MenuButton* menu_button = | 1172 views::MenuButton* menu_button = |
1176 static_cast<views::MenuButton*>(sender); | 1173 static_cast<views::MenuButton*>(sender); |
1177 menu_button->Activate(); | 1174 menu_button->Activate(); |
1178 return false; | 1175 return false; |
1179 } | 1176 } |
1180 break; | 1177 break; |
1181 } | 1178 } |
1182 } | 1179 } |
1183 } | 1180 } |
1184 return true; | 1181 return true; |
1185 } | 1182 } |
1186 | 1183 |
1187 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1184 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
1188 const gfx::Point& point) { | 1185 const gfx::Point& point) { |
1189 const BookmarkNode* node; | 1186 const BookmarkNode* node; |
1190 | 1187 |
1191 int start_index = 0; | 1188 int start_index = 0; |
1192 if (view == other_bookmarked_button_) { | 1189 if (view == other_bookmarked_button_) { |
1193 node = model_->other_node(); | 1190 node = model()->other_node(); |
1194 } else if (view == managed_bookmarks_button_) { | 1191 } else if (view == managed_bookmarks_button_) { |
1195 node = client_->managed_node(); | 1192 node = client_->managed_node(); |
1196 } else if (view == overflow_button_) { | 1193 } else if (view == overflow_button_) { |
1197 node = model_->bookmark_bar_node(); | 1194 node = model()->bookmark_bar_node(); |
1198 start_index = GetFirstHiddenNodeIndex(); | 1195 start_index = GetFirstHiddenNodeIndex(); |
1199 } else { | 1196 } else { |
1200 int button_index = GetIndexOf(view); | 1197 int button_index = GetIndexOf(view); |
1201 DCHECK_NE(-1, button_index); | 1198 DCHECK_NE(-1, button_index); |
1202 node = model_->bookmark_bar_node()->GetChild(button_index); | 1199 node = model()->bookmark_bar_node()->GetChild(button_index); |
1203 } | 1200 } |
1204 | 1201 |
1205 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1202 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
1206 bookmark_menu_ = new BookmarkMenuController( | 1203 bookmark_menu_ = new BookmarkMenuController( |
1207 browser_, page_navigator_, GetWidget(), node, start_index); | 1204 browser_, page_navigator_, GetWidget(), node, start_index); |
1208 bookmark_menu_->set_observer(this); | 1205 bookmark_menu_->set_observer(this); |
1209 bookmark_menu_->RunMenuAt(this, false); | 1206 bookmark_menu_->RunMenuAt(this, false); |
1210 } | 1207 } |
1211 | 1208 |
1212 void BookmarkBarView::ButtonPressed(views::Button* sender, | 1209 void BookmarkBarView::ButtonPressed(views::Button* sender, |
1213 const ui::Event& event) { | 1210 const ui::Event& event) { |
1214 WindowOpenDisposition disposition_from_event_flags = | 1211 WindowOpenDisposition disposition_from_event_flags = |
1215 ui::DispositionFromEventFlags(event.flags()); | 1212 ui::DispositionFromEventFlags(event.flags()); |
1216 | 1213 |
1217 if (sender->tag() == kAppsShortcutButtonTag) { | 1214 if (sender->tag() == kAppsShortcutButtonTag) { |
1218 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), | 1215 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), |
1219 Referrer(), | 1216 Referrer(), |
1220 disposition_from_event_flags, | 1217 disposition_from_event_flags, |
1221 content::PAGE_TRANSITION_AUTO_BOOKMARK, | 1218 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
1222 false); | 1219 false); |
1223 page_navigator_->OpenURL(params); | 1220 page_navigator_->OpenURL(params); |
1224 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1221 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
1225 return; | 1222 return; |
1226 } | 1223 } |
1227 | 1224 |
1228 const BookmarkNode* node; | 1225 const BookmarkNode* node; |
1229 if (sender->tag() == kOtherFolderButtonTag) { | 1226 if (sender->tag() == kOtherFolderButtonTag) { |
1230 node = model_->other_node(); | 1227 node = model()->other_node(); |
1231 } else if (sender->tag() == kManagedFolderButtonTag) { | 1228 } else if (sender->tag() == kManagedFolderButtonTag) { |
1232 node = client_->managed_node(); | 1229 node = client_->managed_node(); |
1233 } else { | 1230 } else { |
1234 int index = GetIndexOf(sender); | 1231 int index = GetIndexOf(sender); |
1235 DCHECK_NE(-1, index); | 1232 DCHECK_NE(-1, index); |
1236 node = model_->bookmark_bar_node()->GetChild(index); | 1233 node = model()->bookmark_bar_node()->GetChild(index); |
1237 } | 1234 } |
1238 DCHECK(page_navigator_); | 1235 DCHECK(page_navigator_); |
1239 | 1236 |
1240 if (node->is_url()) { | 1237 if (node->is_url()) { |
1241 RecordAppLaunch(browser_->profile(), node->url()); | 1238 RecordAppLaunch(browser_->profile(), node->url()); |
1242 OpenURLParams params( | 1239 OpenURLParams params( |
1243 node->url(), Referrer(), disposition_from_event_flags, | 1240 node->url(), Referrer(), disposition_from_event_flags, |
1244 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); | 1241 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); |
1245 page_navigator_->OpenURL(params); | 1242 page_navigator_->OpenURL(params); |
1246 } else { | 1243 } else { |
1247 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, | 1244 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, |
1248 disposition_from_event_flags, browser_->profile()); | 1245 disposition_from_event_flags, browser_->profile()); |
1249 } | 1246 } |
1250 | 1247 |
1251 RecordBookmarkLaunch(node, GetBookmarkLaunchLocation()); | 1248 RecordBookmarkLaunch(node, GetBookmarkLaunchLocation()); |
1252 } | 1249 } |
1253 | 1250 |
1254 void BookmarkBarView::ShowContextMenuForView(views::View* source, | 1251 void BookmarkBarView::ShowContextMenuForView(views::View* source, |
1255 const gfx::Point& point, | 1252 const gfx::Point& point, |
1256 ui::MenuSourceType source_type) { | 1253 ui::MenuSourceType source_type) { |
1257 if (!model_->loaded()) { | 1254 if (!model()->loaded()) { |
1258 // Don't do anything if the model isn't loaded. | 1255 // Don't do anything if the model isn't loaded. |
1259 return; | 1256 return; |
1260 } | 1257 } |
1261 | 1258 |
1262 const BookmarkNode* parent = NULL; | 1259 const BookmarkNode* parent = NULL; |
1263 std::vector<const BookmarkNode*> nodes; | 1260 std::vector<const BookmarkNode*> nodes; |
1264 if (source == other_bookmarked_button_) { | 1261 if (source == other_bookmarked_button_) { |
1265 parent = model_->other_node(); | 1262 parent = model()->other_node(); |
1266 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1263 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
1267 // sure the user can't edit/delete the node in this case. | 1264 // sure the user can't edit/delete the node in this case. |
1268 nodes.push_back(parent); | 1265 nodes.push_back(parent); |
1269 } else if (source == managed_bookmarks_button_) { | 1266 } else if (source == managed_bookmarks_button_) { |
1270 parent = client_->managed_node(); | 1267 parent = client_->managed_node(); |
1271 nodes.push_back(parent); | 1268 nodes.push_back(parent); |
1272 } else if (source != this && source != apps_page_shortcut_) { | 1269 } else if (source != this && source != apps_page_shortcut_) { |
1273 // User clicked on one of the bookmark buttons, find which one they | 1270 // User clicked on one of the bookmark buttons, find which one they |
1274 // clicked on, except for the apps page shortcut, which must behave as if | 1271 // clicked on, except for the apps page shortcut, which must behave as if |
1275 // the user clicked on the bookmark bar background. | 1272 // the user clicked on the bookmark bar background. |
1276 int bookmark_button_index = GetIndexOf(source); | 1273 int bookmark_button_index = GetIndexOf(source); |
1277 DCHECK(bookmark_button_index != -1 && | 1274 DCHECK(bookmark_button_index != -1 && |
1278 bookmark_button_index < GetBookmarkButtonCount()); | 1275 bookmark_button_index < GetBookmarkButtonCount()); |
1279 const BookmarkNode* node = | 1276 const BookmarkNode* node = |
1280 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1277 model()->bookmark_bar_node()->GetChild(bookmark_button_index); |
1281 nodes.push_back(node); | 1278 nodes.push_back(node); |
1282 parent = node->parent(); | 1279 parent = node->parent(); |
1283 } else { | 1280 } else { |
1284 parent = model_->bookmark_bar_node(); | 1281 parent = model()->bookmark_bar_node(); |
1285 nodes.push_back(parent); | 1282 nodes.push_back(parent); |
1286 } | 1283 } |
1287 bool close_on_remove = | 1284 bool close_on_remove = |
1288 (parent == model_->other_node()) && (parent->child_count() == 1); | 1285 (parent == model()->other_node()) && (parent->child_count() == 1); |
1289 | 1286 |
1290 context_menu_.reset(new BookmarkContextMenu( | 1287 context_menu_.reset(new BookmarkContextMenu( |
1291 GetWidget(), browser_, browser_->profile(), | 1288 GetWidget(), browser_, browser_->profile(), |
1292 browser_->tab_strip_model()->GetActiveWebContents(), | 1289 browser_->tab_strip_model()->GetActiveWebContents(), |
1293 parent, nodes, close_on_remove)); | 1290 parent, nodes, close_on_remove)); |
1294 context_menu_->RunMenuAt(point, source_type); | 1291 context_menu_->RunMenuAt(point, source_type); |
1295 } | 1292 } |
1296 | 1293 |
1297 void BookmarkBarView::Init() { | 1294 void BookmarkBarView::Init() { |
1298 // Note that at this point we're not in a hierarchy so GetThemeProvider() will | 1295 // Note that at this point we're not in a hierarchy so GetThemeProvider() will |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1332 | 1329 |
1333 instructions_ = new BookmarkBarInstructionsView(this); | 1330 instructions_ = new BookmarkBarInstructionsView(this); |
1334 AddChildView(instructions_); | 1331 AddChildView(instructions_); |
1335 | 1332 |
1336 set_context_menu_controller(this); | 1333 set_context_menu_controller(this); |
1337 | 1334 |
1338 size_animation_.reset(new gfx::SlideAnimation(this)); | 1335 size_animation_.reset(new gfx::SlideAnimation(this)); |
1339 | 1336 |
1340 client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile( | 1337 client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile( |
1341 browser_->profile()); | 1338 browser_->profile()); |
1342 model_ = client_->model(); | 1339 if (client_) { |
sky
2014/06/06 19:49:20
I'm not sure this ever happens, but I suppose that
Joao da Silva
2014/06/06 20:12:18
BookmarkModelFactory::ServiceIsNULLWhileTesting()
| |
1343 if (model_) { | 1340 model()->AddObserver(this); |
1344 model_->AddObserver(this); | 1341 if (model()->loaded()) |
1345 if (model_->loaded()) | 1342 BookmarkModelLoaded(model(), false); |
1346 BookmarkModelLoaded(model_, false); | |
1347 // else case: we'll receive notification back from the BookmarkModel when | 1343 // else case: we'll receive notification back from the BookmarkModel when |
1348 // done loading, then we'll populate the bar. | 1344 // done loading, then we'll populate the bar. |
1349 } | 1345 } |
1350 } | 1346 } |
1351 | 1347 |
1352 int BookmarkBarView::GetBookmarkButtonCount() const { | 1348 int BookmarkBarView::GetBookmarkButtonCount() const { |
1353 // We contain six non-bookmark button views: managed bookmarks, | 1349 // We contain six non-bookmark button views: managed bookmarks, |
1354 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, | 1350 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, |
1355 // and the instruction label. | 1351 // and the instruction label. |
1356 return child_count() - 6; | 1352 return child_count() - 6; |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1457 // We don't always have a theme provider (ui tests, for example). | 1453 // We don't always have a theme provider (ui tests, for example). |
1458 if (GetThemeProvider()) { | 1454 if (GetThemeProvider()) { |
1459 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1455 button->SetEnabledColor(GetThemeProvider()->GetColor( |
1460 ThemeProperties::COLOR_BOOKMARK_TEXT)); | 1456 ThemeProperties::COLOR_BOOKMARK_TEXT)); |
1461 } | 1457 } |
1462 | 1458 |
1463 button->ClearMaxTextSize(); | 1459 button->ClearMaxTextSize(); |
1464 button->set_context_menu_controller(this); | 1460 button->set_context_menu_controller(this); |
1465 button->set_drag_controller(this); | 1461 button->set_drag_controller(this); |
1466 if (node->is_url()) { | 1462 if (node->is_url()) { |
1467 const gfx::Image& favicon = model_->GetFavicon(node); | 1463 const gfx::Image& favicon = model()->GetFavicon(node); |
1468 if (!favicon.IsEmpty()) | 1464 if (!favicon.IsEmpty()) |
1469 button->SetIcon(*favicon.ToImageSkia()); | 1465 button->SetIcon(*favicon.ToImageSkia()); |
1470 else | 1466 else |
1471 button->SetIcon(GetDefaultFavicon()); | 1467 button->SetIcon(GetDefaultFavicon()); |
1472 } | 1468 } |
1473 button->set_max_width(kMaxButtonWidth); | 1469 button->set_max_width(kMaxButtonWidth); |
1474 } | 1470 } |
1475 | 1471 |
1476 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 1472 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
1477 const BookmarkNode* parent, | 1473 const BookmarkNode* parent, |
1478 int index) { | 1474 int index) { |
1479 UpdateButtonsVisibility(); | 1475 UpdateButtonsVisibility(); |
1480 if (parent != model_->bookmark_bar_node()) { | 1476 if (parent != model->bookmark_bar_node()) { |
1481 // We only care about nodes on the bookmark bar. | 1477 // We only care about nodes on the bookmark bar. |
1482 return; | 1478 return; |
1483 } | 1479 } |
1484 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); | 1480 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); |
1485 const BookmarkNode* node = parent->GetChild(index); | 1481 const BookmarkNode* node = parent->GetChild(index); |
1486 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: | 1482 ProfileSyncService* sync_service(ProfileSyncServiceFactory:: |
1487 GetInstance()->GetForProfile(browser_->profile())); | 1483 GetInstance()->GetForProfile(browser_->profile())); |
1488 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress()) | 1484 if (!throbbing_view_ && sync_service && sync_service->FirstSetupInProgress()) |
1489 StartThrobbing(node, true); | 1485 StartThrobbing(node, true); |
1490 AddChildViewAt(CreateBookmarkButton(node), index); | 1486 AddChildViewAt(CreateBookmarkButton(node), index); |
1491 UpdateColors(); | 1487 UpdateColors(); |
1492 Layout(); | 1488 Layout(); |
1493 SchedulePaint(); | 1489 SchedulePaint(); |
1494 } | 1490 } |
1495 | 1491 |
1496 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, | 1492 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, |
1497 const BookmarkNode* parent, | 1493 const BookmarkNode* parent, |
1498 int index) { | 1494 int index) { |
1499 UpdateButtonsVisibility(); | 1495 UpdateButtonsVisibility(); |
1500 | 1496 |
1501 StopThrobbing(true); | 1497 StopThrobbing(true); |
1502 // No need to start throbbing again as the bookmark bubble can't be up at | 1498 // No need to start throbbing again as the bookmark bubble can't be up at |
1503 // the same time as the user reorders. | 1499 // the same time as the user reorders. |
1504 | 1500 |
1505 if (parent != model_->bookmark_bar_node()) { | 1501 if (parent != model->bookmark_bar_node()) { |
1506 // We only care about nodes on the bookmark bar. | 1502 // We only care about nodes on the bookmark bar. |
1507 return; | 1503 return; |
1508 } | 1504 } |
1509 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); | 1505 DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
1510 views::View* button = child_at(index); | 1506 views::View* button = child_at(index); |
1511 RemoveChildView(button); | 1507 RemoveChildView(button); |
1512 base::MessageLoop::current()->DeleteSoon(FROM_HERE, button); | 1508 base::MessageLoop::current()->DeleteSoon(FROM_HERE, button); |
1513 Layout(); | 1509 Layout(); |
1514 SchedulePaint(); | 1510 SchedulePaint(); |
1515 } | 1511 } |
1516 | 1512 |
1517 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1513 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
1518 const BookmarkNode* node) { | 1514 const BookmarkNode* node) { |
1519 if (node->parent() != model_->bookmark_bar_node()) { | 1515 if (node->parent() != model->bookmark_bar_node()) { |
1520 // We only care about nodes on the bookmark bar. | 1516 // We only care about nodes on the bookmark bar. |
1521 return; | 1517 return; |
1522 } | 1518 } |
1523 int index = model_->bookmark_bar_node()->GetIndexOf(node); | 1519 int index = model->bookmark_bar_node()->GetIndexOf(node); |
1524 DCHECK_NE(-1, index); | 1520 DCHECK_NE(-1, index); |
1525 views::TextButton* button = GetBookmarkButton(index); | 1521 views::TextButton* button = GetBookmarkButton(index); |
1526 gfx::Size old_pref = button->GetPreferredSize(); | 1522 gfx::Size old_pref = button->GetPreferredSize(); |
1527 ConfigureButton(node, button); | 1523 ConfigureButton(node, button); |
1528 gfx::Size new_pref = button->GetPreferredSize(); | 1524 gfx::Size new_pref = button->GetPreferredSize(); |
1529 if (old_pref.width() != new_pref.width()) { | 1525 if (old_pref.width() != new_pref.width()) { |
1530 Layout(); | 1526 Layout(); |
1531 SchedulePaint(); | 1527 SchedulePaint(); |
1532 } else if (button->visible()) { | 1528 } else if (button->visible()) { |
1533 button->SchedulePaint(); | 1529 button->SchedulePaint(); |
1534 } | 1530 } |
1535 } | 1531 } |
1536 | 1532 |
1537 void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) { | 1533 void BookmarkBarView::ShowDropFolderForNode(const BookmarkNode* node) { |
1538 if (bookmark_drop_menu_) { | 1534 if (bookmark_drop_menu_) { |
1539 if (bookmark_drop_menu_->node() == node) { | 1535 if (bookmark_drop_menu_->node() == node) { |
1540 // Already showing for the specified node. | 1536 // Already showing for the specified node. |
1541 return; | 1537 return; |
1542 } | 1538 } |
1543 bookmark_drop_menu_->Cancel(); | 1539 bookmark_drop_menu_->Cancel(); |
1544 } | 1540 } |
1545 | 1541 |
1546 views::MenuButton* menu_button = GetMenuButtonForNode(node); | 1542 views::MenuButton* menu_button = GetMenuButtonForNode(node); |
1547 if (!menu_button) | 1543 if (!menu_button) |
1548 return; | 1544 return; |
1549 | 1545 |
1550 int start_index = 0; | 1546 int start_index = 0; |
1551 if (node == model_->bookmark_bar_node()) | 1547 if (node == model()->bookmark_bar_node()) |
1552 start_index = GetFirstHiddenNodeIndex(); | 1548 start_index = GetFirstHiddenNodeIndex(); |
1553 | 1549 |
1554 drop_info_->is_menu_showing = true; | 1550 drop_info_->is_menu_showing = true; |
1555 bookmark_drop_menu_ = new BookmarkMenuController(browser_, | 1551 bookmark_drop_menu_ = new BookmarkMenuController(browser_, |
1556 page_navigator_, GetWidget(), node, start_index); | 1552 page_navigator_, GetWidget(), node, start_index); |
1557 bookmark_drop_menu_->set_observer(this); | 1553 bookmark_drop_menu_->set_observer(this); |
1558 bookmark_drop_menu_->RunMenuAt(this, true); | 1554 bookmark_drop_menu_->RunMenuAt(this, true); |
1559 } | 1555 } |
1560 | 1556 |
1561 void BookmarkBarView::StopShowFolderDropMenuTimer() { | 1557 void BookmarkBarView::StopShowFolderDropMenuTimer() { |
(...skipping 12 matching lines...) Expand all Loading... | |
1574 FROM_HERE, | 1570 FROM_HERE, |
1575 base::Bind(&BookmarkBarView::ShowDropFolderForNode, | 1571 base::Bind(&BookmarkBarView::ShowDropFolderForNode, |
1576 show_folder_method_factory_.GetWeakPtr(), | 1572 show_folder_method_factory_.GetWeakPtr(), |
1577 node), | 1573 node), |
1578 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 1574 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
1579 } | 1575 } |
1580 | 1576 |
1581 void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, | 1577 void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, |
1582 const BookmarkNodeData& data, | 1578 const BookmarkNodeData& data, |
1583 DropLocation* location) { | 1579 DropLocation* location) { |
1584 DCHECK(model_); | 1580 DCHECK(client_); |
1585 DCHECK(model_->loaded()); | 1581 DCHECK(model()->loaded()); |
1586 DCHECK(data.is_valid()); | 1582 DCHECK(data.is_valid()); |
1587 | 1583 |
1588 *location = DropLocation(); | 1584 *location = DropLocation(); |
1589 | 1585 |
1590 // The drop event uses the screen coordinates while the child Views are | 1586 // The drop event uses the screen coordinates while the child Views are |
1591 // always laid out from left to right (even though they are rendered from | 1587 // always laid out from left to right (even though they are rendered from |
1592 // right-to-left on RTL locales). Thus, in order to make sure the drop | 1588 // right-to-left on RTL locales). Thus, in order to make sure the drop |
1593 // coordinates calculation works, we mirror the event's X coordinate if the | 1589 // coordinates calculation works, we mirror the event's X coordinate if the |
1594 // locale is RTL. | 1590 // locale is RTL. |
1595 int mirrored_x = GetMirroredXInView(event.x()); | 1591 int mirrored_x = GetMirroredXInView(event.x()); |
1596 | 1592 |
1597 bool found = false; | 1593 bool found = false; |
1598 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); | 1594 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); |
1599 Profile* profile = browser_->profile(); | 1595 Profile* profile = browser_->profile(); |
1600 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && | 1596 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && |
1601 other_delta_x < other_bookmarked_button_->width()) { | 1597 other_delta_x < other_bookmarked_button_->width()) { |
1602 // Mouse is over 'other' folder. | 1598 // Mouse is over 'other' folder. |
1603 location->button_type = DROP_OTHER_FOLDER; | 1599 location->button_type = DROP_OTHER_FOLDER; |
1604 location->on = true; | 1600 location->on = true; |
1605 found = true; | 1601 found = true; |
1606 } else if (!GetBookmarkButtonCount()) { | 1602 } else if (!GetBookmarkButtonCount()) { |
1607 // No bookmarks, accept the drop. | 1603 // No bookmarks, accept the drop. |
1608 location->index = 0; | 1604 location->index = 0; |
1609 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); | 1605 const BookmarkNode* node = data.GetFirstNode(model(), profile->GetPath()); |
1610 int ops = node && client_->CanBeEditedByUser(node) ? | 1606 int ops = node && client_->CanBeEditedByUser(node) ? |
1611 ui::DragDropTypes::DRAG_MOVE : | 1607 ui::DragDropTypes::DRAG_MOVE : |
1612 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1608 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
1613 location->operation = chrome::GetPreferredBookmarkDropOperation( | 1609 location->operation = chrome::GetPreferredBookmarkDropOperation( |
1614 event.source_operations(), ops); | 1610 event.source_operations(), ops); |
1615 return; | 1611 return; |
1616 } | 1612 } |
1617 | 1613 |
1618 for (int i = 0; i < GetBookmarkButtonCount() && | 1614 for (int i = 0; i < GetBookmarkButtonCount() && |
1619 GetBookmarkButton(i)->visible() && !found; i++) { | 1615 GetBookmarkButton(i)->visible() && !found; i++) { |
1620 views::TextButton* button = GetBookmarkButton(i); | 1616 views::TextButton* button = GetBookmarkButton(i); |
1621 int button_x = mirrored_x - button->x(); | 1617 int button_x = mirrored_x - button->x(); |
1622 int button_w = button->width(); | 1618 int button_w = button->width(); |
1623 if (button_x < button_w) { | 1619 if (button_x < button_w) { |
1624 found = true; | 1620 found = true; |
1625 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); | 1621 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); |
1626 if (node->is_folder()) { | 1622 if (node->is_folder()) { |
1627 if (button_x <= views::kDropBetweenPixels) { | 1623 if (button_x <= views::kDropBetweenPixels) { |
1628 location->index = i; | 1624 location->index = i; |
1629 } else if (button_x < button_w - views::kDropBetweenPixels) { | 1625 } else if (button_x < button_w - views::kDropBetweenPixels) { |
1630 location->index = i; | 1626 location->index = i; |
1631 location->on = true; | 1627 location->on = true; |
1632 } else { | 1628 } else { |
1633 location->index = i + 1; | 1629 location->index = i + 1; |
1634 } | 1630 } |
1635 } else if (button_x < button_w / 2) { | 1631 } else if (button_x < button_w / 2) { |
(...skipping 26 matching lines...) Expand all Loading... | |
1662 // Mouse is after the last visible button but before more recently | 1658 // Mouse is after the last visible button but before more recently |
1663 // bookmarked; use the last visible index. | 1659 // bookmarked; use the last visible index. |
1664 location->index = GetFirstHiddenNodeIndex(); | 1660 location->index = GetFirstHiddenNodeIndex(); |
1665 } else { | 1661 } else { |
1666 return; | 1662 return; |
1667 } | 1663 } |
1668 } | 1664 } |
1669 | 1665 |
1670 if (location->on) { | 1666 if (location->on) { |
1671 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? | 1667 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? |
1672 model_->other_node() : | 1668 model()->other_node() : |
1673 model_->bookmark_bar_node()->GetChild(location->index); | 1669 model()->bookmark_bar_node()->GetChild(location->index); |
1674 location->operation = chrome::GetBookmarkDropOperation( | 1670 location->operation = chrome::GetBookmarkDropOperation( |
1675 profile, event, data, parent, parent->child_count()); | 1671 profile, event, data, parent, parent->child_count()); |
1676 if (!location->operation && !data.has_single_url() && | 1672 if (!location->operation && !data.has_single_url() && |
1677 data.GetFirstNode(model_, profile->GetPath()) == parent) { | 1673 data.GetFirstNode(model(), profile->GetPath()) == parent) { |
1678 // Don't open a menu if the node being dragged is the menu to open. | 1674 // Don't open a menu if the node being dragged is the menu to open. |
1679 location->on = false; | 1675 location->on = false; |
1680 } | 1676 } |
1681 } else { | 1677 } else { |
1682 location->operation = chrome::GetBookmarkDropOperation( | 1678 location->operation = chrome::GetBookmarkDropOperation( |
1683 profile, event, data, model_->bookmark_bar_node(), location->index); | 1679 profile, event, data, model()->bookmark_bar_node(), location->index); |
1684 } | 1680 } |
1685 } | 1681 } |
1686 | 1682 |
1687 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, | 1683 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, |
1688 ui::OSExchangeData* data) { | 1684 ui::OSExchangeData* data) { |
1689 DCHECK(node && data); | 1685 DCHECK(node && data); |
1690 BookmarkNodeData drag_data(node); | 1686 BookmarkNodeData drag_data(node); |
1691 drag_data.Write(browser_->profile()->GetPath(), data); | 1687 drag_data.Write(browser_->profile()->GetPath(), data); |
1692 } | 1688 } |
1693 | 1689 |
1694 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, | 1690 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
1695 bool overflow_only) { | 1691 bool overflow_only) { |
1696 DCHECK(!throbbing_view_); | 1692 DCHECK(!throbbing_view_); |
1697 | 1693 |
1698 // Determine which visible button is showing the bookmark (or is an ancestor | 1694 // Determine which visible button is showing the bookmark (or is an ancestor |
1699 // of the bookmark). | 1695 // of the bookmark). |
1700 const BookmarkNode* bbn = model_->bookmark_bar_node(); | 1696 const BookmarkNode* bbn = model()->bookmark_bar_node(); |
1701 const BookmarkNode* parent_on_bb = node; | 1697 const BookmarkNode* parent_on_bb = node; |
1702 while (parent_on_bb) { | 1698 while (parent_on_bb) { |
1703 const BookmarkNode* parent = parent_on_bb->parent(); | 1699 const BookmarkNode* parent = parent_on_bb->parent(); |
1704 if (parent == bbn) | 1700 if (parent == bbn) |
1705 break; | 1701 break; |
1706 parent_on_bb = parent; | 1702 parent_on_bb = parent; |
1707 } | 1703 } |
1708 if (parent_on_bb) { | 1704 if (parent_on_bb) { |
1709 int index = bbn->GetIndexOf(parent_on_bb); | 1705 int index = bbn->GetIndexOf(parent_on_bb); |
1710 if (index >= GetFirstHiddenNodeIndex()) { | 1706 if (index >= GetFirstHiddenNodeIndex()) { |
1711 // Node is hidden, animate the overflow button. | 1707 // Node is hidden, animate the overflow button. |
1712 throbbing_view_ = overflow_button_; | 1708 throbbing_view_ = overflow_button_; |
1713 } else if (!overflow_only) { | 1709 } else if (!overflow_only) { |
1714 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1710 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
1715 } | 1711 } |
1716 } else if (client_->IsDescendantOfManagedNode(node)) { | 1712 } else if (client_->IsDescendantOfManagedNode(node)) { |
1717 throbbing_view_ = managed_bookmarks_button_; | 1713 throbbing_view_ = managed_bookmarks_button_; |
1718 } else if (!overflow_only) { | 1714 } else if (!overflow_only) { |
1719 throbbing_view_ = other_bookmarked_button_; | 1715 throbbing_view_ = other_bookmarked_button_; |
1720 } | 1716 } |
1721 | 1717 |
1722 // Use a large number so that the button continues to throb. | 1718 // Use a large number so that the button continues to throb. |
1723 if (throbbing_view_) | 1719 if (throbbing_view_) |
1724 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1720 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
1725 } | 1721 } |
1726 | 1722 |
1727 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( | 1723 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
1728 const BookmarkNode* parent, | 1724 const BookmarkNode* parent, |
1729 int old_index) { | 1725 int old_index) { |
1730 const BookmarkNode* bbn = model_->bookmark_bar_node(); | 1726 const BookmarkNode* bbn = model()->bookmark_bar_node(); |
1731 const BookmarkNode* old_node = parent; | 1727 const BookmarkNode* old_node = parent; |
1732 int old_index_on_bb = old_index; | 1728 int old_index_on_bb = old_index; |
1733 while (old_node && old_node != bbn) { | 1729 while (old_node && old_node != bbn) { |
1734 const BookmarkNode* parent = old_node->parent(); | 1730 const BookmarkNode* parent = old_node->parent(); |
1735 if (parent == bbn) { | 1731 if (parent == bbn) { |
1736 old_index_on_bb = bbn->GetIndexOf(old_node); | 1732 old_index_on_bb = bbn->GetIndexOf(old_node); |
1737 break; | 1733 break; |
1738 } | 1734 } |
1739 old_node = parent; | 1735 old_node = parent; |
1740 } | 1736 } |
(...skipping 19 matching lines...) Expand all Loading... | |
1760 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1756 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
1761 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1757 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
1762 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1758 GetBookmarkButton(i)->SetEnabledColor(text_color); |
1763 other_bookmarked_button_->SetEnabledColor(text_color); | 1759 other_bookmarked_button_->SetEnabledColor(text_color); |
1764 managed_bookmarks_button_->SetEnabledColor(text_color); | 1760 managed_bookmarks_button_->SetEnabledColor(text_color); |
1765 if (apps_page_shortcut_->visible()) | 1761 if (apps_page_shortcut_->visible()) |
1766 apps_page_shortcut_->SetEnabledColor(text_color); | 1762 apps_page_shortcut_->SetEnabledColor(text_color); |
1767 } | 1763 } |
1768 | 1764 |
1769 void BookmarkBarView::UpdateButtonsVisibility() { | 1765 void BookmarkBarView::UpdateButtonsVisibility() { |
1770 bool has_other_children = !model_->other_node()->empty(); | 1766 bool has_other_children = !model()->other_node()->empty(); |
1771 bool update_other = has_other_children != other_bookmarked_button_->visible(); | 1767 bool update_other = has_other_children != other_bookmarked_button_->visible(); |
1772 if (update_other) { | 1768 if (update_other) { |
1773 other_bookmarked_button_->SetVisible(has_other_children); | 1769 other_bookmarked_button_->SetVisible(has_other_children); |
1774 UpdateBookmarksSeparatorVisibility(); | 1770 UpdateBookmarksSeparatorVisibility(); |
1775 } | 1771 } |
1776 | 1772 |
1777 bool has_managed_children = !client_->managed_node()->empty(); | 1773 bool has_managed_children = !client_->managed_node()->empty(); |
1778 bool update_managed = | 1774 bool update_managed = |
1779 has_managed_children != managed_bookmarks_button_->visible(); | 1775 has_managed_children != managed_bookmarks_button_->visible(); |
1780 if (update_managed) | 1776 if (update_managed) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1844 // Then comes the managed bookmarks folder, if visible. | 1840 // Then comes the managed bookmarks folder, if visible. |
1845 if (managed_bookmarks_button_->visible()) { | 1841 if (managed_bookmarks_button_->visible()) { |
1846 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? | 1842 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? |
1847 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); | 1843 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
1848 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), | 1844 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), |
1849 height); | 1845 height); |
1850 x += managed_bookmarks_pref.width() + kButtonPadding; | 1846 x += managed_bookmarks_pref.width() + kButtonPadding; |
1851 } | 1847 } |
1852 | 1848 |
1853 // Then go through the bookmark buttons. | 1849 // Then go through the bookmark buttons. |
1854 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { | 1850 if (GetBookmarkButtonCount() == 0 && client_ && model()->loaded()) { |
1855 gfx::Size pref = instructions_->GetPreferredSize(); | 1851 gfx::Size pref = instructions_->GetPreferredSize(); |
1856 instructions_->SetBounds( | 1852 instructions_->SetBounds( |
1857 x + kInstructionsPadding, y, | 1853 x + kInstructionsPadding, y, |
1858 std::min(static_cast<int>(pref.width()), | 1854 std::min(static_cast<int>(pref.width()), |
1859 max_x - x), | 1855 max_x - x), |
1860 height); | 1856 height); |
1861 instructions_->SetVisible(true); | 1857 instructions_->SetVisible(true); |
1862 } else { | 1858 } else { |
1863 instructions_->SetVisible(false); | 1859 instructions_->SetVisible(false); |
1864 | 1860 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1907 DCHECK(apps_page_shortcut_); | 1903 DCHECK(apps_page_shortcut_); |
1908 // Only perform layout if required. | 1904 // Only perform layout if required. |
1909 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1905 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
1910 browser_->profile(), browser_->host_desktop_type()); | 1906 browser_->profile(), browser_->host_desktop_type()); |
1911 if (apps_page_shortcut_->visible() == visible) | 1907 if (apps_page_shortcut_->visible() == visible) |
1912 return; | 1908 return; |
1913 apps_page_shortcut_->SetVisible(visible); | 1909 apps_page_shortcut_->SetVisible(visible); |
1914 UpdateBookmarksSeparatorVisibility(); | 1910 UpdateBookmarksSeparatorVisibility(); |
1915 Layout(); | 1911 Layout(); |
1916 } | 1912 } |
OLD | NEW |