| 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" |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 12 #include "ui/views/background.h" | 12 #include "ui/views/background.h" |
| 13 #include "ui/views/controls/button/blue_button.h" | 13 #include "ui/views/controls/button/blue_button.h" |
| 14 #include "ui/views/controls/button/custom_button.h" | 14 #include "ui/views/controls/button/custom_button.h" |
| 15 #include "ui/views/controls/button/label_button.h" | 15 #include "ui/views/controls/button/label_button.h" |
| 16 #include "ui/views/controls/button/md_text_button.h" | 16 #include "ui/views/controls/button/md_text_button.h" |
| 17 #include "ui/views/layout/layout_constants.h" | 17 #include "ui/views/layout/layout_constants.h" |
| 18 #include "ui/views/views_delegate.h" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 19 #include "ui/views/window/dialog_delegate.h" | 20 #include "ui/views/window/dialog_delegate.h" |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // The group used by the buttons. This name is chosen voluntarily big not to | 26 // The group used by the buttons. This name is chosen voluntarily big not to |
| 26 // conflict with other groups that could be in the dialog content. | 27 // conflict with other groups that could be in the dialog content. |
| 27 const int kButtonGroup = 6666; | 28 const int kButtonGroup = 6666; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 if (!button) | 46 if (!button) |
| 46 return; | 47 return; |
| 47 | 48 |
| 48 const gfx::Size size = button->GetPreferredSize(); | 49 const gfx::Size size = button->GetPreferredSize(); |
| 49 row_bounds->set_width(row_bounds->width() - size.width()); | 50 row_bounds->set_width(row_bounds->width() - size.width()); |
| 50 DCHECK_LE(button_height, row_bounds->height()); | 51 DCHECK_LE(button_height, row_bounds->height()); |
| 51 button->SetBounds( | 52 button->SetBounds( |
| 52 row_bounds->right(), | 53 row_bounds->right(), |
| 53 row_bounds->y() + (row_bounds->height() - button_height) / 2, | 54 row_bounds->y() + (row_bounds->height() - button_height) / 2, |
| 54 size.width(), button_height); | 55 size.width(), button_height); |
| 55 row_bounds->set_width(row_bounds->width() - kRelatedButtonHSpacing); | 56 int spacing = ViewsDelegate::GetInstance() |
| 57 ? ViewsDelegate::GetInstance() |
| 58 ->GetDialogRelatedButtonHorizontalSpacing() |
| 59 : kRelatedButtonHSpacing; |
| 60 row_bounds->set_width(row_bounds->width() - spacing); |
| 56 } | 61 } |
| 57 | 62 |
| 58 } // namespace | 63 } // namespace |
| 59 | 64 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
| 61 // DialogClientView, public: | 66 // DialogClientView, public: |
| 62 | 67 |
| 63 DialogClientView::DialogClientView(Widget* owner, View* contents_view) | 68 DialogClientView::DialogClientView(Widget* owner, View* contents_view) |
| 64 : ClientView(owner, contents_view), | 69 : ClientView(owner, contents_view), |
| 65 button_row_insets_(0, | 70 button_row_insets_(0, |
| 66 kButtonHEdgeMarginNew, | 71 kButtonHEdgeMarginNew, |
| 67 kButtonVEdgeMarginNew, | 72 kButtonVEdgeMarginNew, |
| 68 kButtonHEdgeMarginNew), | 73 kButtonHEdgeMarginNew), |
| 69 ok_button_(nullptr), | 74 ok_button_(nullptr), |
| 70 cancel_button_(nullptr), | 75 cancel_button_(nullptr), |
| 71 extra_view_(nullptr), | 76 extra_view_(nullptr), |
| 72 delegate_allowed_close_(false) { | 77 delegate_allowed_close_(false) { |
| 73 // Doing this now ensures this accelerator will have lower priority than | 78 // Doing this now ensures this accelerator will have lower priority than |
| 74 // one set by the contents view. | 79 // one set by the contents view. |
| 75 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); | 80 AddAccelerator(ui::Accelerator(ui::VKEY_ESCAPE, ui::EF_NONE)); |
| 81 |
| 82 if (ViewsDelegate::GetInstance()) |
| 83 button_row_insets_ = ViewsDelegate::GetInstance()->GetDialogButtonInsets(); |
| 76 } | 84 } |
| 77 | 85 |
| 78 DialogClientView::~DialogClientView() { | 86 DialogClientView::~DialogClientView() { |
| 79 } | 87 } |
| 80 | 88 |
| 81 void DialogClientView::AcceptWindow() { | 89 void DialogClientView::AcceptWindow() { |
| 82 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. | 90 // Only notify the delegate once. See |delegate_allowed_close_|'s comment. |
| 83 if (!delegate_allowed_close_ && GetDialogDelegate()->Accept()) { | 91 if (!delegate_allowed_close_ && GetDialogDelegate()->Accept()) { |
| 84 delegate_allowed_close_ = true; | 92 delegate_allowed_close_ = true; |
| 85 GetWidget()->Close(); | 93 GetWidget()->Close(); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 std::remove(child_views.begin(), child_views.end(), nullptr), | 374 std::remove(child_views.begin(), child_views.end(), nullptr), |
| 367 child_views.end()); | 375 child_views.end()); |
| 368 | 376 |
| 369 // Setup focus by reordering views. It is not safe to use SetNextFocusableView | 377 // Setup focus by reordering views. It is not safe to use SetNextFocusableView |
| 370 // since child views may be added externally to this view. | 378 // since child views may be added externally to this view. |
| 371 for (size_t i = 0; i < child_views.size(); i++) | 379 for (size_t i = 0; i < child_views.size(); i++) |
| 372 ReorderChildView(child_views[i], i); | 380 ReorderChildView(child_views[i], i); |
| 373 } | 381 } |
| 374 | 382 |
| 375 } // namespace views | 383 } // namespace views |
| OLD | NEW |