Commit 5d10a30b authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Remove ui::DialogModel

DialogModel is a currently unnecessary pure abstract class. Removing it simplifies the dialog
hierarchy.

Change-Id: Iac8c096b2879d594a723c57abcb1a05bba216e4b
Reviewed-on: https://chromium-review.googlesource.com/c/1345212Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613220}
parent 5a6e3d0b
...@@ -104,15 +104,6 @@ BookmarkBubbleView::~BookmarkBubbleView() { ...@@ -104,15 +104,6 @@ BookmarkBubbleView::~BookmarkBubbleView() {
} }
} }
// ui::DialogModel -------------------------------------------------------------
base::string16 BookmarkBubbleView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK)
? IDS_DONE
: IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK);
}
// views::WidgetDelegate ------------------------------------------------------- // views::WidgetDelegate -------------------------------------------------------
views::View* BookmarkBubbleView::GetInitiallyFocusedView() { views::View* BookmarkBubbleView::GetInitiallyFocusedView() {
...@@ -149,6 +140,13 @@ void BookmarkBubbleView::WindowClosing() { ...@@ -149,6 +140,13 @@ void BookmarkBubbleView::WindowClosing() {
// views::DialogDelegate ------------------------------------------------------- // views::DialogDelegate -------------------------------------------------------
base::string16 BookmarkBubbleView::GetDialogButtonLabel(
ui::DialogButton button) const {
return l10n_util::GetStringUTF16((button == ui::DIALOG_BUTTON_OK)
? IDS_DONE
: IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK);
}
views::View* BookmarkBubbleView::CreateExtraView() { views::View* BookmarkBubbleView::CreateExtraView() {
edit_button_ = views::MdTextButton::CreateSecondaryUiButton( edit_button_ = views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
......
...@@ -59,13 +59,13 @@ class BookmarkBubbleView : public LocationBarBubbleDelegateView, ...@@ -59,13 +59,13 @@ class BookmarkBubbleView : public LocationBarBubbleDelegateView,
~BookmarkBubbleView() override; ~BookmarkBubbleView() override;
// LocationBarBubbleDelegateView: // LocationBarBubbleDelegateView:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
View* GetInitiallyFocusedView() override; View* GetInitiallyFocusedView() override;
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override; bool ShouldShowCloseButton() const override;
gfx::ImageSkia GetWindowIcon() override; gfx::ImageSkia GetWindowIcon() override;
bool ShouldShowWindowIcon() const override; bool ShouldShowWindowIcon() const override;
void WindowClosing() override; void WindowClosing() override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
views::View* CreateExtraView() override; views::View* CreateExtraView() override;
bool GetExtraViewPadding(int* padding) override; bool GetExtraViewPadding(int* padding) override;
views::View* CreateFootnoteView() override; views::View* CreateFootnoteView() override;
......
...@@ -74,10 +74,8 @@ class CastDialogView : public views::BubbleDialogDelegateView, ...@@ -74,10 +74,8 @@ class CastDialogView : public views::BubbleDialogDelegateView,
// views::WidgetDelegate: // views::WidgetDelegate:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
// ui::DialogModel:
int GetDialogButtons() const override;
// views::DialogDelegate: // views::DialogDelegate:
int GetDialogButtons() const override;
views::View* CreateExtraView() override; views::View* CreateExtraView() override;
bool Close() override; bool Close() override;
......
...@@ -35,11 +35,9 @@ class CloudServicesDialogView : public views::BubbleDialogDelegateView, ...@@ -35,11 +35,9 @@ class CloudServicesDialogView : public views::BubbleDialogDelegateView,
// views::WidgetDelegate: // views::WidgetDelegate:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
// ui::DialogModel: // views::DialogDelegate:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDialogButtons() const override; int GetDialogButtons() const override;
// views::DialogDelegate:
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
......
...@@ -45,11 +45,9 @@ class MediaRemotingDialogView : public views::BubbleDialogDelegateView { ...@@ -45,11 +45,9 @@ class MediaRemotingDialogView : public views::BubbleDialogDelegateView {
// views::WidgetDelegate: // views::WidgetDelegate:
base::string16 GetWindowTitle() const override; base::string16 GetWindowTitle() const override;
// ui::DialogModel: // views::DialogDelegate:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override; base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDialogButtons() const override; int GetDialogButtons() const override;
// views::DialogDelegate:
bool Accept() override; bool Accept() override;
bool Cancel() override; bool Cancel() override;
bool Close() override; bool Close() override;
......
...@@ -209,8 +209,6 @@ jumbo_component("base") { ...@@ -209,8 +209,6 @@ jumbo_component("base") {
"models/combobox_model.cc", "models/combobox_model.cc",
"models/combobox_model.h", "models/combobox_model.h",
"models/combobox_model_observer.h", "models/combobox_model_observer.h",
"models/dialog_model.cc",
"models/dialog_model.h",
"models/list_model.h", "models/list_model.h",
"models/list_model_observer.h", "models/list_model_observer.h",
"models/list_selection_model.cc", "models/list_selection_model.cc",
...@@ -624,7 +622,6 @@ jumbo_component("base") { ...@@ -624,7 +622,6 @@ jumbo_component("base") {
"idle/idle.h", "idle/idle.h",
"l10n/l10n_font_util.cc", "l10n/l10n_font_util.cc",
"models/button_menu_item_model.cc", "models/button_menu_item_model.cc",
"models/dialog_model.cc",
"pointer/touch_editing_controller.cc", "pointer/touch_editing_controller.cc",
"theme_provider.cc", "theme_provider.cc",
"ui_base_types.cc", "ui_base_types.cc",
......
// Copyright (c) 2013 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 "ui/base/models/dialog_model.h"
namespace ui {
DialogModel::~DialogModel() {
}
} // namespace ui
// Copyright (c) 2013 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_BASE_MODELS_DIALOG_MODEL_H_
#define UI_BASE_MODELS_DIALOG_MODEL_H_
#include "base/strings/string16.h"
#include "ui/base/ui_base_export.h"
#include "ui/base/ui_base_types.h"
namespace ui {
// A model representing a dialog window. The model provides the content to show
// to the user (i.e. title), and the ways the user can interact with it
// (i.e. the buttons).
class UI_BASE_EXPORT DialogModel {
public:
virtual ~DialogModel();
// Returns a mask specifying which of the available DialogButtons are visible
// for the dialog. Note: Dialogs with just an OK button are frowned upon.
virtual int GetDialogButtons() const = 0;
// Returns the default dialog button. This should not be a mask as only
// one button should ever be the default button. Return
// ui::DIALOG_BUTTON_NONE if there is no default. Default
// behavior is to return ui::DIALOG_BUTTON_OK or
// ui::DIALOG_BUTTON_CANCEL (in that order) if they are
// present, ui::DIALOG_BUTTON_NONE otherwise.
virtual int GetDefaultDialogButton() const = 0;
// Returns the label of the specified dialog button.
virtual base::string16 GetDialogButtonLabel(DialogButton button) const = 0;
// Returns whether the specified dialog button is enabled.
virtual bool IsDialogButtonEnabled(DialogButton button) const = 0;
};
} // namespace ui
#endif // UI_BASE_MODELS_DIALOG_MODEL_H_
...@@ -301,7 +301,7 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl ...@@ -301,7 +301,7 @@ class VIEWS_EXPORT BridgedNativeWidgetHostImpl
GetAccessibilityTokensCallback callback) override; GetAccessibilityTokensCallback callback) override;
// DialogObserver: // DialogObserver:
void OnDialogModelChanged() override; void OnDialogChanged() override;
// FocusChangeListener: // FocusChangeListener:
void OnWillChangeFocus(View* focused_before, View* focused_now) override; void OnWillChangeFocus(View* focused_before, View* focused_now) override;
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.h" #include "ui/base/ime/input_method.h"
#include "ui/base/ime/input_method_factory.h" #include "ui/base/ime/input_method_factory.h"
#include "ui/base/models/dialog_model.h"
#include "ui/compositor/recyclable_compositor_mac.h" #include "ui/compositor/recyclable_compositor_mac.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/gfx/geometry/dip_util.h" #include "ui/gfx/geometry/dip_util.h"
...@@ -831,21 +830,21 @@ bool BridgedNativeWidgetHostImpl::GetDialogButtonInfo( ...@@ -831,21 +830,21 @@ bool BridgedNativeWidgetHostImpl::GetDialogButtonInfo(
bool* is_button_enabled, bool* is_button_enabled,
bool* is_button_default) { bool* is_button_default) {
*button_exists = false; *button_exists = false;
ui::DialogModel* model = views::DialogDelegate* dialog =
root_view_->GetWidget()->widget_delegate()->AsDialogDelegate(); root_view_->GetWidget()->widget_delegate()->AsDialogDelegate();
if (!model || !(model->GetDialogButtons() & button)) if (!dialog || !(dialog->GetDialogButtons() & button))
return true; return true;
*button_exists = true; *button_exists = true;
*button_label = model->GetDialogButtonLabel(button); *button_label = dialog->GetDialogButtonLabel(button);
*is_button_enabled = model->IsDialogButtonEnabled(button); *is_button_enabled = dialog->IsDialogButtonEnabled(button);
*is_button_default = button == model->GetDefaultDialogButton(); *is_button_default = button == dialog->GetDefaultDialogButton();
return true; return true;
} }
bool BridgedNativeWidgetHostImpl::GetDoDialogButtonsExist(bool* buttons_exist) { bool BridgedNativeWidgetHostImpl::GetDoDialogButtonsExist(bool* buttons_exist) {
ui::DialogModel* model = views::DialogDelegate* dialog =
root_view_->GetWidget()->widget_delegate()->AsDialogDelegate(); root_view_->GetWidget()->widget_delegate()->AsDialogDelegate();
*buttons_exist = model && model->GetDialogButtons(); *buttons_exist = dialog && dialog->GetDialogButtons();
return true; return true;
} }
...@@ -1024,7 +1023,7 @@ void BridgedNativeWidgetHostImpl::GetAccessibilityTokens( ...@@ -1024,7 +1023,7 @@ void BridgedNativeWidgetHostImpl::GetAccessibilityTokens(
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, DialogObserver: // BridgedNativeWidgetHostImpl, DialogObserver:
void BridgedNativeWidgetHostImpl::OnDialogModelChanged() { void BridgedNativeWidgetHostImpl::OnDialogChanged() {
// Note it's only necessary to clear the TouchBar. If the OS needs it again, // Note it's only necessary to clear the TouchBar. If the OS needs it again,
// a new one will be created. // a new one will be created.
bridge()->ClearTouchBar(); bridge()->ClearTouchBar();
......
...@@ -838,7 +838,7 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView { ...@@ -838,7 +838,7 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
// platform and other factors. // platform and other factors.
void UseNativeWidgetAura() { use_native_widget_aura_ = true; } void UseNativeWidgetAura() { use_native_widget_aura_ = true; }
// ui::DialogModel override. // BubbleDialogDelegateView:
int GetDialogButtons() const override { return 0; } int GetDialogButtons() const override { return 0; }
void OnBeforeBubbleWidgetInit(Widget::InitParams* params, void OnBeforeBubbleWidgetInit(Widget::InitParams* params,
......
...@@ -274,7 +274,7 @@ void DialogClientView::ChildVisibilityChanged(View* child) { ...@@ -274,7 +274,7 @@ void DialogClientView::ChildVisibilityChanged(View* child) {
ChildPreferredSizeChanged(child); ChildPreferredSizeChanged(child);
} }
void DialogClientView::OnDialogModelChanged() { void DialogClientView::OnDialogChanged() {
UpdateDialogButtons(); UpdateDialogButtons();
} }
......
...@@ -88,7 +88,7 @@ class VIEWS_EXPORT DialogClientView : public ClientView, ...@@ -88,7 +88,7 @@ class VIEWS_EXPORT DialogClientView : public ClientView,
void ChildVisibilityChanged(View* child) override; void ChildVisibilityChanged(View* child) override;
// DialogObserver: // DialogObserver:
void OnDialogModelChanged() override; void OnDialogChanged() override;
// Update the dialog buttons to match the dialog's delegate. // Update the dialog buttons to match the dialog's delegate.
void UpdateDialogButtons(); void UpdateDialogButtons();
......
...@@ -96,6 +96,35 @@ Widget::InitParams DialogDelegate::GetDialogWidgetInitParams( ...@@ -96,6 +96,35 @@ Widget::InitParams DialogDelegate::GetDialogWidgetInitParams(
return params; return params;
} }
int DialogDelegate::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
int DialogDelegate::GetDefaultDialogButton() const {
if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
return ui::DIALOG_BUTTON_OK;
if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL)
return ui::DIALOG_BUTTON_CANCEL;
return ui::DIALOG_BUTTON_NONE;
}
base::string16 DialogDelegate::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_APP_OK);
if (button == ui::DIALOG_BUTTON_CANCEL) {
if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_APP_CANCEL);
return l10n_util::GetStringUTF16(IDS_APP_CLOSE);
}
NOTREACHED();
return base::string16();
}
bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const {
return true;
}
View* DialogDelegate::CreateExtraView() { View* DialogDelegate::CreateExtraView() {
return NULL; return NULL;
} }
...@@ -140,35 +169,6 @@ bool DialogDelegate::ShouldSnapFrameWidth() const { ...@@ -140,35 +169,6 @@ bool DialogDelegate::ShouldSnapFrameWidth() const {
return GetDialogButtons() != ui::DIALOG_BUTTON_NONE; return GetDialogButtons() != ui::DIALOG_BUTTON_NONE;
} }
int DialogDelegate::GetDialogButtons() const {
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
int DialogDelegate::GetDefaultDialogButton() const {
if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
return ui::DIALOG_BUTTON_OK;
if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL)
return ui::DIALOG_BUTTON_CANCEL;
return ui::DIALOG_BUTTON_NONE;
}
base::string16 DialogDelegate::GetDialogButtonLabel(
ui::DialogButton button) const {
if (button == ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_APP_OK);
if (button == ui::DIALOG_BUTTON_CANCEL) {
if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
return l10n_util::GetStringUTF16(IDS_APP_CANCEL);
return l10n_util::GetStringUTF16(IDS_APP_CLOSE);
}
NOTREACHED();
return base::string16();
}
bool DialogDelegate::IsDialogButtonEnabled(ui::DialogButton button) const {
return true;
}
View* DialogDelegate::GetInitiallyFocusedView() { View* DialogDelegate::GetInitiallyFocusedView() {
// Focus the default button if any. // Focus the default button if any.
const DialogClientView* dcv = GetDialogClientView(); const DialogClientView* dcv = GetDialogClientView();
...@@ -241,7 +241,7 @@ void DialogDelegate::RemoveObserver(DialogObserver* observer) { ...@@ -241,7 +241,7 @@ void DialogDelegate::RemoveObserver(DialogObserver* observer) {
void DialogDelegate::DialogModelChanged() { void DialogDelegate::DialogModelChanged() {
for (DialogObserver& observer : observer_list_) for (DialogObserver& observer : observer_list_)
observer.OnDialogModelChanged(); observer.OnDialogChanged();
} }
DialogDelegate::~DialogDelegate() { DialogDelegate::~DialogDelegate() {
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/models/dialog_model.h"
#include "ui/base/ui_base_types.h" #include "ui/base/ui_base_types.h"
#include "ui/views/views_export.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h" #include "ui/views/widget/widget_delegate.h"
...@@ -31,8 +31,7 @@ class LabelButton; ...@@ -31,8 +31,7 @@ class LabelButton;
// certain events. // certain events.
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT DialogDelegate : public ui::DialogModel, class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
public WidgetDelegate {
public: public:
DialogDelegate(); DialogDelegate();
...@@ -49,6 +48,24 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel, ...@@ -49,6 +48,24 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
gfx::NativeView parent, gfx::NativeView parent,
const gfx::Rect& bounds); const gfx::Rect& bounds);
// Returns a mask specifying which of the available DialogButtons are visible
// for the dialog. Note: Dialogs with just an OK button are frowned upon.
virtual int GetDialogButtons() const;
// Returns the default dialog button. This should not be a mask as only
// one button should ever be the default button. Return
// ui::DIALOG_BUTTON_NONE if there is no default. Default
// behavior is to return ui::DIALOG_BUTTON_OK or
// ui::DIALOG_BUTTON_CANCEL (in that order) if they are
// present, ui::DIALOG_BUTTON_NONE otherwise.
virtual int GetDefaultDialogButton() const;
// Returns the label of the specified dialog button.
virtual base::string16 GetDialogButtonLabel(ui::DialogButton button) const;
// Returns whether the specified dialog button is enabled.
virtual bool IsDialogButtonEnabled(ui::DialogButton button) const;
// Override this function to display an extra view adjacent to the buttons. // Override this function to display an extra view adjacent to the buttons.
// Overrides may construct the view; this will only be called once per dialog. // Overrides may construct the view; this will only be called once per dialog.
virtual View* CreateExtraView(); virtual View* CreateExtraView();
...@@ -93,12 +110,6 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel, ...@@ -93,12 +110,6 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
// LayoutProvider's snapping. // LayoutProvider's snapping.
virtual bool ShouldSnapFrameWidth() const; virtual bool ShouldSnapFrameWidth() const;
// Overridden from ui::DialogModel:
int GetDialogButtons() const override;
int GetDefaultDialogButton() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
// Overridden from WidgetDelegate: // Overridden from WidgetDelegate:
View* GetInitiallyFocusedView() override; View* GetInitiallyFocusedView() override;
DialogDelegate* AsDialogDelegate() override; DialogDelegate* AsDialogDelegate() override;
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
namespace views { namespace views {
// Allows properties on a ui::DialogModel to be observed. // Allows properties on a DialogDelegate to be observed.
class VIEWS_EXPORT DialogObserver { class VIEWS_EXPORT DialogObserver {
public: public:
// Invoked when a dialog signals a model change. E.g., the enabled buttons, or // Invoked when a dialog signals a model change. E.g., the enabled buttons, or
// the button titles. // the button titles.
virtual void OnDialogModelChanged() = 0; virtual void OnDialogChanged() = 0;
}; };
} // namespace views } // namespace views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment