summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 23:25:13 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-16 23:25:13 +0000
commit48c8fa63122510b2c51c6608a93b30e94192e679 (patch)
treedc22b80b2f4103d865cbfe47c6f4dc52c8595985
parent9ea0ea99d3a1140a17712a286414d387eddbe8ac (diff)
downloadchromium_src-48c8fa63122510b2c51c6608a93b30e94192e679.zip
chromium_src-48c8fa63122510b2c51c6608a93b30e94192e679.tar.gz
chromium_src-48c8fa63122510b2c51c6608a93b30e94192e679.tar.bz2
Rework the Button API to be saner in preparation for NativeControl rejiggering.BaseButton->Button, CustomButtonButton->ImageButtonToggleButton->ToggleImageButtonRemoving SetListener (buttons take listener through ctor)Tidy up source files. No functionality changes, just naming and organization.Look at the button classes first, then everything else.
Review URL: http://codereview.chromium.org/46096 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11799 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/drag_utils.cc3
-rw-r--r--chrome/browser/views/about_ipc_dialog.cc11
-rw-r--r--chrome/browser/views/about_ipc_dialog.h8
-rw-r--r--chrome/browser/views/about_network_dialog.cc11
-rw-r--r--chrome/browser/views/about_network_dialog.h8
-rw-r--r--chrome/browser/views/blocked_popup_container.cc17
-rw-r--r--chrome/browser/views/blocked_popup_container.h14
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc34
-rw-r--r--chrome/browser/views/bookmark_bar_view.h6
-rw-r--r--chrome/browser/views/bookmark_bar_view_test.cc6
-rw-r--r--chrome/browser/views/bookmark_manager_view.cc4
-rw-r--r--chrome/browser/views/constrained_window_impl.cc28
-rw-r--r--chrome/browser/views/download_shelf_view.cc13
-rw-r--r--chrome/browser/views/download_shelf_view.h7
-rw-r--r--chrome/browser/views/find_bar_view.cc39
-rw-r--r--chrome/browser/views/find_bar_view.h13
-rw-r--r--chrome/browser/views/frame/glass_browser_frame_view.h1
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.cc63
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.h15
-rw-r--r--chrome/browser/views/go_button.cc107
-rw-r--r--chrome/browser/views/go_button.h16
-rw-r--r--chrome/browser/views/infobars/infobars.cc15
-rw-r--r--chrome/browser/views/infobars/infobars.h13
-rw-r--r--chrome/browser/views/tabs/tab.cc5
-rw-r--r--chrome/browser/views/tabs/tab.h8
-rw-r--r--chrome/browser/views/tabs/tab_renderer.cc20
-rw-r--r--chrome/browser/views/tabs/tab_renderer.h10
-rw-r--r--chrome/browser/views/tabs/tab_strip.cc17
-rw-r--r--chrome/browser/views/tabs/tab_strip.h10
-rw-r--r--chrome/browser/views/toolbar_star_toggle.cc16
-rw-r--r--chrome/browser/views/toolbar_star_toggle.h8
-rw-r--r--chrome/browser/views/toolbar_view.cc98
-rw-r--r--chrome/browser/views/toolbar_view.h12
-rw-r--r--chrome/views/base_button.h185
-rw-r--r--chrome/views/bitmap_scroll_bar.cc49
-rw-r--r--chrome/views/bitmap_scroll_bar.h18
-rw-r--r--chrome/views/button.cc198
-rw-r--r--chrome/views/button.h143
-rw-r--r--chrome/views/button_dropdown.cc17
-rw-r--r--chrome/views/button_dropdown.h6
-rw-r--r--chrome/views/custom_button.cc (renamed from chrome/views/base_button.cc)215
-rw-r--r--chrome/views/custom_button.h94
-rw-r--r--chrome/views/custom_frame_view.cc62
-rw-r--r--chrome/views/custom_frame_view.h18
-rw-r--r--chrome/views/image_button.cc157
-rw-r--r--chrome/views/image_button.h101
-rw-r--r--chrome/views/menu_button.cc11
-rw-r--r--chrome/views/menu_button.h3
-rw-r--r--chrome/views/text_button.cc76
-rw-r--r--chrome/views/text_button.h62
-rw-r--r--chrome/views/views.vcproj24
51 files changed, 1015 insertions, 1080 deletions
diff --git a/chrome/browser/drag_utils.cc b/chrome/browser/drag_utils.cc
index 4383411..9fbb0bc 100644
--- a/chrome/browser/drag_utils.cc
+++ b/chrome/browser/drag_utils.cc
@@ -91,7 +91,8 @@ void SetURLAndDragImage(const GURL& url,
data->SetURL(url, title);
// Create a button to render the drag image for us.
- views::TextButton button(title.empty() ? UTF8ToWide(url.spec()) : title);
+ views::TextButton button(NULL,
+ title.empty() ? UTF8ToWide(url.spec()) : title);
button.set_max_width(BookmarkBarView::kMaxButtonWidth);
if (icon.isNull()) {
button.SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(
diff --git a/chrome/browser/views/about_ipc_dialog.cc b/chrome/browser/views/about_ipc_dialog.cc
index 6e9848c..a614f86 100644
--- a/chrome/browser/views/about_ipc_dialog.cc
+++ b/chrome/browser/views/about_ipc_dialog.cc
@@ -298,12 +298,9 @@ void AboutIPCDialog::SetupControls() {
views::GridLayout* layout = CreatePanelGridLayout(this);
SetLayoutManager(layout);
- track_toggle_ = new views::TextButton(kStartTrackingLabel);
- track_toggle_->SetListener(this, 1);
- clear_button_ = new views::TextButton(kClearLabel);
- clear_button_->SetListener(this, 2);
- filter_button_ = new views::TextButton(kFilterLabel);
- filter_button_->SetListener(this, 3);
+ track_toggle_ = new views::TextButton(this, kStartTrackingLabel);
+ clear_button_ = new views::TextButton(this, kClearLabel);
+ filter_button_ = new views::TextButton(this, kFilterLabel);
table_ = new views::HWNDView();
@@ -419,7 +416,7 @@ bool AboutIPCDialog::CanResize() const {
return true;
}
-void AboutIPCDialog::ButtonPressed(views::BaseButton* button) {
+void AboutIPCDialog::ButtonPressed(views::Button* button) {
if (button == track_toggle_) {
if (tracking_) {
track_toggle_->SetText(kStartTrackingLabel);
diff --git a/chrome/browser/views/about_ipc_dialog.h b/chrome/browser/views/about_ipc_dialog.h
index 0aa6b06..15c41c2 100644
--- a/chrome/browser/views/about_ipc_dialog.h
+++ b/chrome/browser/views/about_ipc_dialog.h
@@ -13,7 +13,7 @@
#include "base/singleton.h"
#include "chrome/common/ipc_logging.h"
-#include "chrome/views/base_button.h"
+#include "chrome/views/button.h"
#include "chrome/views/dialog_delegate.h"
#include "chrome/views/table_view.h"
@@ -26,7 +26,7 @@ class HWNDView;
} // namespace views
class AboutIPCDialog : public views::DialogDelegate,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public IPC::Logging::Consumer,
public views::View {
public:
@@ -57,8 +57,8 @@ class AboutIPCDialog : public views::DialogDelegate,
// views::WindowDelegate (via view::DialogDelegate).
virtual bool CanResize() const;
- // views::BaseButton::ButtonListener.
- virtual void ButtonPressed(views::BaseButton* button);
+ // views::ButtonListener.
+ virtual void ButtonPressed(views::Button* button);
CListViewCtrl message_list_;
diff --git a/chrome/browser/views/about_network_dialog.cc b/chrome/browser/views/about_network_dialog.cc
index 9631a3e..7028d2b 100644
--- a/chrome/browser/views/about_network_dialog.cc
+++ b/chrome/browser/views/about_network_dialog.cc
@@ -295,12 +295,9 @@ void AboutNetworkDialog::SetupControls() {
views::GridLayout* layout = CreatePanelGridLayout(this);
SetLayoutManager(layout);
- track_toggle_ = new views::TextButton(kStartTrackingLabel);
- track_toggle_->SetListener(this, 1);
- show_button_ = new views::TextButton(kShowCurrentLabel);
- show_button_->SetListener(this, 2);
- clear_button_ = new views::TextButton(kClearLabel);
- clear_button_->SetListener(this, 3);
+ track_toggle_ = new views::TextButton(this, kStartTrackingLabel);
+ show_button_ = new views::TextButton(this, kShowCurrentLabel);
+ clear_button_ = new views::TextButton(this, kClearLabel);
text_field_ = new views::TextField(static_cast<views::TextField::StyleFlags>(
views::TextField::STYLE_MULTILINE));
@@ -358,7 +355,7 @@ bool AboutNetworkDialog::CanResize() const {
return true;
}
-void AboutNetworkDialog::ButtonPressed(views::BaseButton* button) {
+void AboutNetworkDialog::ButtonPressed(views::Button* button) {
if (button == track_toggle_) {
if (tracking_) {
track_toggle_->SetText(kStartTrackingLabel);
diff --git a/chrome/browser/views/about_network_dialog.h b/chrome/browser/views/about_network_dialog.h
index e9fe81d..768cd97 100644
--- a/chrome/browser/views/about_network_dialog.h
+++ b/chrome/browser/views/about_network_dialog.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_VIEWS_ABOUT_NETWORK_DIALOG_H_
#include "base/singleton.h"
-#include "chrome/views/base_button.h"
+#include "chrome/views/button.h"
#include "chrome/views/dialog_delegate.h"
namespace views {
@@ -15,7 +15,7 @@ class TextField;
} // namespace views
class AboutNetworkDialog : public views::DialogDelegate,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public views::View {
public:
// This dialog is a singleton. If the dialog is already opened, it won't do
@@ -47,8 +47,8 @@ class AboutNetworkDialog : public views::DialogDelegate,
// views::WindowDelegate (via view::DialogDelegate).
virtual bool CanResize() const;
- // views::BaseButton::ButtonListener.
- virtual void ButtonPressed(views::BaseButton* button);
+ // views::ButtonListener.
+ virtual void ButtonPressed(views::Button* button);
views::TextButton* track_toggle_;
views::TextButton* show_button_;
diff --git a/chrome/browser/views/blocked_popup_container.cc b/chrome/browser/views/blocked_popup_container.cc
index bd513cf..8ae1801 100644
--- a/chrome/browser/views/blocked_popup_container.cc
+++ b/chrome/browser/views/blocked_popup_container.cc
@@ -22,7 +22,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/views/background.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/menu_button.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -90,23 +90,22 @@ BlockedPopupContainerView::BlockedPopupContainerView(
// Create a button with a multidigit number to reserve space.
popup_count_label_ = new views::MenuButton(
+ this,
l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT,
IntToWString(kWidestNumber)),
NULL, true);
- popup_count_label_->SetTextAlignment(views::TextButton::ALIGN_CENTER);
- popup_count_label_->SetListener(this, 1);
+ popup_count_label_->set_alignment(views::TextButton::ALIGN_CENTER);
AddChildView(popup_count_label_);
// For now, we steal the Find close button, since it looks OK.
- close_button_ = new views::Button();
+ close_button_ = new views::ImageButton(this);
close_button_->SetFocusable(true);
- close_button_->SetImage(views::Button::BS_NORMAL,
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::Button::BS_HOT,
+ close_button_->SetImage(views::CustomButton::BS_HOT,
resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::Button::BS_PUSHED,
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
resource_bundle.GetBitmapNamed(IDR_CLOSE_BAR_P));
- close_button_->SetListener(this, 0);
AddChildView(close_button_);
set_background(views::Background::CreateStandardPanelBackground());
@@ -174,7 +173,7 @@ gfx::Size BlockedPopupContainerView::GetPreferredSize() {
return preferred_size;
}
-void BlockedPopupContainerView::ButtonPressed(views::BaseButton* sender) {
+void BlockedPopupContainerView::ButtonPressed(views::Button* sender) {
if (sender == popup_count_label_) {
launch_menu_.reset(new Menu(this, Menu::TOPLEFT,
container_->GetNativeView()));
diff --git a/chrome/browser/views/blocked_popup_container.h b/chrome/browser/views/blocked_popup_container.h
index 3b012a8..215246b 100644
--- a/chrome/browser/views/blocked_popup_container.h
+++ b/chrome/browser/views/blocked_popup_container.h
@@ -18,7 +18,7 @@
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/common/animation.h"
#include "chrome/common/pref_member.h"
-#include "chrome/views/base_button.h"
+#include "chrome/views/button.h"
#include "chrome/views/menu.h"
#include "chrome/views/view.h"
#include "chrome/views/widget_win.h"
@@ -29,7 +29,7 @@ class TabContents;
class TextButton;
namespace views {
-class Button;
+class ImageButton;
class Menu;
class MenuButton;
}
@@ -37,7 +37,7 @@ class MenuButton;
// The view presented to the user notifying them of the number of popups
// blocked. This view should only be used inside of BlockedPopupContainer.
class BlockedPopupContainerView : public views::View,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public Menu::Delegate {
public:
explicit BlockedPopupContainerView(BlockedPopupContainer* container);
@@ -55,10 +55,8 @@ class BlockedPopupContainerView : public views::View,
// Gets the desired size of the popup notification.
virtual gfx::Size GetPreferredSize();
- // Overridden from views::ButtonListener::ButtonPressed:
-
- // Called when either the menu button or close button is pressed.
- virtual void ButtonPressed(views::BaseButton* sender);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
// Overridden from Menu::Delegate:
@@ -75,7 +73,7 @@ class BlockedPopupContainerView : public views::View,
views::MenuButton* popup_count_label_;
// Our "X" button.
- views::Button* close_button_;
+ views::ImageButton* close_button_;
// Popup menu shown to user.
scoped_ptr<Menu> launch_menu_;
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 5c95b08..5cf84f0 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -41,7 +41,7 @@
#include "grit/theme_resources.h"
#include "skia/ext/skia_utils.h"
-using views::BaseButton;
+using views::CustomButton;
using views::DropTargetEvent;
using views::MenuButton;
using views::MenuItemView;
@@ -190,10 +190,11 @@ static std::wstring CreateToolTipForURLAndTitle(const gfx::Point& screen_loc,
class BookmarkButton : public views::TextButton {
public:
- BookmarkButton(const GURL& url,
+ BookmarkButton(views::ButtonListener* listener,
+ const GURL& url,
const std::wstring& title,
Profile* profile)
- : TextButton(title),
+ : TextButton(listener, title),
url_(url),
profile_(profile) {
show_animation_.reset(new SlideAnimation(this));
@@ -210,7 +211,7 @@ class BookmarkButton : public views::TextButton {
gfx::Point location(x, y);
ConvertPointToScreen(this, &location);
*tooltip = CreateToolTipForURLAndTitle(
- gfx::Point(location.x(), location.y()), url_, GetText(),
+ gfx::Point(location.x(), location.y()), url_, text(),
profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
return !tooltip->empty();
}
@@ -257,10 +258,11 @@ class BookmarkButton : public views::TextButton {
// button.
class BookmarkFolderButton : public views::MenuButton {
public:
- BookmarkFolderButton(const std::wstring& title,
+ BookmarkFolderButton(views::ButtonListener* listener,
+ const std::wstring& title,
views::ViewMenuDelegate* menu_delegate,
bool show_menu_marker)
- : MenuButton(title, menu_delegate, show_menu_marker) {
+ : MenuButton(listener, title, menu_delegate, show_menu_marker) {
show_animation_.reset(new SlideAnimation(this));
if (BookmarkBarView::testing_) {
// For some reason during testing the events generated by animating
@@ -966,15 +968,16 @@ void BookmarkBarView::Init() {
MenuButton* BookmarkBarView::CreateOtherBookmarkedButton() {
MenuButton* button = new BookmarkFolderButton(
- l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this, false);
+ this, l10n_util::GetString(IDS_BOOMARK_BAR_OTHER_BOOKMARKED), this,
+ false);
button->SetIcon(GetGroupIcon());
button->SetContextMenuController(this);
- button->SetListener(this, kOtherFolderButtonTag);
+ button->set_tag(kOtherFolderButtonTag);
return button;
}
MenuButton* BookmarkBarView::CreateOverflowButton() {
- MenuButton* button = new MenuButton(std::wstring(), this, false);
+ MenuButton* button = new MenuButton(NULL, std::wstring(), this, false);
button->SetIcon(*ResourceBundle::GetSharedInstance().
GetBitmapNamed(IDR_BOOKMARK_BAR_CHEVRONS));
@@ -1240,9 +1243,9 @@ void BookmarkBarView::RunMenu(views::View* view,
anchor_point, false);
}
-void BookmarkBarView::ButtonPressed(views::BaseButton* sender) {
+void BookmarkBarView::ButtonPressed(views::Button* sender) {
BookmarkNode* node;
- if (sender->GetTag() == kOtherFolderButtonTag) {
+ if (sender->tag() == kOtherFolderButtonTag) {
node = model_->other_node();
} else {
int index = GetChildIndex(sender);
@@ -1302,17 +1305,16 @@ void BookmarkBarView::ShowContextMenu(View* source,
views::View* BookmarkBarView::CreateBookmarkButton(BookmarkNode* node) {
if (node->is_url()) {
- BookmarkButton* button = new BookmarkButton(node->GetURL(),
+ BookmarkButton* button = new BookmarkButton(this,
+ node->GetURL(),
node->GetTitle(),
GetProfile());
- button->SetListener(this, 0);
ConfigureButton(node, button);
return button;
} else {
views::MenuButton* button =
- new BookmarkFolderButton(node->GetTitle(), this, false);
+ new BookmarkFolderButton(this, node->GetTitle(), this, false);
button->SetIcon(GetGroupIcon());
- button->SetListener(this, 0);
ConfigureButton(node, button);
return button;
}
@@ -1643,7 +1645,7 @@ void BookmarkBarView::StartThrobbing() {
// Node is hidden, animate the overflow button.
throbbing_view_ = overflow_button_;
} else {
- throbbing_view_ = static_cast<BaseButton*>(GetChildViewAt(index));
+ throbbing_view_ = static_cast<CustomButton*>(GetChildViewAt(index));
}
} else {
throbbing_view_ = other_bookmarked_button_;
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index 8b42251..14d7c81 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -40,7 +40,7 @@ class MenuItemView;
class BookmarkBarView : public views::View,
public BookmarkModelObserver,
public views::ViewMenuDelegate,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public Menu::Delegate,
public NotificationObserver,
public views::ContextMenuController,
@@ -307,7 +307,7 @@ class BookmarkBarView : public views::View,
// Invoked when a star entry corresponding to a URL on the bookmark bar is
// pressed. Forwards to the PageNavigator to open the URL.
- virtual void ButtonPressed(views::BaseButton* sender);
+ virtual void ButtonPressed(views::Button* sender);
// Invoked for this View, one of the buttons or the 'other' button. Shows the
// appropriate context menu.
@@ -431,7 +431,7 @@ class BookmarkBarView : public views::View,
// If the bookmark bubble is showing, this is the visible ancestor of the URL.
// The visible ancestor is either the other_bookmarked_button_,
// overflow_button_ or a button on the bar.
- views::BaseButton* throbbing_view_;
+ views::CustomButton* throbbing_view_;
// How many extension toolstrips we have showing in the toolbar.
int num_extension_toolstrips_;
diff --git a/chrome/browser/views/bookmark_bar_view_test.cc b/chrome/browser/views/bookmark_bar_view_test.cc
index 2a4740f..8c5294a 100644
--- a/chrome/browser/views/bookmark_bar_view_test.cc
+++ b/chrome/browser/views/bookmark_bar_view_test.cc
@@ -190,7 +190,7 @@ class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase {
// Button should be depressed.
views::TextButton* button = bb_view_->GetBookmarkButton(0);
- ASSERT_TRUE(button->GetState() == views::BaseButton::BS_PUSHED);
+ ASSERT_TRUE(button->state() == views::CustomButton::BS_PUSHED);
// Click on the 2nd menu item (A URL).
ASSERT_TRUE(menu->GetSubmenu());
@@ -210,7 +210,7 @@ class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase {
// Make sure button is no longer pushed.
views::TextButton* button = bb_view_->GetBookmarkButton(0);
- ASSERT_TRUE(button->GetState() == views::BaseButton::BS_NORMAL);
+ ASSERT_TRUE(button->state() == views::CustomButton::BS_NORMAL);
views::MenuItemView* menu = bb_view_->GetMenu();
ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing());
@@ -258,7 +258,7 @@ class BookmarkBarViewTest2 : public BookmarkBarViewEventTestBase {
// Make sure button is no longer pushed.
views::TextButton* button = bb_view_->GetBookmarkButton(0);
- ASSERT_TRUE(button->GetState() == views::BaseButton::BS_NORMAL);
+ ASSERT_TRUE(button->state() == views::CustomButton::BS_NORMAL);
window_->Activate();
diff --git a/chrome/browser/views/bookmark_manager_view.cc b/chrome/browser/views/bookmark_manager_view.cc
index a0de947..8701f2c 100644
--- a/chrome/browser/views/bookmark_manager_view.cc
+++ b/chrome/browser/views/bookmark_manager_view.cc
@@ -151,12 +151,12 @@ BookmarkManagerView::BookmarkManagerView(Profile* profile)
tree_view_->SetContextMenuController(this);
views::MenuButton* organize_menu_button = new views::MenuButton(
- l10n_util::GetString(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU),
+ NULL, l10n_util::GetString(IDS_BOOKMARK_MANAGER_ORGANIZE_MENU),
this, true);
organize_menu_button->SetID(kOrganizeMenuButtonID);
views::MenuButton* tools_menu_button = new views::MenuButton(
- l10n_util::GetString(IDS_BOOKMARK_MANAGER_TOOLS_MENU),
+ NULL, l10n_util::GetString(IDS_BOOKMARK_MANAGER_TOOLS_MENU),
this, true);
tools_menu_button->SetID(kToolsMenuButtonID);
diff --git a/chrome/browser/views/constrained_window_impl.cc b/chrome/browser/views/constrained_window_impl.cc
index 8ffd4e0..ba436f0 100644
--- a/chrome/browser/views/constrained_window_impl.cc
+++ b/chrome/browser/views/constrained_window_impl.cc
@@ -25,7 +25,7 @@
#include "chrome/common/pref_service.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/client_view.h"
#include "chrome/views/focus_manager.h"
#include "chrome/views/hwnd_view.h"
@@ -188,7 +188,7 @@ SkBitmap* OTRWindowResources::bitmaps_[];
class ConstrainedWindowFrameView
: public views::NonClientFrameView,
- public views::BaseButton::ButtonListener {
+ public views::ButtonListener {
public:
explicit ConstrainedWindowFrameView(ConstrainedWindowImpl* container);
virtual ~ConstrainedWindowFrameView();
@@ -211,8 +211,8 @@ class ConstrainedWindowFrameView
virtual void Layout();
virtual void ThemeChanged();
- // Overridden from views::BaseButton::ButtonListener:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
private:
// Returns the thickness of the border that makes up the window frame edges.
@@ -259,7 +259,7 @@ class ConstrainedWindowFrameView
gfx::Rect title_bounds_;
- views::Button* close_button_;
+ views::ImageButton* close_button_;
// The bounds of the ClientView.
gfx::Rect client_view_bounds_;
@@ -309,19 +309,18 @@ ConstrainedWindowFrameView::ConstrainedWindowFrameView(
ConstrainedWindowImpl* container)
: NonClientFrameView(),
container_(container),
- close_button_(new views::Button) {
+ close_button_(new views::ImageButton(this)) {
InitClass();
InitWindowResources();
- close_button_->SetImage(views::Button::BS_NORMAL,
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON));
- close_button_->SetImage(views::Button::BS_HOT,
+ close_button_->SetImage(views::CustomButton::BS_HOT,
resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H));
- close_button_->SetImage(views::Button::BS_PUSHED,
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P));
- close_button_->SetImageAlignment(views::Button::ALIGN_CENTER,
- views::Button::ALIGN_MIDDLE);
- close_button_->SetListener(this, 0);
+ close_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
+ views::ImageButton::ALIGN_MIDDLE);
AddChildView(close_button_);
}
@@ -430,10 +429,9 @@ void ConstrainedWindowFrameView::ThemeChanged() {
}
////////////////////////////////////////////////////////////////////////////////
-// ConstrainedWindowFrameView, views::BaseButton::Button
-// implementation:
+// ConstrainedWindowFrameView, views::ButtonListener implementation:
-void ConstrainedWindowFrameView::ButtonPressed(views::BaseButton* sender) {
+void ConstrainedWindowFrameView::ButtonPressed(views::Button* sender) {
if (sender == close_button_)
container_->ExecuteSystemMenuCommand(SC_CLOSE);
}
diff --git a/chrome/browser/views/download_shelf_view.cc b/chrome/browser/views/download_shelf_view.cc
index f9081e8..21cd338 100644
--- a/chrome/browser/views/download_shelf_view.cc
+++ b/chrome/browser/views/download_shelf_view.cc
@@ -16,7 +16,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/views/background.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/image_view.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -93,14 +93,13 @@ void DownloadShelfView::Init() {
show_all_view_->SetController(this);
AddChildView(show_all_view_);
- close_button_ = new views::Button();
- close_button_->SetImage(views::Button::BS_NORMAL,
+ close_button_ = new views::ImageButton(this);
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::Button::BS_HOT,
+ close_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::Button::BS_PUSHED,
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
- close_button_->SetListener(this, 0);
AddChildView(close_button_);
set_background(views::Background::CreateSolidBackground(kBackgroundColor));
@@ -263,7 +262,7 @@ void DownloadShelfView::LinkActivated(views::Link* source, int event_flags) {
ShowAllDownloads();
}
-void DownloadShelfView::ButtonPressed(views::BaseButton* button) {
+void DownloadShelfView::ButtonPressed(views::Button* button) {
shelf_animation_->Hide();
}
diff --git a/chrome/browser/views/download_shelf_view.h b/chrome/browser/views/download_shelf_view.h
index 36b2070..1cd7907 100644
--- a/chrome/browser/views/download_shelf_view.h
+++ b/chrome/browser/views/download_shelf_view.h
@@ -11,6 +11,7 @@
#include "chrome/views/link.h"
namespace views {
+class ImageButton;
class ImageView;
}
@@ -28,7 +29,7 @@ class DownloadAnimation;
// it'll automatically remove views once a certain point is reached.
class DownloadShelfView : public DownloadShelf,
public views::View,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public views::LinkController,
public AnimationDelegate {
public:
@@ -50,7 +51,7 @@ class DownloadShelfView : public DownloadShelf,
// Implementation of ButtonListener.
// Invoked when the user clicks the close button. Asks the browser to
// hide the download shelf.
- virtual void ButtonPressed(views::BaseButton* button);
+ virtual void ButtonPressed(views::Button* button);
// Implementation of DownloadShelf.
virtual void AddDownload(BaseDownloadItemModel* download_model);
@@ -90,7 +91,7 @@ class DownloadShelfView : public DownloadShelf,
// Button for closing the downloads. This is contained as a child, and
// deleted by View.
- views::Button* close_button_;
+ views::ImageButton* close_button_;
DISALLOW_COPY_AND_ASSIGN(DownloadShelfView);
};
diff --git a/chrome/browser/views/find_bar_view.cc b/chrome/browser/views/find_bar_view.cc
index 1cb9481..56dfd29 100644
--- a/chrome/browser/views/find_bar_view.cc
+++ b/chrome/browser/views/find_bar_view.cc
@@ -15,6 +15,7 @@
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/views/background.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/label.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -109,39 +110,42 @@ FindBarView::FindBarView(FindBarWin* container)
focus_forwarder_view_ = new FocusForwarderView(find_text_);
AddChildView(focus_forwarder_view_);
- find_previous_button_ = new views::Button();
+ find_previous_button_ = new views::ImageButton(this);
+ find_previous_button_->set_tag(FIND_PREVIOUS_TAG);
find_previous_button_->SetEnabled(false);
find_previous_button_->SetFocusable(true);
- find_previous_button_->SetImage(views::Button::BS_NORMAL,
+ find_previous_button_->SetImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_FINDINPAGE_PREV));
- find_previous_button_->SetImage(views::Button::BS_HOT,
+ find_previous_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_FINDINPAGE_PREV_H));
- find_previous_button_->SetImage(views::Button::BS_DISABLED,
+ find_previous_button_->SetImage(views::CustomButton::BS_DISABLED,
rb.GetBitmapNamed(IDR_FINDINPAGE_PREV_P));
find_previous_button_->SetTooltipText(
l10n_util::GetString(IDS_FIND_IN_PAGE_PREVIOUS_TOOLTIP));
AddChildView(find_previous_button_);
- find_next_button_ = new views::Button();
+ find_next_button_ = new views::ImageButton(this);
+ find_next_button_->set_tag(FIND_NEXT_TAG);
find_next_button_->SetEnabled(false);
find_next_button_->SetFocusable(true);
- find_next_button_->SetImage(views::Button::BS_NORMAL,
+ find_next_button_->SetImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_FINDINPAGE_NEXT));
- find_next_button_->SetImage(views::Button::BS_HOT,
+ find_next_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_FINDINPAGE_NEXT_H));
- find_next_button_->SetImage(views::Button::BS_DISABLED,
+ find_next_button_->SetImage(views::CustomButton::BS_DISABLED,
rb.GetBitmapNamed(IDR_FINDINPAGE_NEXT_P));
find_next_button_->SetTooltipText(
l10n_util::GetString(IDS_FIND_IN_PAGE_NEXT_TOOLTIP));
AddChildView(find_next_button_);
- close_button_ = new views::Button();
+ close_button_ = new views::ImageButton(this);
+ close_button_->set_tag(CLOSE_TAG);
close_button_->SetFocusable(true);
- close_button_->SetImage(views::Button::BS_NORMAL,
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::Button::BS_HOT,
+ close_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::Button::BS_PUSHED,
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
close_button_->SetTooltipText(
l10n_util::GetString(IDS_FIND_IN_PAGE_CLOSE_TOOLTIP));
@@ -345,7 +349,6 @@ void FindBarView::Layout() {
(height() - sz.height()) / 2,
sz.width(),
sz.height());
- close_button_->SetListener(this, CLOSE_TAG);
// Next, the FindNext button to the left the close button.
sz = find_next_button_->GetPreferredSize();
@@ -355,7 +358,6 @@ void FindBarView::Layout() {
(height() - sz.height()) / 2,
sz.width(),
sz.height());
- find_next_button_->SetListener(this, FIND_NEXT_TAG);
// Then, the FindPrevious button to the left the FindNext button.
sz = find_previous_button_->GetPreferredSize();
@@ -364,7 +366,6 @@ void FindBarView::Layout() {
(height() - sz.height()) / 2,
sz.width(),
sz.height());
- find_previous_button_->SetListener(this, FIND_PREVIOUS_TAG);
// Then the label showing the match count number.
sz = match_count_text_->GetPreferredSize();
@@ -421,16 +422,16 @@ gfx::Size FindBarView::GetPreferredSize() {
}
////////////////////////////////////////////////////////////////////////////////
-// FindBarView, views::BaseButton::ButtonListener implementation:
+// FindBarView, views::ButtonListener implementation:
-void FindBarView::ButtonPressed(views::BaseButton* sender) {
- switch (sender->GetTag()) {
+void FindBarView::ButtonPressed(views::Button* sender) {
+ switch (sender->tag()) {
case FIND_PREVIOUS_TAG:
case FIND_NEXT_TAG:
if (find_text_->GetText().length() > 0) {
container_->find_bar_controller()->web_contents()->StartFinding(
find_text_->GetText(),
- sender->GetTag() == FIND_NEXT_TAG);
+ sender->tag() == FIND_NEXT_TAG);
}
break;
case CLOSE_TAG:
diff --git a/chrome/browser/views/find_bar_view.h b/chrome/browser/views/find_bar_view.h
index 2818d6d..2b5748a 100644
--- a/chrome/browser/views/find_bar_view.h
+++ b/chrome/browser/views/find_bar_view.h
@@ -13,6 +13,7 @@
class FindBarWin;
namespace views {
+class ImageButton;
class Label;
class MouseEvent;
class View;
@@ -26,7 +27,7 @@ class View;
//
////////////////////////////////////////////////////////////////////////////////
class FindBarView : public views::View,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public views::TextField::Controller {
public:
// A tag denoting which button the user pressed.
@@ -60,8 +61,8 @@ class FindBarView : public views::View,
virtual gfx::Size GetPreferredSize();
virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
- // Overridden from views::ButtonListener::ButtonPressed:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
// Overridden from views::TextField::Controller:
virtual void ContentsChanged(views::TextField* sender,
@@ -104,9 +105,9 @@ class FindBarView : public views::View,
views::TextField* find_text_;
views::Label* match_count_text_;
FocusForwarderView* focus_forwarder_view_;
- views::Button* find_previous_button_;
- views::Button* find_next_button_;
- views::Button* close_button_;
+ views::ImageButton* find_previous_button_;
+ views::ImageButton* find_next_button_;
+ views::ImageButton* close_button_;
// The last matchcount number we reported to the user.
int last_reported_matchcount_;
diff --git a/chrome/browser/views/frame/glass_browser_frame_view.h b/chrome/browser/views/frame/glass_browser_frame_view.h
index 90bbc9c..585e075 100644
--- a/chrome/browser/views/frame/glass_browser_frame_view.h
+++ b/chrome/browser/views/frame/glass_browser_frame_view.h
@@ -11,6 +11,7 @@
class BrowserView;
class GlassBrowserWindowResources;
+class SkBitmap;
class GlassBrowserFrameView : public BrowserNonClientFrameView {
public:
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc
index 01b8632..0f6d3d1 100644
--- a/chrome/browser/views/frame/opaque_browser_frame_view.cc
+++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc
@@ -13,6 +13,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/root_view.h"
#include "chrome/views/window_resources.h"
#include "grit/chromium_strings.h"
@@ -332,10 +333,10 @@ const int kCaptionTopSpacing = 1;
OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
BrowserView* browser_view)
: BrowserNonClientFrameView(),
- minimize_button_(new views::Button),
- maximize_button_(new views::Button),
- restore_button_(new views::Button),
- close_button_(new views::Button),
+ minimize_button_(new views::ImageButton(this)),
+ maximize_button_(new views::ImageButton(this)),
+ restore_button_(new views::ImageButton(this)),
+ close_button_(new views::ImageButton(this)),
window_icon_(NULL),
frame_(frame),
browser_view_(browser_view) {
@@ -355,57 +356,53 @@ OpaqueBrowserFrameView::OpaqueBrowserFrameView(BrowserFrame* frame,
views::WindowResources* resources = current_active_resources_;
minimize_button_->SetImage(
- views::Button::BS_NORMAL,
+ views::CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON));
minimize_button_->SetImage(
- views::Button::BS_HOT,
+ views::CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_H));
minimize_button_->SetImage(
- views::Button::BS_PUSHED,
+ views::CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_P));
- minimize_button_->SetListener(this, -1);
minimize_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_MINIMIZE));
AddChildView(minimize_button_);
maximize_button_->SetImage(
- views::Button::BS_NORMAL,
+ views::CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON));
maximize_button_->SetImage(
- views::Button::BS_HOT,
+ views::CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON_H));
maximize_button_->SetImage(
- views::Button::BS_PUSHED,
+ views::CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON_P));
- maximize_button_->SetListener(this, -1);
maximize_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_MAXIMIZE));
AddChildView(maximize_button_);
restore_button_->SetImage(
- views::Button::BS_NORMAL,
+ views::CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON));
restore_button_->SetImage(
- views::Button::BS_HOT,
+ views::CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON_H));
restore_button_->SetImage(
- views::Button::BS_PUSHED,
+ views::CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON_P));
- restore_button_->SetListener(this, -1);
restore_button_->SetAccessibleName(
l10n_util::GetString(IDS_ACCNAME_RESTORE));
AddChildView(restore_button_);
close_button_->SetImage(
- views::Button::BS_NORMAL,
+ views::CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON));
close_button_->SetImage(
- views::Button::BS_HOT,
+ views::CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H));
close_button_->SetImage(
- views::Button::BS_PUSHED,
+ views::CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P));
- close_button_->SetListener(this, -1);
close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
AddChildView(close_button_);
@@ -532,9 +529,9 @@ void OpaqueBrowserFrameView::EnableClose(bool enable) {
}
void OpaqueBrowserFrameView::ResetWindowControls() {
- restore_button_->SetState(views::Button::BS_NORMAL);
- minimize_button_->SetState(views::Button::BS_NORMAL);
- maximize_button_->SetState(views::Button::BS_NORMAL);
+ restore_button_->SetState(views::CustomButton::BS_NORMAL);
+ minimize_button_->SetState(views::CustomButton::BS_NORMAL);
+ maximize_button_->SetState(views::CustomButton::BS_NORMAL);
// The close button isn't affected by this constraint.
}
@@ -617,9 +614,9 @@ void OpaqueBrowserFrameView::SetAccessibleName(const std::wstring& name) {
}
///////////////////////////////////////////////////////////////////////////////
-// OpaqueBrowserFrameView, views::BaseButton::ButtonListener implementation:
+// OpaqueBrowserFrameView, views::ButtonListener implementation:
-void OpaqueBrowserFrameView::ButtonPressed(views::BaseButton* sender) {
+void OpaqueBrowserFrameView::ButtonPressed(views::Button* sender) {
if (sender == minimize_button_)
frame_->Minimize();
else if (sender == maximize_button_)
@@ -904,8 +901,8 @@ void OpaqueBrowserFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) {
}
void OpaqueBrowserFrameView::LayoutWindowControls() {
- close_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
- views::Button::ALIGN_BOTTOM);
+ close_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
+ views::ImageButton::ALIGN_BOTTOM);
// Maximized buttons start at window top so that even if their images aren't
// drawn flush with the screen edge, they still obey Fitts' Law.
bool is_maximized = frame_->IsMaximized();
@@ -926,23 +923,23 @@ void OpaqueBrowserFrameView::LayoutWindowControls() {
// When the window is restored, we show a maximized button; otherwise, we show
// a restore button.
bool is_restored = !is_maximized && !frame_->IsMinimized();
- views::Button* invisible_button = is_restored ?
+ views::ImageButton* invisible_button = is_restored ?
restore_button_ : maximize_button_;
invisible_button->SetVisible(false);
- views::Button* visible_button = is_restored ?
+ views::ImageButton* visible_button = is_restored ?
maximize_button_ : restore_button_;
visible_button->SetVisible(true);
- visible_button->SetImageAlignment(views::Button::ALIGN_LEFT,
- views::Button::ALIGN_BOTTOM);
+ visible_button->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
+ views::ImageButton::ALIGN_BOTTOM);
gfx::Size visible_button_size = visible_button->GetPreferredSize();
visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
caption_y, visible_button_size.width(),
visible_button_size.height() + top_extra_height);
minimize_button_->SetVisible(true);
- minimize_button_->SetImageAlignment(views::Button::ALIGN_LEFT,
- views::Button::ALIGN_BOTTOM);
+ minimize_button_->SetImageAlignment(views::ImageButton::ALIGN_LEFT,
+ views::ImageButton::ALIGN_BOTTOM);
gfx::Size minimize_button_size = minimize_button_->GetPreferredSize();
minimize_button_->SetBounds(
visible_button->x() - minimize_button_size.width(), caption_y,
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.h b/chrome/browser/views/frame/opaque_browser_frame_view.h
index ee805f8..3a47ac4 100644
--- a/chrome/browser/views/frame/opaque_browser_frame_view.h
+++ b/chrome/browser/views/frame/opaque_browser_frame_view.h
@@ -15,11 +15,12 @@ class ChromeFont;
class TabContents;
class TabStrip;
namespace views {
+class ImageButton;
class WindowResources;
}
class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public TabIconView::TabIconViewModel {
public:
// Constructs a non-client view for an BrowserFrame. |is_otr| specifies if the
@@ -54,8 +55,8 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
virtual bool GetAccessibleName(std::wstring* name);
virtual void SetAccessibleName(const std::wstring& name);
- // Overridden from views::BaseButton::ButtonListener:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
// Overridden from TabIconView::TabIconViewModel:
virtual bool ShouldTabIconViewAnimate() const;
@@ -126,10 +127,10 @@ class OpaqueBrowserFrameView : public BrowserNonClientFrameView,
gfx::Rect otr_avatar_bounds_;
// Window controls.
- views::Button* minimize_button_;
- views::Button* maximize_button_;
- views::Button* restore_button_;
- views::Button* close_button_;
+ views::ImageButton* minimize_button_;
+ views::ImageButton* maximize_button_;
+ views::ImageButton* restore_button_;
+ views::ImageButton* close_button_;
// The Window icon.
TabIconView* window_icon_;
diff --git a/chrome/browser/views/go_button.cc b/chrome/browser/views/go_button.cc
index fbdd6b8..db205c4 100644
--- a/chrome/browser/views/go_button.cc
+++ b/chrome/browser/views/go_button.cc
@@ -10,14 +10,18 @@
#include "chrome/common/l10n_util.h"
#include "grit/generated_resources.h"
+////////////////////////////////////////////////////////////////////////////////
+// GoButton, public:
+
GoButton::GoButton(LocationBarView* location_bar,
- CommandUpdater* command_updater) : ToggleButton(),
- location_bar_(location_bar),
- command_updater_(command_updater),
- intended_mode_(MODE_GO),
- visible_mode_(MODE_GO),
- button_delay_(NULL),
- stop_timer_(this) {
+ CommandUpdater* command_updater)
+ : ToggleImageButton(this),
+ location_bar_(location_bar),
+ command_updater_(command_updater),
+ intended_mode_(MODE_GO),
+ visible_mode_(MODE_GO),
+ button_delay_(NULL),
+ stop_timer_(this) {
DCHECK(location_bar_);
}
@@ -25,7 +29,40 @@ GoButton::~GoButton() {
stop_timer_.RevokeAll();
}
-void GoButton::NotifyClick(int mouse_event_flags) {
+void GoButton::ChangeMode(Mode mode) {
+ stop_timer_.RevokeAll();
+
+ SetToggled(mode == MODE_STOP);
+ intended_mode_ = mode;
+ visible_mode_ = mode;
+}
+
+void GoButton::ScheduleChangeMode(Mode mode) {
+ if (mode == MODE_STOP) {
+ // If we still have a timer running, we can't yet change to a stop sign,
+ // so we'll queue up the change for when the timer expires or for when
+ // the mouse exits the button.
+ if (!stop_timer_.empty() && state() == BS_HOT) {
+ intended_mode_ = MODE_STOP;
+ } else {
+ ChangeMode(MODE_STOP);
+ }
+ } else {
+ // If we want to change the button to a go button, but the user's mouse
+ // is hovering, don't change the mode just yet - this prevents the
+ // stop button changing to a go under the user's mouse cursor.
+ if (visible_mode_ == MODE_STOP && state() == BS_HOT) {
+ intended_mode_ = MODE_GO;
+ } else {
+ ChangeMode(MODE_GO);
+ }
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// GoButton, views::ButtonListener implementation:
+
+void GoButton::ButtonPressed(views::Button* button) {
if (visible_mode_ == MODE_STOP) {
command_updater_->ExecuteCommand(IDC_STOP);
@@ -33,7 +70,7 @@ void GoButton::NotifyClick(int mouse_event_flags) {
// even if the mouse is still hovering.
ChangeMode(MODE_GO);
} else if (visible_mode_ == MODE_GO && stop_timer_.empty()) {
- // If the go button is visible and not within the doubleclick timer, go.
+ // If the go button is visible and not within the double click timer, go.
command_updater_->ExecuteCommand(IDC_GO);
// Figure out the system double-click time.
@@ -54,53 +91,19 @@ void GoButton::NotifyClick(int mouse_event_flags) {
}
}
+////////////////////////////////////////////////////////////////////////////////
+// GoButton, View overrides:
+
void GoButton::OnMouseExited(const views::MouseEvent& e) {
using namespace views;
if (visible_mode_ != intended_mode_)
ChangeMode(intended_mode_);
- if (GetState() != BS_DISABLED)
+ if (state() != BS_DISABLED)
SetState(BS_NORMAL);
}
-void GoButton::ChangeMode(Mode mode) {
- stop_timer_.RevokeAll();
-
- SetToggled(mode == MODE_STOP);
- intended_mode_ = mode;
- visible_mode_ = mode;
-}
-
-void GoButton::ScheduleChangeMode(Mode mode) {
- if (mode == MODE_STOP) {
- // If we still have a timer running, we can't yet change to a stop sign,
- // so we'll queue up the change for when the timer expires or for when
- // the mouse exits the button.
- if (!stop_timer_.empty() && GetState() == BS_HOT) {
- intended_mode_ = MODE_STOP;
- } else {
- ChangeMode(MODE_STOP);
- }
- } else {
- // If we want to change the button to a go button, but the user's mouse
- // is hovering, don't change the mode just yet - this prevents the
- // stop button changing to a go under the user's mouse cursor.
- if (visible_mode_ == MODE_STOP && GetState() == BS_HOT) {
- intended_mode_ = MODE_GO;
- } else {
- ChangeMode(MODE_GO);
- }
- }
-}
-
-void GoButton::OnButtonTimer() {
- if (intended_mode_ != visible_mode_)
- ChangeMode(intended_mode_);
-
- stop_timer_.RevokeAll();
-}
-
bool GoButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
if (visible_mode_ == MODE_STOP) {
tooltip->assign(l10n_util::GetString(IDS_TOOLTIP_STOP));
@@ -131,3 +134,13 @@ bool GoButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
l10n_util::GetStringF(IDS_TOOLTIP_GO_SEARCH, L"Google", current_text));
return true;
}
+
+////////////////////////////////////////////////////////////////////////////////
+// GoButton, private:
+
+void GoButton::OnButtonTimer() {
+ if (intended_mode_ != visible_mode_)
+ ChangeMode(intended_mode_);
+
+ stop_timer_.RevokeAll();
+}
diff --git a/chrome/browser/views/go_button.h b/chrome/browser/views/go_button.h
index 372bff5..306ae59 100644
--- a/chrome/browser/views/go_button.h
+++ b/chrome/browser/views/go_button.h
@@ -5,7 +5,7 @@
#ifndef CHROME_BROWSER_VIEWS_GO_BUTTON_H__
#define CHROME_BROWSER_VIEWS_GO_BUTTON_H__
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "base/task.h"
class CommandUpdater;
@@ -19,11 +19,12 @@ class LocationBarView;
// according to the content of the location bar and changes to a stop
// button when a page load is in progress. Trickiness comes from the
// desire to have the 'stop' button not change back to 'go' if the user's
-// mouse is hovering over it (to prevent misclicks).
+// mouse is hovering over it (to prevent mis-clicks).
//
////////////////////////////////////////////////////////////////////////////////
-class GoButton : public views::ToggleButton {
+class GoButton : public views::ToggleImageButton,
+ public views::ButtonListener {
public:
// TODO(beng): get rid of the command updater param and instead have a
// delegate.
@@ -32,9 +33,6 @@ class GoButton : public views::ToggleButton {
typedef enum Mode { MODE_GO = 0, MODE_STOP };
- virtual void NotifyClick(int mouse_event_flags);
- virtual void OnMouseExited(const views::MouseEvent& e);
-
// Force the button state
void ChangeMode(Mode mode);
@@ -42,6 +40,11 @@ class GoButton : public views::ToggleButton {
// when page load state changes.
void ScheduleChangeMode(Mode mode);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* button);
+
+ // Overridden from views::View:
+ virtual void OnMouseExited(const views::MouseEvent& e);
virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
private:
@@ -52,7 +55,6 @@ class GoButton : public views::ToggleButton {
LocationBarView* location_bar_;
CommandUpdater* command_updater_;
- ButtonListener* listener_;
// The mode we should be in
Mode intended_mode_;
diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc
index de1401f..4c4e621 100644
--- a/chrome/browser/views/infobars/infobars.cc
+++ b/chrome/browser/views/infobars/infobars.cc
@@ -12,7 +12,7 @@
#include "chrome/common/resource_bundle.h"
#include "chrome/common/slide_animation.h"
#include "chrome/views/background.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/external_focus_tracker.h"
#include "chrome/views/image_view.h"
#include "chrome/views/label.h"
@@ -71,7 +71,7 @@ class InfoBarBackground : public views::Background {
InfoBar::InfoBar(InfoBarDelegate* delegate)
: delegate_(delegate),
- close_button_(new views::Button),
+ close_button_(new views::ImageButton(this)),
delete_factory_(this) {
// We delete ourselves when we're removed from the view hierarchy.
SetParentOwned(false);
@@ -79,13 +79,12 @@ InfoBar::InfoBar(InfoBarDelegate* delegate)
set_background(new InfoBarBackground);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
- close_button_->SetImage(views::Button::BS_NORMAL,
+ close_button_->SetImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_CLOSE_BAR));
- close_button_->SetImage(views::Button::BS_HOT,
+ close_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
- close_button_->SetImage(views::Button::BS_PUSHED,
+ close_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
- close_button_->SetListener(this, 0);
close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
AddChildView(close_button_);
@@ -157,9 +156,9 @@ void InfoBar::RemoveInfoBar() const {
container_->RemoveDelegate(delegate());
}
-// InfoBar, views::BaseButton::ButtonListener implementation: ------------------
+// InfoBar, views::ButtonListener implementation: ------------------
-void InfoBar::ButtonPressed(views::BaseButton* sender) {
+void InfoBar::ButtonPressed(views::Button* sender) {
if (sender == close_button_)
RemoveInfoBar();
}
diff --git a/chrome/browser/views/infobars/infobars.h b/chrome/browser/views/infobars/infobars.h
index 15885ce..c7a0d38 100644
--- a/chrome/browser/views/infobars/infobars.h
+++ b/chrome/browser/views/infobars/infobars.h
@@ -6,14 +6,15 @@
#define CHROME_BROWSER_VIEWS_INFOBARS_INFOBARS_H_
#include "chrome/browser/tab_contents/infobar_delegate.h"
-#include "chrome/views/base_button.h"
+#include "chrome/common/animation.h"
+#include "chrome/views/button.h"
#include "chrome/views/link.h"
#include "chrome/views/native_button.h"
class InfoBarContainer;
class SlideAnimation;
namespace views {
-class Button;
+class ImageButton;
class ExternalFocusTracker;
class ImageView;
class Label;
@@ -24,7 +25,7 @@ class Label;
// that you must implement to use these.
class InfoBar : public views::View,
- public views::BaseButton::ButtonListener,
+ public views::ButtonListener,
public AnimationDelegate {
public:
explicit InfoBar(InfoBarDelegate* delegate);
@@ -70,8 +71,8 @@ class InfoBar : public views::View,
void RemoveInfoBar() const;
private:
- // Overridden from views::Button::ButtonListener:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender);
// Overridden from AnimationDelegate:
virtual void AnimationProgressed(const Animation* animation);
@@ -98,7 +99,7 @@ class InfoBar : public views::View,
InfoBarDelegate* delegate_;
// The Close Button at the right edge of the InfoBar.
- views::Button* close_button_;
+ views::ImageButton* close_button_;
// The animation that runs when the InfoBar is opened or closed.
scoped_ptr<SlideAnimation> animation_;
diff --git a/chrome/browser/views/tabs/tab.cc b/chrome/browser/views/tabs/tab.cc
index 5f1a911..3de8cb9 100644
--- a/chrome/browser/views/tabs/tab.cc
+++ b/chrome/browser/views/tabs/tab.cc
@@ -123,7 +123,6 @@ Tab::Tab(TabDelegate* delegate)
delegate_(delegate),
closing_(false),
menu_controller_(NULL) {
- close_button()->SetListener(this, 0);
close_button()->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE));
close_button()->SetAnimationDuration(0);
SetContextMenuController(this);
@@ -237,9 +236,9 @@ void Tab::ShowContextMenu(views::View* source, int x, int y,
}
///////////////////////////////////////////////////////////////////////////////
-// views::BaseButton::ButtonListener implementation:
+// views::ButtonListener implementation:
-void Tab::ButtonPressed(views::BaseButton* sender) {
+void Tab::ButtonPressed(views::Button* sender) {
if (sender == close_button())
delegate_->CloseTab(this);
}
diff --git a/chrome/browser/views/tabs/tab.h b/chrome/browser/views/tabs/tab.h
index 9c136ae..9230dd0 100644
--- a/chrome/browser/views/tabs/tab.h
+++ b/chrome/browser/views/tabs/tab.h
@@ -7,7 +7,6 @@
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/views/tabs/tab_renderer.h"
-#include "chrome/views/base_button.h"
namespace gfx {
class Path;
@@ -24,8 +23,7 @@ class Profile;
//
///////////////////////////////////////////////////////////////////////////////
class Tab : public TabRenderer,
- public views::ContextMenuController,
- public views::BaseButton::ButtonListener {
+ public views::ContextMenuController {
public:
static const std::string kTabClassName;
@@ -114,8 +112,8 @@ class Tab : public TabRenderer,
int y,
bool is_mouse_gesture);
- // views::BaseButton::ButtonListener overrides:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // views::ButtonListener overrides:
+ virtual void ButtonPressed(views::Button* sender);
// Creates a path that contains the clickable region of the tab's visual
// representation. Used by GetViewForPoint for hit-testing.
diff --git a/chrome/browser/views/tabs/tab_renderer.cc b/chrome/browser/views/tabs/tab_renderer.cc
index 654acea..125bce4 100644
--- a/chrome/browser/views/tabs/tab_renderer.cc
+++ b/chrome/browser/views/tabs/tab_renderer.cc
@@ -132,13 +132,15 @@ int GetContentHeight() {
//
// This is a Button subclass that causes middle clicks to be forwarded to the
// parent View by explicitly not handling them in OnMousePressed.
-class TabCloseButton : public views::Button {
+class TabCloseButton : public views::ImageButton {
public:
- TabCloseButton() : Button() {}
+ explicit TabCloseButton(views::ButtonListener* listener)
+ : views::ImageButton(listener) {
+ }
virtual ~TabCloseButton() {}
virtual bool OnMousePressed(const views::MouseEvent& event) {
- bool handled = BaseButton::OnMousePressed(event);
+ bool handled = ImageButton::OnMousePressed(event);
// Explicitly mark midle-mouse clicks as non-handled to ensure the tab
// sees them.
return event.IsOnlyMiddleMouseButton() ? false : handled;
@@ -148,12 +150,12 @@ class TabCloseButton : public views::Button {
// can highlight itself appropriately. Note that Exit events
// fire before Enter events, so this works.
virtual void OnMouseEntered(const views::MouseEvent& event) {
- BaseButton::OnMouseEntered(event);
+ CustomButton::OnMouseEntered(event);
GetParent()->OnMouseEntered(event);
}
virtual void OnMouseExited(const views::MouseEvent& event) {
- BaseButton::OnMouseExited(event);
+ CustomButton::OnMouseExited(event);
GetParent()->OnMouseExited(event);
}
@@ -217,10 +219,10 @@ TabRenderer::TabRenderer()
InitResources();
// Add the Close Button.
- close_button_ = new TabCloseButton;
- close_button_->SetImage(views::Button::BS_NORMAL, close_button_n);
- close_button_->SetImage(views::Button::BS_HOT, close_button_h);
- close_button_->SetImage(views::Button::BS_PUSHED, close_button_p);
+ close_button_ = new TabCloseButton(this);
+ close_button_->SetImage(views::CustomButton::BS_NORMAL, close_button_n);
+ close_button_->SetImage(views::CustomButton::BS_HOT, close_button_h);
+ close_button_->SetImage(views::CustomButton::BS_PUSHED, close_button_p);
AddChildView(close_button_);
hover_animation_.reset(new SlideAnimation(this));
diff --git a/chrome/browser/views/tabs/tab_renderer.h b/chrome/browser/views/tabs/tab_renderer.h
index 5e2416f..df4cd6c 100644
--- a/chrome/browser/views/tabs/tab_renderer.h
+++ b/chrome/browser/views/tabs/tab_renderer.h
@@ -9,7 +9,7 @@
#include "chrome/common/animation.h"
#include "chrome/common/slide_animation.h"
#include "chrome/common/throb_animation.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/menu.h"
#include "chrome/views/view.h"
@@ -23,6 +23,7 @@ class TabContents;
//
///////////////////////////////////////////////////////////////////////////////
class TabRenderer : public views::View,
+ public views::ButtonListener,
public AnimationDelegate {
public:
// Possible animation states.
@@ -68,12 +69,15 @@ class TabRenderer : public views::View,
static void LoadTabImages(bool use_vista_images);
protected:
- views::Button* close_button() const { return close_button_; }
+ views::ImageButton* close_button() const { return close_button_; }
const gfx::Rect& title_bounds() const { return title_bounds_; }
// Returns the title of the Tab.
std::wstring GetTitle() const;
+ // views::ButtonListener overrides:
+ virtual void ButtonPressed(views::Button* sender) {}
+
private:
// Overridden from views::View:
virtual void Paint(ChromeCanvas* canvas);
@@ -129,7 +133,7 @@ class TabRenderer : public views::View,
int animation_frame_;
// Close Button.
- views::Button* close_button_;
+ views::ImageButton* close_button_;
// Hover animation.
scoped_ptr<SlideAnimation> hover_animation_;
diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc
index d2d4beb..2829289 100644
--- a/chrome/browser/views/tabs/tab_strip.cc
+++ b/chrome/browser/views/tabs/tab_strip.cc
@@ -60,9 +60,11 @@ static inline int Round(double x) {
//
// A subclass of button that hit-tests to the shape of the new tab button.
-class NewTabButton : public views::Button {
+class NewTabButton : public views::ImageButton {
public:
- NewTabButton() {}
+ explicit NewTabButton(views::ButtonListener* listener)
+ : views::ImageButton(listener) {
+ }
virtual ~NewTabButton() {}
protected:
@@ -1005,7 +1007,7 @@ bool TabStrip::HasAvailableDragActions() const {
///////////////////////////////////////////////////////////////////////////////
// TabStrip, views::BaseButton::ButtonListener implementation:
-void TabStrip::ButtonPressed(views::BaseButton* sender) {
+void TabStrip::ButtonPressed(views::Button* sender) {
if (sender == newtab_button_)
model_->AddBlankTab(true);
}
@@ -1069,16 +1071,15 @@ void TabStrip::DidProcessMessage(const MSG& msg) {
void TabStrip::Init() {
model_->AddObserver(this);
- newtab_button_ = new NewTabButton;
- newtab_button_->SetListener(this, TabStripModel::kNoTab);
+ newtab_button_ = new NewTabButton(this);
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
SkBitmap* bitmap;
bitmap = rb.GetBitmapNamed(IDR_NEWTAB_BUTTON);
- newtab_button_->SetImage(views::Button::BS_NORMAL, bitmap);
- newtab_button_->SetImage(views::Button::BS_PUSHED,
+ newtab_button_->SetImage(views::CustomButton::BS_NORMAL, bitmap);
+ newtab_button_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_P));
- newtab_button_->SetImage(views::Button::BS_HOT,
+ newtab_button_->SetImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_NEWTAB_BUTTON_H));
newtab_button_size_.SetSize(bitmap->width(), bitmap->height());
diff --git a/chrome/browser/views/tabs/tab_strip.h b/chrome/browser/views/tabs/tab_strip.h
index e673507..7ee81149 100644
--- a/chrome/browser/views/tabs/tab_strip.h
+++ b/chrome/browser/views/tabs/tab_strip.h
@@ -8,7 +8,7 @@
#include "base/gfx/point.h"
#include "chrome/browser/tabs/tab_strip_model.h"
#include "chrome/browser/views/tabs/tab.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/menu.h"
#include "chrome/views/view.h"
#include "chrome/views/widget_win.h"
@@ -37,7 +37,7 @@ class ImageView;
class TabStrip : public views::View,
public TabStripModelObserver,
public Tab::TabDelegate,
- public views::Button::ButtonListener,
+ public views::ButtonListener,
public MessageLoopForUI::Observer {
public:
TabStrip(TabStripModel* model);
@@ -138,8 +138,8 @@ class TabStrip : public views::View,
virtual bool EndDrag(bool canceled);
virtual bool HasAvailableDragActions() const;
- // views::Button::ButtonListener implementation:
- virtual void ButtonPressed(views::BaseButton* sender);
+ // views::ButtonListener implementation:
+ virtual void ButtonPressed(views::Button* sender);
// MessageLoop::Observer implementation:
virtual void WillProcessMessage(const MSG& msg);
@@ -289,7 +289,7 @@ class TabStrip : public views::View,
bool resize_layout_scheduled_;
// The "New Tab" button.
- views::Button* newtab_button_;
+ views::ImageButton* newtab_button_;
gfx::Size newtab_button_size_;
gfx::Size actual_newtab_button_size_;
diff --git a/chrome/browser/views/toolbar_star_toggle.cc b/chrome/browser/views/toolbar_star_toggle.cc
index acc5a9e..b76f442 100644
--- a/chrome/browser/views/toolbar_star_toggle.cc
+++ b/chrome/browser/views/toolbar_star_toggle.cc
@@ -27,8 +27,10 @@ using base::TimeTicks;
// with the bubble because it has other native windows.
static const int64 kDisallowClickMS = 40;
-ToolbarStarToggle::ToolbarStarToggle(BrowserToolbarView* host)
- : host_(host),
+ToolbarStarToggle::ToolbarStarToggle(views::ButtonListener* listener,
+ BrowserToolbarView* host)
+ : ToggleImageButton(listener),
+ host_(host),
ignore_click_(false) {
}
@@ -49,23 +51,23 @@ void ToolbarStarToggle::ShowStarBubble(const GURL& url, bool newly_bookmarked) {
bool ToolbarStarToggle::OnMousePressed(const views::MouseEvent& e) {
ignore_click_ = ((TimeTicks::Now() - bubble_closed_time_).InMilliseconds() <
kDisallowClickMS);
- return ToggleButton::OnMousePressed(e);
+ return ToggleImageButton::OnMousePressed(e);
}
void ToolbarStarToggle::OnMouseReleased(const views::MouseEvent& e,
bool canceled) {
- ToggleButton::OnMouseReleased(e, canceled);
+ ToggleImageButton::OnMouseReleased(e, canceled);
ignore_click_ = false;
}
void ToolbarStarToggle::OnDragDone() {
- ToggleButton::OnDragDone();
+ ToggleImageButton::OnDragDone();
ignore_click_ = false;
}
void ToolbarStarToggle::NotifyClick(int mouse_event_flags) {
if (!ignore_click_ && !BookmarkBubbleView::IsShowing())
- ToggleButton::NotifyClick(mouse_event_flags);
+ ToggleImageButton::NotifyClick(mouse_event_flags);
}
SkBitmap ToolbarStarToggle::GetImageToPaint() {
@@ -73,7 +75,7 @@ SkBitmap ToolbarStarToggle::GetImageToPaint() {
ResourceBundle &rb = ResourceBundle::GetSharedInstance();
return *rb.GetBitmapNamed(IDR_STARRED_P);
}
- return Button::GetImageToPaint();
+ return ImageButton::GetImageToPaint();
}
void ToolbarStarToggle::InfoBubbleClosing(InfoBubble* info_bubble,
diff --git a/chrome/browser/views/toolbar_star_toggle.h b/chrome/browser/views/toolbar_star_toggle.h
index a794bb9..8b8d766 100644
--- a/chrome/browser/views/toolbar_star_toggle.h
+++ b/chrome/browser/views/toolbar_star_toggle.h
@@ -7,7 +7,7 @@
#include "base/time.h"
#include "chrome/browser/views/info_bubble.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
class BrowserToolbarView;
class GURL;
@@ -16,10 +16,10 @@ class GURL;
// user to star the current page. ToolbarStarToggle manages showing the
// InfoBubble and rendering the appropriate state while the bubble is visible.
-class ToolbarStarToggle : public views::ToggleButton,
+class ToolbarStarToggle : public views::ToggleImageButton,
public InfoBubbleDelegate {
public:
- explicit ToolbarStarToggle(BrowserToolbarView* host);
+ ToolbarStarToggle(views::ButtonListener* listener, BrowserToolbarView* host);
// If the bubble isn't showing, shows it.
void ShowStarBubble(const GURL& url, bool newly_bookmarked);
@@ -32,10 +32,10 @@ class ToolbarStarToggle : public views::ToggleButton,
virtual void OnMouseReleased(const views::MouseEvent& e, bool canceled);
virtual void OnDragDone();
+ protected:
// Only invokes super if ignore_click_ is true and the bubble isn't showing.
virtual void NotifyClick(int mouse_event_flags);
- protected:
// Overridden to so that we appear pressed while the bubble is showing.
virtual SkBitmap GetImageToPaint();
diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc
index 02495fc..e0165c6 100644
--- a/chrome/browser/views/toolbar_view.cc
+++ b/chrome/browser/views/toolbar_view.cc
@@ -132,47 +132,55 @@ void BrowserToolbarView::SetProfile(Profile* profile) {
void BrowserToolbarView::CreateLeftSideControls() {
ResourceBundle &rb = ResourceBundle::GetSharedInstance();
- back_ = new views::ButtonDropDown(back_menu_model_.get());
- back_->SetListener(this, IDC_BACK);
- back_->SetImageAlignment(views::Button::ALIGN_RIGHT,
- views::Button::ALIGN_TOP);
- back_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_BACK));
- back_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_BACK_H));
- back_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_BACK_P));
- back_->SetImage(views::Button::BS_DISABLED, rb.GetBitmapNamed(IDR_BACK_D));
+ back_ = new views::ButtonDropDown(this, back_menu_model_.get());
+ back_->set_tag(IDC_BACK);
+ back_->SetImageAlignment(views::ImageButton::ALIGN_RIGHT,
+ views::ImageButton::ALIGN_TOP);
+ back_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_BACK));
+ back_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_BACK_H));
+ back_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_BACK_P));
+ back_->SetImage(views::CustomButton::BS_DISABLED,
+ rb.GetBitmapNamed(IDR_BACK_D));
back_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_BACK));
back_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_BACK));
back_->SetID(VIEW_ID_BACK_BUTTON);
AddChildView(back_);
- forward_ = new views::ButtonDropDown(forward_menu_model_.get());
- forward_->SetListener(this, IDC_FORWARD);
- forward_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_FORWARD));
- forward_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_FORWARD_H));
- forward_->SetImage(views::Button::BS_PUSHED,
+ forward_ = new views::ButtonDropDown(this, forward_menu_model_.get());
+ forward_->set_tag(IDC_FORWARD);
+ forward_->SetImage(views::CustomButton::BS_NORMAL,
+ rb.GetBitmapNamed(IDR_FORWARD));
+ forward_->SetImage(views::CustomButton::BS_HOT,
+ rb.GetBitmapNamed(IDR_FORWARD_H));
+ forward_->SetImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_FORWARD_P));
- forward_->SetImage(views::Button::BS_DISABLED,
+ forward_->SetImage(views::CustomButton::BS_DISABLED,
rb.GetBitmapNamed(IDR_FORWARD_D));
forward_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_FORWARD));
forward_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_FORWARD));
forward_->SetID(VIEW_ID_FORWARD_BUTTON);
AddChildView(forward_);
- reload_ = new views::Button();
- reload_->SetListener(this, IDC_RELOAD);
- reload_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_RELOAD));
- reload_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_RELOAD_H));
- reload_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_RELOAD_P));
+ reload_ = new views::ImageButton(this);
+ reload_->set_tag(IDC_RELOAD);
+ reload_->SetImage(views::CustomButton::BS_NORMAL,
+ rb.GetBitmapNamed(IDR_RELOAD));
+ reload_->SetImage(views::CustomButton::BS_HOT,
+ rb.GetBitmapNamed(IDR_RELOAD_H));
+ reload_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_RELOAD_P));
reload_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_RELOAD));
reload_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_RELOAD));
reload_->SetID(VIEW_ID_RELOAD_BUTTON);
AddChildView(reload_);
- home_ = new views::Button();
- home_->SetListener(this, IDC_HOME);
- home_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_HOME));
- home_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_HOME_H));
- home_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_HOME_P));
+ home_ = new views::ImageButton(this);
+ home_->set_tag(IDC_HOME);
+ home_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_HOME));
+ home_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_HOME_H));
+ home_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_HOME_P));
home_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_HOME));
home_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_HOME));
home_->SetID(VIEW_ID_HOME_BUTTON);
@@ -182,17 +190,19 @@ void BrowserToolbarView::CreateLeftSideControls() {
void BrowserToolbarView::CreateCenterStack(Profile *profile) {
ResourceBundle &rb = ResourceBundle::GetSharedInstance();
- star_ = new ToolbarStarToggle(this);
- star_->SetListener(this, IDC_STAR);
- star_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_STAR));
- star_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_STAR_H));
- star_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_STAR_P));
- star_->SetImage(views::Button::BS_DISABLED, rb.GetBitmapNamed(IDR_STAR_D));
- star_->SetToggledImage(views::Button::BS_NORMAL,
+ star_ = new ToolbarStarToggle(this, this);
+ star_->set_tag(IDC_STAR);
+ star_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_STAR));
+ star_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_STAR_H));
+ star_->SetImage(views::CustomButton::BS_PUSHED,
+ rb.GetBitmapNamed(IDR_STAR_P));
+ star_->SetImage(views::CustomButton::BS_DISABLED,
+ rb.GetBitmapNamed(IDR_STAR_D));
+ star_->SetToggledImage(views::CustomButton::BS_NORMAL,
rb.GetBitmapNamed(IDR_STARRED));
- star_->SetToggledImage(views::Button::BS_HOT,
+ star_->SetToggledImage(views::CustomButton::BS_HOT,
rb.GetBitmapNamed(IDR_STARRED_H));
- star_->SetToggledImage(views::Button::BS_PUSHED,
+ star_->SetToggledImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_STARRED_P));
star_->SetDragController(this);
star_->SetTooltipText(l10n_util::GetString(IDS_TOOLTIP_STAR));
@@ -209,12 +219,14 @@ void BrowserToolbarView::CreateCenterStack(Profile *profile) {
// The Go button.
go_ = new GoButton(location_bar_, browser_->command_updater());
- go_->SetImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_GO));
- go_->SetImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_GO_H));
- go_->SetImage(views::Button::BS_PUSHED, rb.GetBitmapNamed(IDR_GO_P));
- go_->SetToggledImage(views::Button::BS_NORMAL, rb.GetBitmapNamed(IDR_STOP));
- go_->SetToggledImage(views::Button::BS_HOT, rb.GetBitmapNamed(IDR_STOP_H));
- go_->SetToggledImage(views::Button::BS_PUSHED,
+ go_->SetImage(views::CustomButton::BS_NORMAL, rb.GetBitmapNamed(IDR_GO));
+ go_->SetImage(views::CustomButton::BS_HOT, rb.GetBitmapNamed(IDR_GO_H));
+ go_->SetImage(views::CustomButton::BS_PUSHED, rb.GetBitmapNamed(IDR_GO_P));
+ go_->SetToggledImage(views::CustomButton::BS_NORMAL,
+ rb.GetBitmapNamed(IDR_STOP));
+ go_->SetToggledImage(views::CustomButton::BS_HOT,
+ rb.GetBitmapNamed(IDR_STOP_H));
+ go_->SetToggledImage(views::CustomButton::BS_PUSHED,
rb.GetBitmapNamed(IDR_STOP_P));
go_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_GO));
go_->SetID(VIEW_ID_GO_BUTTON);
@@ -241,7 +253,7 @@ void BrowserToolbarView::OnInputInProgress(bool in_progress) {
void BrowserToolbarView::CreateRightSideControls(Profile* profile) {
ResourceBundle &rb = ResourceBundle::GetSharedInstance();
- page_menu_ = new views::MenuButton(std::wstring(), this, false);
+ page_menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
// We use different menu button images if the locale is right-to-left.
if (UILayoutIsRightToLeft())
@@ -254,7 +266,7 @@ void BrowserToolbarView::CreateRightSideControls(Profile* profile) {
page_menu_->SetID(VIEW_ID_PAGE_MENU);
AddChildView(page_menu_);
- app_menu_ = new views::MenuButton(std::wstring(), this, false);
+ app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false);
if (UILayoutIsRightToLeft())
app_menu_->SetIcon(*rb.GetBitmapNamed(IDR_MENU_CHROME_RTL));
else
@@ -804,8 +816,8 @@ void BrowserToolbarView::EnabledStateChangedForCommand(int id, bool enabled) {
button->SetEnabled(enabled);
}
-void BrowserToolbarView::ButtonPressed(views::BaseButton* sender) {
- browser_->ExecuteCommand(sender->GetTag());
+void BrowserToolbarView::ButtonPressed(views::Button* sender) {
+ browser_->ExecuteCommand(sender->tag());
}
// static
diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h
index 970b378..b1eb0da 100644
--- a/chrome/browser/views/toolbar_view.h
+++ b/chrome/browser/views/toolbar_view.h
@@ -42,7 +42,7 @@ class BrowserToolbarView : public views::View,
public NotificationObserver,
public GetProfilesHelper::Delegate,
public CommandUpdater::CommandObserver,
- public views::BaseButton::ButtonListener {
+ public views::ButtonListener {
public:
explicit BrowserToolbarView(Browser* browser);
virtual ~BrowserToolbarView();
@@ -121,7 +121,7 @@ class BrowserToolbarView : public views::View,
virtual void EnabledStateChangedForCommand(int id, bool enabled);
// Overridden from views::BaseButton::ButtonListener:
- virtual void ButtonPressed(views::BaseButton* sender);
+ virtual void ButtonPressed(views::Button* sender);
private:
// Types of display mode this toolbar can have.
@@ -183,10 +183,10 @@ class BrowserToolbarView : public views::View,
views::View* acc_focused_view_;
// Controls
- views::Button* back_;
- views::Button* forward_;
- views::Button* reload_;
- views::Button* home_;
+ views::ImageButton* back_;
+ views::ImageButton* forward_;
+ views::ImageButton* reload_;
+ views::ImageButton* home_;
ToolbarStarToggle* star_;
LocationBarView* location_bar_;
GoButton* go_;
diff --git a/chrome/views/base_button.h b/chrome/views/base_button.h
deleted file mode 100644
index 7d6c66a..0000000
--- a/chrome/views/base_button.h
+++ /dev/null
@@ -1,185 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CHROME_VIEWS_BASE_BUTTON_H__
-#define CHROME_VIEWS_BASE_BUTTON_H__
-
-#include "chrome/common/animation.h"
-#include "chrome/views/event.h"
-#include "chrome/views/view.h"
-
-class ThrobAnimation;
-
-namespace views {
-
-class MouseEvent;
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton
-//
-// A base button class that shares common button functionality between various
-// specializations.
-//
-////////////////////////////////////////////////////////////////////////////////
-class BaseButton : public View,
- public AnimationDelegate {
- public:
- // Possible states
- typedef enum ButtonState { BS_NORMAL = 0,
- BS_HOT = 1,
- BS_PUSHED = 2,
- BS_DISABLED = 3};
- static const int kButtonStateCount = 4;
-
- virtual ~BaseButton();
-
- // Set / test whether the MenuButton is enabled.
- virtual void SetEnabled(bool f);
- virtual bool IsEnabled() const;
-
- // Set / test whether the button is hot-tracked.
- void SetHotTracked(bool f);
- bool IsHotTracked() const;
-
- // Set how long the hover animation will last for.
- void SetAnimationDuration(int duration);
-
- // Starts throbbing. See HoverAnimation for a description of cycles_til_stop.
- void StartThrobbing(int cycles_til_stop);
-
- // Returns whether the button is pushed.
- bool IsPushed() const;
-
- virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
- void SetTooltipText(const std::wstring& tooltip);
-
- // Overridden from View to take into account the enabled state.
- virtual bool IsFocusable() const;
- virtual bool AcceleratorPressed(const Accelerator& accelerator);
-
- // Overridden from AnimationDelegate to advance the hover state.
- virtual void AnimationProgressed(const Animation* animation);
-
- // Returns a string containing the mnemonic, or the keyboard shortcut.
- bool GetAccessibleKeyboardShortcut(std::wstring* shortcut);
-
- // Returns a brief, identifying string, containing a unique, readable name.
- bool GetAccessibleName(std::wstring* name);
-
- // Assigns a keyboard shortcut string description.
- void SetAccessibleKeyboardShortcut(const std::wstring& shortcut);
-
- // Assigns an accessible string name.
- void SetAccessibleName(const std::wstring& name);
-
- //
- // These methods are overriden to implement a simple push button
- // behavior
- virtual bool OnMousePressed(const MouseEvent& e);
- virtual bool OnMouseDragged(const MouseEvent& e);
- virtual void OnMouseReleased(const MouseEvent& e, bool canceled);
- virtual void OnMouseMoved(const MouseEvent& e);
- virtual void OnMouseEntered(const MouseEvent& e);
- virtual void OnMouseExited(const MouseEvent& e);
- virtual bool OnKeyPressed(const KeyEvent& e);
- virtual bool OnKeyReleased(const KeyEvent& e);
- // Overriden to reset state then invoke super's implementation.
- virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture);
-
- class ButtonListener {
- public:
- //
- // This is invoked once the button is released use BaseButton::GetTag()
- // to find out which button has been pressed.
- //
- virtual void ButtonPressed(BaseButton* sender) = 0;
- };
-
- //
- // The the listener, the object that receives a notification when this
- // button is pressed. tag is any int value to uniquely identify this
- // button.
- virtual void SetListener(ButtonListener *l, int tag);
-
- //
- // Return the button tag as set by SetListener()
- virtual int GetTag();
-
- //
- // Cause the button to notify the listener that a click occured.
- virtual void NotifyClick(int mouse_event_flags);
-
- // Valid when the listener is notified. Contains the event flags from the
- // mouse event, or 0 if not invoked from a mouse event.
- int mouse_event_flags() { return mouse_event_flags_; }
-
- //
- // Get the state.
- //
- int GetState() const {
- return state_;
- }
-
- //
- // Set the state. If the state is different, causes the button
- // to be repainted
- //
- virtual void SetState(ButtonState new_state);
-
-
- virtual void Paint(ChromeCanvas* canvas);
-
- // Variant of paint that allows you to specify whether the paint is for a
- // drag operation. This may be used during drag and drop to get a
- // representation of this button suitable for drag and drop.
- virtual void Paint(ChromeCanvas* canvas, bool for_drag);
-
- protected:
- BaseButton();
-
- // Returns true if the event is one that can trigger notifying the listener.
- // This implementation returns true if the left mouse button is down.
- virtual bool IsTriggerableEvent(const MouseEvent& e);
-
- virtual void OnDragDone();
-
- // Overriden to reset the state to normal (as long as we're not disabled).
- // This ensures we don't get stuck in a down state if on click our ancestor
- // is removed.
- virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
-
- // tooltip text storage
- std::wstring tooltip_text_;
-
- // storage of strings needed for accessibility
- std::wstring accessible_shortcut_;
- std::wstring accessible_name_;
-
- // The button state (defined in implementation)
- int state_;
-
- // Hover animation.
- scoped_ptr<ThrobAnimation> hover_animation_;
-
- private:
- // The current listener
- ButtonListener* listener_;
-
- // tag storage
- int tag_;
-
- // See description in mouse_event_flags().
- int mouse_event_flags_;
-
- // Should we animate when the state changes? Defaults to true, but false while
- // throbbing.
- bool animate_on_state_change_;
-
- DISALLOW_COPY_AND_ASSIGN(BaseButton);
-};
-
-} // namespace views
-
-#endif // CHROME_VIEWS_BASE_BUTTON_H__
diff --git a/chrome/views/bitmap_scroll_bar.cc b/chrome/views/bitmap_scroll_bar.cc
index 98ad4ad..32080a6 100644
--- a/chrome/views/bitmap_scroll_bar.cc
+++ b/chrome/views/bitmap_scroll_bar.cc
@@ -33,11 +33,12 @@ static const int kScrollThumbDragOutSnap = 100;
// down on the button.
//
///////////////////////////////////////////////////////////////////////////////
-class AutorepeatButton : public Button {
+class AutorepeatButton : public ImageButton {
public:
- AutorepeatButton()
- : repeater_(NewCallback<AutorepeatButton>(this,
- &AutorepeatButton::NotifyClick)) {
+ AutorepeatButton(ButtonListener* listener)
+ : ImageButton(listener),
+ repeater_(NewCallback<AutorepeatButton>(this,
+ &AutorepeatButton::NotifyClick)) {
}
virtual ~AutorepeatButton() {}
@@ -55,7 +56,7 @@ class AutorepeatButton : public Button {
private:
void NotifyClick() {
- BaseButton::NotifyClick(0);
+ Button::NotifyClick(0);
}
// The repeat controller that we use to repeatedly click the button when the
@@ -79,7 +80,7 @@ class BitmapScrollBarThumb : public View {
: scroll_bar_(scroll_bar),
drag_start_position_(-1),
mouse_offset_(-1),
- state_(BaseButton::BS_NORMAL) {
+ state_(CustomButton::BS_NORMAL) {
}
virtual ~BitmapScrollBarThumb() { }
@@ -154,17 +155,17 @@ class BitmapScrollBarThumb : public View {
}
virtual void OnMouseEntered(const MouseEvent& event) {
- SetState(BaseButton::BS_HOT);
+ SetState(CustomButton::BS_HOT);
}
virtual void OnMouseExited(const MouseEvent& event) {
- SetState(BaseButton::BS_NORMAL);
+ SetState(CustomButton::BS_NORMAL);
}
virtual bool OnMousePressed(const MouseEvent& event) {
mouse_offset_ = scroll_bar_->IsHorizontal() ? event.x() : event.y();
drag_start_position_ = GetPosition();
- SetState(BaseButton::BS_PUSHED);
+ SetState(CustomButton::BS_PUSHED);
return true;
}
@@ -197,7 +198,7 @@ class BitmapScrollBarThumb : public View {
virtual void OnMouseReleased(const MouseEvent& event,
bool canceled) {
- SetState(BaseButton::BS_HOT);
+ SetState(CustomButton::BS_HOT);
View::OnMouseReleased(event, canceled);
}
@@ -222,11 +223,11 @@ class BitmapScrollBarThumb : public View {
// transparently over the background bitmap.
SkBitmap* grippy_bitmap() const {
return scroll_bar_->images_[BitmapScrollBar::THUMB_GRIPPY]
- [BaseButton::BS_NORMAL];
+ [CustomButton::BS_NORMAL];
}
// Update our state and schedule a repaint when the mouse moves over us.
- void SetState(BaseButton::ButtonState state) {
+ void SetState(CustomButton::ButtonState state) {
state_ = state;
SchedulePaint();
}
@@ -241,7 +242,7 @@ class BitmapScrollBarThumb : public View {
int mouse_offset_;
// The current state of the thumb button.
- BaseButton::ButtonState state_;
+ CustomButton::ButtonState state_;
DISALLOW_EVIL_CONSTRUCTORS(BitmapScrollBarThumb);
};
@@ -254,10 +255,10 @@ class BitmapScrollBarThumb : public View {
BitmapScrollBar::BitmapScrollBar(bool horizontal, bool show_scroll_buttons)
: contents_size_(0),
contents_scroll_offset_(0),
- prev_button_(new AutorepeatButton),
- next_button_(new AutorepeatButton),
+ prev_button_(new AutorepeatButton(this)),
+ next_button_(new AutorepeatButton(this)),
thumb_(new BitmapScrollBarThumb(this)),
- thumb_track_state_(BaseButton::BS_NORMAL),
+ thumb_track_state_(CustomButton::BS_NORMAL),
last_scroll_amount_(SCROLL_NONE),
repeater_(NewCallback<BitmapScrollBar>(this,
&BitmapScrollBar::TrackClicked)),
@@ -268,8 +269,6 @@ BitmapScrollBar::BitmapScrollBar(bool horizontal, bool show_scroll_buttons)
prev_button_->SetVisible(false);
next_button_->SetVisible(false);
}
- prev_button_->SetListener(this, -1);
- next_button_->SetListener(this, -1);
AddChildView(prev_button_);
AddChildView(next_button_);
@@ -299,10 +298,10 @@ gfx::Rect BitmapScrollBar::GetTrackBounds() const {
}
void BitmapScrollBar::SetImage(ScrollBarPart part,
- BaseButton::ButtonState state,
+ CustomButton::ButtonState state,
SkBitmap* bitmap) {
DCHECK(part < PART_COUNT);
- DCHECK(state < BaseButton::kButtonStateCount);
+ DCHECK(state < CustomButton::BS_COUNT);
switch (part) {
case PREV_BUTTON:
prev_button_->SetImage(state, bitmap);
@@ -443,7 +442,7 @@ void BitmapScrollBar::Layout() {
bool BitmapScrollBar::OnMousePressed(const MouseEvent& event) {
if (event.IsOnlyLeftMouseButton()) {
- SetThumbTrackState(BaseButton::BS_PUSHED);
+ SetThumbTrackState(CustomButton::BS_PUSHED);
gfx::Rect thumb_bounds = thumb_->bounds();
if (IsHorizontal()) {
if (event.x() < thumb_bounds.x()) {
@@ -465,7 +464,7 @@ bool BitmapScrollBar::OnMousePressed(const MouseEvent& event) {
}
void BitmapScrollBar::OnMouseReleased(const MouseEvent& event, bool canceled) {
- SetThumbTrackState(BaseButton::BS_NORMAL);
+ SetThumbTrackState(CustomButton::BS_NORMAL);
repeater_.Stop();
View::OnMouseReleased(event, canceled);
}
@@ -624,9 +623,9 @@ void BitmapScrollBar::ExecuteCommand(int id) {
}
///////////////////////////////////////////////////////////////////////////////
-// BitmapScrollBar, BaseButton::ButtonListener implementation:
+// BitmapScrollBar, ButtonListener implementation:
-void BitmapScrollBar::ButtonPressed(BaseButton* sender) {
+void BitmapScrollBar::ButtonPressed(Button* sender) {
if (sender == prev_button_) {
ScrollByAmount(SCROLL_PREV_LINE);
} else if (sender == next_button_) {
@@ -696,7 +695,7 @@ int BitmapScrollBar::CalculateContentsOffset(int thumb_position,
return (thumb_position * contents_size_) / GetTrackSize();
}
-void BitmapScrollBar::SetThumbTrackState(BaseButton::ButtonState state) {
+void BitmapScrollBar::SetThumbTrackState(CustomButton::ButtonState state) {
thumb_track_state_ = state;
SchedulePaint();
}
diff --git a/chrome/views/bitmap_scroll_bar.h b/chrome/views/bitmap_scroll_bar.h
index 453c55f..53e9e72 100644
--- a/chrome/views/bitmap_scroll_bar.h
+++ b/chrome/views/bitmap_scroll_bar.h
@@ -5,7 +5,7 @@
#ifndef CHROME_VIEWS_BITMAP_SCROLL_BAR_H__
#define CHROME_VIEWS_BITMAP_SCROLL_BAR_H__
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/menu.h"
#include "chrome/views/repeat_controller.h"
#include "chrome/views/scroll_bar.h"
@@ -33,7 +33,7 @@ class BitmapScrollBarThumb;
//
///////////////////////////////////////////////////////////////////////////////
class BitmapScrollBar : public ScrollBar,
- public BaseButton::ButtonListener,
+ public ButtonListener,
public ContextMenuController,
public Menu::Delegate {
public:
@@ -66,7 +66,7 @@ class BitmapScrollBar : public ScrollBar,
// Sets the bitmap to be rendered for the specified part and state.
void SetImage(ScrollBarPart part,
- BaseButton::ButtonState state,
+ CustomButton::ButtonState state,
SkBitmap* bitmap);
// An enumeration of different amounts of incremental scroll, representing
@@ -103,7 +103,7 @@ class BitmapScrollBar : public ScrollBar,
virtual bool OnKeyPressed(const KeyEvent& event);
// BaseButton::ButtonListener overrides:
- virtual void ButtonPressed(BaseButton* sender);
+ virtual void ButtonPressed(Button* sender);
// ScrollBar overrides:
virtual void Update(int viewport_size,
@@ -146,11 +146,11 @@ class BitmapScrollBar : public ScrollBar,
// Called when the state of the thumb track changes (e.g. by the user
// pressing the mouse button down in it).
- void SetThumbTrackState(BaseButton::ButtonState state);
+ void SetThumbTrackState(CustomButton::ButtonState state);
// The thumb needs to be able to access the part images.
friend BitmapScrollBarThumb;
- SkBitmap* images_[PART_COUNT][BaseButton::kButtonStateCount];
+ SkBitmap* images_[PART_COUNT][CustomButton::BS_COUNT];
// The size of the scrolled contents, in pixels.
int contents_size_;
@@ -159,13 +159,13 @@ class BitmapScrollBar : public ScrollBar,
int contents_scroll_offset_;
// Up/Down/Left/Right buttons and the Thumb.
- Button* prev_button_;
- Button* next_button_;
+ ImageButton* prev_button_;
+ ImageButton* next_button_;
BitmapScrollBarThumb* thumb_;
// The state of the scrollbar track. Typically, the track will highlight when
// the user presses the mouse on them (during page scrolling).
- BaseButton::ButtonState thumb_track_state_;
+ CustomButton::ButtonState thumb_track_state_;
// The last amount of incremental scroll that this scrollbar performed. This
// is accessed by the callbacks for the auto-repeat up/down buttons to know
diff --git a/chrome/views/button.cc b/chrome/views/button.cc
index 0093927..860d8fa 100644
--- a/chrome/views/button.cc
+++ b/chrome/views/button.cc
@@ -4,198 +4,68 @@
#include "chrome/views/button.h"
-#include <atlbase.h>
-#include <atlapp.h>
-
-#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/common/gfx/chrome_canvas.h"
-#include "chrome/common/l10n_util.h"
-#include "chrome/common/throb_animation.h"
-#include "chrome/views/event.h"
-#include "grit/generated_resources.h"
-#include "skia/ext/image_operations.h"
-
namespace views {
-static const int kDefaultWidth = 16; // Default button width if no theme.
-static const int kDefaultHeight = 14; // Default button height if no theme.
-
////////////////////////////////////////////////////////////////////////////////
-//
-// Button - constructors, destructors, initialization
-//
-////////////////////////////////////////////////////////////////////////////////
-
-Button::Button() : BaseButton(),
- h_alignment_(ALIGN_LEFT),
- v_alignment_(ALIGN_TOP) {
- // By default, we request that the ChromeCanvas passed to our View::Paint()
- // implementation is flipped horizontally so that the button's bitmaps are
- // mirrored when the UI directionality is right-to-left.
- EnableCanvasFlippingForRTLUI(true);
-}
+// Button, public:
Button::~Button() {
}
-////////////////////////////////////////////////////////////////////////////////
-//
-// Button - properties
-//
-////////////////////////////////////////////////////////////////////////////////
-
-void Button::SetImage(ButtonState aState, SkBitmap* anImage) {
- images_[aState] = anImage ? *anImage : SkBitmap();
-}
-
-void Button::SetImageAlignment(HorizontalAlignment h_align,
- VerticalAlignment v_align) {
- h_alignment_ = h_align;
- v_alignment_ = v_align;
- SchedulePaint();
-}
-
-gfx::Size Button::GetPreferredSize() {
- if (!images_[BS_NORMAL].isNull())
- return gfx::Size(images_[BS_NORMAL].width(), images_[BS_NORMAL].height());
- return gfx::Size(kDefaultWidth, kDefaultHeight);
-}
-
-// Set the tooltip text for this button.
-void Button::SetTooltipText(const std::wstring& text) {
- tooltip_text_ = text;
+void Button::SetTooltipText(const std::wstring& tooltip_text) {
+ tooltip_text_ = tooltip_text;
TooltipTextChanged();
}
-// Return the tooltip text currently used by this button.
-std::wstring Button::GetTooltipText() const {
- return tooltip_text_;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Button - painting
-//
////////////////////////////////////////////////////////////////////////////////
+// Button, View overrides:
-void Button::Paint(ChromeCanvas* canvas) {
- View::Paint(canvas);
- SkBitmap img = GetImageToPaint();
-
- if (!img.isNull()) {
- int x = 0, y = 0;
-
- if (h_alignment_ == ALIGN_CENTER)
- x = (width() - img.width()) / 2;
- else if (h_alignment_ == ALIGN_RIGHT)
- x = width() - img.width();
-
- if (v_alignment_ == ALIGN_MIDDLE)
- y = (height() - img.height()) / 2;
- else if (v_alignment_ == ALIGN_BOTTOM)
- y = height() - img.height();
-
- canvas->DrawBitmapInt(img, x, y);
+bool Button::GetTooltipText(int x, int y, std::wstring* tooltip) {
+ if (!tooltip_text_.empty()) {
+ *tooltip = tooltip_text_;
+ return true;
}
- PaintFocusBorder(canvas);
+ return false;
}
-SkBitmap Button::GetImageToPaint() {
- SkBitmap img;
-
- if (!images_[BS_HOT].isNull() && hover_animation_->IsAnimating()) {
- img = skia::ImageOperations::CreateBlendedBitmap(images_[BS_NORMAL],
- images_[BS_HOT], hover_animation_->GetCurrentValue());
- } else {
- img = images_[GetState()];
+bool Button::GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
+ if (!accessible_shortcut_.empty()) {
+ *shortcut = accessible_shortcut_;
+ return true;
}
-
- return !img.isNull() ? img : images_[BS_NORMAL];
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// Button - accessibility
-//
-////////////////////////////////////////////////////////////////////////////////
-
-bool Button::GetAccessibleDefaultAction(std::wstring* action) {
- DCHECK(action);
-
- action->assign(l10n_util::GetString(IDS_ACCACTION_PRESS));
- return true;
-}
-
-bool Button::GetAccessibleRole(VARIANT* role) {
- DCHECK(role);
-
- role->vt = VT_I4;
- role->lVal = ROLE_SYSTEM_PUSHBUTTON;
- return true;
-}
-
-bool Button::GetTooltipText(int x, int y, std::wstring* tooltip) {
- if (tooltip_text_.empty())
- return false;
-
- *tooltip = tooltip_text_;
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// ToggleButton
-//
-////////////////////////////////////////////////////////////////////////////////
-ToggleButton::ToggleButton() : Button(), toggled_(false) {
+ return false;
}
-ToggleButton::~ToggleButton() {
-}
-
-void ToggleButton::SetImage(ButtonState state, SkBitmap* image) {
- if (toggled_) {
- alternate_images_[state] = image ? *image : SkBitmap();
- } else {
- images_[state] = image ? *image : SkBitmap();
- if (state_ == state)
- SchedulePaint();
+bool Button::GetAccessibleName(std::wstring* name) {
+ if (!accessible_name_.empty()) {
+ *name = accessible_name_;
+ return true;
}
+ return false;
}
-void ToggleButton::SetToggledImage(ButtonState state, SkBitmap* image) {
- if (toggled_) {
- images_[state] = image ? *image : SkBitmap();
- if (state_ == state)
- SchedulePaint();
- } else {
- alternate_images_[state] = image ? *image : SkBitmap();
- }
+void Button::SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {
+ accessible_shortcut_.assign(shortcut);
}
-bool ToggleButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
- if (!toggled_ || toggled_tooltip_text_.empty())
- return Button::GetTooltipText(x, y, tooltip);
-
- *tooltip = toggled_tooltip_text_;
- return true;
+void Button::SetAccessibleName(const std::wstring& name) {
+ accessible_name_.assign(name);
}
-void ToggleButton::SetToggled(bool toggled) {
- if (toggled == toggled_)
- return;
+////////////////////////////////////////////////////////////////////////////////
+// Button, protected:
- for (int i = 0; i < kButtonStateCount; ++i) {
- SkBitmap temp = images_[i];
- images_[i] = alternate_images_[i];
- alternate_images_[i] = temp;
- }
- toggled_ = toggled;
- SchedulePaint();
+Button::Button(ButtonListener* listener)
+ : listener_(listener),
+ tag_(-1),
+ mouse_event_flags_(0) {
}
-void ToggleButton::SetToggledTooltipText(const std::wstring& tooltip) {
- toggled_tooltip_text_.assign(tooltip);
+void Button::NotifyClick(int mouse_event_flags) {
+ mouse_event_flags_ = mouse_event_flags;
+ listener_->ButtonPressed(this);
+ // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have
+ // deleted us.
}
} // namespace views
diff --git a/chrome/views/button.h b/chrome/views/button.h
index df8c463..a29fb78 100644
--- a/chrome/views/button.h
+++ b/chrome/views/button.h
@@ -5,125 +5,68 @@
#ifndef CHROME_VIEWS_BUTTON_H_
#define CHROME_VIEWS_BUTTON_H_
-#include "chrome/views/base_button.h"
-#include "skia/include/SkBitmap.h"
+#include "chrome/views/view.h"
namespace views {
-////////////////////////////////////////////////////////////////////////////////
-//
-// Button
-//
-// A simple button class
-//
-////////////////////////////////////////////////////////////////////////////////
-class Button : public BaseButton {
- public:
- //
- // Create a Button
- Button();
- virtual ~Button();
-
- //
- // Set the image the button should use for the provided state.
- virtual void SetImage(ButtonState aState, SkBitmap* anImage);
-
- enum HorizontalAlignment { ALIGN_LEFT = 0,
- ALIGN_CENTER,
- ALIGN_RIGHT, };
+class Button;
- enum VerticalAlignment {ALIGN_TOP = 0,
- ALIGN_MIDDLE,
- ALIGN_BOTTOM };
-
- void SetImageAlignment(HorizontalAlignment h_align,
- VerticalAlignment v_align);
-
- //
- // Computes the minimum size given the current theme and graphics
- gfx::Size GetPreferredSize();
+// An interface implemented by an object to let it know that a button was
+// pressed.
+class ButtonListener {
+ public:
+ virtual void ButtonPressed(Button* sender) = 0;
+};
- // Returns the MSAA default action of the current view. The string returned
- // describes the default action that will occur when executing
- // IAccessible::DoDefaultAction.
- bool GetAccessibleDefaultAction(std::wstring* action);
+// A View representing a button. Depending on the specific type, the button
+// could be implemented by a native control or custom rendered.
+class Button : public View {
+ public:
+ virtual ~Button();
- // Returns the MSAA role of the current view. The role is what assistive
- // technologies (ATs) use to determine what behavior to expect from a given
- // control.
- bool GetAccessibleRole(VARIANT* role);
+ void SetTooltipText(const std::wstring& tooltip_text);
- // Set the tooltip text for this button.
- void SetTooltipText(const std::wstring& text);
+ int tag() const { return tag_; }
+ void set_tag(int tag) { tag_ = tag; }
- // Return the tooltip text currently used by this button.
- std::wstring GetTooltipText() const;
+ int mouse_event_flags() const { return mouse_event_flags_; }
- // Overridden from View.
+ // Overridden from View:
virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
- protected:
+ virtual bool GetAccessibleKeyboardShortcut(std::wstring* shortcut);
+ virtual bool GetAccessibleName(std::wstring* name);
+ virtual void SetAccessibleKeyboardShortcut(const std::wstring& shortcut);
+ virtual void SetAccessibleName(const std::wstring& name);
- // Overridden to render the button.
- virtual void Paint(ChromeCanvas* canvas);
-
- // Returns the image to paint. This is invoked from paint and returns a value
- // from images.
- virtual SkBitmap GetImageToPaint();
-
- // Images.
- SkBitmap images_[kButtonStateCount];
+ protected:
+ // Construct the Button with a Listener. The listener can be NULL, as long as
+ // the specific button implementation makes sure to not call NotifyClick. This
+ // can be true of buttons that don't have a listener - e.g. menubuttons where
+ // there's no default action.
+ explicit Button(ButtonListener* listener);
- // Alignment State.
- HorizontalAlignment h_alignment_;
- VerticalAlignment v_alignment_;
+ // Cause the button to notify the listener that a click occurred.
+ virtual void NotifyClick(int mouse_event_flags);
- // The tooltip text or empty string for none.
+ private:
+ // The text shown in a tooltip.
std::wstring tooltip_text_;
- DISALLOW_COPY_AND_ASSIGN(Button);
-};
+ // Accessibility data.
+ std::wstring accessible_shortcut_;
+ std::wstring accessible_name_;
-////////////////////////////////////////////////////////////////////////////////
-//
-// ToggleButton
-//
-// A togglable button. It swaps out its graphics when toggled.
-//
-////////////////////////////////////////////////////////////////////////////////
-class ToggleButton : public Button {
- public:
- ToggleButton();
- virtual ~ToggleButton();
+ // The button's listener. Notified when clicked.
+ ButtonListener* listener_;
- // Overridden from Button.
- virtual void SetImage(ButtonState aState, SkBitmap* anImage);
-
- // Like Button::SetImage(), but to set the graphics used for the
- // "has been toggled" state. Must be called for each button state
- // before the button is toggled.
- void SetToggledImage(ButtonState state, SkBitmap* image);
-
- virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
+ // The id tag associated with this button. Used to disambiguate buttons in
+ // the ButtonListener implementation.
+ int tag_;
- // Set the tooltip text displayed when the button is toggled.
- void SetToggledTooltipText(const std::wstring& tooltip);
+ // Event flags present when the button was clicked.
+ int mouse_event_flags_;
- // Change the toggled state.
- void SetToggled(bool toggled);
-
- private:
- // The parent class's images_ member is used for the current images,
- // and this array is used to hold the alternative images.
- // We swap between the two when toggling.
- SkBitmap alternate_images_[kButtonStateCount];
-
- bool toggled_;
-
- // The parent class's tooltip_text_ is displayed when not toggled, and
- // this one is shown when toggled.
- std::wstring toggled_tooltip_text_;
-
- DISALLOW_EVIL_CONSTRUCTORS(ToggleButton);
+ DISALLOW_COPY_AND_ASSIGN(Button);
};
} // namespace views
diff --git a/chrome/views/button_dropdown.cc b/chrome/views/button_dropdown.cc
index 6428598..9d30561 100644
--- a/chrome/views/button_dropdown.cc
+++ b/chrome/views/button_dropdown.cc
@@ -22,11 +22,12 @@ static const int kMenuTimerDelay = 500;
//
////////////////////////////////////////////////////////////////////////////////
-ButtonDropDown::ButtonDropDown(Menu::Delegate* menu_delegate)
- : Button(),
- menu_delegate_(menu_delegate),
- y_position_on_lbuttondown_(0),
- show_menu_factory_(this) {
+ButtonDropDown::ButtonDropDown(ButtonListener* listener,
+ Menu::Delegate* menu_delegate)
+ : ImageButton(listener),
+ menu_delegate_(menu_delegate),
+ y_position_on_lbuttondown_(0),
+ show_menu_factory_(this) {
}
ButtonDropDown::~ButtonDropDown() {
@@ -52,11 +53,11 @@ bool ButtonDropDown::OnMousePressed(const MouseEvent& e) {
kMenuTimerDelay);
}
- return Button::OnMousePressed(e);
+ return ImageButton::OnMousePressed(e);
}
void ButtonDropDown::OnMouseReleased(const MouseEvent& e, bool canceled) {
- Button::OnMouseReleased(e, canceled);
+ ImageButton::OnMouseReleased(e, canceled);
if (canceled)
return;
@@ -77,7 +78,7 @@ void ButtonDropDown::OnMouseReleased(const MouseEvent& e, bool canceled) {
}
bool ButtonDropDown::OnMouseDragged(const MouseEvent& e) {
- bool result = Button::OnMouseDragged(e);
+ bool result = ImageButton::OnMouseDragged(e);
if (!show_menu_factory_.empty()) {
// SM_CYDRAG is a pixel value for minimum dragging distance before operation
diff --git a/chrome/views/button_dropdown.h b/chrome/views/button_dropdown.h
index 380426c..e92204b 100644
--- a/chrome/views/button_dropdown.h
+++ b/chrome/views/button_dropdown.h
@@ -6,7 +6,7 @@
#define CHROME_VIEWS_BUTTON_DROPDOWN_H__
#include "base/task.h"
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/menu.h"
namespace views {
@@ -19,9 +19,9 @@ namespace views {
// display a menu
//
////////////////////////////////////////////////////////////////////////////////
-class ButtonDropDown : public Button {
+class ButtonDropDown : public ImageButton {
public:
- explicit ButtonDropDown(Menu::Delegate* menu_delegate);
+ ButtonDropDown(ButtonListener* listener, Menu::Delegate* menu_delegate);
virtual ~ButtonDropDown();
// Returns the MSAA default action of the current view. The string returned
diff --git a/chrome/views/base_button.cc b/chrome/views/custom_button.cc
index 26b123f..70c8fc7 100644
--- a/chrome/views/base_button.cc
+++ b/chrome/views/custom_button.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/views/base_button.h"
+#include "chrome/views/custom_button.h"
#include "base/base_drag_source.h"
#include "chrome/browser/drag_utils.h"
@@ -17,43 +17,19 @@ namespace views {
static const int kHoverFadeDurationMs = 150;
////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton - constructors, destructors, initialization
-//
-////////////////////////////////////////////////////////////////////////////////
-
-BaseButton::BaseButton()
- : listener_(NULL),
- tag_(-1),
- state_(BS_NORMAL),
- mouse_event_flags_(0),
- animate_on_state_change_(true) {
- hover_animation_.reset(new ThrobAnimation(this));
- hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
-}
-
-BaseButton::~BaseButton() {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton - properties
-//
-////////////////////////////////////////////////////////////////////////////////
+// CustomButton, public:
-bool BaseButton::IsTriggerableEvent(const MouseEvent& e) {
- return e.IsLeftMouseButton();
+CustomButton::~CustomButton() {
}
-void BaseButton::SetState(BaseButton::ButtonState new_state) {
- if (new_state != state_) {
+void CustomButton::SetState(ButtonState state) {
+ if (state != state_) {
if (animate_on_state_change_ || !hover_animation_->IsAnimating()) {
animate_on_state_change_ = true;
- if (state_ == BaseButton::BS_NORMAL && new_state == BaseButton::BS_HOT) {
+ if (state_ == BS_NORMAL && state == BS_HOT) {
// Button is hovered from a normal state, start hover animation.
hover_animation_->Show();
- } else if (state_ == BaseButton::BS_HOT &&
- new_state == BaseButton::BS_NORMAL) {
+ } else if (state_ == BS_HOT && state == BS_NORMAL) {
// Button is returning to a normal state from hover, start hover
// fade animation.
hover_animation_->Hide();
@@ -62,97 +38,76 @@ void BaseButton::SetState(BaseButton::ButtonState new_state) {
}
}
- state_ = new_state;
+ state_ = state;
SchedulePaint();
}
}
-void BaseButton::SetEnabled(bool f) {
- if (f && state_ == BS_DISABLED) {
- SetState(BS_NORMAL);
- } else if (!f && state_ != BS_DISABLED) {
- SetState(BS_DISABLED);
- }
-}
-
-void BaseButton::SetAnimationDuration(int duration) {
- hover_animation_->SetSlideDuration(duration);
-}
-
-void BaseButton::StartThrobbing(int cycles_til_stop) {
+void CustomButton::StartThrobbing(int cycles_til_stop) {
animate_on_state_change_ = false;
hover_animation_->StartThrobbing(cycles_til_stop);
}
-bool BaseButton::IsEnabled() const {
- return state_ != BS_DISABLED;
+void CustomButton::SetAnimationDuration(int duration) {
+ hover_animation_->SetSlideDuration(duration);
}
-void BaseButton::SetHotTracked(bool f) {
- if (f && state_ != BS_DISABLED) {
- SetState(BS_HOT);
- } else if (!f && state_ != BS_DISABLED) {
+////////////////////////////////////////////////////////////////////////////////
+// CustomButton, View overrides:
+
+void CustomButton::SetEnabled(bool enabled) {
+ if (enabled && state_ == BS_DISABLED) {
SetState(BS_NORMAL);
+ } else if (!enabled && state_ != BS_DISABLED) {
+ SetState(BS_DISABLED);
}
}
-bool BaseButton::IsHotTracked() const {
- return state_ == BS_HOT;
+bool CustomButton::IsEnabled() const {
+ return state_ != BS_DISABLED;
}
-bool BaseButton::IsPushed() const {
- return state_ == BS_PUSHED;
+bool CustomButton::IsFocusable() const {
+ return (state_ != BS_DISABLED) && View::IsFocusable();
}
-void BaseButton::SetListener(ButtonListener *l, int tag) {
- listener_ = l;
- tag_ = tag;
-}
+////////////////////////////////////////////////////////////////////////////////
+// CustomButton, protected:
-int BaseButton::GetTag() {
- return tag_;
+CustomButton::CustomButton(ButtonListener* listener)
+ : Button(listener),
+ state_(BS_NORMAL),
+ animate_on_state_change_(true) {
+ hover_animation_.reset(new ThrobAnimation(this));
+ hover_animation_->SetSlideDuration(kHoverFadeDurationMs);
}
-bool BaseButton::IsFocusable() const {
- return (state_ != BS_DISABLED) && View::IsFocusable();
+bool CustomButton::IsTriggerableEvent(const MouseEvent& e) {
+ return e.IsLeftMouseButton();
}
////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton - Tooltips
-//
-////////////////////////////////////////////////////////////////////////////////
+// CustomButton, View overrides (protected):
-bool BaseButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
- if (!tooltip_text_.empty()) {
- *tooltip = tooltip_text_;
+bool CustomButton::AcceleratorPressed(const Accelerator& accelerator) {
+ if (enabled_) {
+ SetState(BS_NORMAL);
+ NotifyClick(0);
return true;
}
return false;
}
-void BaseButton::SetTooltipText(const std::wstring& tooltip) {
- tooltip_text_.assign(tooltip);
- TooltipTextChanged();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton - Events
-//
-////////////////////////////////////////////////////////////////////////////////
-
-bool BaseButton::OnMousePressed(const MouseEvent& e) {
+bool CustomButton::OnMousePressed(const MouseEvent& e) {
if (state_ != BS_DISABLED) {
- if (IsTriggerableEvent(e) && HitTest(e.location())) {
+ if (IsTriggerableEvent(e) && HitTest(e.location()))
SetState(BS_PUSHED);
- }
RequestFocus();
}
return true;
}
-bool BaseButton::OnMouseDragged(const MouseEvent& e) {
+bool CustomButton::OnMouseDragged(const MouseEvent& e) {
if (state_ != BS_DISABLED) {
if (!HitTest(e.location()))
SetState(BS_NORMAL);
@@ -164,7 +119,7 @@ bool BaseButton::OnMouseDragged(const MouseEvent& e) {
return true;
}
-void BaseButton::OnMouseReleased(const MouseEvent& e, bool canceled) {
+void CustomButton::OnMouseReleased(const MouseEvent& e, bool canceled) {
if (InDrag()) {
// Starting a drag results in a MouseReleased, we need to ignore it.
return;
@@ -185,12 +140,12 @@ void BaseButton::OnMouseReleased(const MouseEvent& e, bool canceled) {
}
}
-void BaseButton::OnMouseEntered(const MouseEvent& e) {
+void CustomButton::OnMouseEntered(const MouseEvent& e) {
if (state_ != BS_DISABLED)
SetState(BS_HOT);
}
-void BaseButton::OnMouseMoved(const MouseEvent& e) {
+void CustomButton::OnMouseMoved(const MouseEvent& e) {
if (state_ != BS_DISABLED) {
if (HitTest(e.location())) {
SetState(BS_HOT);
@@ -200,21 +155,13 @@ void BaseButton::OnMouseMoved(const MouseEvent& e) {
}
}
-void BaseButton::OnMouseExited(const MouseEvent& e) {
+void CustomButton::OnMouseExited(const MouseEvent& e) {
// Starting a drag results in a MouseExited, we need to ignore it.
if (state_ != BS_DISABLED && !InDrag())
SetState(BS_NORMAL);
}
-void BaseButton::NotifyClick(int mouse_event_flags) {
- mouse_event_flags_ = mouse_event_flags;
- if (listener_ != NULL)
- listener_->ButtonPressed(this);
- // NOTE: don't attempt to reset mouse_event_flags_ as the listener may have
- // deleted us.
-}
-
-bool BaseButton::OnKeyPressed(const KeyEvent& e) {
+bool CustomButton::OnKeyPressed(const KeyEvent& e) {
if (state_ != BS_DISABLED) {
// Space sets button state to pushed. Enter clicks the button. This matches
// the Windows native behavior of buttons, where Space clicks the button
@@ -231,7 +178,7 @@ bool BaseButton::OnKeyPressed(const KeyEvent& e) {
return false;
}
-bool BaseButton::OnKeyReleased(const KeyEvent& e) {
+bool CustomButton::OnKeyReleased(const KeyEvent& e) {
if (state_ != BS_DISABLED) {
if (e.GetCharacter() == VK_SPACE) {
SetState(BS_NORMAL);
@@ -242,75 +189,51 @@ bool BaseButton::OnKeyReleased(const KeyEvent& e) {
return false;
}
-void BaseButton::ShowContextMenu(int x, int y, bool is_mouse_gesture) {
+void CustomButton::OnDragDone() {
+ SetState(BS_NORMAL);
+}
+
+void CustomButton::ShowContextMenu(int x, int y, bool is_mouse_gesture) {
if (GetContextMenuController()) {
// We're about to show the context menu. Showing the context menu likely
// means we won't get a mouse exited and reset state. Reset it now to be
// sure.
- if (GetState() != BS_DISABLED)
+ if (state_ != BS_DISABLED)
SetState(BS_NORMAL);
View::ShowContextMenu(x, y, is_mouse_gesture);
}
}
-bool BaseButton::AcceleratorPressed(const Accelerator& accelerator) {
- if (enabled_) {
- SetState(BS_NORMAL);
- NotifyClick(0);
- return true;
- }
- return false;
-}
-
-void BaseButton::AnimationProgressed(const Animation* animation) {
- SchedulePaint();
-}
-
-void BaseButton::OnDragDone() {
- SetState(BS_NORMAL);
-}
-
-void BaseButton::ViewHierarchyChanged(bool is_add, View *parent, View *child) {
+void CustomButton::ViewHierarchyChanged(bool is_add, View *parent,
+ View *child) {
if (!is_add && state_ != BS_DISABLED)
SetState(BS_NORMAL);
}
////////////////////////////////////////////////////////////////////////////////
-//
-// BaseButton - Accessibility
-//
-////////////////////////////////////////////////////////////////////////////////
+// CustomButton, AnimationDelegate implementation:
-bool BaseButton::GetAccessibleKeyboardShortcut(std::wstring* shortcut) {
- if (!accessible_shortcut_.empty()) {
- *shortcut = accessible_shortcut_;
- return true;
- }
- return false;
-}
-
-bool BaseButton::GetAccessibleName(std::wstring* name) {
- if (!accessible_name_.empty()) {
- *name = accessible_name_;
- return true;
- }
- return false;
+void CustomButton::AnimationProgressed(const Animation* animation) {
+ SchedulePaint();
}
-void BaseButton::SetAccessibleKeyboardShortcut(const std::wstring& shortcut) {
- accessible_shortcut_.assign(shortcut);
-}
+////////////////////////////////////////////////////////////////////////////////
+// CustomButton, private:
-void BaseButton::SetAccessibleName(const std::wstring& name) {
- accessible_name_.assign(name);
+void CustomButton::SetHighlighted(bool highlighted) {
+ if (highlighted && state_ != BS_DISABLED) {
+ SetState(BS_HOT);
+ } else if (!highlighted && state_ != BS_DISABLED) {
+ SetState(BS_NORMAL);
+ }
}
-void BaseButton::Paint(ChromeCanvas* canvas) {
- View::Paint(canvas);
+bool CustomButton::IsHighlighted() const {
+ return state_ == BS_HOT;
}
-void BaseButton::Paint(ChromeCanvas* canvas, bool for_drag) {
- Paint(canvas);
+bool CustomButton::IsPushed() const {
+ return state_ == BS_PUSHED;
}
} // namespace views
diff --git a/chrome/views/custom_button.h b/chrome/views/custom_button.h
new file mode 100644
index 0000000..eeeb22c
--- /dev/null
+++ b/chrome/views/custom_button.h
@@ -0,0 +1,94 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_VIEWS_CUSTOM_BUTTON_H_
+#define CHROME_VIEWS_CUSTOM_BUTTON_H_
+
+#include "chrome/common/animation.h"
+#include "chrome/views/button.h"
+
+class ThrobAnimation;
+
+namespace views {
+
+// A button with custom rendering. The common base class of IconButton and
+// TextButton.
+class CustomButton : public Button,
+ public AnimationDelegate {
+ public:
+ virtual ~CustomButton();
+
+ // Possible states
+ enum ButtonState {
+ BS_NORMAL = 0,
+ BS_HOT,
+ BS_PUSHED,
+ BS_DISABLED,
+ BS_COUNT
+ };
+
+ // Get/sets the current display state of the button.
+ ButtonState state() const { return state_; }
+ void SetState(ButtonState state);
+
+ // Starts throbbing. See HoverAnimation for a description of cycles_til_stop.
+ void StartThrobbing(int cycles_til_stop);
+
+ // Set how long the hover animation will last for.
+ void SetAnimationDuration(int duration);
+
+ // Overridden from View:
+ virtual void SetEnabled(bool enabled);
+ virtual bool IsEnabled() const;
+ virtual bool IsFocusable() const;
+
+ protected:
+ // Construct the Button with a Listener. See comment for Button's ctor.
+ explicit CustomButton(ButtonListener* listener);
+
+ // Returns true if the event is one that can trigger notifying the listener.
+ // This implementation returns true if the left mouse button is down.
+ virtual bool IsTriggerableEvent(const MouseEvent& e);
+
+ // Overridden from View:
+ virtual bool AcceleratorPressed(const Accelerator& accelerator);
+ virtual bool OnMousePressed(const MouseEvent& e);
+ virtual bool OnMouseDragged(const MouseEvent& e);
+ virtual void OnMouseReleased(const MouseEvent& e, bool canceled);
+ virtual void OnMouseEntered(const MouseEvent& e);
+ virtual void OnMouseMoved(const MouseEvent& e);
+ virtual void OnMouseExited(const MouseEvent& e);
+ virtual bool OnKeyPressed(const KeyEvent& e);
+ virtual bool OnKeyReleased(const KeyEvent& e);
+ virtual void OnDragDone();
+ virtual void ShowContextMenu(int x, int y, bool is_mouse_gesture);
+ virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child);
+
+ // Overridden from AnimationDelegate:
+ virtual void AnimationProgressed(const Animation* animation);
+
+ // The button state (defined in implementation)
+ ButtonState state_;
+
+ // Hover animation.
+ scoped_ptr<ThrobAnimation> hover_animation_;
+
+ private:
+ // Set / test whether the button is highlighted (in the hover state).
+ void SetHighlighted(bool highlighted);
+ bool IsHighlighted() const;
+
+ // Returns whether the button is pushed.
+ bool IsPushed() const;
+
+ // Should we animate when the state changes? Defaults to true, but false while
+ // throbbing.
+ bool animate_on_state_change_;
+
+ DISALLOW_COPY_AND_ASSIGN(CustomButton);
+};
+
+} // namespace views
+
+#endif // CHROME_VIEWS_CUSTOM_BUTTON_H_
diff --git a/chrome/views/custom_frame_view.cc b/chrome/views/custom_frame_view.cc
index d9db4b2..d330be0 100644
--- a/chrome/views/custom_frame_view.cc
+++ b/chrome/views/custom_frame_view.cc
@@ -219,45 +219,41 @@ const int kCaptionTopSpacing = 1;
CustomFrameView::CustomFrameView(Window* frame)
: NonClientFrameView(),
- close_button_(new Button),
- restore_button_(new Button),
- maximize_button_(new Button),
- minimize_button_(new Button),
- system_menu_button_(new Button),
+ close_button_(new ImageButton(this)),
+ restore_button_(new ImageButton(this)),
+ maximize_button_(new ImageButton(this)),
+ minimize_button_(new ImageButton(this)),
+ system_menu_button_(new ImageButton(this)),
should_show_minmax_buttons_(false),
frame_(frame) {
InitClass();
WindowResources* resources = active_resources_;
// Close button images will be set in LayoutWindowControls().
- close_button_->SetListener(this, -1);
AddChildView(close_button_);
- restore_button_->SetImage(Button::BS_NORMAL,
+ restore_button_->SetImage(CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON));
- restore_button_->SetImage(Button::BS_HOT,
+ restore_button_->SetImage(CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON_H));
- restore_button_->SetImage(Button::BS_PUSHED,
+ restore_button_->SetImage(CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_RESTORE_BUTTON_ICON_P));
- restore_button_->SetListener(this, -1);
AddChildView(restore_button_);
- maximize_button_->SetImage(Button::BS_NORMAL,
+ maximize_button_->SetImage(CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON));
- maximize_button_->SetImage(Button::BS_HOT,
+ maximize_button_->SetImage(CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON_H));
- maximize_button_->SetImage(Button::BS_PUSHED,
+ maximize_button_->SetImage(CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_MAXIMIZE_BUTTON_ICON_P));
- maximize_button_->SetListener(this, -1);
AddChildView(maximize_button_);
- minimize_button_->SetImage(Button::BS_NORMAL,
+ minimize_button_->SetImage(CustomButton::BS_NORMAL,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON));
- minimize_button_->SetImage(Button::BS_HOT,
+ minimize_button_->SetImage(CustomButton::BS_HOT,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_H));
- minimize_button_->SetImage(Button::BS_PUSHED,
+ minimize_button_->SetImage(CustomButton::BS_PUSHED,
resources->GetPartBitmap(FRAME_MINIMIZE_BUTTON_ICON_P));
- minimize_button_->SetListener(this, -1);
AddChildView(minimize_button_);
should_show_minmax_buttons_ = frame_->GetDelegate()->CanMaximize();
@@ -344,9 +340,9 @@ void CustomFrameView::EnableClose(bool enable) {
}
void CustomFrameView::ResetWindowControls() {
- restore_button_->SetState(Button::BS_NORMAL);
- minimize_button_->SetState(Button::BS_NORMAL);
- maximize_button_->SetState(Button::BS_NORMAL);
+ restore_button_->SetState(CustomButton::BS_NORMAL);
+ minimize_button_->SetState(CustomButton::BS_NORMAL);
+ maximize_button_->SetState(CustomButton::BS_NORMAL);
// The close button isn't affected by this constraint.
}
@@ -378,9 +374,9 @@ gfx::Size CustomFrameView::GetPreferredSize() {
}
///////////////////////////////////////////////////////////////////////////////
-// CustomFrameView, BaseButton::ButtonListener implementation:
+// CustomFrameView, ButtonListener implementation:
-void CustomFrameView::ButtonPressed(BaseButton* sender) {
+void CustomFrameView::ButtonPressed(Button* sender) {
if (sender == close_button_)
frame_->Close();
else if (sender == minimize_button_)
@@ -560,7 +556,8 @@ void CustomFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) {
}
void CustomFrameView::LayoutWindowControls() {
- close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM);
+ close_button_->SetImageAlignment(ImageButton::ALIGN_LEFT,
+ ImageButton::ALIGN_BOTTOM);
// Maximized buttons start at window top so that even if their images aren't
// drawn flush with the screen edge, they still obey Fitts' Law.
bool is_maximized = frame_->IsMaximized();
@@ -583,24 +580,25 @@ void CustomFrameView::LayoutWindowControls() {
// When the window is restored, we show a maximized button; otherwise, we show
// a restore button.
bool is_restored = !is_maximized && !frame_->IsMinimized();
- views::Button* invisible_button = is_restored ?
+ views::ImageButton* invisible_button = is_restored ?
restore_button_ : maximize_button_;
invisible_button->SetVisible(false);
- views::Button* visible_button = is_restored ?
+ views::ImageButton* visible_button = is_restored ?
maximize_button_ : restore_button_;
FramePartBitmap normal_part, hot_part, pushed_part;
if (should_show_minmax_buttons_) {
visible_button->SetVisible(true);
- visible_button->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM);
+ visible_button->SetImageAlignment(ImageButton::ALIGN_LEFT,
+ ImageButton::ALIGN_BOTTOM);
gfx::Size visible_button_size = visible_button->GetPreferredSize();
visible_button->SetBounds(close_button_->x() - visible_button_size.width(),
caption_y, visible_button_size.width(),
visible_button_size.height() + top_extra_height);
minimize_button_->SetVisible(true);
- minimize_button_->SetImageAlignment(Button::ALIGN_LEFT,
- Button::ALIGN_BOTTOM);
+ minimize_button_->SetImageAlignment(ImageButton::ALIGN_LEFT,
+ ImageButton::ALIGN_BOTTOM);
gfx::Size minimize_button_size = minimize_button_->GetPreferredSize();
minimize_button_->SetBounds(
visible_button->x() - minimize_button_size.width(), caption_y,
@@ -619,11 +617,11 @@ void CustomFrameView::LayoutWindowControls() {
pushed_part = FRAME_CLOSE_BUTTON_ICON_SA_P;
}
- close_button_->SetImage(Button::BS_NORMAL,
+ close_button_->SetImage(CustomButton::BS_NORMAL,
active_resources_->GetPartBitmap(normal_part));
- close_button_->SetImage(Button::BS_HOT,
+ close_button_->SetImage(CustomButton::BS_HOT,
active_resources_->GetPartBitmap(hot_part));
- close_button_->SetImage(Button::BS_PUSHED,
+ close_button_->SetImage(CustomButton::BS_PUSHED,
active_resources_->GetPartBitmap(pushed_part));
}
diff --git a/chrome/views/custom_frame_view.h b/chrome/views/custom_frame_view.h
index 2a47c73..2edc3f9 100644
--- a/chrome/views/custom_frame_view.h
+++ b/chrome/views/custom_frame_view.h
@@ -5,7 +5,7 @@
#ifndef CHROME_VIEWS_CUSTOM_FRAME_VIEW_H_
#define CHROME_VIEWS_CUSTOM_FRAME_VIEW_H_
-#include "chrome/views/button.h"
+#include "chrome/views/image_button.h"
#include "chrome/views/non_client_view.h"
#include "chrome/views/window.h"
#include "chrome/views/window_resources.h"
@@ -29,7 +29,7 @@ namespace views {
//
////////////////////////////////////////////////////////////////////////////////
class CustomFrameView : public NonClientFrameView,
- public BaseButton::ButtonListener {
+ public ButtonListener {
public:
explicit CustomFrameView(Window* frame);
virtual ~CustomFrameView();
@@ -49,8 +49,8 @@ class CustomFrameView : public NonClientFrameView,
virtual void Layout();
virtual gfx::Size GetPreferredSize();
- // BaseButton::ButtonListener implementation:
- virtual void ButtonPressed(BaseButton* sender);
+ // ButtonListener implementation:
+ virtual void ButtonPressed(Button* sender);
private:
// Returns the thickness of the border that makes up the window frame edges.
@@ -98,11 +98,11 @@ class CustomFrameView : public NonClientFrameView,
gfx::Rect title_bounds_;
// Window controls.
- Button* close_button_;
- Button* restore_button_;
- Button* maximize_button_;
- Button* minimize_button_;
- Button* system_menu_button_; // Uses the window icon if visible.
+ ImageButton* close_button_;
+ ImageButton* restore_button_;
+ ImageButton* maximize_button_;
+ ImageButton* minimize_button_;
+ ImageButton* system_menu_button_; // Uses the window icon if visible.
bool should_show_minmax_buttons_;
// The window that owns this view.
diff --git a/chrome/views/image_button.cc b/chrome/views/image_button.cc
new file mode 100644
index 0000000..e6e370f
--- /dev/null
+++ b/chrome/views/image_button.cc
@@ -0,0 +1,157 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/views/image_button.h"
+
+#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/l10n_util.h"
+#include "chrome/common/throb_animation.h"
+#include "grit/generated_resources.h"
+#include "skia/ext/image_operations.h"
+
+namespace views {
+
+static const int kDefaultWidth = 16; // Default button width if no theme.
+static const int kDefaultHeight = 14; // Default button height if no theme.
+
+////////////////////////////////////////////////////////////////////////////////
+// ImageButton, public:
+
+ImageButton::ImageButton(ButtonListener* listener)
+ : CustomButton(listener),
+ h_alignment_(ALIGN_LEFT),
+ v_alignment_(ALIGN_TOP) {
+ // By default, we request that the ChromeCanvas passed to our View::Paint()
+ // implementation is flipped horizontally so that the button's bitmaps are
+ // mirrored when the UI directionality is right-to-left.
+ EnableCanvasFlippingForRTLUI(true);
+}
+
+ImageButton::~ImageButton() {
+}
+
+void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) {
+ images_[aState] = anImage ? *anImage : SkBitmap();
+}
+
+void ImageButton::SetImageAlignment(HorizontalAlignment h_align,
+ VerticalAlignment v_align) {
+ h_alignment_ = h_align;
+ v_alignment_ = v_align;
+ SchedulePaint();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ImageButton, View overrides:
+
+gfx::Size ImageButton::GetPreferredSize() {
+ if (!images_[BS_NORMAL].isNull())
+ return gfx::Size(images_[BS_NORMAL].width(), images_[BS_NORMAL].height());
+ return gfx::Size(kDefaultWidth, kDefaultHeight);
+}
+
+void ImageButton::Paint(ChromeCanvas* canvas) {
+ // Call the base class first to paint any background/borders.
+ View::Paint(canvas);
+
+ SkBitmap img = GetImageToPaint();
+
+ if (!img.isNull()) {
+ int x = 0, y = 0;
+
+ if (h_alignment_ == ALIGN_CENTER)
+ x = (width() - img.width()) / 2;
+ else if (h_alignment_ == ALIGN_RIGHT)
+ x = width() - img.width();
+
+ if (v_alignment_ == ALIGN_MIDDLE)
+ y = (height() - img.height()) / 2;
+ else if (v_alignment_ == ALIGN_BOTTOM)
+ y = height() - img.height();
+
+ canvas->DrawBitmapInt(img, x, y);
+ }
+ PaintFocusBorder(canvas);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ImageButton, protected:
+
+SkBitmap ImageButton::GetImageToPaint() {
+ SkBitmap img;
+
+ if (!images_[BS_HOT].isNull() && hover_animation_->IsAnimating()) {
+ img = skia::ImageOperations::CreateBlendedBitmap(images_[BS_NORMAL],
+ images_[BS_HOT], hover_animation_->GetCurrentValue());
+ } else {
+ img = images_[state_];
+ }
+
+ return !img.isNull() ? img : images_[BS_NORMAL];
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ToggleImageButton, public:
+
+ToggleImageButton::ToggleImageButton(ButtonListener* listener)
+ : ImageButton(listener),
+ toggled_(false) {
+}
+
+ToggleImageButton::~ToggleImageButton() {
+}
+
+void ToggleImageButton::SetToggled(bool toggled) {
+ if (toggled == toggled_)
+ return;
+
+ for (int i = 0; i < BS_COUNT; ++i) {
+ SkBitmap temp = images_[i];
+ images_[i] = alternate_images_[i];
+ alternate_images_[i] = temp;
+ }
+ toggled_ = toggled;
+ SchedulePaint();
+}
+
+void ToggleImageButton::SetToggledImage(ButtonState state, SkBitmap* image) {
+ if (toggled_) {
+ images_[state] = image ? *image : SkBitmap();
+ if (state_ == state)
+ SchedulePaint();
+ } else {
+ alternate_images_[state] = image ? *image : SkBitmap();
+ }
+}
+
+void ToggleImageButton::SetToggledTooltipText(const std::wstring& tooltip) {
+ toggled_tooltip_text_.assign(tooltip);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ToggleImageButton, ImageButton overrides:
+
+void ToggleImageButton::SetImage(ButtonState state, SkBitmap* image) {
+ if (toggled_) {
+ alternate_images_[state] = image ? *image : SkBitmap();
+ } else {
+ images_[state] = image ? *image : SkBitmap();
+ if (state_ == state)
+ SchedulePaint();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ToggleImageButton, View overrides:
+
+bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) {
+ if (!toggled_ || toggled_tooltip_text_.empty())
+ return Button::GetTooltipText(x, y, tooltip);
+
+ *tooltip = toggled_tooltip_text_;
+ return true;
+}
+
+} // namespace views
diff --git a/chrome/views/image_button.h b/chrome/views/image_button.h
new file mode 100644
index 0000000..f39753e
--- /dev/null
+++ b/chrome/views/image_button.h
@@ -0,0 +1,101 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_VIEWS_IMAGE_BUTTON_H_
+#define CHROME_VIEWS_IMAGE_BUTTON_H_
+
+#include "chrome/views/custom_button.h"
+#include "skia/include/SkBitmap.h"
+
+namespace views {
+
+// An image button.
+class ImageButton : public CustomButton {
+ public:
+ explicit ImageButton(ButtonListener* listener);
+ virtual ~ImageButton();
+
+ // Set the image the button should use for the provided state.
+ virtual void SetImage(ButtonState aState, SkBitmap* anImage);
+
+ enum HorizontalAlignment { ALIGN_LEFT = 0,
+ ALIGN_CENTER,
+ ALIGN_RIGHT, };
+
+ enum VerticalAlignment { ALIGN_TOP = 0,
+ ALIGN_MIDDLE,
+ ALIGN_BOTTOM };
+
+ // Sets how the image is laid out within the button's bounds.
+ void SetImageAlignment(HorizontalAlignment h_align,
+ VerticalAlignment v_align);
+
+ // Overridden from View:
+ virtual gfx::Size GetPreferredSize();
+ virtual void Paint(ChromeCanvas* canvas);
+
+ protected:
+ // Returns the image to paint. This is invoked from paint and returns a value
+ // from images.
+ virtual SkBitmap GetImageToPaint();
+
+ // The images used to render the different states of this button.
+ SkBitmap images_[BS_COUNT];
+
+ private:
+ // Image alignment.
+ HorizontalAlignment h_alignment_;
+ VerticalAlignment v_alignment_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageButton);
+};
+
+////////////////////////////////////////////////////////////////////////////////
+//
+// ToggleImageButton
+//
+// A toggle-able ImageButton. It swaps out its graphics when toggled.
+//
+////////////////////////////////////////////////////////////////////////////////
+class ToggleImageButton : public ImageButton {
+ public:
+ ToggleImageButton(ButtonListener* listener);
+ virtual ~ToggleImageButton();
+
+ // Change the toggled state.
+ void SetToggled(bool toggled);
+
+ // Like Button::SetImage(), but to set the graphics used for the
+ // "has been toggled" state. Must be called for each button state
+ // before the button is toggled.
+ void SetToggledImage(ButtonState state, SkBitmap* image);
+
+ // Set the tooltip text displayed when the button is toggled.
+ void SetToggledTooltipText(const std::wstring& tooltip);
+
+ // Overridden from ImageButton:
+ virtual void SetImage(ButtonState aState, SkBitmap* anImage);
+
+ // Overridden from View:
+ virtual bool GetTooltipText(int x, int y, std::wstring* tooltip);
+
+ private:
+ // The parent class's images_ member is used for the current images,
+ // and this array is used to hold the alternative images.
+ // We swap between the two when toggling.
+ SkBitmap alternate_images_[BS_COUNT];
+
+ // True if the button is currently toggled.
+ bool toggled_;
+
+ // The parent class's tooltip_text_ is displayed when not toggled, and
+ // this one is shown when toggled.
+ std::wstring toggled_tooltip_text_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(ToggleImageButton);
+};
+
+} // namespace views
+
+#endif // CHROME_VIEWS_IMAGE_BUTTON_H_
diff --git a/chrome/views/menu_button.cc b/chrome/views/menu_button.cc
index 09a9318..21cc828 100644
--- a/chrome/views/menu_button.cc
+++ b/chrome/views/menu_button.cc
@@ -43,10 +43,11 @@ static const int kMenuMarkerPaddingRight = -1;
//
////////////////////////////////////////////////////////////////////////////////
-MenuButton::MenuButton(const std::wstring& text,
+MenuButton::MenuButton(ButtonListener* listener,
+ const std::wstring& text,
ViewMenuDelegate* menu_delegate,
bool show_menu_marker)
- : TextButton(text),
+ : TextButton(listener, text),
menu_visible_(false),
menu_closed_time_(),
menu_delegate_(menu_delegate),
@@ -55,7 +56,7 @@ MenuButton::MenuButton(const std::wstring& text,
kMenuMarker = ResourceBundle::GetSharedInstance()
.GetBitmapNamed(IDR_MENU_DROPARROW);
}
- SetTextAlignment(TextButton::ALIGN_LEFT);
+ set_alignment(TextButton::ALIGN_LEFT);
}
MenuButton::~MenuButton() {
@@ -180,7 +181,7 @@ bool MenuButton::Activate() {
bool MenuButton::OnMousePressed(const MouseEvent& e) {
RequestFocus();
- if (GetState() != BS_DISABLED) {
+ if (state() != BS_DISABLED) {
// If we're draggable (GetDragOperations returns a non-zero value), then
// don't pop on press, instead wait for release.
if (e.IsOnlyLeftMouseButton() && HitTest(e.location()) &&
@@ -198,7 +199,7 @@ bool MenuButton::OnMousePressed(const MouseEvent& e) {
void MenuButton::OnMouseReleased(const MouseEvent& e,
bool canceled) {
if (GetDragOperations(e.x(), e.y()) != DragDropTypes::DRAG_NONE &&
- GetState() != BS_DISABLED && !canceled && !InDrag() &&
+ state() != BS_DISABLED && !canceled && !InDrag() &&
e.IsOnlyLeftMouseButton() && HitTest(e.location())) {
Activate();
} else {
diff --git a/chrome/views/menu_button.h b/chrome/views/menu_button.h
index 185d59f..55fe4e5 100644
--- a/chrome/views/menu_button.h
+++ b/chrome/views/menu_button.h
@@ -29,7 +29,8 @@ class MenuButton : public TextButton {
public:
//
// Create a Button
- MenuButton(const std::wstring& text,
+ MenuButton(ButtonListener* listener,
+ const std::wstring& text,
ViewMenuDelegate* menu_delegate,
bool show_menu_marker);
virtual ~MenuButton();
diff --git a/chrome/views/text_button.cc b/chrome/views/text_button.cc
index 5c2e663..f7c0cda 100644
--- a/chrome/views/text_button.cc
+++ b/chrome/views/text_button.cc
@@ -72,7 +72,7 @@ TextButtonBorder::~TextButtonBorder() {
void TextButtonBorder::Paint(const View& view, ChromeCanvas* canvas) const {
const TextButton* mb = static_cast<const TextButton*>(&view);
- int state = mb->GetState();
+ int state = mb->state();
// TextButton takes care of deciding when to call Paint.
const MBBImageSet* set = &hot_set_;
@@ -151,16 +151,13 @@ void TextButtonBorder::GetInsets(gfx::Insets* insets) const {
}
////////////////////////////////////////////////////////////////////////////////
-//
-// TextButton - Implementation
-//
-////////////////////////////////////////////////////////////////////////////////
+// TextButton, public:
-TextButton::TextButton(const std::wstring& text)
- : font_(ResourceBundle::GetSharedInstance().GetFont(
+TextButton::TextButton(ButtonListener* listener, const std::wstring& text)
+ : CustomButton(listener),
+ font_(ResourceBundle::GetSharedInstance().GetFont(
ResourceBundle::BaseFont)),
color_(kEnabledColor),
- BaseButton(),
max_width_(0),
alignment_(ALIGN_LEFT) {
SetText(text);
@@ -171,31 +168,6 @@ TextButton::TextButton(const std::wstring& text)
TextButton::~TextButton() {
}
-gfx::Size TextButton::GetPreferredSize() {
- gfx::Insets insets = GetInsets();
-
- // Use the max size to set the button boundaries.
- gfx::Size prefsize(max_text_size_.width() + icon_.width() + insets.width(),
- std::max(max_text_size_.height(), icon_.height()) +
- insets.height());
-
- if (icon_.width() > 0 && !text_.empty())
- prefsize.Enlarge(kIconTextPadding, 0);
-
- if (max_width_ > 0)
- prefsize.set_width(std::min(max_width_, prefsize.width()));
-
- return prefsize;
-}
-
-gfx::Size TextButton::GetMinimumSize() {
- return max_text_size_;
-}
-
-bool TextButton::OnMousePressed(const MouseEvent& e) {
- return true;
-}
-
void TextButton::SetText(const std::wstring& text) {
text_ = text;
// Update our new current and max text size
@@ -213,10 +185,6 @@ void TextButton::ClearMaxTextSize() {
max_text_size_ = text_size_;
}
-void TextButton::Paint(ChromeCanvas* canvas) {
- Paint(canvas, false);
-}
-
void TextButton::Paint(ChromeCanvas* canvas, bool for_drag) {
if (!for_drag) {
PaintBackground(canvas);
@@ -313,12 +281,44 @@ void TextButton::Paint(ChromeCanvas* canvas, bool for_drag) {
}
}
+////////////////////////////////////////////////////////////////////////////////
+// TextButton, View overrides:
+
+gfx::Size TextButton::GetPreferredSize() {
+ gfx::Insets insets = GetInsets();
+
+ // Use the max size to set the button boundaries.
+ gfx::Size prefsize(max_text_size_.width() + icon_.width() + insets.width(),
+ std::max(max_text_size_.height(), icon_.height()) +
+ insets.height());
+
+ if (icon_.width() > 0 && !text_.empty())
+ prefsize.Enlarge(kIconTextPadding, 0);
+
+ if (max_width_ > 0)
+ prefsize.set_width(std::min(max_width_, prefsize.width()));
+
+ return prefsize;
+}
+
+gfx::Size TextButton::GetMinimumSize() {
+ return max_text_size_;
+}
+
void TextButton::SetEnabled(bool enabled) {
if (enabled == IsEnabled())
return;
- BaseButton::SetEnabled(enabled);
+ CustomButton::SetEnabled(enabled);
color_ = enabled ? kEnabledColor : kDisabledColor;
SchedulePaint();
}
+bool TextButton::OnMousePressed(const MouseEvent& e) {
+ return true;
+}
+
+void TextButton::Paint(ChromeCanvas* canvas) {
+ Paint(canvas, false);
+}
+
} // namespace views
diff --git a/chrome/views/text_button.h b/chrome/views/text_button.h
index 0fd8a61..9a4d68f 100644
--- a/chrome/views/text_button.h
+++ b/chrome/views/text_button.h
@@ -5,17 +5,13 @@
#ifndef CHROME_VIEWS_TEXT_BUTTON_H__
#define CHROME_VIEWS_TEXT_BUTTON_H__
-#include <windows.h>
-
#include "chrome/common/gfx/chrome_font.h"
#include "chrome/views/border.h"
-#include "chrome/views/base_button.h"
+#include "chrome/views/custom_button.h"
#include "skia/include/SkBitmap.h"
namespace views {
-class MouseEvent;
-
////////////////////////////////////////////////////////////////////////////////
//
// TextButtonBorder
@@ -64,77 +60,79 @@ class TextButtonBorder : public Border {
// passed to SetText. To reset the cached max size invoke ClearMaxTextSize.
//
////////////////////////////////////////////////////////////////////////////////
-class TextButton : public BaseButton {
-public:
- TextButton(const std::wstring& text);
+class TextButton : public CustomButton {
+ public:
+ TextButton(ButtonListener* listener, const std::wstring& text);
virtual ~TextButton();
+ // Call SetText once per string in your set of possible values at button
+ // creation time, so that it can contain the largest of them and avoid
+ // resizing the button when the text changes.
+ virtual void SetText(const std::wstring& text);
+ std::wstring text() const { return text_; }
+
typedef enum TextAlignment {
ALIGN_LEFT,
ALIGN_CENTER,
ALIGN_RIGHT
};
- virtual gfx::Size GetPreferredSize();
- virtual gfx::Size GetMinimumSize();
- virtual bool OnMousePressed(const MouseEvent& e);
-
- // Call SetText once per string in your set of possible values at
- // button creation time, so that it can contain the largest of them
- // and avoid resizing the button when the text changes.
- virtual void SetText(const std::wstring& text);
-
- void TextButton::SetTextAlignment(TextAlignment alignment) {
- alignment_ = alignment;
- }
-
- const std::wstring& GetText() { return text_; }
+ void set_alignment(TextAlignment alignment) { alignment_ = alignment; }
// Sets the icon.
void SetIcon(const SkBitmap& icon);
-
- const SkBitmap& GetIcon() { return icon_; }
+ SkBitmap icon() const { return icon_; }
// TextButton remembers the maximum display size of the text passed to
// SetText. This method resets the cached maximum display size to the
// current size.
void ClearMaxTextSize();
- virtual void Paint(ChromeCanvas* canvas);
+ void set_max_width(int max_width) { max_width_ = max_width; }
+
+ // Paint the button into the specified canvas. If |for_drag| is true, the
+ // function paints a drag image representation into the canvas.
virtual void Paint(ChromeCanvas* canvas, bool for_drag);
- // Sets the enabled state. Setting the enabled state resets the color.
+ // Overridden from View:
+ virtual gfx::Size GetPreferredSize();
+ virtual gfx::Size GetMinimumSize();
virtual void SetEnabled(bool enabled);
- // Sets the max width. The preferred width of the button will never be larger
- // then the specified value. A value <= 0 indicates the preferred width
- // is not constrained in anyway.
- void set_max_width(int max_width) { max_width_ = max_width; }
+ protected:
+ virtual bool OnMousePressed(const MouseEvent& e);
+ virtual void Paint(ChromeCanvas* canvas);
private:
+ // The text string that is displayed in the button.
std::wstring text_;
+
+ // The size of the text string.
gfx::Size text_size_;
// Track the size of the largest text string seen so far, so that
// changing text_ will not resize the button boundary.
gfx::Size max_text_size_;
+ // The alignment of the text string within the button.
TextAlignment alignment_;
+ // The font used to paint the text.
ChromeFont font_;
// Text color.
SkColor color_;
+ // An icon displayed with the text.
SkBitmap icon_;
- // See setter for details.
+ // The width of the button will never be larger than this value. A value <= 0
+ // indicates the width is not constrained.
int max_width_;
DISALLOW_EVIL_CONSTRUCTORS(TextButton);
};
-
} // namespace views
#endif // CHROME_VIEWS_TEXT_BUTTON_H__
diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj
index 49e1abe..01f8da5 100644
--- a/chrome/views/views.vcproj
+++ b/chrome/views/views.vcproj
@@ -178,14 +178,6 @@
>
</File>
<File
- RelativePath=".\base_button.cc"
- >
- </File>
- <File
- RelativePath=".\base_button.h"
- >
- </File>
- <File
RelativePath=".\bitmap_scroll_bar.cc"
>
</File>
@@ -254,6 +246,14 @@
>
</File>
<File
+ RelativePath=".\custom_button.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\custom_button.h"
+ >
+ </File>
+ <File
RelativePath=".\custom_frame_view.cc"
>
</File>
@@ -338,6 +338,14 @@
>
</File>
<File
+ RelativePath=".\image_button.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\image_button.h"
+ >
+ </File>
+ <File
RelativePath=".\image_view.cc"
>
</File>