| 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 9644589f961b4c9c8a66eff3514fc20af316b3cb..505806e1ee8c718661b6bf5864d071336fc46592 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/search/search_model.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/browser/ui/view_ids.h"
|
| @@ -147,13 +148,47 @@ static const int kSearchNewTabBookmarkBarHeight = 36;
|
| static const int kSearchNewTabHorizontalPadding = 0;
|
| static const int kSearchNewTabVerticalPadding = 0;
|
|
|
| +// 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 anima
|
| + // 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[];
|
| @@ -162,17 +197,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,
|
| @@ -184,12 +211,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;
|
| }
|
| @@ -197,7 +218,6 @@ class BookmarkButton : public views::TextButton {
|
| private:
|
| const GURL& url_;
|
| Profile* profile_;
|
| - scoped_ptr<ui::SlideAnimation> show_animation_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(BookmarkButton);
|
| };
|
| @@ -206,6 +226,33 @@ 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:
|
| +
|
| + 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'
|
| @@ -406,6 +453,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),
|
| @@ -627,13 +675,21 @@ gfx::Size BookmarkBarView::GetMinimumSize() {
|
| browser_->search_model()->mode()) * 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();
|
|
|
| @@ -1074,6 +1130,12 @@ void BookmarkBarView::OnMenuButtonClicked(views::View* view,
|
|
|
| void BookmarkBarView::ButtonPressed(views::Button* sender,
|
| const ui::Event& event) {
|
| + if (sender->tag() == kAppsShortcutButtonTag) {
|
| + chrome::ShowAppLauncherPage(browser_);
|
| + bookmark_utils::RecordAppsPageOpen(GetBookmarkLaunchLocation());
|
| + return;
|
| + }
|
| +
|
| const BookmarkNode* node;
|
| if (sender->tag() == kOtherFolderButtonTag) {
|
| node = model_->other_node();
|
| @@ -1113,11 +1175,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());
|
| @@ -1161,13 +1224,18 @@ 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)
|
| - // Ash does not paint the bookmarks separator line because it looks odd on
|
| - // the flat background. We keep it present for layout, but don't draw it.
|
| - bookmarks_separator_view_->SetVisible(false);
|
| -#endif
|
| + UpdateBookmarksSeparatorVisibility();
|
|
|
| instructions_ = new BookmarkBarInstructionsView(this);
|
| AddChildView(instructions_);
|
| @@ -1188,8 +1256,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) {
|
| @@ -1259,6 +1327,19 @@ 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);
|
| + return button;
|
| +}
|
| +
|
| void BookmarkBarView::ConfigureButton(const BookmarkNode* node,
|
| views::TextButton* button) {
|
| button->SetText(node->GetTitle());
|
| @@ -1573,13 +1654,20 @@ void BookmarkBarView::UpdateOtherBookmarksVisibility() {
|
| if (has_other_children == other_bookmarked_button_->visible())
|
| return;
|
| other_bookmarked_button_->SetVisible(has_other_children);
|
| -#if !defined(USE_ASH)
|
| - bookmarks_separator_view_->SetVisible(has_other_children);
|
| -#endif
|
| + UpdateBookmarksSeparatorVisibility();
|
| Layout();
|
| SchedulePaint();
|
| }
|
|
|
| +void BookmarkBarView::UpdateBookmarksSeparatorVisibility() {
|
| + // Ash does not paint the bookmarks separator line because it looks odd on
|
| + // the flat background. We keep it present for layout, but don't draw it.
|
| + bookmarks_separator_view_->SetVisible(
|
| + browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH &&
|
| + (other_bookmarked_button_->visible() ||
|
| + apps_page_shortcut_->visible()));
|
| +}
|
| +
|
| gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) {
|
| gfx::Size prefsize;
|
| if (!parent() && !compute_bounds_only)
|
| @@ -1615,11 +1703,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.
|
| @@ -1688,6 +1780,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;
|
| @@ -1712,3 +1813,16 @@ 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());
|
| + UpdateBookmarksSeparatorVisibility();
|
| + Layout();
|
| +}
|
|
|