Chromium Code Reviews| Index: chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| index ac2ed9f36e743fefa5f1d8db89239d18bd472e3b..87e5e49f38d5afe08316b86f2d2e6dc55f9d2e6f 100644 |
| --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| @@ -30,6 +30,7 @@ |
| #include "chrome/browser/ui/bookmarks/bookmark_utils.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/chrome_pages.h" |
| +#include "chrome/browser/ui/search/search.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/browser/ui/view_ids.h" |
| #include "chrome/browser/ui/views/bookmarks/bookmark_bar_instructions_view.h" |
| @@ -133,6 +134,9 @@ static const int kInstructionsPadding = 6; |
| // Tag for the 'Other bookmarks' button. |
| static const int kOtherFolderButtonTag = 1; |
| +// Tag for the 'Apps Shortcut' button. |
| +static const int kAppsShortcutButtonTag = 2; |
| + |
| namespace { |
| // BookmarkButton ------------------------------------------------------------- |
| @@ -263,6 +267,48 @@ class OverFlowButton : public views::MenuButton { |
| DISALLOW_COPY_AND_ASSIGN(OverFlowButton); |
| }; |
| +// ShortcutButton ------------------------------------------------------------- |
| + |
| +// Buttons used for the shortcuts on the bookmark bar. |
| + |
| +class ShortcutButton : public views::TextButton { |
|
Alexei Svitkine (slow)
2013/02/25 21:13:29
Should this implement GetTooltipText()?
MAD
2013/02/25 21:41:01
No need for tooltip, the name of the shortcut is a
|
| + public: |
| + // The internal view class name. |
| + static const char kViewClassName[]; |
| + |
| + ShortcutButton(views::ButtonListener* listener, |
| + const string16& title) |
| + : TextButton(listener, title) { |
| + show_animation_.reset(new ui::SlideAnimation(this)); |
| + if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { |
|
Alexei Svitkine (slow)
2013/02/25 21:13:29
It seems most of this logic is identical to Bookma
MAD
2013/02/25 21:41:01
I thought about it, but I recently got slapped on
|
| + // For some reason during testing the events generated by animating |
| + // throw off the test. So, don't animate while testing. |
| + show_animation_->Reset(1); |
| + } else { |
| + show_animation_->Show(); |
| + } |
| + } |
| + |
| + virtual bool IsTriggerableEvent(const ui::Event& e) OVERRIDE { |
| + return e.type() == ui::ET_GESTURE_TAP || |
| + e.type() == ui::ET_GESTURE_TAP_DOWN || |
| + event_utils::IsPossibleDispositionEvent(e); |
| + } |
| + |
| + virtual std::string GetClassName() const OVERRIDE { |
| + return kViewClassName; |
| + } |
| + |
| + private: |
| + scoped_ptr<ui::SlideAnimation> show_animation_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ShortcutButton); |
| +}; |
| + |
| +// static for ShortcutButton |
| +const char ShortcutButton::kViewClassName[] = |
| + "browser/ui/views/bookmarks/ShortcutButton"; |
| + |
| void RecordAppLaunch(Profile* profile, GURL url) { |
| DCHECK(profile->GetExtensionService()); |
| if (!profile->GetExtensionService()->IsInstalledApp(url)) |
| @@ -382,6 +428,7 @@ BookmarkBarView::BookmarkBarView(Browser* browser, BrowserView* browser_view) |
| bookmark_menu_(NULL), |
| bookmark_drop_menu_(NULL), |
| other_bookmarked_button_(NULL), |
| + apps_page_shortcut_(NULL), |
| ALLOW_THIS_IN_INITIALIZER_LIST(show_folder_method_factory_(this)), |
| overflow_button_(NULL), |
| instructions_(NULL), |
| @@ -607,8 +654,11 @@ gfx::Size BookmarkBarView::GetMinimumSize() { |
| gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| gfx::Size bookmarks_separator_pref = |
| bookmarks_separator_view_->GetPreferredSize(); |
| + gfx::Size apps_page_shortcut_pref = |
| + apps_page_shortcut_->GetPreferredSize(); |
| width += other_bookmarked_pref.width() + kButtonPadding + |
| + apps_page_shortcut_pref.width() + kButtonPadding + |
| overflow_pref.width() + kButtonPadding + |
| bookmarks_separator_pref.width(); |
| @@ -1029,7 +1079,9 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| const BookmarkNode* node; |
| int start_index = 0; |
| - if (view == other_bookmarked_button_) { |
| + if (view == other_bookmarked_button_ || view == apps_page_shortcut_) { |
| + // We want the same menu for both, so use the other node since the app |
| + // shortcut doesn't have a node. |
| node = model_->other_node(); |
| } else if (view == overflow_button_) { |
| node = model_->bookmark_bar_node(); |
| @@ -1048,6 +1100,11 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| void BookmarkBarView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| + if (sender->tag() == kAppsShortcutButtonTag) { |
| + chrome::ShowAppLauncherPage(browser_); |
| + return; |
| + } |
| + |
| const BookmarkNode* node; |
| if (sender->tag() == kOtherFolderButtonTag) { |
| node = model_->other_node(); |
| @@ -1090,11 +1147,12 @@ void BookmarkBarView::ShowContextMenuForView(views::View* source, |
| if (source == other_bookmarked_button_) { |
| parent = model_->other_node(); |
| // Do this so the user can open all bookmarks. BookmarkContextMenu makes |
| - // sure the user can edit/delete the node in this case. |
| + // sure the user can't edit/delete the node in this case. |
| nodes.push_back(parent); |
| - } else if (source != this) { |
| + } else if (source != this && source != apps_page_shortcut_) { |
| // User clicked on one of the bookmark buttons, find which one they |
| - // clicked on. |
| + // clicked on, except for the apps page shortcut, which must behave as if |
| + // the user clicked on the bookmark bar background. |
| int bookmark_button_index = GetIndexOf(source); |
| DCHECK(bookmark_button_index != -1 && |
| bookmark_button_index < GetBookmarkButtonCount()); |
| @@ -1138,6 +1196,15 @@ void BookmarkBarView::Init() { |
| other_bookmarked_button_->SetEnabled(false); |
| AddChildView(other_bookmarked_button_); |
| + apps_page_shortcut_ = CreateAppsPageShortcutButton(); |
| + AddChildView(apps_page_shortcut_); |
| + profile_pref_registrar_.Init(browser_->profile()->GetPrefs()); |
| + profile_pref_registrar_.Add( |
| + prefs::kShowAppsShortcutInBookmarkBar, |
| + base::Bind(&BookmarkBarView::OnAppsPageShortcutVisibilityChanged, |
| + base::Unretained(this))); |
| + apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); |
| + |
| bookmarks_separator_view_ = new ButtonSeparatorView(); |
| AddChildView(bookmarks_separator_view_); |
| #if defined(USE_ASH) |
| @@ -1165,8 +1232,8 @@ void BookmarkBarView::Init() { |
| int BookmarkBarView::GetBookmarkButtonCount() { |
| // We contain four non-bookmark button views: other bookmarks, bookmarks |
| - // separator, chevrons (for overflow), and the instruction label. |
| - return child_count() - 4; |
| + // separator, chevrons (for overflow), apps page, and the instruction label. |
| + return child_count() - 5; |
| } |
| views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
| @@ -1230,6 +1297,18 @@ views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { |
| } |
| } |
| +views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { |
| + views::TextButton* button = new ShortcutButton( |
| + this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BAR_APPS_SHORTCUT_NAME)); |
| + button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + button->SetIcon(*rb.GetImageSkiaNamed(IDR_PRODUCT_LOGO_16)); |
| + button->set_context_menu_controller(this); |
| + button->set_tag(kAppsShortcutButtonTag); |
| + button->SetEnabled(true); |
| + return button; |
| +} |
| + |
| void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
| views::TextButton* button) { |
| button->SetText(node->GetTitle()); |
| @@ -1584,11 +1663,15 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
| gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| gfx::Size bookmarks_separator_pref = |
| bookmarks_separator_view_->GetPreferredSize(); |
| + gfx::Size apps_page_shortcut_pref = apps_page_shortcut_->visible() ? |
| + apps_page_shortcut_->GetPreferredSize() : gfx::Size(); |
| int max_x = width - overflow_pref.width() - kButtonPadding - |
| bookmarks_separator_pref.width(); |
| if (other_bookmarked_button_->visible()) |
| max_x -= other_bookmarked_pref.width() + kButtonPadding; |
| + if (apps_page_shortcut_->visible()) |
| + max_x -= apps_page_shortcut_pref.width() + kButtonPadding; |
| // Next, layout out the buttons. Any buttons that are placed beyond the |
| // visible region and made invisible. |
| @@ -1657,6 +1740,15 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
| x += other_bookmarked_pref.width() + kButtonPadding; |
| } |
| + // The app page shortcut button. |
| + if (apps_page_shortcut_->visible()) { |
| + if (!compute_bounds_only) { |
| + apps_page_shortcut_->SetBounds(x, y, apps_page_shortcut_pref.width(), |
| + height); |
| + } |
| + x += apps_page_shortcut_pref.width() + kButtonPadding; |
| + } |
| + |
| // Set the preferred size computed so far. |
| if (compute_bounds_only) { |
| x += kRightMargin; |
| @@ -1679,3 +1771,15 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
| } |
| return prefsize; |
| } |
| + |
| +bool BookmarkBarView::ShouldShowAppsShortcut() { |
| + return chrome::search::IsInstantExtendedAPIEnabled(browser_->profile()) && |
| + browser_->profile()->GetPrefs()->GetBoolean( |
| + prefs::kShowAppsShortcutInBookmarkBar); |
| +} |
| + |
| +void BookmarkBarView::OnAppsPageShortcutVisibilityChanged() { |
| + DCHECK(apps_page_shortcut_); |
| + apps_page_shortcut_->SetVisible(ShouldShowAppsShortcut()); |
| + Layout(); |
| +} |