tab_strip_model_observer.h revision dc0f95d653279beabeb9817299e2902918ba123e
1// Copyright (c) 2010 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_TABS_TAB_STRIP_MODEL_OBSERVER_H_
6#define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_OBSERVER_H_
7#pragma once
8
9class TabContentsWrapper;
10class TabStripModel;
11
12////////////////////////////////////////////////////////////////////////////////
13//
14// TabStripModelObserver
15//
16//  Objects implement this interface when they wish to be notified of changes
17//  to the TabStripModel.
18//
19//  Two major implementers are the TabStrip, which uses notifications sent
20//  via this interface to update the presentation of the strip, and the Browser
21//  object, which updates bookkeeping and shows/hides individual TabContentses.
22//
23//  Register your TabStripModelObserver with the TabStripModel using its
24//  Add/RemoveObserver methods.
25//
26////////////////////////////////////////////////////////////////////////////////
27class TabStripModelObserver {
28 public:
29  // Enumeration of the possible values supplied to TabChangedAt.
30  enum TabChangeType {
31    // Only the loading state changed.
32    LOADING_ONLY,
33
34    // Only the title changed and page isn't loading.
35    TITLE_NOT_LOADING,
36
37    // Change not characterized by LOADING_ONLY or TITLE_NOT_LOADING.
38    ALL
39  };
40
41  // A new TabContents was inserted into the TabStripModel at the specified
42  // index. |foreground| is whether or not it was opened in the foreground
43  // (selected).
44  virtual void TabInsertedAt(TabContentsWrapper* contents,
45                             int index,
46                             bool foreground);
47
48  // The specified TabContents at |index| is being closed (and eventually
49  // destroyed). |tab_strip_model| is the TabStripModel the tab was part of.
50  virtual void TabClosingAt(TabStripModel* tab_strip_model,
51                            TabContentsWrapper* contents,
52                            int index);
53
54  // The specified TabContents at |index| is being detached, perhaps to be
55  // inserted in another TabStripModel. The implementer should take whatever
56  // action is necessary to deal with the TabContents no longer being present.
57  virtual void TabDetachedAt(TabContentsWrapper* contents, int index);
58
59  // The selected TabContents is about to change from |old_contents|.
60  // This gives observers a chance to prepare for an impending switch before it
61  // happens.
62  virtual void TabDeselected(TabContentsWrapper* contents);
63
64  // Sent when the selection changes. The previously selected tab is identified
65  // by |old_contents| and the newly selected tab by |new_contents|. |index| is
66  // the index of |new_contents|. When using multiple selection this may be sent
67  // even when the selected tab (as returned by selected_index()) has not
68  // changed. For example, if the selection is extended this method is invoked
69  // to inform observers the selection has changed, but |old_contents| and
70  // |new_contents| are the same.  If you only care about when the selected tab
71  // changes, check for when |old_contents| differs from
72  // |new_contents|. |user_gesture| specifies whether or not this was done by a
73  // user input event (e.g. clicking on a tab, keystroke) or as a side-effect of
74  // some other function.
75  //
76  // TODO(sky): consider not overloading this. Instead rename this to
77  // TabActivatedAt (or something) and have TabSelectionChanged as well.
78  // TabSelectedAt. This requires renaming everyone to use new terms instead of
79  // selection.
80  virtual void TabSelectedAt(TabContentsWrapper* old_contents,
81                             TabContentsWrapper* new_contents,
82                             int index,
83                             bool user_gesture);
84
85  // The specified TabContents at |from_index| was moved to |to_index|.
86  virtual void TabMoved(TabContentsWrapper* contents,
87                        int from_index,
88                        int to_index);
89
90  // The specified TabContents at |index| changed in some way. |contents| may
91  // be an entirely different object and the old value is no longer available
92  // by the time this message is delivered.
93  //
94  // See TabChangeType for a description of |change_type|.
95  virtual void TabChangedAt(TabContentsWrapper* contents,
96                            int index,
97                            TabChangeType change_type);
98
99  // The tab contents was replaced at the specified index. This is invoked when
100  // instant is enabled and the user navigates by way of instant.
101  virtual void TabReplacedAt(TabStripModel* tab_strip_model,
102                             TabContentsWrapper* old_contents,
103                             TabContentsWrapper* new_contents,
104                             int index);
105
106  // Invoked when the pinned state of a tab changes. See note in
107  // TabMiniStateChanged as to how this relates to TabMiniStateChanged.
108  virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index);
109
110  // Invoked if the mini state of a tab changes.
111  // NOTE: this is sent when the pinned state of a non-app tab changes and is
112  // sent in addition to TabPinnedStateChanged. UI code typically need not care
113  // about TabPinnedStateChanged, but instead this.
114  virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index);
115
116  // Invoked when the blocked state of a tab changes.
117  // NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal
118  // window.
119  virtual void TabBlockedStateChanged(TabContentsWrapper* contents, int index);
120
121  // The TabStripModel now no longer has any tabs. The implementer may
122  // use this as a trigger to try and close the window containing the
123  // TabStripModel, for example...
124  virtual void TabStripEmpty();
125
126  // Sent when the tabstrip model is about to be deleted and any reference held
127  // must be dropped.
128  virtual void TabStripModelDeleted();
129
130 protected:
131  virtual ~TabStripModelObserver() {}
132};
133
134#endif  // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_OBSERVER_H_
135