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/base/material_design/material_design_controller.h" | 10 #include "ui/base/material_design/material_design_controller.h" |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 if (details.is_add) { | 183 if (details.is_add) { |
| 184 if (child == this) | 184 if (child == this) |
| 185 UpdateDialogButtons(); | 185 UpdateDialogButtons(); |
| 186 return; | 186 return; |
| 187 } | 187 } |
| 188 | 188 |
| 189 if (details.parent != button_row_container_) | 189 if (details.parent != button_row_container_) |
| 190 return; | 190 return; |
| 191 | 191 |
| 192 // SetupViews() removes all children, managing data members itself. | 192 // SetupViews() removes all children, managing data members itself. |
| 193 if (preserve_button_row_data_members_) | 193 if (adding_or_removing_views_) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 // Otherwise, this should only happen during teardown. Ensure there are no | 196 // Otherwise, this should only happen during teardown. Ensure there are no |
| 197 // references to deleted Views. | 197 // references to deleted Views. |
| 198 button_row_container_->SetLayoutManager(nullptr); | 198 button_row_container_->SetLayoutManager(nullptr); |
| 199 | 199 |
| 200 if (child == ok_button_) | 200 if (child == ok_button_) |
| 201 ok_button_ = nullptr; | 201 ok_button_ = nullptr; |
| 202 else if (child == cancel_button_) | 202 else if (child == cancel_button_) |
| 203 cancel_button_ = nullptr; | 203 cancel_button_ = nullptr; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 233 } | 233 } |
| 234 | 234 |
| 235 //////////////////////////////////////////////////////////////////////////////// | 235 //////////////////////////////////////////////////////////////////////////////// |
| 236 // DialogClientView, private: | 236 // DialogClientView, private: |
| 237 | 237 |
| 238 DialogDelegate* DialogClientView::GetDialogDelegate() const { | 238 DialogDelegate* DialogClientView::GetDialogDelegate() const { |
| 239 return GetWidget()->widget_delegate()->AsDialogDelegate(); | 239 return GetWidget()->widget_delegate()->AsDialogDelegate(); |
| 240 } | 240 } |
| 241 | 241 |
| 242 void DialogClientView::ChildPreferredSizeChanged(View* child) { | 242 void DialogClientView::ChildPreferredSizeChanged(View* child) { |
| 243 if (child == extra_view_) | 243 if (!adding_or_removing_views_ && child == extra_view_) |
| 244 Layout(); | 244 Layout(); |
|
tapted
2017/03/08 11:25:26
This can probably just be InvalidateLayout()... bu
Peter Kasting
2017/03/08 11:33:17
Would that even do anything? IIRC, InvalidateLayo
tapted
2017/03/08 12:19:03
Yeah it would just ensure a future call to Layout(
| |
| 245 } | 245 } |
| 246 | 246 |
| 247 void DialogClientView::ChildVisibilityChanged(View* child) { | 247 void DialogClientView::ChildVisibilityChanged(View* child) { |
| 248 // Showing or hiding |extra_view_| can alter which columns have linked sizes. | 248 // Showing or hiding |extra_view_| can alter which columns have linked sizes. |
| 249 if (child == extra_view_) | 249 if (child == extra_view_) |
| 250 UpdateDialogButtons(); | 250 UpdateDialogButtons(); |
| 251 ChildPreferredSizeChanged(child); | 251 ChildPreferredSizeChanged(child); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void DialogClientView::UpdateDialogButton(LabelButton** member, | 254 void DialogClientView::UpdateDialogButton(LabelButton** member, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 DialogClientView::GetButtonRowViews() { | 309 DialogClientView::GetButtonRowViews() { |
| 310 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr; | 310 View* first = ShouldShow(extra_view_) ? extra_view_ : nullptr; |
| 311 View* second = cancel_button_; | 311 View* second = cancel_button_; |
| 312 View* third = ok_button_; | 312 View* third = ok_button_; |
| 313 if (kIsOkButtonOnLeftSide) | 313 if (kIsOkButtonOnLeftSide) |
| 314 std::swap(second, third); | 314 std::swap(second, third); |
| 315 return {{first, second, third}}; | 315 return {{first, second, third}}; |
| 316 } | 316 } |
| 317 | 317 |
| 318 void DialogClientView::SetupLayout() { | 318 void DialogClientView::SetupLayout() { |
| 319 base::AutoReset<bool> auto_reset(&adding_or_removing_views_, true); | |
| 319 GridLayout* layout = new GridLayout(button_row_container_); | 320 GridLayout* layout = new GridLayout(button_row_container_); |
| 320 layout->set_minimum_size(minimum_size_); | 321 layout->set_minimum_size(minimum_size_); |
| 321 | 322 |
| 322 // Clobber any existing LayoutManager since it has weak references to child | 323 // Clobber any existing LayoutManager since it has weak references to child |
| 323 // Views which may be removed by SetupViews(). | 324 // Views which may be removed by SetupViews(). |
| 324 button_row_container_->SetLayoutManager(layout); | 325 button_row_container_->SetLayoutManager(layout); |
| 325 SetupViews(); | 326 SetupViews(); |
| 326 const std::array<View*, kNumButtons> views = GetButtonRowViews(); | 327 const std::array<View*, kNumButtons> views = GetButtonRowViews(); |
| 327 | 328 |
| 328 // Visibility changes on |extra_view_| must be observed to re-Layout. However, | 329 // Visibility changes on |extra_view_| must be observed to re-Layout. However, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 // Only link the extra view column if it is a button. | 395 // Only link the extra view column if it is a button. |
| 395 if (views[0] && !CustomButton::AsCustomButton(views[0])) | 396 if (views[0] && !CustomButton::AsCustomButton(views[0])) |
| 396 column_set->LinkColumnSizes(link[1], link[2], -1); | 397 column_set->LinkColumnSizes(link[1], link[2], -1); |
| 397 else | 398 else |
| 398 column_set->LinkColumnSizes(link[0], link[1], link[2], -1); | 399 column_set->LinkColumnSizes(link[0], link[1], link[2], -1); |
| 399 } | 400 } |
| 400 layout->AddPaddingRow(kFixed, insets.bottom()); | 401 layout->AddPaddingRow(kFixed, insets.bottom()); |
| 401 } | 402 } |
| 402 | 403 |
| 403 void DialogClientView::SetupViews() { | 404 void DialogClientView::SetupViews() { |
| 404 { | 405 button_row_container_->RemoveAllChildViews(false /* delete children */); |
| 405 base::AutoReset<bool> auto_reset(&preserve_button_row_data_members_, true); | 406 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can |
| 406 button_row_container_->RemoveAllChildViews(false /* delete children */); | 407 // be re-added to the layout when becoming visible. |
| 407 // If SetupLayout() "stored" a hidden |extra_view_| in |this|, ensure it can | 408 if (extra_view_) |
| 408 // be re-added to the layout when becoming visible. | 409 RemoveChildView(extra_view_); |
| 409 if (extra_view_) | |
| 410 RemoveChildView(extra_view_); | |
| 411 } | |
| 412 | 410 |
| 413 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); | 411 UpdateDialogButton(&ok_button_, ui::DIALOG_BUTTON_OK); |
| 414 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); | 412 UpdateDialogButton(&cancel_button_, ui::DIALOG_BUTTON_CANCEL); |
| 415 | 413 |
| 416 if (extra_view_) | 414 if (extra_view_) |
| 417 return; | 415 return; |
| 418 | 416 |
| 419 extra_view_ = GetDialogDelegate()->CreateExtraView(); | 417 extra_view_ = GetDialogDelegate()->CreateExtraView(); |
| 420 if (extra_view_) | 418 if (extra_view_) |
| 421 extra_view_->SetGroup(kButtonGroup); | 419 extra_view_->SetGroup(kButtonGroup); |
| 422 } | 420 } |
| 423 | 421 |
| 424 } // namespace views | 422 } // namespace views |
| OLD | NEW |