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/blue_button.h" | 10 #include "ui/views/controls/button/blue_button.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 | 48 |
49 void DialogClientView::AcceptWindow() { | 49 void DialogClientView::AcceptWindow() { |
50 // Only notify the delegate once. See |notified_delegate_|'s comment. | 50 // Only notify the delegate once. See |notified_delegate_|'s comment. |
51 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { | 51 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { |
52 notified_delegate_ = true; | 52 notified_delegate_ = true; |
53 Close(); | 53 Close(); |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 void DialogClientView::CancelWindow() { | 57 void DialogClientView::CancelWindow() { |
58 // Call the standard Close handler, which checks with the delegate before | 58 // Only notify the delegate once. See |notified_delegate_|'s comment. |
59 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, | 59 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) { |
60 // so that the close box on the window also shares this code path. | 60 notified_delegate_ = true; |
61 Close(); | 61 Close(); |
| 62 } |
62 } | 63 } |
63 | 64 |
64 void DialogClientView::UpdateDialogButtons() { | 65 void DialogClientView::UpdateDialogButtons() { |
65 const int buttons = GetDialogDelegate()->GetDialogButtons(); | 66 const int buttons = GetDialogDelegate()->GetDialogButtons(); |
66 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 67 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
67 if (default_button_) | 68 if (default_button_) |
68 default_button_->SetIsDefault(false); | 69 default_button_->SetIsDefault(false); |
69 default_button_ = NULL; | 70 default_button_ = NULL; |
70 | 71 |
71 if (buttons & ui::DIALOG_BUTTON_OK) { | 72 if (buttons & ui::DIALOG_BUTTON_OK) { |
(...skipping 30 matching lines...) Expand all Loading... |
102 ResetAccelerators(); | 103 ResetAccelerators(); |
103 } | 104 } |
104 | 105 |
105 /////////////////////////////////////////////////////////////////////////////// | 106 /////////////////////////////////////////////////////////////////////////////// |
106 // DialogClientView, ClientView overrides: | 107 // DialogClientView, ClientView overrides: |
107 | 108 |
108 bool DialogClientView::CanClose() { | 109 bool DialogClientView::CanClose() { |
109 if (notified_delegate_) | 110 if (notified_delegate_) |
110 return true; | 111 return true; |
111 | 112 |
112 DialogDelegate* dialog = GetDialogDelegate(); | 113 // The dialog is closing but no Accept or Cancel action has been performed |
113 int buttons = dialog->GetDialogButtons(); | 114 // before: it's a Close action. |
114 bool close = true; | 115 if (GetDialogDelegate()->Close()) { |
115 if ((buttons & ui::DIALOG_BUTTON_CANCEL) || | 116 notified_delegate_ = true; |
116 (buttons == ui::DIALOG_BUTTON_NONE)) | 117 GetDialogDelegate()->OnClosed(); |
117 close = dialog->Cancel(); | 118 return true; |
118 else if (buttons & ui::DIALOG_BUTTON_OK) | 119 } |
119 close = dialog->Accept(true); | 120 return false; |
120 notified_delegate_ = close; | |
121 return close; | |
122 } | 121 } |
123 | 122 |
124 DialogClientView* DialogClientView::AsDialogClientView() { | 123 DialogClientView* DialogClientView::AsDialogClientView() { |
125 return this; | 124 return this; |
126 } | 125 } |
127 | 126 |
128 const DialogClientView* DialogClientView::AsDialogClientView() const { | 127 const DialogClientView* DialogClientView::AsDialogClientView() const { |
129 return this; | 128 return this; |
130 } | 129 } |
131 | 130 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 // NOTE: The insets only apply to the buttons, extra view, and footnote view. | 395 // NOTE: The insets only apply to the buttons, extra view, and footnote view. |
397 return DialogDelegate::UseNewStyle() ? | 396 return DialogDelegate::UseNewStyle() ? |
398 gfx::Insets(0, kButtonHEdgeMarginNew, | 397 gfx::Insets(0, kButtonHEdgeMarginNew, |
399 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew) : | 398 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew) : |
400 gfx::Insets(0, kButtonHEdgeMargin, | 399 gfx::Insets(0, kButtonHEdgeMargin, |
401 kButtonVEdgeMargin, kButtonHEdgeMargin); | 400 kButtonVEdgeMargin, kButtonHEdgeMargin); |
402 } | 401 } |
403 | 402 |
404 void DialogClientView::Close() { | 403 void DialogClientView::Close() { |
405 GetWidget()->Close(); | 404 GetWidget()->Close(); |
406 GetDialogDelegate()->OnClose(); | 405 GetDialogDelegate()->OnClosed(); |
407 } | 406 } |
408 | 407 |
409 } // namespace views | 408 } // namespace views |
OLD | NEW |