Chromium Code Reviews| Index: components/wug/view.h |
| diff --git a/components/wug/view.h b/components/wug/view.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..1f4f6a7254ffcd96c86cb161c55775309df48727 |
| --- /dev/null |
| +++ b/components/wug/view.h |
| @@ -0,0 +1,98 @@ |
| +// 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. |
| + |
| +#ifndef CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ |
| +#define CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ |
| + |
| +#include "base/containers/scoped_ptr_hash_map.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/wug/export.h" |
| + |
| +namespace base { |
| +class DictionaryValue; |
| +} |
| + |
| +namespace wug { |
| + |
| +class ViewModel; |
| + |
| +/** |
| + * Base block of the UI. Every View instance is associated with single |
|
Nikita (slow)
2015/02/26 14:28:58
nit: please mention what type of UI.
There's no me
dzhioev (left Google)
2015/03/02 11:02:32
Done.
|
| + * ViewModel instance which provides a context for the view. Views are |
| + * hierarchical. Every child of view has an unique id. |
| + */ |
| +class WUG_EXPORT View { |
| + public: |
| + explicit View(const std::string& id); |
| + virtual ~View(); |
| + |
| + virtual void Init(); |
|
Denis Kuznetsov (DE-MUC)
2015/02/26 14:35:23
It is not obvious that OnReady should be called a
dzhioev (left Google)
2015/03/02 11:02:33
Done.
|
| + |
| + // Root view is a view without parent. |
| + // Root view should have id equal to "WUG_ROOT". |
| + bool IsRootView() const; |
| + |
| + ViewModel* GetViewModel() const; |
| + |
| + // Called by view-model when it is ready. |
| + void OnViewModelReady(); |
| + |
| + const std::string& id() const { return id_; } |
| + |
| + // Every view has an unique path in a view hierarchy which is: |
| + // a) |id| for the root view; |
| + // b) concatenation of parent's path, $-sign and |id| for not-root views. |
| + const std::string& path() const { return path_; } |
| + |
| + View* GetChild(const std::string& id) const; |
|
Denis Kuznetsov (DE-MUC)
2015/02/26 14:35:23
Add comment to method, including specifics on how
dzhioev (left Google)
2015/03/02 11:02:31
Done.
|
| + |
| + // Called by view-model when it changes the context. |
| + virtual void OnContextChanged(const base::DictionaryValue& diff) = 0; |
| + |
| + protected: |
| + // Called when view is ready, which means view-model and all children are |
| + // ready. |
| + virtual void OnReady(); |
| + |
| + // Forwards context changes stored in |diff| to view-model. |
| + void UpdateContext(const base::DictionaryValue& diff); |
| + |
| + // Forwards |event| to view-model. |
| + void HandleEvent(const std::string& event); |
| + |
| + bool ready() const { return ready_; } |
| + |
| + base::ScopedPtrHashMap<std::string, View>& children() { return children_; } |
| + |
| + void AddChild(View* child); |
| + |
| + virtual std::string GetType() = 0; |
| + virtual ViewModel* CreateViewModel() = 0; |
| + virtual void CreateAndAddChildren() = 0; |
| + |
| + private: |
| + void OnChildReady(View* child); |
|
Denis Kuznetsov (DE-MUC)
2015/02/26 14:35:23
Need a bit more details on "Ready" contract:
- Ca
dzhioev (left Google)
2015/03/02 11:02:31
Added to comments here and near AddChild().
|
| + void OnChildrenReady(); |
| + void set_parent(View* parent) { parent_ = parent; } |
| + |
| + View* parent_; |
| + std::string id_; |
| + std::string path_; |
| + |
| + // Number of ready child views. |
|
Nikita (slow)
2015/02/26 14:28:58
nit: number of child views that are ready.
dzhioev (left Google)
2015/03/02 11:02:32
Done.
|
| + int ready_children_; |
| + |
| + bool view_model_ready_; |
| + bool ready_; |
| + base::ScopedPtrHashMap<std::string, View> children_; |
| + scoped_ptr<ViewModel> view_model_; |
| + base::WeakPtrFactory<View> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(View); |
| +}; |
| + |
| +} // namespace wug |
| + |
| +#endif // CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ |