diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-16 23:25:13 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-16 23:25:13 +0000 |
commit | 48c8fa63122510b2c51c6608a93b30e94192e679 (patch) | |
tree | dc22b80b2f4103d865cbfe47c6f4dc52c8595985 /chrome/browser/views/tabs | |
parent | 9ea0ea99d3a1140a17712a286414d387eddbe8ac (diff) | |
download | chromium_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
Diffstat (limited to 'chrome/browser/views/tabs')
-rw-r--r-- | chrome/browser/views/tabs/tab.cc | 5 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab.h | 8 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_renderer.cc | 20 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_renderer.h | 10 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.cc | 17 | ||||
-rw-r--r-- | chrome/browser/views/tabs/tab_strip.h | 10 |
6 files changed, 37 insertions, 33 deletions
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_; |