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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { | 61 delegate_allowed_close_(false) {} |
62 } | |
63 | 62 |
64 DialogClientView::~DialogClientView() { | 63 DialogClientView::~DialogClientView() { |
65 } | 64 } |
66 | 65 |
67 void DialogClientView::AcceptWindow() { | 66 void DialogClientView::AcceptWindow() { |
68 // Only notify the delegate once. See |notified_delegate_|'s comment. | 67 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. |
69 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { | 68 if (!delegate_allowed_close_ && GetDialogDelegate()->Accept(false)) { |
70 notified_delegate_ = true; | 69 delegate_allowed_close_ = true; |
71 Close(); | 70 GetWidget()->Close(); |
72 } | 71 } |
73 } | 72 } |
74 | 73 |
75 void DialogClientView::CancelWindow() { | 74 void DialogClientView::CancelWindow() { |
76 // Only notify the delegate once. See |notified_delegate_|'s comment. | 75 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. |
77 if (!notified_delegate_ && GetDialogDelegate()->Cancel()) { | 76 if (!delegate_allowed_close_ && GetDialogDelegate()->Cancel()) { |
78 notified_delegate_ = true; | 77 delegate_allowed_close_ = true; |
79 Close(); | 78 GetWidget()->Close(); |
80 } | 79 } |
81 } | 80 } |
82 | 81 |
83 void DialogClientView::UpdateDialogButtons() { | 82 void DialogClientView::UpdateDialogButtons() { |
84 const int buttons = GetDialogDelegate()->GetDialogButtons(); | 83 const int buttons = GetDialogDelegate()->GetDialogButtons(); |
85 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 84 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
86 | 85 |
87 if (buttons & ui::DIALOG_BUTTON_OK) { | 86 if (buttons & ui::DIALOG_BUTTON_OK) { |
88 if (!ok_button_) { | 87 if (!ok_button_) { |
89 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); | 88 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); |
(...skipping 25 matching lines...) Expand all Loading... | |
115 if (!has_dialog_buttons()) | 114 if (!has_dialog_buttons()) |
116 AddAccelerator(escape); | 115 AddAccelerator(escape); |
117 else | 116 else |
118 ResetAccelerators(); | 117 ResetAccelerators(); |
119 } | 118 } |
120 | 119 |
121 /////////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////////// |
122 // DialogClientView, ClientView overrides: | 121 // DialogClientView, ClientView overrides: |
123 | 122 |
124 bool DialogClientView::CanClose() { | 123 bool DialogClientView::CanClose() { |
125 if (notified_delegate_) | 124 // If the dialog is closing but no Accept or Cancel action has been performed |
126 return true; | 125 // before, it's a Close action. |
127 | 126 delegate_allowed_close_ = |
msw
2016/02/22 18:44:04
nit: |=
Evan Stade
2016/02/22 22:10:18
I don't think that has the same behavior. We speci
| |
128 // The dialog is closing but no Accept or Cancel action has been performed | 127 delegate_allowed_close_ || GetDialogDelegate()->Close(); |
129 // before: it's a Close action. | 128 return delegate_allowed_close_; |
130 if (GetDialogDelegate()->Close()) { | |
131 notified_delegate_ = true; | |
132 GetDialogDelegate()->OnClosed(); | |
133 return true; | |
134 } | |
135 return false; | |
136 } | 129 } |
137 | 130 |
138 DialogClientView* DialogClientView::AsDialogClientView() { | 131 DialogClientView* DialogClientView::AsDialogClientView() { |
139 return this; | 132 return this; |
140 } | 133 } |
141 | 134 |
142 const DialogClientView* DialogClientView::AsDialogClientView() const { | 135 const DialogClientView* DialogClientView::AsDialogClientView() const { |
143 return this; | 136 return this; |
144 } | 137 } |
145 | 138 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 | 225 |
233 // Layout the contents view to the top and side edges of the contents bounds. | 226 // Layout the contents view to the top and side edges of the contents bounds. |
234 // NOTE: The local insets do not apply to the contents view sides or top. | 227 // NOTE: The local insets do not apply to the contents view sides or top. |
235 const gfx::Rect contents_bounds = GetContentsBounds(); | 228 const gfx::Rect contents_bounds = GetContentsBounds(); |
236 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), | 229 contents_view()->SetBounds(contents_bounds.x(), contents_bounds.y(), |
237 contents_bounds.width(), bounds.bottom() - contents_bounds.y()); | 230 contents_bounds.width(), bounds.bottom() - contents_bounds.y()); |
238 } | 231 } |
239 | 232 |
240 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { | 233 bool DialogClientView::AcceleratorPressed(const ui::Accelerator& accelerator) { |
241 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE); | 234 DCHECK_EQ(accelerator.key_code(), ui::VKEY_ESCAPE); |
242 Close(); | 235 GetWidget()->Close(); |
243 return true; | 236 return true; |
244 } | 237 } |
245 | 238 |
246 void DialogClientView::ViewHierarchyChanged( | 239 void DialogClientView::ViewHierarchyChanged( |
247 const ViewHierarchyChangedDetails& details) { | 240 const ViewHierarchyChangedDetails& details) { |
248 ClientView::ViewHierarchyChanged(details); | 241 ClientView::ViewHierarchyChanged(details); |
249 if (details.is_add && details.child == this) { | 242 if (details.is_add && details.child == this) { |
250 UpdateDialogButtons(); | 243 UpdateDialogButtons(); |
251 CreateExtraView(); | 244 CreateExtraView(); |
252 CreateFootnoteView(); | 245 CreateFootnoteView(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 | 280 |
288 //////////////////////////////////////////////////////////////////////////////// | 281 //////////////////////////////////////////////////////////////////////////////// |
289 // DialogClientView, protected: | 282 // DialogClientView, protected: |
290 | 283 |
291 DialogClientView::DialogClientView(View* contents_view) | 284 DialogClientView::DialogClientView(View* contents_view) |
292 : ClientView(NULL, contents_view), | 285 : ClientView(NULL, contents_view), |
293 ok_button_(NULL), | 286 ok_button_(NULL), |
294 cancel_button_(NULL), | 287 cancel_button_(NULL), |
295 extra_view_(NULL), | 288 extra_view_(NULL), |
296 footnote_view_(NULL), | 289 footnote_view_(NULL), |
297 notified_delegate_(false) {} | 290 delegate_allowed_close_(false) {} |
298 | 291 |
299 DialogDelegate* DialogClientView::GetDialogDelegate() const { | 292 DialogDelegate* DialogClientView::GetDialogDelegate() const { |
300 return GetWidget()->widget_delegate()->AsDialogDelegate(); | 293 return GetWidget()->widget_delegate()->AsDialogDelegate(); |
301 } | 294 } |
302 | 295 |
303 void DialogClientView::CreateExtraView() { | 296 void DialogClientView::CreateExtraView() { |
304 if (extra_view_) | 297 if (extra_view_) |
305 return; | 298 return; |
306 | 299 |
307 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 300 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 return std::max(extra_view_height, buttons_height); | 361 return std::max(extra_view_height, buttons_height); |
369 } | 362 } |
370 | 363 |
371 gfx::Insets DialogClientView::GetButtonRowInsets() const { | 364 gfx::Insets DialogClientView::GetButtonRowInsets() const { |
372 // NOTE: The insets only apply to the buttons, extra view, and footnote view. | 365 // NOTE: The insets only apply to the buttons, extra view, and footnote view. |
373 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : | 366 return GetButtonsAndExtraViewRowHeight() == 0 ? gfx::Insets() : |
374 gfx::Insets(0, kButtonHEdgeMarginNew, | 367 gfx::Insets(0, kButtonHEdgeMarginNew, |
375 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); | 368 kButtonVEdgeMarginNew, kButtonHEdgeMarginNew); |
376 } | 369 } |
377 | 370 |
378 void DialogClientView::Close() { | |
379 GetWidget()->Close(); | |
380 GetDialogDelegate()->OnClosed(); | |
381 } | |
382 | |
383 } // namespace views | 371 } // namespace views |
OLD | NEW |