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 "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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 if (!cancel_button_) { | 105 if (!cancel_button_) { |
| 106 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); | 106 cancel_button_ = CreateDialogButton(ui::DIALOG_BUTTON_CANCEL); |
| 107 AddChildView(cancel_button_); | 107 AddChildView(cancel_button_); |
| 108 } | 108 } |
| 109 | 109 |
| 110 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL); | 110 UpdateButton(cancel_button_, ui::DIALOG_BUTTON_CANCEL); |
| 111 } else if (cancel_button_) { | 111 } else if (cancel_button_) { |
| 112 delete cancel_button_; | 112 delete cancel_button_; |
| 113 cancel_button_ = NULL; | 113 cancel_button_ = NULL; |
| 114 } | 114 } |
| 115 | |
| 116 SetupFocusChain(); | |
| 115 } | 117 } |
| 116 | 118 |
| 117 /////////////////////////////////////////////////////////////////////////////// | 119 /////////////////////////////////////////////////////////////////////////////// |
| 118 // DialogClientView, ClientView overrides: | 120 // DialogClientView, ClientView overrides: |
| 119 | 121 |
| 120 bool DialogClientView::CanClose() { | 122 bool DialogClientView::CanClose() { |
| 121 // If the dialog is closing but no Accept or Cancel action has been performed | 123 // If the dialog is closing but no Accept or Cancel action has been performed |
| 122 // before, it's a Close action. | 124 // before, it's a Close action. |
| 123 if (!delegate_allowed_close_) | 125 if (!delegate_allowed_close_) |
| 124 delegate_allowed_close_ = GetDialogDelegate()->Close(); | 126 delegate_allowed_close_ = GetDialogDelegate()->Close(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 UpdateDialogButtons(); | 228 UpdateDialogButtons(); |
| 227 CreateExtraView(); | 229 CreateExtraView(); |
| 228 } else if (!details.is_add && details.child != this) { | 230 } else if (!details.is_add && details.child != this) { |
| 229 if (details.child == ok_button_) | 231 if (details.child == ok_button_) |
| 230 ok_button_ = nullptr; | 232 ok_button_ = nullptr; |
| 231 else if (details.child == cancel_button_) | 233 else if (details.child == cancel_button_) |
| 232 cancel_button_ = nullptr; | 234 cancel_button_ = nullptr; |
| 233 else if (details.child == extra_view_) | 235 else if (details.child == extra_view_) |
| 234 extra_view_ = nullptr; | 236 extra_view_ = nullptr; |
| 235 } | 237 } |
| 236 | |
| 237 SetupFocusChain(); | |
| 238 } | 238 } |
| 239 | 239 |
| 240 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 240 void DialogClientView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 241 // The old dialog style needs an explicit background color, while the new | 241 // The old dialog style needs an explicit background color, while the new |
| 242 // dialog style simply inherits the bubble's frame view color. | 242 // dialog style simply inherits the bubble's frame view color. |
| 243 const DialogDelegate* dialog = GetDialogDelegate(); | 243 const DialogDelegate* dialog = GetDialogDelegate(); |
| 244 | 244 |
| 245 if (dialog && !dialog->UseNewStyleForThisDialog()) { | 245 if (dialog && !dialog->UseNewStyleForThisDialog()) { |
| 246 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> | 246 set_background(views::Background::CreateSolidBackground(GetNativeTheme()-> |
| 247 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); | 247 GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 } | 279 } |
| 280 | 280 |
| 281 void DialogClientView::CreateExtraView() { | 281 void DialogClientView::CreateExtraView() { |
| 282 if (extra_view_) | 282 if (extra_view_) |
| 283 return; | 283 return; |
| 284 | 284 |
| 285 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 285 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
| 286 if (extra_view_) { | 286 if (extra_view_) { |
| 287 extra_view_->SetGroup(kButtonGroup); | 287 extra_view_->SetGroup(kButtonGroup); |
| 288 AddChildView(extra_view_); | 288 AddChildView(extra_view_); |
| 289 SetupFocusChain(); | |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 void DialogClientView::ChildPreferredSizeChanged(View* child) { | 293 void DialogClientView::ChildPreferredSizeChanged(View* child) { |
| 293 if (child == extra_view_) | 294 if (child == extra_view_) |
| 294 Layout(); | 295 Layout(); |
| 295 } | 296 } |
| 296 | 297 |
| 297 void DialogClientView::ChildVisibilityChanged(View* child) { | 298 void DialogClientView::ChildVisibilityChanged(View* child) { |
| 298 ChildPreferredSizeChanged(child); | 299 ChildPreferredSizeChanged(child); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 353 } else { | 354 } else { |
| 354 child_views.push_back(cancel_button_); | 355 child_views.push_back(cancel_button_); |
| 355 child_views.push_back(ok_button_); | 356 child_views.push_back(ok_button_); |
| 356 } | 357 } |
| 357 | 358 |
| 358 // Remove all null views from the vector. | 359 // Remove all null views from the vector. |
| 359 child_views.erase( | 360 child_views.erase( |
| 360 std::remove(child_views.begin(), child_views.end(), nullptr), | 361 std::remove(child_views.begin(), child_views.end(), nullptr), |
| 361 child_views.end()); | 362 child_views.end()); |
| 362 | 363 |
| 363 // Setup focus. | 364 // Setup focus by reordering views. |
|
sky
2016/04/07 19:09:37
You should document why this doesn't use SetNextFo
karandeepb
2016/04/08 01:40:43
Done.
| |
| 364 for (size_t i = 0; i < child_views.size(); i++) { | 365 for (size_t i = 0; i < child_views.size(); i++) |
| 365 child_views[i]->SetNextFocusableView( | 366 ReorderChildView(child_views[i], i); |
| 366 i + 1 != child_views.size() ? child_views[i + 1] : nullptr); | |
| 367 } | |
| 368 } | 367 } |
| 369 | 368 |
| 370 } // namespace views | 369 } // namespace views |
| OLD | NEW |