Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/ui/views/payments/payment_request_item_list.h" | 5 #include "chrome/browser/ui/views/payments/payment_request_item_list.h" |
| 6 | 6 |
| 7 #include "chrome/app/vector_icons/vector_icons.h" | |
| 7 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" | 8 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h" |
| 8 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" | 9 #include "chrome/browser/ui/views/payments/payment_request_row_view.h" |
| 9 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | 10 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" |
| 10 #include "components/payments/content/payment_request_state.h" | 11 #include "components/payments/content/payment_request_state.h" |
| 11 #include "ui/gfx/paint_vector_icon.h" | 12 #include "ui/gfx/paint_vector_icon.h" |
| 13 #include "ui/views/controls/button/image_button.h" | |
| 14 #include "ui/views/controls/button/image_button_factory.h" | |
| 12 #include "ui/views/controls/image_view.h" | 15 #include "ui/views/controls/image_view.h" |
| 13 #include "ui/views/layout/box_layout.h" | 16 #include "ui/views/layout/box_layout.h" |
| 14 #include "ui/views/layout/grid_layout.h" | 17 #include "ui/views/layout/grid_layout.h" |
| 15 #include "ui/views/vector_icons.h" | 18 #include "ui/views/vector_icons.h" |
| 16 #include "ui/views/view.h" | 19 #include "ui/views/view.h" |
| 17 | 20 |
| 18 namespace payments { | 21 namespace payments { |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 const SkColor kCheckmarkColor = 0xFF609265; | 25 const SkColor kCheckmarkColor = 0xFF609265; |
| 23 | 26 |
| 24 } // namespace | 27 } // namespace |
| 25 | 28 |
| 26 PaymentRequestItemList::Item::Item(PaymentRequestSpec* spec, | 29 PaymentRequestItemList::Item::Item(PaymentRequestSpec* spec, |
| 27 PaymentRequestState* state, | 30 PaymentRequestState* state, |
| 28 PaymentRequestItemList* list, | 31 PaymentRequestItemList* list, |
| 29 bool selected) | 32 bool selected, |
| 30 : spec_(spec), state_(state), list_(list), selected_(selected) {} | 33 bool show_edit_button) |
| 34 : spec_(spec), | |
| 35 state_(state), | |
| 36 list_(list), | |
| 37 selected_(selected), | |
| 38 show_edit_button_(show_edit_button) {} | |
| 31 | 39 |
| 32 PaymentRequestItemList::Item::~Item() {} | 40 PaymentRequestItemList::Item::~Item() {} |
| 33 | 41 |
| 34 views::View* PaymentRequestItemList::Item::GetItemView() { | 42 views::View* PaymentRequestItemList::Item::GetItemView() { |
| 35 if (!item_view_) { | 43 if (!item_view_) { |
| 36 item_view_ = CreateItemView(); | 44 item_view_ = CreateItemView(); |
| 37 item_view_->set_owned_by_client(); | 45 item_view_->set_owned_by_client(); |
| 38 } | 46 } |
| 39 | 47 |
| 40 return item_view_.get(); | 48 return item_view_.get(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 51 if (notify) | 59 if (notify) |
| 52 SelectedStateChanged(); | 60 SelectedStateChanged(); |
| 53 } | 61 } |
| 54 | 62 |
| 55 std::unique_ptr<views::ImageView> PaymentRequestItemList::Item::CreateCheckmark( | 63 std::unique_ptr<views::ImageView> PaymentRequestItemList::Item::CreateCheckmark( |
| 56 bool selected) { | 64 bool selected) { |
| 57 std::unique_ptr<views::ImageView> checkmark = | 65 std::unique_ptr<views::ImageView> checkmark = |
| 58 base::MakeUnique<views::ImageView>(); | 66 base::MakeUnique<views::ImageView>(); |
| 59 checkmark->set_id(static_cast<int>(DialogViewID::CHECKMARK_VIEW)); | 67 checkmark->set_id(static_cast<int>(DialogViewID::CHECKMARK_VIEW)); |
| 60 checkmark->set_can_process_events_within_subtree(false); | 68 checkmark->set_can_process_events_within_subtree(false); |
| 61 checkmark->set_owned_by_client(); | 69 checkmark->set_owned_by_client(); |
|
Evan Stade
2017/05/10 16:06:25
why is this and the edit button owned by the clien
anthonyvd
2017/05/10 16:39:26
The relationship between views and their controlle
Evan Stade
2017/05/10 17:57:05
The convention is different for every other piece
| |
| 62 checkmark->SetImage( | 70 checkmark->SetImage( |
| 63 gfx::CreateVectorIcon(views::kMenuCheckIcon, kCheckmarkColor)); | 71 gfx::CreateVectorIcon(views::kMenuCheckIcon, kCheckmarkColor)); |
| 64 checkmark->SetVisible(selected); | 72 checkmark->SetVisible(selected); |
| 65 return checkmark; | 73 return checkmark; |
| 66 } | 74 } |
| 67 | 75 |
| 68 std::unique_ptr<views::View> PaymentRequestItemList::Item::CreateExtraView() { | 76 std::unique_ptr<views::View> PaymentRequestItemList::Item::CreateExtraView() { |
| 69 return nullptr; | 77 return nullptr; |
| 70 } | 78 } |
| 71 | 79 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 87 views::ColumnSet* columns = layout->AddColumnSet(0); | 95 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 88 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, | 96 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, 1, |
| 89 views::GridLayout::USE_PREF, 0, 0); | 97 views::GridLayout::USE_PREF, 0, 0); |
| 90 | 98 |
| 91 columns->AddPaddingColumn(1, 0); | 99 columns->AddPaddingColumn(1, 0); |
| 92 | 100 |
| 93 // Add a column for the checkmark shown next to the selected profile. | 101 // Add a column for the checkmark shown next to the selected profile. |
| 94 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 102 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, |
| 95 views::GridLayout::USE_PREF, 0, 0); | 103 views::GridLayout::USE_PREF, 0, 0); |
| 96 | 104 |
| 97 // Add a column for the extra_view, which comes after the checkmark. | 105 // The space between the checkmark, extra view, and edit button. |
| 98 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 0, | 106 constexpr int kExtraViewSpacing = 16; |
| 99 views::GridLayout::USE_PREF, 0, 0); | 107 std::unique_ptr<views::View> extra_view = CreateExtraView(); |
| 108 if (extra_view) { | |
| 109 columns->AddPaddingColumn(0, kExtraViewSpacing); | |
| 110 // Add a column for the extra_view, which comes after the checkmark. | |
| 111 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 112 0, views::GridLayout::USE_PREF, 0, 0); | |
| 113 } | |
| 114 | |
| 115 if (show_edit_button_) { | |
| 116 edit_button_.reset(views::CreateVectorImageButton(this)); | |
| 117 edit_button_->set_owned_by_client(); | |
| 118 views::SetImageFromVectorIcon(edit_button_.get(), kIcEditIcon); | |
| 119 constexpr int kEditIconSize = 16; | |
| 120 edit_button_->SetSize(gfx::Size(kEditIconSize, kEditIconSize)); | |
|
Evan Stade
2017/05/10 16:06:25
You should only call View::SetSize during layout.
anthonyvd
2017/05/10 16:39:26
Good point, done.
| |
| 121 edit_button_->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); | |
| 122 edit_button_->set_id(static_cast<int>(DialogViewID::EDIT_ITEM_BUTTON)); | |
| 123 | |
| 124 columns->AddPaddingColumn(0, kExtraViewSpacing); | |
| 125 // Add a column for the edit_button if it exists. | |
| 126 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 127 0, views::GridLayout::USE_PREF, 0, 0); | |
| 128 } | |
| 100 | 129 |
| 101 layout->StartRow(0, 0); | 130 layout->StartRow(0, 0); |
| 102 content->set_can_process_events_within_subtree(false); | 131 content->set_can_process_events_within_subtree(false); |
| 103 layout->AddView(content.release()); | 132 layout->AddView(content.release()); |
| 104 | 133 |
| 105 checkmark_ = CreateCheckmark(selected()); | 134 checkmark_ = CreateCheckmark(selected()); |
| 106 layout->AddView(checkmark_.get()); | 135 layout->AddView(checkmark_.get()); |
| 107 | 136 |
| 108 std::unique_ptr<views::View> extra_view = CreateExtraView(); | |
| 109 if (extra_view) | 137 if (extra_view) |
| 110 layout->AddView(extra_view.release()); | 138 layout->AddView(extra_view.release()); |
| 111 | 139 |
| 140 if (edit_button_) | |
| 141 layout->AddView(edit_button_.get()); | |
| 142 | |
| 112 return std::move(row); | 143 return std::move(row); |
| 113 } | 144 } |
| 114 | 145 |
| 115 void PaymentRequestItemList::Item::ButtonPressed(views::Button* sender, | 146 void PaymentRequestItemList::Item::ButtonPressed(views::Button* sender, |
| 116 const ui::Event& event) { | 147 const ui::Event& event) { |
| 117 if (CanBeSelected()) { | 148 if (sender == edit_button_.get()) { |
| 149 EditButtonPressed(); | |
| 150 } else if (CanBeSelected()) { | |
| 118 list()->SelectItem(this); | 151 list()->SelectItem(this); |
| 119 } else { | 152 } else { |
| 120 PerformSelectionFallback(); | 153 PerformSelectionFallback(); |
| 121 } | 154 } |
| 122 } | 155 } |
| 123 | 156 |
| 124 PaymentRequestItemList::PaymentRequestItemList() : selected_item_(nullptr) {} | 157 PaymentRequestItemList::PaymentRequestItemList() : selected_item_(nullptr) {} |
| 125 | 158 |
| 126 PaymentRequestItemList::~PaymentRequestItemList() {} | 159 PaymentRequestItemList::~PaymentRequestItemList() {} |
| 127 | 160 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 // It's possible that no item is currently selected, either during list | 198 // It's possible that no item is currently selected, either during list |
| 166 // creation or in the middle of the selection operation when the previously | 199 // creation or in the middle of the selection operation when the previously |
| 167 // selected item has been deselected but the new one isn't selected yet. | 200 // selected item has been deselected but the new one isn't selected yet. |
| 168 if (selected_item_) | 201 if (selected_item_) |
| 169 selected_item_->SetSelected(/*selected=*/false, /*notify=*/true); | 202 selected_item_->SetSelected(/*selected=*/false, /*notify=*/true); |
| 170 | 203 |
| 171 selected_item_ = nullptr; | 204 selected_item_ = nullptr; |
| 172 } | 205 } |
| 173 | 206 |
| 174 } // namespace payments | 207 } // namespace payments |
| OLD | NEW |