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 c73dc5910c57f69a9e36474442cd5fafda09a571..317055f2facfb713763dc20c5ff0a9eb3ed0c7a8 100644 |
| --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc |
| @@ -71,8 +71,11 @@ |
| #include "ui/base/window_open_disposition.h" |
| #include "ui/gfx/animation/slide_animation.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/gfx/text_constants.h" |
| #include "ui/gfx/text_elider.h" |
| #include "ui/views/button_drag_utils.h" |
| +#include "ui/views/controls/button/label_button.h" |
| +#include "ui/views/controls/button/label_button_border.h" |
| #include "ui/views/controls/button/menu_button.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/drag_utils.h" |
| @@ -88,6 +91,7 @@ using content::PageNavigator; |
| using content::Referrer; |
| using ui::DropTargetEvent; |
| using views::CustomButton; |
| +using views::LabelButtonBorder; |
| using views::MenuButton; |
| using views::View; |
| @@ -135,6 +139,13 @@ static const int kOtherFolderButtonTag = 1; |
| // Tag for the 'Apps Shortcut' button. |
| static const int kAppsShortcutButtonTag = 2; |
| +// Preferred padding between text and edge. |
| +// |
| +// Note that the vertical padding is one pixel less than it was in TextButton; |
| +// we clip the bottom of letters like 'g' or 'p' if we don't. |
| +static const int kButtonPaddingHorizontal = 6; |
| +static const int kButtonPaddingVertical = 4; |
| + |
| // Tag for the 'Managed bookmarks' button. |
| static const int kManagedFolderButtonTag = 3; |
| @@ -148,11 +159,12 @@ bool animations_enabled = true; |
| // Base class for text buttons used on the bookmark bar. |
| -class BookmarkButtonBase : public views::TextButton { |
| +class BookmarkButtonBase : public views::LabelButton { |
| public: |
| BookmarkButtonBase(views::ButtonListener* listener, |
| const base::string16& title) |
| - : TextButton(listener, title) { |
| + : LabelButton(listener, title) { |
| + SetElideBehavior(gfx::FADE_TAIL); |
|
msw
2014/06/11 00:55:46
This changed the appearance of elided bookmark but
|
| show_animation_.reset(new gfx::SlideAnimation(this)); |
| if (!animations_enabled) { |
| // For some reason during testing the events generated by animating |
| @@ -169,6 +181,16 @@ class BookmarkButtonBase : public views::TextButton { |
| event_utils::IsPossibleDispositionEvent(e); |
| } |
| + virtual scoped_ptr<LabelButtonBorder> CreateDefaultBorder() const OVERRIDE { |
| + // We change the insets on the border to match the previous TextButton. |
| + scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
| + border->set_insets(gfx::Insets(kButtonPaddingVertical, |
| + kButtonPaddingHorizontal, |
| + kButtonPaddingVertical, |
| + kButtonPaddingHorizontal)); |
| + return border.Pass(); |
| + } |
| + |
| private: |
| scoped_ptr<gfx::SlideAnimation> show_animation_; |
| @@ -198,7 +220,7 @@ class BookmarkButton : public BookmarkButtonBase { |
| gfx::Point location(p); |
| ConvertPointToScreen(this, &location); |
| *tooltip = BookmarkBarView::CreateToolTipForURLAndTitle( |
| - GetWidget(), location, url_, text(), profile_); |
| + GetWidget(), location, url_, GetText(), profile_); |
| return !tooltip->empty(); |
| } |
| @@ -265,8 +287,8 @@ class BookmarkFolderButton : public views::MenuButton { |
| virtual bool GetTooltipText(const gfx::Point& p, |
| base::string16* tooltip) const OVERRIDE { |
| - if (text_size_.width() > GetTextBounds().width()) |
| - *tooltip = text_; |
| + if (label()->GetPreferredSize().width() > label()->size().width()) |
| + *tooltip = GetText(); |
| return !tooltip->empty(); |
| } |
| @@ -284,10 +306,6 @@ class BookmarkFolderButton : public views::MenuButton { |
| return false; |
| } |
| - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { |
| - views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL); |
| - } |
| - |
| private: |
| scoped_ptr<gfx::SlideAnimation> show_animation_; |
| @@ -420,7 +438,7 @@ const int BookmarkBarView::kMaxButtonWidth = 150; |
| const int BookmarkBarView::kNewtabHorizontalPadding = 2; |
| const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3; |
| -static const gfx::ImageSkia& GetDefaultFavicon() { |
| +const gfx::ImageSkia& GetDefaultFavicon() { |
| if (!kDefaultFavicon) { |
| ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON); |
| @@ -428,7 +446,7 @@ static const gfx::ImageSkia& GetDefaultFavicon() { |
| return *kDefaultFavicon; |
| } |
| -static const gfx::ImageSkia& GetFolderIcon() { |
| +const gfx::ImageSkia& GetFolderIcon() { |
| if (!kFolderIcon) { |
| ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER); |
| @@ -1120,13 +1138,21 @@ void BookmarkBarView::WriteDragDataForView(View* sender, |
| for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| if (sender == GetBookmarkButton(i)) { |
| - views::TextButton* button = GetBookmarkButton(i); |
| - scoped_ptr<gfx::Canvas> canvas( |
| - views::GetCanvasForDragImage(button->GetWidget(), button->size())); |
| - button->PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); |
| - drag_utils::SetDragImageOnDataObject(*canvas, button->size(), |
| - press_pt.OffsetFromOrigin(), |
| - data); |
| + views::LabelButton* button = GetBookmarkButton(i); |
| + const BookmarkNode* node = model()->bookmark_bar_node()->GetChild(i); |
| + |
| + const gfx::Image& image_from_model = model()->GetFavicon(node); |
| + const gfx::ImageSkia& icon = image_from_model.IsEmpty() ? |
| + (node->is_folder() ? GetFolderIcon() : GetDefaultFavicon()) : |
| + *image_from_model.ToImageSkia(); |
| + |
| + button_drag_utils::SetDragImage( |
| + node->url(), |
| + node->GetTitle(), |
| + icon, |
| + &press_pt, |
| + data, |
| + button->GetWidget()); |
| WriteBookmarkDragData(model()->bookmark_bar_node()->GetChild(i), data); |
| return; |
| } |
| @@ -1352,9 +1378,9 @@ int BookmarkBarView::GetBookmarkButtonCount() const { |
| return child_count() - 6; |
| } |
| -views::TextButton* BookmarkBarView::GetBookmarkButton(int index) { |
| +views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) { |
| DCHECK(index >= 0 && index < GetBookmarkButtonCount()); |
| - return static_cast<views::TextButton*>(child_at(index)); |
| + return static_cast<views::LabelButton*>(child_at(index)); |
| } |
| BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const { |
| @@ -1376,7 +1402,7 @@ MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() { |
| MenuButton* button = |
| new BookmarkFolderButton(this, base::string16(), this, false); |
| button->set_id(VIEW_ID_OTHER_BOOKMARKS); |
| - button->SetIcon(GetFolderIcon()); |
| + button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon()); |
| button->set_context_menu_controller(this); |
| button->set_tag(kOtherFolderButtonTag); |
| return button; |
| @@ -1389,7 +1415,7 @@ MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { |
| button->set_id(VIEW_ID_MANAGED_BOOKMARKS); |
| // TODO(joaodasilva): replace with a "managed folder" icon. |
| // http://crbug.com/49598 |
| - button->SetIcon(GetFolderIcon()); |
| + button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon()); |
| button->set_context_menu_controller(this); |
| button->set_tag(kManagedFolderButtonTag); |
| return button; |
| @@ -1398,7 +1424,8 @@ MenuButton* BookmarkBarView::CreateManagedBookmarksButton() { |
| MenuButton* BookmarkBarView::CreateOverflowButton() { |
| ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| MenuButton* button = new OverFlowButton(this); |
| - button->SetIcon(*rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
| + button->SetImage(views::Button::STATE_NORMAL, |
| + *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS)); |
| // The overflow button's image contains an arrow and therefore it is a |
| // direction sensitive image and we need to flip it if the UI layout is |
| @@ -1426,47 +1453,49 @@ views::View* BookmarkBarView::CreateBookmarkButton(const BookmarkNode* node) { |
| } else { |
| views::MenuButton* button = new BookmarkFolderButton( |
| this, node->GetTitle(), this, false); |
| - button->SetIcon(GetFolderIcon()); |
| + button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon()); |
| ConfigureButton(node, button); |
| return button; |
| } |
| } |
| -views::TextButton* BookmarkBarView::CreateAppsPageShortcutButton() { |
| - views::TextButton* button = new ShortcutButton( |
| +views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() { |
| + views::LabelButton* 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_BOOKMARK_BAR_APPS_SHORTCUT)); |
| + button->SetImage(views::Button::STATE_NORMAL, |
| + *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT)); |
| button->set_context_menu_controller(this); |
| button->set_tag(kAppsShortcutButtonTag); |
| return button; |
| } |
| void BookmarkBarView::ConfigureButton(const BookmarkNode* node, |
| - views::TextButton* button) { |
| + views::LabelButton* button) { |
| button->SetText(node->GetTitle()); |
| button->SetAccessibleName(node->GetTitle()); |
| button->set_id(VIEW_ID_BOOKMARK_BAR_ELEMENT); |
| // We don't always have a theme provider (ui tests, for example). |
| if (GetThemeProvider()) { |
| - button->SetEnabledColor(GetThemeProvider()->GetColor( |
| - ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| + button->SetTextColor( |
| + views::Button::STATE_NORMAL, |
| + GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT)); |
| } |
| - button->ClearMaxTextSize(); |
| + button->set_min_size(gfx::Size()); |
| button->set_context_menu_controller(this); |
| button->set_drag_controller(this); |
| if (node->is_url()) { |
| const gfx::Image& favicon = model()->GetFavicon(node); |
| if (!favicon.IsEmpty()) |
| - button->SetIcon(*favicon.ToImageSkia()); |
| + button->SetImage(views::Button::STATE_NORMAL, *favicon.ToImageSkia()); |
| else |
| - button->SetIcon(GetDefaultFavicon()); |
| + button->SetImage(views::Button::STATE_NORMAL, GetDefaultFavicon()); |
| } |
| - button->set_max_width(kMaxButtonWidth); |
| + button->set_max_size(gfx::Size(kMaxButtonWidth, 0)); |
| } |
| void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, |
| @@ -1518,7 +1547,7 @@ void BookmarkBarView::BookmarkNodeChangedImpl(BookmarkModel* model, |
| } |
| int index = model->bookmark_bar_node()->GetIndexOf(node); |
| DCHECK_NE(-1, index); |
| - views::TextButton* button = GetBookmarkButton(index); |
| + views::LabelButton* button = GetBookmarkButton(index); |
| gfx::Size old_pref = button->GetPreferredSize(); |
| ConfigureButton(node, button); |
| gfx::Size new_pref = button->GetPreferredSize(); |
| @@ -1613,7 +1642,7 @@ void BookmarkBarView::CalculateDropLocation(const DropTargetEvent& event, |
| for (int i = 0; i < GetBookmarkButtonCount() && |
| GetBookmarkButton(i)->visible() && !found; i++) { |
| - views::TextButton* button = GetBookmarkButton(i); |
| + views::LabelButton* button = GetBookmarkButton(i); |
| int button_x = mirrored_x - button->x(); |
| int button_w = button->width(); |
| if (button_x < button_w) { |
| @@ -1754,12 +1783,16 @@ void BookmarkBarView::UpdateColors() { |
| return; |
| SkColor text_color = |
| theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT); |
| - for (int i = 0; i < GetBookmarkButtonCount(); ++i) |
| - GetBookmarkButton(i)->SetEnabledColor(text_color); |
| - other_bookmarked_button_->SetEnabledColor(text_color); |
| - managed_bookmarks_button_->SetEnabledColor(text_color); |
| + for (int i = 0; i < GetBookmarkButtonCount(); ++i) { |
| + GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, |
| + text_color); |
|
msw
2014/06/11 00:55:45
nit: fits on line above.
|
| + } |
| + other_bookmarked_button_->SetTextColor(views::Button::STATE_NORMAL, |
| + text_color); |
|
msw
2014/06/11 00:55:46
nit: |color| would make this call and the one belo
|
| + managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, |
| + text_color); |
| if (apps_page_shortcut_->visible()) |
| - apps_page_shortcut_->SetEnabledColor(text_color); |
| + apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, text_color); |
| } |
| void BookmarkBarView::UpdateButtonsVisibility() { |