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 25 matching lines...) Expand all Loading... | |
| 36 ok_button_(NULL), | 36 ok_button_(NULL), |
| 37 cancel_button_(NULL), | 37 cancel_button_(NULL), |
| 38 default_button_(NULL), | 38 default_button_(NULL), |
| 39 focus_manager_(NULL), | 39 focus_manager_(NULL), |
| 40 extra_view_(NULL), | 40 extra_view_(NULL), |
| 41 footnote_view_(NULL), | 41 footnote_view_(NULL), |
| 42 notified_delegate_(false) { | 42 notified_delegate_(false) { |
| 43 } | 43 } |
| 44 | 44 |
| 45 DialogClientView::~DialogClientView() { | 45 DialogClientView::~DialogClientView() { |
| 46 if (focus_manager_) | |
| 47 focus_manager_->RemoveFocusChangeListener(this); | |
| 48 focus_manager_ = NULL; | |
| 49 } | 46 } |
| 50 | 47 |
| 51 void DialogClientView::AcceptWindow() { | 48 void DialogClientView::AcceptWindow() { |
| 52 // Only notify the delegate once. See |notified_delegate_|'s comment. | 49 // Only notify the delegate once. See |notified_delegate_|'s comment. |
| 53 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { | 50 if (!notified_delegate_ && GetDialogDelegate()->Accept(false)) { |
| 54 notified_delegate_ = true; | 51 notified_delegate_ = true; |
| 55 Close(); | 52 Close(); |
| 56 } | 53 } |
| 57 } | 54 } |
| 58 | 55 |
| 59 void DialogClientView::CancelWindow() { | 56 void DialogClientView::CancelWindow() { |
| 60 // Call the standard Close handler, which checks with the delegate before | 57 // Call the standard Close handler, which checks with the delegate before |
| 61 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, | 58 // proceeding. This checking _isn't_ done here, but in the WM_CLOSE handler, |
| 62 // so that the close box on the window also shares this code path. | 59 // so that the close box on the window also shares this code path. |
| 63 Close(); | 60 Close(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 void DialogClientView::UpdateDialogButtons() { | 63 void DialogClientView::UpdateDialogButtons() { |
| 67 const int buttons = GetDialogDelegate()->GetDialogButtons(); | 64 const int buttons = GetDialogDelegate()->GetDialogButtons(); |
| 68 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 65 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
| 69 if (default_button_) | 66 if (default_button_) |
| 70 default_button_->SetIsDefault(false); | 67 default_button_->SetIsDefault(false); |
| 71 default_button_ = NULL; | 68 default_button_ = NULL; |
| 72 | 69 |
| 73 if (buttons & ui::DIALOG_BUTTON_OK) { | 70 if (buttons & ui::DIALOG_BUTTON_OK) { |
| 74 if (!ok_button_) { | 71 if (!ok_button_) { |
| 75 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); | 72 ok_button_ = CreateDialogButton(ui::DIALOG_BUTTON_OK); |
| 76 if (buttons & ui::DIALOG_BUTTON_CANCEL) | 73 if (!(buttons & ui::DIALOG_BUTTON_CANCEL)) |
| 77 ok_button_->AddAccelerator(escape); | 74 ok_button_->AddAccelerator(escape); |
| 78 AddChildView(ok_button_); | 75 AddChildView(ok_button_); |
| 79 } | 76 } |
| 80 | 77 |
| 81 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK); | 78 UpdateButton(ok_button_, ui::DIALOG_BUTTON_OK); |
| 82 } else if (ok_button_) { | 79 } else if (ok_button_) { |
| 80 RemoveChildView(ok_button_); | |
|
sky
2013/06/17 20:30:14
Is there a particular reason you are adding this?
msw
2013/06/17 21:10:56
Ah, solely out of ignorance; updated this and simp
| |
| 83 delete ok_button_; | 81 delete ok_button_; |
| 84 ok_button_ = NULL; | 82 ok_button_ = NULL; |
| 85 } | 83 } |
| 86 | 84 |
| 87 if (buttons & ui::DIALOG_BUTTON_CANCEL) { | 85 if (buttons & ui::DIALOG_BUTTON_CANCEL) { |
| 88 if (!cancel_button_) { | 86 if (!cancel_button_) { |
| 89 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); | 87 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); |
| 90 cancel_button_->AddAccelerator(escape); | 88 cancel_button_->AddAccelerator(escape); |
| 91 AddChildView(cancel_button_); | 89 AddChildView(cancel_button_); |
| 92 } | 90 } |
| 93 | 91 |
| 94 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL); | 92 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL); |
| 95 } else if (cancel_button_) { | 93 } else if (cancel_button_) { |
| 94 RemoveChildView(cancel_button_); | |
| 96 delete cancel_button_; | 95 delete cancel_button_; |
| 97 cancel_button_ = NULL; | 96 cancel_button_ = NULL; |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Use the escape key to close the window if there are no dialog buttons. | 99 // Use the escape key to close the window if there are no dialog buttons. |
| 101 if (!has_dialog_buttons()) | 100 if (!has_dialog_buttons()) |
| 102 AddAccelerator(escape); | 101 AddAccelerator(escape); |
| 103 else | 102 else |
| 104 ResetAccelerators(); | 103 ResetAccelerators(); |
| 105 } | 104 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> | 264 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> |
| 266 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); | 265 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); |
| 267 | 266 |
| 268 focus_manager_ = GetFocusManager(); | 267 focus_manager_ = GetFocusManager(); |
| 269 if (focus_manager_) | 268 if (focus_manager_) |
| 270 GetFocusManager()->AddFocusChangeListener(this); | 269 GetFocusManager()->AddFocusChangeListener(this); |
| 271 | 270 |
| 272 UpdateDialogButtons(); | 271 UpdateDialogButtons(); |
| 273 CreateExtraView(); | 272 CreateExtraView(); |
| 274 CreateFootnoteView(); | 273 CreateFootnoteView(); |
| 274 } else if (!details.is_add && details.child == this) { | |
| 275 if (focus_manager_) | |
| 276 focus_manager_->RemoveFocusChangeListener(this); | |
| 277 focus_manager_ = NULL; | |
| 278 } else if (!details.is_add) { | |
| 279 if (details.child == default_button_) | |
| 280 default_button_ = NULL; | |
| 281 if (details.child == ok_button_) | |
| 282 ok_button_ = NULL; | |
| 283 if (details.child == cancel_button_) | |
| 284 cancel_button_ = NULL; | |
| 275 } | 285 } |
| 276 } | 286 } |
| 277 | 287 |
| 278 //////////////////////////////////////////////////////////////////////////////// | 288 //////////////////////////////////////////////////////////////////////////////// |
| 279 // DialogClientView, ButtonListener implementation: | 289 // DialogClientView, ButtonListener implementation: |
| 280 | 290 |
| 281 void DialogClientView::ButtonPressed(Button* sender, const ui::Event& event) { | 291 void DialogClientView::ButtonPressed(Button* sender, const ui::Event& event) { |
| 282 // Check for a valid delegate to avoid handling events after destruction. | 292 // Check for a valid delegate to avoid handling events after destruction. |
| 283 if (!GetDialogDelegate()) | 293 if (!GetDialogDelegate()) |
| 284 return; | 294 return; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 gfx::Insets(0, kButtonHEdgeMargin, | 394 gfx::Insets(0, kButtonHEdgeMargin, |
| 385 kButtonVEdgeMargin, kButtonHEdgeMargin); | 395 kButtonVEdgeMargin, kButtonHEdgeMargin); |
| 386 } | 396 } |
| 387 | 397 |
| 388 void DialogClientView::Close() { | 398 void DialogClientView::Close() { |
| 389 GetWidget()->Close(); | 399 GetWidget()->Close(); |
| 390 GetDialogDelegate()->OnClose(); | 400 GetDialogDelegate()->OnClose(); |
| 391 } | 401 } |
| 392 | 402 |
| 393 } // namespace views | 403 } // namespace views |
| OLD | NEW |