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

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

Issue 2699833004: Add WebStateListOrderController to control WebState insertion. (Closed)
Patch Set: Created 3 years, 10 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 #import "ios/shared/chrome/browser/tabs/web_state_list.h" 5 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h" 11 #import "ios/shared/chrome/browser/tabs/web_state_list_observer.h"
12 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h"
12 #import "ios/web/public/navigation_manager.h" 13 #import "ios/web/public/navigation_manager.h"
13 #import "ios/web/public/web_state/web_state.h" 14 #import "ios/web/public/web_state/web_state.h"
14 15
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 17 #error "This file requires ARC support."
17 #endif 18 #endif
18 19
19 // Wrapper around a WebState stored in a WebStateList. May own the WebState 20 // Wrapper around a WebState stored in a WebStateList. May own the WebState
20 // dependending on the WebStateList ownership setting (should always be true 21 // dependending on the WebStateList ownership setting (should always be true
21 // once ownership of Tab is sane, see http://crbug.com/546222 for progress). 22 // once ownership of Tab is sane, see http://crbug.com/546222 for progress).
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 if (opener_ != opener) 89 if (opener_ != opener)
89 return false; 90 return false;
90 91
91 if (!use_group) 92 if (!use_group)
92 return true; 93 return true;
93 94
94 return opener_last_committed_index_ == opener_navigation_index; 95 return opener_last_committed_index_ == opener_navigation_index;
95 } 96 }
96 97
97 WebStateList::WebStateList(WebStateOwnership ownership) 98 WebStateList::WebStateList(WebStateOwnership ownership)
98 : web_state_ownership_(ownership) {} 99 : web_state_ownership_(ownership),
100 order_controller_(base::MakeUnique<WebStateListOrderController>(this)) {}
99 101
100 WebStateList::~WebStateList() = default; 102 WebStateList::~WebStateList() = default;
101 103
102 bool WebStateList::ContainsIndex(int index) const { 104 bool WebStateList::ContainsIndex(int index) const {
103 return 0 <= index && index < count(); 105 return 0 <= index && index < count();
104 } 106 }
105 107
106 web::WebState* WebStateList::GetWebStateAt(int index) const { 108 web::WebState* WebStateList::GetWebStateAt(int index) const {
107 DCHECK(ContainsIndex(index)); 109 DCHECK(ContainsIndex(index));
108 return web_state_wrappers_[index]->web_state(); 110 return web_state_wrappers_[index]->web_state();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 base::MakeUnique<WebStateWrapper>(web_state, 144 base::MakeUnique<WebStateWrapper>(web_state,
143 web_state_ownership_ == WebStateOwned)); 145 web_state_ownership_ == WebStateOwned));
144 146
145 if (opener) 147 if (opener)
146 SetOpenerOfWebStateAt(index, opener); 148 SetOpenerOfWebStateAt(index, opener);
147 149
148 for (auto& observer : observers_) 150 for (auto& observer : observers_)
149 observer.WebStateInsertedAt(this, web_state, index); 151 observer.WebStateInsertedAt(this, web_state, index);
150 } 152 }
151 153
154 void WebStateList::AddWebState(int index,
155 ui::PageTransition transition,
156 web::WebState* web_state,
157 web::WebState* opener) {
158 if (PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_LINK)) {
159 // Assume WebStates opened via link clicks are part of the same "task" as
160 // their parent and are grouped together, unless the index is forced.
161 if (index == kInvalidIndex)
marq (ping after 24h) 2017/02/17 13:33:00 The header says to pass kInvalidIndex to have the
sdefresne 2017/02/20 16:12:56 Addressed.
162 index = order_controller_->DetermineInsertionIndex(transition, opener);
163 }
164
165 if (index < 0 || count() < index)
166 index = count();
167
168 if (PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_TYPED)) {
169 // Also, any WebState opened at the end of the WebStateList with a "TYPED"
170 // transition inherit groups as well. This covers the cases where the user
171 // creats a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types
rohitrao (ping after 24h) 2017/02/17 13:04:12 creates
sdefresne 2017/02/20 16:12:56 Removed.
172 // in the address bar and presses Alt+Enter. This allows for opening a new
173 // Tab to quickly look up something. When this Tab is closed, the old one
marq (ping after 24h) 2017/02/17 13:33:00 Nit: do we need a comment in our iOS code that des
sdefresne 2017/02/20 16:12:56 Removed.
174 // is re-selected, not the next-adjacent.
175 // TODO(crbug.com/661988): Make this work.
176 }
177
178 InsertWebState(index, web_state, opener);
179 }
180
152 void WebStateList::MoveWebStateAt(int from_index, int to_index) { 181 void WebStateList::MoveWebStateAt(int from_index, int to_index) {
153 DCHECK(ContainsIndex(from_index)); 182 DCHECK(ContainsIndex(from_index));
154 DCHECK(ContainsIndex(to_index)); 183 DCHECK(ContainsIndex(to_index));
155 if (from_index == to_index) 184 if (from_index == to_index)
156 return; 185 return;
157 186
158 std::unique_ptr<WebStateWrapper> web_state_wrapper = 187 std::unique_ptr<WebStateWrapper> web_state_wrapper =
159 std::move(web_state_wrappers_[from_index]); 188 std::move(web_state_wrappers_[from_index]);
160 web::WebState* web_state = web_state_wrapper->web_state(); 189 web::WebState* web_state = web_state_wrapper->web_state();
161 web_state_wrappers_.erase(web_state_wrappers_.begin() + from_index); 190 web_state_wrappers_.erase(web_state_wrappers_.begin() + from_index);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } else if (found_index != kInvalidIndex) { 266 } else if (found_index != kInvalidIndex) {
238 return found_index; 267 return found_index;
239 } 268 }
240 } 269 }
241 270
242 return found_index; 271 return found_index;
243 } 272 }
244 273
245 // static 274 // static
246 const int WebStateList::kInvalidIndex; 275 const int WebStateList::kInvalidIndex;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698