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 CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_
6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_
8 #import <Foundation/Foundation.h>
10 #include "base/compiler_specific.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
19 // A C++ bridge class to handle receiving notifications from the C++ tab strip
20 // model. When the caller allocates a bridge, it automatically registers for
21 // notifications from |model| and passes messages to |controller| via the
22 // informal protocol below. The owner of this object is responsible for deleting
23 // it (and thus unhooking notifications) before |controller| is destroyed.
24 class TabStripModelObserverBridge
: public TabStripModelObserver
{
26 TabStripModelObserverBridge(TabStripModel
* model
, id controller
);
27 virtual ~TabStripModelObserverBridge();
29 // Overridden from TabStripModelObserver
30 virtual void TabInsertedAt(content::WebContents
* contents
,
32 bool foreground
) OVERRIDE
;
33 virtual void TabClosingAt(TabStripModel
* tab_strip_model
,
34 content::WebContents
* contents
,
36 virtual void TabDetachedAt(content::WebContents
* contents
,
38 virtual void TabDeactivated(content::WebContents
* contents
) OVERRIDE
;
39 virtual void ActiveTabChanged(content::WebContents
* old_contents
,
40 content::WebContents
* new_contents
,
43 virtual void TabSelectionChanged(
44 TabStripModel
* tab_strip_model
,
45 const ui::ListSelectionModel
& old_model
) OVERRIDE
;
46 virtual void TabMoved(content::WebContents
* contents
,
48 int to_index
) OVERRIDE
;
49 virtual void TabChangedAt(content::WebContents
* contents
,
51 TabChangeType change_type
) OVERRIDE
;
52 virtual void TabReplacedAt(TabStripModel
* tab_strip_model
,
53 content::WebContents
* old_contents
,
54 content::WebContents
* new_contents
,
56 virtual void TabMiniStateChanged(content::WebContents
* contents
,
58 virtual void TabStripEmpty() OVERRIDE
;
59 virtual void TabStripModelDeleted() OVERRIDE
;
62 id controller_
; // weak, owns me
63 TabStripModel
* model_
; // weak, owned by Browser
66 // A collection of methods which can be selectively implemented by any
67 // Cocoa object to receive updates about changes to a tab strip model. It is
68 // ok to not implement them, the calling code checks before calling.
69 @interface
NSObject(TabStripModelBridge
)
70 - (void)insertTabWithContents
:(content::WebContents
*)contents
71 atIndex
:(NSInteger
)index
72 inForeground
:(bool)inForeground
;
73 - (void)tabClosingWithContents
:(content::WebContents
*)contents
74 atIndex
:(NSInteger
)index
;
75 - (void)tabDetachedWithContents
:(content::WebContents
*)contents
76 atIndex
:(NSInteger
)index
;
77 - (void)tabDeactivatedWithContents
:(content::WebContents
*)contents
;
78 - (void)activateTabWithContents
:(content::WebContents
*)newContents
79 previousContents
:(content::WebContents
*)oldContents
80 atIndex
:(NSInteger
)index
82 - (void)tabMovedWithContents
:(content::WebContents
*)contents
83 fromIndex
:(NSInteger
)from
84 toIndex
:(NSInteger
)to
;
85 - (void)tabChangedWithContents
:(content::WebContents
*)contents
86 atIndex
:(NSInteger
)index
87 changeType
:(TabStripModelObserver::TabChangeType
)change
;
88 - (void)tabReplacedWithContents
:(content::WebContents
*)newContents
89 previousContents
:(content::WebContents
*)oldContents
90 atIndex
:(NSInteger
)index
;
91 - (void)tabMiniStateChangedWithContents
:(content::WebContents
*)contents
92 atIndex
:(NSInteger
)index
;
93 - (void)tabStripEmpty
;
94 - (void)tabStripModelDeleted
;
95 - (void)tabSelectionChanged
;
98 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_