Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/observer_list.h" | |
| 6 #include "base/strings/utf_string_conversions.h" | |
| 7 #include "chrome/browser/payments/ui/order_summary_state.h" | |
| 8 #include "ui/views/controls/button/md_text_button.h" | |
| 9 #include "ui/views/controls/label.h" | |
| 10 #include "ui/views/layout/grid_layout.h" | |
| 11 | |
| 12 namespace payments { | |
| 13 | |
| 14 const int kBackButtonTag = 0; | |
| 15 | |
| 16 OrderSummaryState::OrderSummaryState() | |
| 17 : view_(nullptr) {} | |
| 18 | |
| 19 OrderSummaryState::~OrderSummaryState() {} | |
| 20 | |
| 21 views::View* OrderSummaryState::GetView() { | |
| 22 if (!view_) { | |
| 23 view_ = new views::View(); | |
| 24 view_->SetSize(gfx::Size(300, 300)); | |
| 25 | |
| 26 views::GridLayout* layout = new views::GridLayout(view_); | |
|
please use gerrit instead
2016/11/22 21:39:32
Who owns this object? Raw pointers are scary.
If
anthonyvd
2016/11/22 22:11:18
The view owns the layout manager implicitly. From
| |
| 27 view_->SetLayoutManager(layout); | |
| 28 views::ColumnSet* columns = layout->AddColumnSet(0); | |
|
please use gerrit instead
2016/11/22 21:39:32
Who owns this object?
anthonyvd
2016/11/22 22:11:18
The GridLayout does, this function returns a non-o
| |
| 29 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | |
| 30 0, views::GridLayout::USE_PREF, 0, 0); | |
| 31 | |
| 32 layout->StartRow(0, 0); | |
| 33 layout->AddView(new views::Label(base::ASCIIToUTF16("Order Summary"))); | |
| 34 | |
| 35 layout->StartRow(0, 0); | |
| 36 views::LabelButton* back_button = | |
|
please use gerrit instead
2016/11/22 21:39:32
Who owns this object?
anthonyvd
2016/11/22 22:11:19
Views are always owned by their parent unless set_
| |
| 37 views::MdTextButton::CreateSecondaryUiBlueButton( | |
| 38 this, base::ASCIIToUTF16("Back")); | |
| 39 back_button->set_tag(kBackButtonTag); | |
| 40 layout->AddView(back_button); | |
| 41 } | |
| 42 return view_; | |
| 43 } | |
| 44 | |
| 45 void OrderSummaryState::AddObserver(Observer* observer) { | |
| 46 observers_.AddObserver(observer); | |
| 47 } | |
| 48 | |
| 49 void OrderSummaryState::RemoveObserver(Observer* observer) { | |
| 50 observers_.RemoveObserver(observer); | |
| 51 } | |
| 52 | |
| 53 void OrderSummaryState::ButtonPressed( | |
| 54 views::Button* sender, const ui::Event& event) { | |
| 55 if (!interactable()) | |
| 56 return; | |
| 57 | |
| 58 if (sender->tag() == kBackButtonTag) { | |
| 59 for (auto& observer : observers_) { | |
| 60 observer.OnBackClicked(); | |
| 61 } | |
| 62 } | |
| 63 } | |
| 64 | |
| 65 } // namespace payments | |
| OLD | NEW |