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

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

Issue 340003002: Revert of views: Move MenuButton from TextButton to LabelButton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 f9d00128f4a6a2be7c714291332c667413c50651..3a4d1f89550f02fcf5a8eca1c2ffe8c3ed60a5fa 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -73,11 +73,8 @@
#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"
@@ -93,7 +90,6 @@
using content::Referrer;
using ui::DropTargetEvent;
using views::CustomButton;
-using views::LabelButtonBorder;
using views::MenuButton;
using views::View;
@@ -141,13 +137,6 @@
// 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;
@@ -161,12 +150,11 @@
// Base class for text buttons used on the bookmark bar.
-class BookmarkButtonBase : public views::LabelButton {
+class BookmarkButtonBase : public views::TextButton {
public:
BookmarkButtonBase(views::ButtonListener* listener,
const base::string16& title)
- : LabelButton(listener, title) {
- SetElideBehavior(gfx::FADE_TAIL);
+ : TextButton(listener, title) {
show_animation_.reset(new gfx::SlideAnimation(this));
if (!animations_enabled) {
// For some reason during testing the events generated by animating
@@ -183,16 +171,6 @@
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_;
@@ -222,7 +200,7 @@
gfx::Point location(p);
ConvertPointToScreen(this, &location);
*tooltip = BookmarkBarView::CreateToolTipForURLAndTitle(
- GetWidget(), location, url_, GetText(), profile_);
+ GetWidget(), location, url_, text(), profile_);
return !tooltip->empty();
}
@@ -289,8 +267,8 @@
virtual bool GetTooltipText(const gfx::Point& p,
base::string16* tooltip) const OVERRIDE {
- if (label()->GetPreferredSize().width() > label()->size().width())
- *tooltip = GetText();
+ if (text_size_.width() > GetTextBounds().width())
+ *tooltip = text_;
return !tooltip->empty();
}
@@ -308,6 +286,10 @@
return false;
}
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ views::MenuButton::PaintButton(canvas, views::MenuButton::PB_NORMAL);
+ }
+
private:
scoped_ptr<gfx::SlideAnimation> show_animation_;
@@ -440,7 +422,7 @@
const int BookmarkBarView::kNewtabHorizontalPadding = 2;
const int BookmarkBarView::kToolbarAttachedBookmarkBarOverlap = 3;
-const gfx::ImageSkia& GetDefaultFavicon() {
+static const gfx::ImageSkia& GetDefaultFavicon() {
if (!kDefaultFavicon) {
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
kDefaultFavicon = rb->GetImageSkiaNamed(IDR_DEFAULT_FAVICON);
@@ -448,7 +430,7 @@
return *kDefaultFavicon;
}
-const gfx::ImageSkia& GetFolderIcon() {
+static const gfx::ImageSkia& GetFolderIcon() {
if (!kFolderIcon) {
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
kFolderIcon = rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_FOLDER);
@@ -1140,21 +1122,13 @@
for (int i = 0; i < GetBookmarkButtonCount(); ++i) {
if (sender == GetBookmarkButton(i)) {
- 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());
+ 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,
+ press_pt.OffsetFromOrigin(),
+ data);
WriteBookmarkDragData(model_->bookmark_bar_node()->GetChild(i), data);
return;
}
@@ -1384,9 +1358,9 @@
return child_count() - 6;
}
-views::LabelButton* BookmarkBarView::GetBookmarkButton(int index) {
+views::TextButton* BookmarkBarView::GetBookmarkButton(int index) {
DCHECK(index >= 0 && index < GetBookmarkButtonCount());
- return static_cast<views::LabelButton*>(child_at(index));
+ return static_cast<views::TextButton*>(child_at(index));
}
BookmarkLaunchLocation BookmarkBarView::GetBookmarkLaunchLocation() const {
@@ -1408,7 +1382,7 @@
MenuButton* button =
new BookmarkFolderButton(this, base::string16(), this, false);
button->set_id(VIEW_ID_OTHER_BOOKMARKS);
- button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
+ button->SetIcon(GetFolderIcon());
button->set_context_menu_controller(this);
button->set_tag(kOtherFolderButtonTag);
return button;
@@ -1421,7 +1395,7 @@
button->set_id(VIEW_ID_MANAGED_BOOKMARKS);
// TODO(joaodasilva): replace with a "managed folder" icon.
// http://crbug.com/49598
- button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
+ button->SetIcon(GetFolderIcon());
button->set_context_menu_controller(this);
button->set_tag(kManagedFolderButtonTag);
return button;
@@ -1430,8 +1404,7 @@
MenuButton* BookmarkBarView::CreateOverflowButton() {
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
MenuButton* button = new OverFlowButton(this);
- button->SetImage(views::Button::STATE_NORMAL,
- *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_CHEVRONS));
+ button->SetIcon(*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
@@ -1459,49 +1432,47 @@
} else {
views::MenuButton* button = new BookmarkFolderButton(
this, node->GetTitle(), this, false);
- button->SetImage(views::Button::STATE_NORMAL, GetFolderIcon());
+ button->SetIcon(GetFolderIcon());
ConfigureButton(node, button);
return button;
}
}
-views::LabelButton* BookmarkBarView::CreateAppsPageShortcutButton() {
- views::LabelButton* button = new ShortcutButton(
+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->SetImage(views::Button::STATE_NORMAL,
- *rb->GetImageSkiaNamed(IDR_BOOKMARK_BAR_APPS_SHORTCUT));
+ button->SetIcon(*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::LabelButton* button) {
+ views::TextButton* 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->SetTextColor(
- views::Button::STATE_NORMAL,
- GetThemeProvider()->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT));
- }
-
- button->set_min_size(gfx::Size());
+ button->SetEnabledColor(GetThemeProvider()->GetColor(
+ ThemeProperties::COLOR_BOOKMARK_TEXT));
+ }
+
+ button->ClearMaxTextSize();
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->SetImage(views::Button::STATE_NORMAL, *favicon.ToImageSkia());
+ button->SetIcon(*favicon.ToImageSkia());
else
- button->SetImage(views::Button::STATE_NORMAL, GetDefaultFavicon());
- }
- button->set_max_size(gfx::Size(kMaxButtonWidth, 0));
+ button->SetIcon(GetDefaultFavicon());
+ }
+ button->set_max_width(kMaxButtonWidth);
}
void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model,
@@ -1561,7 +1532,7 @@
}
int index = model->bookmark_bar_node()->GetIndexOf(node);
DCHECK_NE(-1, index);
- views::LabelButton* button = GetBookmarkButton(index);
+ views::TextButton* button = GetBookmarkButton(index);
gfx::Size old_pref = button->GetPreferredSize();
ConfigureButton(node, button);
gfx::Size new_pref = button->GetPreferredSize();
@@ -1656,7 +1627,7 @@
for (int i = 0; i < GetBookmarkButtonCount() &&
GetBookmarkButton(i)->visible() && !found; i++) {
- views::LabelButton* button = GetBookmarkButton(i);
+ views::TextButton* button = GetBookmarkButton(i);
int button_x = mirrored_x - button->x();
int button_w = button->width();
if (button_x < button_w) {
@@ -1795,14 +1766,14 @@
const ui::ThemeProvider* theme_provider = GetThemeProvider();
if (!theme_provider)
return;
- SkColor color =
+ SkColor text_color =
theme_provider->GetColor(ThemeProperties::COLOR_BOOKMARK_TEXT);
for (int i = 0; i < GetBookmarkButtonCount(); ++i)
- GetBookmarkButton(i)->SetTextColor(views::Button::STATE_NORMAL, color);
- other_bookmarked_button_->SetTextColor(views::Button::STATE_NORMAL, color);
- managed_bookmarks_button_->SetTextColor(views::Button::STATE_NORMAL, color);
+ GetBookmarkButton(i)->SetEnabledColor(text_color);
+ other_bookmarked_button_->SetEnabledColor(text_color);
+ managed_bookmarks_button_->SetEnabledColor(text_color);
if (apps_page_shortcut_->visible())
- apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, color);
+ apps_page_shortcut_->SetEnabledColor(text_color);
}
void BookmarkBarView::UpdateButtonsVisibility() {
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.h ('k') | chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698