diff options
Diffstat (limited to 'chrome/browser/tabs/tab_strip_model.cc')
-rw-r--r-- | chrome/browser/tabs/tab_strip_model.cc | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/chrome/browser/tabs/tab_strip_model.cc b/chrome/browser/tabs/tab_strip_model.cc index d65e126..2245011 100644 --- a/chrome/browser/tabs/tab_strip_model.cc +++ b/chrome/browser/tabs/tab_strip_model.cc @@ -106,18 +106,18 @@ bool TabStripModel::ContainsIndex(int index) const { } void TabStripModel::AppendTabContents(TabContents* contents, bool foreground) { - // Tabs opened in the foreground using this method inherit the group of the - // previously selected tab. int index = order_controller_->DetermineInsertionIndexForAppending(); - InsertTabContentsAt(index, contents, foreground, foreground); + InsertTabContentsAt(index, contents, + foreground ? (ADD_INHERIT_GROUP | ADD_SELECTED) : + ADD_NONE); } void TabStripModel::InsertTabContentsAt(int index, TabContents* contents, - bool foreground, - bool inherit_group, - bool pinned) { - index = ConstrainInsertionIndex(index, contents->is_app() || pinned); + int add_types) { + bool foreground = add_types & ADD_SELECTED; + index = ConstrainInsertionIndex(index, contents->is_app() || + add_types & ADD_PINNED); // In tab dragging situations, if the last tab in the window was detached // then the user aborted the drag, we will have the |closing_all_| member @@ -130,8 +130,8 @@ void TabStripModel::InsertTabContentsAt(int index, // since the old contents and the new contents will be the same... TabContents* selected_contents = GetSelectedTabContents(); TabContentsData* data = new TabContentsData(contents); - data->pinned = pinned; - if (inherit_group && selected_contents) { + data->pinned = (add_types & ADD_PINNED) == ADD_PINNED; + if ((add_types & ADD_INHERIT_GROUP) && selected_contents) { if (foreground) { // Forget any existing relationships, we don't want to make things too // confusing by having multiple groups active at the same time. @@ -151,8 +151,27 @@ void TabStripModel::InsertTabContentsAt(int index, FOR_EACH_OBSERVER(TabStripModelObserver, observers_, TabInsertedAt(contents, index, foreground)); - if (foreground) { + if (foreground) ChangeSelectedContentsFrom(selected_contents, index, false); + + // Ensure that the new TabContentsView begins at the same size as the + // previous TabContentsView if it existed. Otherwise, the initial WebKit + // layout will be performed based on a width of 0 pixels, causing a + // very long, narrow, inaccurate layout. Because some scripts on pages (as + // well as WebKit's anchor link location calculation) are run on the + // initial layout and not recalculated later, we need to ensure the first + // layout is performed with sane view dimensions even when we're opening a + // new background tab. + if (!foreground) { + if (selected_contents) { + contents->view()->SizeContents( + selected_contents->view()->GetContainerSize()); + } + // We need to hide the contents or else we get and execute paints for + // background tabs. With enough background tabs they will steal the + // backing store of the visible tab causing flashing. See bug 20831. + contents->HideContents(); + contents->WasHidden(); } } @@ -161,7 +180,9 @@ void TabStripModel::ReplaceNavigationControllerAt( // This appears to be OK with no flicker since no redraw event // occurs between the call to add an aditional tab and one to close // the previous tab. - InsertTabContentsAt(index + 1, controller->tab_contents(), true, true); + InsertTabContentsAt( + index + 1, controller->tab_contents(), + TabStripModel::ADD_SELECTED | TabStripModel::ADD_INHERIT_GROUP); std::vector<int> closing_tabs; closing_tabs.push_back(index); InternalCloseTabs(closing_tabs, CLOSE_NONE); @@ -486,24 +507,24 @@ int TabStripModel::ConstrainInsertionIndex(int index, bool mini_tab) { void TabStripModel::AddTabContents(TabContents* contents, int index, - bool force_index, PageTransition::Type transition, - bool foreground) { + int add_types) { // If the newly-opened tab is part of the same task as the parent tab, we want // to inherit the parent's "group" attribute, so that if this tab is then // closed we'll jump back to the parent tab. // TODO(jbs): Perhaps instead of trying to infer this we should expose // inherit_group directly to callers, who may have more context - bool inherit_group = false; + bool inherit_group = (add_types & ADD_INHERIT_GROUP) == ADD_INHERIT_GROUP; - if (transition == PageTransition::LINK && !force_index) { + if (transition == PageTransition::LINK && + (add_types & ADD_FORCE_INDEX) == 0) { // We assume tabs opened via link clicks are part of the same task as their // parent. Note that when |force_index| is true (e.g. when the user // drag-and-drops a link to the tab strip), callers aren't really handling // link clicks, they just want to score the navigation like a link click in // the history backend, so we don't inherit the group in this case. index = order_controller_->DetermineInsertionIndex( - contents, transition, foreground); + contents, transition, add_types & ADD_SELECTED); inherit_group = true; } else { // For all other types, respect what was passed to us, normalizing -1s and @@ -521,29 +542,14 @@ void TabStripModel::AddTabContents(TabContents* contents, // is re-selected, not the next-adjacent. inherit_group = true; } - InsertTabContentsAt(index, contents, foreground, inherit_group); + InsertTabContentsAt( + index, contents, + add_types | (inherit_group ? TabStripModel::ADD_INHERIT_GROUP : 0)); // Reset the index, just in case insert ended up moving it on us. index = GetIndexOfTabContents(contents); + if (inherit_group && transition == PageTransition::TYPED) contents_data_[index]->reset_group_on_select = true; - - // Ensure that the new TabContentsView begins at the same size as the - // previous TabContentsView if it existed. Otherwise, the initial WebKit - // layout will be performed based on a width of 0 pixels, causing a - // very long, narrow, inaccurate layout. Because some scripts on pages (as - // well as WebKit's anchor link location calculation) are run on the - // initial layout and not recalculated later, we need to ensure the first - // layout is performed with sane view dimensions even when we're opening a - // new background tab. - if (TabContents* old_contents = GetSelectedTabContents()) { - if (!foreground) { - contents->view()->SizeContents(old_contents->view()->GetContainerSize()); - // We need to hide the contents or else we get and execute paints for - // background tabs. With enough background tabs they will steal the - // backing store of the visible tab causing flashing. See bug 20831. - contents->HideContents(); - } - } } void TabStripModel::CloseSelectedTab() { |