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 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 using content::WebContents;
11 TabStripModelObserverBridge::TabStripModelObserverBridge(TabStripModel* model,
13 : controller_(controller), model_(model) {
14 DCHECK(model && controller);
15 // Register to be a listener on the model so we can get updates and tell
16 // |controller_| about them in the future.
17 model_->AddObserver(this);
20 TabStripModelObserverBridge::~TabStripModelObserverBridge() {
21 // Remove ourselves from receiving notifications.
22 model_->RemoveObserver(this);
25 void TabStripModelObserverBridge::TabInsertedAt(WebContents* contents,
28 if ([controller_ respondsToSelector:
29 @selector(insertTabWithContents:atIndex:inForeground:)]) {
30 [controller_ insertTabWithContents:contents
32 inForeground:foreground];
36 void TabStripModelObserverBridge::TabClosingAt(TabStripModel* tab_strip_model,
37 WebContents* contents,
39 if ([controller_ respondsToSelector:
40 @selector(tabClosingWithContents:atIndex:)]) {
41 [controller_ tabClosingWithContents:contents atIndex:index];
45 void TabStripModelObserverBridge::TabDetachedAt(WebContents* contents,
47 if ([controller_ respondsToSelector:
48 @selector(tabDetachedWithContents:atIndex:)]) {
49 [controller_ tabDetachedWithContents:contents atIndex:index];
53 void TabStripModelObserverBridge::TabDeactivated(WebContents* contents) {
54 if ([controller_ respondsToSelector:@selector(tabDeactivatedWithContents:)])
55 [controller_ tabDeactivatedWithContents:contents];
58 void TabStripModelObserverBridge::ActiveTabChanged(WebContents* old_contents,
59 WebContents* new_contents,
62 if ([controller_ respondsToSelector:@selector(
63 activateTabWithContents:previousContents:atIndex:reason:)]) {
64 [controller_ activateTabWithContents:new_contents
65 previousContents:old_contents
71 void TabStripModelObserverBridge::TabMoved(WebContents* contents,
74 if ([controller_ respondsToSelector:
75 @selector(tabMovedWithContents:fromIndex:toIndex:)]) {
76 [controller_ tabMovedWithContents:contents
82 void TabStripModelObserverBridge::TabChangedAt(WebContents* contents,
84 TabChangeType change_type) {
85 if ([controller_ respondsToSelector:
86 @selector(tabChangedWithContents:atIndex:changeType:)]) {
87 [controller_ tabChangedWithContents:contents
89 changeType:change_type];
93 void TabStripModelObserverBridge::TabReplacedAt(TabStripModel* tab_strip_model,
94 WebContents* old_contents,
95 WebContents* new_contents,
97 if ([controller_ respondsToSelector:
98 @selector(tabReplacedWithContents:previousContents:atIndex:)]) {
99 [controller_ tabReplacedWithContents:new_contents
100 previousContents:old_contents
103 TabChangedAt(new_contents, index, ALL);
107 void TabStripModelObserverBridge::TabMiniStateChanged(WebContents* contents,
109 if ([controller_ respondsToSelector:
110 @selector(tabMiniStateChangedWithContents:atIndex:)]) {
111 [controller_ tabMiniStateChangedWithContents:contents
116 void TabStripModelObserverBridge::TabStripEmpty() {
117 if ([controller_ respondsToSelector:@selector(tabStripEmpty)])
118 [controller_ tabStripEmpty];
121 void TabStripModelObserverBridge::TabStripModelDeleted() {
122 if ([controller_ respondsToSelector:@selector(tabStripModelDeleted)])
123 [controller_ tabStripModelDeleted];