Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(277)

Side by Side Diff: ui/views/window/dialog_delegate.cc

Issue 2151933002: DialogDelegate: allow platforms to prevent Cancel being default (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test for mac Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/window/dialog_client_view_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gfx/color_palette.h" 13 #include "ui/gfx/color_palette.h"
14 #include "ui/strings/grit/ui_strings.h" 14 #include "ui/strings/grit/ui_strings.h"
15 #include "ui/views/bubble/bubble_border.h" 15 #include "ui/views/bubble/bubble_border.h"
16 #include "ui/views/bubble/bubble_frame_view.h" 16 #include "ui/views/bubble/bubble_frame_view.h"
17 #include "ui/views/controls/button/label_button.h" 17 #include "ui/views/controls/button/label_button.h"
18 #include "ui/views/layout/layout_constants.h" 18 #include "ui/views/layout/layout_constants.h"
19 #include "ui/views/style/platform_style.h"
19 #include "ui/views/widget/widget.h" 20 #include "ui/views/widget/widget.h"
20 #include "ui/views/widget/widget_observer.h" 21 #include "ui/views/widget/widget_observer.h"
21 #include "ui/views/window/dialog_client_view.h" 22 #include "ui/views/window/dialog_client_view.h"
22 23
23 #if defined(OS_WIN) 24 #if defined(OS_WIN)
24 #include "ui/base/win/shell.h" 25 #include "ui/base/win/shell.h"
25 #endif 26 #endif
26 27
27 namespace views { 28 namespace views {
28 29
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 if ((buttons & ui::DIALOG_BUTTON_CANCEL) || 113 if ((buttons & ui::DIALOG_BUTTON_CANCEL) ||
113 (buttons == ui::DIALOG_BUTTON_NONE)) { 114 (buttons == ui::DIALOG_BUTTON_NONE)) {
114 return Cancel(); 115 return Cancel();
115 } 116 }
116 return Accept(); 117 return Accept();
117 } 118 }
118 119
119 void DialogDelegate::UpdateButton(LabelButton* button, ui::DialogButton type) { 120 void DialogDelegate::UpdateButton(LabelButton* button, ui::DialogButton type) {
120 button->SetText(GetDialogButtonLabel(type)); 121 button->SetText(GetDialogButtonLabel(type));
121 button->SetEnabled(IsDialogButtonEnabled(type)); 122 button->SetEnabled(IsDialogButtonEnabled(type));
122 button->SetIsDefault(type == GetDefaultDialogButton()); 123 bool is_default = type == GetDefaultDialogButton();
124 if (!PlatformStyle::kDialogDefaultButtonCanBeCancel &&
125 type == ui::DIALOG_BUTTON_CANCEL) {
126 is_default = false;
127 }
128 button->SetIsDefault(is_default);
123 } 129 }
124 130
125 int DialogDelegate::GetDialogButtons() const { 131 int DialogDelegate::GetDialogButtons() const {
126 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL; 132 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
127 } 133 }
128 134
129 int DialogDelegate::GetDefaultDialogButton() const { 135 int DialogDelegate::GetDefaultDialogButton() const {
130 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK) 136 if (GetDialogButtons() & ui::DIALOG_BUTTON_OK)
131 return ui::DIALOG_BUTTON_OK; 137 return ui::DIALOG_BUTTON_OK;
132 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) 138 if (GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 state->role = ui::AX_ROLE_DIALOG; 259 state->role = ui::AX_ROLE_DIALOG;
254 } 260 }
255 261
256 void DialogDelegateView::ViewHierarchyChanged( 262 void DialogDelegateView::ViewHierarchyChanged(
257 const ViewHierarchyChangedDetails& details) { 263 const ViewHierarchyChangedDetails& details) {
258 if (details.is_add && details.child == this && GetWidget()) 264 if (details.is_add && details.child == this && GetWidget())
259 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 265 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
260 } 266 }
261 267
262 } // namespace views 268 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/window/dialog_client_view_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698