Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ | |
| 6 #define CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ | |
| 7 | |
| 8 #include "base/containers/scoped_ptr_hash_map.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "base/memory/weak_ptr.h" | |
| 11 #include "components/wug/export.h" | |
| 12 | |
| 13 namespace base { | |
| 14 class DictionaryValue; | |
| 15 } | |
| 16 | |
| 17 namespace wug { | |
| 18 | |
| 19 class ViewModel; | |
| 20 | |
| 21 /** | |
| 22 * 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.
| |
| 23 * ViewModel instance which provides a context for the view. Views are | |
| 24 * hierarchical. Every child of view has an unique id. | |
| 25 */ | |
| 26 class WUG_EXPORT View { | |
| 27 public: | |
| 28 explicit View(const std::string& id); | |
| 29 virtual ~View(); | |
| 30 | |
| 31 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.
| |
| 32 | |
| 33 // Root view is a view without parent. | |
| 34 // Root view should have id equal to "WUG_ROOT". | |
| 35 bool IsRootView() const; | |
| 36 | |
| 37 ViewModel* GetViewModel() const; | |
| 38 | |
| 39 // Called by view-model when it is ready. | |
| 40 void OnViewModelReady(); | |
| 41 | |
| 42 const std::string& id() const { return id_; } | |
| 43 | |
| 44 // Every view has an unique path in a view hierarchy which is: | |
| 45 // a) |id| for the root view; | |
| 46 // b) concatenation of parent's path, $-sign and |id| for not-root views. | |
| 47 const std::string& path() const { return path_; } | |
| 48 | |
| 49 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.
| |
| 50 | |
| 51 // Called by view-model when it changes the context. | |
| 52 virtual void OnContextChanged(const base::DictionaryValue& diff) = 0; | |
| 53 | |
| 54 protected: | |
| 55 // Called when view is ready, which means view-model and all children are | |
| 56 // ready. | |
| 57 virtual void OnReady(); | |
| 58 | |
| 59 // Forwards context changes stored in |diff| to view-model. | |
| 60 void UpdateContext(const base::DictionaryValue& diff); | |
| 61 | |
| 62 // Forwards |event| to view-model. | |
| 63 void HandleEvent(const std::string& event); | |
| 64 | |
| 65 bool ready() const { return ready_; } | |
| 66 | |
| 67 base::ScopedPtrHashMap<std::string, View>& children() { return children_; } | |
| 68 | |
| 69 void AddChild(View* child); | |
| 70 | |
| 71 virtual std::string GetType() = 0; | |
| 72 virtual ViewModel* CreateViewModel() = 0; | |
| 73 virtual void CreateAndAddChildren() = 0; | |
| 74 | |
| 75 private: | |
| 76 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().
| |
| 77 void OnChildrenReady(); | |
| 78 void set_parent(View* parent) { parent_ = parent; } | |
| 79 | |
| 80 View* parent_; | |
| 81 std::string id_; | |
| 82 std::string path_; | |
| 83 | |
| 84 // 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.
| |
| 85 int ready_children_; | |
| 86 | |
| 87 bool view_model_ready_; | |
| 88 bool ready_; | |
| 89 base::ScopedPtrHashMap<std::string, View> children_; | |
| 90 scoped_ptr<ViewModel> view_model_; | |
| 91 base::WeakPtrFactory<View> weak_factory_; | |
| 92 | |
| 93 DISALLOW_COPY_AND_ASSIGN(View); | |
| 94 }; | |
| 95 | |
| 96 } // namespace wug | |
| 97 | |
| 98 #endif // CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ | |
| OLD | NEW |