| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/web/navigation/crw_session_controller.h" | 5 #import "ios/web/navigation/crw_session_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 std::swap(mergedItems, _items); | 534 std::swap(mergedItems, _items); |
| 535 | 535 |
| 536 // Update state to reflect inserted NavigationItems. | 536 // Update state to reflect inserted NavigationItems. |
| 537 _previousItemIndex = -1; | 537 _previousItemIndex = -1; |
| 538 _lastCommittedItemIndex = self.items.size() - 1; | 538 _lastCommittedItemIndex = self.items.size() - 1; |
| 539 | 539 |
| 540 DCHECK_LT(static_cast<NSUInteger>(_lastCommittedItemIndex), | 540 DCHECK_LT(static_cast<NSUInteger>(_lastCommittedItemIndex), |
| 541 self.items.size()); | 541 self.items.size()); |
| 542 } | 542 } |
| 543 | 543 |
| 544 - (void)goToItemAtIndex:(NSInteger)index { | 544 - (void)goToItemAtIndex:(NSInteger)index |
| 545 discardNonCommittedItems:(BOOL)discard { |
| 545 if (index < 0 || static_cast<NSUInteger>(index) >= self.items.size()) | 546 if (index < 0 || static_cast<NSUInteger>(index) >= self.items.size()) |
| 546 return; | 547 return; |
| 547 | 548 |
| 548 if (index < _lastCommittedItemIndex) { | 549 if (index == _lastCommittedItemIndex) { |
| 549 // Going back. | 550 // |delta| is 0, no need to change current navigation index. |
| 550 [self discardNonCommittedItems]; | |
| 551 } else if (_lastCommittedItemIndex < index) { | |
| 552 // Going forward. | |
| 553 [self discardTransientItem]; | |
| 554 } else { | |
| 555 // |delta| is 0, no need to change the last committed item index. | |
| 556 return; | 551 return; |
| 557 } | 552 } |
| 558 | 553 |
| 554 if (discard) { |
| 555 if (index < _lastCommittedItemIndex) { |
| 556 // Going back. |
| 557 [self discardNonCommittedItems]; |
| 558 } else if (_lastCommittedItemIndex < index) { |
| 559 // Going forward. |
| 560 [self discardTransientItem]; |
| 561 } |
| 562 } |
| 563 |
| 559 _previousItemIndex = _lastCommittedItemIndex; | 564 _previousItemIndex = _lastCommittedItemIndex; |
| 560 _lastCommittedItemIndex = index; | 565 _lastCommittedItemIndex = index; |
| 561 } | 566 } |
| 562 | 567 |
| 563 - (void)removeItemAtIndex:(NSInteger)index { | 568 - (void)removeItemAtIndex:(NSInteger)index { |
| 564 DCHECK(index < static_cast<NSInteger>(self.items.size())); | 569 DCHECK(index < static_cast<NSInteger>(self.items.size())); |
| 565 DCHECK(index != _lastCommittedItemIndex); | 570 DCHECK(index != _lastCommittedItemIndex); |
| 566 DCHECK(index >= 0); | 571 DCHECK(index >= 0); |
| 567 | 572 |
| 568 [self discardNonCommittedItems]; | 573 [self discardNonCommittedItems]; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 return item; | 657 return item; |
| 653 } | 658 } |
| 654 | 659 |
| 655 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { | 660 - (BOOL)isRedirectTransitionForItemAtIndex:(size_t)index { |
| 656 DCHECK_LT(index, self.items.size()); | 661 DCHECK_LT(index, self.items.size()); |
| 657 ui::PageTransition transition = self.items[index]->GetTransitionType(); | 662 ui::PageTransition transition = self.items[index]->GetTransitionType(); |
| 658 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; | 663 return (transition & ui::PAGE_TRANSITION_IS_REDIRECT_MASK) ? YES : NO; |
| 659 } | 664 } |
| 660 | 665 |
| 661 @end | 666 @end |
| OLD | NEW |