OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/base_drag_source.h" | 9 #include "base/base_drag_source.h" |
10 #include "base/gfx/skia_utils.h" | 10 #include "base/gfx/skia_utils.h" |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 paint_down.setShader(gfx::CreateGradientShader(height() / 2, | 621 paint_down.setShader(gfx::CreateGradientShader(height() / 2, |
622 height(), | 622 height(), |
623 kSeparatorColor, | 623 kSeparatorColor, |
624 kBackgroundColor))->safeUnref(); | 624 kBackgroundColor))->safeUnref(); |
625 SkRect rc_down = { | 625 SkRect rc_down = { |
626 SkIntToScalar(kSeparatorStartX), SkIntToScalar(height() / 2), | 626 SkIntToScalar(kSeparatorStartX), SkIntToScalar(height() / 2), |
627 SkIntToScalar(1), SkIntToScalar(height() - 1) }; | 627 SkIntToScalar(1), SkIntToScalar(height() - 1) }; |
628 canvas->drawRect(rc_down, paint_down); | 628 canvas->drawRect(rc_down, paint_down); |
629 } | 629 } |
630 | 630 |
631 virtual void GetPreferredSize(CSize* out) { | 631 virtual gfx::Size GetPreferredSize() { |
632 // We get the full height of the bookmark bar, so that the height returned | 632 // We get the full height of the bookmark bar, so that the height returned |
633 // here doesn't matter. | 633 // here doesn't matter. |
634 out->SetSize(kSeparatorWidth, 1); | 634 return gfx::Size(kSeparatorWidth, 1); |
635 } | 635 } |
636 | 636 |
637 private: | 637 private: |
638 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 638 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
639 }; | 639 }; |
640 | 640 |
641 } // namespace | 641 } // namespace |
642 | 642 |
643 // BookmarkBarView ------------------------------------------------------------ | 643 // BookmarkBarView ------------------------------------------------------------ |
644 | 644 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 if (model_->IsLoaded()) | 732 if (model_->IsLoaded()) |
733 Loaded(model_); | 733 Loaded(model_); |
734 // else case: we'll receive notification back from the BookmarkModel when done | 734 // else case: we'll receive notification back from the BookmarkModel when done |
735 // loading, then we'll populate the bar. | 735 // loading, then we'll populate the bar. |
736 } | 736 } |
737 | 737 |
738 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { | 738 void BookmarkBarView::SetPageNavigator(PageNavigator* navigator) { |
739 page_navigator_ = navigator; | 739 page_navigator_ = navigator; |
740 } | 740 } |
741 | 741 |
742 void BookmarkBarView::GetPreferredSize(CSize *out) { | 742 gfx::Size BookmarkBarView::GetPreferredSize() { |
743 if (!prefButtonHeight) { | 743 if (!prefButtonHeight) { |
744 ChromeViews::TextButton text_button(L"X"); | 744 ChromeViews::TextButton text_button(L"X"); |
745 CSize text_button_pref; | 745 gfx::Size text_button_pref = text_button.GetMinimumSize(); |
746 text_button.GetMinimumSize(&text_button_pref); | 746 prefButtonHeight = static_cast<int>(text_button_pref.height()); |
747 prefButtonHeight = static_cast<int>(text_button_pref.cy); | |
748 } | 747 } |
749 | 748 |
| 749 gfx::Size prefsize; |
750 if (IsNewTabPage()) { | 750 if (IsNewTabPage()) { |
751 out->cy = kBarHeight + static_cast<int>(static_cast<double> | 751 prefsize.set_height(kBarHeight + static_cast<int>(static_cast<double> |
752 (kNewtabBarHeight - kBarHeight) * | 752 (kNewtabBarHeight - kBarHeight) * |
753 (1 - size_animation_->GetCurrentValue())); | 753 (1 - size_animation_->GetCurrentValue()))); |
754 } else { | 754 } else { |
755 out->cy = std::max(static_cast<int>(static_cast<double>(kBarHeight) * | 755 prefsize.set_height( |
756 size_animation_->GetCurrentValue()), 1); | 756 std::max(static_cast<int>(static_cast<double>(kBarHeight) * |
| 757 size_animation_->GetCurrentValue()), 1)); |
757 } | 758 } |
758 | 759 |
759 // Width doesn't matter, we're always given a width based on the browser size. | 760 // Width doesn't matter, we're always given a width based on the browser |
760 out->cx = 1; | 761 // size. |
| 762 prefsize.set_width(1); |
| 763 |
| 764 return prefsize; |
761 } | 765 } |
762 | 766 |
763 void BookmarkBarView::Layout() { | 767 void BookmarkBarView::Layout() { |
764 if (!GetParent()) | 768 if (!GetParent()) |
765 return; | 769 return; |
766 | 770 |
767 // First layout out the buttons. Any buttons that are placed beyond the | 771 // First layout out the buttons. Any buttons that are placed beyond the |
768 // visible region and made invisible. | 772 // visible region and made invisible. |
769 int x = kLeftMargin; | 773 int x = kLeftMargin; |
770 int y = kTopMargin; | 774 int y = kTopMargin; |
771 int width = View::width() - kRightMargin - kLeftMargin; | 775 int width = View::width() - kRightMargin - kLeftMargin; |
772 int height = View::height() - kTopMargin - kBottomMargin; | 776 int height = View::height() - kTopMargin - kBottomMargin; |
773 int separator_margin = kSeparatorMargin; | 777 int separator_margin = kSeparatorMargin; |
774 | 778 |
775 if (IsNewTabPage()) { | 779 if (IsNewTabPage()) { |
776 double current_state = 1 - size_animation_->GetCurrentValue(); | 780 double current_state = 1 - size_animation_->GetCurrentValue(); |
777 x += static_cast<int>(static_cast<double> | 781 x += static_cast<int>(static_cast<double> |
778 (kNewtabHorizontalPadding) * current_state); | 782 (kNewtabHorizontalPadding) * current_state); |
779 y += static_cast<int>(static_cast<double> | 783 y += static_cast<int>(static_cast<double> |
780 (kNewtabVerticalPadding) * current_state); | 784 (kNewtabVerticalPadding) * current_state); |
781 width -= static_cast<int>(static_cast<double> | 785 width -= static_cast<int>(static_cast<double> |
782 (kNewtabHorizontalPadding) * current_state); | 786 (kNewtabHorizontalPadding) * current_state); |
783 height -= static_cast<int>(static_cast<double> | 787 height -= static_cast<int>(static_cast<double> |
784 (kNewtabVerticalPadding * 2) * current_state); | 788 (kNewtabVerticalPadding * 2) * current_state); |
785 separator_margin -= static_cast<int>(static_cast<double> | 789 separator_margin -= static_cast<int>(static_cast<double> |
786 (kSeparatorMargin) * current_state); | 790 (kSeparatorMargin) * current_state); |
787 } | 791 } |
788 | 792 |
789 CSize other_bookmarked_pref; | 793 gfx::Size other_bookmarked_pref = |
790 other_bookmarked_button_->GetPreferredSize(&other_bookmarked_pref); | 794 other_bookmarked_button_->GetPreferredSize(); |
791 CSize overflow_pref; | 795 gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
792 overflow_button_->GetPreferredSize(&overflow_pref); | 796 gfx::Size bookmarks_separator_pref = |
793 CSize bookmarks_separator_pref; | 797 bookmarks_separator_view_->GetPreferredSize(); |
794 bookmarks_separator_view_->GetPreferredSize(&bookmarks_separator_pref); | 798 const int max_x = width - other_bookmarked_pref.width() - kButtonPadding - |
795 const int max_x = width - other_bookmarked_pref.cx - kButtonPadding - | 799 overflow_pref.width() - kButtonPadding - |
796 overflow_pref.cx - kButtonPadding - | 800 bookmarks_separator_pref.width(); |
797 bookmarks_separator_pref.cx; | |
798 | 801 |
799 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { | 802 if (GetBookmarkButtonCount() == 0 && model_ && model_->IsLoaded()) { |
800 CSize pref; | 803 gfx::Size pref = instructions_->GetPreferredSize(); |
801 instructions_->GetPreferredSize(&pref); | 804 instructions_->SetBounds( |
802 instructions_->SetBounds(x + kInstructionsPadding, y, | 805 x + kInstructionsPadding, y, |
803 std::min(static_cast<int>(pref.cx), max_x - x), | 806 std::min(static_cast<int>(pref.width()), |
804 height); | 807 max_x - x), |
| 808 height); |
805 instructions_->SetVisible(true); | 809 instructions_->SetVisible(true); |
806 } else { | 810 } else { |
807 instructions_->SetVisible(false); | 811 instructions_->SetVisible(false); |
808 | 812 |
809 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { | 813 for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
810 ChromeViews::View* child = GetChildViewAt(i); | 814 ChromeViews::View* child = GetChildViewAt(i); |
811 CSize pref; | 815 gfx::Size pref = child->GetPreferredSize(); |
812 child->GetPreferredSize(&pref); | 816 int next_x = x + pref.width() + kButtonPadding; |
813 int next_x = x + pref.cx + kButtonPadding; | |
814 child->SetVisible(next_x < max_x); | 817 child->SetVisible(next_x < max_x); |
815 child->SetBounds(x, y, pref.cx, height); | 818 child->SetBounds(x, y, pref.width(), height); |
816 x = next_x; | 819 x = next_x; |
817 } | 820 } |
818 } | 821 } |
819 | 822 |
820 // Layout the right side of the bar. | 823 // Layout the right side of the bar. |
821 const bool all_visible = | 824 const bool all_visible = |
822 (GetBookmarkButtonCount() == 0 || | 825 (GetBookmarkButtonCount() == 0 || |
823 GetChildViewAt(GetBookmarkButtonCount() - 1)->IsVisible()); | 826 GetChildViewAt(GetBookmarkButtonCount() - 1)->IsVisible()); |
824 | 827 |
825 // Layout the recently bookmarked button. | 828 // Layout the recently bookmarked button. |
826 x = max_x + kButtonPadding; | 829 x = max_x + kButtonPadding; |
827 | 830 |
828 // The overflow button. | 831 // The overflow button. |
829 overflow_button_->SetBounds(x, y, overflow_pref.cx, height); | 832 overflow_button_->SetBounds(x, y, overflow_pref.width(), height); |
830 overflow_button_->SetVisible(!all_visible); | 833 overflow_button_->SetVisible(!all_visible); |
831 | 834 |
832 x += overflow_pref.cx; | 835 x += overflow_pref.height(); |
833 | 836 |
834 // Separator. | 837 // Separator. |
835 bookmarks_separator_view_->SetBounds(x, | 838 bookmarks_separator_view_->SetBounds(x, |
836 y - kTopMargin, | 839 y - kTopMargin, |
837 bookmarks_separator_pref.cx, | 840 bookmarks_separator_pref.width(), |
838 height + kTopMargin + kBottomMargin - | 841 height + kTopMargin + kBottomMargin - |
839 separator_margin); | 842 separator_margin); |
840 x += bookmarks_separator_pref.cx; | 843 x += bookmarks_separator_pref.width(); |
841 | 844 |
842 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.cx, height); | 845 other_bookmarked_button_->SetBounds(x, y, other_bookmarked_pref.width(), |
843 x += other_bookmarked_pref.cx + kButtonPadding; | 846 height); |
| 847 x += other_bookmarked_pref.width() + kButtonPadding; |
844 } | 848 } |
845 | 849 |
846 void BookmarkBarView::DidChangeBounds(const CRect& previous, | 850 void BookmarkBarView::DidChangeBounds(const CRect& previous, |
847 const CRect& current) { | 851 const CRect& current) { |
848 Layout(); | 852 Layout(); |
849 } | 853 } |
850 | 854 |
851 void BookmarkBarView::ViewHierarchyChanged(bool is_add, | 855 void BookmarkBarView::ViewHierarchyChanged(bool is_add, |
852 View* parent, View* child) { | 856 View* parent, View* child) { |
853 if (is_add && child == this && height() > 0) { | 857 if (is_add && child == this && height() > 0) { |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 | 1295 |
1292 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, | 1296 void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
1293 BookmarkNode* node) { | 1297 BookmarkNode* node) { |
1294 if (node->GetParent() != model_->GetBookmarkBarNode()) { | 1298 if (node->GetParent() != model_->GetBookmarkBarNode()) { |
1295 // We only care about nodes on the bookmark bar. | 1299 // We only care about nodes on the bookmark bar. |
1296 return; | 1300 return; |
1297 } | 1301 } |
1298 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); | 1302 int index = model_->GetBookmarkBarNode()->IndexOfChild(node); |
1299 DCHECK(index != -1); | 1303 DCHECK(index != -1); |
1300 ChromeViews::TextButton* button = GetBookmarkButton(index); | 1304 ChromeViews::TextButton* button = GetBookmarkButton(index); |
1301 CSize old_pref; | 1305 gfx::Size old_pref = button->GetPreferredSize(); |
1302 button->GetPreferredSize(&old_pref); | |
1303 ConfigureButton(node, button); | 1306 ConfigureButton(node, button); |
1304 CSize new_pref; | 1307 gfx::Size new_pref = button->GetPreferredSize(); |
1305 button->GetPreferredSize(&new_pref); | 1308 if (old_pref.width() != new_pref.width()) { |
1306 if (old_pref.cx != new_pref.cx) { | |
1307 Layout(); | 1309 Layout(); |
1308 SchedulePaint(); | 1310 SchedulePaint(); |
1309 } else if (button->IsVisible()) { | 1311 } else if (button->IsVisible()) { |
1310 button->SchedulePaint(); | 1312 button->SchedulePaint(); |
1311 } | 1313 } |
1312 } | 1314 } |
1313 | 1315 |
1314 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, | 1316 void BookmarkBarView::BookmarkNodeFavIconLoaded(BookmarkModel* model, |
1315 BookmarkNode* node) { | 1317 BookmarkNode* node) { |
1316 if (menu_runner_.get()) | 1318 if (menu_runner_.get()) |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1856 } | 1858 } |
1857 | 1859 |
1858 void BookmarkBarView::StopThrobbing(bool immediate) { | 1860 void BookmarkBarView::StopThrobbing(bool immediate) { |
1859 if (!throbbing_view_) | 1861 if (!throbbing_view_) |
1860 return; | 1862 return; |
1861 | 1863 |
1862 // If not immediate, cycle through 2 more complete cycles. | 1864 // If not immediate, cycle through 2 more complete cycles. |
1863 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 1865 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
1864 throbbing_view_ = NULL; | 1866 throbbing_view_ = NULL; |
1865 } | 1867 } |
OLD | NEW |