OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |
| 6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |
| 7 |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" |
| 12 |
| 13 // Protocol that correspond to WebStateListObserver API. Allows registering |
| 14 // Objective-C objects to listen to WebStateList events. |
| 15 @protocol WebStateListObserving<NSObject> |
| 16 |
| 17 @optional |
| 18 |
| 19 // Invoked after a new WebState has been added to the WebStateList at the |
| 20 // specified index. |
| 21 - (void)webStateList:(WebStateList*)webStateList |
| 22 didInsertWebState:(web::WebState*)webState |
| 23 atIndex:(int)index; |
| 24 |
| 25 // Invoked after the WebState at the specified index is moved to another index. |
| 26 - (void)webStateList:(WebStateList*)webStateList |
| 27 didMoveWebState:(web::WebState*)webState |
| 28 fromIndex:(int)fromIndex |
| 29 toIndex:(int)toIndex; |
| 30 |
| 31 // Invoked after the WebState at the specified index is replaced by another |
| 32 // WebState. |
| 33 - (void)webStateList:(WebStateList*)webStateList |
| 34 didReplaceWebState:(web::WebState*)oldWebState |
| 35 withWebState:(web::WebState*)newWebState |
| 36 atIndex:(int)index; |
| 37 |
| 38 // Invoked after the WebState at the specified index has been detached. The |
| 39 // WebState is still valid but is no longer in the WebStateList. |
| 40 - (void)webStateList:(WebStateList*)webStateList |
| 41 didDetachWebState:(web::WebState*)webState |
| 42 atIndex:(int)index; |
| 43 |
| 44 @end |
| 45 |
| 46 // Observer that bridges WebStateList events to an Objective-C observer that |
| 47 // implements the WebStateListObserver protocol (the observer is owned). |
| 48 class WebStateListObserverBridge : public WebStateListObserver { |
| 49 public: |
| 50 explicit WebStateListObserverBridge(id<WebStateListObserving> observer); |
| 51 ~WebStateListObserverBridge() override; |
| 52 |
| 53 private: |
| 54 // WebStateListObserver implementation. |
| 55 void WebStateInsertedAt(WebStateList* web_state_list, |
| 56 web::WebState* web_state, |
| 57 int index) override; |
| 58 void WebStateMoved(WebStateList* web_state_list, |
| 59 web::WebState* web_state, |
| 60 int from_index, |
| 61 int to_index) override; |
| 62 void WebStateReplacedAt(WebStateList* web_state_list, |
| 63 web::WebState* old_web_state, |
| 64 web::WebState* new_web_state, |
| 65 int index) override; |
| 66 void WebStateDetachedAt(WebStateList* web_state_list, |
| 67 web::WebState* web_state, |
| 68 int index) override; |
| 69 |
| 70 id<WebStateListObserving> observer_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(WebStateListObserverBridge); |
| 73 }; |
| 74 |
| 75 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_OBSERVER_BRIDGE_H_ |
OLD | NEW |