| 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_) { |
| 83 delete ok_button_; | 80 delete ok_button_; |
| 84 ok_button_ = NULL; | 81 ok_button_ = NULL; |
| 85 } | 82 } |
| 86 | 83 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> | 262 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> |
| 266 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); | 263 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); |
| 267 | 264 |
| 268 focus_manager_ = GetFocusManager(); | 265 focus_manager_ = GetFocusManager(); |
| 269 if (focus_manager_) | 266 if (focus_manager_) |
| 270 GetFocusManager()->AddFocusChangeListener(this); | 267 GetFocusManager()->AddFocusChangeListener(this); |
| 271 | 268 |
| 272 UpdateDialogButtons(); | 269 UpdateDialogButtons(); |
| 273 CreateExtraView(); | 270 CreateExtraView(); |
| 274 CreateFootnoteView(); | 271 CreateFootnoteView(); |
| 272 } else if (!details.is_add && details.child == this) { |
| 273 if (focus_manager_) |
| 274 focus_manager_->RemoveFocusChangeListener(this); |
| 275 focus_manager_ = NULL; |
| 276 } else if (!details.is_add) { |
| 277 if (details.child == default_button_) |
| 278 default_button_ = NULL; |
| 279 if (details.child == ok_button_) |
| 280 ok_button_ = NULL; |
| 281 if (details.child == cancel_button_) |
| 282 cancel_button_ = NULL; |
| 275 } | 283 } |
| 276 } | 284 } |
| 277 | 285 |
| 278 //////////////////////////////////////////////////////////////////////////////// | 286 //////////////////////////////////////////////////////////////////////////////// |
| 279 // DialogClientView, ButtonListener implementation: | 287 // DialogClientView, ButtonListener implementation: |
| 280 | 288 |
| 281 void DialogClientView::ButtonPressed(Button* sender, const ui::Event& event) { | 289 void DialogClientView::ButtonPressed(Button* sender, const ui::Event& event) { |
| 282 // Check for a valid delegate to avoid handling events after destruction. | 290 // Check for a valid delegate to avoid handling events after destruction. |
| 283 if (!GetDialogDelegate()) | 291 if (!GetDialogDelegate()) |
| 284 return; | 292 return; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 gfx::Insets(0, kButtonHEdgeMargin, | 392 gfx::Insets(0, kButtonHEdgeMargin, |
| 385 kButtonVEdgeMargin, kButtonHEdgeMargin); | 393 kButtonVEdgeMargin, kButtonHEdgeMargin); |
| 386 } | 394 } |
| 387 | 395 |
| 388 void DialogClientView::Close() { | 396 void DialogClientView::Close() { |
| 389 GetWidget()->Close(); | 397 GetWidget()->Close(); |
| 390 GetDialogDelegate()->OnClose(); | 398 GetDialogDelegate()->OnClose(); |
| 391 } | 399 } |
| 392 | 400 |
| 393 } // namespace views | 401 } // namespace views |
| OLD | NEW |