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

Unified Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 6020: Fixes a couple of bookmark bar bugs:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/bookmarks/bookmark_drag_data.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/bookmark_bar_view.cc
===================================================================
--- chrome/browser/views/bookmark_bar_view.cc (revision 2631)
+++ chrome/browser/views/bookmark_bar_view.cc (working copy)
@@ -143,6 +143,9 @@
// 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,27 +257,27 @@
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);
+ canvas->FillRectInt(0, -kTopMargin, view->width(),
+ view->height() + kTopMargin + kBottomMargin, paint);
}
- virtual void AnimationProgressed(const Animation* animation) {
- ChromeViews::TextButton::AnimationProgressed(animation);
- SchedulePaint();
- }
-
private:
const GURL& url_;
Profile* profile_;
@@ -283,6 +286,45 @@
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 @@
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 @@
}
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::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 @@
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;
}
« no previous file with comments | « chrome/browser/bookmarks/bookmark_drag_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698