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