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 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.
| |
22 public: | |
23 View(const std::string& id); | |
Nikita (slow)
2015/02/24 15:22:43
explicit
dzhioev (left Google)
2015/02/26 14:01:38
Done.
| |
24 virtual ~View(); | |
25 | |
26 virtual void Init(); | |
27 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.
| |
28 | |
29 ViewModel* GetViewModel() const; | |
30 | |
31 // Called by view-model when it is ready. | |
32 void OnViewModelReady(); | |
33 | |
34 const std::string& id() { return id_; } | |
35 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.
| |
36 View* GetChild(const std::string& id) const; | |
37 | |
38 // Called by view-model when it changes the context. | |
39 virtual void OnContextChanged(const base::DictionaryValue& diff) = 0; | |
40 | |
41 protected: | |
42 // Called when view and all its children are ready. | |
43 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.
| |
44 | |
45 // Forwards context changes stored in |diff| to view-model. | |
46 void UpdateContext(const base::DictionaryValue& diff); | |
47 | |
48 // Forwards |event| to view-model. | |
49 void HandleEvent(const std::string& event); | |
50 | |
51 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'.
| |
52 | |
53 base::ScopedPtrHashMap<std::string, View>& children() { return children_; } | |
54 | |
55 void AddChild(View* child); | |
56 | |
57 virtual std::string GetType() = 0; | |
58 virtual ViewModel* CreateViewModel() = 0; | |
59 virtual void CreateAndAddChildren() = 0; | |
60 | |
61 private: | |
62 void OnChildReady(View* child); | |
63 void OnChildrenReady(); | |
64 void set_parent(View* parent) { parent_ = parent; } | |
65 | |
66 View* parent_; | |
67 std::string id_; | |
68 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()
| |
69 int ready_children_; | |
Nikita (slow)
2015/02/24 15:22:42
nit: comment
dzhioev (left Google)
2015/02/26 14:01:38
Done.
| |
70 bool view_model_ready_; | |
71 bool ready_; | |
72 | |
73 base::ScopedPtrHashMap<std::string, View> children_; | |
74 scoped_ptr<ViewModel> view_model_; | |
75 | |
76 base::WeakPtrFactory<View> weak_factory_; | |
77 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.
| |
78 }; | |
79 | |
80 } // namespace wug | |
81 | |
82 #endif // CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ | |
OLD | NEW |