Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / tabs / tab_strip_model_observer_bridge.mm
blob8d113558c317bb9d40fa7f04c9f8f673997770c2
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,
12                                                          id controller)
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,
26                                                 int index,
27                                                 bool foreground) {
28   if ([controller_ respondsToSelector:
29           @selector(insertTabWithContents:atIndex:inForeground:)]) {
30     [controller_ insertTabWithContents:contents
31                                atIndex:index
32                           inForeground:foreground];
33   }
36 void TabStripModelObserverBridge::TabClosingAt(TabStripModel* tab_strip_model,
37                                                WebContents* contents,
38                                                int index) {
39   if ([controller_ respondsToSelector:
40           @selector(tabClosingWithContents:atIndex:)]) {
41     [controller_ tabClosingWithContents:contents atIndex:index];
42   }
45 void TabStripModelObserverBridge::TabDetachedAt(WebContents* contents,
46                                                 int index) {
47   if ([controller_ respondsToSelector:
48           @selector(tabDetachedWithContents:atIndex:)]) {
49     [controller_ tabDetachedWithContents:contents atIndex:index];
50   }
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,
60                                                    int index,
61                                                    int reason) {
62   if ([controller_ respondsToSelector:@selector(
63           activateTabWithContents:previousContents:atIndex:reason:)]) {
64     [controller_ activateTabWithContents:new_contents
65                         previousContents:old_contents
66                                  atIndex:index
67                                   reason:reason];
68   }
71 void TabStripModelObserverBridge::TabMoved(WebContents* contents,
72                                            int from_index,
73                                            int to_index) {
74   if ([controller_ respondsToSelector:
75        @selector(tabMovedWithContents:fromIndex:toIndex:)]) {
76     [controller_ tabMovedWithContents:contents
77                             fromIndex:from_index
78                               toIndex:to_index];
79   }
82 void TabStripModelObserverBridge::TabChangedAt(WebContents* contents,
83                                                int index,
84                                                TabChangeType change_type) {
85   if ([controller_ respondsToSelector:
86           @selector(tabChangedWithContents:atIndex:changeType:)]) {
87     [controller_ tabChangedWithContents:contents
88                                 atIndex:index
89                              changeType:change_type];
90   }
93 void TabStripModelObserverBridge::TabReplacedAt(TabStripModel* tab_strip_model,
94                                                 WebContents* old_contents,
95                                                 WebContents* new_contents,
96                                                 int index) {
97   if ([controller_ respondsToSelector:
98           @selector(tabReplacedWithContents:previousContents:atIndex:)]) {
99     [controller_ tabReplacedWithContents:new_contents
100                         previousContents:old_contents
101                                  atIndex:index];
102   } else {
103     TabChangedAt(new_contents, index, ALL);
104   }
107 void TabStripModelObserverBridge::TabMiniStateChanged(WebContents* contents,
108                                                       int index) {
109   if ([controller_ respondsToSelector:
110           @selector(tabMiniStateChangedWithContents:atIndex:)]) {
111     [controller_ tabMiniStateChangedWithContents:contents
112                                          atIndex:index];
113   }
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];