diff options
author | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 15:21:16 +0000 |
---|---|---|
committer | sky@google.com <sky@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-10-01 15:21:16 +0000 |
commit | f89a6233760f8ca8033265046ed9ea38bbc20bf9 (patch) | |
tree | a438abfbbfd918fd0cff1862ab4b26ce7507484c /chrome/browser/views | |
parent | f9b05c2dd900aa1850111c4a052db0da6e060a5a (diff) | |
download | chromium_src-f89a6233760f8ca8033265046ed9ea38bbc20bf9.zip chromium_src-f89a6233760f8ca8033265046ed9ea38bbc20bf9.tar.gz chromium_src-f89a6233760f8ca8033265046ed9ea38bbc20bf9.tar.bz2 |
Fixes a couple of bookmark bar bugs:
. The folders on the bookmark bar now fade in like urls.
. You can now middle click on folders to open all URLs.
. If you attempt to open a folder with more than 15 urls we'll prompt
before openning.
BUG=242 529 1295385
TEST=middle click on a folder on the bookmark bar and make sure it
opens all tabs in the background. Try this with a folder containing
more than 15 bookmarks and make sure you get a message box before
asking if you really want to open them all.
Review URL: http://codereview.chromium.org/6020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2756 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 94 |
1 files changed, 75 insertions, 19 deletions
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index 8d2531a..20bee0b 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -143,6 +143,9 @@ static const int kInstructionsPadding = 6; // Color of the instructional text. static const SkColor kInstructionsColor = SkColorSetRGB(128, 128, 142); +// Tag for the other button. +static const int kOtherFolderButtonTag = 1; + namespace { // Calculates the drop operation given the event and supported set of @@ -254,25 +257,25 @@ class BookmarkButton : public ChromeViews::TextButton { virtual void Paint(ChromeCanvas *canvas) { ChromeViews::TextButton::Paint(canvas); + PaintAnimation(this, canvas, show_animation_->GetCurrentValue()); + } + + static void PaintAnimation(ChromeViews::View* view, + ChromeCanvas* canvas, + double animation_value) { // Since we can't change the alpha of the button (it contains un-alphable // text), we paint the bar background over the front of the button. As the // bar background is a gradient, we have to paint the gradient at the // size of the parent (hence all the margin math below). We can't use // the parent's actual bounds because they differ from what is painted. SkPaint paint; - paint.setAlpha(static_cast<int>( - (1.0 - show_animation_->GetCurrentValue()) * 255)); + paint.setAlpha(static_cast<int>((1.0 - animation_value) * 255)); paint.setShader(gfx::CreateGradientShader(0, - height() + kTopMargin + kBottomMargin, + view->height() + kTopMargin + kBottomMargin, kTopBorderColor, kBackgroundColor))->safeUnref(); - canvas->FillRectInt(0, -kTopMargin, width(), - height() + kTopMargin + kBottomMargin, paint); - } - - virtual void AnimationProgressed(const Animation* animation) { - ChromeViews::TextButton::AnimationProgressed(animation); - SchedulePaint(); + canvas->FillRectInt(0, -kTopMargin, view->width(), + view->height() + kTopMargin + kBottomMargin, paint); } private: @@ -283,6 +286,45 @@ class BookmarkButton : public ChromeViews::TextButton { DISALLOW_COPY_AND_ASSIGN(BookmarkButton); }; +// BookmarkFolderButton ------------------------------------------------------- + +// Buttons used for folders on the bookmark bar, including the 'other folders' +// button. +class BookmarkFolderButton : public ChromeViews::MenuButton { + public: + BookmarkFolderButton(const std::wstring& title, + ChromeViews::ViewMenuDelegate* menu_delegate, + bool show_menu_marker) + : MenuButton(title, menu_delegate, show_menu_marker) { + show_animation_.reset(new SlideAnimation(this)); + if (BookmarkBarView::testing_) { + // 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 ChromeViews::MouseEvent& e) { + // This is hard coded to avoid potential notification on left mouse down, + // which we want to show the menu. + return e.IsMiddleMouseButton(); + } + + virtual void Paint(ChromeCanvas *canvas) { + ChromeViews::MenuButton::Paint(canvas, false); + + BookmarkButton::PaintAnimation(this, canvas, + show_animation_->GetCurrentValue()); + } + + private: + scoped_ptr<SlideAnimation> show_animation_; + + DISALLOW_COPY_AND_ASSIGN(BookmarkFolderButton); +}; + // DropInfo ------------------------------------------------------------------- // Tracks drops on the BookmarkBarView. @@ -386,6 +428,7 @@ class MenuRunner : public ChromeViews::MenuDelegate, MenuItemView* menu, int* next_menu_id) { DCHECK(!parent->GetChildCount() || + start_child_index < parent->GetChildCount()); for (int i = start_child_index; i < parent->GetChildCount(); ++i) { BookmarkNode* node = parent->GetChild(i); @@ -1127,10 +1170,11 @@ void BookmarkBarView::Init() { } MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { - MenuButton* button = new MenuButton( + MenuButton* button = new BookmarkFolderButton( l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, false); button->SetIcon(GetGroupIcon()); button->SetContextMenuController(this); + button->SetListener(this, kOtherFolderButtonTag); return button; } @@ -1371,14 +1415,25 @@ void BookmarkBarView::RunMenu(ChromeViews::View* view, } void BookmarkBarView::ButtonPressed(ChromeViews::BaseButton* sender) { - int index = GetChildIndex(sender); - DCHECK(index != -1); - BookmarkNode* node = model_->GetBookmarkBarNode()->GetChild(index); + BookmarkNode* node; + if (sender->GetTag() == kOtherFolderButtonTag) { + node = model_->other_node(); + } else { + int index = GetChildIndex(sender); + DCHECK(index != -1); + node = model_->GetBookmarkBarNode()->GetChild(index); + } DCHECK(page_navigator_); - page_navigator_->OpenURL( - node->GetURL(), - event_utils::DispositionFromEventFlags(sender->mouse_event_flags()), - PageTransition::AUTO_BOOKMARK); + if (node->is_url()) { + page_navigator_->OpenURL( + node->GetURL(), + event_utils::DispositionFromEventFlags(sender->mouse_event_flags()), + PageTransition::AUTO_BOOKMARK); + } else { + BookmarkBarContextMenuController::OpenAll( + GetViewContainer()->GetHWND(), GetPageNavigator(), node, + event_utils::DispositionFromEventFlags(sender->mouse_event_flags())); + } UserMetrics::RecordAction(L"ClickedBookmarkBarURLButton", profile_); } @@ -1416,8 +1471,9 @@ ChromeViews::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) { return button; } else { ChromeViews::MenuButton* button = - new ChromeViews::MenuButton(node->GetTitle(), this, false); + new BookmarkFolderButton(node->GetTitle(), this, false); button->SetIcon(GetGroupIcon()); + button->SetListener(this, 0); ConfigureButton(node, button); return button; } |