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

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

Issue 1547563003: Fix and simplify bookmark bar detach/attach animation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months 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
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 other_bookmarks_button_(NULL), 540 other_bookmarks_button_(NULL),
541 managed_bookmarks_button_(NULL), 541 managed_bookmarks_button_(NULL),
542 supervised_bookmarks_button_(NULL), 542 supervised_bookmarks_button_(NULL),
543 apps_page_shortcut_(NULL), 543 apps_page_shortcut_(NULL),
544 overflow_button_(NULL), 544 overflow_button_(NULL),
545 instructions_(NULL), 545 instructions_(NULL),
546 bookmarks_separator_view_(NULL), 546 bookmarks_separator_view_(NULL),
547 browser_(browser), 547 browser_(browser),
548 browser_view_(browser_view), 548 browser_view_(browser_view),
549 infobar_visible_(false), 549 infobar_visible_(false),
550 size_animation_(this),
550 throbbing_view_(NULL), 551 throbbing_view_(NULL),
551 bookmark_bar_state_(BookmarkBar::SHOW), 552 bookmark_bar_state_(BookmarkBar::SHOW),
552 animating_detached_(false), 553 animating_detached_(false),
553 show_folder_method_factory_(this) { 554 show_folder_method_factory_(this) {
554 set_id(VIEW_ID_BOOKMARK_BAR); 555 set_id(VIEW_ID_BOOKMARK_BAR);
555 Init(); 556 Init();
556 557
557 size_animation_->Reset(1); 558 size_animation_.Reset(1);
558 } 559 }
559 560
560 BookmarkBarView::~BookmarkBarView() { 561 BookmarkBarView::~BookmarkBarView() {
561 if (model_) 562 if (model_)
562 model_->RemoveObserver(this); 563 model_->RemoveObserver(this);
563 564
564 // It's possible for the menu to outlive us, reset the observer to make sure 565 // It's possible for the menu to outlive us, reset the observer to make sure
565 // it doesn't have a reference to us. 566 // it doesn't have a reference to us.
566 if (bookmark_menu_) { 567 if (bookmark_menu_) {
567 bookmark_menu_->set_observer(NULL); 568 bookmark_menu_->set_observer(NULL);
(...skipping 28 matching lines...) Expand all
596 } 597 }
597 598
598 void BookmarkBarView::SetBookmarkBarState( 599 void BookmarkBarView::SetBookmarkBarState(
599 BookmarkBar::State state, 600 BookmarkBar::State state,
600 BookmarkBar::AnimateChangeType animate_type) { 601 BookmarkBar::AnimateChangeType animate_type) {
601 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE && 602 if (animate_type == BookmarkBar::ANIMATE_STATE_CHANGE &&
602 animations_enabled) { 603 animations_enabled) {
603 animating_detached_ = (state == BookmarkBar::DETACHED || 604 animating_detached_ = (state == BookmarkBar::DETACHED ||
604 bookmark_bar_state_ == BookmarkBar::DETACHED); 605 bookmark_bar_state_ == BookmarkBar::DETACHED);
605 if (state == BookmarkBar::SHOW) 606 if (state == BookmarkBar::SHOW)
606 size_animation_->Show(); 607 size_animation_.Show();
607 else 608 else
608 size_animation_->Hide(); 609 size_animation_.Hide();
609 } else { 610 } else {
610 size_animation_->Reset(state == BookmarkBar::SHOW ? 1 : 0); 611 size_animation_.Reset(state == BookmarkBar::SHOW ? 1 : 0);
611 } 612 }
612 bookmark_bar_state_ = state; 613 bookmark_bar_state_ = state;
613 } 614 }
614 615
615 bool BookmarkBarView::is_animating() {
616 return size_animation_->is_animating();
617 }
618
619 const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex( 616 const BookmarkNode* BookmarkBarView::GetNodeForButtonAtModelIndex(
620 const gfx::Point& loc, 617 const gfx::Point& loc,
621 int* model_start_index) { 618 int* model_start_index) {
622 *model_start_index = 0; 619 *model_start_index = 0;
623 620
624 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height()) 621 if (loc.x() < 0 || loc.x() >= width() || loc.y() < 0 || loc.y() >= height())
625 return NULL; 622 return NULL;
626 623
627 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y()); 624 gfx::Point adjusted_loc(GetMirroredXInView(loc.x()), loc.y());
628 625
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 base::string16 elided_url( 743 base::string16 elided_url(
747 url_formatter::ElideUrl(url, tt_fonts, max_width, languages)); 744 url_formatter::ElideUrl(url, tt_fonts, max_width, languages));
748 elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url); 745 elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url);
749 result.append(elided_url); 746 result.append(elided_url);
750 } 747 }
751 return result; 748 return result;
752 } 749 }
753 750
754 bool BookmarkBarView::IsDetached() const { 751 bool BookmarkBarView::IsDetached() const {
755 return (bookmark_bar_state_ == BookmarkBar::DETACHED) || 752 return (bookmark_bar_state_ == BookmarkBar::DETACHED) ||
756 (animating_detached_ && size_animation_->is_animating()); 753 (animating_detached_ && size_animation_.is_animating());
757 }
758
759 double BookmarkBarView::GetAnimationValue() const {
760 return size_animation_->GetCurrentValue();
761 } 754 }
762 755
763 int BookmarkBarView::GetToolbarOverlap() const { 756 int BookmarkBarView::GetToolbarOverlap() const {
764 int attached_overlap = kToolbarAttachedBookmarkBarOverlap + 757 int attached_overlap = kToolbarAttachedBookmarkBarOverlap +
765 views::NonClientFrameView::kClientEdgeThickness; 758 views::NonClientFrameView::kClientEdgeThickness;
766 if (!IsDetached()) 759 if (!IsDetached())
767 return attached_overlap; 760 return attached_overlap;
768 761
769 int detached_overlap = views::NonClientFrameView::kClientEdgeThickness; 762 int detached_overlap = views::NonClientFrameView::kClientEdgeThickness;
770 763
771 // Do not animate the overlap when the infobar is above us (i.e. when we're 764 // Do not animate the overlap when the infobar is above us (i.e. when we're
772 // detached), since drawing over the infobar looks weird. 765 // detached), since drawing over the infobar looks weird.
773 if (infobar_visible_) 766 if (infobar_visible_)
774 return detached_overlap; 767 return detached_overlap;
775 768
776 // When detached with no infobar, animate the overlap between the attached and 769 // When detached with no infobar, animate the overlap between the attached and
777 // detached states. 770 // detached states.
778 return detached_overlap + static_cast<int>( 771 return detached_overlap + static_cast<int>(
779 (attached_overlap - detached_overlap) * 772 (attached_overlap - detached_overlap) *
780 size_animation_->GetCurrentValue()); 773 size_animation_.GetCurrentValue());
781 } 774 }
782 775
783 gfx::Size BookmarkBarView::GetPreferredSize() const { 776 gfx::Size BookmarkBarView::GetPreferredSize() const {
784 gfx::Size prefsize; 777 gfx::Size prefsize;
785 if (IsDetached()) { 778 if (IsDetached()) {
786 prefsize.set_height( 779 prefsize.set_height(
787 chrome::kBookmarkBarHeight + 780 chrome::kBookmarkBarHeight +
788 static_cast<int>( 781 static_cast<int>(
789 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * 782 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) *
790 (1 - size_animation_->GetCurrentValue()))); 783 (1 - size_animation_.GetCurrentValue())));
791 } else { 784 } else {
792 prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight * 785 prefsize.set_height(static_cast<int>(chrome::kBookmarkBarHeight *
793 size_animation_->GetCurrentValue())); 786 size_animation_.GetCurrentValue()));
794 } 787 }
795 return prefsize; 788 return prefsize;
796 } 789 }
797 790
798 bool BookmarkBarView::CanProcessEventsWithinSubtree() const { 791 bool BookmarkBarView::CanProcessEventsWithinSubtree() const {
799 // If the bookmark bar is attached and the omnibox popup is open (on top of 792 // If the bookmark bar is attached and the omnibox popup is open (on top of
800 // the bar), prevent events from targeting the bookmark bar or any of its 793 // the bar), prevent events from targeting the bookmark bar or any of its
801 // descendants. This will prevent hovers/clicks just above the omnibox popup 794 // descendants. This will prevent hovers/clicks just above the omnibox popup
802 // from activating the top few pixels of items on the bookmark bar. 795 // from activating the top few pixels of items on the bookmark bar.
803 if (!IsDetached() && browser_view_ && 796 if (!IsDetached() && browser_view_ &&
804 browser_view_->GetLocationBar()->GetOmniboxView()->model()-> 797 browser_view_->GetLocationBar()->GetOmniboxView()->model()->
805 popup_model()->IsOpen()) { 798 popup_model()->IsOpen()) {
806 return false; 799 return false;
807 } 800 }
808 return true; 801 return true;
809 } 802 }
810 803
811 gfx::Size BookmarkBarView::GetMinimumSize() const { 804 gfx::Size BookmarkBarView::GetMinimumSize() const {
812 // The minimum width of the bookmark bar should at least contain the overflow 805 // The minimum width of the bookmark bar should at least contain the overflow
813 // button, by which one can access all the Bookmark Bar items, and the "Other 806 // button, by which one can access all the Bookmark Bar items, and the "Other
814 // Bookmarks" folder, along with appropriate margins and button padding. 807 // Bookmarks" folder, along with appropriate margins and button padding.
815 // It should also contain the Managed and/or Supervised Bookmarks folders, 808 // It should also contain the Managed and/or Supervised Bookmarks folders,
816 // if they are visible. 809 // if they are visible.
817 int width = GetHorizontalMargin(); 810 int width = GetHorizontalMargin();
818 811
819 int height = chrome::kBookmarkBarHeight; 812 int height = chrome::kBookmarkBarHeight;
820 if (IsDetached()) { 813 if (IsDetached()) {
821 double current_state = 1 - size_animation_->GetCurrentValue(); 814 double current_state = 1 - size_animation_.GetCurrentValue();
822 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state); 815 width += 2 * static_cast<int>(kNewTabHorizontalPadding * current_state);
823 height += static_cast<int>( 816 height += static_cast<int>(
824 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) * 817 (chrome::kNTPBookmarkBarHeight - chrome::kBookmarkBarHeight) *
825 current_state); 818 current_state);
826 } 819 }
827 820
828 if (managed_bookmarks_button_->visible()) { 821 if (managed_bookmarks_button_->visible()) {
829 gfx::Size size = managed_bookmarks_button_->GetPreferredSize(); 822 gfx::Size size = managed_bookmarks_button_->GetPreferredSize();
830 width += size.width() + kButtonPadding; 823 width += size.width() + kButtonPadding;
831 } 824 }
(...skipping 27 matching lines...) Expand all
859 return; 852 return;
860 853
861 int x = GetHorizontalMargin(); 854 int x = GetHorizontalMargin();
862 int top_margin = IsDetached() ? kDetachedTopMargin : 0; 855 int top_margin = IsDetached() ? kDetachedTopMargin : 0;
863 int y = top_margin; 856 int y = top_margin;
864 int width = View::width() - 2 * GetHorizontalMargin(); 857 int width = View::width() - 2 * GetHorizontalMargin();
865 int height = chrome::kBookmarkBarHeight - kBottomMargin; 858 int height = chrome::kBookmarkBarHeight - kBottomMargin;
866 int separator_margin = kSeparatorMargin; 859 int separator_margin = kSeparatorMargin;
867 860
868 if (IsDetached()) { 861 if (IsDetached()) {
869 double current_state = 1 - size_animation_->GetCurrentValue(); 862 double current_state = 1 - size_animation_.GetCurrentValue();
870 x += static_cast<int>(kNewTabHorizontalPadding * current_state); 863 x += static_cast<int>(kNewTabHorizontalPadding * current_state);
871 y += (View::height() - chrome::kBookmarkBarHeight) / 2; 864 y += (View::height() - chrome::kBookmarkBarHeight) / 2;
872 width -= static_cast<int>(kNewTabHorizontalPadding * current_state); 865 width -= static_cast<int>(kNewTabHorizontalPadding * current_state);
873 separator_margin -= static_cast<int>(kSeparatorMargin * current_state); 866 separator_margin -= static_cast<int>(kSeparatorMargin * current_state);
874 } else { 867 } else {
875 // For the attached appearance, pin the content to the bottom of the bar 868 // For the attached appearance, pin the content to the bottom of the bar
876 // when animating in/out, as shrinking its height instead looks weird. This 869 // when animating in/out, as shrinking its height instead looks weird. This
877 // also matches how we layout infobars. 870 // also matches how we layout infobars.
878 y += View::height() - chrome::kBookmarkBarHeight; 871 y += View::height() - chrome::kBookmarkBarHeight;
879 } 872 }
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1379 &press_pt, data, widget); 1372 &press_pt, data, widget);
1380 WriteBookmarkDragData(node, data); 1373 WriteBookmarkDragData(node, data);
1381 return; 1374 return;
1382 } 1375 }
1383 } 1376 }
1384 NOTREACHED(); 1377 NOTREACHED();
1385 } 1378 }
1386 1379
1387 int BookmarkBarView::GetDragOperationsForView(View* sender, 1380 int BookmarkBarView::GetDragOperationsForView(View* sender,
1388 const gfx::Point& p) { 1381 const gfx::Point& p) {
1389 if (size_animation_->is_animating() || 1382 if (size_animation_.is_animating() ||
1390 (size_animation_->GetCurrentValue() == 0 && 1383 (size_animation_.GetCurrentValue() == 0 &&
1391 bookmark_bar_state_ != BookmarkBar::DETACHED)) { 1384 bookmark_bar_state_ != BookmarkBar::DETACHED)) {
1392 // Don't let the user drag while animating open or we're closed (and not 1385 // Don't let the user drag while animating open or we're closed (and not
1393 // detached, when detached size_animation_ is always 0). This typically is 1386 // detached, when detached size_animation_ is always 0). This typically is
1394 // only hit if the user does something to inadvertently trigger DnD such as 1387 // only hit if the user does something to inadvertently trigger DnD such as
1395 // pressing the mouse and hitting control-b. 1388 // pressing the mouse and hitting control-b.
1396 return ui::DragDropTypes::DRAG_NONE; 1389 return ui::DragDropTypes::DRAG_NONE;
1397 } 1390 }
1398 1391
1399 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { 1392 for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
1400 if (sender == GetBookmarkButton(i)) { 1393 if (sender == GetBookmarkButton(i)) {
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1592 1585
1593 bookmarks_separator_view_ = new ButtonSeparatorView(); 1586 bookmarks_separator_view_ = new ButtonSeparatorView();
1594 AddChildView(bookmarks_separator_view_); 1587 AddChildView(bookmarks_separator_view_);
1595 UpdateBookmarksSeparatorVisibility(); 1588 UpdateBookmarksSeparatorVisibility();
1596 1589
1597 instructions_ = new BookmarkBarInstructionsView(this); 1590 instructions_ = new BookmarkBarInstructionsView(this);
1598 AddChildView(instructions_); 1591 AddChildView(instructions_);
1599 1592
1600 set_context_menu_controller(this); 1593 set_context_menu_controller(this);
1601 1594
1602 size_animation_.reset(new gfx::SlideAnimation(this));
1603
1604 model_ = BookmarkModelFactory::GetForProfile(browser_->profile()); 1595 model_ = BookmarkModelFactory::GetForProfile(browser_->profile());
1605 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile()); 1596 managed_ = ManagedBookmarkServiceFactory::GetForProfile(browser_->profile());
1606 if (model_) { 1597 if (model_) {
1607 model_->AddObserver(this); 1598 model_->AddObserver(this);
1608 if (model_->loaded()) 1599 if (model_->loaded())
1609 BookmarkModelLoaded(model_, false); 1600 BookmarkModelLoaded(model_, false);
1610 // else case: we'll receive notification back from the BookmarkModel when 1601 // else case: we'll receive notification back from the BookmarkModel when
1611 // done loading, then we'll populate the bar. 1602 // done loading, then we'll populate the bar.
1612 } 1603 }
1613 } 1604 }
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
2104 return; 2095 return;
2105 apps_page_shortcut_->SetVisible(visible); 2096 apps_page_shortcut_->SetVisible(visible);
2106 UpdateBookmarksSeparatorVisibility(); 2097 UpdateBookmarksSeparatorVisibility();
2107 LayoutAndPaint(); 2098 LayoutAndPaint();
2108 } 2099 }
2109 2100
2110 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() { 2101 void BookmarkBarView::OnShowManagedBookmarksPrefChanged() {
2111 if (UpdateOtherAndManagedButtonsVisibility()) 2102 if (UpdateOtherAndManagedButtonsVisibility())
2112 LayoutAndPaint(); 2103 LayoutAndPaint();
2113 } 2104 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/frame/browser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698