| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 | 355 |
| 356 // Returns the bitmap to use for starred folders. | 356 // Returns the bitmap to use for starred folders. |
| 357 static const SkBitmap& GetFolderIcon() { | 357 static const SkBitmap& GetFolderIcon() { |
| 358 if (!kFolderIcon) { | 358 if (!kFolderIcon) { |
| 359 kFolderIcon = ResourceBundle::GetSharedInstance(). | 359 kFolderIcon = ResourceBundle::GetSharedInstance(). |
| 360 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); | 360 GetBitmapNamed(IDR_BOOKMARK_BAR_FOLDER); |
| 361 } | 361 } |
| 362 return *kFolderIcon; | 362 return *kFolderIcon; |
| 363 } | 363 } |
| 364 | 364 |
| 365 BookmarkBarView::BookmarkBarView(Profile* profile, Browser* browser) | 365 BookmarkBarView::BookmarkBarView(Browser* browser) |
| 366 : profile_(NULL), | 366 : page_navigator_(NULL), |
| 367 page_navigator_(NULL), | |
| 368 model_(NULL), | 367 model_(NULL), |
| 369 bookmark_menu_(NULL), | 368 bookmark_menu_(NULL), |
| 370 bookmark_drop_menu_(NULL), | 369 bookmark_drop_menu_(NULL), |
| 371 other_bookmarked_button_(NULL), | 370 other_bookmarked_button_(NULL), |
| 372 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), | 371 ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), |
| 373 sync_error_button_(NULL), | 372 sync_error_button_(NULL), |
| 374 sync_service_(NULL), | 373 sync_service_(browser->profile()->GetProfileSyncService()), |
| 375 overflow_button_(NULL), | 374 overflow_button_(NULL), |
| 376 instructions_(NULL), | 375 instructions_(NULL), |
| 377 bookmarks_separator_view_(NULL), | 376 bookmarks_separator_view_(NULL), |
| 378 browser_(browser), | 377 browser_(browser), |
| 379 infobar_visible_(false), | 378 infobar_visible_(false), |
| 380 throbbing_view_(NULL), | 379 throbbing_view_(NULL), |
| 381 bookmark_bar_state_(BookmarkBar::SHOW), | 380 bookmark_bar_state_(BookmarkBar::SHOW), |
| 382 animating_detached_(false) { | 381 animating_detached_(false) { |
| 383 if (profile->GetProfileSyncService()) { | 382 if (sync_service_) |
| 384 // Obtain a pointer to the profile sync service and add our instance as an | |
| 385 // observer. | |
| 386 sync_service_ = profile->GetProfileSyncService(); | |
| 387 sync_service_->AddObserver(this); | 383 sync_service_->AddObserver(this); |
| 388 } | |
| 389 | 384 |
| 390 set_id(VIEW_ID_BOOKMARK_BAR); | 385 set_id(VIEW_ID_BOOKMARK_BAR); |
| 391 Init(); | 386 Init(); |
| 392 SetProfile(profile); | |
| 393 | 387 |
| 394 size_animation_->Reset(1); | 388 size_animation_->Reset(1); |
| 395 } | 389 } |
| 396 | 390 |
| 397 BookmarkBarView::~BookmarkBarView() { | 391 BookmarkBarView::~BookmarkBarView() { |
| 398 if (model_) | 392 if (model_) |
| 399 model_->RemoveObserver(this); | 393 model_->RemoveObserver(this); |
| 400 | 394 |
| 401 // It's possible for the menu to outlive us, reset the observer to make sure | 395 // It's possible for the menu to outlive us, reset the observer to make sure |
| 402 // it doesn't have a reference to us. | 396 // it doesn't have a reference to us. |
| 403 if (bookmark_menu_) | 397 if (bookmark_menu_) |
| 404 bookmark_menu_->set_observer(NULL); | 398 bookmark_menu_->set_observer(NULL); |
| 405 | 399 |
| 406 StopShowFolderDropMenuTimer(); | 400 StopShowFolderDropMenuTimer(); |
| 407 | 401 |
| 408 if (sync_service_) | 402 if (sync_service_) |
| 409 sync_service_->RemoveObserver(this); | 403 sync_service_->RemoveObserver(this); |
| 410 } | 404 } |
| 411 | 405 |
| 412 void BookmarkBarView::SetProfile(Profile* profile) { | |
| 413 DCHECK(profile); | |
| 414 if (profile_ == profile) | |
| 415 return; | |
| 416 | |
| 417 StopThrobbing(true); | |
| 418 | |
| 419 // Cancels the current cancelable. | |
| 420 registrar_.RemoveAll(); | |
| 421 | |
| 422 profile_ = profile; | |
| 423 | |
| 424 if (model_) | |
| 425 model_->RemoveObserver(this); | |
| 426 | |
| 427 // Disable the other bookmarked button, we'll re-enable when the model is | |
| 428 // loaded. | |
| 429 other_bookmarked_button_->SetEnabled(false); | |
| 430 | |
| 431 Source<Profile> ns_source(profile_->GetOriginalProfile()); | |
| 432 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN, ns_source); | |
| 433 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN, ns_source); | |
| 434 | |
| 435 // Remove any existing bookmark buttons. | |
| 436 while (GetBookmarkButtonCount()) | |
| 437 delete child_at(0); | |
| 438 | |
| 439 model_ = profile_->GetBookmarkModel(); | |
| 440 if (model_) { | |
| 441 model_->AddObserver(this); | |
| 442 if (model_->IsLoaded()) | |
| 443 Loaded(model_, false); | |
| 444 // else case: we'll receive notification back from the BookmarkModel when | |
| 445 // done loading, then we'll populate the bar. | |
| 446 } | |
| 447 } | |
| 448 | |
| 449 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { | 406 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { |
| 450 page_navigator_ = navigator; | 407 page_navigator_ = navigator; |
| 451 } | 408 } |
| 452 | 409 |
| 453 void BookmarkBarView::SetBookmarkBarState( | 410 void BookmarkBarView::SetBookmarkBarState( |
| 454 BookmarkBar::State state, | 411 BookmarkBar::State state, |
| 455 BookmarkBar::AnimateChangeType animate_type) { | 412 BookmarkBar::AnimateChangeType animate_type) { |
| 456 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE) { | 413 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE) { |
| 457 animating_detached_ = (state == BookmarkBar::DETACHED || | 414 animating_detached_ = (state == BookmarkBar::DETACHED || |
| 458 bookmark_bar_state_ == BookmarkBar::DETACHED); | 415 bookmark_bar_state_ == BookmarkBar::DETACHED); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat()); | 675 custom_formats->insert(BookmarkNodeData::GetBookmarkCustomFormat()); |
| 719 return true; | 676 return true; |
| 720 } | 677 } |
| 721 | 678 |
| 722 bool BookmarkBarView::AreDropTypesRequired() { | 679 bool BookmarkBarView::AreDropTypesRequired() { |
| 723 return true; | 680 return true; |
| 724 } | 681 } |
| 725 | 682 |
| 726 bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) { | 683 bool BookmarkBarView::CanDrop(const ui::OSExchangeData& data) { |
| 727 if (!model_ || !model_->IsLoaded() || | 684 if (!model_ || !model_->IsLoaded() || |
| 728 !profile_->GetPrefs()->GetBoolean(prefs::kEditBookmarksEnabled)) | 685 !browser_->profile()->GetPrefs()->GetBoolean( |
| 686 prefs::kEditBookmarksEnabled)) |
| 729 return false; | 687 return false; |
| 730 | 688 |
| 731 if (!drop_info_.get()) | 689 if (!drop_info_.get()) |
| 732 drop_info_.reset(new DropInfo()); | 690 drop_info_.reset(new DropInfo()); |
| 733 | 691 |
| 734 // Only accept drops of 1 node, which is the case for all data dragged from | 692 // Only accept drops of 1 node, which is the case for all data dragged from |
| 735 // bookmark bar and menus. | 693 // bookmark bar and menus. |
| 736 return drop_info_->data.Read(data) && drop_info_->data.size() == 1; | 694 return drop_info_->data.Read(data) && drop_info_->data.size() == 1; |
| 737 } | 695 } |
| 738 | 696 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 830 index = parent_node->child_count(); | 788 index = parent_node->child_count(); |
| 831 } else if (drop_info_->location.on) { | 789 } else if (drop_info_->location.on) { |
| 832 parent_node = root->GetChild(index); | 790 parent_node = root->GetChild(index); |
| 833 index = parent_node->child_count(); | 791 index = parent_node->child_count(); |
| 834 } else { | 792 } else { |
| 835 parent_node = root; | 793 parent_node = root; |
| 836 } | 794 } |
| 837 const BookmarkNodeData data = drop_info_->data; | 795 const BookmarkNodeData data = drop_info_->data; |
| 838 DCHECK(data.is_valid()); | 796 DCHECK(data.is_valid()); |
| 839 drop_info_.reset(); | 797 drop_info_.reset(); |
| 840 return bookmark_utils::PerformBookmarkDrop(profile_, data, parent_node, | 798 return bookmark_utils::PerformBookmarkDrop(browser_->profile(), data, |
| 841 index); | 799 parent_node, index); |
| 842 } | 800 } |
| 843 | 801 |
| 844 void BookmarkBarView::ShowContextMenu(const gfx::Point& p, | 802 void BookmarkBarView::ShowContextMenu(const gfx::Point& p, |
| 845 bool is_mouse_gesture) { | 803 bool is_mouse_gesture) { |
| 846 ShowContextMenuForView(this, p, is_mouse_gesture); | 804 ShowContextMenuForView(this, p, is_mouse_gesture); |
| 847 } | 805 } |
| 848 | 806 |
| 849 void BookmarkBarView::OnThemeChanged() { | 807 void BookmarkBarView::OnThemeChanged() { |
| 850 UpdateColors(); | 808 UpdateColors(); |
| 851 } | 809 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 // Don't let the user drag while animating open or we're closed (and not | 970 // Don't let the user drag while animating open or we're closed (and not |
| 1013 // detached, when detached size_animation_ is always 0). This typically is | 971 // detached, when detached size_animation_ is always 0). This typically is |
| 1014 // only hit if the user does something to inadvertently trigger DnD such as | 972 // only hit if the user does something to inadvertently trigger DnD such as |
| 1015 // pressing the mouse and hitting control-b. | 973 // pressing the mouse and hitting control-b. |
| 1016 return ui::DragDropTypes::DRAG_NONE; | 974 return ui::DragDropTypes::DRAG_NONE; |
| 1017 } | 975 } |
| 1018 | 976 |
| 1019 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 977 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 1020 if (sender == GetBookmarkButton(i)) { | 978 if (sender == GetBookmarkButton(i)) { |
| 1021 return bookmark_utils::BookmarkDragOperation( | 979 return bookmark_utils::BookmarkDragOperation( |
| 1022 profile_, model_->bookmark_bar_node()->GetChild(i)); | 980 browser_->profile(), model_->bookmark_bar_node()->GetChild(i)); |
| 1023 } | 981 } |
| 1024 } | 982 } |
| 1025 NOTREACHED(); | 983 NOTREACHED(); |
| 1026 return ui::DragDropTypes::DRAG_NONE; | 984 return ui::DragDropTypes::DRAG_NONE; |
| 1027 } | 985 } |
| 1028 | 986 |
| 1029 bool BookmarkBarView::CanStartDragForView(views::View* sender, | 987 bool BookmarkBarView::CanStartDragForView(views::View* sender, |
| 1030 const gfx::Point& press_pt, | 988 const gfx::Point& press_pt, |
| 1031 const gfx::Point& p) { | 989 const gfx::Point& p) { |
| 1032 // Check if we have not moved enough horizontally but we have moved downward | 990 // Check if we have not moved enough horizontally but we have moved downward |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1058 node = model_->other_node(); | 1016 node = model_->other_node(); |
| 1059 } else if (view == overflow_button_) { | 1017 } else if (view == overflow_button_) { |
| 1060 node = model_->bookmark_bar_node(); | 1018 node = model_->bookmark_bar_node(); |
| 1061 start_index = GetFirstHiddenNodeIndex(); | 1019 start_index = GetFirstHiddenNodeIndex(); |
| 1062 } else { | 1020 } else { |
| 1063 int button_index = GetIndexOf(view); | 1021 int button_index = GetIndexOf(view); |
| 1064 DCHECK_NE(-1, button_index); | 1022 DCHECK_NE(-1, button_index); |
| 1065 node = model_->bookmark_bar_node()->GetChild(button_index); | 1023 node = model_->bookmark_bar_node()->GetChild(button_index); |
| 1066 } | 1024 } |
| 1067 | 1025 |
| 1068 bookmark_menu_ = new BookmarkMenuController( | 1026 bookmark_menu_ = new BookmarkMenuController(browser_->profile(), |
| 1069 profile_, page_navigator_, GetWidget(), node, start_index); | 1027 page_navigator_, GetWidget(), node, start_index); |
| 1070 bookmark_menu_->set_observer(this); | 1028 bookmark_menu_->set_observer(this); |
| 1071 bookmark_menu_->RunMenuAt(this, false); | 1029 bookmark_menu_->RunMenuAt(this, false); |
| 1072 } | 1030 } |
| 1073 | 1031 |
| 1074 void BookmarkBarView::ButtonPressed(views::Button* sender, | 1032 void BookmarkBarView::ButtonPressed(views::Button* sender, |
| 1075 const views::Event& event) { | 1033 const views::Event& event) { |
| 1076 // Show the login wizard if the user clicked the re-login button. | 1034 // Show the login wizard if the user clicked the re-login button. |
| 1077 if (sender->tag() == kSyncErrorButtonTag) { | 1035 if (sender->tag() == kSyncErrorButtonTag) { |
| 1078 DCHECK(sender == sync_error_button_); | 1036 DCHECK(sender == sync_error_button_); |
| 1079 DCHECK(sync_service_ && !sync_service_->IsManaged()); | 1037 DCHECK(sync_service_ && !sync_service_->IsManaged()); |
| 1080 sync_service_->ShowErrorUI(); | 1038 sync_service_->ShowErrorUI(); |
| 1081 return; | 1039 return; |
| 1082 } | 1040 } |
| 1083 | 1041 |
| 1084 const BookmarkNode* node; | 1042 const BookmarkNode* node; |
| 1085 if (sender->tag() == kOtherFolderButtonTag) { | 1043 if (sender->tag() == kOtherFolderButtonTag) { |
| 1086 node = model_->other_node(); | 1044 node = model_->other_node(); |
| 1087 } else { | 1045 } else { |
| 1088 int index = GetIndexOf(sender); | 1046 int index = GetIndexOf(sender); |
| 1089 DCHECK_NE(-1, index); | 1047 DCHECK_NE(-1, index); |
| 1090 node = model_->bookmark_bar_node()->GetChild(index); | 1048 node = model_->bookmark_bar_node()->GetChild(index); |
| 1091 } | 1049 } |
| 1092 DCHECK(page_navigator_); | 1050 DCHECK(page_navigator_); |
| 1093 | 1051 |
| 1094 WindowOpenDisposition disposition_from_event_flags = | 1052 WindowOpenDisposition disposition_from_event_flags = |
| 1095 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()); | 1053 event_utils::DispositionFromEventFlags(sender->mouse_event_flags()); |
| 1096 | 1054 |
| 1055 Profile* profile = browser_->profile(); |
| 1097 if (node->is_url()) { | 1056 if (node->is_url()) { |
| 1098 RecordAppLaunch(profile_, node->url()); | 1057 RecordAppLaunch(profile, node->url()); |
| 1099 page_navigator_->OpenURL(node->url(), GURL(), | 1058 page_navigator_->OpenURL(node->url(), GURL(), |
| 1100 disposition_from_event_flags, PageTransition::AUTO_BOOKMARK); | 1059 disposition_from_event_flags, PageTransition::AUTO_BOOKMARK); |
| 1101 } else { | 1060 } else { |
| 1102 bookmark_utils::OpenAll(GetWidget()->GetNativeWindow(), profile_, | 1061 bookmark_utils::OpenAll(GetWidget()->GetNativeWindow(), profile, |
| 1103 page_navigator_, node, disposition_from_event_flags); | 1062 page_navigator_, node, disposition_from_event_flags); |
| 1104 } | 1063 } |
| 1105 UserMetrics::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton")); | 1064 UserMetrics::RecordAction(UserMetricsAction("ClickedBookmarkBarURLButton")); |
| 1106 } | 1065 } |
| 1107 | 1066 |
| 1108 void BookmarkBarView::ShowContextMenuForView(View* source, | 1067 void BookmarkBarView::ShowContextMenuForView(View* source, |
| 1109 const gfx::Point& p, | 1068 const gfx::Point& p, |
| 1110 bool is_mouse_gesture) { | 1069 bool is_mouse_gesture) { |
| 1111 if (!model_->IsLoaded()) { | 1070 if (!model_->IsLoaded()) { |
| 1112 // Don't do anything if the model isn't loaded. | 1071 // Don't do anything if the model isn't loaded. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1127 DCHECK(bookmark_button_index != -1 && | 1086 DCHECK(bookmark_button_index != -1 && |
| 1128 bookmark_button_index < GetBookmarkButtonCount()); | 1087 bookmark_button_index < GetBookmarkButtonCount()); |
| 1129 const BookmarkNode* node = | 1088 const BookmarkNode* node = |
| 1130 model_->bookmark_bar_node()->GetChild(bookmark_button_index); | 1089 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
| 1131 nodes.push_back(node); | 1090 nodes.push_back(node); |
| 1132 parent = node->parent(); | 1091 parent = node->parent(); |
| 1133 } else { | 1092 } else { |
| 1134 parent = model_->bookmark_bar_node(); | 1093 parent = model_->bookmark_bar_node(); |
| 1135 nodes.push_back(parent); | 1094 nodes.push_back(parent); |
| 1136 } | 1095 } |
| 1137 // Browser may be null during testing. | 1096 Profile* profile = browser_->profile(); |
| 1138 PageNavigator* navigator = | |
| 1139 browser() ? browser()->GetSelectedTabContents() : NULL; | |
| 1140 bool close_on_remove = | 1097 bool close_on_remove = |
| 1141 (parent == profile_->GetBookmarkModel()->other_node() && | 1098 (parent == profile->GetBookmarkModel()->other_node()) && |
| 1142 parent->child_count() == 1); | 1099 (parent->child_count() == 1); |
| 1143 BookmarkContextMenu controller(GetWidget(), profile_, | 1100 BookmarkContextMenu controller(GetWidget(), profile, |
| 1144 navigator, parent, nodes, close_on_remove); | 1101 browser_->GetSelectedTabContents(), parent, nodes, close_on_remove); |
| 1145 controller.RunMenuAt(p); | 1102 controller.RunMenuAt(p); |
| 1146 } | 1103 } |
| 1147 | 1104 |
| 1148 void BookmarkBarView::Observe(int type, | 1105 void BookmarkBarView::Observe(int type, |
| 1149 const NotificationSource& source, | 1106 const NotificationSource& source, |
| 1150 const NotificationDetails& details) { | 1107 const NotificationDetails& details) { |
| 1151 DCHECK(profile_); | 1108 DCHECK(browser_->profile()); |
| 1152 switch (type) { | 1109 switch (type) { |
| 1153 case chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN: { | 1110 case chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN: { |
| 1154 StopThrobbing(true); | 1111 StopThrobbing(true); |
| 1155 GURL url = *(Details<GURL>(details).ptr()); | 1112 GURL url = *(Details<GURL>(details).ptr()); |
| 1156 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url); | 1113 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url); |
| 1157 if (!node) | 1114 if (!node) |
| 1158 return; // Generally shouldn't happen. | 1115 return; // Generally shouldn't happen. |
| 1159 StartThrobbing(node, false); | 1116 StartThrobbing(node, false); |
| 1160 break; | 1117 break; |
| 1161 } | 1118 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1182 | 1139 |
| 1183 // Child views are traversed in the order they are added. Make sure the order | 1140 // Child views are traversed in the order they are added. Make sure the order |
| 1184 // they are added matches the visual order. | 1141 // they are added matches the visual order. |
| 1185 sync_error_button_ = CreateSyncErrorButton(); | 1142 sync_error_button_ = CreateSyncErrorButton(); |
| 1186 AddChildView(sync_error_button_); | 1143 AddChildView(sync_error_button_); |
| 1187 | 1144 |
| 1188 overflow_button_ = CreateOverflowButton(); | 1145 overflow_button_ = CreateOverflowButton(); |
| 1189 AddChildView(overflow_button_); | 1146 AddChildView(overflow_button_); |
| 1190 | 1147 |
| 1191 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 1148 other_bookmarked_button_ = CreateOtherBookmarkedButton(); |
| 1149 // We'll re-enable when the model is loaded. |
| 1150 other_bookmarked_button_->SetEnabled(false); |
| 1192 AddChildView(other_bookmarked_button_); | 1151 AddChildView(other_bookmarked_button_); |
| 1193 | 1152 |
| 1194 bookmarks_separator_view_ = new ButtonSeparatorView(); | 1153 bookmarks_separator_view_ = new ButtonSeparatorView(); |
| 1195 AddChildView(bookmarks_separator_view_); | 1154 AddChildView(bookmarks_separator_view_); |
| 1196 | 1155 |
| 1197 instructions_ = new BookmarkBarInstructionsView(this); | 1156 instructions_ = new BookmarkBarInstructionsView(this); |
| 1198 AddChildView(instructions_); | 1157 AddChildView(instructions_); |
| 1199 | 1158 |
| 1200 set_context_menu_controller(this); | 1159 set_context_menu_controller(this); |
| 1201 | 1160 |
| 1202 size_animation_.reset(new ui::SlideAnimation(this)); | 1161 size_animation_.reset(new ui::SlideAnimation(this)); |
| 1162 |
| 1163 Profile* profile = browser_->profile(); |
| 1164 Source<Profile> ns_source(profile->GetOriginalProfile()); |
| 1165 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_BUBBLE_SHOWN, ns_source); |
| 1166 registrar_.Add(this, chrome::NOTIFICATION_BOOKMARK_BUBBLE_HIDDEN, ns_source); |
| 1167 |
| 1168 model_ = profile->GetBookmarkModel(); |
| 1169 if (model_) { |
| 1170 model_->AddObserver(this); |
| 1171 if (model_->IsLoaded()) |
| 1172 Loaded(model_, false); |
| 1173 // else case: we'll receive notification back from the BookmarkModel when |
| 1174 // done loading, then we'll populate the bar. |
| 1175 } |
| 1203 } | 1176 } |
| 1204 | 1177 |
| 1205 int BookmarkBarView::GetBookmarkButtonCount() { | 1178 int BookmarkBarView::GetBookmarkButtonCount() { |
| 1206 // We contain five non-bookmark button views: other bookmarks, bookmarks | 1179 // We contain five non-bookmark button views: other bookmarks, bookmarks |
| 1207 // separator, chevrons (for overflow), the instruction label and the sync | 1180 // separator, chevrons (for overflow), the instruction label and the sync |
| 1208 // error button. | 1181 // error button. |
| 1209 return child_count() - 5; | 1182 return child_count() - 5; |
| 1210 } | 1183 } |
| 1211 | 1184 |
| 1212 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { | 1185 views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1273 sync_error_button->SetAccessibleName( | 1246 sync_error_button->SetAccessibleName( |
| 1274 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); | 1247 l10n_util::GetStringUTF16(IDS_ACCNAME_SYNC_ERROR_BUTTON)); |
| 1275 sync_error_button->SetIcon( | 1248 sync_error_button->SetIcon( |
| 1276 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); | 1249 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); |
| 1277 return sync_error_button; | 1250 return sync_error_button; |
| 1278 } | 1251 } |
| 1279 | 1252 |
| 1280 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { | 1253 views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { |
| 1281 if (node->is_url()) { | 1254 if (node->is_url()) { |
| 1282 BookmarkButton* button = new BookmarkButton(this, node->url(), | 1255 BookmarkButton* button = new BookmarkButton(this, node->url(), |
| 1283 UTF16ToWide(node->GetTitle()), profile_); | 1256 UTF16ToWide(node->GetTitle()), browser_->profile()); |
| 1284 ConfigureButton(node, button); | 1257 ConfigureButton(node, button); |
| 1285 return button; | 1258 return button; |
| 1286 } else { | 1259 } else { |
| 1287 views::MenuButton* button = new BookmarkFolderButton(this, | 1260 views::MenuButton* button = new BookmarkFolderButton(this, |
| 1288 UTF16ToWide(node->GetTitle()), this, false); | 1261 UTF16ToWide(node->GetTitle()), this, false); |
| 1289 button->SetIcon(GetFolderIcon()); | 1262 button->SetIcon(GetFolderIcon()); |
| 1290 ConfigureButton(node, button); | 1263 ConfigureButton(node, button); |
| 1291 return button; | 1264 return button; |
| 1292 } | 1265 } |
| 1293 } | 1266 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1386 | 1359 |
| 1387 views::MenuButton* menu_button = GetMenuButtonForNode(node); | 1360 views::MenuButton* menu_button = GetMenuButtonForNode(node); |
| 1388 if (!menu_button) | 1361 if (!menu_button) |
| 1389 return; | 1362 return; |
| 1390 | 1363 |
| 1391 int start_index = 0; | 1364 int start_index = 0; |
| 1392 if (node == model_->bookmark_bar_node()) | 1365 if (node == model_->bookmark_bar_node()) |
| 1393 start_index = GetFirstHiddenNodeIndex(); | 1366 start_index = GetFirstHiddenNodeIndex(); |
| 1394 | 1367 |
| 1395 drop_info_->is_menu_showing = true; | 1368 drop_info_->is_menu_showing = true; |
| 1396 bookmark_drop_menu_ = new BookmarkMenuController( | 1369 bookmark_drop_menu_ = new BookmarkMenuController(browser_->profile(), |
| 1397 profile_, page_navigator_, GetWidget(), node, start_index); | 1370 page_navigator_, GetWidget(), node, start_index); |
| 1398 bookmark_drop_menu_->set_observer(this); | 1371 bookmark_drop_menu_->set_observer(this); |
| 1399 bookmark_drop_menu_->RunMenuAt(this, true); | 1372 bookmark_drop_menu_->RunMenuAt(this, true); |
| 1400 } | 1373 } |
| 1401 | 1374 |
| 1402 void BookmarkBarView::StopShowFolderDropMenuTimer() { | 1375 void BookmarkBarView::StopShowFolderDropMenuTimer() { |
| 1403 show_folder_method_factory_.RevokeAll(); | 1376 show_folder_method_factory_.RevokeAll(); |
| 1404 } | 1377 } |
| 1405 | 1378 |
| 1406 void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) { | 1379 void BookmarkBarView::StartShowFolderDropMenuTimer(const BookmarkNode* node) { |
| 1407 if (testing_) { | 1380 if (testing_) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1429 | 1402 |
| 1430 // The drop event uses the screen coordinates while the child Views are | 1403 // The drop event uses the screen coordinates while the child Views are |
| 1431 // always laid out from left to right (even though they are rendered from | 1404 // always laid out from left to right (even though they are rendered from |
| 1432 // right-to-left on RTL locales). Thus, in order to make sure the drop | 1405 // right-to-left on RTL locales). Thus, in order to make sure the drop |
| 1433 // coordinates calculation works, we mirror the event's X coordinate if the | 1406 // coordinates calculation works, we mirror the event's X coordinate if the |
| 1434 // locale is RTL. | 1407 // locale is RTL. |
| 1435 int mirrored_x = GetMirroredXInView(event.x()); | 1408 int mirrored_x = GetMirroredXInView(event.x()); |
| 1436 | 1409 |
| 1437 bool found = false; | 1410 bool found = false; |
| 1438 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); | 1411 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); |
| 1412 Profile* profile = browser_->profile(); |
| 1439 if (other_bookmarked_button_->IsVisible() && other_delta_x >= 0 && | 1413 if (other_bookmarked_button_->IsVisible() && other_delta_x >= 0 && |
| 1440 other_delta_x < other_bookmarked_button_->width()) { | 1414 other_delta_x < other_bookmarked_button_->width()) { |
| 1441 // Mouse is over 'other' folder. | 1415 // Mouse is over 'other' folder. |
| 1442 location->button_type = DROP_OTHER_FOLDER; | 1416 location->button_type = DROP_OTHER_FOLDER; |
| 1443 location->on = true; | 1417 location->on = true; |
| 1444 found = true; | 1418 found = true; |
| 1445 } else if (!GetBookmarkButtonCount()) { | 1419 } else if (!GetBookmarkButtonCount()) { |
| 1446 // No bookmarks, accept the drop. | 1420 // No bookmarks, accept the drop. |
| 1447 location->index = 0; | 1421 location->index = 0; |
| 1448 int ops = data.GetFirstNode(profile_) | 1422 int ops = data.GetFirstNode(profile) ? ui::DragDropTypes::DRAG_MOVE : |
| 1449 ? ui::DragDropTypes::DRAG_MOVE | 1423 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
| 1450 : ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | |
| 1451 location->operation = | 1424 location->operation = |
| 1452 bookmark_utils::PreferredDropOperation(event.source_operations(), ops); | 1425 bookmark_utils::PreferredDropOperation(event.source_operations(), ops); |
| 1453 return; | 1426 return; |
| 1454 } | 1427 } |
| 1455 | 1428 |
| 1456 for (int i = 0; i < GetBookmarkButtonCount() && | 1429 for (int i = 0; i < GetBookmarkButtonCount() && |
| 1457 GetBookmarkButton(i)->IsVisible() && !found; i++) { | 1430 GetBookmarkButton(i)->IsVisible() && !found; i++) { |
| 1458 views::TextButton* button = GetBookmarkButton(i); | 1431 views::TextButton* button = GetBookmarkButton(i); |
| 1459 int button_x = mirrored_x - button->x(); | 1432 int button_x = mirrored_x - button->x(); |
| 1460 int button_w = button->width(); | 1433 int button_w = button->width(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 } else { | 1476 } else { |
| 1504 return; | 1477 return; |
| 1505 } | 1478 } |
| 1506 } | 1479 } |
| 1507 | 1480 |
| 1508 if (location->on) { | 1481 if (location->on) { |
| 1509 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? | 1482 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? |
| 1510 model_->other_node() : | 1483 model_->other_node() : |
| 1511 model_->bookmark_bar_node()->GetChild(location->index); | 1484 model_->bookmark_bar_node()->GetChild(location->index); |
| 1512 location->operation = | 1485 location->operation = |
| 1513 bookmark_utils::BookmarkDropOperation(profile_, event, data, parent, | 1486 bookmark_utils::BookmarkDropOperation(profile, event, data, parent, |
| 1514 parent->child_count()); | 1487 parent->child_count()); |
| 1515 if (!location->operation && !data.has_single_url() && | 1488 if (!location->operation && !data.has_single_url() && |
| 1516 data.GetFirstNode(profile_) == parent) { | 1489 data.GetFirstNode(profile) == parent) { |
| 1517 // Don't open a menu if the node being dragged is the menu to open. | 1490 // Don't open a menu if the node being dragged is the menu to open. |
| 1518 location->on = false; | 1491 location->on = false; |
| 1519 } | 1492 } |
| 1520 } else { | 1493 } else { |
| 1521 location->operation = | 1494 location->operation = bookmark_utils::BookmarkDropOperation(profile, event, |
| 1522 bookmark_utils::BookmarkDropOperation(profile_, event, data, | 1495 data, model_->bookmark_bar_node(), location->index); |
| 1523 model_->bookmark_bar_node(), | |
| 1524 location->index); | |
| 1525 } | 1496 } |
| 1526 } | 1497 } |
| 1527 | 1498 |
| 1528 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, | 1499 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, |
| 1529 ui::OSExchangeData* data) { | 1500 ui::OSExchangeData* data) { |
| 1530 DCHECK(node && data); | 1501 DCHECK(node && data); |
| 1531 BookmarkNodeData drag_data(node); | 1502 BookmarkNodeData drag_data(node); |
| 1532 drag_data.Write(profile_, data); | 1503 drag_data.Write(browser_->profile(), data); |
| 1533 } | 1504 } |
| 1534 | 1505 |
| 1535 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, | 1506 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
| 1536 bool overflow_only) { | 1507 bool overflow_only) { |
| 1537 DCHECK(!throbbing_view_); | 1508 DCHECK(!throbbing_view_); |
| 1538 | 1509 |
| 1539 // Determine which visible button is showing the bookmark (or is an ancestor | 1510 // Determine which visible button is showing the bookmark (or is an ancestor |
| 1540 // of the bookmark). | 1511 // of the bookmark). |
| 1541 const BookmarkNode* bbn = model_->bookmark_bar_node(); | 1512 const BookmarkNode* bbn = model_->bookmark_bar_node(); |
| 1542 const BookmarkNode* parent_on_bb = node; | 1513 const BookmarkNode* parent_on_bb = node; |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 (1 - size_animation_->GetCurrentValue()))); | 1724 (1 - size_animation_->GetCurrentValue()))); |
| 1754 } else { | 1725 } else { |
| 1755 prefsize.set_height( | 1726 prefsize.set_height( |
| 1756 static_cast<int>( | 1727 static_cast<int>( |
| 1757 browser_defaults::kBookmarkBarHeight * | 1728 browser_defaults::kBookmarkBarHeight * |
| 1758 size_animation_->GetCurrentValue())); | 1729 size_animation_->GetCurrentValue())); |
| 1759 } | 1730 } |
| 1760 } | 1731 } |
| 1761 return prefsize; | 1732 return prefsize; |
| 1762 } | 1733 } |
| OLD | NEW |