Remove ComboboxListener
Replaces uses of it with PerformActionCallback (updated to pass the Combobox*) or base::RepeatingClosure. Bug: 772945 Change-Id: I7a54755016bebd628654ec3f18ccdcd012345cd1 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2402326 Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org> Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Auto-Submit: Peter Boström <pbos@chromium.org> Cr-Commit-Position: refs/heads/master@{#805793}
This commit is contained in:

committed by
Commit Bot

parent
fcc1378db5
commit
2031a8a78d
chrome/browser/ui/views
apps
app_info_dialog
autofill
payments
page_info
passwords
payments
cvc_unmask_view_controller.cccvc_unmask_view_controller.heditor_view_controller.cceditor_view_controller.h
translate
ui/views
@ -200,7 +200,8 @@ void AppInfoSummaryPanel::AddLaunchOptionControl(views::View* vertical_stack) {
|
||||
std::make_unique<views::Combobox>(launch_options_combobox_model_.get());
|
||||
launch_options_combobox->SetAccessibleName(
|
||||
l10n_util::GetStringUTF16(IDS_APPLICATION_INFO_LAUNCH_OPTIONS_ACCNAME));
|
||||
launch_options_combobox->set_listener(this);
|
||||
launch_options_combobox->set_callback(base::BindRepeating(
|
||||
&AppInfoSummaryPanel::OnPerformAction, base::Unretained(this)));
|
||||
launch_options_combobox->SetSelectedIndex(
|
||||
launch_options_combobox_model_->GetIndexForLaunchType(GetLaunchType()));
|
||||
|
||||
@ -224,12 +225,9 @@ void AppInfoSummaryPanel::AddSubviews() {
|
||||
}
|
||||
|
||||
void AppInfoSummaryPanel::OnPerformAction(views::Combobox* combobox) {
|
||||
if (combobox == launch_options_combobox_) {
|
||||
SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex(
|
||||
launch_options_combobox_->GetSelectedIndex()));
|
||||
} else {
|
||||
NOTREACHED();
|
||||
}
|
||||
DCHECK(combobox == launch_options_combobox_);
|
||||
SetLaunchType(launch_options_combobox_model_->GetLaunchTypeAtIndex(
|
||||
launch_options_combobox_->GetSelectedIndex()));
|
||||
}
|
||||
|
||||
void AppInfoSummaryPanel::StartCalculatingAppSize() {
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "chrome/browser/ui/views/apps/app_info_dialog/app_info_panel.h"
|
||||
#include "extensions/common/constants.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
|
||||
class LaunchOptionsComboboxModel;
|
||||
class Profile;
|
||||
@ -31,7 +30,6 @@ class View;
|
||||
// The summary panel of the app info dialog, which provides basic information
|
||||
// and controls related to the app.
|
||||
class AppInfoSummaryPanel : public AppInfoPanel,
|
||||
public views::ComboboxListener,
|
||||
public base::SupportsWeakPtr<AppInfoSummaryPanel> {
|
||||
public:
|
||||
AppInfoSummaryPanel(Profile* profile, const extensions::Extension* app);
|
||||
@ -45,8 +43,8 @@ class AppInfoSummaryPanel : public AppInfoPanel,
|
||||
void AddLaunchOptionControl(views::View* vertical_stack);
|
||||
void AddSubviews();
|
||||
|
||||
// Overridden from views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
// Called when the combobox selection changes.
|
||||
void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
// Called asynchronously to calculate and update the size of the app displayed
|
||||
// in the dialog.
|
||||
|
@ -360,12 +360,14 @@ void CardUnmaskPromptViews::InitIfNecessary() {
|
||||
|
||||
// Add the month and year comboboxes if the expiration date is needed.
|
||||
auto month_input = std::make_unique<views::Combobox>(&month_combobox_model_);
|
||||
month_input->set_listener(this);
|
||||
month_input->set_callback(base::BindRepeating(
|
||||
&CardUnmaskPromptViews::OnPerformAction, base::Unretained(this)));
|
||||
month_input->SetAccessibleName(
|
||||
l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_MONTH));
|
||||
month_input_ = input_row->AddChildView(std::move(month_input));
|
||||
auto year_input = std::make_unique<views::Combobox>(&year_combobox_model_);
|
||||
year_input->set_listener(this);
|
||||
year_input->set_callback(base::BindRepeating(
|
||||
&CardUnmaskPromptViews::OnPerformAction, base::Unretained(this)));
|
||||
year_input->SetAccessibleName(
|
||||
l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_EXPIRATION_YEAR));
|
||||
year_input_ = input_row->AddChildView(std::move(year_input));
|
||||
|
@ -11,16 +11,16 @@
|
||||
#include "chrome/browser/ui/autofill/payments/autofill_dialog_models.h"
|
||||
#include "components/autofill/core/browser/ui/payments/card_unmask_prompt_view.h"
|
||||
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/window/dialog_delegate.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
}
|
||||
} // namespace content
|
||||
|
||||
namespace views {
|
||||
class Checkbox;
|
||||
class Combobox;
|
||||
class Label;
|
||||
class Textfield;
|
||||
class Throbber;
|
||||
@ -31,7 +31,6 @@ namespace autofill {
|
||||
class CardUnmaskPromptController;
|
||||
|
||||
class CardUnmaskPromptViews : public CardUnmaskPromptView,
|
||||
public views::ComboboxListener,
|
||||
public views::BubbleDialogDelegateView,
|
||||
public views::TextfieldController {
|
||||
public:
|
||||
@ -39,7 +38,7 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
|
||||
content::WebContents* web_contents);
|
||||
~CardUnmaskPromptViews() override;
|
||||
|
||||
// CardUnmaskPromptView
|
||||
// CardUnmaskPromptView:
|
||||
void Show() override;
|
||||
void ControllerGone() override;
|
||||
void DisableAndWaitForVerification() override;
|
||||
@ -66,9 +65,6 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
|
||||
void ContentsChanged(views::Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// views::ComboboxListener
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
private:
|
||||
friend class CardUnmaskPromptViewTesterViews;
|
||||
|
||||
@ -83,6 +79,8 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
|
||||
|
||||
void LinkClicked();
|
||||
|
||||
void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
CardUnmaskPromptController* controller_;
|
||||
content::WebContents* web_contents_;
|
||||
|
||||
|
@ -127,11 +127,6 @@ void SaveCardOfferBubbleViews::ContentsChanged(
|
||||
DialogModelChanged();
|
||||
}
|
||||
|
||||
void SaveCardOfferBubbleViews::OnPerformAction(views::Combobox* sender) {
|
||||
DCHECK(month_input_dropdown_ == sender || year_input_dropdown_ == sender);
|
||||
DialogModelChanged();
|
||||
}
|
||||
|
||||
SaveCardOfferBubbleViews::~SaveCardOfferBubbleViews() {}
|
||||
|
||||
std::unique_ptr<views::View> SaveCardOfferBubbleViews::CreateMainContentView() {
|
||||
@ -231,7 +226,8 @@ SaveCardOfferBubbleViews::CreateRequestExpirationDateView() {
|
||||
|
||||
// Set up the month and year comboboxes.
|
||||
month_input_dropdown_ = new views::Combobox(&month_combobox_model_);
|
||||
month_input_dropdown_->set_listener(this);
|
||||
month_input_dropdown_->set_closure(base::BindRepeating(
|
||||
&SaveCardOfferBubbleViews::DialogModelChanged, base::Unretained(this)));
|
||||
month_input_dropdown_->SetAccessibleName(
|
||||
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH));
|
||||
month_input_dropdown_->SetID(DialogViewId::EXPIRATION_DATE_DROPBOX_MONTH);
|
||||
@ -245,7 +241,8 @@ SaveCardOfferBubbleViews::CreateRequestExpirationDateView() {
|
||||
}
|
||||
|
||||
year_input_dropdown_ = new views::Combobox(&year_combobox_model_);
|
||||
year_input_dropdown_->set_listener(this);
|
||||
year_input_dropdown_->set_closure(base::BindRepeating(
|
||||
&SaveCardOfferBubbleViews::DialogModelChanged, base::Unretained(this)));
|
||||
year_input_dropdown_->SetAccessibleName(
|
||||
l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR));
|
||||
year_input_dropdown_->SetID(DialogViewId::EXPIRATION_DATE_DROPBOX_YEAR);
|
||||
|
@ -8,12 +8,15 @@
|
||||
#include "chrome/browser/ui/autofill/payments/autofill_dialog_models.h"
|
||||
#include "chrome/browser/ui/views/autofill/payments/payments_view_util.h"
|
||||
#include "chrome/browser/ui/views/autofill/payments/save_card_bubble_views.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
|
||||
namespace content {
|
||||
class WebContents;
|
||||
}
|
||||
} // namespace content
|
||||
|
||||
namespace views {
|
||||
class Combobox;
|
||||
} // namespace views
|
||||
|
||||
namespace autofill {
|
||||
|
||||
@ -22,7 +25,6 @@ namespace autofill {
|
||||
// previously saved. It includes a description of the card that is being saved
|
||||
// and an [Save] button. (Non-material UI's include a [No Thanks] button).
|
||||
class SaveCardOfferBubbleViews : public SaveCardBubbleViews,
|
||||
public views::ComboboxListener,
|
||||
public views::TextfieldController {
|
||||
public:
|
||||
// Bubble will be anchored to |anchor_view|.
|
||||
@ -39,9 +41,6 @@ class SaveCardOfferBubbleViews : public SaveCardBubbleViews,
|
||||
void ContentsChanged(views::Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<views::View> CreateMainContentView() override;
|
||||
|
||||
|
@ -89,7 +89,7 @@ class MediaComboboxModel : public ui::ComboboxModel {
|
||||
// and/or camera).
|
||||
class MediaMenuBlock : public views::View {
|
||||
public:
|
||||
MediaMenuBlock(views::ComboboxListener* listener,
|
||||
MediaMenuBlock(views::Combobox::PerformActionCallback callback,
|
||||
ContentSettingBubbleModel::MediaMenuMap media) {
|
||||
const ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
|
||||
|
||||
@ -137,7 +137,7 @@ class MediaMenuBlock : public views::View {
|
||||
auto combobox =
|
||||
std::make_unique<views::Combobox>(std::move(combobox_model));
|
||||
combobox->SetEnabled(combobox_enabled);
|
||||
combobox->set_listener(listener);
|
||||
combobox->set_callback(callback);
|
||||
combobox->SetSelectedIndex(combobox_selected_index);
|
||||
layout->AddView(std::move(combobox));
|
||||
}
|
||||
@ -517,7 +517,10 @@ void ContentSettingBubbleContents::Init() {
|
||||
// Layout code for the media device menus.
|
||||
if (content_setting_bubble_model_->AsMediaStreamBubbleModel()) {
|
||||
rows.push_back(
|
||||
{std::make_unique<MediaMenuBlock>(this, bubble_content.media_menus),
|
||||
{std::make_unique<MediaMenuBlock>(
|
||||
base::BindRepeating(&ContentSettingBubbleContents::OnPerformAction,
|
||||
base::Unretained(this)),
|
||||
bubble_content.media_menus),
|
||||
LayoutRowType::INDENTED});
|
||||
}
|
||||
|
||||
|
@ -18,14 +18,14 @@
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/button/checkbox.h"
|
||||
#include "ui/views/controls/button/radio_button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
|
||||
namespace views {
|
||||
class Combobox;
|
||||
class ImageButton;
|
||||
class RadioButton;
|
||||
class LabelButton;
|
||||
class Link;
|
||||
}
|
||||
} // namespace views
|
||||
|
||||
// ContentSettingBubbleContents is used when the user turns on different kinds
|
||||
// of content blocking (e.g. "block images"). When viewing a page with blocked
|
||||
@ -39,7 +39,6 @@ class Link;
|
||||
class ContentSettingBubbleContents : public content::WebContentsObserver,
|
||||
public views::BubbleDialogDelegateView,
|
||||
public views::ButtonListener,
|
||||
public views::ComboboxListener,
|
||||
public ContentSettingBubbleModel::Owner {
|
||||
public:
|
||||
ContentSettingBubbleContents(
|
||||
@ -81,6 +80,8 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
|
||||
void LinkClicked(views::Link* source, int event_flags);
|
||||
void CustomLinkClicked();
|
||||
|
||||
void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
// content::WebContentsObserver:
|
||||
void DidFinishNavigation(
|
||||
content::NavigationHandle* navigation_handle) override;
|
||||
@ -90,8 +91,6 @@ class ContentSettingBubbleContents : public content::WebContentsObserver,
|
||||
// views::ButtonListener:
|
||||
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
// Provides data for this bubble.
|
||||
std::unique_ptr<ContentSettingBubbleModel> content_setting_bubble_model_;
|
||||
|
@ -23,7 +23,6 @@
|
||||
#include "ui/gfx/color_utils.h"
|
||||
#include "ui/gfx/image/image.h"
|
||||
#include "ui/views/controls/combobox/combobox.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/image_view.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/layout/grid_layout.h"
|
||||
@ -93,8 +92,7 @@ base::string16 ComboboxModelAdapter::GetItemAt(int index) const {
|
||||
}
|
||||
|
||||
// The |PermissionCombobox| provides a combobox for selecting a permission type.
|
||||
class PermissionCombobox : public views::Combobox,
|
||||
public views::ComboboxListener {
|
||||
class PermissionCombobox : public views::Combobox {
|
||||
public:
|
||||
PermissionCombobox(ComboboxModelAdapter* model,
|
||||
bool enabled,
|
||||
@ -109,8 +107,7 @@ class PermissionCombobox : public views::Combobox,
|
||||
gfx::Size CalculatePreferredSize() const override;
|
||||
|
||||
private:
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
void OnPerformAction(Combobox* combobox);
|
||||
|
||||
ComboboxModelAdapter* model_;
|
||||
|
||||
@ -124,7 +121,8 @@ PermissionCombobox::PermissionCombobox(ComboboxModelAdapter* model,
|
||||
bool enabled,
|
||||
bool use_default)
|
||||
: views::Combobox(model), model_(model) {
|
||||
set_listener(this);
|
||||
set_callback(base::BindRepeating(&PermissionCombobox::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
SetEnabled(enabled);
|
||||
UpdateSelectedIndex(use_default);
|
||||
SetSizeToLargestLabel(false);
|
||||
|
@ -376,7 +376,9 @@ PasswordSaveUpdateWithAccountStoreView::PasswordSaveUpdateWithAccountStoreView(
|
||||
controller_.GetPrimaryAccountEmail(),
|
||||
controller_.GetPrimaryAccountAvatar(ComboboxIconSize()),
|
||||
controller_.IsUsingAccountStore());
|
||||
destination_dropdown->set_listener(this);
|
||||
destination_dropdown->set_callback(base::BindRepeating(
|
||||
&PasswordSaveUpdateWithAccountStoreView::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
destination_dropdown_ = destination_dropdown.get();
|
||||
}
|
||||
const autofill::PasswordForm& password_form = controller_.pending_password();
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "chrome/browser/ui/passwords/bubble_controllers/save_update_with_account_store_bubble_controller.h"
|
||||
#include "chrome/browser/ui/views/passwords/password_bubble_view_base.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/layout/animating_layout_manager.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
@ -33,7 +32,6 @@ class FeaturePromoBubbleView;
|
||||
class PasswordSaveUpdateWithAccountStoreView
|
||||
: public PasswordBubbleViewBase,
|
||||
public views::ButtonListener,
|
||||
public views::ComboboxListener,
|
||||
public views::WidgetObserver,
|
||||
public views::AnimatingLayoutManager::Observer {
|
||||
public:
|
||||
@ -65,10 +63,6 @@ class PasswordSaveUpdateWithAccountStoreView
|
||||
// views::ButtonListener:
|
||||
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
// Used for the destination combobox.
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
// views::WidgetObserver:
|
||||
void OnWidgetDestroying(views::Widget* widget) override;
|
||||
|
||||
@ -91,6 +85,8 @@ class PasswordSaveUpdateWithAccountStoreView
|
||||
void UpdateUsernameAndPasswordInModel();
|
||||
void UpdateBubbleUIElements();
|
||||
|
||||
void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
// Whether we should show the IPH informing the user about the destination
|
||||
// picker and that they can now select where to store the passwords. It
|
||||
// creates (if needed) and queries the |iph_tracker_|
|
||||
|
@ -189,14 +189,16 @@ void CvcUnmaskViewController::FillContentView(views::View* content_view) {
|
||||
layout->StartRow(views::GridLayout::kFixedSize, 1);
|
||||
if (requesting_expiration) {
|
||||
auto month = std::make_unique<views::Combobox>(&month_combobox_model_);
|
||||
month->set_listener(this);
|
||||
month->set_closure(base::BindRepeating(
|
||||
&CvcUnmaskViewController::OnPerformAction, base::Unretained(this)));
|
||||
month->SetID(static_cast<int>(DialogViewID::CVC_MONTH));
|
||||
month->SelectValue(credit_card_.Expiration2DigitMonthAsString());
|
||||
month->SetInvalid(true);
|
||||
layout->AddView(std::move(month));
|
||||
|
||||
auto year = std::make_unique<views::Combobox>(&year_combobox_model_);
|
||||
year->set_listener(this);
|
||||
year->set_closure(base::BindRepeating(
|
||||
&CvcUnmaskViewController::OnPerformAction, base::Unretained(this)));
|
||||
year->SetID(static_cast<int>(DialogViewID::CVC_YEAR));
|
||||
year->SelectValue(credit_card_.Expiration4DigitYearAsString());
|
||||
year->SetInvalid(true);
|
||||
@ -383,7 +385,7 @@ void CvcUnmaskViewController::ContentsChanged(
|
||||
UpdatePayButtonState();
|
||||
}
|
||||
|
||||
void CvcUnmaskViewController::OnPerformAction(views::Combobox* combobox) {
|
||||
void CvcUnmaskViewController::OnPerformAction() {
|
||||
if (!dialog()->IsInteractive())
|
||||
return;
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "components/autofill/core/browser/payments/full_card_request.h"
|
||||
#include "components/autofill/core/browser/payments/payments_client.h"
|
||||
#include "components/autofill/core/browser/payments/risk_data_loader.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
|
||||
namespace autofill {
|
||||
@ -40,7 +39,6 @@ class CvcUnmaskViewController
|
||||
: public PaymentRequestSheetController,
|
||||
public autofill::RiskDataLoader,
|
||||
public autofill::payments::FullCardRequest::UIDelegate,
|
||||
public views::ComboboxListener,
|
||||
public views::TextfieldController {
|
||||
public:
|
||||
CvcUnmaskViewController(
|
||||
@ -91,8 +89,7 @@ class CvcUnmaskViewController
|
||||
void ContentsChanged(views::Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
void OnPerformAction();
|
||||
|
||||
autofill::MonthComboboxModel month_combobox_model_;
|
||||
autofill::YearComboboxModel year_combobox_model_;
|
||||
|
@ -214,7 +214,8 @@ EditorViewController::CreateComboboxForField(const EditorField& field,
|
||||
|
||||
// Using autofill field type as a view ID.
|
||||
combobox->SetID(GetInputFieldViewId(field.type));
|
||||
combobox->set_listener(this);
|
||||
combobox->set_callback(base::BindRepeating(
|
||||
&EditorViewController::OnPerformAction, base::Unretained(this)));
|
||||
comboboxes_.insert(std::make_pair(combobox.get(), field));
|
||||
return combobox;
|
||||
}
|
||||
@ -227,8 +228,7 @@ void EditorViewController::ContentsChanged(views::Textfield* sender,
|
||||
}
|
||||
|
||||
void EditorViewController::OnPerformAction(views::Combobox* sender) {
|
||||
ValidatingCombobox* sender_cast = static_cast<ValidatingCombobox*>(sender);
|
||||
sender_cast->OnContentsChanged();
|
||||
static_cast<ValidatingCombobox*>(sender)->OnContentsChanged();
|
||||
primary_button()->SetEnabled(ValidateInputFields());
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include "chrome/browser/ui/views/payments/payment_request_sheet_controller.h"
|
||||
#include "chrome/browser/ui/views/payments/validation_delegate.h"
|
||||
#include "components/autofill/core/browser/field_types.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
@ -77,8 +76,7 @@ struct EditorField {
|
||||
// The PaymentRequestSheetController subtype for the editor screens of the
|
||||
// Payment Request flow.
|
||||
class EditorViewController : public PaymentRequestSheetController,
|
||||
public views::TextfieldController,
|
||||
public views::ComboboxListener {
|
||||
public views::TextfieldController {
|
||||
public:
|
||||
using TextFieldsMap =
|
||||
std::unordered_map<ValidatingTextfield*, const EditorField>;
|
||||
@ -152,8 +150,8 @@ class EditorViewController : public PaymentRequestSheetController,
|
||||
bool ShouldShowSecondaryButton() override;
|
||||
void FillContentView(views::View* content_view) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
// Combobox callback.
|
||||
virtual void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
// Update the editor view by removing all it's child views and recreating
|
||||
// the input fields returned by GetFieldDefinitions. Note that
|
||||
|
@ -834,7 +834,8 @@ std::unique_ptr<views::View> TranslateBubbleView::CreateViewAdvancedSource() {
|
||||
}
|
||||
|
||||
source_language_combobox->SetID(COMBOBOX_ID_SOURCE_LANGUAGE);
|
||||
source_language_combobox->set_listener(this);
|
||||
source_language_combobox->set_callback(base::BindRepeating(
|
||||
&TranslateBubbleView::OnPerformAction, base::Unretained(this)));
|
||||
source_language_combobox_ = source_language_combobox.get();
|
||||
|
||||
auto advanced_done_button = std::make_unique<views::MdTextButton>(
|
||||
@ -866,7 +867,8 @@ std::unique_ptr<views::View> TranslateBubbleView::CreateViewAdvancedTarget() {
|
||||
std::make_unique<views::Combobox>(target_language_combobox_model_.get());
|
||||
|
||||
target_language_combobox->SetID(COMBOBOX_ID_TARGET_LANGUAGE);
|
||||
target_language_combobox->set_listener(this);
|
||||
target_language_combobox->set_callback(base::BindRepeating(
|
||||
&TranslateBubbleView::OnPerformAction, base::Unretained(this)));
|
||||
target_language_combobox_ = target_language_combobox.get();
|
||||
|
||||
auto advanced_done_button = std::make_unique<views::MdTextButton>(
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "content/public/browser/web_contents_observer.h"
|
||||
#include "ui/base/models/simple_menu_model.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/image_view.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/controls/menu/menu_runner.h"
|
||||
@ -37,13 +36,13 @@ class Browser;
|
||||
|
||||
namespace views {
|
||||
class Checkbox;
|
||||
class Combobox;
|
||||
class LabelButton;
|
||||
class View;
|
||||
} // namespace views
|
||||
|
||||
class TranslateBubbleView : public LocationBarBubbleDelegateView,
|
||||
public views::ButtonListener,
|
||||
public views::ComboboxListener,
|
||||
public ui::SimpleMenuModel::Delegate,
|
||||
public views::TabbedPaneListener {
|
||||
public:
|
||||
@ -81,6 +80,8 @@ class TranslateBubbleView : public LocationBarBubbleDelegateView,
|
||||
|
||||
TranslateBubbleModel* model() { return model_.get(); }
|
||||
|
||||
void OnPerformAction(views::Combobox* combobox);
|
||||
|
||||
// LocationBarBubbleDelegateView:
|
||||
void Init() override;
|
||||
View* GetInitiallyFocusedView() override;
|
||||
@ -94,9 +95,6 @@ class TranslateBubbleView : public LocationBarBubbleDelegateView,
|
||||
// views::ButtonListener:
|
||||
void ButtonPressed(views::Button* source, const ui::Event& event) override;
|
||||
|
||||
// views::ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
// ui::SimpleMenuModel::Delegate:
|
||||
bool IsCommandIdChecked(int command_id) const override;
|
||||
bool IsCommandIdEnabled(int command_id) const override;
|
||||
|
@ -122,7 +122,6 @@ component("views") {
|
||||
"controls/button/toggle_button.h",
|
||||
"controls/color_tracking_icon_view.h",
|
||||
"controls/combobox/combobox.h",
|
||||
"controls/combobox/combobox_listener.h",
|
||||
"controls/combobox/combobox_util.h",
|
||||
"controls/editable_combobox/editable_combobox.h",
|
||||
"controls/focus_ring.h",
|
||||
|
@ -295,7 +295,17 @@ Combobox* BubbleDialogModelHost::AddOrUpdateCombobox(
|
||||
combobox->SetAccessibleName(model->accessible_name(GetPassKey()).empty()
|
||||
? model->label(GetPassKey())
|
||||
: model->accessible_name(GetPassKey()));
|
||||
combobox->set_listener(this);
|
||||
combobox->set_callback(base::BindRepeating(
|
||||
[](ui::DialogModelCombobox* model,
|
||||
util::PassKey<DialogModelHost> pass_key, Combobox* combobox) {
|
||||
// TODO(pbos): This should be a subscription through the Combobox
|
||||
// directly, but Combobox right now doesn't support listening to
|
||||
// selected-index changes.
|
||||
model->OnSelectedIndexChanged(pass_key, combobox->GetSelectedIndex());
|
||||
model->OnPerformAction(pass_key);
|
||||
},
|
||||
model, GetPassKey()));
|
||||
|
||||
// TODO(pbos): Add subscription to combobox selected-index changes.
|
||||
combobox->SetSelectedIndex(model->selected_index());
|
||||
auto* combobox_ptr = combobox.get();
|
||||
@ -325,23 +335,6 @@ void BubbleDialogModelHost::NotifyTextfieldTextChanged(Textfield* textfield) {
|
||||
->OnTextChanged(GetPassKey(), textfield->GetText());
|
||||
}
|
||||
|
||||
void BubbleDialogModelHost::NotifyComboboxSelectedIndexChanged(
|
||||
Combobox* combobox) {
|
||||
view_to_field_[combobox]
|
||||
->AsCombobox(GetPassKey())
|
||||
->OnSelectedIndexChanged(GetPassKey(), combobox->GetSelectedIndex());
|
||||
}
|
||||
|
||||
void BubbleDialogModelHost::OnPerformAction(Combobox* combobox) {
|
||||
// TODO(pbos): This should be a subscription through the Combobox directly,
|
||||
// but Combobox right now doesn't support listening to selected-index changes.
|
||||
NotifyComboboxSelectedIndexChanged(combobox);
|
||||
|
||||
view_to_field_[combobox]
|
||||
->AsCombobox(GetPassKey())
|
||||
->OnPerformAction(GetPassKey());
|
||||
}
|
||||
|
||||
void BubbleDialogModelHost::OnViewCreatedForField(View* view,
|
||||
ui::DialogModelField* field) {
|
||||
#if DCHECK_IS_ON()
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "ui/base/models/dialog_model.h"
|
||||
#include "ui/views/bubble/bubble_dialog_delegate_view.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
|
||||
namespace views {
|
||||
class Combobox;
|
||||
@ -30,8 +29,7 @@ class Textfield;
|
||||
// DialogModel::host(). This helps minimize platform-specific code from
|
||||
// platform-agnostic model-delegate code.
|
||||
class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegateView,
|
||||
public ui::DialogModelHost,
|
||||
public ComboboxListener {
|
||||
public ui::DialogModelHost {
|
||||
public:
|
||||
// Constructs a BubbleDialogModelHost, which for most purposes is to used as a
|
||||
// BubbleDialogDelegateView. The BubbleDialogDelegateView is nominally handed
|
||||
@ -52,9 +50,6 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegateView,
|
||||
void SelectAllText(int unique_id) override;
|
||||
void OnFieldAdded(ui::DialogModelField* field) override;
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(views::Combobox* combobox) override;
|
||||
|
||||
private:
|
||||
void OnWindowClosing();
|
||||
|
||||
@ -72,7 +67,6 @@ class VIEWS_EXPORT BubbleDialogModelHost : public BubbleDialogDelegateView,
|
||||
void OnViewCreatedForField(View* view, ui::DialogModelField* field);
|
||||
|
||||
void NotifyTextfieldTextChanged(views::Textfield* textfield);
|
||||
void NotifyComboboxSelectedIndexChanged(views::Combobox* combobox);
|
||||
|
||||
View* FieldToView(ui::DialogModelField* field);
|
||||
|
||||
|
@ -676,7 +676,7 @@ void Combobox::OnPerformAction() {
|
||||
NotifyAccessibilityEvent(ax::mojom::Event::kValueChanged, true);
|
||||
SchedulePaint();
|
||||
|
||||
callback_.Run();
|
||||
callback_.Run(this);
|
||||
|
||||
// Note |this| may be deleted by |callback_|.
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
#include "ui/base/models/combobox_model.h"
|
||||
#include "ui/base/models/combobox_model_observer.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/prefix_delegate.h"
|
||||
#include "ui/views/style/typography.h"
|
||||
|
||||
@ -45,7 +44,8 @@ class VIEWS_EXPORT Combobox : public View,
|
||||
public:
|
||||
METADATA_HEADER(Combobox);
|
||||
|
||||
using PerformActionCallback = base::RepeatingClosure;
|
||||
using PerformActionCallback =
|
||||
base::RepeatingCallback<void(Combobox* combobox)>;
|
||||
|
||||
static constexpr int kDefaultComboboxTextContext = style::CONTEXT_BUTTON;
|
||||
static constexpr int kDefaultComboboxTextStyle = style::STYLE_PRIMARY;
|
||||
@ -66,25 +66,19 @@ class VIEWS_EXPORT Combobox : public View,
|
||||
|
||||
const gfx::FontList& GetFontList() const;
|
||||
|
||||
// TODO(pbos): Migrate users of this to set_callback().
|
||||
void set_listener(ComboboxListener* listener) {
|
||||
if (!listener) {
|
||||
set_callback(base::DoNothing());
|
||||
return;
|
||||
}
|
||||
|
||||
set_callback(base::BindRepeating(
|
||||
[](ComboboxListener* listener, Combobox* combobox) {
|
||||
listener->OnPerformAction(combobox);
|
||||
},
|
||||
listener, this));
|
||||
}
|
||||
|
||||
// Sets the callback which will be called when a selection has been made.
|
||||
void set_callback(PerformActionCallback callback) {
|
||||
callback_ = std::move(callback);
|
||||
}
|
||||
|
||||
// Version of set_callback() that takes a RepeatingClosure by discarding the
|
||||
// argument.
|
||||
void set_closure(base::RepeatingClosure closure) {
|
||||
set_callback(base::BindRepeating(
|
||||
[](base::RepeatingClosure closure, Combobox*) { closure.Run(); },
|
||||
std::move(closure)));
|
||||
}
|
||||
|
||||
// Gets/Sets the selected index.
|
||||
int GetSelectedIndex() const { return selected_index_; }
|
||||
void SetSelectedIndex(int index);
|
||||
|
@ -1,32 +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_COMBOBOX_COMBOBOX_LISTENER_H_
|
||||
#define UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_LISTENER_H_
|
||||
|
||||
#include "ui/views/views_export.h"
|
||||
|
||||
namespace views {
|
||||
|
||||
class Combobox;
|
||||
|
||||
// Interface used to notify consumers when something interesting happens to a
|
||||
// Combobox.
|
||||
class VIEWS_EXPORT ComboboxListener {
|
||||
public:
|
||||
// Invoked when the user does the appropriate gesture that some action should
|
||||
// be performed. This is invoked if the user clicks on the menu button and
|
||||
// then clicks an item, and also when the menu is not showing and the does a
|
||||
// gesture to change the selection (for example, presses the home or end
|
||||
// keys). This is not invoked when the menu is shown and the user changes the
|
||||
// selection without closing the menu.
|
||||
virtual void OnPerformAction(Combobox* combobox) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~ComboboxListener() = default;
|
||||
};
|
||||
|
||||
} // namespace views
|
||||
|
||||
#endif // UI_VIEWS_CONTROLS_COMBOBOX_COMBOBOX_LISTENER_H_
|
@ -29,7 +29,6 @@
|
||||
#include "ui/events/keycodes/keyboard_codes.h"
|
||||
#include "ui/events/test/event_generator.h"
|
||||
#include "ui/events/types/event_type.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/style/platform_style.h"
|
||||
#include "ui/views/test/ax_event_counter.h"
|
||||
#include "ui/views/test/combobox_test_api.h"
|
||||
@ -148,13 +147,12 @@ class VectorComboboxModel : public ui::ComboboxModel {
|
||||
DISALLOW_COPY_AND_ASSIGN(VectorComboboxModel);
|
||||
};
|
||||
|
||||
class EvilListener : public ComboboxListener {
|
||||
class EvilListener {
|
||||
public:
|
||||
EvilListener() = default;
|
||||
~EvilListener() override = default;
|
||||
~EvilListener() = default;
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override {
|
||||
void OnPerformAction(Combobox* combobox) {
|
||||
delete combobox;
|
||||
deleted_ = true;
|
||||
}
|
||||
@ -167,12 +165,12 @@ class EvilListener : public ComboboxListener {
|
||||
DISALLOW_COPY_AND_ASSIGN(EvilListener);
|
||||
};
|
||||
|
||||
class TestComboboxListener : public views::ComboboxListener {
|
||||
class TestComboboxListener {
|
||||
public:
|
||||
TestComboboxListener() = default;
|
||||
~TestComboboxListener() override = default;
|
||||
~TestComboboxListener() = default;
|
||||
|
||||
void OnPerformAction(views::Combobox* combobox) override {
|
||||
void OnPerformAction(views::Combobox* combobox) {
|
||||
perform_action_index_ = combobox->GetSelectedIndex();
|
||||
actions_performed_++;
|
||||
}
|
||||
@ -539,7 +537,8 @@ TEST_F(ComboboxTest, ListenerHandlesDelete) {
|
||||
// |combobox| will be deleted on change.
|
||||
TestCombobox* combobox = new TestCombobox(&model);
|
||||
auto evil_listener = std::make_unique<EvilListener>();
|
||||
combobox->set_listener(evil_listener.get());
|
||||
combobox->set_callback(base::BindRepeating(
|
||||
&EvilListener::OnPerformAction, base::Unretained(evil_listener.get())));
|
||||
ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2));
|
||||
EXPECT_TRUE(evil_listener->deleted());
|
||||
}
|
||||
@ -548,7 +547,8 @@ TEST_F(ComboboxTest, Click) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
combobox_->Layout();
|
||||
|
||||
// Click the left side. The menu is shown.
|
||||
@ -563,7 +563,8 @@ TEST_F(ComboboxTest, ClickButDisabled) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
|
||||
combobox_->Layout();
|
||||
combobox_->SetEnabled(false);
|
||||
@ -579,7 +580,8 @@ TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
|
||||
// The click event is ignored. Instead the menu is shown.
|
||||
PressKey(ui::VKEY_RETURN);
|
||||
@ -592,7 +594,8 @@ TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
|
||||
// The click event is ignored. Instead the menu is shwon.
|
||||
PressKey(ui::VKEY_SPACE);
|
||||
@ -638,7 +641,8 @@ TEST_F(ComboboxTest, NotifyOnClickWithMouse) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
|
||||
combobox_->Layout();
|
||||
|
||||
@ -757,7 +761,8 @@ TEST_F(ComboboxTest, TypingPrefixNotifiesListener) {
|
||||
InitCombobox(nullptr);
|
||||
|
||||
TestComboboxListener listener;
|
||||
combobox_->set_listener(&listener);
|
||||
combobox_->set_callback(base::BindRepeating(
|
||||
&TestComboboxListener::OnPerformAction, base::Unretained(&listener)));
|
||||
ui::TextInputClient* input_client =
|
||||
widget_->GetInputMethod()->GetTextInputClient();
|
||||
|
||||
|
@ -28,14 +28,14 @@ class VIEWS_EXAMPLES_EXPORT BoxLayoutExample : public LayoutExampleBase {
|
||||
// Set the border insets on the current BoxLayout instance.
|
||||
void UpdateBorderInsets();
|
||||
|
||||
// ComboboxListener
|
||||
// LayoutExampleBase:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
|
||||
// TextfieldController
|
||||
// TextfieldController:
|
||||
void ContentsChanged(Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// LayoutExampleBase
|
||||
// LayoutExampleBase:
|
||||
void ButtonPressedImpl(Button* sender) override;
|
||||
void CreateAdditionalControls(int vertical_start_pos) override;
|
||||
void UpdateLayoutManager() override;
|
||||
|
@ -46,12 +46,14 @@ void ComboboxExample::CreateExampleView(View* container) {
|
||||
|
||||
combobox_ = container->AddChildView(
|
||||
std::make_unique<Combobox>(std::make_unique<ComboboxModelExample>()));
|
||||
combobox_->set_listener(this);
|
||||
combobox_->set_callback(base::BindRepeating(&ComboboxExample::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
combobox_->SetSelectedIndex(3);
|
||||
|
||||
auto* disabled_combobox = container->AddChildView(
|
||||
std::make_unique<Combobox>(std::make_unique<ComboboxModelExample>()));
|
||||
disabled_combobox->set_listener(this);
|
||||
disabled_combobox->set_callback(base::BindRepeating(
|
||||
&ComboboxExample::OnPerformAction, base::Unretained(this)));
|
||||
disabled_combobox->SetSelectedIndex(4);
|
||||
disabled_combobox->SetEnabled(false);
|
||||
}
|
||||
|
@ -7,14 +7,13 @@
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/base/models/combobox_model.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/examples/example_base.h"
|
||||
|
||||
namespace views {
|
||||
class Combobox;
|
||||
namespace examples {
|
||||
|
||||
class VIEWS_EXAMPLES_EXPORT ComboboxExample : public ExampleBase,
|
||||
public ComboboxListener {
|
||||
class VIEWS_EXAMPLES_EXPORT ComboboxExample : public ExampleBase {
|
||||
public:
|
||||
ComboboxExample();
|
||||
~ComboboxExample() override;
|
||||
@ -23,8 +22,7 @@ class VIEWS_EXAMPLES_EXPORT ComboboxExample : public ExampleBase,
|
||||
void CreateExampleView(View* container) override;
|
||||
|
||||
private:
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
void OnPerformAction(Combobox* combobox);
|
||||
|
||||
Combobox* combobox_ = nullptr;
|
||||
|
||||
|
@ -153,7 +153,8 @@ void DialogExample::CreateExampleView(View* container) {
|
||||
|
||||
StartRowWithLabel(layout, "Modal Type");
|
||||
mode_ = layout->AddView(std::make_unique<Combobox>(&mode_model_));
|
||||
mode_->set_listener(this);
|
||||
mode_->set_closure(base::BindRepeating(&DialogExample::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
mode_->SetSelectedIndex(ui::MODAL_TYPE_CHILD);
|
||||
|
||||
StartRowWithLabel(layout, "Bubble");
|
||||
@ -274,12 +275,12 @@ void DialogExample::ButtonPressed(Button* sender, const ui::Event& event) {
|
||||
LogStatus("You nearly always want Child Modal for bubbles.");
|
||||
}
|
||||
persistent_bubble_->SetEnabled(bubble_->GetChecked());
|
||||
OnPerformAction(mode_); // Validate the modal type.
|
||||
OnPerformAction(); // Validate the modal type.
|
||||
|
||||
if (!bubble_->GetChecked() && GetModalType() == ui::MODAL_TYPE_CHILD) {
|
||||
// Do something reasonable when simply unchecking bubble and re-enable.
|
||||
mode_->SetSelectedIndex(ui::MODAL_TYPE_WINDOW);
|
||||
OnPerformAction(mode_);
|
||||
OnPerformAction();
|
||||
}
|
||||
return;
|
||||
}
|
||||
@ -310,7 +311,7 @@ void DialogExample::ContentsChanged(Textfield* sender,
|
||||
ResizeDialog();
|
||||
}
|
||||
|
||||
void DialogExample::OnPerformAction(Combobox* combobox) {
|
||||
void DialogExample::OnPerformAction() {
|
||||
bool enable = bubble_->GetChecked() || GetModalType() != ui::MODAL_TYPE_CHILD;
|
||||
#if defined(OS_APPLE)
|
||||
enable = enable && GetModalType() != ui::MODAL_TYPE_SYSTEM;
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "base/macros.h"
|
||||
#include "ui/base/models/simple_combobox_model.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/examples/example_base.h"
|
||||
|
||||
@ -27,8 +26,7 @@ namespace examples {
|
||||
// An example that exercises BubbleDialogDelegateView or DialogDelegateView.
|
||||
class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase,
|
||||
public ButtonListener,
|
||||
public TextfieldController,
|
||||
public ComboboxListener {
|
||||
public TextfieldController {
|
||||
public:
|
||||
DialogExample();
|
||||
~DialogExample() override;
|
||||
@ -50,6 +48,9 @@ class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase,
|
||||
const char* value);
|
||||
void AddCheckbox(GridLayout* layout, Checkbox** member);
|
||||
|
||||
// Checkbox callback
|
||||
void OnPerformAction();
|
||||
|
||||
// Interrogates the configuration Views for DialogDelegate.
|
||||
ui::ModalType GetModalType() const;
|
||||
int GetDialogButtons() const;
|
||||
@ -67,9 +68,6 @@ class VIEWS_EXAMPLES_EXPORT DialogExample : public ExampleBase,
|
||||
void ContentsChanged(Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
|
||||
DialogDelegate* last_dialog_ = nullptr;
|
||||
Label* last_body_label_ = nullptr;
|
||||
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include "ui/base/ui_base_paths.h"
|
||||
#include "ui/views/background.h"
|
||||
#include "ui/views/controls/combobox/combobox.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/examples/create_examples.h"
|
||||
#include "ui/views/layout/fill_layout.h"
|
||||
@ -109,8 +108,7 @@ class ComboboxModelExampleList : public ui::ComboboxModel {
|
||||
DISALLOW_COPY_AND_ASSIGN(ComboboxModelExampleList);
|
||||
};
|
||||
|
||||
class ExamplesWindowContents : public WidgetDelegateView,
|
||||
public ComboboxListener {
|
||||
class ExamplesWindowContents : public WidgetDelegateView {
|
||||
public:
|
||||
ExamplesWindowContents(base::OnceClosure on_close, ExampleVector examples)
|
||||
: on_close_(std::move(on_close)) {
|
||||
@ -122,7 +120,8 @@ class ExamplesWindowContents : public WidgetDelegateView,
|
||||
auto combobox = std::make_unique<Combobox>(std::move(combobox_model));
|
||||
|
||||
instance_ = this;
|
||||
combobox->set_listener(this);
|
||||
combobox->set_callback(base::BindRepeating(
|
||||
&ExamplesWindowContents::OnPerformAction, base::Unretained(this)));
|
||||
|
||||
SetBackground(CreateThemedSolidBackground(
|
||||
this, ui::NativeTheme::kColorId_DialogBackground));
|
||||
@ -181,10 +180,9 @@ class ExamplesWindowContents : public WidgetDelegateView,
|
||||
return size;
|
||||
}
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override {
|
||||
void OnPerformAction(Combobox* combobox) {
|
||||
DCHECK_EQ(combobox, combobox_);
|
||||
int index = combobox->GetSelectedIndex();
|
||||
int index = combobox_->GetSelectedIndex();
|
||||
DCHECK_LT(index, combobox_model_->GetItemCount());
|
||||
example_shown_->RemoveAllChildViews(false);
|
||||
example_shown_->AddChildView(combobox_model_->GetItemViewAt(index));
|
||||
|
@ -8,7 +8,6 @@
|
||||
#include "base/macros.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/button/label_button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/examples/layout_example_base.h"
|
||||
#include "ui/views/layout/flex_layout.h"
|
||||
@ -27,14 +26,10 @@ class VIEWS_EXAMPLES_EXPORT FlexLayoutExample : public LayoutExampleBase {
|
||||
~FlexLayoutExample() override;
|
||||
|
||||
private:
|
||||
// ComboboxListener
|
||||
// LayoutExampleBase:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
|
||||
// TextfieldController
|
||||
void ContentsChanged(Textfield* sender,
|
||||
const base::string16& new_contents) override;
|
||||
|
||||
// LayoutExampleBase
|
||||
void ButtonPressedImpl(Button* sender) override;
|
||||
void CreateAdditionalControls(int vertical_start_pos) override;
|
||||
void UpdateLayoutManager() override;
|
||||
|
@ -143,6 +143,8 @@ void LabelExample::ButtonPressed(Button* button, const ui::Event& event) {
|
||||
}
|
||||
|
||||
void LabelExample::OnPerformAction(Combobox* combobox) {
|
||||
// TODO(pbos): Provide different callbacks for alignment_ and elide_behavior_
|
||||
// instead.
|
||||
if (combobox == alignment_) {
|
||||
custom_label_->SetHorizontalAlignment(
|
||||
static_cast<gfx::HorizontalAlignment>(combobox->GetSelectedIndex()));
|
||||
@ -229,7 +231,8 @@ Combobox* LabelExample::AddCombobox(GridLayout* layout,
|
||||
auto combobox = std::make_unique<Combobox>(
|
||||
std::make_unique<ExampleComboboxModel>(strings, count));
|
||||
combobox->SetSelectedIndex(0);
|
||||
combobox->set_listener(this);
|
||||
combobox->set_callback(base::BindRepeating(&LabelExample::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
return layout->AddView(std::move(combobox));
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,13 @@
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/examples/example_base.h"
|
||||
|
||||
namespace views {
|
||||
|
||||
class Checkbox;
|
||||
class Combobox;
|
||||
class GridLayout;
|
||||
class Label;
|
||||
|
||||
@ -21,7 +21,6 @@ namespace examples {
|
||||
|
||||
class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase,
|
||||
public ButtonListener,
|
||||
public ComboboxListener,
|
||||
public TextfieldController {
|
||||
public:
|
||||
LabelExample();
|
||||
@ -33,8 +32,7 @@ class VIEWS_EXAMPLES_EXPORT LabelExample : public ExampleBase,
|
||||
// ButtonListener:
|
||||
void ButtonPressed(Button* button, const ui::Event& event) override;
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
void OnPerformAction(Combobox* combobox);
|
||||
|
||||
// TextfieldController:
|
||||
void ContentsChanged(Textfield* sender,
|
||||
|
@ -169,7 +169,8 @@ Combobox* LayoutExampleBase::CreateAndAddCombobox(
|
||||
gfx::Point(label->x() + label->width() + kLayoutExampleVerticalSpacing,
|
||||
*vertical_pos));
|
||||
combo_box->SizeToPreferredSize();
|
||||
combo_box->set_listener(this);
|
||||
combo_box->set_callback(base::BindRepeating(
|
||||
&LayoutExampleBase::OnPerformAction, base::Unretained(this)));
|
||||
label->SetSize(gfx::Size(label->width(), combo_box->height()));
|
||||
control_panel_->AddChildView(std::move(label));
|
||||
|
||||
|
@ -10,12 +10,13 @@
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/button/checkbox.h"
|
||||
#include "ui/views/controls/button/label_button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/controls/textfield/textfield_controller.h"
|
||||
#include "ui/views/examples/example_base.h"
|
||||
#include "ui/views/view.h"
|
||||
|
||||
namespace views {
|
||||
class Combobox;
|
||||
|
||||
namespace examples {
|
||||
|
||||
// Provides an example of a layout manager with arbitrary specific manager and
|
||||
@ -23,7 +24,6 @@ namespace examples {
|
||||
// manager of choice.
|
||||
class VIEWS_EXAMPLES_EXPORT LayoutExampleBase : public ExampleBase,
|
||||
public ButtonListener,
|
||||
public ComboboxListener,
|
||||
public TextfieldController {
|
||||
public:
|
||||
// Grouping of multiple textfields that provide insets.
|
||||
@ -127,6 +127,9 @@ class VIEWS_EXAMPLES_EXPORT LayoutExampleBase : public ExampleBase,
|
||||
// common controls is done.
|
||||
virtual void ButtonPressedImpl(Button* sender);
|
||||
|
||||
// Combobox callback defined by child classes.
|
||||
virtual void OnPerformAction(views::Combobox* combobox) = 0;
|
||||
|
||||
// Performs layout-specific update of the layout manager.
|
||||
virtual void UpdateLayoutManager() = 0;
|
||||
|
||||
|
@ -154,7 +154,8 @@ Combobox* TextExample::AddCombobox(GridLayout* layout,
|
||||
auto combobox = std::make_unique<Combobox>(
|
||||
std::make_unique<ExampleComboboxModel>(strings, count));
|
||||
combobox->SetSelectedIndex(0);
|
||||
combobox->set_listener(this);
|
||||
combobox->set_callback(base::BindRepeating(&TextExample::OnPerformAction,
|
||||
base::Unretained(this)));
|
||||
return layout->AddView(std::move(combobox), kNumColumns - 1, 1);
|
||||
}
|
||||
|
||||
|
@ -10,18 +10,17 @@
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "ui/views/controls/button/button.h"
|
||||
#include "ui/views/controls/combobox/combobox_listener.h"
|
||||
#include "ui/views/examples/example_base.h"
|
||||
|
||||
namespace views {
|
||||
class Checkbox;
|
||||
class Combobox;
|
||||
class GridLayout;
|
||||
|
||||
namespace examples {
|
||||
|
||||
class VIEWS_EXAMPLES_EXPORT TextExample : public ExampleBase,
|
||||
public ButtonListener,
|
||||
public ComboboxListener {
|
||||
public ButtonListener {
|
||||
public:
|
||||
TextExample();
|
||||
~TextExample() override;
|
||||
@ -39,12 +38,11 @@ class VIEWS_EXAMPLES_EXPORT TextExample : public ExampleBase,
|
||||
const char* const* strings,
|
||||
int count);
|
||||
|
||||
void OnPerformAction(Combobox* combobox);
|
||||
|
||||
// ButtonListener:
|
||||
void ButtonPressed(Button* button, const ui::Event& event) override;
|
||||
|
||||
// ComboboxListener:
|
||||
void OnPerformAction(Combobox* combobox) override;
|
||||
|
||||
class TextExampleView;
|
||||
// The content of the scroll view.
|
||||
TextExampleView* text_view_;
|
||||
|
Reference in New Issue
Block a user