OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 5 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 using base::UserMetricsAction; | 29 using base::UserMetricsAction; |
30 using content::WebContents; | 30 using content::WebContents; |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Returns true if the specified transition is one of the types that cause the | 34 // Returns true if the specified transition is one of the types that cause the |
35 // opener relationships for the tab in which the transition occurred to be | 35 // opener relationships for the tab in which the transition occurred to be |
36 // forgotten. This is generally any navigation that isn't a link click (i.e. | 36 // forgotten. This is generally any navigation that isn't a link click (i.e. |
37 // any navigation that can be considered to be the start of a new task distinct | 37 // any navigation that can be considered to be the start of a new task distinct |
38 // from what had previously occurred in that tab). | 38 // from what had previously occurred in that tab). |
39 bool ShouldForgetOpenersForTransition(content::PageTransition transition) { | 39 bool ShouldForgetOpenersForTransition(ui::PageTransition transition) { |
40 return transition == content::PAGE_TRANSITION_TYPED || | 40 return transition == ui::PAGE_TRANSITION_TYPED || |
41 transition == content::PAGE_TRANSITION_AUTO_BOOKMARK || | 41 transition == ui::PAGE_TRANSITION_AUTO_BOOKMARK || |
42 transition == content::PAGE_TRANSITION_GENERATED || | 42 transition == ui::PAGE_TRANSITION_GENERATED || |
43 transition == content::PAGE_TRANSITION_KEYWORD || | 43 transition == ui::PAGE_TRANSITION_KEYWORD || |
44 transition == content::PAGE_TRANSITION_AUTO_TOPLEVEL; | 44 transition == ui::PAGE_TRANSITION_AUTO_TOPLEVEL; |
45 } | 45 } |
46 | 46 |
47 // CloseTracker is used when closing a set of WebContents. It listens for | 47 // CloseTracker is used when closing a set of WebContents. It listens for |
48 // deletions of the WebContents and removes from the internal set any time one | 48 // deletions of the WebContents and removes from the internal set any time one |
49 // is deleted. | 49 // is deleted. |
50 class CloseTracker { | 50 class CloseTracker { |
51 public: | 51 public: |
52 typedef std::vector<WebContents*> Contents; | 52 typedef std::vector<WebContents*> Contents; |
53 | 53 |
54 explicit CloseTracker(const Contents& contents); | 54 explicit CloseTracker(const Contents& contents); |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 DCHECK(ContainsIndex(start_index)); | 598 DCHECK(ContainsIndex(start_index)); |
599 | 599 |
600 for (int i = contents_data_.size() - 1; i > start_index; --i) { | 600 for (int i = contents_data_.size() - 1; i > start_index; --i) { |
601 if (contents_data_[i]->opener() == opener) | 601 if (contents_data_[i]->opener() == opener) |
602 return i; | 602 return i; |
603 } | 603 } |
604 return kNoTab; | 604 return kNoTab; |
605 } | 605 } |
606 | 606 |
607 void TabStripModel::TabNavigating(WebContents* contents, | 607 void TabStripModel::TabNavigating(WebContents* contents, |
608 content::PageTransition transition) { | 608 ui::PageTransition transition) { |
609 if (ShouldForgetOpenersForTransition(transition)) { | 609 if (ShouldForgetOpenersForTransition(transition)) { |
610 // Don't forget the openers if this tab is a New Tab page opened at the | 610 // Don't forget the openers if this tab is a New Tab page opened at the |
611 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one | 611 // end of the TabStrip (e.g. by pressing Ctrl+T). Give the user one |
612 // navigation of one of these transition types before resetting the | 612 // navigation of one of these transition types before resetting the |
613 // opener relationships (this allows for the use case of opening a new | 613 // opener relationships (this allows for the use case of opening a new |
614 // tab to do a quick look-up of something while viewing a tab earlier in | 614 // tab to do a quick look-up of something while viewing a tab earlier in |
615 // the strip). We can make this heuristic more permissive if need be. | 615 // the strip). We can make this heuristic more permissive if need be. |
616 if (!IsNewTabAtEndOfTabStrip(contents)) { | 616 if (!IsNewTabAtEndOfTabStrip(contents)) { |
617 // If the user navigates the current tab to another page in any way | 617 // If the user navigates the current tab to another page in any way |
618 // other than by clicking a link, we want to pro-actively forget all | 618 // other than by clicking a link, we want to pro-actively forget all |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 } | 776 } |
777 | 777 |
778 void TabStripModel::SetSelectionFromModel( | 778 void TabStripModel::SetSelectionFromModel( |
779 const ui::ListSelectionModel& source) { | 779 const ui::ListSelectionModel& source) { |
780 DCHECK_NE(ui::ListSelectionModel::kUnselectedIndex, source.active()); | 780 DCHECK_NE(ui::ListSelectionModel::kUnselectedIndex, source.active()); |
781 SetSelection(source, NOTIFY_DEFAULT); | 781 SetSelection(source, NOTIFY_DEFAULT); |
782 } | 782 } |
783 | 783 |
784 void TabStripModel::AddWebContents(WebContents* contents, | 784 void TabStripModel::AddWebContents(WebContents* contents, |
785 int index, | 785 int index, |
786 content::PageTransition transition, | 786 ui::PageTransition transition, |
787 int add_types) { | 787 int add_types) { |
788 // If the newly-opened tab is part of the same task as the parent tab, we want | 788 // If the newly-opened tab is part of the same task as the parent tab, we want |
789 // to inherit the parent's "group" attribute, so that if this tab is then | 789 // to inherit the parent's "group" attribute, so that if this tab is then |
790 // closed we'll jump back to the parent tab. | 790 // closed we'll jump back to the parent tab. |
791 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; | 791 bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; |
792 | 792 |
793 if (transition == content::PAGE_TRANSITION_LINK && | 793 if (transition == ui::PAGE_TRANSITION_LINK && |
794 (add_types & ADD_FORCE_INDEX) == 0) { | 794 (add_types & ADD_FORCE_INDEX) == 0) { |
795 // We assume tabs opened via link clicks are part of the same task as their | 795 // We assume tabs opened via link clicks are part of the same task as their |
796 // parent. Note that when |force_index| is true (e.g. when the user | 796 // parent. Note that when |force_index| is true (e.g. when the user |
797 // drag-and-drops a link to the tab strip), callers aren't really handling | 797 // drag-and-drops a link to the tab strip), callers aren't really handling |
798 // link clicks, they just want to score the navigation like a link click in | 798 // link clicks, they just want to score the navigation like a link click in |
799 // the history backend, so we don't inherit the group in this case. | 799 // the history backend, so we don't inherit the group in this case. |
800 index = order_controller_->DetermineInsertionIndex(transition, | 800 index = order_controller_->DetermineInsertionIndex(transition, |
801 add_types & ADD_ACTIVE); | 801 add_types & ADD_ACTIVE); |
802 inherit_group = true; | 802 inherit_group = true; |
803 } else { | 803 } else { |
804 // For all other types, respect what was passed to us, normalizing -1s and | 804 // For all other types, respect what was passed to us, normalizing -1s and |
805 // values that are too large. | 805 // values that are too large. |
806 if (index < 0 || index > count()) | 806 if (index < 0 || index > count()) |
807 index = count(); | 807 index = count(); |
808 } | 808 } |
809 | 809 |
810 if (transition == content::PAGE_TRANSITION_TYPED && index == count()) { | 810 if (transition == ui::PAGE_TRANSITION_TYPED && index == count()) { |
811 // Also, any tab opened at the end of the TabStrip with a "TYPED" | 811 // Also, any tab opened at the end of the TabStrip with a "TYPED" |
812 // transition inherit group as well. This covers the cases where the user | 812 // transition inherit group as well. This covers the cases where the user |
813 // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types | 813 // creates a New Tab (e.g. Ctrl+T, or clicks the New Tab button), or types |
814 // in the address bar and presses Alt+Enter. This allows for opening a new | 814 // in the address bar and presses Alt+Enter. This allows for opening a new |
815 // Tab to quickly look up something. When this Tab is closed, the old one | 815 // Tab to quickly look up something. When this Tab is closed, the old one |
816 // is re-selected, not the next-adjacent. | 816 // is re-selected, not the next-adjacent. |
817 inherit_group = true; | 817 inherit_group = true; |
818 } | 818 } |
819 InsertWebContentsAt(index, contents, | 819 InsertWebContentsAt(index, contents, |
820 add_types | (inherit_group ? ADD_INHERIT_GROUP : 0)); | 820 add_types | (inherit_group ? ADD_INHERIT_GROUP : 0)); |
821 // Reset the index, just in case insert ended up moving it on us. | 821 // Reset the index, just in case insert ended up moving it on us. |
822 index = GetIndexOfWebContents(contents); | 822 index = GetIndexOfWebContents(contents); |
823 | 823 |
824 if (inherit_group && transition == content::PAGE_TRANSITION_TYPED) | 824 if (inherit_group && transition == ui::PAGE_TRANSITION_TYPED) |
825 contents_data_[index]->set_reset_group_on_select(true); | 825 contents_data_[index]->set_reset_group_on_select(true); |
826 | 826 |
827 // TODO(sky): figure out why this is here and not in InsertWebContentsAt. When | 827 // TODO(sky): figure out why this is here and not in InsertWebContentsAt. When |
828 // here we seem to get failures in startup perf tests. | 828 // here we seem to get failures in startup perf tests. |
829 // Ensure that the new WebContentsView begins at the same size as the | 829 // Ensure that the new WebContentsView begins at the same size as the |
830 // previous WebContentsView if it existed. Otherwise, the initial WebKit | 830 // previous WebContentsView if it existed. Otherwise, the initial WebKit |
831 // layout will be performed based on a width of 0 pixels, causing a | 831 // layout will be performed based on a width of 0 pixels, causing a |
832 // very long, narrow, inaccurate layout. Because some scripts on pages (as | 832 // very long, narrow, inaccurate layout. Because some scripts on pages (as |
833 // well as WebKit's anchor link location calculation) are run on the | 833 // well as WebKit's anchor link location calculation) are run on the |
834 // initial layout and not recalculated later, we need to ensure the first | 834 // initial layout and not recalculated later, we need to ensure the first |
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 void TabStripModel::ForgetOpenersAndGroupsReferencing( | 1405 void TabStripModel::ForgetOpenersAndGroupsReferencing( |
1406 const WebContents* tab) { | 1406 const WebContents* tab) { |
1407 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); | 1407 for (WebContentsDataVector::const_iterator i = contents_data_.begin(); |
1408 i != contents_data_.end(); ++i) { | 1408 i != contents_data_.end(); ++i) { |
1409 if ((*i)->group() == tab) | 1409 if ((*i)->group() == tab) |
1410 (*i)->set_group(NULL); | 1410 (*i)->set_group(NULL); |
1411 if ((*i)->opener() == tab) | 1411 if ((*i)->opener() == tab) |
1412 (*i)->set_opener(NULL); | 1412 (*i)->set_opener(NULL); |
1413 } | 1413 } |
1414 } | 1414 } |
OLD | NEW |