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

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: Disable DragDirectlyToSecondWindow. 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 3a4d1f89550f02fcf5a8eca1c2ffe8c3ed60a5fa..f9d00128f4a6a2be7c714291332c667413c50651 100644
--- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
+++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc
@@ -73,8 +73,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"
@@ -90,6 +93,7 @@ using content::PageNavigator;
using content::Referrer;
using ui::DropTargetEvent;
using views::CustomButton;
+using views::LabelButtonBorder;
using views::MenuButton;
using views::View;
@@ -137,6 +141,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;
@@ -150,11 +161,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
@@ -171,6 +183,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_;
@@ -200,7 +222,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();
}
@@ -267,8 +289,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();
}
@@ -286,10 +308,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_;
@@ -422,7 +440,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);
@@ -430,7 +448,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);
@@ -1122,13 +1140,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,
- 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;
}
@@ -1358,9 +1384,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 {
@@ -1382,7 +1408,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;
@@ -1395,7 +1421,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;
@@ -1404,7 +1430,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
@@ -1432,47 +1459,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,
@@ -1532,7 +1561,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();
@@ -1627,7 +1656,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) {
@@ -1766,14 +1795,14 @@ void BookmarkBarView::UpdateColors() {
const ui::ThemeProvider* theme_provider = GetThemeProvider();
if (!theme_provider)
return;
- SkColor text_color =
+ SkColor 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);
+ 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);
if (apps_page_shortcut_->visible())
- apps_page_shortcut_->SetEnabledColor(text_color);
+ apps_page_shortcut_->SetTextColor(views::Button::STATE_NORMAL, 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