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 "app/gfx/canvas.h" | 9 #include "app/gfx/canvas.h" |
10 #include "app/gfx/text_elider.h" | 10 #include "app/gfx/text_elider.h" |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
334 SkIntToScalar(1), SkIntToScalar(height() - 1) }; | 334 SkIntToScalar(1), SkIntToScalar(height() - 1) }; |
335 canvas->drawRect(rc_down, paint_down); | 335 canvas->drawRect(rc_down, paint_down); |
336 } | 336 } |
337 | 337 |
338 virtual gfx::Size GetPreferredSize() { | 338 virtual gfx::Size GetPreferredSize() { |
339 // We get the full height of the bookmark bar, so that the height returned | 339 // We get the full height of the bookmark bar, so that the height returned |
340 // here doesn't matter. | 340 // here doesn't matter. |
341 return gfx::Size(kSeparatorWidth, 1); | 341 return gfx::Size(kSeparatorWidth, 1); |
342 } | 342 } |
343 | 343 |
344 virtual bool GetAccessibleName(std::wstring* name) { | |
jcampan
2009/07/14 16:44:24
Nit: DCHECK(name)
| |
345 if (!accessible_name_.empty()) { | |
346 (*name).assign(accessible_name_); | |
jcampan
2009/07/14 16:44:24
Nit: name-> instead of (*name).
| |
347 return true; | |
348 } | |
349 return false; | |
350 } | |
351 | |
352 virtual bool GetAccessibleRole(AccessibilityTypes::Role* role) { | |
353 DCHECK(role); | |
354 | |
355 *role = AccessibilityTypes::ROLE_SEPARATOR; | |
356 return true; | |
357 } | |
358 | |
359 virtual void SetAccessibleName(const std::wstring& name) { | |
360 accessible_name_.assign(name); | |
361 } | |
362 | |
344 private: | 363 private: |
364 // Storage of strings needed for accessibility. | |
365 std::wstring accessible_name_; | |
366 | |
345 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); | 367 DISALLOW_COPY_AND_ASSIGN(ButtonSeparatorView); |
346 }; | 368 }; |
347 | 369 |
348 // BookmarkBarView ------------------------------------------------------------ | 370 // BookmarkBarView ------------------------------------------------------------ |
349 | 371 |
350 // static | 372 // static |
351 const int BookmarkBarView::kMaxButtonWidth = 150; | 373 const int BookmarkBarView::kMaxButtonWidth = 150; |
352 | 374 |
353 // static | 375 // static |
354 bool BookmarkBarView::testing_ = false; | 376 bool BookmarkBarView::testing_ = false; |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
795 const BookmarkNode* parent_node; | 817 const BookmarkNode* parent_node; |
796 if (is_over_other) { | 818 if (is_over_other) { |
797 parent_node = root; | 819 parent_node = root; |
798 index = parent_node->GetChildCount(); | 820 index = parent_node->GetChildCount(); |
799 } else if (drop_on) { | 821 } else if (drop_on) { |
800 parent_node = root->GetChild(index); | 822 parent_node = root->GetChild(index); |
801 index = parent_node->GetChildCount(); | 823 index = parent_node->GetChildCount(); |
802 } else { | 824 } else { |
803 parent_node = root; | 825 parent_node = root; |
804 } | 826 } |
805 return bookmark_utils::PerformBookmarkDrop(profile_, data, parent_node, index) ; | 827 return bookmark_utils::PerformBookmarkDrop(profile_, data, parent_node, |
828 index); | |
829 } | |
830 | |
831 bool BookmarkBarView::GetAccessibleName(std::wstring* name) { | |
832 if (!accessible_name_.empty()) { | |
833 (*name).assign(accessible_name_); | |
jcampan
2009/07/14 16:44:24
Same nits as above: CHECK(name) and name->
| |
834 return true; | |
835 } | |
836 return false; | |
837 } | |
838 | |
839 bool BookmarkBarView::GetAccessibleRole(AccessibilityTypes::Role* role) { | |
840 DCHECK(role); | |
841 | |
842 *role = AccessibilityTypes::ROLE_TOOLBAR; | |
843 return true; | |
844 } | |
845 | |
846 void BookmarkBarView::SetAccessibleName(const std::wstring& name) { | |
847 accessible_name_.assign(name); | |
806 } | 848 } |
807 | 849 |
808 void BookmarkBarView::OnFullscreenToggled(bool fullscreen) { | 850 void BookmarkBarView::OnFullscreenToggled(bool fullscreen) { |
809 if (!fullscreen) | 851 if (!fullscreen) |
810 size_animation_->Reset(IsAlwaysShown() ? 1 : 0); | 852 size_animation_->Reset(IsAlwaysShown() ? 1 : 0); |
811 else if (IsAlwaysShown()) | 853 else if (IsAlwaysShown()) |
812 size_animation_->Reset(0); | 854 size_animation_->Reset(0); |
813 } | 855 } |
814 | 856 |
815 bool BookmarkBarView::IsDetachedStyle() { | 857 bool BookmarkBarView::IsDetachedStyle() { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 if (!kDefaultFavIcon) | 914 if (!kDefaultFavIcon) |
873 kDefaultFavIcon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | 915 kDefaultFavIcon = rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
874 | 916 |
875 other_bookmarked_button_ = CreateOtherBookmarkedButton(); | 917 other_bookmarked_button_ = CreateOtherBookmarkedButton(); |
876 AddChildView(other_bookmarked_button_); | 918 AddChildView(other_bookmarked_button_); |
877 | 919 |
878 overflow_button_ = CreateOverflowButton(); | 920 overflow_button_ = CreateOverflowButton(); |
879 AddChildView(overflow_button_); | 921 AddChildView(overflow_button_); |
880 | 922 |
881 bookmarks_separator_view_ = new ButtonSeparatorView(); | 923 bookmarks_separator_view_ = new ButtonSeparatorView(); |
924 bookmarks_separator_view_->SetAccessibleName( | |
925 l10n_util::GetString(IDS_ACCNAME_SEPARATOR)); | |
882 AddChildView(bookmarks_separator_view_); | 926 AddChildView(bookmarks_separator_view_); |
883 | 927 |
884 instructions_ = new views::Label( | 928 instructions_ = new views::Label( |
885 l10n_util::GetString(IDS_BOOKMARKS_NO_ITEMS), | 929 l10n_util::GetString(IDS_BOOKMARKS_NO_ITEMS), |
886 rb.GetFont(ResourceBundle::BaseFont)); | 930 rb.GetFont(ResourceBundle::BaseFont)); |
887 instructions_->SetColor(kInstructionsColor); | 931 instructions_->SetColor(kInstructionsColor); |
888 AddChildView(instructions_); | 932 AddChildView(instructions_); |
889 | 933 |
890 SetContextMenuController(this); | 934 SetContextMenuController(this); |
891 | 935 |
892 size_animation_.reset(new SlideAnimation(this)); | 936 size_animation_.reset(new SlideAnimation(this)); |
893 } | 937 } |
894 | 938 |
895 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { | 939 MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
896 MenuButton* button = new BookmarkFolderButton( | 940 MenuButton* button = new BookmarkFolderButton( |
897 this, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, | 941 this, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, |
898 false); | 942 false); |
899 button->SetIcon(GetGroupIcon()); | 943 button->SetIcon(GetGroupIcon()); |
900 button->SetContextMenuController(this); | 944 button->SetContextMenuController(this); |
901 button->set_tag(kOtherFolderButtonTag); | 945 button->set_tag(kOtherFolderButtonTag); |
946 button->SetAccessibleName( | |
947 l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED)); | |
902 return button; | 948 return button; |
903 } | 949 } |
904 | 950 |
905 MenuButton* BookmarkBarView::CreateOverflowButton() { | 951 MenuButton* BookmarkBarView::CreateOverflowButton() { |
906 MenuButton* button = new MenuButton(NULL, std::wstring(), this, false); | 952 MenuButton* button = new MenuButton(NULL, std::wstring(), this, false); |
907 button->SetIcon(*ResourceBundle::GetSharedInstance(). | 953 button->SetIcon(*ResourceBundle::GetSharedInstance(). |
908 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); | 954 GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
909 | 955 |
910 // The overflow button's image contains an arrow and therefore it is a | 956 // The overflow button's image contains an arrow and therefore it is a |
911 // direction sensitive image and we need to flip it if the UI layout is | 957 // direction sensitive image and we need to flip it if the UI layout is |
912 // right-to-left. | 958 // right-to-left. |
913 // | 959 // |
914 // By default, menu buttons are not flipped because they generally contain | 960 // By default, menu buttons are not flipped because they generally contain |
915 // text and flipping the gfx::Canvas object will break text rendering. Since | 961 // text and flipping the gfx::Canvas object will break text rendering. Since |
916 // the overflow button does not contain text, we can safely flip it. | 962 // the overflow button does not contain text, we can safely flip it. |
917 button->EnableCanvasFlippingForRTLUI(true); | 963 button->EnableCanvasFlippingForRTLUI(true); |
918 | 964 |
919 // Make visible as necessary. | 965 // Make visible as necessary. |
920 button->SetVisible(false); | 966 button->SetVisible(false); |
967 // Set accessibility name. | |
968 button->SetAccessibleName( | |
969 l10n_util::GetString(IDS_ACCNAME_BOOKMARKS_CHEVRON)); | |
921 return button; | 970 return button; |
922 } | 971 } |
923 | 972 |
924 int BookmarkBarView::GetBookmarkButtonCount() { | 973 int BookmarkBarView::GetBookmarkButtonCount() { |
925 // We contain at least four non-bookmark button views: recently bookmarked, | 974 // We contain at least four non-bookmark button views: recently bookmarked, |
926 // bookmarks separator, chevrons (for overflow), the instruction | 975 // bookmarks separator, chevrons (for overflow), the instruction |
927 // label. | 976 // label. |
928 return GetChildViewCount() - 4; | 977 return GetChildViewCount() - 4; |
929 } | 978 } |
930 | 979 |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1256 new BookmarkFolderButton(this, node->GetTitle(), this, false); | 1305 new BookmarkFolderButton(this, node->GetTitle(), this, false); |
1257 button->SetIcon(GetGroupIcon()); | 1306 button->SetIcon(GetGroupIcon()); |
1258 ConfigureButton(node, button); | 1307 ConfigureButton(node, button); |
1259 return button; | 1308 return button; |
1260 } | 1309 } |
1261 } | 1310 } |
1262 | 1311 |
1263 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, | 1312 void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
1264 views::TextButton* button) { | 1313 views::TextButton* button) { |
1265 button->SetText(node->GetTitle()); | 1314 button->SetText(node->GetTitle()); |
1315 button->SetAccessibleName(node->GetTitle()); | |
1266 | 1316 |
1267 // We don't always have a theme provider (ui tests, for example). | 1317 // We don't always have a theme provider (ui tests, for example). |
1268 if (GetThemeProvider()) { | 1318 if (GetThemeProvider()) { |
1269 button->SetEnabledColor(GetThemeProvider()->GetColor( | 1319 button->SetEnabledColor(GetThemeProvider()->GetColor( |
1270 BrowserThemeProvider::COLOR_BOOKMARK_TEXT)); | 1320 BrowserThemeProvider::COLOR_BOOKMARK_TEXT)); |
1271 } | 1321 } |
1272 | 1322 |
1273 button->ClearMaxTextSize(); | 1323 button->ClearMaxTextSize(); |
1274 button->SetContextMenuController(this); | 1324 button->SetContextMenuController(this); |
1275 button->SetDragController(this); | 1325 button->SetDragController(this); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1505 } else { | 1555 } else { |
1506 return DragDropTypes::DRAG_NONE; | 1556 return DragDropTypes::DRAG_NONE; |
1507 } | 1557 } |
1508 } | 1558 } |
1509 | 1559 |
1510 if (*drop_on) { | 1560 if (*drop_on) { |
1511 const BookmarkNode* parent = | 1561 const BookmarkNode* parent = |
1512 *is_over_other ? model_->other_node() : | 1562 *is_over_other ? model_->other_node() : |
1513 model_->GetBookmarkBarNode()->GetChild(*index); | 1563 model_->GetBookmarkBarNode()->GetChild(*index); |
1514 int operation = | 1564 int operation = |
1515 bookmark_utils::BookmarkDropOperation(profile_,event, data, parent, | 1565 bookmark_utils::BookmarkDropOperation(profile_, event, data, parent, |
1516 parent->GetChildCount()); | 1566 parent->GetChildCount()); |
1517 if (!operation && !data.has_single_url() && | 1567 if (!operation && !data.has_single_url() && |
1518 data.GetFirstNode(profile_) == parent) { | 1568 data.GetFirstNode(profile_) == parent) { |
1519 // Don't open a menu if the node being dragged is the the menu to | 1569 // Don't open a menu if the node being dragged is the the menu to |
1520 // open. | 1570 // open. |
1521 *drop_on = false; | 1571 *drop_on = false; |
1522 } | 1572 } |
1523 return operation; | 1573 return operation; |
1524 } | 1574 } |
1525 return bookmark_utils::BookmarkDropOperation(profile_, event, data, | 1575 return bookmark_utils::BookmarkDropOperation(profile_, event, data, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1573 } | 1623 } |
1574 | 1624 |
1575 void BookmarkBarView::StopThrobbing(bool immediate) { | 1625 void BookmarkBarView::StopThrobbing(bool immediate) { |
1576 if (!throbbing_view_) | 1626 if (!throbbing_view_) |
1577 return; | 1627 return; |
1578 | 1628 |
1579 // If not immediate, cycle through 2 more complete cycles. | 1629 // If not immediate, cycle through 2 more complete cycles. |
1580 throbbing_view_->StartThrobbing(immediate ? 0 : 4); | 1630 throbbing_view_->StartThrobbing(immediate ? 0 : 4); |
1581 throbbing_view_ = NULL; | 1631 throbbing_view_ = NULL; |
1582 } | 1632 } |
OLD | NEW |