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

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

Issue 298813002: views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove stray LOG Created 6 years, 6 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
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 494690801a386f6c62aea532a58ef647f92ef105..8226c41de26a73c51267890aa479407b5b8ae147 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;
+
namespace {
// To enable/disable BookmarkBar animations during testing. In production
@@ -145,11 +156,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);
show_animation_.reset(new gfx::SlideAnimation(this));
if (!animations_enabled) {
// For some reason during testing the events generated by animating
@@ -166,6 +178,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_;
@@ -195,7 +217,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();
}
@@ -262,8 +284,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();
}
@@ -281,10 +303,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_;
@@ -417,7 +435,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);
@@ -425,7 +443,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);
@@ -1098,13 +1116,16 @@ 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::ImageSkia& icon = *model_->GetFavicon(node).ToImageSkia();
+ button_drag_utils::SetURLAndDragImage(
+ node->url(),
+ node->GetTitle(),
+ icon,
+ data,
+ button->GetWidget());
WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data);
return;
}
@@ -1316,9 +1337,9 @@ int BookmarkBarView::GetBookmarkButtonCount() const {
return child_count() - 5;
}
-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 {
@@ -1340,7 +1361,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;
@@ -1349,7 +1370,8 @@ MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() {
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
@@ -1377,47 +1399,48 @@ 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();
msw 2014/06/09 17:18:40 ditto: call 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,
@@ -1469,7 +1492,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();
@@ -1563,7 +1586,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) {
@@ -1700,11 +1723,14 @@ 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);
+ for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
+ GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL,
+ text_color);
+ }
+ other_bookmarked_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::UpdateOtherBookmarksVisibility() {

Powered by Google App Engine
This is Rietveld 408576698