diff options
40 files changed, 309 insertions, 247 deletions
diff --git a/chrome/browser/extensions/api/bookmarks/bookmark_apitest.cc b/chrome/browser/extensions/api/bookmarks/bookmark_apitest.cc index 9de6ae6..14dc9e1 100644 --- a/chrome/browser/extensions/api/bookmarks/bookmark_apitest.cc +++ b/chrome/browser/extensions/api/bookmarks/bookmark_apitest.cc @@ -15,8 +15,8 @@ #include "components/bookmarks/common/bookmark_pref_names.h" #include "components/bookmarks/test/bookmark_test_helpers.h" -// Flaky on Win only. http://crbug.com/383452 -#if defined(OS_WIN) +// Flaky on Windows and Linux. http://crbug.com/383452 +#if defined(OS_WIN) || defined(OS_LINUX) #define MAYBE_Bookmarks DISABLED_Bookmarks #else #define MAYBE_Bookmarks Bookmarks diff --git a/chrome/browser/ui/libgtk2ui/gtk2_border.cc b/chrome/browser/ui/libgtk2ui/gtk2_border.cc index 0863bcf..0859637f 100644 --- a/chrome/browser/ui/libgtk2ui/gtk2_border.cc +++ b/chrome/browser/ui/libgtk2ui/gtk2_border.cc @@ -17,6 +17,7 @@ #include "ui/gfx/rect.h" #include "ui/gfx/skia_util.h" #include "ui/views/controls/button/label_button.h" +#include "ui/views/controls/button/label_button_border.h" #include "ui/views/native_theme_delegate.h" using views::Button; @@ -63,7 +64,7 @@ class ButtonImageSkiaSource : public gfx::ImageSkiaSource { Gtk2Border::Gtk2Border(Gtk2UI* gtk2_ui, views::LabelButton* owning_button, - scoped_ptr<views::Border> border) + scoped_ptr<views::LabelButtonBorder> border) : gtk2_ui_(gtk2_ui), owning_button_(owning_button), border_(border.Pass()), @@ -132,7 +133,8 @@ void Gtk2Border::PaintState(const ui::NativeTheme::State state, bool focused = extra.button.is_focused; Button::ButtonState views_state = Button::GetButtonStateFrom(state); - if (ShouldDrawBorder(focused, views_state)) { + if (border_->GetPainter(focused, views_state) || + (focused && border_->GetPainter(false, views_state))) { gfx::ImageSkia* image = &button_images_[focused][views_state]; if (image->isNull() || image->size() != rect.size()) { @@ -145,17 +147,4 @@ void Gtk2Border::PaintState(const ui::NativeTheme::State state, } } -bool Gtk2Border::ShouldDrawBorder(bool focused, - views::Button::ButtonState state) { - // This logic should be kept in sync with the LabelButtonBorder constructor. - if (owning_button_->style() == Button::STYLE_BUTTON) { - return true; - } else if (owning_button_->style() == Button::STYLE_TEXTBUTTON) { - return focused == false && (state == Button::STATE_HOVERED || - state == Button::STATE_PRESSED); - } - - return false; -} - } // namespace libgtk2ui diff --git a/chrome/browser/ui/libgtk2ui/gtk2_border.h b/chrome/browser/ui/libgtk2ui/gtk2_border.h index ca1fcd4..ebd41bf 100644 --- a/chrome/browser/ui/libgtk2ui/gtk2_border.h +++ b/chrome/browser/ui/libgtk2ui/gtk2_border.h @@ -18,7 +18,7 @@ class Canvas; namespace views { class LabelButton; -class Border; +class LabelButtonBorder; } namespace libgtk2ui { @@ -29,7 +29,7 @@ class Gtk2Border : public views::Border, public ui::NativeThemeObserver { public: Gtk2Border(Gtk2UI* gtk2_ui, views::LabelButton* owning_button, - scoped_ptr<views::Border> border); + scoped_ptr<views::LabelButtonBorder> border); virtual ~Gtk2Border(); // Overridden from views::Border: @@ -46,8 +46,6 @@ class Gtk2Border : public views::Border, public ui::NativeThemeObserver { const gfx::Rect& rect, gfx::Canvas* canvas); - bool ShouldDrawBorder(bool focused, views::Button::ButtonState state); - Gtk2UI* gtk2_ui_; gfx::ImageSkia button_images_[2][views::Button::STATE_COUNT]; @@ -58,7 +56,7 @@ class Gtk2Border : public views::Border, public ui::NativeThemeObserver { // The views::Border that we are replacing in native mode. We keep track of // this for inset information. - scoped_ptr<views::Border> border_; + scoped_ptr<views::LabelButtonBorder> border_; ScopedObserver<ui::NativeTheme, ui::NativeThemeObserver> observer_manager_; diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc index da56985..293feeb 100644 --- a/chrome/browser/ui/libgtk2ui/gtk2_ui.cc +++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.cc @@ -45,6 +45,7 @@ #include "ui/gfx/skbitmap_operations.h" #include "ui/gfx/skia_util.h" #include "ui/views/controls/button/label_button.h" +#include "ui/views/controls/button/label_button_border.h" #include "ui/views/linux_ui/window_button_order_observer.h" #if defined(USE_GCONF) @@ -557,9 +558,9 @@ gfx::Image Gtk2UI::GetIconForContentType( scoped_ptr<views::Border> Gtk2UI::CreateNativeBorder( views::LabelButton* owning_button, - scoped_ptr<views::Border> border) { + scoped_ptr<views::LabelButtonBorder> border) { if (owning_button->GetNativeTheme() != NativeThemeGtk2::instance()) - return border.Pass(); + return border.PassAs<views::Border>(); return scoped_ptr<views::Border>( new Gtk2Border(this, owning_button, border.Pass())); diff --git a/chrome/browser/ui/libgtk2ui/gtk2_ui.h b/chrome/browser/ui/libgtk2ui/gtk2_ui.h index 734f77d..2ef92556 100644 --- a/chrome/browser/ui/libgtk2ui/gtk2_ui.h +++ b/chrome/browser/ui/libgtk2ui/gtk2_ui.h @@ -103,7 +103,7 @@ class Gtk2UI : public views::LinuxUI { const std::string& content_type, int size) const OVERRIDE; virtual scoped_ptr<views::Border> CreateNativeBorder( views::LabelButton* owning_button, - scoped_ptr<views::Border> border) OVERRIDE; + scoped_ptr<views::LabelButtonBorder> border) OVERRIDE; virtual void AddWindowButtonOrderObserver( views::WindowButtonOrderObserver* observer) OVERRIDE; virtual void RemoveWindowButtonOrderObserver( diff --git a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc index 72d99f3..a033401 100644 --- a/chrome/browser/ui/views/autofill/autofill_dialog_views.cc +++ b/chrome/browser/ui/views/autofill/autofill_dialog_views.cc @@ -507,8 +507,7 @@ void AutofillDialogViews::AccountChooser::Update() { gfx::Image icon = delegate_->AccountChooserImage(); image_->SetImage(icon.AsImageSkia()); menu_button_->SetText(delegate_->AccountChooserText()); - // This allows the button to shrink if the new text is smaller. - menu_button_->ClearMaxTextSize(); + menu_button_->set_min_size(gfx::Size()); bool show_link = !delegate_->MenuModelForAccountChooser(); menu_button_->SetVisible(!show_link); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc index 3a4d1f8..f9d0012 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() { diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h index 65ae8e8..5383d8980 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view.h @@ -46,7 +46,7 @@ namespace views { class CustomButton; class MenuButton; class MenuItemView; -class TextButton; +class LabelButton; } // BookmarkBarView renders the BookmarkModel. Each starred entry on the @@ -289,7 +289,7 @@ class BookmarkBarView : public DetachableToolbarView, int GetBookmarkButtonCount() const; // Returns the button at the specified index. - views::TextButton* GetBookmarkButton(int index); + views::LabelButton* GetBookmarkButton(int index); // Returns BOOKMARK_LAUNCH_LOCATION_DETACHED_BAR or // BOOKMARK_LAUNCH_LOCATION_ATTACHED_BAR based on detached state. @@ -312,11 +312,11 @@ class BookmarkBarView : public DetachableToolbarView, views::View* CreateBookmarkButton(const BookmarkNode* node); // Creates the button for rendering the apps page shortcut. - views::TextButton* CreateAppsPageShortcutButton(); + views::LabelButton* CreateAppsPageShortcutButton(); // Configures the button from the specified node. This sets the text, // and icon. - void ConfigureButton(const BookmarkNode* node, views::TextButton* button); + void ConfigureButton(const BookmarkNode* node, views::LabelButton* button); // Implementation for BookmarkNodeAddedImpl. void BookmarkNodeAddedImpl(BookmarkModel* model, @@ -412,7 +412,7 @@ class BookmarkBarView : public DetachableToolbarView, views::MenuButton* managed_bookmarks_button_; // Shows the Apps page shortcut. - views::TextButton* apps_page_shortcut_; + views::LabelButton* apps_page_shortcut_; // Task used to delay showing of the drop menu. base::WeakPtrFactory<BookmarkBarView> show_folder_method_factory_; diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc index f52926e..bc26a27 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc @@ -300,7 +300,7 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { bb_view_pref_ = bb_view_->GetPreferredSize(); bb_view_pref_.set_width(1000); - views::TextButton* button = GetBookmarkButton(6); + views::LabelButton* button = GetBookmarkButton(6); while (button->visible()) { bb_view_pref_.set_width(bb_view_pref_.width() - 25); bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); @@ -342,7 +342,7 @@ class BookmarkBarViewEventTestBase : public ViewEventTestBase { virtual gfx::Size GetPreferredSize() const OVERRIDE { return bb_view_pref_; } - views::TextButton* GetBookmarkButton(int view_index) { + views::LabelButton* GetBookmarkButton(int view_index) { return bb_view_->GetBookmarkButton(view_index); } @@ -401,7 +401,7 @@ class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest1::Step2)); @@ -415,7 +415,7 @@ class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); // Button should be depressed. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED); // Click on the 2nd menu item (A URL). @@ -434,7 +434,7 @@ class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { model_->bookmark_bar_node()->GetChild(0)->GetChild(0)->url()); // Make sure button is no longer pushed. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ASSERT_TRUE(button->state() == views::CustomButton::STATE_NORMAL); views::MenuItemView* menu = bb_view_->GetMenu(); @@ -452,7 +452,7 @@ class BookmarkBarViewTest2 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest2::Step2)); @@ -490,7 +490,7 @@ class BookmarkBarViewTest2 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing()); // Make sure button is no longer pushed. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ASSERT_TRUE(button->state() == views::CustomButton::STATE_NORMAL); Done(); @@ -620,7 +620,7 @@ class BookmarkBarViewTest4 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest4::Step2)); @@ -676,7 +676,7 @@ class BookmarkBarViewTest5 : public BookmarkBarViewEventTestBase { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest5::Step2)); @@ -743,7 +743,7 @@ class BookmarkBarViewTest6 : public BookmarkBarViewEventTestBase { protected: virtual void DoTestOnMessageLoop() OVERRIDE { // Press the mouse button on the overflow button. Don't release it though. - views::TextButton* button = bb_view_->overflow_button(); + views::LabelButton* button = bb_view_->overflow_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN, CreateEventTask(this, &BookmarkBarViewTest6::Step2)); } @@ -784,7 +784,7 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest7::Step2)); @@ -809,7 +809,7 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase { void Step3() { // Drag over other button. - views::TextButton* other_button = + views::LabelButton* other_button = bb_view_->other_bookmarked_button(); gfx::Point loc(other_button->width() / 2, other_button->height() / 2); views::View::ConvertPointToScreen(other_button, &loc); @@ -831,7 +831,7 @@ class BookmarkBarViewTest7 : public BookmarkBarViewEventTestBase { void Step3A() { // Drag over other button. - views::TextButton* other_button = + views::LabelButton* other_button = bb_view_->other_bookmarked_button(); gfx::Point loc(other_button->width() / 2, other_button->height() / 2); views::View::ConvertPointToScreen(other_button, &loc); @@ -884,7 +884,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest8::Step2)); @@ -909,7 +909,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase { void Step3() { // Drag over other button. - views::TextButton* other_button = + views::LabelButton* other_button = bb_view_->other_bookmarked_button(); gfx::Point loc(other_button->width() / 2, other_button->height() / 2); views::View::ConvertPointToScreen(other_button, &loc); @@ -930,7 +930,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase { void Step3A() { // Drag over other button. - views::TextButton* other_button = + views::LabelButton* other_button = bb_view_->other_bookmarked_button(); gfx::Point loc(other_button->width() / 2, other_button->height() / 2); views::View::ConvertPointToScreen(other_button, &loc); @@ -945,7 +945,7 @@ class BookmarkBarViewTest8 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(drop_menu->GetSubmenu()->IsShowing()); // Now drag back over first menu. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); gfx::Point loc(button->width() / 2, button->height() / 2); views::View::ConvertPointToScreen(button, &loc); ui_controls::SendMouseMoveNotifyWhenDone(loc.x(), loc.y(), @@ -991,7 +991,7 @@ class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest9::Step2)); @@ -1060,7 +1060,7 @@ class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest10::Step2)); @@ -1174,7 +1174,7 @@ class BookmarkBarViewTest11 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest11::Step2)); @@ -1249,7 +1249,7 @@ class BookmarkBarViewTest12 : public BookmarkBarViewEventTestBase { protected: virtual void DoTestOnMessageLoop() OVERRIDE { // Open up the other folder. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest12::Step2)); @@ -1352,7 +1352,7 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest13::Step2)); @@ -1436,7 +1436,7 @@ class BookmarkBarViewTest14 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // right mouse button. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::RIGHT, ui_controls::DOWN | ui_controls::UP, base::Closure()); // Step2 will be invoked by BookmarkContextMenuNotificationObserver. @@ -1475,7 +1475,7 @@ class BookmarkBarViewTest15 : public BookmarkBarViewEventTestBase { protected: virtual void DoTestOnMessageLoop() OVERRIDE { // Show the other bookmarks. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest15::Step2)); @@ -1547,7 +1547,7 @@ class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the first folder on the bookmark bar and press the // mouse. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest16::Step2)); @@ -1561,7 +1561,7 @@ class BookmarkBarViewTest16 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); // Button should be depressed. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED); // Close the window. @@ -1594,7 +1594,7 @@ class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the other folder on the bookmark bar and press the // left mouse button. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest17::Step2)); @@ -1678,7 +1678,7 @@ class BookmarkBarViewTest18 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the other folder on the bookmark bar and press the // left mouse button. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest18::Step2)); @@ -1692,7 +1692,7 @@ class BookmarkBarViewTest18 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); // Move the mouse to the first folder on the bookmark bar - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); gfx::Point button_center(button->width() / 2, button->height() / 2); views::View::ConvertPointToScreen(button, &button_center); ui_controls::SendMouseMoveNotifyWhenDone( @@ -1735,7 +1735,7 @@ class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase { virtual void DoTestOnMessageLoop() OVERRIDE { // Move the mouse to the other folder on the bookmark bar and press the // left mouse button. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest19::Step2)); @@ -1764,7 +1764,7 @@ class BookmarkBarViewTest19 : public BookmarkBarViewEventTestBase { ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); // Move the mouse back to the other bookmark button. - views::TextButton* button = bb_view_->other_bookmarked_button(); + views::LabelButton* button = bb_view_->other_bookmarked_button(); gfx::Point button_center(button->width() / 2, button->height() / 2); views::View::ConvertPointToScreen(button, &button_center); ui_controls::SendMouseMoveNotifyWhenDone( @@ -1834,7 +1834,7 @@ class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase { // Move the mouse to the first folder on the bookmark bar and press the // left mouse button. - views::TextButton* button = GetBookmarkButton(0); + views::LabelButton* button = GetBookmarkButton(0); ui_test_utils::MoveMouseToCenterAndPress( button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest20::Step2)); @@ -1921,7 +1921,7 @@ class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase { // Move the mouse to the empty folder on the bookmark bar and press the // left mouse button. virtual void DoTestOnMessageLoop() OVERRIDE { - views::TextButton* button = GetBookmarkButton(5); + views::LabelButton* button = GetBookmarkButton(5); ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, CreateEventTask(this, &BookmarkBarViewTest21::Step2)); @@ -1968,9 +1968,9 @@ class BookmarkBarViewTest21 : public BookmarkBarViewEventTestBase { // Confirm that the empty folder gets removed and menu doesn't show. void Step4() { - views::TextButton* button = GetBookmarkButton(5); + views::LabelButton* button = GetBookmarkButton(5); ASSERT_TRUE(button); - EXPECT_EQ(ASCIIToUTF16("d"), button->text()); + EXPECT_EQ(ASCIIToUTF16("d"), button->GetText()); EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); EXPECT_TRUE(bb_view_->GetMenu() == NULL); diff --git a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc index f17ba97..308a997 100644 --- a/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc +++ b/chrome/browser/ui/views/bookmarks/bookmark_bar_view_unittest.cc @@ -18,7 +18,7 @@ #include "chrome/test/base/testing_browser_process.h" #include "chrome/test/base/testing_pref_service_syncable.h" #include "components/bookmarks/test/bookmark_test_helpers.h" -#include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/button/label_button.h" class BookmarkBarViewInstantExtendedTest : public BrowserWithTestWindowTest { public: diff --git a/chrome/browser/ui/views/content_setting_bubble_contents.cc b/chrome/browser/ui/views/content_setting_bubble_contents.cc index 5980bb6..59f12ac 100644 --- a/chrome/browser/ui/views/content_setting_bubble_contents.cc +++ b/chrome/browser/ui/views/content_setting_bubble_contents.cc @@ -293,9 +293,7 @@ void ContentSettingBubbleContents::Init() { views::MenuButton* menu_button = new views::MenuButton( NULL, base::UTF8ToUTF16((i->second.selected_device.name)), this, true); - menu_button->set_alignment(views::TextButton::ALIGN_LEFT); - menu_button->SetBorder(scoped_ptr<views::Border>( - new views::TextButtonNativeThemeBorder(menu_button))); + menu_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); menu_button->set_animate_on_state_change(false); MediaMenuParts* menu_view = new MediaMenuParts(i->first); @@ -337,8 +335,8 @@ void ContentSettingBubbleContents::Init() { // Set all the menu buttons to the width we calculated above. for (MediaMenuPartsMap::const_iterator i = media_menus_.begin(); i != media_menus_.end(); ++i) { - i->first->set_min_width(menu_width); - i->first->set_max_width(menu_width); + i->first->set_min_size(gfx::Size(menu_width, 0)); + i->first->set_max_size(gfx::Size(menu_width, 0)); } } @@ -467,7 +465,7 @@ void ContentSettingBubbleContents::OnMenuButtonClicked( int ContentSettingBubbleContents::GetPreferredMediaMenuWidth( views::MenuButton* button, ui::SimpleMenuModel* menu_model) { - base::string16 title = button->text(); + base::string16 title = button->GetText(); int width = button->GetPreferredSize().width(); for (int i = 0; i < menu_model->GetItemCount(); ++i) { diff --git a/chrome/browser/ui/views/find_bar_view.cc b/chrome/browser/ui/views/find_bar_view.cc index 37bca60..e0dd961 100644 --- a/chrome/browser/ui/views/find_bar_view.cc +++ b/chrome/browser/ui/views/find_bar_view.cc @@ -28,6 +28,7 @@ #include "ui/base/theme_provider.h" #include "ui/events/event.h" #include "ui/gfx/canvas.h" +#include "ui/views/border.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/label.h" #include "ui/views/painter.h" diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc index a6ba3c2..ac0fda3 100644 --- a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc +++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc @@ -121,11 +121,8 @@ void BrowserNonClientFrameView::UpdateAvatarInfo() { if (avatar_button_ && !AvatarMenu::ShouldShowAvatarMenu()) avatar_button_->SetEnabled(false); } - if (avatar_button_) { + if (avatar_button_) avatar_button_->SetAvatarIcon(avatar, is_rectangle); - if (!text.empty()) - avatar_button_->SetText(text); - } // For popups and panels which don't have the avatar button, we still // need to draw the taskbar decoration. Even though we have an icon on the diff --git a/chrome/browser/ui/views/infobars/extension_infobar.cc b/chrome/browser/ui/views/infobars/extension_infobar.cc index d9ea3c2..a7ff5ba 100644 --- a/chrome/browser/ui/views/infobars/extension_infobar.cc +++ b/chrome/browser/ui/views/infobars/extension_infobar.cc @@ -208,7 +208,7 @@ void ExtensionInfoBar::OnImageLoaded(const gfx::Image& image) { gfx::CanvasImageSource* source = new MenuImageSource(*icon, *drop_image); gfx::ImageSkia menu_image = gfx::ImageSkia(source, source->size()); - icon_as_menu_->SetIcon(menu_image); + icon_as_menu_->SetImage(views::Button::STATE_NORMAL, menu_image); } else { icon_as_image_->SetImage(*icon); } diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index cd5da729..3874c8a 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -23,6 +23,7 @@ #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/button/text_button.h" #include "ui/views/controls/image_view.h" #include "ui/views/controls/label.h" #include "ui/views/controls/link.h" @@ -129,8 +130,8 @@ views::MenuButton* InfoBarView::CreateMenuButton( ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); menu_button->set_menu_marker( rb.GetImageNamed(IDR_INFOBARBUTTON_MENU_DROPARROW).ToImageSkia()); - menu_button->SetEnabledColor(SK_ColorBLACK); - menu_button->SetHoverColor(SK_ColorBLACK); + menu_button->SetTextColor(views::Button::STATE_NORMAL, SK_ColorBLACK); + menu_button->SetTextColor(views::Button::STATE_HOVERED, SK_ColorBLACK); menu_button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); menu_button->SizeToPreferredSize(); menu_button->SetFocusable(true); diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 8221529..26c959c 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -1641,6 +1641,7 @@ void LocationBarView::WriteDragDataForView(views::View* sender, button_drag_utils::SetURLAndDragImage(web_contents->GetURL(), web_contents->GetTitle(), favicon, + NULL, data, sender->GetWidget()); } diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index 08f77a5..538d386 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -944,7 +944,7 @@ void OmniboxViewViews::OnWriteDragData(ui::OSExchangeData* data) { if (is_all_selected) model()->GetDataForURLExport(&url, &title, &favicon); button_drag_utils::SetURLAndDragImage(url, title, favicon.AsImageSkia(), - data, GetWidget()); + NULL, data, GetWidget()); data->SetURL(url, title); } } diff --git a/chrome/browser/ui/views/profiles/avatar_label.cc b/chrome/browser/ui/views/profiles/avatar_label.cc index 7b7bad7..7650091 100644 --- a/chrome/browser/ui/views/profiles/avatar_label.cc +++ b/chrome/browser/ui/views/profiles/avatar_label.cc @@ -14,6 +14,7 @@ #include "ui/base/theme_provider.h" #include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" +#include "ui/views/border.h" #include "ui/views/painter.h" namespace { diff --git a/chrome/browser/ui/views/profiles/new_avatar_button.cc b/chrome/browser/ui/views/profiles/new_avatar_button.cc index 173eb14..117f703 100644 --- a/chrome/browser/ui/views/profiles/new_avatar_button.cc +++ b/chrome/browser/ui/views/profiles/new_avatar_button.cc @@ -4,6 +4,7 @@ #include "chrome/browser/ui/views/profiles/new_avatar_button.h" +#include "base/strings/utf_string_conversions.h" #include "base/win/windows_version.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/profiles/profile_manager.h" @@ -18,29 +19,34 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/font_list.h" +#include "ui/gfx/text_constants.h" #include "ui/gfx/text_elider.h" #include "ui/views/border.h" +#include "ui/views/controls/button/label_button_border.h" #include "ui/views/painter.h" namespace { // Text padding within the button border. -const int kInset = 10; +const int kLeftRightInset = 7; +const int kTopBottomInset = 2; scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], const int hot_image_set[], const int pushed_image_set[]) { - scoped_ptr<views::TextButtonDefaultBorder> border( - new views::TextButtonDefaultBorder()); + scoped_ptr<views::LabelButtonBorder> border( + new views::LabelButtonBorder(views::Button::STYLE_TEXTBUTTON)); - border->SetInsets(gfx::Insets(kInset, kInset, kInset, kInset)); - border->set_normal_painter( + border->SetPainter(false, views::Button::STATE_NORMAL, views::Painter::CreateImageGridPainter(normal_image_set)); - border->set_hot_painter( + border->SetPainter(false, views::Button::STATE_HOVERED, views::Painter::CreateImageGridPainter(hot_image_set)); - border->set_pushed_painter( + border->SetPainter(false, views::Button::STATE_PRESSED, views::Painter::CreateImageGridPainter(pushed_image_set)); + border->set_insets(gfx::Insets(kTopBottomInset, kLeftRightInset, + kTopBottomInset, kLeftRightInset)); + return border.PassAs<views::Border>(); } @@ -71,7 +77,11 @@ NewAvatarButton::NewAvatarButton( : MenuButton(listener, GetButtonText(browser->profile()), NULL, true), browser_(browser) { set_animate_on_state_change(false); - set_icon_placement(ICON_ON_RIGHT); + SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); + SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); + SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); + SetHaloColor(SK_ColorDKGRAY); + SetHorizontalAlignment(gfx::ALIGN_RIGHT); ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); @@ -130,22 +140,6 @@ NewAvatarButton::~NewAvatarButton() { error->RemoveObserver(this); } -void NewAvatarButton::OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) { - // Get text bounds, and then adjust for the top and RTL languages. - gfx::Rect rect = GetTextBounds(); - rect.Offset(0, -rect.y()); - if (rect.width() > 0) - rect.set_x(GetMirroredXForRect(rect)); - - canvas->DrawStringRectWithHalo( - text(), - gfx::FontList(), - SK_ColorWHITE, - SK_ColorDKGRAY, - rect, - gfx::Canvas::NO_SUBPIXEL_RENDERING); -} - void NewAvatarButton::OnProfileAdded(const base::FilePath& profile_path) { UpdateAvatarButtonAndRelayoutParent(); } @@ -173,14 +167,15 @@ void NewAvatarButton::OnErrorChanged() { icon = *rb->GetImageNamed(IDR_WARNING).ToImageSkia(); } - SetIcon(icon); + SetImage(views::Button::STATE_NORMAL, icon); UpdateAvatarButtonAndRelayoutParent(); } void NewAvatarButton::UpdateAvatarButtonAndRelayoutParent() { // We want the button to resize if the new text is shorter. SetText(GetButtonText(browser_->profile())); - ClearMaxTextSize(); + set_min_size(gfx::Size()); + InvalidateLayout(); // Because the width of the button might have changed, the parent browser // frame needs to recalculate the button bounds and redraw it. diff --git a/chrome/browser/ui/views/profiles/new_avatar_button.h b/chrome/browser/ui/views/profiles/new_avatar_button.h index 805ba0c..457bb54 100644 --- a/chrome/browser/ui/views/profiles/new_avatar_button.h +++ b/chrome/browser/ui/views/profiles/new_avatar_button.h @@ -28,9 +28,6 @@ class NewAvatarButton : public views::MenuButton, Browser* browser); virtual ~NewAvatarButton(); - // views::TextButton: - virtual void OnPaintText(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; - private: friend class NewAvatarMenuButtonTest; friend class ProfileChooserViewBrowserTest; diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc b/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc index 89583ad..4d9a194 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller_interactive_uitest.cc @@ -1199,7 +1199,7 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest, EXPECT_FALSE(browser2->window()->IsMaximized()); } -#if defined(OS_CHROMEOS) || defined(OS_LINUX) +#if defined(OS_CHROMEOS) || defined(OS_LINUX) || defined(OS_WIN) // TODO(sky,sad): Disabled as it fails due to resize locks with a real // compositor. crbug.com/331924 #define MAYBE_DragDirectlyToSecondWindow DISABLED_DragDirectlyToSecondWindow diff --git a/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc b/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc index ed69780..45e55d6 100644 --- a/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc +++ b/chrome/browser/ui/views/toolbar/browser_action_test_util_views.cc @@ -44,8 +44,8 @@ void BrowserActionTestUtil::InspectPopup(int index) { } bool BrowserActionTestUtil::HasIcon(int index) { - return GetContainer(browser_)->GetBrowserActionViewAt(index)->button()-> - HasIcon(); + return !GetContainer(browser_)->GetBrowserActionViewAt(index)->button()-> + GetImage(views::Button::STATE_NORMAL).isNull(); } gfx::Image BrowserActionTestUtil::GetIcon(int index) { diff --git a/chrome/browser/ui/views/toolbar/browser_action_view.cc b/chrome/browser/ui/views/toolbar/browser_action_view.cc index 6c13116..e277c3c 100644 --- a/chrome/browser/ui/views/toolbar/browser_action_view.cc +++ b/chrome/browser/ui/views/toolbar/browser_action_view.cc @@ -37,14 +37,6 @@ using extensions::Extension; //////////////////////////////////////////////////////////////////////////////// // BrowserActionView -bool BrowserActionView::Delegate::NeedToShowMultipleIconStates() const { - return true; -} - -bool BrowserActionView::Delegate::NeedToShowTooltip() const { - return true; -} - BrowserActionView::BrowserActionView(const Extension* extension, Browser* browser, BrowserActionView::Delegate* delegate) @@ -110,7 +102,7 @@ BrowserActionButton::BrowserActionButton(const Extension* extension, called_registered_extension_command_(false), icon_observer_(NULL) { SetBorder(views::Border::NullBorder()); - set_alignment(TextButton::ALIGN_CENTER); + SetHorizontalAlignment(gfx::ALIGN_CENTER); set_context_menu_controller(this); // No UpdateState() here because View hierarchy not setup yet. Our parent @@ -211,8 +203,6 @@ void BrowserActionButton::UpdateState() { if (tab_id < 0) return; - SetShowMultipleIconStates(delegate_->NeedToShowMultipleIconStates()); - if (!IsEnabled(tab_id)) { SetState(views::CustomButton::STATE_DISABLED); } else { @@ -231,21 +221,23 @@ void BrowserActionButton::UpdateState() { ThemeServiceFactory::GetForProfile(browser_->profile()); gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); - SetIcon(gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); + SetImage(views::Button::STATE_NORMAL, + gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); gfx::ImageSkia bg_h = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_H); - SetHoverIcon(gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_h, icon)); + SetImage(views::Button::STATE_HOVERED, + gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_h, icon)); gfx::ImageSkia bg_p = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION_P); - SetPushedIcon( - gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_p, icon)); + SetImage(views::Button::STATE_PRESSED, + gfx::ImageSkiaOperations::CreateSuperimposedImage(bg_p, icon)); } // If the browser action name is empty, show the extension name instead. std::string title = browser_action()->GetTitle(tab_id); base::string16 name = base::UTF8ToUTF16(title.empty() ? extension()->name() : title); - SetTooltipText(delegate_->NeedToShowTooltip() ? name : base::string16()); + SetTooltipText(name); SetAccessibleName(name); parent()->SchedulePaint(); @@ -320,7 +312,7 @@ bool BrowserActionButton::Activate() { bool BrowserActionButton::OnMousePressed(const ui::MouseEvent& event) { if (!event.IsRightMouseButton()) { return IsPopup() ? MenuButton::OnMousePressed(event) : - TextButton::OnMousePressed(event); + LabelButton::OnMousePressed(event); } if (!views::View::ShouldShowContextMenuOnMousePress()) { @@ -338,7 +330,7 @@ void BrowserActionButton::OnMouseReleased(const ui::MouseEvent& event) { // loss of focus). MenuButton::OnMouseReleased(event); } else { - TextButton::OnMouseReleased(event); + LabelButton::OnMouseReleased(event); } } @@ -346,19 +338,19 @@ void BrowserActionButton::OnMouseExited(const ui::MouseEvent& event) { if (IsPopup() || context_menu_) MenuButton::OnMouseExited(event); else - TextButton::OnMouseExited(event); + LabelButton::OnMouseExited(event); } bool BrowserActionButton::OnKeyReleased(const ui::KeyEvent& event) { return IsPopup() ? MenuButton::OnKeyReleased(event) : - TextButton::OnKeyReleased(event); + LabelButton::OnKeyReleased(event); } void BrowserActionButton::OnGestureEvent(ui::GestureEvent* event) { if (IsPopup()) MenuButton::OnGestureEvent(event); else - TextButton::OnGestureEvent(event); + LabelButton::OnGestureEvent(event); } bool BrowserActionButton::AcceleratorPressed( @@ -391,7 +383,7 @@ gfx::ImageSkia BrowserActionButton::GetIconWithBadge() { } gfx::ImageSkia BrowserActionButton::GetIconForTest() { - return icon(); + return GetImage(views::Button::STATE_NORMAL); } BrowserActionButton::~BrowserActionButton() { diff --git a/chrome/browser/ui/views/toolbar/browser_action_view.h b/chrome/browser/ui/views/toolbar/browser_action_view.h index 983f791..11fa162 100644 --- a/chrome/browser/ui/views/toolbar/browser_action_view.h +++ b/chrome/browser/ui/views/toolbar/browser_action_view.h @@ -54,9 +54,6 @@ class BrowserActionView : public views::View { // Called when a browser action becomes visible/hidden. virtual void OnBrowserActionVisibilityChanged() = 0; - virtual bool NeedToShowMultipleIconStates() const; - virtual bool NeedToShowTooltip() const; - protected: virtual ~Delegate() {} }; diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container.cc b/chrome/browser/ui/views/toolbar/browser_actions_container.cc index 1f7b54a..64a2be4 100644 --- a/chrome/browser/ui/views/toolbar/browser_actions_container.cc +++ b/chrome/browser/ui/views/toolbar/browser_actions_container.cc @@ -40,6 +40,7 @@ #include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/canvas.h" #include "ui/gfx/geometry/rect.h" +#include "ui/views/controls/button/label_button_border.h" #include "ui/views/controls/resize_area.h" #include "ui/views/metrics.h" #include "ui/views/painter.h" @@ -56,6 +57,35 @@ const int kItemSpacing = ToolbarView::kStandardSpacing; // Horizontal spacing before the chevron (if visible). const int kChevronSpacing = kItemSpacing - 2; +// A version of MenuButton with almost empty insets to fit properly on the +// toolbar. +class ChevronMenuButton : public views::MenuButton { + public: + ChevronMenuButton(views::ButtonListener* listener, + const base::string16& text, + views::MenuButtonListener* menu_button_listener, + bool show_menu_marker) + : views::MenuButton(listener, + text, + menu_button_listener, + show_menu_marker) { + } + + virtual ~ChevronMenuButton() {} + + virtual scoped_ptr<views::LabelButtonBorder> CreateDefaultBorder() const + OVERRIDE { + // The chevron resource was designed to not have any insets. + scoped_ptr<views::LabelButtonBorder> border = + views::MenuButton::CreateDefaultBorder(); + border->set_insets(gfx::Insets()); + return border.Pass(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ChevronMenuButton); +}; + } // namespace // static @@ -97,8 +127,7 @@ BrowserActionsContainer::BrowserActionsContainer(Browser* browser, resize_area_ = new views::ResizeArea(this); AddChildView(resize_area_); - chevron_ = new views::MenuButton(NULL, base::string16(), this, false); - chevron_->SetBorder(views::Border::NullBorder()); + chevron_ = new ChevronMenuButton(NULL, base::string16(), this, false); chevron_->EnableCanvasFlippingForRTLUI(true); chevron_->SetAccessibleName( l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); @@ -782,11 +811,8 @@ void BrowserActionsContainer::HighlightModeChanged(bool is_highlighting) { void BrowserActionsContainer::LoadImages() { ui::ThemeProvider* tp = GetThemeProvider(); - chevron_->SetIcon(*tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); - chevron_->SetHoverIcon(*tp->GetImageSkiaNamed( - IDR_BROWSER_ACTIONS_OVERFLOW_H)); - chevron_->SetPushedIcon(*tp->GetImageSkiaNamed( - IDR_BROWSER_ACTIONS_OVERFLOW_P)); + chevron_->SetImage(views::Button::STATE_NORMAL, + *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); diff --git a/chrome/browser/ui/views/toolbar/wrench_toolbar_button.cc b/chrome/browser/ui/views/toolbar/wrench_toolbar_button.cc index c3c5d7d..c096597 100644 --- a/chrome/browser/ui/views/toolbar/wrench_toolbar_button.cc +++ b/chrome/browser/ui/views/toolbar/wrench_toolbar_button.cc @@ -7,14 +7,11 @@ #include "grit/theme_resources.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/theme_provider.h" +#include "ui/views/painter.h" WrenchToolbarButton::WrenchToolbarButton(views::MenuButtonListener* listener) : views::MenuButton(NULL, base::string16(), listener, false) { wrench_icon_painter_.reset(new WrenchIconPainter(this)); - - // Used for sizing only. - ui::ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - SetIcon(*rb.GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)); } WrenchToolbarButton::~WrenchToolbarButton() { @@ -25,6 +22,11 @@ void WrenchToolbarButton::SetSeverity(WrenchIconPainter::Severity severity, wrench_icon_painter_->SetSeverity(severity, animate); } +gfx::Size WrenchToolbarButton::GetPreferredSize() const { + return ResourceBundle::GetSharedInstance(). + GetImageSkiaNamed(IDR_TOOLBAR_BEZEL_HOVER)->size(); +} + void WrenchToolbarButton::OnPaint(gfx::Canvas* canvas) { wrench_icon_painter_->Paint( canvas, GetThemeProvider(), gfx::Rect(size()), GetCurrentBezelType()); diff --git a/chrome/browser/ui/views/toolbar/wrench_toolbar_button.h b/chrome/browser/ui/views/toolbar/wrench_toolbar_button.h index 697164d..a884d75 100644 --- a/chrome/browser/ui/views/toolbar/wrench_toolbar_button.h +++ b/chrome/browser/ui/views/toolbar/wrench_toolbar_button.h @@ -17,13 +17,14 @@ class WrenchToolbarButton : public views::MenuButton, void SetSeverity(WrenchIconPainter::Severity severity, bool animate); - private: // views::MenuButton: + virtual gfx::Size GetPreferredSize() const OVERRIDE; virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; // WrenchIconPainter::Delegate: virtual void ScheduleWrenchIconPaint() OVERRIDE; + private: WrenchIconPainter::BezelType GetCurrentBezelType() const; scoped_ptr<WrenchIconPainter> wrench_icon_painter_; diff --git a/chrome/browser/ui/views/website_settings/permission_selector_view.cc b/chrome/browser/ui/views/website_settings/permission_selector_view.cc index 40fab86..6b44308 100644 --- a/chrome/browser/ui/views/website_settings/permission_selector_view.cc +++ b/chrome/browser/ui/views/website_settings/permission_selector_view.cc @@ -45,9 +45,6 @@ class PermissionMenuButton : public views::MenuButton, bool show_menu_marker); virtual ~PermissionMenuButton(); - // Overridden from views::MenuButton. - virtual gfx::Size GetPreferredSize() const OVERRIDE; - // Overridden from views::TextButton. virtual void SetText(const base::string16& text) OVERRIDE; @@ -75,28 +72,11 @@ PermissionMenuButton::PermissionMenuButton(const base::string16& text, bool show_menu_marker) : MenuButton(NULL, text, this, show_menu_marker), menu_model_(model) { - } PermissionMenuButton::~PermissionMenuButton() { } -gfx::Size PermissionMenuButton::GetPreferredSize() const { - gfx::Insets insets = GetInsets(); - // Scale the button to the current text size. - gfx::Size prefsize(text_size_.width() + insets.width(), - text_size_.height() + insets.height()); - if (max_width_ > 0) - prefsize.set_width(std::min(max_width_, prefsize.width())); - if (show_menu_marker()) { - prefsize.Enlarge(menu_marker()->width() + - views::MenuButton::kMenuMarkerPaddingLeft + - views::MenuButton::kMenuMarkerPaddingRight, - 0); - } - return prefsize; -} - void PermissionMenuButton::SetText(const base::string16& text) { MenuButton::SetText(text); SizeToPreferredSize(); @@ -104,15 +84,15 @@ void PermissionMenuButton::SetText(const base::string16& text) { void PermissionMenuButton::GetAccessibleState(ui::AXViewState* state) { MenuButton::GetAccessibleState(state); - state->value = text(); + state->value = GetText(); } void PermissionMenuButton::OnNativeThemeChanged(const ui::NativeTheme* theme) { - SetEnabledColor(theme->GetSystemColor( + SetTextColor(views::Button::STATE_NORMAL, GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_LabelEnabledColor)); - SetHoverColor(theme->GetSystemColor( + SetTextColor(views::Button::STATE_HOVERED, GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_LabelEnabledColor)); - SetDisabledColor(theme->GetSystemColor( + SetTextColor(views::Button::STATE_DISABLED, GetNativeTheme()->GetSystemColor( ui::NativeTheme::kColorId_LabelDisabledColor)); } diff --git a/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc b/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc index a9c064a..5f2d7f7 100644 --- a/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc +++ b/chrome/browser/ui/views/website_settings/permissions_bubble_view.cc @@ -99,7 +99,7 @@ PermissionCombobox::~PermissionCombobox() {} void PermissionCombobox::GetAccessibleState(ui::AXViewState* state) { MenuButton::GetAccessibleState(state); - state->value = text(); + state->value = GetText(); } void PermissionCombobox::OnMenuButtonClicked(View* source, diff --git a/ui/app_list/views/search_box_view.cc b/ui/app_list/views/search_box_view.cc index a9b65a1..2569942 100644 --- a/ui/app_list/views/search_box_view.cc +++ b/ui/app_list/views/search_box_view.cc @@ -16,6 +16,7 @@ #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" #include "ui/events/event.h" +#include "ui/views/border.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/image_view.h" @@ -57,10 +58,12 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, #if !defined(OS_CHROMEOS) menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); menu_button_->SetBorder(views::Border::NullBorder()); - menu_button_->SetIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); - menu_button_->SetHoverIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); - menu_button_->SetPushedIcon(*rb.GetImageSkiaNamed( - IDR_APP_LIST_TOOLS_PRESSED)); + menu_button_->SetImage(views::Button::STATE_NORMAL, + *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); + menu_button_->SetImage(views::Button::STATE_HOVERED, + *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); + menu_button_->SetImage(views::Button::STATE_PRESSED, + *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED)); AddChildView(menu_button_); #endif diff --git a/ui/message_center/views/notifier_settings_view.cc b/ui/message_center/views/notifier_settings_view.cc index 5a46f48..a282ccb 100644 --- a/ui/message_center/views/notifier_settings_view.cc +++ b/ui/message_center/views/notifier_settings_view.cc @@ -28,6 +28,7 @@ #include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/label_button_border.h" #include "ui/views/controls/button/menu_button.h" +#include "ui/views/controls/button/text_button.h" #include "ui/views/controls/image_view.h" #include "ui/views/controls/label.h" #include "ui/views/controls/link.h" diff --git a/ui/views/button_drag_utils.cc b/ui/views/button_drag_utils.cc index 500c5e0..2c4f25a 100644 --- a/ui/views/button_drag_utils.cc +++ b/ui/views/button_drag_utils.cc @@ -10,6 +10,7 @@ #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/canvas.h" +#include "ui/gfx/geometry/point.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/drag_utils.h" @@ -18,17 +19,25 @@ namespace button_drag_utils { // Maximum width of the link drag image in pixels. -static const int kLinkDragImageMaxWidth = 200; +static const int kLinkDragImageMaxWidth = 150; void SetURLAndDragImage(const GURL& url, const base::string16& title, const gfx::ImageSkia& icon, + const gfx::Point* press_pt, ui::OSExchangeData* data, views::Widget* widget) { DCHECK(url.is_valid() && data); - data->SetURL(url, title); + SetDragImage(url, title, icon, press_pt, data, widget); +} +void SetDragImage(const GURL& url, + const base::string16& title, + const gfx::ImageSkia& icon, + const gfx::Point* press_pt, + ui::OSExchangeData* data, + views::Widget* widget) { // Create a button to render the drag image for us. views::TextButton button(NULL, title.empty() ? base::UTF8ToUTF16(url.spec()) @@ -43,14 +52,17 @@ void SetURLAndDragImage(const GURL& url, gfx::Size prefsize = button.GetPreferredSize(); button.SetBounds(0, 0, prefsize.width(), prefsize.height()); + gfx::Vector2d press_point; + if (press_pt) + press_point = press_pt->OffsetFromOrigin(); + else + press_point = gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2); + // Render the image. scoped_ptr<gfx::Canvas> canvas( views::GetCanvasForDragImage(widget, prefsize)); button.PaintButton(canvas.get(), views::TextButton::PB_FOR_DRAG); - drag_utils::SetDragImageOnDataObject( - *canvas, - gfx::Vector2d(prefsize.width() / 2, prefsize.height() / 2), - data); + drag_utils::SetDragImageOnDataObject(*canvas, press_point, data); } } // namespace button_drag_utils diff --git a/ui/views/button_drag_utils.h b/ui/views/button_drag_utils.h index 0570ff2..8f1a7ee 100644 --- a/ui/views/button_drag_utils.h +++ b/ui/views/button_drag_utils.h @@ -12,6 +12,7 @@ class GURL; namespace gfx { class ImageSkia; +class Point; } namespace ui { @@ -25,13 +26,23 @@ class Widget; namespace button_drag_utils { // Sets url and title on data as well as setting a suitable image for dragging. -// The image looks like that of the bookmark buttons. +// The image looks like that of the bookmark buttons. |press_pt| is optional +// offset; otherwise, it centers the drag image. VIEWS_EXPORT void SetURLAndDragImage(const GURL& url, const base::string16& title, const gfx::ImageSkia& icon, + const gfx::Point* press_pt, ui::OSExchangeData* data, views::Widget* widget); +// As above, but only sets the image. +VIEWS_EXPORT void SetDragImage(const GURL& url, + const base::string16& title, + const gfx::ImageSkia& icon, + const gfx::Point* press_pt, + ui::OSExchangeData* data, + views::Widget* widget); + } // namespace drag_utils #endif // UI_VIEWS_BUTTON_DRAG_UTILS_H_ diff --git a/ui/views/controls/button/custom_button.h b/ui/views/controls/button/custom_button.h index 930cc92..4614a5c 100644 --- a/ui/views/controls/button/custom_button.h +++ b/ui/views/controls/button/custom_button.h @@ -18,8 +18,8 @@ namespace views { class CustomButtonStateChangedDelegate; -// A button with custom rendering. The common base class of ImageButton and -// TextButton. +// A button with custom rendering. The common base class of ImageButton, +// LabelButton and TextButton. // Note that this type of button is not focusable by default and will not be // part of the focus chain. Call SetFocusable(true) to make it part of the // focus chain. diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc index 4cddedf..3f5196b 100644 --- a/ui/views/controls/button/label_button.cc +++ b/ui/views/controls/button/label_button.cc @@ -100,6 +100,10 @@ void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { explicitly_set_colors_[for_state] = true; } +void LabelButton::SetHaloColor(SkColor color) { + label_->set_halo_color(color); +} + bool LabelButton::GetTextMultiLine() const { return label_->is_multi_line(); } @@ -222,7 +226,7 @@ void LabelButton::Layout() { adjusted_alignment = (adjusted_alignment == gfx::ALIGN_LEFT) ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT; - gfx::Rect child_area(GetLocalBounds()); + gfx::Rect child_area(GetChildAreaBounds()); child_area.Inset(GetInsets()); gfx::Size image_size(image_->GetPreferredSize()); @@ -275,6 +279,10 @@ void LabelButton::SetBorder(scoped_ptr<Border> border) { View::SetBorder(border.Pass()); } +gfx::Rect LabelButton::GetChildAreaBounds() { + return GetLocalBounds(); +} + void LabelButton::OnPaint(gfx::Canvas* canvas) { View::OnPaint(canvas); Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); @@ -366,7 +374,7 @@ void LabelButton::UpdateThemedBorder() { views::LinuxUI* linux_ui = views::LinuxUI::instance(); if (linux_ui) { SetBorder(linux_ui->CreateNativeBorder( - this, label_button_border.PassAs<Border>())); + this, label_button_border.Pass())); } else #endif { diff --git a/ui/views/controls/button/label_button.h b/ui/views/controls/button/label_button.h index 8e13ffc..425f5c0 100644 --- a/ui/views/controls/button/label_button.h +++ b/ui/views/controls/button/label_button.h @@ -38,11 +38,14 @@ class VIEWS_EXPORT LabelButton : public CustomButton, // Get or set the text shown on the button. const base::string16& GetText() const; - void SetText(const base::string16& text); + virtual void SetText(const base::string16& text); // Set the text color shown for the specified button state. void SetTextColor(ButtonState for_state, SkColor color); + // Sets a halo color on the label. + void SetHaloColor(SkColor color); + // Get or set the text's multi-line property to break on '\n', etc. bool GetTextMultiLine() const; void SetTextMultiLine(bool text_multi_line); @@ -72,6 +75,7 @@ class VIEWS_EXPORT LabelButton : public CustomButton, void SetStyle(ButtonStyle style); void SetFocusPainter(scoped_ptr<Painter> focus_painter); + Painter* focus_painter() { return focus_painter_.get(); } // View: virtual void SetBorder(scoped_ptr<Border> border) OVERRIDE; @@ -83,6 +87,10 @@ class VIEWS_EXPORT LabelButton : public CustomButton, ImageView* image() const { return image_; } Label* label() const { return label_; } + // Returns the available area for the label and image. Subclasses can change + // these bounds if they need room to do manual painting. + virtual gfx::Rect GetChildAreaBounds(); + // View: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual void OnFocus() OVERRIDE; diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc index dcfed7e..29271ce 100644 --- a/ui/views/controls/button/menu_button.cc +++ b/ui/views/controls/button/menu_button.cc @@ -16,6 +16,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" #include "ui/gfx/screen.h" +#include "ui/gfx/text_constants.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/mouse_constants.h" @@ -46,7 +47,7 @@ MenuButton::MenuButton(ButtonListener* listener, const base::string16& text, MenuButtonListener* menu_button_listener, bool show_menu_marker) - : TextButton(listener, text), + : LabelButton(listener, text), menu_visible_(false), menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), listener_(menu_button_listener), @@ -54,7 +55,7 @@ MenuButton::MenuButton(ButtonListener* listener, menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( IDR_MENU_DROPARROW).ToImageSkia()), destroyed_flag_(NULL) { - set_alignment(TextButton::ALIGN_LEFT); + SetHorizontalAlignment(gfx::ALIGN_LEFT); } MenuButton::~MenuButton() { @@ -133,8 +134,8 @@ bool MenuButton::Activate() { return true; } -void MenuButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { - TextButton::PaintButton(canvas, mode); +void MenuButton::OnPaint(gfx::Canvas* canvas) { + LabelButton::OnPaint(canvas); if (show_menu_marker_) PaintMenuMarker(canvas); @@ -147,7 +148,7 @@ void MenuButton::PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) { //////////////////////////////////////////////////////////////////////////////// gfx::Size MenuButton::GetPreferredSize() const { - gfx::Size prefsize = TextButton::GetPreferredSize(); + gfx::Size prefsize = LabelButton::GetPreferredSize(); if (show_menu_marker_) { prefsize.Enlarge(menu_marker_->width() + kMenuMarkerPaddingLeft + kMenuMarkerPaddingRight, @@ -186,7 +187,7 @@ void MenuButton::OnMouseReleased(const ui::MouseEvent& event) { HitTestPoint(event.location())) { Activate(); } else { - TextButton::OnMouseReleased(event); + LabelButton::OnMouseReleased(event); } } @@ -209,7 +210,7 @@ void MenuButton::OnGestureEvent(ui::GestureEvent* event) { // the gesture event here. return; } - TextButton::OnGestureEvent(event); + LabelButton::OnGestureEvent(event); } bool MenuButton::OnKeyPressed(const ui::KeyEvent& event) { @@ -265,6 +266,17 @@ void MenuButton::PaintMenuMarker(gfx::Canvas* canvas) { canvas->DrawImageInt(*menu_marker_, arrow_bounds.x(), arrow_bounds.y()); } +gfx::Rect MenuButton::GetChildAreaBounds() { + gfx::Size s = size(); + + if (show_menu_marker_) { + s.set_width(s.width() - menu_marker_->width() - kMenuMarkerPaddingLeft - + kMenuMarkerPaddingRight); + } + + return gfx::Rect(s); +} + int MenuButton::GetMaximumScreenXCoordinate() { if (!GetWidget()) { NOTREACHED(); diff --git a/ui/views/controls/button/menu_button.h b/ui/views/controls/button/menu_button.h index 1ca6de0..257d2f6 100644 --- a/ui/views/controls/button/menu_button.h +++ b/ui/views/controls/button/menu_button.h @@ -10,7 +10,7 @@ #include "base/strings/string16.h" #include "base/time/time.h" #include "ui/views/background.h" -#include "ui/views/controls/button/text_button.h" +#include "ui/views/controls/button/label_button.h" namespace views { @@ -23,7 +23,7 @@ class MenuButtonListener; // A button that shows a menu when the left mouse button is pushed // //////////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT MenuButton : public TextButton { +class VIEWS_EXPORT MenuButton : public LabelButton { public: static const char kViewClassName[]; @@ -50,12 +50,10 @@ class VIEWS_EXPORT MenuButton : public TextButton { // Activate the button (called when the button is pressed). virtual bool Activate(); - // Overridden from TextButton for the potential use of a drop marker. - virtual void PaintButton(gfx::Canvas* canvas, PaintButtonMode mode) OVERRIDE; - // Overridden from View: virtual gfx::Size GetPreferredSize() const OVERRIDE; virtual const char* GetClassName() const OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE; virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; @@ -68,6 +66,9 @@ class VIEWS_EXPORT MenuButton : public TextButton { // Paint the menu marker image. void PaintMenuMarker(gfx::Canvas* canvas); + // Overridden from LabelButton: + virtual gfx::Rect GetChildAreaBounds() OVERRIDE; + // True if the menu is currently visible. bool menu_visible_; diff --git a/ui/views/controls/button/radio_button.h b/ui/views/controls/button/radio_button.h index abffd60..edbb2c6 100644 --- a/ui/views/controls/button/radio_button.h +++ b/ui/views/controls/button/radio_button.h @@ -30,7 +30,7 @@ class VIEWS_EXPORT RadioButton : public Checkbox { // Overridden from Button: virtual void NotifyClick(const ui::Event& event) OVERRIDE; - // Overridden from TextButtonBase: + // Overridden from LabelButton: virtual ui::NativeTheme::Part GetThemePart() const OVERRIDE; // Overridden from Checkbox: diff --git a/ui/views/linux_ui/linux_ui.h b/ui/views/linux_ui/linux_ui.h index 504de81..b5466f5 100644 --- a/ui/views/linux_ui/linux_ui.h +++ b/ui/views/linux_ui/linux_ui.h @@ -35,6 +35,7 @@ class NativeTheme; namespace views { class Border; class LabelButton; +class LabelButtonBorder; class View; class WindowButtonOrderObserver; @@ -125,7 +126,7 @@ class VIEWS_EXPORT LinuxUI : public ui::LinuxInputMethodContextFactory, // Builds a Border which paints the native button style. virtual scoped_ptr<Border> CreateNativeBorder( views::LabelButton* owning_button, - scoped_ptr<views::Border> border) = 0; + scoped_ptr<views::LabelButtonBorder> border) = 0; // Notifies the observer about changes about how window buttons should be // laid out. If the order is anything other than the default min,max,close on |