| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/tabs/tab_strip_model.h" | 5 #include "chrome/browser/tabs/tab_strip_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "content/browser/user_metrics.h" | 33 #include "content/browser/user_metrics.h" |
| 34 #include "content/common/notification_service.h" | 34 #include "content/common/notification_service.h" |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // Returns true if the specified transition is one of the types that cause the | 38 // Returns true if the specified transition is one of the types that cause the |
| 39 // opener relationships for the tab in which the transition occured to be | 39 // opener relationships for the tab in which the transition occured to be |
| 40 // forgotten. This is generally any navigation that isn't a link click (i.e. | 40 // forgotten. This is generally any navigation that isn't a link click (i.e. |
| 41 // any navigation that can be considered to be the start of a new task distinct | 41 // any navigation that can be considered to be the start of a new task distinct |
| 42 // from what had previously occurred in that tab). | 42 // from what had previously occurred in that tab). |
| 43 bool ShouldForgetOpenersForTransition(PageTransition::Type transition) { | 43 bool ShouldForgetOpenersForTransition(content::PageTransition transition) { |
| 44 return transition == PageTransition::TYPED || | 44 return transition == content::PAGE_TRANSITION_TYPED || |
| 45 transition == PageTransition::AUTO_BOOKMARK || | 45 transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || |
| 46 transition == PageTransition::GENERATED || | 46 transition == content::PAGE_TRANSITION_GENERATED || |
| 47 transition == PageTransition::KEYWORD || | 47 transition == content::PAGE_TRANSITION_KEYWORD || |
| 48 transition == PageTransition::START_PAGE; | 48 transition == content::PAGE_TRANSITION_START_PAGE; |
| 49 } | 49 } |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 /////////////////////////////////////////////////////////////////////////////// | 53 /////////////////////////////////////////////////////////////////////////////// |
| 54 // TabStripModelDelegate, public: | 54 // TabStripModelDelegate, public: |
| 55 | 55 |
| 56 bool TabStripModelDelegate::CanCloseTab() const { | 56 bool TabStripModelDelegate::CanCloseTab() const { |
| 57 return true; | 57 return true; |
| 58 } | 58 } |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 next = iter - 1; | 473 next = iter - 1; |
| 474 if (next == end) | 474 if (next == end) |
| 475 break; | 475 break; |
| 476 if ((*next)->opener == opener) | 476 if ((*next)->opener == opener) |
| 477 return static_cast<int>(next - contents_data_.begin()); | 477 return static_cast<int>(next - contents_data_.begin()); |
| 478 } | 478 } |
| 479 return kNoTab; | 479 return kNoTab; |
| 480 } | 480 } |
| 481 | 481 |
| 482 void TabStripModel::TabNavigating(TabContentsWrapper* contents, | 482 void TabStripModel::TabNavigating(TabContentsWrapper* contents, |
| 483 PageTransition::Type transition) { | 483 content::PageTransition transition) { |
| 484 if (ShouldForgetOpenersForTransition(transition)) { | 484 if (ShouldForgetOpenersForTransition(transition)) { |
| 485 // Don't forget the openers if this tab is a New Tab page opened at the | 485 // Don't forget the openers if this tab is a New Tab page opened at the |
| 486 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one | 486 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one |
| 487 // navigation of one of these transition types before resetting the | 487 // navigation of one of these transition types before resetting the |
| 488 // opener relationships (this allows for the use case of opening a new | 488 // opener relationships (this allows for the use case of opening a new |
| 489 // tab to do a quick look-up of something while viewing a tab earlier in | 489 // tab to do a quick look-up of something while viewing a tab earlier in |
| 490 // the strip). We can make this heuristic more permissive if need be. | 490 // the strip). We can make this heuristic more permissive if need be. |
| 491 if (!IsNewTabAtEndOfTabStrip(contents)) { | 491 if (!IsNewTabAtEndOfTabStrip(contents)) { |
| 492 // If the user navigates the current tab to another page in any way | 492 // If the user navigates the current tab to another page in any way |
| 493 // other than by clicking a link, we want to pro-actively forget all | 493 // other than by clicking a link, we want to pro-actively forget all |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 DCHECK_NE(TabStripSelectionModel::kUnselectedIndex, source.active()); | 658 DCHECK_NE(TabStripSelectionModel::kUnselectedIndex, source.active()); |
| 659 TabContentsWrapper* old_contents = GetActiveTabContents(); | 659 TabContentsWrapper* old_contents = GetActiveTabContents(); |
| 660 TabStripSelectionModel old_model; | 660 TabStripSelectionModel old_model; |
| 661 old_model.Copy(selection_model()); | 661 old_model.Copy(selection_model()); |
| 662 selection_model_.Copy(source); | 662 selection_model_.Copy(source); |
| 663 NotifyIfActiveOrSelectionChanged(old_contents, false, old_model); | 663 NotifyIfActiveOrSelectionChanged(old_contents, false, old_model); |
| 664 } | 664 } |
| 665 | 665 |
| 666 void TabStripModel::AddTabContents(TabContentsWrapper* contents, | 666 void TabStripModel::AddTabContents(TabContentsWrapper* contents, |
| 667 int index, | 667 int index, |
| 668 PageTransition::Type transition, | 668 content::PageTransition transition, |
| 669 int add_types) { | 669 int add_types) { |
| 670 // If the newly-opened tab is part of the same task as the parent tab, we want | 670 // If the newly-opened tab is part of the same task as the parent tab, we want |
| 671 // to inherit the parent's "group" attribute, so that if this tab is then | 671 // to inherit the parent's "group" attribute, so that if this tab is then |
| 672 // closed we'll jump back to the parent tab. | 672 // closed we'll jump back to the parent tab. |
| 673 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; | 673 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; |
| 674 | 674 |
| 675 if (transition == PageTransition::LINK && | 675 if (transition == content::PAGE_TRANSITION_LINK && |
| 676 (add_types & ADD_FORCE_INDEX) == 0) { | 676 (add_types & ADD_FORCE_INDEX) == 0) { |
| 677 // We assume tabs opened via link clicks are part of the same task as their | 677 // We assume tabs opened via link clicks are part of the same task as their |
| 678 // parent. Note that when |force_index| is true (e.g. when the user | 678 // parent. Note that when |force_index| is true (e.g. when the user |
| 679 // drag-and-drops a link to the tab strip), callers aren't really handling | 679 // drag-and-drops a link to the tab strip), callers aren't really handling |
| 680 // link clicks, they just want to score the navigation like a link click in | 680 // link clicks, they just want to score the navigation like a link click in |
| 681 // the history backend, so we don't inherit the group in this case. | 681 // the history backend, so we don't inherit the group in this case. |
| 682 index = order_controller_->DetermineInsertionIndex( | 682 index = order_controller_->DetermineInsertionIndex( |
| 683 contents, transition, add_types & ADD_ACTIVE); | 683 contents, transition, add_types & ADD_ACTIVE); |
| 684 inherit_group = true; | 684 inherit_group = true; |
| 685 } else { | 685 } else { |
| 686 // For all other types, respect what was passed to us, normalizing -1s and | 686 // For all other types, respect what was passed to us, normalizing -1s and |
| 687 // values that are too large. | 687 // values that are too large. |
| 688 if (index < 0 || index > count()) | 688 if (index < 0 || index > count()) |
| 689 index = order_controller_->DetermineInsertionIndexForAppending(); | 689 index = order_controller_->DetermineInsertionIndexForAppending(); |
| 690 } | 690 } |
| 691 | 691 |
| 692 if (transition == PageTransition::TYPED && index == count()) { | 692 if (transition == content::PAGE_TRANSITION_TYPED && index == count()) { |
| 693 // Also, any tab opened at the end of the TabStrip with a "TYPED" | 693 // Also, any tab opened at the end of the TabStrip with a "TYPED" |
| 694 // transition inherit group as well. This covers the cases where the user | 694 // transition inherit group as well. This covers the cases where the user |
| 695 // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types | 695 // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types |
| 696 // in the address bar and presses Alt+Enter. This allows for opening a new | 696 // in the address bar and presses Alt+Enter. This allows for opening a new |
| 697 // Tab to quickly look up something. When this Tab is closed, the old one | 697 // Tab to quickly look up something. When this Tab is closed, the old one |
| 698 // is re-selected, not the next-adjacent. | 698 // is re-selected, not the next-adjacent. |
| 699 inherit_group = true; | 699 inherit_group = true; |
| 700 } | 700 } |
| 701 InsertTabContentsAt( | 701 InsertTabContentsAt( |
| 702 index, contents, | 702 index, contents, |
| 703 add_types | (inherit_group ? ADD_INHERIT_GROUP : 0)); | 703 add_types | (inherit_group ? ADD_INHERIT_GROUP : 0)); |
| 704 // Reset the index, just in case insert ended up moving it on us. | 704 // Reset the index, just in case insert ended up moving it on us. |
| 705 index = GetIndexOfTabContents(contents); | 705 index = GetIndexOfTabContents(contents); |
| 706 | 706 |
| 707 if (inherit_group && transition == PageTransition::TYPED) | 707 if (inherit_group && transition == content::PAGE_TRANSITION_TYPED) |
| 708 contents_data_.at(index)->reset_group_on_select = true; | 708 contents_data_.at(index)->reset_group_on_select = true; |
| 709 | 709 |
| 710 // TODO(sky): figure out why this is here and not in InsertTabContentsAt. When | 710 // TODO(sky): figure out why this is here and not in InsertTabContentsAt. When |
| 711 // here we seem to get failures in startup perf tests. | 711 // here we seem to get failures in startup perf tests. |
| 712 // Ensure that the new TabContentsView begins at the same size as the | 712 // Ensure that the new TabContentsView begins at the same size as the |
| 713 // previous TabContentsView if it existed. Otherwise, the initial WebKit | 713 // previous TabContentsView if it existed. Otherwise, the initial WebKit |
| 714 // layout will be performed based on a width of 0 pixels, causing a | 714 // layout will be performed based on a width of 0 pixels, causing a |
| 715 // very long, narrow, inaccurate layout. Because some scripts on pages (as | 715 // very long, narrow, inaccurate layout. Because some scripts on pages (as |
| 716 // well as WebKit's anchor link location calculation) are run on the | 716 // well as WebKit's anchor link location calculation) are run on the |
| 717 // initial layout and not recalculated later, we need to ensure the first | 717 // initial layout and not recalculated later, we need to ensure the first |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1318 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1318 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
| 1319 const NavigationController* tab) { | 1319 const NavigationController* tab) { |
| 1320 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); | 1320 for (TabContentsDataVector::const_iterator i = contents_data_.begin(); |
| 1321 i != contents_data_.end(); ++i) { | 1321 i != contents_data_.end(); ++i) { |
| 1322 if ((*i)->group == tab) | 1322 if ((*i)->group == tab) |
| 1323 (*i)->group = NULL; | 1323 (*i)->group = NULL; |
| 1324 if ((*i)->opener == tab) | 1324 if ((*i)->opener == tab) |
| 1325 (*i)->opener = NULL; | 1325 (*i)->opener = NULL; |
| 1326 } | 1326 } |
| 1327 } | 1327 } |
| OLD | NEW |