Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/window/dialog_delegate.h" | 5 #include "ui/views/window/dialog_delegate.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | |
| 13 #include "ui/gfx/color_palette.h" | 14 #include "ui/gfx/color_palette.h" |
| 14 #include "ui/strings/grit/ui_strings.h" | 15 #include "ui/strings/grit/ui_strings.h" |
| 15 #include "ui/views/bubble/bubble_border.h" | 16 #include "ui/views/bubble/bubble_border.h" |
| 16 #include "ui/views/bubble/bubble_frame_view.h" | 17 #include "ui/views/bubble/bubble_frame_view.h" |
| 17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 18 #include "ui/views/layout/layout_constants.h" | 19 #include "ui/views/layout/layout_constants.h" |
| 19 #include "ui/views/style/platform_style.h" | 20 #include "ui/views/style/platform_style.h" |
| 20 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 21 #include "ui/views/widget/widget_observer.h" | 22 #include "ui/views/widget/widget_observer.h" |
| 22 #include "ui/views/window/dialog_client_view.h" | 23 #include "ui/views/window/dialog_client_view.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 button->SetText(GetDialogButtonLabel(type)); | 122 button->SetText(GetDialogButtonLabel(type)); |
| 122 button->SetEnabled(IsDialogButtonEnabled(type)); | 123 button->SetEnabled(IsDialogButtonEnabled(type)); |
| 123 bool is_default = type == GetDefaultDialogButton(); | 124 bool is_default = type == GetDefaultDialogButton(); |
| 124 if (!PlatformStyle::kDialogDefaultButtonCanBeCancel && | 125 if (!PlatformStyle::kDialogDefaultButtonCanBeCancel && |
| 125 type == ui::DIALOG_BUTTON_CANCEL) { | 126 type == ui::DIALOG_BUTTON_CANCEL) { |
| 126 is_default = false; | 127 is_default = false; |
| 127 } | 128 } |
| 128 button->SetIsDefault(is_default); | 129 button->SetIsDefault(is_default); |
| 129 } | 130 } |
| 130 | 131 |
| 132 DialogDelegate::DialogWidth DialogDelegate::GetDefaultDialogWidth() const { | |
| 133 return DIALOG_WIDTH_DEFAULT; | |
| 134 } | |
| 135 | |
| 131 int DialogDelegate::GetDialogButtons() const { | 136 int DialogDelegate::GetDialogButtons() const { |
| 132 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; | 137 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; |
| 133 } | 138 } |
| 134 | 139 |
| 135 int DialogDelegate::GetDefaultDialogButton() const { | 140 int DialogDelegate::GetDefaultDialogButton() const { |
| 136 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) | 141 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) |
| 137 return ui::DIALOG_BUTTON_OK; | 142 return ui::DIALOG_BUTTON_OK; |
| 138 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) | 143 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) |
| 139 return ui::DIALOG_BUTTON_CANCEL; | 144 return ui::DIALOG_BUTTON_CANCEL; |
| 140 return ui::DIALOG_BUTTON_NONE; | 145 return ui::DIALOG_BUTTON_NONE; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 261 state->name = GetWindowTitle(); | 266 state->name = GetWindowTitle(); |
| 262 state->role = ui::AX_ROLE_DIALOG; | 267 state->role = ui::AX_ROLE_DIALOG; |
| 263 } | 268 } |
| 264 | 269 |
| 265 void DialogDelegateView::ViewHierarchyChanged( | 270 void DialogDelegateView::ViewHierarchyChanged( |
| 266 const ViewHierarchyChangedDetails& details) { | 271 const ViewHierarchyChangedDetails& details) { |
| 267 if (details.is_add && details.child == this && GetWidget()) | 272 if (details.is_add && details.child == this && GetWidget()) |
| 268 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 273 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 269 } | 274 } |
| 270 | 275 |
| 276 gfx::Size DialogDelegateView::GetPreferredSize() const { | |
| 277 int height = View::GetPreferredSize().height(); | |
|
Evan Stade
2016/09/28 16:14:37
you should get the width in the switch statement b
Elly Fong-Jones
2016/09/28 18:44:09
Done.
| |
| 278 DialogDelegate::DialogWidth width = DialogDelegate::DIALOG_WIDTH_DEFAULT; | |
| 279 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) | |
| 280 width = GetDefaultDialogWidth(); | |
| 281 switch (width) { | |
| 282 case DialogDelegate::DIALOG_WIDTH_SMALL: return gfx::Size(320, height); | |
| 283 case DialogDelegate::DIALOG_WIDTH_MEDIUM: return gfx::Size(448, height); | |
| 284 case DialogDelegate::DIALOG_WIDTH_LARGE: return gfx::Size(512, height); | |
| 285 default: return View::GetPreferredSize(); | |
|
Evan Stade
2016/09/28 16:14:37
don't we want to enforce small/medium/large? If we
Evan Stade
2016/09/28 16:14:37
nit: better not to have a default --- explicitly l
Elly Fong-Jones
2016/09/28 18:44:09
We do, but we can't right now, until every DialogD
Elly Fong-Jones
2016/09/28 18:44:09
Done.
Evan Stade
2016/09/28 21:12:38
if every dialogdelegate is going to need to explic
| |
| 286 } | |
| 287 return gfx::Size(); | |
| 288 } | |
| 289 | |
| 271 } // namespace views | 290 } // namespace views |
| OLD | NEW |