1 // Copyright 2015 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.
5 #include "components/webui_generator/view.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "components/webui_generator/view_model.h"
11 namespace webui_generator
{
13 View::View(const std::string
& id
)
17 view_model_ready_(false),
26 CreateAndAddChildren();
29 path_
= parent_
->path() + "$";
32 view_model_
.reset(CreateViewModel());
33 view_model_
->SetView(this);
35 for (auto& id_child
: children_
)
36 id_child
.second
->Init();
38 if (children_
.empty())
42 bool View::IsRootView() const {
46 ViewModel
* View::GetViewModel() const {
47 return view_model_
.get();
50 void View::OnViewModelReady() {
51 view_model_ready_
= true;
52 if (ready_children_
== static_cast<int>(children_
.size()))
56 View
* View::GetChild(const std::string
& id
) const {
57 auto it
= children_
.find(id
);
58 if (it
== children_
.end())
64 void View::OnReady() {
70 parent_
->OnChildReady(this);
73 void View::UpdateContext(const base::DictionaryValue
& diff
) {
75 view_model_
->UpdateContext(diff
);
78 void View::HandleEvent(const std::string
& event
) {
80 view_model_
->OnEvent(event
);
83 void View::AddChild(View
* child
) {
84 DCHECK(children_
.find(child
->id()) == children_
.end());
85 DCHECK(!child
->id().empty());
86 children_
.set(child
->id(), make_scoped_ptr(child
));
87 child
->set_parent(this);
90 void View::OnChildReady(View
* child
) {
92 if (ready_children_
== static_cast<int>(children_
.size()))
96 void View::OnChildrenReady() {
97 view_model_
->OnChildrenReady();
98 if (view_model_ready_
)
102 } // namespace webui_generator