OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 5 #ifndef IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 6 #define IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); | 32 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); |
33 ~WebStateList(); | 33 ~WebStateList(); |
34 | 34 |
35 // Returns whether the model is empty or not. | 35 // Returns whether the model is empty or not. |
36 bool empty() const { return web_state_wrappers_.empty(); } | 36 bool empty() const { return web_state_wrappers_.empty(); } |
37 | 37 |
38 // Returns the number of WebStates in the model. | 38 // Returns the number of WebStates in the model. |
39 int count() const { return static_cast<int>(web_state_wrappers_.size()); } | 39 int count() const { return static_cast<int>(web_state_wrappers_.size()); } |
40 | 40 |
| 41 // Returns the index of the currently active WebState, or kInvalidIndex if |
| 42 // there are no active WebState. |
| 43 int active_index() const { return active_index_; } |
| 44 |
41 // Returns true if the specified index is contained by the model. | 45 // Returns true if the specified index is contained by the model. |
42 bool ContainsIndex(int index) const; | 46 bool ContainsIndex(int index) const; |
43 | 47 |
| 48 // Returns the currently active WebState or null if there is none. |
| 49 web::WebState* GetActiveWebState() const; |
| 50 |
44 // Returns the WebState at the specified index. It is invalid to call this | 51 // Returns the WebState at the specified index. It is invalid to call this |
45 // with an index such that |ContainsIndex(index)| returns false. | 52 // with an index such that |ContainsIndex(index)| returns false. |
46 web::WebState* GetWebStateAt(int index) const; | 53 web::WebState* GetWebStateAt(int index) const; |
47 | 54 |
48 // Returns the index of the specified WebState or kInvalidIndex if the | 55 // Returns the index of the specified WebState or kInvalidIndex if the |
49 // WebState is not in the model. | 56 // WebState is not in the model. |
50 int GetIndexOfWebState(const web::WebState* web_state) const; | 57 int GetIndexOfWebState(const web::WebState* web_state) const; |
51 | 58 |
52 // Returns the WebState that opened the WebState at the specified index or | 59 // Returns the WebState that opened the WebState at the specified index or |
53 // null if there is no opener on record. | 60 // null if there is no opener on record. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Replaces the WebState at the specified index with new WebState. Returns | 99 // Replaces the WebState at the specified index with new WebState. Returns |
93 // the old WebState at that index to the caller (abandon ownership of the | 100 // the old WebState at that index to the caller (abandon ownership of the |
94 // returned WebState). An optional opener for the new WebState may be passed. | 101 // returned WebState). An optional opener for the new WebState may be passed. |
95 web::WebState* ReplaceWebStateAt(int index, | 102 web::WebState* ReplaceWebStateAt(int index, |
96 web::WebState* web_state, | 103 web::WebState* web_state, |
97 web::WebState* opener); | 104 web::WebState* opener); |
98 | 105 |
99 // Detaches the WebState at the specified index. | 106 // Detaches the WebState at the specified index. |
100 void DetachWebStateAt(int index); | 107 void DetachWebStateAt(int index); |
101 | 108 |
| 109 // Makes the WebState at the specified index the active WebState. |
| 110 void ActivateWebStateAt(int index); |
| 111 |
102 // Adds an observer to the model. | 112 // Adds an observer to the model. |
103 void AddObserver(WebStateListObserver* observer); | 113 void AddObserver(WebStateListObserver* observer); |
104 | 114 |
105 // Removes an observer from the model. | 115 // Removes an observer from the model. |
106 void RemoveObserver(WebStateListObserver* observer); | 116 void RemoveObserver(WebStateListObserver* observer); |
107 | 117 |
108 // Invalid index. | 118 // Invalid index. |
109 static const int kInvalidIndex = -1; | 119 static const int kInvalidIndex = -1; |
110 | 120 |
111 private: | 121 private: |
112 // Sets the opener of any WebState that reference the WebState at the | 122 // Sets the opener of any WebState that reference the WebState at the |
113 // specified index to null. | 123 // specified index to null. |
114 void FixOpenersReferencing(int index); | 124 void FixOpenersReferencing(int index); |
115 | 125 |
| 126 // Notify the observers if the active WebState change. |
| 127 void NotifyIfActiveWebStateChanged(web::WebState* old_web_state, |
| 128 bool user_action); |
| 129 |
116 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of | 130 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of |
117 // WebStates opened from the specified WebState after |start_index|, or | 131 // WebStates opened from the specified WebState after |start_index|, or |
118 // kInvalidIndex if there are no such WebState. If |use_group| is true, the | 132 // kInvalidIndex if there are no such WebState. If |use_group| is true, the |
119 // opener's navigation index is used to detect navigation changes within the | 133 // opener's navigation index is used to detect navigation changes within the |
120 // same session. | 134 // same session. |
121 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, | 135 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, |
122 int start_index, | 136 int start_index, |
123 bool use_group, | 137 bool use_group, |
124 int n) const; | 138 int n) const; |
125 | 139 |
126 class WebStateWrapper; | 140 class WebStateWrapper; |
127 const WebStateOwnership web_state_ownership_; | 141 const WebStateOwnership web_state_ownership_; |
128 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; | 142 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; |
129 | 143 |
130 // An object that determines where new WebState should be inserted and where | 144 // An object that determines where new WebState should be inserted and where |
131 // selection should move when a WebState is detached. | 145 // selection should move when a WebState is detached. |
132 std::unique_ptr<WebStateListOrderController> order_controller_; | 146 std::unique_ptr<WebStateListOrderController> order_controller_; |
133 | 147 |
134 // List of observers notified of changes to the model. | 148 // List of observers notified of changes to the model. |
135 base::ObserverList<WebStateListObserver, true> observers_; | 149 base::ObserverList<WebStateListObserver, true> observers_; |
136 | 150 |
| 151 // Index of the currently active WebState, kInvalidIndex if no such WebState. |
| 152 int active_index_ = kInvalidIndex; |
| 153 |
137 DISALLOW_COPY_AND_ASSIGN(WebStateList); | 154 DISALLOW_COPY_AND_ASSIGN(WebStateList); |
138 }; | 155 }; |
139 | 156 |
140 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ | 157 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ |
OLD | NEW |