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() {
}
}
// 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::View* BookmarkBubbleView::GetInitiallyFocusedView() {
......@@ -149,6 +140,13 @@ void BookmarkBubbleView::WindowClosing() {
// 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() {
edit_button_ = views::MdTextButton::CreateSecondaryUiButton(
this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
......
......@@ -59,13 +59,13 @@ class BookmarkBubbleView : public LocationBarBubbleDelegateView,
~BookmarkBubbleView() override;
// LocationBarBubbleDelegateView:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
View* GetInitiallyFocusedView() override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
gfx::ImageSkia GetWindowIcon() override;
bool ShouldShowWindowIcon() const override;
void WindowClosing() override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
views::View* CreateExtraView() override;
bool GetExtraViewPadding(int* padding) override;
views::View* CreateFootnoteView() override;
......
......@@ -74,10 +74,8 @@ class CastDialogView : public views::BubbleDialogDelegateView,
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// ui::DialogModel:
int GetDialogButtons() const override;
// views::DialogDelegate:
int GetDialogButtons() const override;
views::View* CreateExtraView() override;
bool Close() override;
......
......@@ -35,11 +35,9 @@ class CloudServicesDialogView : public views::BubbleDialogDelegateView,
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// ui::DialogModel:
// views::DialogDelegate:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDialogButtons() const override;
// views::DialogDelegate:
bool Accept() override;
bool Cancel() override;
......
......@@ -45,11 +45,9 @@ class MediaRemotingDialogView : public views::BubbleDialogDelegateView {
// views::WidgetDelegate:
base::string16 GetWindowTitle() const override;
// ui::DialogModel:
// views::DialogDelegate:
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
int GetDialogButtons() const override;
// views::DialogDelegate:
bool Accept() override;
bool Cancel() override;
bool Close() override;
......
......@@ -209,8 +209,6 @@ jumbo_component("base") {
"models/combobox_model.cc",
"models/combobox_model.h",
"models/combobox_model_observer.h",
"models/dialog_model.cc",
"models/dialog_model.h",
"models/list_model.h",
"models/list_model_observer.h",
"models/list_selection_model.cc",
......@@ -624,7 +622,6 @@ jumbo_component("base") {
"idle/idle.h",
"l10n/l10n_font_util.cc",
"models/button_menu_item_model.cc",
"models/dialog_model.cc",
"pointer/touch_editing_controller.cc",
"theme_provider.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
GetAccessibilityTokensCallback callback) override;
// DialogObserver:
void OnDialogModelChanged() override;
void OnDialogChanged() override;
// FocusChangeListener:
void OnWillChangeFocus(View* focused_before, View* focused_now) override;
......
......@@ -12,7 +12,6 @@
#include "ui/base/hit_test.h"
#include "ui/base/ime/input_method.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/display/screen.h"
#include "ui/gfx/geometry/dip_util.h"
......@@ -831,21 +830,21 @@ bool BridgedNativeWidgetHostImpl::GetDialogButtonInfo(
bool* is_button_enabled,
bool* is_button_default) {
*button_exists = false;
ui::DialogModel* model =
views::DialogDelegate* dialog =
root_view_->GetWidget()->widget_delegate()->AsDialogDelegate();
if (!model || !(model->GetDialogButtons() & button))
if (!dialog || !(dialog->GetDialogButtons() & button))
return true;
*button_exists = true;
*button_label = model->GetDialogButtonLabel(button);
*is_button_enabled = model->IsDialogButtonEnabled(button);
*is_button_default = button == model->GetDefaultDialogButton();
*button_label = dialog->GetDialogButtonLabel(button);
*is_button_enabled = dialog->IsDialogButtonEnabled(button);
*is_button_default = button == dialog->GetDefaultDialogButton();
return true;
}
bool BridgedNativeWidgetHostImpl::GetDoDialogButtonsExist(bool* buttons_exist) {
ui::DialogModel* model =
views::DialogDelegate* dialog =
root_view_->GetWidget()->widget_delegate()->AsDialogDelegate();
*buttons_exist = model && model->GetDialogButtons();
*buttons_exist = dialog && dialog->GetDialogButtons();
return true;
}
......@@ -1024,7 +1023,7 @@ void BridgedNativeWidgetHostImpl::GetAccessibilityTokens(
////////////////////////////////////////////////////////////////////////////////
// BridgedNativeWidgetHostImpl, DialogObserver:
void BridgedNativeWidgetHostImpl::OnDialogModelChanged() {
void BridgedNativeWidgetHostImpl::OnDialogChanged() {
// Note it's only necessary to clear the TouchBar. If the OS needs it again,
// a new one will be created.
bridge()->ClearTouchBar();
......
......@@ -838,7 +838,7 @@ class TestBubbleDialogDelegateView : public BubbleDialogDelegateView {
// platform and other factors.
void UseNativeWidgetAura() { use_native_widget_aura_ = true; }
// ui::DialogModel override.
// BubbleDialogDelegateView:
int GetDialogButtons() const override { return 0; }
void OnBeforeBubbleWidgetInit(Widget::InitParams* params,
......
......@@ -274,7 +274,7 @@ void DialogClientView::ChildVisibilityChanged(View* child) {
ChildPreferredSizeChanged(child);
}
void DialogClientView::OnDialogModelChanged() {
void DialogClientView::OnDialogChanged() {
UpdateDialogButtons();
}
......
......@@ -88,7 +88,7 @@ class VIEWS_EXPORT DialogClientView : public ClientView,
void ChildVisibilityChanged(View* child) override;
// DialogObserver:
void OnDialogModelChanged() override;
void OnDialogChanged() override;
// Update the dialog buttons to match the dialog's delegate.
void UpdateDialogButtons();
......
......@@ -96,6 +96,35 @@ Widget::InitParams DialogDelegate::GetDialogWidgetInitParams(
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() {
return NULL;
}
......@@ -140,35 +169,6 @@ bool DialogDelegate::ShouldSnapFrameWidth() const {
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() {
// Focus the default button if any.
const DialogClientView* dcv = GetDialogClientView();
......@@ -241,7 +241,7 @@ void DialogDelegate::RemoveObserver(DialogObserver* observer) {
void DialogDelegate::DialogModelChanged() {
for (DialogObserver& observer : observer_list_)
observer.OnDialogModelChanged();
observer.OnDialogChanged();
}
DialogDelegate::~DialogDelegate() {
......
......@@ -10,8 +10,8 @@
#include "base/strings/string16.h"
#include "base/time/time.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/models/dialog_model.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_delegate.h"
......@@ -31,8 +31,7 @@ class LabelButton;
// certain events.
//
///////////////////////////////////////////////////////////////////////////////
class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
public WidgetDelegate {
class VIEWS_EXPORT DialogDelegate : public WidgetDelegate {
public:
DialogDelegate();
......@@ -49,6 +48,24 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
gfx::NativeView parent,
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.
// Overrides may construct the view; this will only be called once per dialog.
virtual View* CreateExtraView();
......@@ -93,12 +110,6 @@ class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
// LayoutProvider's snapping.
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:
View* GetInitiallyFocusedView() override;
DialogDelegate* AsDialogDelegate() override;
......
......@@ -9,12 +9,12 @@
namespace views {
// Allows properties on a ui::DialogModel to be observed.
// Allows properties on a DialogDelegate to be observed.
class VIEWS_EXPORT DialogObserver {
public:
// Invoked when a dialog signals a model change. E.g., the enabled buttons, or
// the button titles.
virtual void OnDialogModelChanged() = 0;
virtual void OnDialogChanged() = 0;
};
} // 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