Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(858)

Unified Diff: components/wug/view.cc

Issue 928163002: Initial implementation of WebUI generator (WUG) toolkit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Owners updated. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/wug/view.cc
diff --git a/components/wug/view.cc b/components/wug/view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0d55e74aac50682d2eba34b83154a95afb6d9b29
--- /dev/null
+++ b/components/wug/view.cc
@@ -0,0 +1,97 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/wug/view.h"
+
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "components/wug/view_model.h"
+
+namespace wug {
+
+View::View(const std::string& id)
+ : parent_(NULL),
+ id_(id),
+ ready_children_(0),
+ view_model_ready_(false),
+ ready_(false),
+ weak_factory_(this) {
+}
+
+View::~View() {
+}
+
+void View::Init() {
+ CreateAndAddChildren();
+ if (!IsRootView())
Nikita (slow) 2015/02/24 15:22:42 nit: insert empty line.
dzhioev (left Google) 2015/02/26 14:01:38 Done.
+ path_ = parent_->path() + "$";
+ path_ += id_;
+ view_model_.reset(CreateViewModel());
+ view_model_->SetView(this);
+ for (auto& id_child : children_) {
Nikita (slow) 2015/02/24 15:22:42 nit: insert empty line, drop {}
dzhioev (left Google) 2015/02/26 14:01:37 Done.
+ id_child.second->Init();
+ }
+ if (children_.empty())
Nikita (slow) 2015/02/24 15:22:42 nit: insert empty line.
dzhioev (left Google) 2015/02/26 14:01:38 Done.
+ OnChildrenReady();
+}
+
+bool View::IsRootView() const {
+ return !parent_;
+}
+
+ViewModel* View::GetViewModel() const {
+ return view_model_.get();
+}
+
+void View::OnViewModelReady() {
+ view_model_ready_ = true;
+ if (ready_children_ == static_cast<int>(children_.size()))
+ OnReady();
+}
+
+View* View::GetChild(const std::string& id) const {
+ auto it = children_.find(id);
+ if (it == children_.end())
+ return nullptr;
+ return it->second;
Nikita (slow) 2015/02/24 15:22:42 nit: insert empty line.
dzhioev (left Google) 2015/02/26 14:01:38 Done.
+}
+
+void View::OnReady() {
+ if (ready_)
+ return;
+ ready_ = true;
Nikita (slow) 2015/02/24 15:22:42 nit: insert empty line.
dzhioev (left Google) 2015/02/26 14:01:38 Done.
+ if (!IsRootView())
+ parent_->OnChildReady(this);
+}
+
+void View::UpdateContext(const base::DictionaryValue& diff) {
+ DCHECK(ready_);
+ view_model_->UpdateContext(diff);
+}
+
+void View::HandleEvent(const std::string& event) {
+ DCHECK(ready_);
+ view_model_->OnEvent(event);
+}
+
+void View::AddChild(View* child) {
+ DCHECK(children_.find(child->id()) == children_.end());
+ DCHECK(!child->id().empty());
+ children_.set(child->id(), make_scoped_ptr(child));
+ child->set_parent(this);
+}
+
+void View::OnChildReady(View* child) {
+ ++ready_children_;
+ if (ready_children_ == static_cast<int>(children_.size()))
+ OnChildrenReady();
+}
+
+void View::OnChildrenReady() {
+ view_model_->OnChildrenReady();
+ if (view_model_ready_)
+ OnReady();
+}
+
+} // namespace wug

Powered by Google App Engine
This is Rietveld 408576698