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 ~TabStripModelObserverBridge() override
;
29 // Overridden from TabStripModelObserver
30 void TabInsertedAt(content::WebContents
* contents
,
32 bool foreground
) override
;
33 void TabClosingAt(TabStripModel
* tab_strip_model
,
34 content::WebContents
* contents
,
36 void TabDetachedAt(content::WebContents
* contents
, int index
) override
;
37 void TabDeactivated(content::WebContents
* contents
) override
;
38 void ActiveTabChanged(content::WebContents
* old_contents
,
39 content::WebContents
* new_contents
,
42 void TabSelectionChanged(TabStripModel
* tab_strip_model
,
43 const ui::ListSelectionModel
& old_model
) override
;
44 void TabMoved(content::WebContents
* contents
,
46 int to_index
) override
;
47 void TabChangedAt(content::WebContents
* contents
,
49 TabChangeType change_type
) override
;
50 void TabReplacedAt(TabStripModel
* tab_strip_model
,
51 content::WebContents
* old_contents
,
52 content::WebContents
* new_contents
,
54 void TabPinnedStateChanged(content::WebContents
* contents
,
56 void TabStripEmpty() override
;
57 void TabStripModelDeleted() override
;
60 id controller_
; // weak, owns me
61 TabStripModel
* model_
; // weak, owned by Browser
64 // A collection of methods which can be selectively implemented by any
65 // Cocoa object to receive updates about changes to a tab strip model. It is
66 // ok to not implement them, the calling code checks before calling.
67 @interface
NSObject(TabStripModelBridge
)
68 - (void)insertTabWithContents
:(content::WebContents
*)contents
69 atIndex
:(NSInteger
)index
70 inForeground
:(bool)inForeground
;
71 - (void)tabClosingWithContents
:(content::WebContents
*)contents
72 atIndex
:(NSInteger
)index
;
73 - (void)tabDetachedWithContents
:(content::WebContents
*)contents
74 atIndex
:(NSInteger
)index
;
75 - (void)tabDeactivatedWithContents
:(content::WebContents
*)contents
;
76 - (void)activateTabWithContents
:(content::WebContents
*)newContents
77 previousContents
:(content::WebContents
*)oldContents
78 atIndex
:(NSInteger
)index
80 - (void)tabMovedWithContents
:(content::WebContents
*)contents
81 fromIndex
:(NSInteger
)from
82 toIndex
:(NSInteger
)to
;
83 - (void)tabChangedWithContents
:(content::WebContents
*)contents
84 atIndex
:(NSInteger
)index
85 changeType
:(TabStripModelObserver::TabChangeType
)change
;
86 - (void)tabReplacedWithContents
:(content::WebContents
*)newContents
87 previousContents
:(content::WebContents
*)oldContents
88 atIndex
:(NSInteger
)index
;
89 - (void)tabPinnedStateChangedWithContents
:(content::WebContents
*)contents
90 atIndex
:(NSInteger
)index
;
91 - (void)tabStripEmpty
;
92 - (void)tabStripModelDeleted
;
93 - (void)tabSelectionChanged
;
96 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_