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 "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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } // namespace | 50 } // namespace |
51 | 51 |
52 /////////////////////////////////////////////////////////////////////////////// | 52 /////////////////////////////////////////////////////////////////////////////// |
53 // DialogClientView, public: | 53 // DialogClientView, public: |
54 | 54 |
55 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 55 DialogClientView::DialogClientView(Widget* owner, View* contents_view) |
56 : ClientView(owner, contents_view), | 56 : ClientView(owner, contents_view), |
57 ok_button_(NULL), | 57 ok_button_(NULL), |
58 cancel_button_(NULL), | 58 cancel_button_(NULL), |
59 extra_view_(NULL), | 59 extra_view_(NULL), |
60 footnote_view_(NULL), | 60 footnote_view_(NULL) {} |
61 notified_delegate_(false) { | |
62 } | |
63 | 61 |
64 DialogClientView::~DialogClientView() { | 62 DialogClientView::~DialogClientView() { |
65 } | 63 } |
66 | 64 |
67 void DialogClientView::AcceptWindow() { | 65 void DialogClientView::AcceptWindow() { |
68 // Only notify the delegate once. See |notified_delegate_|'s comment. | 66 if (GetDialogDelegate()->Accept(false)) |
69 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { | |
70 notified_delegate_ = true; | |
71 Close(); | 67 Close(); |
72 } | |
73 } | 68 } |
74 | 69 |
75 void DialogClientView::CancelWindow() { | 70 void DialogClientView::CancelWindow() { |
76 // Only notify the delegate once. See |notified_delegate_|'s comment. | 71 if (GetDialogDelegate()->Cancel()) |
77 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) { | |
78 notified_delegate_ = true; | |
79 Close(); | 72 Close(); |
80 } | |
81 } | 73 } |
82 | 74 |
83 void DialogClientView::UpdateDialogButtons() { | 75 void DialogClientView::UpdateDialogButtons() { |
84 const int buttons = GetDialogDelegate()->GetDialogButtons(); | 76 const int buttons = GetDialogDelegate()->GetDialogButtons(); |
85 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 77 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
86 | 78 |
87 if (buttons & ui::DIALOG_BUTTON_OK) { | 79 if (buttons & ui::DIALOG_BUTTON_OK) { |
88 if (!ok_button_) { | 80 if (!ok_button_) { |
89 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); | 81 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); |
90 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) | 82 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
(...skipping 24 matching lines...) Expand all Loading... |
115 if (!has_dialog_buttons()) | 107 if (!has_dialog_buttons()) |
116 AddAccelerator(escape); | 108 AddAccelerator(escape); |
117 else | 109 else |
118 ResetAccelerators(); | 110 ResetAccelerators(); |
119 } | 111 } |
120 | 112 |
121 /////////////////////////////////////////////////////////////////////////////// | 113 /////////////////////////////////////////////////////////////////////////////// |
122 // DialogClientView, ClientView overrides: | 114 // DialogClientView, ClientView overrides: |
123 | 115 |
124 bool DialogClientView::CanClose() { | 116 bool DialogClientView::CanClose() { |
125 if (notified_delegate_) | |
126 return true; | |
127 | |
128 // The dialog is closing but no Accept or Cancel action has been performed | 117 // The dialog is closing but no Accept or Cancel action has been performed |
129 // before: it's a Close action. | 118 // before: it's a Close action. |
130 if (GetDialogDelegate()->Close()) { | 119 return GetDialogDelegate()->Close(); |
131 notified_delegate_ = true; | |
132 GetDialogDelegate()->OnClosed(); | |
133 return true; | |
134 } | |
135 return false; | |
136 } | 120 } |
137 | 121 |
138 DialogClientView* DialogClientView::AsDialogClientView() { | 122 DialogClientView* DialogClientView::AsDialogClientView() { |
139 return this; | 123 return this; |
140 } | 124 } |
141 | 125 |
142 const DialogClientView* DialogClientView::AsDialogClientView() const { | 126 const DialogClientView* DialogClientView::AsDialogClientView() const { |
143 return this; | 127 return this; |
144 } | 128 } |
145 | 129 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 } | 270 } |
287 | 271 |
288 //////////////////////////////////////////////////////////////////////////////// | 272 //////////////////////////////////////////////////////////////////////////////// |
289 // DialogClientView, protected: | 273 // DialogClientView, protected: |
290 | 274 |
291 DialogClientView::DialogClientView(View* contents_view) | 275 DialogClientView::DialogClientView(View* contents_view) |
292 : ClientView(NULL, contents_view), | 276 : ClientView(NULL, contents_view), |
293 ok_button_(NULL), | 277 ok_button_(NULL), |
294 cancel_button_(NULL), | 278 cancel_button_(NULL), |
295 extra_view_(NULL), | 279 extra_view_(NULL), |
296 footnote_view_(NULL), | 280 footnote_view_(NULL) {} |
297 notified_delegate_(false) {} | |
298 | 281 |
299 DialogDelegate* DialogClientView::GetDialogDelegate() const { | 282 DialogDelegate* DialogClientView::GetDialogDelegate() const { |
300 return GetWidget()->widget_delegate()->AsDialogDelegate(); | 283 return GetWidget()->widget_delegate()->AsDialogDelegate(); |
301 } | 284 } |
302 | 285 |
303 void DialogClientView::CreateExtraView() { | 286 void DialogClientView::CreateExtraView() { |
304 if (extra_view_) | 287 if (extra_view_) |
305 return; | 288 return; |
306 | 289 |
307 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 290 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 | 353 |
371 gfx::Insets DialogClientView::GetButtonRowInsets() const { | 354 gfx::Insets DialogClientView::GetButtonRowInsets() const { |
372 // NOTE: The insets only apply to the buttons, extra view, and footnote view. | 355 // NOTE: The insets only apply to the buttons, extra view, and footnote view. |
373 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : | 356 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : |
374 gfx::Insets(0, kButtonHEdgeMarginNew, | 357 gfx::Insets(0, kButtonHEdgeMarginNew, |
375 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); | 358 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); |
376 } | 359 } |
377 | 360 |
378 void DialogClientView::Close() { | 361 void DialogClientView::Close() { |
379 GetWidget()->Close(); | 362 GetWidget()->Close(); |
380 GetDialogDelegate()->OnClosed(); | |
381 } | 363 } |
382 | 364 |
383 } // namespace views | 365 } // namespace views |
OLD | NEW |