| 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 12 matching lines...) Expand all Loading... |
| 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() : model_->bookmark_bar_node(); |
| 919 int index = drop_info_->location.index; | 921 int index = drop_info_->location.index; |
| 920 | 922 |
| 921 if (index != -1) { | 923 if (index != -1) { |
| 922 // TODO(sky): optimize the SchedulePaint region. | 924 // TODO(sky): optimize the SchedulePaint region. |
| 923 SchedulePaint(); | 925 SchedulePaint(); |
| 924 } | 926 } |
| 925 const BookmarkNode* parent_node; | 927 const BookmarkNode* parent_node; |
| 926 if (drop_info_->location.button_type == DROP_OTHER_FOLDER) { | 928 if (drop_info_->location.button_type == DROP_OTHER_FOLDER) { |
| 927 parent_node = root; | 929 parent_node = root; |
| 928 index = parent_node->child_count(); | 930 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) { | 987 } else if (bookmark_bar_state_ == BookmarkBar::DETACHED) { |
| 986 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView", | 988 UMA_HISTOGRAM_COUNTS("Import.ShowDialog.FromFloatingBookmarkBarView", |
| 987 time_from_install); | 989 time_from_install); |
| 988 } | 990 } |
| 989 | 991 |
| 990 chrome::ShowImportDialog(browser_); | 992 chrome::ShowImportDialog(browser_); |
| 991 } | 993 } |
| 992 | 994 |
| 993 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { | 995 void BookmarkBarView::OnBookmarkBubbleShown(const GURL& url) { |
| 994 StopThrobbing(true); | 996 StopThrobbing(true); |
| 995 const BookmarkNode* node = model()->GetMostRecentlyAddedUserNodeForURL(url); | 997 const BookmarkNode* node = model_->GetMostRecentlyAddedUserNodeForURL(url); |
| 996 if (!node) | 998 if (!node) |
| 997 return; // Generally shouldn't happen. | 999 return; // Generally shouldn't happen. |
| 998 StartThrobbing(node, false); | 1000 StartThrobbing(node, false); |
| 999 } | 1001 } |
| 1000 | 1002 |
| 1001 void BookmarkBarView::OnBookmarkBubbleHidden() { | 1003 void BookmarkBarView::OnBookmarkBubbleHidden() { |
| 1002 StopThrobbing(false); | 1004 StopThrobbing(false); |
| 1003 } | 1005 } |
| 1004 | 1006 |
| 1005 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, | 1007 void BookmarkBarView::BookmarkModelLoaded(BookmarkModel* model, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1023 other_bookmarked_button_->SetEnabled(true); | 1025 other_bookmarked_button_->SetEnabled(true); |
| 1024 managed_bookmarks_button_->SetEnabled(true); | 1026 managed_bookmarks_button_->SetEnabled(true); |
| 1025 | 1027 |
| 1026 Layout(); | 1028 Layout(); |
| 1027 SchedulePaint(); | 1029 SchedulePaint(); |
| 1028 } | 1030 } |
| 1029 | 1031 |
| 1030 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { | 1032 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { |
| 1031 NOTREACHED(); | 1033 NOTREACHED(); |
| 1032 // Do minimal cleanup, presumably we'll be deleted shortly. | 1034 // Do minimal cleanup, presumably we'll be deleted shortly. |
| 1033 model->RemoveObserver(this); | 1035 model_->RemoveObserver(this); |
| 1034 client_ = NULL; | 1036 model_ = NULL; |
| 1035 } | 1037 } |
| 1036 | 1038 |
| 1037 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, | 1039 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
| 1038 const BookmarkNode* old_parent, | 1040 const BookmarkNode* old_parent, |
| 1039 int old_index, | 1041 int old_index, |
| 1040 const BookmarkNode* new_parent, | 1042 const BookmarkNode* new_parent, |
| 1041 int new_index) { | 1043 int new_index) { |
| 1042 bool was_throbbing = throbbing_view_ && | 1044 bool was_throbbing = throbbing_view_ && |
| 1043 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); | 1045 throbbing_view_ == DetermineViewToThrobFromRemove(old_parent, old_index); |
| 1044 if (was_throbbing) | 1046 if (was_throbbing) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 | 1122 |
| 1121 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1123 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 1122 if (sender == GetBookmarkButton(i)) { | 1124 if (sender == GetBookmarkButton(i)) { |
| 1123 views::TextButton* button = GetBookmarkButton(i); | 1125 views::TextButton* button = GetBookmarkButton(i); |
| 1124 scoped_ptr<gfx::Canvas> canvas( | 1126 scoped_ptr<gfx::Canvas> canvas( |
| 1125 views::GetCanvasForDragImage(button->GetWidget(), button->size())); | 1127 views::GetCanvasForDragImage(button->GetWidget(), button->size())); |
| 1126 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); | 1128 button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); |
| 1127 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), | 1129 drag_utils::SetDragImageOnDataObject(*canvas, button->size(), |
| 1128 press_pt.OffsetFromOrigin(), | 1130 press_pt.OffsetFromOrigin(), |
| 1129 data); | 1131 data); |
| 1130 WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data); | 1132 WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data); |
| 1131 return; | 1133 return; |
| 1132 } | 1134 } |
| 1133 } | 1135 } |
| 1134 NOTREACHED(); | 1136 NOTREACHED(); |
| 1135 } | 1137 } |
| 1136 | 1138 |
| 1137 int BookmarkBarView::GetDragOperationsForView(View* sender, | 1139 int BookmarkBarView::GetDragOperationsForView(View* sender, |
| 1138 const gfx::Point& p) { | 1140 const gfx::Point& p) { |
| 1139 if (size_animation_->is_animating() || | 1141 if (size_animation_->is_animating() || |
| 1140 (size_animation_->GetCurrentValue() == 0 && | 1142 (size_animation_->GetCurrentValue() == 0 && |
| 1141 bookmark_bar_state_ != BookmarkBar::DETACHED)) { | 1143 bookmark_bar_state_ != BookmarkBar::DETACHED)) { |
| 1142 // Don't let the user drag while animating open or we're closed (and not | 1144 // 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 | 1145 // 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 | 1146 // only hit if the user does something to inadvertently trigger DnD such as |
| 1145 // pressing the mouse and hitting control-b. | 1147 // pressing the mouse and hitting control-b. |
| 1146 return ui::DragDropTypes::DRAG_NONE; | 1148 return ui::DragDropTypes::DRAG_NONE; |
| 1147 } | 1149 } |
| 1148 | 1150 |
| 1149 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1151 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 1150 if (sender == GetBookmarkButton(i)) { | 1152 if (sender == GetBookmarkButton(i)) { |
| 1151 return chrome::GetBookmarkDragOperation( | 1153 return chrome::GetBookmarkDragOperation( |
| 1152 browser_->profile(), model()->bookmark_bar_node()->GetChild(i)); | 1154 browser_->profile(), model_->bookmark_bar_node()->GetChild(i)); |
| 1153 } | 1155 } |
| 1154 } | 1156 } |
| 1155 NOTREACHED(); | 1157 NOTREACHED(); |
| 1156 return ui::DragDropTypes::DRAG_NONE; | 1158 return ui::DragDropTypes::DRAG_NONE; |
| 1157 } | 1159 } |
| 1158 | 1160 |
| 1159 bool BookmarkBarView::CanStartDragForView(views::View* sender, | 1161 bool BookmarkBarView::CanStartDragForView(views::View* sender, |
| 1160 const gfx::Point& press_pt, | 1162 const gfx::Point& press_pt, |
| 1161 const gfx::Point& p) { | 1163 const gfx::Point& p) { |
| 1162 // Check if we have not moved enough horizontally but we have moved downward | 1164 // Check if we have not moved enough horizontally but we have moved downward |
| 1163 // vertically - downward drag. | 1165 // vertically - downward drag. |
| 1164 gfx::Vector2d move_offset = p - press_pt; | 1166 gfx::Vector2d move_offset = p - press_pt; |
| 1165 gfx::Vector2d horizontal_offset(move_offset.x(), 0); | 1167 gfx::Vector2d horizontal_offset(move_offset.x(), 0); |
| 1166 if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { | 1168 if (!View::ExceededDragThreshold(horizontal_offset) && move_offset.y() > 0) { |
| 1167 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 1169 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| 1168 if (sender == GetBookmarkButton(i)) { | 1170 if (sender == GetBookmarkButton(i)) { |
| 1169 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); | 1171 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); |
| 1170 // If the folder button was dragged, show the menu instead. | 1172 // If the folder button was dragged, show the menu instead. |
| 1171 if (node && node->is_folder()) { | 1173 if (node && node->is_folder()) { |
| 1172 views::MenuButton* menu_button = | 1174 views::MenuButton* menu_button = |
| 1173 static_cast<views::MenuButton*>(sender); | 1175 static_cast<views::MenuButton*>(sender); |
| 1174 menu_button->Activate(); | 1176 menu_button->Activate(); |
| 1175 return false; | 1177 return false; |
| 1176 } | 1178 } |
| 1177 break; | 1179 break; |
| 1178 } | 1180 } |
| 1179 } | 1181 } |
| 1180 } | 1182 } |
| 1181 return true; | 1183 return true; |
| 1182 } | 1184 } |
| 1183 | 1185 |
| 1184 void BookmarkBarView::OnMenuButtonClicked(views::View* view, | 1186 void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| 1185 const gfx::Point& point) { | 1187 const gfx::Point& point) { |
| 1186 const BookmarkNode* node; | 1188 const BookmarkNode* node; |
| 1187 | 1189 |
| 1188 int start_index = 0; | 1190 int start_index = 0; |
| 1189 if (view == other_bookmarked_button_) { | 1191 if (view == other_bookmarked_button_) { |
| 1190 node = model()->other_node(); | 1192 node = model_->other_node(); |
| 1191 } else if (view == managed_bookmarks_button_) { | 1193 } else if (view == managed_bookmarks_button_) { |
| 1192 node = client_->managed_node(); | 1194 node = client_->managed_node(); |
| 1193 } else if (view == overflow_button_) { | 1195 } else if (view == overflow_button_) { |
| 1194 node = model()->bookmark_bar_node(); | 1196 node = model_->bookmark_bar_node(); |
| 1195 start_index = GetFirstHiddenNodeIndex(); | 1197 start_index = GetFirstHiddenNodeIndex(); |
| 1196 } else { | 1198 } else { |
| 1197 int button_index = GetIndexOf(view); | 1199 int button_index = GetIndexOf(view); |
| 1198 DCHECK_NE(-1, button_index); | 1200 DCHECK_NE(-1, button_index); |
| 1199 node = model()->bookmark_bar_node()->GetChild(button_index); | 1201 node = model_->bookmark_bar_node()->GetChild(button_index); |
| 1200 } | 1202 } |
| 1201 | 1203 |
| 1202 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); | 1204 RecordBookmarkFolderOpen(GetBookmarkLaunchLocation()); |
| 1203 bookmark_menu_ = new BookmarkMenuController( | 1205 bookmark_menu_ = new BookmarkMenuController( |
| 1204 browser_, page_navigator_, GetWidget(), node, start_index); | 1206 browser_, page_navigator_, GetWidget(), node, start_index); |
| 1205 bookmark_menu_->set_observer(this); | 1207 bookmark_menu_->set_observer(this); |
| 1206 bookmark_menu_->RunMenuAt(this, false); | 1208 bookmark_menu_->RunMenuAt(this, false); |
| 1207 } | 1209 } |
| 1208 | 1210 |
| 1209 void BookmarkBarView::ButtonPressed(views::Button* sender, | 1211 void BookmarkBarView::ButtonPressed(views::Button* sender, |
| 1210 const ui::Event& event) { | 1212 const ui::Event& event) { |
| 1211 WindowOpenDisposition disposition_from_event_flags = | 1213 WindowOpenDisposition disposition_from_event_flags = |
| 1212 ui::DispositionFromEventFlags(event.flags()); | 1214 ui::DispositionFromEventFlags(event.flags()); |
| 1213 | 1215 |
| 1214 if (sender->tag() == kAppsShortcutButtonTag) { | 1216 if (sender->tag() == kAppsShortcutButtonTag) { |
| 1215 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), | 1217 OpenURLParams params(GURL(chrome::kChromeUIAppsURL), |
| 1216 Referrer(), | 1218 Referrer(), |
| 1217 disposition_from_event_flags, | 1219 disposition_from_event_flags, |
| 1218 content::PAGE_TRANSITION_AUTO_BOOKMARK, | 1220 content::PAGE_TRANSITION_AUTO_BOOKMARK, |
| 1219 false); | 1221 false); |
| 1220 page_navigator_->OpenURL(params); | 1222 page_navigator_->OpenURL(params); |
| 1221 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); | 1223 RecordBookmarkAppsPageOpen(GetBookmarkLaunchLocation()); |
| 1222 return; | 1224 return; |
| 1223 } | 1225 } |
| 1224 | 1226 |
| 1225 const BookmarkNode* node; | 1227 const BookmarkNode* node; |
| 1226 if (sender->tag() == kOtherFolderButtonTag) { | 1228 if (sender->tag() == kOtherFolderButtonTag) { |
| 1227 node = model()->other_node(); | 1229 node = model_->other_node(); |
| 1228 } else if (sender->tag() == kManagedFolderButtonTag) { | 1230 } else if (sender->tag() == kManagedFolderButtonTag) { |
| 1229 node = client_->managed_node(); | 1231 node = client_->managed_node(); |
| 1230 } else { | 1232 } else { |
| 1231 int index = GetIndexOf(sender); | 1233 int index = GetIndexOf(sender); |
| 1232 DCHECK_NE(-1, index); | 1234 DCHECK_NE(-1, index); |
| 1233 node = model()->bookmark_bar_node()->GetChild(index); | 1235 node = model_->bookmark_bar_node()->GetChild(index); |
| 1234 } | 1236 } |
| 1235 DCHECK(page_navigator_); | 1237 DCHECK(page_navigator_); |
| 1236 | 1238 |
| 1237 if (node->is_url()) { | 1239 if (node->is_url()) { |
| 1238 RecordAppLaunch(browser_->profile(), node->url()); | 1240 RecordAppLaunch(browser_->profile(), node->url()); |
| 1239 OpenURLParams params( | 1241 OpenURLParams params( |
| 1240 node->url(), Referrer(), disposition_from_event_flags, | 1242 node->url(), Referrer(), disposition_from_event_flags, |
| 1241 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); | 1243 content::PAGE_TRANSITION_AUTO_BOOKMARK, false); |
| 1242 page_navigator_->OpenURL(params); | 1244 page_navigator_->OpenURL(params); |
| 1243 } else { | 1245 } else { |
| 1244 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, | 1246 chrome::OpenAll(GetWidget()->GetNativeWindow(), page_navigator_, node, |
| 1245 disposition_from_event_flags, browser_->profile()); | 1247 disposition_from_event_flags, browser_->profile()); |
| 1246 } | 1248 } |
| 1247 | 1249 |
| 1248 RecordBookmarkLaunch(node, GetBookmarkLaunchLocation()); | 1250 RecordBookmarkLaunch(node, GetBookmarkLaunchLocation()); |
| 1249 } | 1251 } |
| 1250 | 1252 |
| 1251 void BookmarkBarView::ShowContextMenuForView(views::View* source, | 1253 void BookmarkBarView::ShowContextMenuForView(views::View* source, |
| 1252 const gfx::Point& point, | 1254 const gfx::Point& point, |
| 1253 ui::MenuSourceType source_type) { | 1255 ui::MenuSourceType source_type) { |
| 1254 if (!model()->loaded()) { | 1256 if (!model_->loaded()) { |
| 1255 // Don't do anything if the model isn't loaded. | 1257 // Don't do anything if the model isn't loaded. |
| 1256 return; | 1258 return; |
| 1257 } | 1259 } |
| 1258 | 1260 |
| 1259 const BookmarkNode* parent = NULL; | 1261 const BookmarkNode* parent = NULL; |
| 1260 std::vector<const BookmarkNode*> nodes; | 1262 std::vector<const BookmarkNode*> nodes; |
| 1261 if (source == other_bookmarked_button_) { | 1263 if (source == other_bookmarked_button_) { |
| 1262 parent = model()->other_node(); | 1264 parent = model_->other_node(); |
| 1263 // Do this so the user can open all bookmarks. BookmarkContextMenu makes | 1265 // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
| 1264 // sure the user can't edit/delete the node in this case. | 1266 // sure the user can't edit/delete the node in this case. |
| 1265 nodes.push_back(parent); | 1267 nodes.push_back(parent); |
| 1266 } else if (source == managed_bookmarks_button_) { | 1268 } else if (source == managed_bookmarks_button_) { |
| 1267 parent = client_->managed_node(); | 1269 parent = client_->managed_node(); |
| 1268 nodes.push_back(parent); | 1270 nodes.push_back(parent); |
| 1269 } else if (source != this && source != apps_page_shortcut_) { | 1271 } else if (source != this && source != apps_page_shortcut_) { |
| 1270 // User clicked on one of the bookmark buttons, find which one they | 1272 // 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 | 1273 // clicked on, except for the apps page shortcut, which must behave as if |
| 1272 // the user clicked on the bookmark bar background. | 1274 // the user clicked on the bookmark bar background. |
| 1273 int bookmark_button_index = GetIndexOf(source); | 1275 int bookmark_button_index = GetIndexOf(source); |
| 1274 DCHECK(bookmark_button_index != -1 && | 1276 DCHECK(bookmark_button_index != -1 && |
| 1275 bookmark_button_index < GetBookmarkButtonCount()); | 1277 bookmark_button_index < GetBookmarkButtonCount()); |
| 1276 const BookmarkNode* node = | 1278 const BookmarkNode* node = |
| 1277 model()->bookmark_bar_node()->GetChild(bookmark_button_index); | 1279 model_->bookmark_bar_node()->GetChild(bookmark_button_index); |
| 1278 nodes.push_back(node); | 1280 nodes.push_back(node); |
| 1279 parent = node->parent(); | 1281 parent = node->parent(); |
| 1280 } else { | 1282 } else { |
| 1281 parent = model()->bookmark_bar_node(); | 1283 parent = model_->bookmark_bar_node(); |
| 1282 nodes.push_back(parent); | 1284 nodes.push_back(parent); |
| 1283 } | 1285 } |
| 1284 bool close_on_remove = | 1286 bool close_on_remove = |
| 1285 (parent == model()->other_node()) && (parent->child_count() == 1); | 1287 (parent == model_->other_node()) && (parent->child_count() == 1); |
| 1286 | 1288 |
| 1287 context_menu_.reset(new BookmarkContextMenu( | 1289 context_menu_.reset(new BookmarkContextMenu( |
| 1288 GetWidget(), browser_, browser_->profile(), | 1290 GetWidget(), browser_, browser_->profile(), |
| 1289 browser_->tab_strip_model()->GetActiveWebContents(), | 1291 browser_->tab_strip_model()->GetActiveWebContents(), |
| 1290 parent, nodes, close_on_remove)); | 1292 parent, nodes, close_on_remove)); |
| 1291 context_menu_->RunMenuAt(point, source_type); | 1293 context_menu_->RunMenuAt(point, source_type); |
| 1292 } | 1294 } |
| 1293 | 1295 |
| 1294 void BookmarkBarView::Init() { | 1296 void BookmarkBarView::Init() { |
| 1295 // Note that at this point we're not in a hierarchy so GetThemeProvider() will | 1297 // 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_); | 1329 AddChildView(bookmarks_separator_view_); |
| 1328 UpdateBookmarksSeparatorVisibility(); | 1330 UpdateBookmarksSeparatorVisibility(); |
| 1329 | 1331 |
| 1330 instructions_ = new BookmarkBarInstructionsView(this); | 1332 instructions_ = new BookmarkBarInstructionsView(this); |
| 1331 AddChildView(instructions_); | 1333 AddChildView(instructions_); |
| 1332 | 1334 |
| 1333 set_context_menu_controller(this); | 1335 set_context_menu_controller(this); |
| 1334 | 1336 |
| 1335 size_animation_.reset(new gfx::SlideAnimation(this)); | 1337 size_animation_.reset(new gfx::SlideAnimation(this)); |
| 1336 | 1338 |
| 1337 client_ = BookmarkModelFactory::GetChromeBookmarkClientForProfile( | 1339 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); |
| 1338 browser_->profile()); | 1340 client_ = ChromeBookmarkClientFactory::GetForProfile(browser_->profile()); |
| 1339 if (client_) { | 1341 if (model_) { |
| 1340 model()->AddObserver(this); | 1342 model_->AddObserver(this); |
| 1341 if (model()->loaded()) | 1343 if (model_->loaded()) |
| 1342 BookmarkModelLoaded(model(), false); | 1344 BookmarkModelLoaded(model_, false); |
| 1343 // else case: we'll receive notification back from the BookmarkModel when | 1345 // else case: we'll receive notification back from the BookmarkModel when |
| 1344 // done loading, then we'll populate the bar. | 1346 // done loading, then we'll populate the bar. |
| 1345 } | 1347 } |
| 1346 } | 1348 } |
| 1347 | 1349 |
| 1348 int BookmarkBarView::GetBookmarkButtonCount() const { | 1350 int BookmarkBarView::GetBookmarkButtonCount() const { |
| 1349 // We contain six non-bookmark button views: managed bookmarks, | 1351 // We contain six non-bookmark button views: managed bookmarks, |
| 1350 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, | 1352 // other bookmarks, bookmarks separator, chevrons (for overflow), apps page, |
| 1351 // and the instruction label. | 1353 // and the instruction label. |
| 1352 return child_count() - 6; | 1354 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). | 1455 // We don't always have a theme provider (ui tests, for example). |
| 1454 if (GetThemeProvider()) { | 1456 if (GetThemeProvider()) { |
| 1455 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1457 button->SetEnabledColor(GetThemeProvider()->GetColor( |
| 1456 ThemeProperties::COLOR_BOOKMARK_TEXT)); | 1458 ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| 1457 } | 1459 } |
| 1458 | 1460 |
| 1459 button->ClearMaxTextSize(); | 1461 button->ClearMaxTextSize(); |
| 1460 button->set_context_menu_controller(this); | 1462 button->set_context_menu_controller(this); |
| 1461 button->set_drag_controller(this); | 1463 button->set_drag_controller(this); |
| 1462 if (node->is_url()) { | 1464 if (node->is_url()) { |
| 1463 const gfx::Image& favicon = model()->GetFavicon(node); | 1465 const gfx::Image& favicon = model_->GetFavicon(node); |
| 1464 if (!favicon.IsEmpty()) | 1466 if (!favicon.IsEmpty()) |
| 1465 button->SetIcon(*favicon.ToImageSkia()); | 1467 button->SetIcon(*favicon.ToImageSkia()); |
| 1466 else | 1468 else |
| 1467 button->SetIcon(GetDefaultFavicon()); | 1469 button->SetIcon(GetDefaultFavicon()); |
| 1468 } | 1470 } |
| 1469 button->set_max_width(kMaxButtonWidth); | 1471 button->set_max_width(kMaxButtonWidth); |
| 1470 } | 1472 } |
| 1471 | 1473 |
| 1472 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 1474 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
| 1473 const BookmarkNode* parent, | 1475 const BookmarkNode* parent, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 return; | 1539 return; |
| 1538 } | 1540 } |
| 1539 bookmark_drop_menu_->Cancel(); | 1541 bookmark_drop_menu_->Cancel(); |
| 1540 } | 1542 } |
| 1541 | 1543 |
| 1542 views::MenuButton* menu_button = GetMenuButtonForNode(node); | 1544 views::MenuButton* menu_button = GetMenuButtonForNode(node); |
| 1543 if (!menu_button) | 1545 if (!menu_button) |
| 1544 return; | 1546 return; |
| 1545 | 1547 |
| 1546 int start_index = 0; | 1548 int start_index = 0; |
| 1547 if (node == model()->bookmark_bar_node()) | 1549 if (node == model_->bookmark_bar_node()) |
| 1548 start_index = GetFirstHiddenNodeIndex(); | 1550 start_index = GetFirstHiddenNodeIndex(); |
| 1549 | 1551 |
| 1550 drop_info_->is_menu_showing = true; | 1552 drop_info_->is_menu_showing = true; |
| 1551 bookmark_drop_menu_ = new BookmarkMenuController(browser_, | 1553 bookmark_drop_menu_ = new BookmarkMenuController(browser_, |
| 1552 page_navigator_, GetWidget(), node, start_index); | 1554 page_navigator_, GetWidget(), node, start_index); |
| 1553 bookmark_drop_menu_->set_observer(this); | 1555 bookmark_drop_menu_->set_observer(this); |
| 1554 bookmark_drop_menu_->RunMenuAt(this, true); | 1556 bookmark_drop_menu_->RunMenuAt(this, true); |
| 1555 } | 1557 } |
| 1556 | 1558 |
| 1557 void BookmarkBarView::StopShowFolderDropMenuTimer() { | 1559 void BookmarkBarView::StopShowFolderDropMenuTimer() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1570 FROM_HERE, | 1572 FROM_HERE, |
| 1571 base::Bind(&BookmarkBarView::ShowDropFolderForNode, | 1573 base::Bind(&BookmarkBarView::ShowDropFolderForNode, |
| 1572 show_folder_method_factory_.GetWeakPtr(), | 1574 show_folder_method_factory_.GetWeakPtr(), |
| 1573 node), | 1575 node), |
| 1574 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); | 1576 base::TimeDelta::FromMilliseconds(views::GetMenuShowDelay())); |
| 1575 } | 1577 } |
| 1576 | 1578 |
| 1577 void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, | 1579 void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, |
| 1578 const BookmarkNodeData& data, | 1580 const BookmarkNodeData& data, |
| 1579 DropLocation* location) { | 1581 DropLocation* location) { |
| 1580 DCHECK(client_); | 1582 DCHECK(model_); |
| 1581 DCHECK(model()->loaded()); | 1583 DCHECK(model_->loaded()); |
| 1582 DCHECK(data.is_valid()); | 1584 DCHECK(data.is_valid()); |
| 1583 | 1585 |
| 1584 *location = DropLocation(); | 1586 *location = DropLocation(); |
| 1585 | 1587 |
| 1586 // The drop event uses the screen coordinates while the child Views are | 1588 // 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 | 1589 // 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 | 1590 // 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 | 1591 // coordinates calculation works, we mirror the event's X coordinate if the |
| 1590 // locale is RTL. | 1592 // locale is RTL. |
| 1591 int mirrored_x = GetMirroredXInView(event.x()); | 1593 int mirrored_x = GetMirroredXInView(event.x()); |
| 1592 | 1594 |
| 1593 bool found = false; | 1595 bool found = false; |
| 1594 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); | 1596 const int other_delta_x = mirrored_x - other_bookmarked_button_->x(); |
| 1595 Profile* profile = browser_->profile(); | 1597 Profile* profile = browser_->profile(); |
| 1596 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && | 1598 if (other_bookmarked_button_->visible() && other_delta_x >= 0 && |
| 1597 other_delta_x < other_bookmarked_button_->width()) { | 1599 other_delta_x < other_bookmarked_button_->width()) { |
| 1598 // Mouse is over 'other' folder. | 1600 // Mouse is over 'other' folder. |
| 1599 location->button_type = DROP_OTHER_FOLDER; | 1601 location->button_type = DROP_OTHER_FOLDER; |
| 1600 location->on = true; | 1602 location->on = true; |
| 1601 found = true; | 1603 found = true; |
| 1602 } else if (!GetBookmarkButtonCount()) { | 1604 } else if (!GetBookmarkButtonCount()) { |
| 1603 // No bookmarks, accept the drop. | 1605 // No bookmarks, accept the drop. |
| 1604 location->index = 0; | 1606 location->index = 0; |
| 1605 const BookmarkNode* node = data.GetFirstNode(model(), profile->GetPath()); | 1607 const BookmarkNode* node = data.GetFirstNode(model_, profile->GetPath()); |
| 1606 int ops = node && client_->CanBeEditedByUser(node) ? | 1608 int ops = node && client_->CanBeEditedByUser(node) ? |
| 1607 ui::DragDropTypes::DRAG_MOVE : | 1609 ui::DragDropTypes::DRAG_MOVE : |
| 1608 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; | 1610 ui::DragDropTypes::DRAG_COPY | ui::DragDropTypes::DRAG_LINK; |
| 1609 location->operation = chrome::GetPreferredBookmarkDropOperation( | 1611 location->operation = chrome::GetPreferredBookmarkDropOperation( |
| 1610 event.source_operations(), ops); | 1612 event.source_operations(), ops); |
| 1611 return; | 1613 return; |
| 1612 } | 1614 } |
| 1613 | 1615 |
| 1614 for (int i = 0; i < GetBookmarkButtonCount() && | 1616 for (int i = 0; i < GetBookmarkButtonCount() && |
| 1615 GetBookmarkButton(i)->visible() && !found; i++) { | 1617 GetBookmarkButton(i)->visible() && !found; i++) { |
| 1616 views::TextButton* button = GetBookmarkButton(i); | 1618 views::TextButton* button = GetBookmarkButton(i); |
| 1617 int button_x = mirrored_x - button->x(); | 1619 int button_x = mirrored_x - button->x(); |
| 1618 int button_w = button->width(); | 1620 int button_w = button->width(); |
| 1619 if (button_x < button_w) { | 1621 if (button_x < button_w) { |
| 1620 found = true; | 1622 found = true; |
| 1621 const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); | 1623 const BookmarkNode* node = model_->bookmark_bar_node()->GetChild(i); |
| 1622 if (node->is_folder()) { | 1624 if (node->is_folder()) { |
| 1623 if (button_x <= views::kDropBetweenPixels) { | 1625 if (button_x <= views::kDropBetweenPixels) { |
| 1624 location->index = i; | 1626 location->index = i; |
| 1625 } else if (button_x < button_w - views::kDropBetweenPixels) { | 1627 } else if (button_x < button_w - views::kDropBetweenPixels) { |
| 1626 location->index = i; | 1628 location->index = i; |
| 1627 location->on = true; | 1629 location->on = true; |
| 1628 } else { | 1630 } else { |
| 1629 location->index = i + 1; | 1631 location->index = i + 1; |
| 1630 } | 1632 } |
| 1631 } else if (button_x < button_w / 2) { | 1633 } else if (button_x < button_w / 2) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1658 // Mouse is after the last visible button but before more recently | 1660 // Mouse is after the last visible button but before more recently |
| 1659 // bookmarked; use the last visible index. | 1661 // bookmarked; use the last visible index. |
| 1660 location->index = GetFirstHiddenNodeIndex(); | 1662 location->index = GetFirstHiddenNodeIndex(); |
| 1661 } else { | 1663 } else { |
| 1662 return; | 1664 return; |
| 1663 } | 1665 } |
| 1664 } | 1666 } |
| 1665 | 1667 |
| 1666 if (location->on) { | 1668 if (location->on) { |
| 1667 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? | 1669 const BookmarkNode* parent = (location->button_type == DROP_OTHER_FOLDER) ? |
| 1668 model()->other_node() : | 1670 model_->other_node() : |
| 1669 model()->bookmark_bar_node()->GetChild(location->index); | 1671 model_->bookmark_bar_node()->GetChild(location->index); |
| 1670 location->operation = chrome::GetBookmarkDropOperation( | 1672 location->operation = chrome::GetBookmarkDropOperation( |
| 1671 profile, event, data, parent, parent->child_count()); | 1673 profile, event, data, parent, parent->child_count()); |
| 1672 if (!location->operation && !data.has_single_url() && | 1674 if (!location->operation && !data.has_single_url() && |
| 1673 data.GetFirstNode(model(), profile->GetPath()) == parent) { | 1675 data.GetFirstNode(model_, profile->GetPath()) == parent) { |
| 1674 // Don't open a menu if the node being dragged is the menu to open. | 1676 // Don't open a menu if the node being dragged is the menu to open. |
| 1675 location->on = false; | 1677 location->on = false; |
| 1676 } | 1678 } |
| 1677 } else { | 1679 } else { |
| 1678 location->operation = chrome::GetBookmarkDropOperation( | 1680 location->operation = chrome::GetBookmarkDropOperation( |
| 1679 profile, event, data, model()->bookmark_bar_node(), location->index); | 1681 profile, event, data, model_->bookmark_bar_node(), location->index); |
| 1680 } | 1682 } |
| 1681 } | 1683 } |
| 1682 | 1684 |
| 1683 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, | 1685 void BookmarkBarView::WriteBookmarkDragData(const BookmarkNode* node, |
| 1684 ui::OSExchangeData* data) { | 1686 ui::OSExchangeData* data) { |
| 1685 DCHECK(node && data); | 1687 DCHECK(node && data); |
| 1686 BookmarkNodeData drag_data(node); | 1688 BookmarkNodeData drag_data(node); |
| 1687 drag_data.Write(browser_->profile()->GetPath(), data); | 1689 drag_data.Write(browser_->profile()->GetPath(), data); |
| 1688 } | 1690 } |
| 1689 | 1691 |
| 1690 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, | 1692 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
| 1691 bool overflow_only) { | 1693 bool overflow_only) { |
| 1692 DCHECK(!throbbing_view_); | 1694 DCHECK(!throbbing_view_); |
| 1693 | 1695 |
| 1694 // Determine which visible button is showing the bookmark (or is an ancestor | 1696 // Determine which visible button is showing the bookmark (or is an ancestor |
| 1695 // of the bookmark). | 1697 // of the bookmark). |
| 1696 const BookmarkNode* bbn = model()->bookmark_bar_node(); | 1698 const BookmarkNode* bbn = model_->bookmark_bar_node(); |
| 1697 const BookmarkNode* parent_on_bb = node; | 1699 const BookmarkNode* parent_on_bb = node; |
| 1698 while (parent_on_bb) { | 1700 while (parent_on_bb) { |
| 1699 const BookmarkNode* parent = parent_on_bb->parent(); | 1701 const BookmarkNode* parent = parent_on_bb->parent(); |
| 1700 if (parent == bbn) | 1702 if (parent == bbn) |
| 1701 break; | 1703 break; |
| 1702 parent_on_bb = parent; | 1704 parent_on_bb = parent; |
| 1703 } | 1705 } |
| 1704 if (parent_on_bb) { | 1706 if (parent_on_bb) { |
| 1705 int index = bbn->GetIndexOf(parent_on_bb); | 1707 int index = bbn->GetIndexOf(parent_on_bb); |
| 1706 if (index >= GetFirstHiddenNodeIndex()) { | 1708 if (index >= GetFirstHiddenNodeIndex()) { |
| 1707 // Node is hidden, animate the overflow button. | 1709 // Node is hidden, animate the overflow button. |
| 1708 throbbing_view_ = overflow_button_; | 1710 throbbing_view_ = overflow_button_; |
| 1709 } else if (!overflow_only) { | 1711 } else if (!overflow_only) { |
| 1710 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); | 1712 throbbing_view_ = static_cast<CustomButton*>(child_at(index)); |
| 1711 } | 1713 } |
| 1712 } else if (client_->IsDescendantOfManagedNode(node)) { | 1714 } else if (client_->IsDescendantOfManagedNode(node)) { |
| 1713 throbbing_view_ = managed_bookmarks_button_; | 1715 throbbing_view_ = managed_bookmarks_button_; |
| 1714 } else if (!overflow_only) { | 1716 } else if (!overflow_only) { |
| 1715 throbbing_view_ = other_bookmarked_button_; | 1717 throbbing_view_ = other_bookmarked_button_; |
| 1716 } | 1718 } |
| 1717 | 1719 |
| 1718 // Use a large number so that the button continues to throb. | 1720 // Use a large number so that the button continues to throb. |
| 1719 if (throbbing_view_) | 1721 if (throbbing_view_) |
| 1720 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1722 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
| 1721 } | 1723 } |
| 1722 | 1724 |
| 1723 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( | 1725 views::CustomButton* BookmarkBarView::DetermineViewToThrobFromRemove( |
| 1724 const BookmarkNode* parent, | 1726 const BookmarkNode* parent, |
| 1725 int old_index) { | 1727 int old_index) { |
| 1726 const BookmarkNode* bbn = model()->bookmark_bar_node(); | 1728 const BookmarkNode* bbn = model_->bookmark_bar_node(); |
| 1727 const BookmarkNode* old_node = parent; | 1729 const BookmarkNode* old_node = parent; |
| 1728 int old_index_on_bb = old_index; | 1730 int old_index_on_bb = old_index; |
| 1729 while (old_node && old_node != bbn) { | 1731 while (old_node && old_node != bbn) { |
| 1730 const BookmarkNode* parent = old_node->parent(); | 1732 const BookmarkNode* parent = old_node->parent(); |
| 1731 if (parent == bbn) { | 1733 if (parent == bbn) { |
| 1732 old_index_on_bb = bbn->GetIndexOf(old_node); | 1734 old_index_on_bb = bbn->GetIndexOf(old_node); |
| 1733 break; | 1735 break; |
| 1734 } | 1736 } |
| 1735 old_node = parent; | 1737 old_node = parent; |
| 1736 } | 1738 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1756 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); | 1758 theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| 1757 for (int i = 0; i < GetBookmarkButtonCount(); ++i) | 1759 for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
| 1758 GetBookmarkButton(i)->SetEnabledColor(text_color); | 1760 GetBookmarkButton(i)->SetEnabledColor(text_color); |
| 1759 other_bookmarked_button_->SetEnabledColor(text_color); | 1761 other_bookmarked_button_->SetEnabledColor(text_color); |
| 1760 managed_bookmarks_button_->SetEnabledColor(text_color); | 1762 managed_bookmarks_button_->SetEnabledColor(text_color); |
| 1761 if (apps_page_shortcut_->visible()) | 1763 if (apps_page_shortcut_->visible()) |
| 1762 apps_page_shortcut_->SetEnabledColor(text_color); | 1764 apps_page_shortcut_->SetEnabledColor(text_color); |
| 1763 } | 1765 } |
| 1764 | 1766 |
| 1765 void BookmarkBarView::UpdateButtonsVisibility() { | 1767 void BookmarkBarView::UpdateButtonsVisibility() { |
| 1766 bool has_other_children = !model()->other_node()->empty(); | 1768 bool has_other_children = !model_->other_node()->empty(); |
| 1767 bool update_other = has_other_children != other_bookmarked_button_->visible(); | 1769 bool update_other = has_other_children != other_bookmarked_button_->visible(); |
| 1768 if (update_other) { | 1770 if (update_other) { |
| 1769 other_bookmarked_button_->SetVisible(has_other_children); | 1771 other_bookmarked_button_->SetVisible(has_other_children); |
| 1770 UpdateBookmarksSeparatorVisibility(); | 1772 UpdateBookmarksSeparatorVisibility(); |
| 1771 } | 1773 } |
| 1772 | 1774 |
| 1773 bool has_managed_children = !client_->managed_node()->empty(); | 1775 bool has_managed_children = !client_->managed_node()->empty(); |
| 1774 bool update_managed = | 1776 bool update_managed = |
| 1775 has_managed_children != managed_bookmarks_button_->visible(); | 1777 has_managed_children != managed_bookmarks_button_->visible(); |
| 1776 if (update_managed) | 1778 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. | 1842 // Then comes the managed bookmarks folder, if visible. |
| 1841 if (managed_bookmarks_button_->visible()) { | 1843 if (managed_bookmarks_button_->visible()) { |
| 1842 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? | 1844 gfx::Size managed_bookmarks_pref = managed_bookmarks_button_->visible() ? |
| 1843 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); | 1845 managed_bookmarks_button_->GetPreferredSize() : gfx::Size(); |
| 1844 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), | 1846 managed_bookmarks_button_->SetBounds(x, y, managed_bookmarks_pref.width(), |
| 1845 height); | 1847 height); |
| 1846 x += managed_bookmarks_pref.width() + kButtonPadding; | 1848 x += managed_bookmarks_pref.width() + kButtonPadding; |
| 1847 } | 1849 } |
| 1848 | 1850 |
| 1849 // Then go through the bookmark buttons. | 1851 // Then go through the bookmark buttons. |
| 1850 if (GetBookmarkButtonCount() == 0 && client_ && model()->loaded()) { | 1852 if (GetBookmarkButtonCount() == 0 && model_ && model_->loaded()) { |
| 1851 gfx::Size pref = instructions_->GetPreferredSize(); | 1853 gfx::Size pref = instructions_->GetPreferredSize(); |
| 1852 instructions_->SetBounds( | 1854 instructions_->SetBounds( |
| 1853 x + kInstructionsPadding, y, | 1855 x + kInstructionsPadding, y, |
| 1854 std::min(static_cast<int>(pref.width()), | 1856 std::min(static_cast<int>(pref.width()), |
| 1855 max_x - x), | 1857 max_x - x), |
| 1856 height); | 1858 height); |
| 1857 instructions_->SetVisible(true); | 1859 instructions_->SetVisible(true); |
| 1858 } else { | 1860 } else { |
| 1859 instructions_->SetVisible(false); | 1861 instructions_->SetVisible(false); |
| 1860 | 1862 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1903 DCHECK(apps_page_shortcut_); | 1905 DCHECK(apps_page_shortcut_); |
| 1904 // Only perform layout if required. | 1906 // Only perform layout if required. |
| 1905 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( | 1907 bool visible = chrome::ShouldShowAppsShortcutInBookmarkBar( |
| 1906 browser_->profile(), browser_->host_desktop_type()); | 1908 browser_->profile(), browser_->host_desktop_type()); |
| 1907 if (apps_page_shortcut_->visible() == visible) | 1909 if (apps_page_shortcut_->visible() == visible) |
| 1908 return; | 1910 return; |
| 1909 apps_page_shortcut_->SetVisible(visible); | 1911 apps_page_shortcut_->SetVisible(visible); |
| 1910 UpdateBookmarksSeparatorVisibility(); | 1912 UpdateBookmarksSeparatorVisibility(); |
| 1911 Layout(); | 1913 Layout(); |
| 1912 } | 1914 } |
| OLD | NEW |