| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_ | 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_ | 6 #define CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" |
| 13 | 13 |
| 14 class TabContents; | 14 class TabContents; |
| 15 typedef TabContents TabContentsWrapper; | |
| 16 class TabStripModel; | 15 class TabStripModel; |
| 17 | 16 |
| 18 // A C++ bridge class to handle receiving notifications from the C++ tab strip | 17 // A C++ bridge class to handle receiving notifications from the C++ tab strip |
| 19 // model. When the caller allocates a bridge, it automatically registers for | 18 // model. When the caller allocates a bridge, it automatically registers for |
| 20 // notifications from |model| and passes messages to |controller| via the | 19 // notifications from |model| and passes messages to |controller| via the |
| 21 // informal protocol below. The owner of this object is responsible for deleting | 20 // informal protocol below. The owner of this object is responsible for deleting |
| 22 // it (and thus unhooking notifications) before |controller| is destroyed. | 21 // it (and thus unhooking notifications) before |controller| is destroyed. |
| 23 class TabStripModelObserverBridge : public TabStripModelObserver { | 22 class TabStripModelObserverBridge : public TabStripModelObserver { |
| 24 public: | 23 public: |
| 25 TabStripModelObserverBridge(TabStripModel* model, id controller); | 24 TabStripModelObserverBridge(TabStripModel* model, id controller); |
| 26 virtual ~TabStripModelObserverBridge(); | 25 virtual ~TabStripModelObserverBridge(); |
| 27 | 26 |
| 28 // Overridden from TabStripModelObserver | 27 // Overridden from TabStripModelObserver |
| 29 virtual void TabInsertedAt(TabContentsWrapper* contents, | 28 virtual void TabInsertedAt(TabContents* contents, |
| 30 int index, | 29 int index, |
| 31 bool foreground) OVERRIDE; | 30 bool foreground) OVERRIDE; |
| 32 virtual void TabClosingAt(TabStripModel* tab_strip_model, | 31 virtual void TabClosingAt(TabStripModel* tab_strip_model, |
| 33 TabContentsWrapper* contents, | 32 TabContents* contents, |
| 34 int index) OVERRIDE; | 33 int index) OVERRIDE; |
| 35 virtual void TabDetachedAt(TabContentsWrapper* contents, int index) OVERRIDE; | 34 virtual void TabDetachedAt(TabContents* contents, int index) OVERRIDE; |
| 36 virtual void ActiveTabChanged(TabContentsWrapper* old_contents, | 35 virtual void ActiveTabChanged(TabContents* old_contents, |
| 37 TabContentsWrapper* new_contents, | 36 TabContents* new_contents, |
| 38 int index, | 37 int index, |
| 39 bool user_gesture) OVERRIDE; | 38 bool user_gesture) OVERRIDE; |
| 40 virtual void TabMoved(TabContentsWrapper* contents, | 39 virtual void TabMoved(TabContents* contents, |
| 41 int from_index, | 40 int from_index, |
| 42 int to_index) OVERRIDE; | 41 int to_index) OVERRIDE; |
| 43 virtual void TabChangedAt(TabContentsWrapper* contents, int index, | 42 virtual void TabChangedAt(TabContents* contents, int index, |
| 44 TabChangeType change_type) OVERRIDE; | 43 TabChangeType change_type) OVERRIDE; |
| 45 virtual void TabReplacedAt(TabStripModel* tab_strip_model, | 44 virtual void TabReplacedAt(TabStripModel* tab_strip_model, |
| 46 TabContentsWrapper* old_contents, | 45 TabContents* old_contents, |
| 47 TabContentsWrapper* new_contents, | 46 TabContents* new_contents, |
| 48 int index) OVERRIDE; | 47 int index) OVERRIDE; |
| 49 virtual void TabMiniStateChanged(TabContentsWrapper* contents, | 48 virtual void TabMiniStateChanged(TabContents* contents, |
| 50 int index) OVERRIDE; | 49 int index) OVERRIDE; |
| 51 virtual void TabStripEmpty() OVERRIDE; | 50 virtual void TabStripEmpty() OVERRIDE; |
| 52 virtual void TabStripModelDeleted() OVERRIDE; | 51 virtual void TabStripModelDeleted() OVERRIDE; |
| 53 | 52 |
| 54 private: | 53 private: |
| 55 id controller_; // weak, owns me | 54 id controller_; // weak, owns me |
| 56 TabStripModel* model_; // weak, owned by Browser | 55 TabStripModel* model_; // weak, owned by Browser |
| 57 }; | 56 }; |
| 58 | 57 |
| 59 // A collection of methods which can be selectively implemented by any | 58 // A collection of methods which can be selectively implemented by any |
| 60 // Cocoa object to receive updates about changes to a tab strip model. It is | 59 // Cocoa object to receive updates about changes to a tab strip model. It is |
| 61 // ok to not implement them, the calling code checks before calling. | 60 // ok to not implement them, the calling code checks before calling. |
| 62 @interface NSObject(TabStripModelBridge) | 61 @interface NSObject(TabStripModelBridge) |
| 63 - (void)insertTabWithContents:(TabContentsWrapper*)contents | 62 - (void)insertTabWithContents:(TabContents*)contents |
| 64 atIndex:(NSInteger)index | 63 atIndex:(NSInteger)index |
| 65 inForeground:(bool)inForeground; | 64 inForeground:(bool)inForeground; |
| 66 - (void)tabClosingWithContents:(TabContentsWrapper*)contents | 65 - (void)tabClosingWithContents:(TabContents*)contents |
| 67 atIndex:(NSInteger)index; | 66 atIndex:(NSInteger)index; |
| 68 - (void)tabDetachedWithContents:(TabContentsWrapper*)contents | 67 - (void)tabDetachedWithContents:(TabContents*)contents |
| 69 atIndex:(NSInteger)index; | 68 atIndex:(NSInteger)index; |
| 70 - (void)activateTabWithContents:(TabContentsWrapper*)newContents | 69 - (void)activateTabWithContents:(TabContents*)newContents |
| 71 previousContents:(TabContentsWrapper*)oldContents | 70 previousContents:(TabContents*)oldContents |
| 72 atIndex:(NSInteger)index | 71 atIndex:(NSInteger)index |
| 73 userGesture:(bool)wasUserGesture; | 72 userGesture:(bool)wasUserGesture; |
| 74 - (void)tabMovedWithContents:(TabContentsWrapper*)contents | 73 - (void)tabMovedWithContents:(TabContents*)contents |
| 75 fromIndex:(NSInteger)from | 74 fromIndex:(NSInteger)from |
| 76 toIndex:(NSInteger)to; | 75 toIndex:(NSInteger)to; |
| 77 - (void)tabChangedWithContents:(TabContentsWrapper*)contents | 76 - (void)tabChangedWithContents:(TabContents*)contents |
| 78 atIndex:(NSInteger)index | 77 atIndex:(NSInteger)index |
| 79 changeType:(TabStripModelObserver::TabChangeType)change; | 78 changeType:(TabStripModelObserver::TabChangeType)change; |
| 80 - (void)tabReplacedWithContents:(TabContentsWrapper*)newContents | 79 - (void)tabReplacedWithContents:(TabContents*)newContents |
| 81 previousContents:(TabContentsWrapper*)oldContents | 80 previousContents:(TabContents*)oldContents |
| 82 atIndex:(NSInteger)index; | 81 atIndex:(NSInteger)index; |
| 83 - (void)tabMiniStateChangedWithContents:(TabContentsWrapper*)contents | 82 - (void)tabMiniStateChangedWithContents:(TabContents*)contents |
| 84 atIndex:(NSInteger)index; | 83 atIndex:(NSInteger)index; |
| 85 - (void)tabStripEmpty; | 84 - (void)tabStripEmpty; |
| 86 - (void)tabStripModelDeleted; | 85 - (void)tabStripModelDeleted; |
| 87 @end | 86 @end |
| 88 | 87 |
| 89 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_ | 88 #endif // CHROME_BROWSER_UI_COCOA_TABS_TAB_STRIP_MODEL_OBSERVER_BRIDGE_H_ |
| OLD | NEW |