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::TabSelectionChanged(
72 TabStripModel* tab_strip_model,
73 const ui::ListSelectionModel& old_model) {
74 if ([controller_ respondsToSelector:@selector(tabSelectionChanged)]) {
75 [controller_ tabSelectionChanged];
79 void TabStripModelObserverBridge::TabMoved(WebContents* contents,
82 if ([controller_ respondsToSelector:
83 @selector(tabMovedWithContents:fromIndex:toIndex:)]) {
84 [controller_ tabMovedWithContents:contents
90 void TabStripModelObserverBridge::TabChangedAt(WebContents* contents,
92 TabChangeType change_type) {
93 if ([controller_ respondsToSelector:
94 @selector(tabChangedWithContents:atIndex:changeType:)]) {
95 [controller_ tabChangedWithContents:contents
97 changeType:change_type];
101 void TabStripModelObserverBridge::TabReplacedAt(TabStripModel* tab_strip_model,
102 WebContents* old_contents,
103 WebContents* new_contents,
105 if ([controller_ respondsToSelector:
106 @selector(tabReplacedWithContents:previousContents:atIndex:)]) {
107 [controller_ tabReplacedWithContents:new_contents
108 previousContents:old_contents
111 TabChangedAt(new_contents, index, ALL);
115 void TabStripModelObserverBridge::TabMiniStateChanged(WebContents* contents,
117 if ([controller_ respondsToSelector:
118 @selector(tabMiniStateChangedWithContents:atIndex:)]) {
119 [controller_ tabMiniStateChangedWithContents:contents
124 void TabStripModelObserverBridge::TabStripEmpty() {
125 if ([controller_ respondsToSelector:@selector(tabStripEmpty)])
126 [controller_ tabStripEmpty];
129 void TabStripModelObserverBridge::TabStripModelDeleted() {
130 if ([controller_ respondsToSelector:@selector(tabStripModelDeleted)])
131 [controller_ tabStripModelDeleted];