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

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

Issue 12550006: Mac: Add a shortcut to open the Apps page from the bookmark bar. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 // once, or we didn't properly clear things. Either of which shouldn't happen. 950 // once, or we didn't properly clear things. Either of which shouldn't happen.
951 DCHECK_EQ(0, GetBookmarkButtonCount()); 951 DCHECK_EQ(0, GetBookmarkButtonCount());
952 const BookmarkNode* node = model_->bookmark_bar_node(); 952 const BookmarkNode* node = model_->bookmark_bar_node();
953 DCHECK(node); 953 DCHECK(node);
954 // Create a button for each of the children on the bookmark bar. 954 // Create a button for each of the children on the bookmark bar.
955 for (int i = 0, child_count = node->child_count(); i < child_count; ++i) 955 for (int i = 0, child_count = node->child_count(); i < child_count; ++i)
956 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); 956 AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i);
957 DCHECK(model_->other_node()); 957 DCHECK(model_->other_node());
958 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle()); 958 other_bookmarked_button_->SetAccessibleName(model_->other_node()->GetTitle());
959 other_bookmarked_button_->SetText(model_->other_node()->GetTitle()); 959 other_bookmarked_button_->SetText(model_->other_node()->GetTitle());
960 apps_page_shortcut_->SetAccessibleName(model_->apps_node()->GetTitle());
961 apps_page_shortcut_->SetText(model_->apps_node()->GetTitle());
960 UpdateColors(); 962 UpdateColors();
961 UpdateOtherBookmarksVisibility(); 963 UpdateOtherBookmarksVisibility();
962 other_bookmarked_button_->SetEnabled(true); 964 other_bookmarked_button_->SetEnabled(true);
963 965 UpdateAppsPageShortcutVisibility();
966 apps_page_shortcut_->SetEnabled(true);
964 Layout(); 967 Layout();
965 SchedulePaint(); 968 SchedulePaint();
966 } 969 }
967 970
968 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) { 971 void BookmarkBarView::BookmarkModelBeingDeleted(BookmarkModel* model) {
969 // In normal shutdown The bookmark model should never be deleted before us. 972 // In normal shutdown The bookmark model should never be deleted before us.
970 // When X exits suddenly though, it can happen, This code exists 973 // When X exits suddenly though, it can happen, This code exists
971 // to check for regressions in shutdown code and not crash. 974 // to check for regressions in shutdown code and not crash.
972 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers()) 975 if (!browser_shutdown::ShuttingDownWithoutClosingBrowsers())
973 NOTREACHED(); 976 NOTREACHED();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1217 // they are added matches the visual order. 1220 // they are added matches the visual order.
1218 overflow_button_ = CreateOverflowButton(); 1221 overflow_button_ = CreateOverflowButton();
1219 AddChildView(overflow_button_); 1222 AddChildView(overflow_button_);
1220 1223
1221 other_bookmarked_button_ = CreateOtherBookmarkedButton(); 1224 other_bookmarked_button_ = CreateOtherBookmarkedButton();
1222 // We'll re-enable when the model is loaded. 1225 // We'll re-enable when the model is loaded.
1223 other_bookmarked_button_->SetEnabled(false); 1226 other_bookmarked_button_->SetEnabled(false);
1224 AddChildView(other_bookmarked_button_); 1227 AddChildView(other_bookmarked_button_);
1225 1228
1226 apps_page_shortcut_ = CreateAppsPageShortcutButton(); 1229 apps_page_shortcut_ = CreateAppsPageShortcutButton();
1230 // We'll re-enable when the model is loaded.
1231 other_bookmarked_button_->SetEnabled(false);
1227 AddChildView(apps_page_shortcut_); 1232 AddChildView(apps_page_shortcut_);
1228 profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); 1233 profile_pref_registrar_.Init(browser_->profile()->GetPrefs());
1229 profile_pref_registrar_.Add( 1234 profile_pref_registrar_.Add(
1230 prefs::kShowAppsShortcutInBookmarkBar, 1235 prefs::kShowAppsShortcutInBookmarkBar,
1231 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged, 1236 base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged,
1232 base::Unretained(this))); 1237 base::Unretained(this)));
1233 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut());
1234 1238
1235 bookmarks_separator_view_ = new ButtonSeparatorView(); 1239 bookmarks_separator_view_ = new ButtonSeparatorView();
1236 AddChildView(bookmarks_separator_view_); 1240 AddChildView(bookmarks_separator_view_);
1237 UpdateBookmarksSeparatorVisibility(); 1241 UpdateBookmarksSeparatorVisibility();
1238 1242
1239 instructions_ = new BookmarkBarInstructionsView(this); 1243 instructions_ = new BookmarkBarInstructionsView(this);
1240 AddChildView(instructions_); 1244 AddChildView(instructions_);
1241 1245
1242 set_context_menu_controller(this); 1246 set_context_menu_controller(this);
1243 1247
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 } else { 1324 } else {
1321 views::MenuButton* button = new BookmarkFolderButton( 1325 views::MenuButton* button = new BookmarkFolderButton(
1322 this, node->GetTitle(), this, false); 1326 this, node->GetTitle(), this, false);
1323 button->SetIcon(GetFolderIcon()); 1327 button->SetIcon(GetFolderIcon());
1324 ConfigureButton(node, button); 1328 ConfigureButton(node, button);
1325 return button; 1329 return button;
1326 } 1330 }
1327 } 1331 }
1328 1332
1329 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { 1333 views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() {
1330 views::TextButton* button = new ShortcutButton( 1334 views::TextButton* button = new ShortcutButton(this, string16());
1331 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME));
1332 button->SetTooltipText(l10n_util::GetStringUTF16( 1335 button->SetTooltipText(l10n_util::GetStringUTF16(
1333 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); 1336 IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP));
1334 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); 1337 button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT);
1335 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1338 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1336 button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16)); 1339 button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16));
1337 button->set_context_menu_controller(this); 1340 button->set_context_menu_controller(this);
1338 button->set_tag(kAppsShortcutButtonTag); 1341 button->set_tag(kAppsShortcutButtonTag);
1339 return button; 1342 return button;
1340 } 1343 }
1341 1344
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
1651 void BookmarkBarView::UpdateOtherBookmarksVisibility() { 1654 void BookmarkBarView::UpdateOtherBookmarksVisibility() {
1652 bool has_other_children = !model_->other_node()->empty(); 1655 bool has_other_children = !model_->other_node()->empty();
1653 if (has_other_children == other_bookmarked_button_->visible()) 1656 if (has_other_children == other_bookmarked_button_->visible())
1654 return; 1657 return;
1655 other_bookmarked_button_->SetVisible(has_other_children); 1658 other_bookmarked_button_->SetVisible(has_other_children);
1656 UpdateBookmarksSeparatorVisibility(); 1659 UpdateBookmarksSeparatorVisibility();
1657 Layout(); 1660 Layout();
1658 SchedulePaint(); 1661 SchedulePaint();
1659 } 1662 }
1660 1663
1664 void BookmarkBarView::UpdateAppsPageShortcutVisibility() {
1665 bool visible = model_->IsLoaded() &&
1666 chrome::search::IsInstantExtendedAPIEnabled() &&
1667 browser_->profile()->GetPrefs()->GetBoolean(
1668 prefs::kShowAppsShortcutInBookmarkBar);
1669 if (visible == apps_page_shortcut_->visible())
1670 return;
1671 apps_page_shortcut_->SetVisible(visible);
1672 UpdateBookmarksSeparatorVisibility();
1673 Layout();
1674 SchedulePaint();
1675 }
1676
1661 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() { 1677 void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {
1662 // Ash does not paint the bookmarks separator line because it looks odd on 1678 // Ash does not paint the bookmarks separator line because it looks odd on
1663 // the flat background. We keep it present for layout, but don't draw it. 1679 // the flat background. We keep it present for layout, but don't draw it.
1664 bookmarks_separator_view_->SetVisible( 1680 bookmarks_separator_view_->SetVisible(
1665 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH && 1681 browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH &&
1666 (other_bookmarked_button_->visible() || 1682 (other_bookmarked_button_->visible() ||
1667 apps_page_shortcut_->visible())); 1683 apps_page_shortcut_->visible()));
1668 } 1684 }
1669 1685
1670 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { 1686 gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 } else { 1818 } else {
1803 prefsize.set_height( 1819 prefsize.set_height(
1804 static_cast<int>( 1820 static_cast<int>(
1805 browser_defaults::kBookmarkBarHeight * 1821 browser_defaults::kBookmarkBarHeight *
1806 size_animation_->GetCurrentValue())); 1822 size_animation_->GetCurrentValue()));
1807 } 1823 }
1808 } 1824 }
1809 return prefsize; 1825 return prefsize;
1810 } 1826 }
1811 1827
1812 bool BookmarkBarView::ShouldShowAppsShortcut() const {
1813 return chrome::search::IsInstantExtendedAPIEnabled() &&
1814 browser_->profile()->GetPrefs()->GetBoolean(
1815 prefs::kShowAppsShortcutInBookmarkBar);
1816 }
1817
1818 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() { 1828 void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() {
1819 DCHECK(apps_page_shortcut_); 1829 DCHECK(apps_page_shortcut_);
1820 apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); 1830 UpdateAppsPageShortcutVisibility();
1821 UpdateBookmarksSeparatorVisibility();
1822 Layout();
1823 } 1831 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698