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 { |
| 22 public: |
| 23 View(const std::string& id); |
| 24 virtual ~View(); |
| 25 |
| 26 virtual void Init(); |
| 27 bool IsRootView() const; |
| 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_; } |
| 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(); |
| 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_; } |
| 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_; |
| 69 int ready_children_; |
| 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); |
| 78 }; |
| 79 |
| 80 } // namespace wug |
| 81 |
| 82 #endif // CHROME_BROWSER_UI_WEBUI_WUG_VIEW_H_ |
OLD | NEW |