Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 2011 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 
      9 class TabContentsWrapper;
     10 class 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 ////////////////////////////////////////////////////////////////////////////////
     27 class 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 active tab has not changed. For example, if the selection is
     68   // extended this method is invoked to inform observers the selection has
     69   // changed, but |old_contents| and |new_contents| are the same.  If you only
     70   // care about when the active tab changes, check for when |old_contents|
     71   // differs from |new_contents|. |user_gesture| specifies whether or not this
     72   // was done by a user input event (e.g. clicking on a tab, keystroke) or as a
     73   // side-effect of some other function.
     74   //
     75   // TODO(sky): consider not overloading this. Instead rename this to
     76   // TabActivatedAt (or something) and have TabSelectionChanged as well.
     77   // TabSelectedAt. This requires renaming everyone to use new terms instead of
     78   // selection.
     79   virtual void TabSelectedAt(TabContentsWrapper* old_contents,
     80                              TabContentsWrapper* new_contents,
     81                              int index,
     82                              bool user_gesture);
     83 
     84   // The specified TabContents at |from_index| was moved to |to_index|.
     85   virtual void TabMoved(TabContentsWrapper* contents,
     86                         int from_index,
     87                         int to_index);
     88 
     89   // The specified TabContents at |index| changed in some way. |contents| may
     90   // be an entirely different object and the old value is no longer available
     91   // by the time this message is delivered.
     92   //
     93   // See TabChangeType for a description of |change_type|.
     94   virtual void TabChangedAt(TabContentsWrapper* contents,
     95                             int index,
     96                             TabChangeType change_type);
     97 
     98   // The tab contents was replaced at the specified index. This is invoked when
     99   // instant is enabled and the user navigates by way of instant.
    100   virtual void TabReplacedAt(TabStripModel* tab_strip_model,
    101                              TabContentsWrapper* old_contents,
    102                              TabContentsWrapper* new_contents,
    103                              int index);
    104 
    105   // Invoked when the pinned state of a tab changes. See note in
    106   // TabMiniStateChanged as to how this relates to TabMiniStateChanged.
    107   virtual void TabPinnedStateChanged(TabContentsWrapper* contents, int index);
    108 
    109   // Invoked if the mini state of a tab changes.
    110   // NOTE: this is sent when the pinned state of a non-app tab changes and is
    111   // sent in addition to TabPinnedStateChanged. UI code typically need not care
    112   // about TabPinnedStateChanged, but instead this.
    113   virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index);
    114 
    115   // Invoked when the blocked state of a tab changes.
    116   // NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal
    117   // window.
    118   virtual void TabBlockedStateChanged(TabContentsWrapper* contents, int index);
    119 
    120   // The TabStripModel now no longer has any tabs. The implementer may
    121   // use this as a trigger to try and close the window containing the
    122   // TabStripModel, for example...
    123   virtual void TabStripEmpty();
    124 
    125   // Sent when the tabstrip model is about to be deleted and any reference held
    126   // must be dropped.
    127   virtual void TabStripModelDeleted();
    128 
    129  protected:
    130   virtual ~TabStripModelObserver() {}
    131 };
    132 
    133 #endif  // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_OBSERVER_H_
    134