Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / base / models / tree_model.h
blobd553a4043a86f0bef4db1a79e95a1acf60fa550c
1 // Copyright (c) 2012 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.
5 #ifndef UI_BASE_MODELS_TREE_MODEL_H_
6 #define UI_BASE_MODELS_TREE_MODEL_H_
8 #include <vector>
10 #include "base/strings/string16.h"
11 #include "ui/base/ui_base_export.h"
13 namespace gfx {
14 class ImageSkia;
17 namespace ui {
19 class TreeModel;
21 // TreeModelNode --------------------------------------------------------------
23 // Type of class returned from the model.
24 class TreeModelNode {
25 public:
26 // Returns the title for the node.
27 virtual const base::string16& GetTitle() const = 0;
29 protected:
30 virtual ~TreeModelNode() {}
33 // Observer for the TreeModel. Notified of significant events to the model.
34 class UI_BASE_EXPORT TreeModelObserver {
35 public:
36 // Notification that nodes were added to the specified parent.
37 virtual void TreeNodesAdded(TreeModel* model,
38 TreeModelNode* parent,
39 int start,
40 int count) = 0;
42 // Notification that nodes were removed from the specified parent.
43 virtual void TreeNodesRemoved(TreeModel* model,
44 TreeModelNode* parent,
45 int start,
46 int count) = 0;
48 // Notification that the contents of a node has changed.
49 virtual void TreeNodeChanged(TreeModel* model, TreeModelNode* node) = 0;
51 protected:
52 virtual ~TreeModelObserver() {}
55 // TreeModel ------------------------------------------------------------------
57 // The model for TreeView.
58 class UI_BASE_EXPORT TreeModel {
59 public:
60 // Returns the root of the tree. This may or may not be shown in the tree,
61 // see SetRootShown for details.
62 virtual TreeModelNode* GetRoot() = 0;
64 // Returns the number of children in |parent|.
65 virtual int GetChildCount(TreeModelNode* parent) = 0;
67 // Returns the child node of |parent| at |index|.
68 virtual TreeModelNode* GetChild(TreeModelNode* parent, int index) = 0;
70 // Returns the index of |child| in |parent|.
71 virtual int GetIndexOf(TreeModelNode* parent, TreeModelNode* child) = 0;
73 // Returns the parent of |node|, or NULL if |node| is the root.
74 virtual TreeModelNode* GetParent(TreeModelNode* node) = 0;
76 // Adds an observer of the model.
77 virtual void AddObserver(TreeModelObserver* observer) = 0;
79 // Removes an observer of the model.
80 virtual void RemoveObserver(TreeModelObserver* observer) = 0;
82 // Sets the title of |node|.
83 // This is only invoked if the node is editable and the user edits a node.
84 virtual void SetTitle(TreeModelNode* node, const base::string16& title);
86 // Returns the set of icons for the nodes in the tree. You only need override
87 // this if you don't want to use the default folder icons.
88 virtual void GetIcons(std::vector<gfx::ImageSkia>* icons) {}
90 // Returns the index of the icon to use for |node|. Return -1 to use the
91 // default icon. The index is relative to the list of icons returned from
92 // GetIcons.
93 virtual int GetIconIndex(TreeModelNode* node);
95 protected:
96 virtual ~TreeModel() {}
99 } // namespace ui
101 #endif // UI_BASE_MODELS_TREE_MODEL_H_