Home | History | Annotate | Download | only in tabs
      1 // Copyright (c) 2010 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 #ifndef CHROME_BROWSER_TABS_TAB_STRIP_MODEL_ORDER_CONTROLLER_H_
      6 #define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_ORDER_CONTROLLER_H_
      7 #pragma once
      8 
      9 #include "chrome/browser/tabs/tab_strip_model.h"
     10 #include "content/common/page_transition_types.h"
     11 
     12 class TabContentsWrapper;
     13 
     14 ///////////////////////////////////////////////////////////////////////////////
     15 // TabStripModelOrderController
     16 //
     17 //  An object that allows different types of ordering and reselection to be
     18 //  heuristics plugged into a TabStripModel.
     19 //
     20 class TabStripModelOrderController : public TabStripModelObserver {
     21  public:
     22   explicit TabStripModelOrderController(TabStripModel* tabstrip);
     23   virtual ~TabStripModelOrderController();
     24 
     25   // Sets the insertion policy. Default is INSERT_AFTER.
     26   void set_insertion_policy(TabStripModel::InsertionPolicy policy) {
     27     insertion_policy_ = policy;
     28   }
     29   TabStripModel::InsertionPolicy insertion_policy() const {
     30     return insertion_policy_;
     31   }
     32 
     33   // Determine where to place a newly opened tab by using the supplied
     34   // transition and foreground flag to figure out how it was opened.
     35   int DetermineInsertionIndex(TabContentsWrapper* new_contents,
     36                               PageTransition::Type transition,
     37                               bool foreground);
     38 
     39   // Returns the index to append tabs at.
     40   int DetermineInsertionIndexForAppending();
     41 
     42   // Determine where to shift selection after a tab is closed.
     43   int DetermineNewSelectedIndex(int removed_index) const;
     44 
     45   // Overridden from TabStripModelObserver:
     46   virtual void TabSelectedAt(TabContentsWrapper* old_contents,
     47                              TabContentsWrapper* new_contents,
     48                              int index,
     49                              bool user_gesture);
     50 
     51  private:
     52   // Returns a valid index to be selected after the tab at |removing_index| is
     53   // closed. If |index| is after |removing_index|, |index| is adjusted to
     54   // reflect the fact that |removing_index| is going away.
     55   int GetValidIndex(int index, int removing_index) const;
     56 
     57   TabStripModel* tabstrip_;
     58 
     59   TabStripModel::InsertionPolicy insertion_policy_;
     60 
     61   DISALLOW_COPY_AND_ASSIGN(TabStripModelOrderController);
     62 };
     63 
     64 #endif  // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_ORDER_CONTROLLER_H_
     65