| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/bookmark_bar_view.h" | 5 #include "chrome/browser/views/bookmark_bar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 virtual void Paint(gfx::Canvas *canvas) { | 241 virtual void Paint(gfx::Canvas *canvas) { |
| 242 views::MenuButton::Paint(canvas, false); | 242 views::MenuButton::Paint(canvas, false); |
| 243 } | 243 } |
| 244 | 244 |
| 245 private: | 245 private: |
| 246 scoped_ptr<SlideAnimation> show_animation_; | 246 scoped_ptr<SlideAnimation> show_animation_; |
| 247 | 247 |
| 248 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); | 248 DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); |
| 249 }; | 249 }; |
| 250 | 250 |
| 251 // OverFlowButton (chevron) -------------------------------------------------- |
| 252 |
| 253 class OverFlowButton : public views::MenuButton { |
| 254 public: |
| 255 explicit OverFlowButton(BookmarkBarView* owner) |
| 256 : MenuButton(NULL, std::wstring(), owner, false), |
| 257 owner_(owner) {} |
| 258 |
| 259 virtual bool OnMousePressed(const views::MouseEvent& e) { |
| 260 owner_->StopThrobbing(true); |
| 261 return views::MenuButton::OnMousePressed(e); |
| 262 } |
| 263 |
| 264 private: |
| 265 BookmarkBarView* owner_; |
| 266 |
| 267 DISALLOW_COPY_AND_ASSIGN(OverFlowButton); |
| 268 }; |
| 269 |
| 251 } // namespace | 270 } // namespace |
| 252 | 271 |
| 253 // DropInfo ------------------------------------------------------------------- | 272 // DropInfo ------------------------------------------------------------------- |
| 254 | 273 |
| 255 // Tracks drops on the BookmarkBarView. | 274 // Tracks drops on the BookmarkBarView. |
| 256 | 275 |
| 257 struct BookmarkBarView::DropInfo { | 276 struct BookmarkBarView::DropInfo { |
| 258 DropInfo() | 277 DropInfo() |
| 259 : valid(false), | 278 : valid(false), |
| 260 drop_index(-1), | 279 drop_index(-1), |
| (...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 false); | 921 false); |
| 903 button->SetIcon(GetGroupIcon()); | 922 button->SetIcon(GetGroupIcon()); |
| 904 button->SetContextMenuController(this); | 923 button->SetContextMenuController(this); |
| 905 button->set_tag(kOtherFolderButtonTag); | 924 button->set_tag(kOtherFolderButtonTag); |
| 906 button->SetAccessibleName( | 925 button->SetAccessibleName( |
| 907 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); | 926 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); |
| 908 return button; | 927 return button; |
| 909 } | 928 } |
| 910 | 929 |
| 911 MenuButton* BookmarkBarView::CreateOverflowButton() { | 930 MenuButton* BookmarkBarView::CreateOverflowButton() { |
| 912 MenuButton* button = new MenuButton(NULL, std::wstring(), this, false); | 931 MenuButton* button = new OverFlowButton(this); |
| 913 button->SetIcon(*ResourceBundle::GetSharedInstance(). | 932 button->SetIcon(*ResourceBundle::GetSharedInstance(). |
| 914 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 933 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
| 915 | 934 |
| 916 // The overflow button's image contains an arrow and therefore it is a | 935 // The overflow button's image contains an arrow and therefore it is a |
| 917 // direction sensitive image and we need to flip it if the UI layout is | 936 // direction sensitive image and we need to flip it if the UI layout is |
| 918 // right-to-left. | 937 // right-to-left. |
| 919 // | 938 // |
| 920 // By default, menu buttons are not flipped because they generally contain | 939 // By default, menu buttons are not flipped because they generally contain |
| 921 // text and flipping the gfx::Canvas object will break text rendering. Since | 940 // text and flipping the gfx::Canvas object will break text rendering. Since |
| 922 // the overflow button does not contain text, we can safely flip it. | 941 // the overflow button does not contain text, we can safely flip it. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 NotifyModelChanged(); | 978 NotifyModelChanged(); |
| 960 model_->RemoveObserver(this); | 979 model_->RemoveObserver(this); |
| 961 model_ = NULL; | 980 model_ = NULL; |
| 962 } | 981 } |
| 963 | 982 |
| 964 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, | 983 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, |
| 965 const BookmarkNode* old_parent, | 984 const BookmarkNode* old_parent, |
| 966 int old_index, | 985 int old_index, |
| 967 const BookmarkNode* new_parent, | 986 const BookmarkNode* new_parent, |
| 968 int new_index) { | 987 int new_index) { |
| 969 StopThrobbing(true); | |
| 970 BookmarkNodeRemovedImpl(model, old_parent, old_index); | 988 BookmarkNodeRemovedImpl(model, old_parent, old_index); |
| 971 BookmarkNodeAddedImpl(model, new_parent, new_index); | 989 BookmarkNodeAddedImpl(model, new_parent, new_index); |
| 972 StartThrobbing(); | |
| 973 } | 990 } |
| 974 | 991 |
| 975 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, | 992 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, |
| 976 const BookmarkNode* parent, | 993 const BookmarkNode* parent, |
| 977 int index) { | 994 int index) { |
| 978 StopThrobbing(true); | |
| 979 BookmarkNodeAddedImpl(model, parent, index); | 995 BookmarkNodeAddedImpl(model, parent, index); |
| 980 StartThrobbing(); | |
| 981 } | 996 } |
| 982 | 997 |
| 983 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, | 998 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
| 984 const BookmarkNode* parent, | 999 const BookmarkNode* parent, |
| 985 int index) { | 1000 int index) { |
| 986 NotifyModelChanged(); | 1001 NotifyModelChanged(); |
| 987 if (parent != model_->GetBookmarkBarNode()) { | 1002 if (parent != model_->GetBookmarkBarNode()) { |
| 988 // We only care about nodes on the bookmark bar. | 1003 // We only care about nodes on the bookmark bar. |
| 989 return; | 1004 return; |
| 990 } | 1005 } |
| 991 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); | 1006 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); |
| 992 AddChildView(index, CreateBookmarkButton(parent->GetChild(index))); | 1007 const BookmarkNode* node = parent->GetChild(index); |
| 1008 if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { |
| 1009 StartThrobbing(node, true); |
| 1010 } |
| 1011 AddChildView(index, CreateBookmarkButton(node)); |
| 993 UpdateColors(); | 1012 UpdateColors(); |
| 994 Layout(); | 1013 Layout(); |
| 995 SchedulePaint(); | 1014 SchedulePaint(); |
| 996 } | 1015 } |
| 997 | 1016 |
| 998 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, | 1017 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, |
| 999 const BookmarkNode* parent, | 1018 const BookmarkNode* parent, |
| 1000 int old_index, | 1019 int old_index, |
| 1001 const BookmarkNode* node) { | 1020 const BookmarkNode* node) { |
| 1002 StopThrobbing(true); | |
| 1003 BookmarkNodeRemovedImpl(model, parent, old_index); | 1021 BookmarkNodeRemovedImpl(model, parent, old_index); |
| 1004 StartThrobbing(); | |
| 1005 } | 1022 } |
| 1006 | 1023 |
| 1007 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, | 1024 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, |
| 1008 const BookmarkNode* parent, | 1025 const BookmarkNode* parent, |
| 1009 int index) { | 1026 int index) { |
| 1010 StopThrobbing(true); | 1027 StopThrobbing(true); |
| 1011 // No need to start throbbing again as the bookmark bubble can't be up at | 1028 // No need to start throbbing again as the bookmark bubble can't be up at |
| 1012 // the same time as the user reorders. | 1029 // the same time as the user reorders. |
| 1013 | 1030 |
| 1014 NotifyModelChanged(); | 1031 NotifyModelChanged(); |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1274 DCHECK(profile_); | 1291 DCHECK(profile_); |
| 1275 switch (type.value) { | 1292 switch (type.value) { |
| 1276 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: | 1293 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: |
| 1277 if (IsAlwaysShown()) { | 1294 if (IsAlwaysShown()) { |
| 1278 size_animation_->Show(); | 1295 size_animation_->Show(); |
| 1279 } else { | 1296 } else { |
| 1280 size_animation_->Hide(); | 1297 size_animation_->Hide(); |
| 1281 } | 1298 } |
| 1282 break; | 1299 break; |
| 1283 | 1300 |
| 1284 case NotificationType::BOOKMARK_BUBBLE_SHOWN: | 1301 case NotificationType::BOOKMARK_BUBBLE_SHOWN: { |
| 1285 StopThrobbing(true); | 1302 StopThrobbing(true); |
| 1286 bubble_url_ = *(Details<GURL>(details).ptr()); | 1303 GURL url = *(Details<GURL>(details).ptr()); |
| 1287 StartThrobbing(); | 1304 const BookmarkNode* node = model_->GetMostRecentlyAddedNodeForURL(url); |
| 1305 if (!node) |
| 1306 return; // Generally shouldn't happen. |
| 1307 StartThrobbing(node, false); |
| 1288 break; | 1308 break; |
| 1289 | 1309 } |
| 1290 case NotificationType::BOOKMARK_BUBBLE_HIDDEN: | 1310 case NotificationType::BOOKMARK_BUBBLE_HIDDEN: |
| 1291 StopThrobbing(false); | 1311 StopThrobbing(false); |
| 1292 bubble_url_ = GURL(); | |
| 1293 break; | 1312 break; |
| 1294 | 1313 |
| 1295 default: | 1314 default: |
| 1296 NOTREACHED(); | 1315 NOTREACHED(); |
| 1297 break; | 1316 break; |
| 1298 } | 1317 } |
| 1299 } | 1318 } |
| 1300 | 1319 |
| 1301 void BookmarkBarView::ThemeChanged() { | 1320 void BookmarkBarView::ThemeChanged() { |
| 1302 UpdateColors(); | 1321 UpdateColors(); |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1477 | 1496 |
| 1478 int BookmarkBarView::GetFirstHiddenNodeIndex() { | 1497 int BookmarkBarView::GetFirstHiddenNodeIndex() { |
| 1479 const int bb_count = GetBookmarkButtonCount(); | 1498 const int bb_count = GetBookmarkButtonCount(); |
| 1480 for (int i = 0; i < bb_count; ++i) { | 1499 for (int i = 0; i < bb_count; ++i) { |
| 1481 if (!GetBookmarkButton(i)->IsVisible()) | 1500 if (!GetBookmarkButton(i)->IsVisible()) |
| 1482 return i; | 1501 return i; |
| 1483 } | 1502 } |
| 1484 return bb_count; | 1503 return bb_count; |
| 1485 } | 1504 } |
| 1486 | 1505 |
| 1487 void BookmarkBarView::StartThrobbing() { | 1506 void BookmarkBarView::StartThrobbing(const BookmarkNode* node, |
| 1507 bool overflow_only) { |
| 1488 DCHECK(!throbbing_view_); | 1508 DCHECK(!throbbing_view_); |
| 1489 | 1509 |
| 1490 if (bubble_url_.is_empty()) | 1510 // Determine which visible button is showing the bookmark (or is an ancestor |
| 1491 return; // Bubble isn't showing; nothing to throb. | 1511 // of the bookmark). |
| 1492 | 1512 const BookmarkNode* bbn = model_->GetBookmarkBarNode(); |
| 1493 if (!GetWidget()) | 1513 const BookmarkNode* parent_on_bb = node; |
| 1494 return; // We're not showing, don't do anything. | 1514 while (parent_on_bb) { |
| 1495 | 1515 const BookmarkNode* parent = parent_on_bb->GetParent(); |
| 1496 const BookmarkNode* node = | 1516 if (parent == bbn) |
| 1497 model_->GetMostRecentlyAddedNodeForURL(bubble_url_); | 1517 break; |
| 1498 if (!node) | 1518 parent_on_bb = parent; |
| 1499 return; // Generally shouldn't happen. | 1519 } |
| 1500 | 1520 if (parent_on_bb) { |
| 1501 // Determine which visible button is showing the url (or is an ancestor of | |
| 1502 // the url). | |
| 1503 if (node->HasAncestor(model_->GetBookmarkBarNode())) { | |
| 1504 const BookmarkNode* bbn = model_->GetBookmarkBarNode(); | |
| 1505 const BookmarkNode* parent_on_bb = node; | |
| 1506 while (parent_on_bb->GetParent() != bbn) | |
| 1507 parent_on_bb = parent_on_bb->GetParent(); | |
| 1508 int index = bbn->IndexOfChild(parent_on_bb); | 1521 int index = bbn->IndexOfChild(parent_on_bb); |
| 1509 if (index >= GetFirstHiddenNodeIndex()) { | 1522 if (index >= GetFirstHiddenNodeIndex()) { |
| 1510 // Node is hidden, animate the overflow button. | 1523 // Node is hidden, animate the overflow button. |
| 1511 throbbing_view_ = overflow_button_; | 1524 throbbing_view_ = overflow_button_; |
| 1512 } else { | 1525 } else if (!overflow_only) { |
| 1513 throbbing_view_ = static_cast<CustomButton*>(GetChildViewAt(index)); | 1526 throbbing_view_ = static_cast<CustomButton*>(GetChildViewAt(index)); |
| 1514 } | 1527 } |
| 1515 } else { | 1528 } else if (!overflow_only) { |
| 1516 throbbing_view_ = other_bookmarked_button_; | 1529 throbbing_view_ = other_bookmarked_button_; |
| 1517 } | 1530 } |
| 1518 | 1531 |
| 1519 // Use a large number so that the button continues to throb. | 1532 // Use a large number so that the button continues to throb. |
| 1520 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); | 1533 if (throbbing_view_) |
| 1534 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); |
| 1521 } | 1535 } |
| 1522 | 1536 |
| 1523 void BookmarkBarView::StopThrobbing(bool immediate) { | 1537 void BookmarkBarView::StopThrobbing(bool immediate) { |
| 1524 if (!throbbing_view_) | 1538 if (!throbbing_view_) |
| 1525 return; | 1539 return; |
| 1526 | 1540 |
| 1527 // If not immediate, cycle through 2 more complete cycles. | 1541 // If not immediate, cycle through 2 more complete cycles. |
| 1528 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 1542 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
| 1529 throbbing_view_ = NULL; | 1543 throbbing_view_ = NULL; |
| 1530 } | 1544 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1706 // The tooltip is the only way we have to display text explaining the error | 1720 // The tooltip is the only way we have to display text explaining the error |
| 1707 // to the user. | 1721 // to the user. |
| 1708 sync_error_button->SetTooltipText( | 1722 sync_error_button->SetTooltipText( |
| 1709 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); | 1723 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); |
| 1710 sync_error_button->SetAccessibleName( | 1724 sync_error_button->SetAccessibleName( |
| 1711 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); | 1725 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); |
| 1712 sync_error_button->SetIcon( | 1726 sync_error_button->SetIcon( |
| 1713 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); | 1727 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); |
| 1714 return sync_error_button; | 1728 return sync_error_button; |
| 1715 } | 1729 } |
| OLD | NEW |