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

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

Issue 2699833004: Add WebStateListOrderController to control WebState insertion. (Closed)
Patch Set: Address comments. 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
(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 #import "ios/shared/chrome/browser/tabs/web_state_list_order_controller.h"
6
7 #include <cstdint>
8
9 #include "base/logging.h"
10 #import "ios/shared/chrome/browser/tabs/web_state_list.h"
11
12 WebStateListOrderController::WebStateListOrderController(
13 WebStateList* web_state_list)
14 : web_state_list_(web_state_list) {
15 DCHECK(web_state_list_);
16 }
17
18 WebStateListOrderController::~WebStateListOrderController() = default;
19
20 int WebStateListOrderController::DetermineInsertionIndex(
21 ui::PageTransition transition,
22 web::WebState* opener) const {
23 if (!opener)
24 return web_state_list_->count();
25
26 if (!PageTransitionCoreTypeIs(transition, ui::PAGE_TRANSITION_LINK))
27 return web_state_list_->count();
28
29 int opener_index = web_state_list_->GetIndexOfWebState(opener);
30 DCHECK_NE(WebStateList::kInvalidIndex, opener_index);
31
32 int list_child_index = web_state_list_->GetIndexOfLastWebStateOpenedBy(
33 opener, opener_index, true);
34
35 int reference_index = list_child_index != WebStateList::kInvalidIndex
36 ? list_child_index
37 : opener_index;
38
39 // Check for overflows (just a DCHECK as INT_MAX open WebState is unlikely).
40 DCHECK_LT(reference_index, INT_MAX);
41 return reference_index + 1;
42 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698