- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / tabs / tab_strip_model_observer_bridge.mm
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.
4
5 #include "chrome/browser/ui/cocoa/tabs/tab_strip_model_observer_bridge.h"
6
7 #include "chrome/browser/ui/tabs/tab_strip_model.h"
8
9 using content::WebContents;
10
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);
18 }
19
20 TabStripModelObserverBridge::~TabStripModelObserverBridge() {
21   // Remove ourselves from receiving notifications.
22   model_->RemoveObserver(this);
23 }
24
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   }
34 }
35
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   }
43 }
44
45 void TabStripModelObserverBridge::TabDetachedAt(WebContents* contents,
46                                                 int index) {
47   if ([controller_ respondsToSelector:
48           @selector(tabDetachedWithContents:atIndex:)]) {
49     [controller_ tabDetachedWithContents:contents atIndex:index];
50   }
51 }
52
53 void TabStripModelObserverBridge::TabDeactivated(WebContents* contents) {
54   if ([controller_ respondsToSelector:@selector(tabDeactivatedWithContents:)])
55     [controller_ tabDeactivatedWithContents:contents];
56 }
57
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   }
69 }
70
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   }
80 }
81
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   }
91 }
92
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   }
105 }
106
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   }
114 }
115
116 void TabStripModelObserverBridge::TabStripEmpty() {
117   if ([controller_ respondsToSelector:@selector(tabStripEmpty)])
118     [controller_ tabStripEmpty];
119 }
120
121 void TabStripModelObserverBridge::TabStripModelDeleted() {
122   if ([controller_ respondsToSelector:@selector(tabStripModelDeleted)])
123     [controller_ tabStripModelDeleted];
124 }