Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: ios/shared/chrome/browser/tabs/web_state_list.h

Issue 2703333006: Move the notion of current Tab from TabModel to WebStateList. (Closed)
Patch Set: Rebase. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 32
33 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed); 33 explicit WebStateList(WebStateOwnership ownership = WebStateBorrowed);
34 ~WebStateList(); 34 ~WebStateList();
35 35
36 // Returns whether the model is empty or not. 36 // Returns whether the model is empty or not.
37 bool empty() const { return web_state_wrappers_.empty(); } 37 bool empty() const { return web_state_wrappers_.empty(); }
38 38
39 // Returns the number of WebStates in the model. 39 // Returns the number of WebStates in the model.
40 int count() const { return static_cast<int>(web_state_wrappers_.size()); } 40 int count() const { return static_cast<int>(web_state_wrappers_.size()); }
41 41
42 // Returns the index of the currently active WebState, or kInvalidIndex if
43 // there are no active WebState.
44 int active_index() const { return active_index_; }
45
42 // Returns true if the specified index is contained by the model. 46 // Returns true if the specified index is contained by the model.
43 bool ContainsIndex(int index) const; 47 bool ContainsIndex(int index) const;
44 48
49 // Returns the currently active WebState or null if there is none.
50 web::WebState* GetActiveWebState() const;
51
45 // Returns the WebState at the specified index. It is invalid to call this 52 // Returns the WebState at the specified index. It is invalid to call this
46 // with an index such that |ContainsIndex(index)| returns false. 53 // with an index such that |ContainsIndex(index)| returns false.
47 web::WebState* GetWebStateAt(int index) const; 54 web::WebState* GetWebStateAt(int index) const;
48 55
49 // Returns the index of the specified WebState or kInvalidIndex if the 56 // Returns the index of the specified WebState or kInvalidIndex if the
50 // WebState is not in the model. 57 // WebState is not in the model.
51 int GetIndexOfWebState(const web::WebState* web_state) const; 58 int GetIndexOfWebState(const web::WebState* web_state) const;
52 59
53 // Returns the WebState that opened the WebState at the specified index or 60 // Returns the WebState that opened the WebState at the specified index or
54 // null if there is no opener on record. 61 // null if there is no opener on record.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // the old WebState at that index to the caller (abandon ownership of the 101 // the old WebState at that index to the caller (abandon ownership of the
95 // returned WebState). An optional opener for the new WebState may be passed. 102 // returned WebState). An optional opener for the new WebState may be passed.
96 web::WebState* ReplaceWebStateAt(int index, 103 web::WebState* ReplaceWebStateAt(int index,
97 web::WebState* web_state, 104 web::WebState* web_state,
98 web::WebState* opener) WARN_UNUSED_RESULT; 105 web::WebState* opener) WARN_UNUSED_RESULT;
99 106
100 // Detaches the WebState at the specified index. Returns the detached WebState 107 // Detaches the WebState at the specified index. Returns the detached WebState
101 // to the caller (abandon ownership of the returned WebState). 108 // to the caller (abandon ownership of the returned WebState).
102 web::WebState* DetachWebStateAt(int index) WARN_UNUSED_RESULT; 109 web::WebState* DetachWebStateAt(int index) WARN_UNUSED_RESULT;
103 110
111 // Makes the WebState at the specified index the active WebState.
112 void ActivateWebStateAt(int index);
113
104 // Adds an observer to the model. 114 // Adds an observer to the model.
105 void AddObserver(WebStateListObserver* observer); 115 void AddObserver(WebStateListObserver* observer);
106 116
107 // Removes an observer from the model. 117 // Removes an observer from the model.
108 void RemoveObserver(WebStateListObserver* observer); 118 void RemoveObserver(WebStateListObserver* observer);
109 119
110 // Invalid index. 120 // Invalid index.
111 static const int kInvalidIndex = -1; 121 static const int kInvalidIndex = -1;
112 122
113 private: 123 private:
114 // Sets the opener of any WebState that reference the WebState at the 124 // Sets the opener of any WebState that reference the WebState at the
115 // specified index to null. 125 // specified index to null.
116 void ClearOpenersReferencing(int index); 126 void ClearOpenersReferencing(int index);
117 127
128 // Notify the observers if the active WebState change.
129 void NotifyIfActiveWebStateChanged(web::WebState* old_web_state,
130 bool user_action);
131
118 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of 132 // Returns the index of the |n|-th WebState (with n > 0) in the sequence of
119 // WebStates opened from the specified WebState after |start_index|, or 133 // WebStates opened from the specified WebState after |start_index|, or
120 // kInvalidIndex if there are no such WebState. If |use_group| is true, the 134 // kInvalidIndex if there are no such WebState. If |use_group| is true, the
121 // opener's navigation index is used to detect navigation changes within the 135 // opener's navigation index is used to detect navigation changes within the
122 // same session. 136 // same session.
123 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener, 137 int GetIndexOfNthWebStateOpenedBy(const web::WebState* opener,
124 int start_index, 138 int start_index,
125 bool use_group, 139 bool use_group,
126 int n) const; 140 int n) const;
127 141
128 class WebStateWrapper; 142 class WebStateWrapper;
129 const WebStateOwnership web_state_ownership_; 143 const WebStateOwnership web_state_ownership_;
130 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_; 144 std::vector<std::unique_ptr<WebStateWrapper>> web_state_wrappers_;
131 145
132 // An object that determines where new WebState should be inserted and where 146 // An object that determines where new WebState should be inserted and where
133 // selection should move when a WebState is detached. 147 // selection should move when a WebState is detached.
134 std::unique_ptr<WebStateListOrderController> order_controller_; 148 std::unique_ptr<WebStateListOrderController> order_controller_;
135 149
136 // List of observers notified of changes to the model. 150 // List of observers notified of changes to the model.
137 base::ObserverList<WebStateListObserver, true> observers_; 151 base::ObserverList<WebStateListObserver, true> observers_;
138 152
153 // Index of the currently active WebState, kInvalidIndex if no such WebState.
154 int active_index_ = kInvalidIndex;
155
139 DISALLOW_COPY_AND_ASSIGN(WebStateList); 156 DISALLOW_COPY_AND_ASSIGN(WebStateList);
140 }; 157 };
141 158
142 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_ 159 #endif // IOS_SHARED_CHROME_BROWSER_TABS_WEB_STATE_LIST_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/browser_view_controller.mm ('k') | ios/shared/chrome/browser/tabs/web_state_list.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698