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_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_
6#define CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_
7#pragma once
8
9#import <Foundation/Foundation.h>
10
11#include "chrome/browser/tabs/tab_strip_model_observer.h"
12
13class TabContentsWrapper;
14class TabStripModel;
15
16// A C++ bridge class to handle receiving notifications from the C++ tab strip
17// model. When the caller allocates a bridge, it automatically registers for
18// notifications from |model| and passes messages to |controller| via the
19// informal protocol below. The owner of this object is responsible for deleting
20// it (and thus unhooking notifications) before |controller| is destroyed.
21class TabStripModelObserverBridge : public TabStripModelObserver {
22 public:
23  TabStripModelObserverBridge(TabStripModel* model, id controller);
24  virtual ~TabStripModelObserverBridge();
25
26  // Overridden from TabStripModelObserver
27  virtual void TabInsertedAt(TabContentsWrapper* contents,
28                             int index,
29                             bool foreground);
30  virtual void TabClosingAt(TabStripModel* tab_strip_model,
31                            TabContentsWrapper* contents,
32                            int index);
33  virtual void TabDetachedAt(TabContentsWrapper* contents, int index);
34  virtual void TabSelectedAt(TabContentsWrapper* old_contents,
35                             TabContentsWrapper* new_contents,
36                             int index,
37                             bool user_gesture);
38  virtual void TabMoved(TabContentsWrapper* contents,
39                        int from_index,
40                        int to_index);
41  virtual void TabChangedAt(TabContentsWrapper* contents, int index,
42                            TabChangeType change_type);
43  virtual void TabReplacedAt(TabStripModel* tab_strip_model,
44                             TabContentsWrapper* old_contents,
45                             TabContentsWrapper* new_contents,
46                             int index);
47  virtual void TabMiniStateChanged(TabContentsWrapper* contents, int index);
48  virtual void TabStripEmpty();
49  virtual void TabStripModelDeleted();
50
51 private:
52  id controller_;  // weak, owns me
53  TabStripModel* model_;  // weak, owned by Browser
54};
55
56// A collection of methods which can be selectively implemented by any
57// Cocoa object to receive updates about changes to a tab strip model. It is
58// ok to not implement them, the calling code checks before calling.
59@interface NSObject(TabStripModelBridge)
60- (void)insertTabWithContents:(TabContentsWrapper*)contents
61                      atIndex:(NSInteger)index
62                 inForeground:(bool)inForeground;
63- (void)tabClosingWithContents:(TabContentsWrapper*)contents
64                       atIndex:(NSInteger)index;
65- (void)tabDetachedWithContents:(TabContentsWrapper*)contents
66                        atIndex:(NSInteger)index;
67- (void)selectTabWithContents:(TabContentsWrapper*)newContents
68             previousContents:(TabContentsWrapper*)oldContents
69                      atIndex:(NSInteger)index
70                  userGesture:(bool)wasUserGesture;
71- (void)tabMovedWithContents:(TabContentsWrapper*)contents
72                    fromIndex:(NSInteger)from
73                      toIndex:(NSInteger)to;
74- (void)tabChangedWithContents:(TabContentsWrapper*)contents
75                       atIndex:(NSInteger)index
76                    changeType:(TabStripModelObserver::TabChangeType)change;
77- (void)tabReplacedWithContents:(TabContentsWrapper*)newContents
78               previousContents:(TabContentsWrapper*)oldContents
79                        atIndex:(NSInteger)index;
80- (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents
81                                atIndex:(NSInteger)index;
82- (void)tabStripEmpty;
83- (void)tabStripModelDeleted;
84@end
85
86#endif  // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_
87