diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 19:34:39 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-15 19:34:39 +0000 |
commit | 723538f823510b20c8a14b9c9acf3812d598348f (patch) | |
tree | 065ecf7c74e7d1f5c10263afa1f3984ccdb23cd8 /ui/views | |
parent | 104432dfcc31a165979d7be9cabf7d43429cab60 (diff) | |
download | chromium_src-723538f823510b20c8a14b9c9acf3812d598348f.zip chromium_src-723538f823510b20c8a14b9c9acf3812d598348f.tar.gz chromium_src-723538f823510b20c8a14b9c9acf3812d598348f.tar.bz2 |
views: Rename MenuButtonDelegate::RunMenu to something more obvious.
The reason is that there are a lot of RunMenu() functions all over the code,
and actually the event for this function is that the menu button was pressed.
So we tell that to subclasses and they do whatever they want; they do not necessarily need to run a menu.
Thus this patch renames RunMenu to OnMenuButtonClicked.
BUG=117092
R=sky@chromium.org
TBR=stevenjb@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9693022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126967 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r-- | ui/views/controls/button/menu_button.cc | 10 | ||||
-rw-r--r-- | ui/views/controls/button/menu_button.h | 8 | ||||
-rw-r--r-- | ui/views/controls/button/menu_button_delegate.h | 40 | ||||
-rw-r--r-- | ui/views/controls/button/menu_button_listener.h | 31 | ||||
-rw-r--r-- | ui/views/examples/menu_example.cc | 12 | ||||
-rw-r--r-- | ui/views/views.gyp | 2 |
6 files changed, 48 insertions, 55 deletions
diff --git a/ui/views/controls/button/menu_button.cc b/ui/views/controls/button/menu_button.cc index 68b5210..0959bcf 100644 --- a/ui/views/controls/button/menu_button.cc +++ b/ui/views/controls/button/menu_button.cc @@ -15,7 +15,7 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/screen.h" #include "ui/views/controls/button/button.h" -#include "ui/views/controls/button/menu_button_delegate.h" +#include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/events/event.h" #include "ui/views/widget/root_view.h" #include "ui/views/widget/widget.h" @@ -48,12 +48,12 @@ const char MenuButton::kViewClassName[] = "views/MenuButton"; MenuButton::MenuButton(ButtonListener* listener, const string16& text, - MenuButtonDelegate* menu_delegate, + MenuButtonListener* menu_button_listener, bool show_menu_marker) : TextButton(listener, text), menu_visible_(false), menu_offset_(kDefaultMenuOffsetX, kDefaultMenuOffsetY), - menu_delegate_(menu_delegate), + listener_(menu_button_listener), show_menu_marker_(show_menu_marker), menu_marker_(ui::ResourceBundle::GetSharedInstance().GetImageNamed( IDR_MENU_DROPARROW).ToSkBitmap()), @@ -74,7 +74,7 @@ MenuButton::~MenuButton() { bool MenuButton::Activate() { SetState(BS_PUSHED); - if (menu_delegate_) { + if (listener_) { gfx::Rect lb = GetLocalBounds(); // The position of the menu depends on whether or not the locale is @@ -108,7 +108,7 @@ bool MenuButton::Activate() { bool destroyed = false; destroyed_flag_ = &destroyed; - menu_delegate_->RunMenu(this, menu_position); + listener_->OnMenuButtonClicked(this, menu_position); if (destroyed) { // The menu was deleted while showing. Don't attempt any processing. diff --git a/ui/views/controls/button/menu_button.h b/ui/views/controls/button/menu_button.h index 35702fe..d37044b 100644 --- a/ui/views/controls/button/menu_button.h +++ b/ui/views/controls/button/menu_button.h @@ -17,7 +17,7 @@ namespace views { class MouseEvent; -class MenuButtonDelegate; +class MenuButtonListener; //////////////////////////////////////////////////////////////////////////////// @@ -34,7 +34,7 @@ class VIEWS_EXPORT MenuButton : public TextButton { // Create a Button. MenuButton(ButtonListener* listener, const string16& text, - MenuButtonDelegate* menu_delegate, + MenuButtonListener* menu_button_listener, bool show_menu_marker); virtual ~MenuButton(); @@ -83,8 +83,8 @@ class VIEWS_EXPORT MenuButton : public TextButton { // the button is not part of the displayed menu. base::Time menu_closed_time_; - // The associated menu's resource identifier. - MenuButtonDelegate* menu_delegate_; + // Our listener. Not owned. + MenuButtonListener* listener_; // Whether or not we're showing a drop marker. bool show_menu_marker_; diff --git a/ui/views/controls/button/menu_button_delegate.h b/ui/views/controls/button/menu_button_delegate.h deleted file mode 100644 index 32b1dd4..0000000 --- a/ui/views/controls/button/menu_button_delegate.h +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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 UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_DELEGATE_H_ -#define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_DELEGATE_H_ -#pragma once - -#include "ui/views/views_export.h" - -namespace gfx { -class Point; -} - -namespace views { - -class View; - -//////////////////////////////////////////////////////////////////////////////// -// -// MenuButtonDelegate -// -// An interface that allows a component to tell a View about a menu that it -// has constructed that the view can show (e.g. for MenuButton views, or as a -// context menu.) -// -//////////////////////////////////////////////////////////////////////////////// -class VIEWS_EXPORT MenuButtonDelegate { - public: - // Creates and shows a menu at the specified position. |source| is the view - // the MenuButtonDelegate was set on. - virtual void RunMenu(View* source, const gfx::Point& point) = 0; - - protected: - virtual ~MenuButtonDelegate() {} -}; - -} // namespace views - -#endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_DELEGATE_H_ diff --git a/ui/views/controls/button/menu_button_listener.h b/ui/views/controls/button/menu_button_listener.h new file mode 100644 index 0000000..91d999a --- /dev/null +++ b/ui/views/controls/button/menu_button_listener.h @@ -0,0 +1,31 @@ +// Copyright (c) 2012 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 UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_LISTENER_H_ +#define UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_LISTENER_H_ +#pragma once + +#include "ui/views/views_export.h" + +namespace gfx { +class Point; +} + +namespace views { + +class View; + +// An interface implemented by an object to let it know that a menu button was +// clicked. +class VIEWS_EXPORT MenuButtonListener { + public: + virtual void OnMenuButtonClicked(View* source, const gfx::Point& point) = 0; + + protected: + virtual ~MenuButtonListener() {} +}; + +} // namespace views + +#endif // UI_VIEWS_CONTROLS_BUTTON_MENU_BUTTON_LISTENER_H_ diff --git a/ui/views/examples/menu_example.cc b/ui/views/examples/menu_example.cc index db5cee1..9eafcb6 100644 --- a/ui/views/examples/menu_example.cc +++ b/ui/views/examples/menu_example.cc @@ -9,7 +9,7 @@ #include "base/utf_string_conversions.h" #include "ui/base/models/simple_menu_model.h" #include "ui/views/controls/button/menu_button.h" -#include "ui/views/controls/button/menu_button_delegate.h" +#include "ui/views/controls/button/menu_button_listener.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/controls/menu/menu_2.h" #include "ui/views/layout/fill_layout.h" @@ -59,14 +59,15 @@ class ExampleMenuModel : public ui::SimpleMenuModel, DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel); }; -class ExampleMenuButton : public MenuButton, public MenuButtonDelegate { +class ExampleMenuButton : public MenuButton, public MenuButtonListener { public: ExampleMenuButton(const string16& test, bool show_menu_marker); virtual ~ExampleMenuButton(); private: - // Overridden from MenuButtonDelegate: - virtual void RunMenu(View* source, const gfx::Point& point) OVERRIDE; + // Overridden from MenuButtonListener: + virtual void OnMenuButtonClicked(View* source, + const gfx::Point& point) OVERRIDE; scoped_ptr<ExampleMenuModel> menu_model_; DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton); @@ -187,7 +188,8 @@ ExampleMenuButton::ExampleMenuButton(const string16& test, ExampleMenuButton::~ExampleMenuButton() { } -void ExampleMenuButton::RunMenu(View* source, const gfx::Point& point) { +void ExampleMenuButton::OnMenuButtonClicked(View* source, + const gfx::Point& point) { if (!menu_model_.get()) menu_model_.reset(new ExampleMenuModel); diff --git a/ui/views/views.gyp b/ui/views/views.gyp index cffde5c..b53012f 100644 --- a/ui/views/views.gyp +++ b/ui/views/views.gyp @@ -80,7 +80,7 @@ 'controls/button/image_button.h', 'controls/button/menu_button.cc', 'controls/button/menu_button.h', - 'controls/button/menu_button_delegate.h', + 'controls/button/menu_button_listener.h', 'controls/button/radio_button.cc', 'controls/button/radio_button.h', 'controls/button/text_button.cc', |