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..60321f33bd74b9520f23b78bc93aa2174de285f7 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,13 +134,47 @@ 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 { |
| +// BookmarkButtonBase --------------------------------------------------------- |
| + |
| +// Base class for text buttons used on the bookmark bar. |
| + |
| +class BookmarkButtonBase : public views::TextButton { |
| + public: |
| + BookmarkButtonBase(views::ButtonListener* listener, |
| + const string16& title) |
| + : TextButton(listener, title) { |
| + show_animation_.reset(new ui::SlideAnimation(this)); |
| + if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { |
| + // 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); |
| + } |
| + |
| + private: |
| + scoped_ptr<ui::SlideAnimation> show_animation_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BookmarkButtonBase); |
| +}; |
| + |
| // BookmarkButton ------------------------------------------------------------- |
| // Buttons used for the bookmarks on the bookmark bar. |
| -class BookmarkButton : public views::TextButton { |
| +class BookmarkButton : public BookmarkButtonBase { |
| public: |
| // The internal view class name. |
| static const char kViewClassName[]; |
| @@ -148,17 +183,9 @@ class BookmarkButton : public views::TextButton { |
| const GURL& url, |
| const string16& title, |
| Profile* profile) |
| - : TextButton(listener, title), |
| + : BookmarkButtonBase(listener, title), |
| url_(url), |
| profile_(profile) { |
| - show_animation_.reset(new ui::SlideAnimation(this)); |
| - if (bookmark_utils::IsBookmarkBarViewAnimationsDisabled()) { |
| - // 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 GetTooltipText(const gfx::Point& p, |
| @@ -170,12 +197,6 @@ class BookmarkButton : public views::TextButton { |
| return !tooltip->empty(); |
| } |
| - 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; |
| } |
| @@ -183,7 +204,6 @@ class BookmarkButton : public views::TextButton { |
| private: |
| const GURL& url_; |
| Profile* profile_; |
| - scoped_ptr<ui::SlideAnimation> show_animation_; |
| DISALLOW_COPY_AND_ASSIGN(BookmarkButton); |
| }; |
| @@ -192,6 +212,34 @@ class BookmarkButton : public views::TextButton { |
| const char BookmarkButton::kViewClassName[] = |
| "browser/ui/views/bookmarks/BookmarkButton"; |
| +// ShortcutButton ------------------------------------------------------------- |
| + |
| +// Buttons used for the shortcuts on the bookmark bar. |
| + |
| +class ShortcutButton : public BookmarkButtonBase { |
| + public: |
| + // The internal view class name. |
| + static const char kViewClassName[]; |
| + |
| + ShortcutButton(views::ButtonListener* listener, |
| + const string16& title) |
| + : BookmarkButtonBase(listener, title) { |
| + } |
| + |
| + 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"; |
| + |
| // BookmarkFolderButton ------------------------------------------------------- |
| // Buttons used for folders on the bookmark bar, including the 'other folders' |
| @@ -382,6 +430,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), |
| @@ -602,13 +651,21 @@ gfx::Size BookmarkBarView::GetMinimumSize() { |
| width += 2 * static_cast<int>(kNewtabHorizontalPadding * current_state); |
| } |
| - gfx::Size other_bookmarked_pref = |
| - other_bookmarked_button_->GetPreferredSize(); |
| - gfx::Size overflow_pref = overflow_button_->GetPreferredSize(); |
| - gfx::Size bookmarks_separator_pref = |
| - bookmarks_separator_view_->GetPreferredSize(); |
| + gfx::Size other_bookmarked_pref; |
| + if (other_bookmarked_button_->visible()) |
| + other_bookmarked_pref = other_bookmarked_button_->GetPreferredSize(); |
| + gfx::Size overflow_pref; |
| + if (overflow_button_->visible()) |
| + overflow_pref = overflow_button_->GetPreferredSize(); |
| + gfx::Size bookmarks_separator_pref; |
| + if (bookmarks_separator_view_->visible()) |
| + bookmarks_separator_pref = bookmarks_separator_view_->GetPreferredSize(); |
| + gfx::Size apps_page_shortcut_pref; |
| + if (apps_page_shortcut_->visible()) |
| + 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(); |
| @@ -1048,6 +1105,13 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view, |
| void BookmarkBarView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| + if (sender->tag() == kAppsShortcutButtonTag) { |
| + chrome::ShowAppLauncherPage(browser_); |
| + content::RecordAction( |
| + UserMetricsAction("ClickedBookmarkBarAppsShortcutButton")); |
| + return; |
| + } |
| + |
| const BookmarkNode* node; |
| if (sender->tag() == kOtherFolderButtonTag) { |
| node = model_->other_node(); |
| @@ -1090,11 +1154,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 +1203,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 +1239,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 +1304,20 @@ 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->SetTooltipText(l10n_util::GetStringUTF16( |
| + IDS_BOOKMARK_BAR_APPS_SHORTCUT_TOOLTIP)); |
| + button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| + button->SetIcon(*rb.GetImageSkiaNamed(IDR_WEBSTORE_ICON_16)); |
| + button->set_context_menu_controller(this); |
| + button->set_tag(kAppsShortcutButtonTag); |
| + button->SetEnabled(true); |
|
sky
2013/02/28 21:50:31
Enabled is this default.
beaudoin
2013/03/04 23:30:14
Done.
|
| + return button; |
| +} |
| + |
| void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
| views::TextButton* button) { |
| button->SetText(node->GetTitle()); |
| @@ -1584,11 +1672,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 +1749,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 +1780,20 @@ gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { |
| } |
| return prefsize; |
| } |
| + |
| +bool BookmarkBarView::ShouldShowAppsShortcut() const { |
| + 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(); |
| +} |
| + |
| +bool BookmarkBarView::IsAppsShortcutVisibleForTesting() const { |
| + DCHECK(apps_page_shortcut_); |
| + return apps_page_shortcut_->visible(); |
| +} |