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_client_view.h" | 5 #include "ui/views/window/dialog_client_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ui/base/keycodes/keyboard_codes.h" | 9 #include "ui/base/keycodes/keyboard_codes.h" |
| 10 #include "ui/views/controls/button/label_button.h" | 10 #include "ui/views/controls/button/label_button.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 | 47 |
| 48 void DialogClientView::AcceptWindow() { | 48 void DialogClientView::AcceptWindow() { |
| 49 // Only notify the delegate once. See |notified_delegate_|'s comment. | 49 // Only notify the delegate once. See |notified_delegate_|'s comment. |
| 50 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { | 50 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { |
| 51 notified_delegate_ = true; | 51 notified_delegate_ = true; |
| 52 Close(); | 52 Close(); |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 void DialogClientView::CancelWindow() { | 56 void DialogClientView::CancelWindow() { |
| 57 // Call the standard Close handler, which checks with the delegate before | 57 // Only notify the delegate once. See |notified_delegate_|'s comment. |
| 58 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, | 58 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) { |
| 59 // so that the close box on the window also shares this code path. | 59 notified_delegate_ = true; |
| 60 Close(); | 60 Close(); |
| 61 } | |
| 61 } | 62 } |
| 62 | 63 |
| 63 void DialogClientView::UpdateDialogButtons() { | 64 void DialogClientView::UpdateDialogButtons() { |
| 64 const int buttons = GetDialogDelegate()->GetDialogButtons(); | 65 const int buttons = GetDialogDelegate()->GetDialogButtons(); |
| 65 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 66 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
| 66 if (default_button_) | 67 if (default_button_) |
| 67 default_button_->SetIsDefault(false); | 68 default_button_->SetIsDefault(false); |
| 68 default_button_ = NULL; | 69 default_button_ = NULL; |
| 69 | 70 |
| 70 if (buttons & ui::DIALOG_BUTTON_OK) { | 71 if (buttons & ui::DIALOG_BUTTON_OK) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 101 ResetAccelerators(); | 102 ResetAccelerators(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 /////////////////////////////////////////////////////////////////////////////// | 105 /////////////////////////////////////////////////////////////////////////////// |
| 105 // DialogClientView, ClientView overrides: | 106 // DialogClientView, ClientView overrides: |
| 106 | 107 |
| 107 bool DialogClientView::CanClose() { | 108 bool DialogClientView::CanClose() { |
| 108 if (notified_delegate_) | 109 if (notified_delegate_) |
| 109 return true; | 110 return true; |
| 110 | 111 |
| 111 DialogDelegate* dialog = GetDialogDelegate(); | 112 // The dialog is closing but no Accept or Cancel action has been performed |
| 112 int buttons = dialog->GetDialogButtons(); | 113 // before: it's a Dismiss action. |
| 113 bool close = true; | 114 if (GetDialogDelegate()->Dismiss()) { |
| 114 if ((buttons & ui::DIALOG_BUTTON_CANCEL) || | 115 notified_delegate_ = true; |
| 115 (buttons == ui::DIALOG_BUTTON_NONE)) | 116 GetDialogDelegate()->OnClose(); |
|
fdoray
2013/06/28 15:32:59
Before this CL, DialogDelegate::OnClose was not ca
| |
| 116 close = dialog->Cancel(); | 117 return true; |
| 117 else if (buttons & ui::DIALOG_BUTTON_OK) | 118 } |
| 118 close = dialog->Accept(true); | 119 return false; |
| 119 notified_delegate_ = close; | |
| 120 return close; | |
| 121 } | 120 } |
| 122 | 121 |
| 123 DialogClientView* DialogClientView::AsDialogClientView() { | 122 DialogClientView* DialogClientView::AsDialogClientView() { |
| 124 return this; | 123 return this; |
| 125 } | 124 } |
| 126 | 125 |
| 127 const DialogClientView* DialogClientView::AsDialogClientView() const { | 126 const DialogClientView* DialogClientView::AsDialogClientView() const { |
| 128 return this; | 127 return this; |
| 129 } | 128 } |
| 130 | 129 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 392 gfx::Insets(0, kButtonHEdgeMargin, | 391 gfx::Insets(0, kButtonHEdgeMargin, |
| 393 kButtonVEdgeMargin, kButtonHEdgeMargin); | 392 kButtonVEdgeMargin, kButtonHEdgeMargin); |
| 394 } | 393 } |
| 395 | 394 |
| 396 void DialogClientView::Close() { | 395 void DialogClientView::Close() { |
| 397 GetWidget()->Close(); | 396 GetWidget()->Close(); |
| 398 GetDialogDelegate()->OnClose(); | 397 GetDialogDelegate()->OnClose(); |
| 399 } | 398 } |
| 400 | 399 |
| 401 } // namespace views | 400 } // namespace views |
| OLD | NEW |