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..96228d3ecf83a6af1f356d518703d92a39606967 |
| --- /dev/null |
| +++ b/components/wug/view.h |
| @@ -0,0 +1,82 @@ |
| +// 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; |
| + |
| +class WUG_EXPORT View { |
|
Nikita (slow)
2015/02/24 15:22:42
nit: Add comment.
Nikita (slow)
2015/02/24 15:22:43
I suggest renaming View to smth else.
Otherwise it
dzhioev (left Google)
2015/02/26 14:01:38
I don't think that it is a problem.
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| + public: |
| + View(const std::string& id); |
|
Nikita (slow)
2015/02/24 15:22:43
explicit
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| + virtual ~View(); |
| + |
| + virtual void Init(); |
| + bool IsRootView() const; |
|
Nikita (slow)
2015/02/24 15:22:43
nit: add comment i.e. what "root view" means.
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| + |
| + ViewModel* GetViewModel() const; |
| + |
| + // Called by view-model when it is ready. |
| + void OnViewModelReady(); |
| + |
| + const std::string& id() { return id_; } |
| + const std::string& path() { return path_; } |
|
Nikita (slow)
2015/02/24 15:22:43
nit: Add comment. Not clear what "path" means.
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| + View* GetChild(const std::string& id) const; |
| + |
| + // Called by view-model when it changes the context. |
| + virtual void OnContextChanged(const base::DictionaryValue& diff) = 0; |
| + |
| + protected: |
| + // Called when view and all its children are ready. |
| + virtual void OnReady(); |
|
Nikita (slow)
2015/02/24 15:22:42
nit: Rename to OnViewAndChildrenReady()
dzhioev (left Google)
2015/02/26 14:01:38
Changed comment instead.
|
| + |
| + // 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() { return ready_; } |
|
Nikita (slow)
2015/02/24 15:22:43
nit: Should this be public instead?
dzhioev (left Google)
2015/02/26 14:01:38
I don't think so. Made it 'const'.
|
| + |
| + 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); |
| + void OnChildrenReady(); |
| + void set_parent(View* parent) { parent_ = parent; } |
| + |
| + View* parent_; |
| + std::string id_; |
| + std::string path_; |
|
Nikita (slow)
2015/02/24 15:22:43
nit: comment
dzhioev (left Google)
2015/02/26 14:01:38
Already added comment to path()
|
| + int ready_children_; |
|
Nikita (slow)
2015/02/24 15:22:42
nit: comment
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| + 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); |
|
Nikita (slow)
2015/02/24 15:22:43
nit: insert empty line
dzhioev (left Google)
2015/02/26 14:01:38
Done.
|
| +}; |
| + |
| +} // namespace wug |
| + |
| +#endif // CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ |