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

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: Addressed review comments. 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
« no previous file with comments | « ui/views/window/dialog_client_view.h ('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_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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::UpdateDialogButtons() {
84 const int buttons = GetDialogDelegate()->GetDialogButtons(); 84 // Add buttons in left to right order, so that the focus order is left to
85 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); 85 // right.
86 86 if (kIsOkButtonOnLeftSide) {
87 if (buttons & ui::DIALOG_BUTTON_OK) { 87 UpdateOKButton();
88 if (!ok_button_) { 88 UpdateCancelButton();
89 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); 89 } else {
90 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) 90 UpdateCancelButton();
91 ok_button_->AddAccelerator(escape); 91 UpdateOKButton();
92 AddChildView(ok_button_);
93 }
94
95 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK);
96 } else if (ok_button_) {
97 delete ok_button_;
98 ok_button_ = NULL;
99 }
100
101 if (buttons & ui::DIALOG_BUTTON_CANCEL) {
102 if (!cancel_button_) {
103 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
104 cancel_button_->AddAccelerator(escape);
105 AddChildView(cancel_button_);
106 }
107
108 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL);
109 } else if (cancel_button_) {
110 delete cancel_button_;
111 cancel_button_ = NULL;
112 } 92 }
113 93
114 // Use the escape key to close the window if there are no dialog buttons. 94 // Use the escape key to close the window if there are no dialog buttons.
115 if (!has_dialog_buttons()) 95 if (!has_dialog_buttons())
116 AddAccelerator(escape); 96 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
117 else 97 else
118 ResetAccelerators(); 98 ResetAccelerators();
119 } 99 }
120 100
121 /////////////////////////////////////////////////////////////////////////////// 101 ///////////////////////////////////////////////////////////////////////////////
122 // DialogClientView, ClientView overrides: 102 // DialogClientView, ClientView overrides:
123 103
124 bool DialogClientView::CanClose() { 104 bool DialogClientView::CanClose() {
125 if (notified_delegate_) 105 if (notified_delegate_)
126 return true; 106 return true;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { 220 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) {
241 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE); 221 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE);
242 Close(); 222 Close();
243 return true; 223 return true;
244 } 224 }
245 225
246 void DialogClientView::ViewHierarchyChanged( 226 void DialogClientView::ViewHierarchyChanged(
247 const ViewHierarchyChangedDetails& details) { 227 const ViewHierarchyChangedDetails& details) {
248 ClientView::ViewHierarchyChanged(details); 228 ClientView::ViewHierarchyChanged(details);
249 if (details.is_add && details.child == this) { 229 if (details.is_add && details.child == this) {
230 CreateExtraView();
250 UpdateDialogButtons(); 231 UpdateDialogButtons();
251 CreateExtraView();
252 CreateFootnoteView(); 232 CreateFootnoteView();
253 } else if (!details.is_add && details.child != this) { 233 } else if (!details.is_add && details.child != this) {
254 if (details.child == ok_button_) 234 if (details.child == ok_button_)
255 ok_button_ = NULL; 235 ok_button_ = NULL;
256 if (details.child == cancel_button_) 236 if (details.child == cancel_button_)
257 cancel_button_ = NULL; 237 cancel_button_ = NULL;
258 } 238 }
259 } 239 }
260 240
261 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) { 241 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 } 332 }
353 333
354 void DialogClientView::UpdateButton(LabelButton* button, 334 void DialogClientView::UpdateButton(LabelButton* button,
355 ui::DialogButton type) { 335 ui::DialogButton type) {
356 DialogDelegate* dialog = GetDialogDelegate(); 336 DialogDelegate* dialog = GetDialogDelegate();
357 button->SetText(dialog->GetDialogButtonLabel(type)); 337 button->SetText(dialog->GetDialogButtonLabel(type));
358 button->SetEnabled(dialog->IsDialogButtonEnabled(type)); 338 button->SetEnabled(dialog->IsDialogButtonEnabled(type));
359 button->SetIsDefault(type == dialog->GetDefaultDialogButton()); 339 button->SetIsDefault(type == dialog->GetDefaultDialogButton());
360 } 340 }
361 341
342 void DialogClientView::UpdateOKButton() {
343 const int buttons = GetDialogDelegate()->GetDialogButtons();
344 if (buttons & ui::DIALOG_BUTTON_OK) {
345 if (!ok_button_) {
346 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK);
347 if (!(buttons & ui::DIALOG_BUTTON_CANCEL))
348 ok_button_->AddAccelerator(
349 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
350 AddChildView(ok_button_);
351 }
352
353 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK);
354 } else if (ok_button_) {
355 delete ok_button_;
356 ok_button_ = NULL;
tapted 2016/02/15 10:22:20 nit: now this is a move in the diff it should prob
karandeepb 2016/02/15 23:29:33 Done.
357 }
358 }
359
360 void DialogClientView::UpdateCancelButton() {
361 if (GetDialogDelegate()->GetDialogButtons() & ui::DIALOG_BUTTON_CANCEL) {
362 if (!cancel_button_) {
363 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL);
364 cancel_button_->AddAccelerator(
365 ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE));
366 AddChildView(cancel_button_);
367 }
368
369 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL);
370 } else if (cancel_button_) {
371 delete cancel_button_;
372 cancel_button_ = NULL;
373 }
374 }
375
362 int DialogClientView::GetButtonsAndExtraViewRowHeight() const { 376 int DialogClientView::GetButtonsAndExtraViewRowHeight() const {
363 int extra_view_height = ShouldShow(extra_view_) ? 377 int extra_view_height = ShouldShow(extra_view_) ?
364 extra_view_->GetPreferredSize().height() : 0; 378 extra_view_->GetPreferredSize().height() : 0;
365 int buttons_height = std::max( 379 int buttons_height = std::max(
366 ok_button_ ? ok_button_->GetPreferredSize().height() : 0, 380 ok_button_ ? ok_button_->GetPreferredSize().height() : 0,
367 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0); 381 cancel_button_ ? cancel_button_->GetPreferredSize().height() : 0);
368 return std::max(extra_view_height, buttons_height); 382 return std::max(extra_view_height, buttons_height);
369 } 383 }
370 384
371 gfx::Insets DialogClientView::GetButtonRowInsets() const { 385 gfx::Insets DialogClientView::GetButtonRowInsets() const {
372 // NOTE: The insets only apply to the buttons, extra view, and footnote view. 386 // NOTE: The insets only apply to the buttons, extra view, and footnote view.
373 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : 387 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() :
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
« no previous file with comments | « 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