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

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

Issue 1690133003: DialogClientView: Correct the order in which subviews are focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 10 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
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_client_view.h" 5 #include "ui/views/window/dialog_client_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 } 73 }
74 74
75 void DialogClientView::CancelWindow() { 75 void DialogClientView::CancelWindow() {
76 // Only notify the delegate once. See |notified_delegate_|'s comment. 76 // Only notify the delegate once. See |notified_delegate_|'s comment.
77 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) { 77 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) {
78 notified_delegate_ = true; 78 notified_delegate_ = true;
79 Close(); 79 Close();
80 } 80 }
81 } 81 }
82 82
83 void DialogClientView::UpdateDialogButtons() { 83 void DialogClientView::UpdateOKButton() {
84 const int buttons = GetDialogDelegate()->GetDialogButtons(); 84 const int buttons = GetDialogDelegate()->GetDialogButtons();
85 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE);
86
87 if (buttons & ui::DIALOG_BUTTON_OK) { 85 if (buttons & ui::DIALOG_BUTTON_OK) {
88 if (!ok_button_) { 86 if (!ok_button_) {
89 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); 87 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK);
90 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) 88 if (!(buttons & ui::DIALOG_BUTTON_CANCEL))
91 ok_button_->AddAccelerator(escape); 89 ok_button_->AddAccelerator(
90 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
92 AddChildView(ok_button_); 91 AddChildView(ok_button_);
93 } 92 }
94 93
95 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK); 94 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK);
96 } else if (ok_button_) { 95 } else if (ok_button_) {
97 delete ok_button_; 96 delete ok_button_;
98 ok_button_ = NULL; 97 ok_button_ = NULL;
99 } 98 }
99 }
100 100
101 if (buttons & ui::DIALOG_BUTTON_CANCEL) { 101 void DialogClientView::UpdateCancelButton() {
102 if (GetDialogDelegate()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) {
102 if (!cancel_button_) { 103 if (!cancel_button_) {
103 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); 104 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
104 cancel_button_->AddAccelerator(escape); 105 cancel_button_->AddAccelerator(
106 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
105 AddChildView(cancel_button_); 107 AddChildView(cancel_button_);
106 } 108 }
107 109
108 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL); 110 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL);
109 } else if (cancel_button_) { 111 } else if (cancel_button_) {
110 delete cancel_button_; 112 delete cancel_button_;
111 cancel_button_ = NULL; 113 cancel_button_ = NULL;
112 } 114 }
115 }
116
117 void DialogClientView::UpdateDialogButtons() {
118 // Add buttons in left to right order, so that they focus order is left to
tapted 2016/02/15 06:24:14 nit: they -> the is left to right -> matches
karandeepb 2016/02/15 06:59:15 Done.
tapted 2016/02/15 10:22:20 (I think you missed the second line of this nit :)
karandeepb 2016/02/15 23:29:33 Done.
119 // right.
120 if (kIsOkButtonOnLeftSide) {
121 UpdateOKButton();
122 UpdateCancelButton();
123 } else {
124 UpdateCancelButton();
125 UpdateOKButton();
126 }
113 127
114 // Use the escape key to close the window if there are no dialog buttons. 128 // Use the escape key to close the window if there are no dialog buttons.
115 if (!has_dialog_buttons()) 129 if (!has_dialog_buttons())
116 AddAccelerator(escape); 130 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
117 else 131 else
118 ResetAccelerators(); 132 ResetAccelerators();
119 } 133 }
120 134
121 /////////////////////////////////////////////////////////////////////////////// 135 ///////////////////////////////////////////////////////////////////////////////
122 // DialogClientView, ClientView overrides: 136 // DialogClientView, ClientView overrides:
123 137
124 bool DialogClientView::CanClose() { 138 bool DialogClientView::CanClose() {
125 if (notified_delegate_) 139 if (notified_delegate_)
126 return true; 140 return true;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { 254 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) {
241 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE); 255 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE);
242 Close(); 256 Close();
243 return true; 257 return true;
244 } 258 }
245 259
246 void DialogClientView::ViewHierarchyChanged( 260 void DialogClientView::ViewHierarchyChanged(
247 const ViewHierarchyChangedDetails& details) { 261 const ViewHierarchyChangedDetails& details) {
248 ClientView::ViewHierarchyChanged(details); 262 ClientView::ViewHierarchyChanged(details);
249 if (details.is_add && details.child == this) { 263 if (details.is_add && details.child == this) {
264 CreateExtraView();
250 UpdateDialogButtons(); 265 UpdateDialogButtons();
251 CreateExtraView();
252 CreateFootnoteView(); 266 CreateFootnoteView();
253 } else if (!details.is_add && details.child != this) { 267 } else if (!details.is_add && details.child != this) {
254 if (details.child == ok_button_) 268 if (details.child == ok_button_)
255 ok_button_ = NULL; 269 ok_button_ = NULL;
256 if (details.child == cancel_button_) 270 if (details.child == cancel_button_)
257 cancel_button_ = NULL; 271 cancel_button_ = NULL;
258 } 272 }
259 } 273 }
260 274
261 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 275 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 gfx::Insets(0, kButtonHEdgeMarginNew, 388 gfx::Insets(0, kButtonHEdgeMarginNew,
375 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); 389 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew);
376 } 390 }
377 391
378 void DialogClientView::Close() { 392 void DialogClientView::Close() {
379 GetWidget()->Close(); 393 GetWidget()->Close();
380 GetDialogDelegate()->OnClosed(); 394 GetDialogDelegate()->OnClosed();
381 } 395 }
382 396
383 } // namespace views 397 } // namespace views
OLDNEW
« ui/views/window/dialog_client_view.h ('K') | « ui/views/window/dialog_client_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698