Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 395005: Makes the chevron throb after a user sync'ed his bookmarks (if the overflow m... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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), owner_(owner) {}
257
258 virtual bool OnMousePressed(const views::MouseEvent& e) {
259 owner_->StopThrobbing(true);
260 return views::MenuButton::OnMousePressed(e);
261 }
262 private:
263 BookmarkBarView* owner_;
264
265 DISALLOW_COPY_AND_ASSIGN(OverFlowButton);
266 };
267
251 } // namespace 268 } // namespace
252 269
253 // DropInfo ------------------------------------------------------------------- 270 // DropInfo -------------------------------------------------------------------
254 271
255 // Tracks drops on the BookmarkBarView. 272 // Tracks drops on the BookmarkBarView.
256 273
257 struct BookmarkBarView::DropInfo { 274 struct BookmarkBarView::DropInfo {
258 DropInfo() 275 DropInfo()
259 : valid(false), 276 : valid(false),
260 drop_index(-1), 277 drop_index(-1),
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 false); 917 false);
901 button->SetIcon(GetGroupIcon()); 918 button->SetIcon(GetGroupIcon());
902 button->SetContextMenuController(this); 919 button->SetContextMenuController(this);
903 button->set_tag(kOtherFolderButtonTag); 920 button->set_tag(kOtherFolderButtonTag);
904 button->SetAccessibleName( 921 button->SetAccessibleName(
905 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); 922 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED));
906 return button; 923 return button;
907 } 924 }
908 925
909 MenuButton* BookmarkBarView::CreateOverflowButton() { 926 MenuButton* BookmarkBarView::CreateOverflowButton() {
910 MenuButton* button = new MenuButton(NULL, std::wstring(), this, false); 927 MenuButton* button = new OverFlowButton(this);
911 button->SetIcon(*ResourceBundle::GetSharedInstance(). 928 button->SetIcon(*ResourceBundle::GetSharedInstance().
912 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); 929 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS));
913 930
914 // The overflow button's image contains an arrow and therefore it is a 931 // The overflow button's image contains an arrow and therefore it is a
915 // direction sensitive image and we need to flip it if the UI layout is 932 // direction sensitive image and we need to flip it if the UI layout is
916 // right-to-left. 933 // right-to-left.
917 // 934 //
918 // By default, menu buttons are not flipped because they generally contain 935 // By default, menu buttons are not flipped because they generally contain
919 // text and flipping the gfx::Canvas object will break text rendering. Since 936 // text and flipping the gfx::Canvas object will break text rendering. Since
920 // the overflow button does not contain text, we can safely flip it. 937 // the overflow button does not contain text, we can safely flip it.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 NotifyModelChanged(); 974 NotifyModelChanged();
958 model_->RemoveObserver(this); 975 model_->RemoveObserver(this);
959 model_ = NULL; 976 model_ = NULL;
960 } 977 }
961 978
962 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model, 979 void BookmarkBarView::BookmarkNodeMoved(BookmarkModel* model,
963 const BookmarkNode* old_parent, 980 const BookmarkNode* old_parent,
964 int old_index, 981 int old_index,
965 const BookmarkNode* new_parent, 982 const BookmarkNode* new_parent,
966 int new_index) { 983 int new_index) {
967 StopThrobbing(true);
968 BookmarkNodeRemovedImpl(model, old_parent, old_index); 984 BookmarkNodeRemovedImpl(model, old_parent, old_index);
969 BookmarkNodeAddedImpl(model, new_parent, new_index); 985 BookmarkNodeAddedImpl(model, new_parent, new_index);
970 StartThrobbing();
971 } 986 }
972 987
973 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model, 988 void BookmarkBarView::BookmarkNodeAdded(BookmarkModel* model,
974 const BookmarkNode* parent, 989 const BookmarkNode* parent,
975 int index) { 990 int index) {
976 StopThrobbing(true);
977 BookmarkNodeAddedImpl(model, parent, index); 991 BookmarkNodeAddedImpl(model, parent, index);
978 StartThrobbing();
979 } 992 }
980 993
981 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, 994 void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
982 const BookmarkNode* parent, 995 const BookmarkNode* parent,
983 int index) { 996 int index) {
984 NotifyModelChanged(); 997 NotifyModelChanged();
985 if (parent != model_->GetBookmarkBarNode()) { 998 if (parent != model_->GetBookmarkBarNode()) {
986 // We only care about nodes on the bookmark bar. 999 // We only care about nodes on the bookmark bar.
987 return; 1000 return;
988 } 1001 }
989 DCHECK(index >= 0 && index <= GetBookmarkButtonCount()); 1002 DCHECK(index >= 0 && index <= GetBookmarkButtonCount());
990 AddChildView(index, CreateBookmarkButton(parent->GetChild(index))); 1003 const BookmarkNode* node = parent->GetChild(index);
1004 if (!throbbing_view_ && sync_service_->SetupInProgress()) {
1005 StartThrobbing(node, true);
1006 }
1007 AddChildView(index, CreateBookmarkButton(node));
991 UpdateColors(); 1008 UpdateColors();
992 Layout(); 1009 Layout();
993 SchedulePaint(); 1010 SchedulePaint();
994 } 1011 }
995 1012
996 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model, 1013 void BookmarkBarView::BookmarkNodeRemoved(BookmarkModel* model,
997 const BookmarkNode* parent, 1014 const BookmarkNode* parent,
998 int old_index, 1015 int old_index,
999 const BookmarkNode* node) { 1016 const BookmarkNode* node) {
1000 StopThrobbing(true);
1001 BookmarkNodeRemovedImpl(model, parent, old_index); 1017 BookmarkNodeRemovedImpl(model, parent, old_index);
1002 StartThrobbing();
1003 } 1018 }
1004 1019
1005 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model, 1020 void BookmarkBarView::BookmarkNodeRemovedImpl(BookmarkModel* model,
1006 const BookmarkNode* parent, 1021 const BookmarkNode* parent,
1007 int index) { 1022 int index) {
1008 StopThrobbing(true); 1023 StopThrobbing(true);
1009 // No need to start throbbing again as the bookmark bubble can't be up at 1024 // No need to start throbbing again as the bookmark bubble can't be up at
1010 // the same time as the user reorders. 1025 // the same time as the user reorders.
1011 1026
1012 NotifyModelChanged(); 1027 NotifyModelChanged();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 DCHECK(profile_); 1287 DCHECK(profile_);
1273 switch (type.value) { 1288 switch (type.value) {
1274 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED: 1289 case NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED:
1275 if (IsAlwaysShown()) { 1290 if (IsAlwaysShown()) {
1276 size_animation_->Show(); 1291 size_animation_->Show();
1277 } else { 1292 } else {
1278 size_animation_->Hide(); 1293 size_animation_->Hide();
1279 } 1294 }
1280 break; 1295 break;
1281 1296
1282 case NotificationType::BOOKMARK_BUBBLE_SHOWN: 1297 case NotificationType::BOOKMARK_BUBBLE_SHOWN: {
1283 StopThrobbing(true); 1298 StopThrobbing(true);
1284 bubble_url_ = *(Details<GURL>(details).ptr()); 1299 const BookmarkNode* node =
1285 StartThrobbing(); 1300 model_->GetMostRecentlyAddedNodeForURL(*(Details<GURL>(details).ptr()));
1301 if (!node)
1302 return; // Generally shouldn't happen.
1303 StartThrobbing(node, false);
1286 break; 1304 break;
1287 1305 }
1288 case NotificationType::BOOKMARK_BUBBLE_HIDDEN: 1306 case NotificationType::BOOKMARK_BUBBLE_HIDDEN:
1289 StopThrobbing(false); 1307 StopThrobbing(false);
1290 bubble_url_ = GURL();
1291 break; 1308 break;
1292 1309
1293 default: 1310 default:
1294 NOTREACHED(); 1311 NOTREACHED();
1295 break; 1312 break;
1296 } 1313 }
1297 } 1314 }
1298 1315
1299 void BookmarkBarView::ThemeChanged() { 1316 void BookmarkBarView::ThemeChanged() {
1300 UpdateColors(); 1317 UpdateColors();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 1492
1476 int BookmarkBarView::GetFirstHiddenNodeIndex() { 1493 int BookmarkBarView::GetFirstHiddenNodeIndex() {
1477 const int bb_count = GetBookmarkButtonCount(); 1494 const int bb_count = GetBookmarkButtonCount();
1478 for (int i = 0; i < bb_count; ++i) { 1495 for (int i = 0; i < bb_count; ++i) {
1479 if (!GetBookmarkButton(i)->IsVisible()) 1496 if (!GetBookmarkButton(i)->IsVisible())
1480 return i; 1497 return i;
1481 } 1498 }
1482 return bb_count; 1499 return bb_count;
1483 } 1500 }
1484 1501
1485 void BookmarkBarView::StartThrobbing() { 1502 void BookmarkBarView::StartThrobbing(const BookmarkNode* node,
1503 bool overflow_only) {
1486 DCHECK(!throbbing_view_); 1504 DCHECK(!throbbing_view_);
1487 1505
1488 if (bubble_url_.is_empty()) 1506 // Determine which visible button is showing the bookmark (or is an ancestor
1489 return; // Bubble isn't showing; nothing to throb. 1507 // of the bookmark).
1490 1508 const BookmarkNode* bbn = model_->GetBookmarkBarNode();
1491 if (!GetWidget()) 1509 const BookmarkNode* parent_on_bb = node;
1492 return; // We're not showing, don't do anything. 1510 while (parent_on_bb) {
1493 1511 const BookmarkNode* parent = parent_on_bb->GetParent();
1494 const BookmarkNode* node = 1512 if (parent == bbn)
1495 model_->GetMostRecentlyAddedNodeForURL(bubble_url_); 1513 break;
1496 if (!node) 1514 parent_on_bb = parent;
1497 return; // Generally shouldn't happen. 1515 }
1498 1516 if (parent_on_bb) {
1499 // Determine which visible button is showing the url (or is an ancestor of
1500 // the url).
1501 if (node->HasAncestor(model_->GetBookmarkBarNode())) {
1502 const BookmarkNode* bbn = model_->GetBookmarkBarNode();
1503 const BookmarkNode* parent_on_bb = node;
1504 while (parent_on_bb->GetParent() != bbn)
1505 parent_on_bb = parent_on_bb->GetParent();
1506 int index = bbn->IndexOfChild(parent_on_bb); 1517 int index = bbn->IndexOfChild(parent_on_bb);
1507 if (index >= GetFirstHiddenNodeIndex()) { 1518 if (index >= GetFirstHiddenNodeIndex()) {
1508 // Node is hidden, animate the overflow button. 1519 // Node is hidden, animate the overflow button.
1509 throbbing_view_ = overflow_button_; 1520 throbbing_view_ = overflow_button_;
1510 } else { 1521 } else if (!overflow_only) {
1511 throbbing_view_ = static_cast<CustomButton*>(GetChildViewAt(index)); 1522 throbbing_view_ = static_cast<CustomButton*>(GetChildViewAt(index));
1512 } 1523 }
1513 } else { 1524 } else if (!overflow_only) {
1514 throbbing_view_ = other_bookmarked_button_; 1525 throbbing_view_ = other_bookmarked_button_;
1515 } 1526 }
1516 1527
1517 // Use a large number so that the button continues to throb. 1528 // Use a large number so that the button continues to throb.
1518 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max()); 1529 if (throbbing_view_)
1530 throbbing_view_->StartThrobbing(std::numeric_limits<int>::max());
1519 } 1531 }
1520 1532
1521 void BookmarkBarView::StopThrobbing(bool immediate) { 1533 void BookmarkBarView::StopThrobbing(bool immediate) {
1522 if (!throbbing_view_) 1534 if (!throbbing_view_)
1523 return; 1535 return;
1524 1536
1525 // If not immediate, cycle through 2 more complete cycles. 1537 // If not immediate, cycle through 2 more complete cycles.
1526 throbbing_view_->StartThrobbing(immediate ? 0 : 4); 1538 throbbing_view_->StartThrobbing(immediate ? 0 : 4);
1527 throbbing_view_ = NULL; 1539 throbbing_view_ = NULL;
1528 } 1540 }
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
1704 // The tooltip is the only way we have to display text explaining the error 1716 // The tooltip is the only way we have to display text explaining the error
1705 // to the user. 1717 // to the user.
1706 sync_error_button->SetTooltipText( 1718 sync_error_button->SetTooltipText(
1707 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC)); 1719 l10n_util::GetString(IDS_SYNC_BOOKMARK_BAR_ERROR_DESC));
1708 sync_error_button->SetAccessibleName( 1720 sync_error_button->SetAccessibleName(
1709 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON)); 1721 l10n_util::GetString(IDS_ACCNAME_SYNC_ERROR_BUTTON));
1710 sync_error_button->SetIcon( 1722 sync_error_button->SetIcon(
1711 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING)); 1723 *ResourceBundle::GetSharedInstance().GetBitmapNamed(IDR_WARNING));
1712 return sync_error_button; 1724 return sync_error_button;
1713 } 1725 }
OLDNEW
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698