| 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 {
|
| + public:
|
| + View(const std::string& id);
|
| + virtual ~View();
|
| +
|
| + virtual void Init();
|
| + bool IsRootView() const;
|
| +
|
| + 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_; }
|
| + 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();
|
| +
|
| + // 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_; }
|
| +
|
| + 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_;
|
| + 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_
|
|
|