| 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 #ifndef CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ | 5 #ifndef CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ |
| 6 #define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ | 6 #define CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 namespace content { | 23 namespace content { |
| 24 class NavigationController; | 24 class NavigationController; |
| 25 class WebContents; | 25 class WebContents; |
| 26 } | 26 } |
| 27 | 27 |
| 28 //////////////////////////////////////////////////////////////////////////////// | 28 //////////////////////////////////////////////////////////////////////////////// |
| 29 // | 29 // |
| 30 // TabStripModel | 30 // TabStripModel |
| 31 // | 31 // |
| 32 // A model & low level controller of a Browser Window tabstrip. Holds a vector | 32 // A model & low level controller of a Browser Window tabstrip. Holds a vector |
| 33 // of TabContents, and provides an API for adding, removing and shuffling | 33 // of TabContentsWrappers, and provides an API for adding, removing and |
| 34 // them, as well as a higher level API for doing specific Browser-related | 34 // shuffling them, as well as a higher level API for doing specific Browser- |
| 35 // tasks like adding new Tabs from just a URL, etc. | 35 // related tasks like adding new Tabs from just a URL, etc. |
| 36 // | 36 // |
| 37 // Each tab may be any one of the following states: | 37 // Each tab may be any one of the following states: |
| 38 // . Mini-tab. Mini tabs are locked to the left side of the tab strip and | 38 // . Mini-tab. Mini tabs are locked to the left side of the tab strip and |
| 39 // rendered differently (small tabs with only a favicon). The model makes | 39 // rendered differently (small tabs with only a favicon). The model makes |
| 40 // sure all mini-tabs are at the beginning of the tab strip. For example, | 40 // sure all mini-tabs are at the beginning of the tab strip. For example, |
| 41 // if a non-mini tab is added it is forced to be with non-mini tabs. Requests | 41 // if a non-mini tab is added it is forced to be with non-mini tabs. Requests |
| 42 // to move tabs outside the range of the tab type are ignored. For example, | 42 // to move tabs outside the range of the tab type are ignored. For example, |
| 43 // a request to move a mini-tab after non-mini-tabs is ignored. | 43 // a request to move a mini-tab after non-mini-tabs is ignored. |
| 44 // You'll notice there is no explicit api for making a tab a mini-tab, rather | 44 // You'll notice there is no explicit api for making a tab a mini-tab, rather |
| 45 // there are two tab types that are implicitly mini-tabs: | 45 // there are two tab types that are implicitly mini-tabs: |
| (...skipping 24 matching lines...) Expand all Loading... |
| 70 | 70 |
| 71 // Newly created tabs are inserted before the selection. | 71 // Newly created tabs are inserted before the selection. |
| 72 INSERT_BEFORE, | 72 INSERT_BEFORE, |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Used to specify what should happen when the tab is closed. | 75 // Used to specify what should happen when the tab is closed. |
| 76 enum CloseTypes { | 76 enum CloseTypes { |
| 77 CLOSE_NONE = 0, | 77 CLOSE_NONE = 0, |
| 78 | 78 |
| 79 // Indicates the tab was closed by the user. If true, | 79 // Indicates the tab was closed by the user. If true, |
| 80 // TabContents::SetClosedByUserGesture(true) is invoked. | 80 // WebContents::SetClosedByUserGesture(true) is invoked. |
| 81 CLOSE_USER_GESTURE = 1 << 0, | 81 CLOSE_USER_GESTURE = 1 << 0, |
| 82 | 82 |
| 83 // If true the history is recorded so that the tab can be reopened later. | 83 // If true the history is recorded so that the tab can be reopened later. |
| 84 // You almost always want to set this. | 84 // You almost always want to set this. |
| 85 CLOSE_CREATE_HISTORICAL_TAB = 1 << 1, | 85 CLOSE_CREATE_HISTORICAL_TAB = 1 << 1, |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 // Constants used when adding tabs. | 88 // Constants used when adding tabs. |
| 89 enum AddTabTypes { | 89 enum AddTabTypes { |
| 90 // Used to indicate nothing special should happen to the newly inserted | 90 // Used to indicate nothing special should happen to the newly inserted |
| 91 // tab. | 91 // tab. |
| 92 ADD_NONE = 0, | 92 ADD_NONE = 0, |
| 93 | 93 |
| 94 // The tab should be active. | 94 // The tab should be active. |
| 95 ADD_ACTIVE = 1 << 0, | 95 ADD_ACTIVE = 1 << 0, |
| 96 | 96 |
| 97 // The tab should be pinned. | 97 // The tab should be pinned. |
| 98 ADD_PINNED = 1 << 1, | 98 ADD_PINNED = 1 << 1, |
| 99 | 99 |
| 100 // If not set the insertion index of the TabContents is left up to the Order | 100 // If not set the insertion index of the TabContentsWrapper is left up to |
| 101 // Controller associated, so the final insertion index may differ from the | 101 // the Order Controller associated, so the final insertion index may differ |
| 102 // specified index. Otherwise the index supplied is used. | 102 // from the specified index. Otherwise the index supplied is used. |
| 103 ADD_FORCE_INDEX = 1 << 2, | 103 ADD_FORCE_INDEX = 1 << 2, |
| 104 | 104 |
| 105 // If set the newly inserted tab inherits the group of the currently | 105 // If set the newly inserted tab inherits the group of the currently |
| 106 // selected tab. If not set the tab may still inherit the group under | 106 // selected tab. If not set the tab may still inherit the group under |
| 107 // certain situations. | 107 // certain situations. |
| 108 ADD_INHERIT_GROUP = 1 << 3, | 108 ADD_INHERIT_GROUP = 1 << 3, |
| 109 | 109 |
| 110 // If set the newly inserted tab's opener is set to the active tab. If not | 110 // If set the newly inserted tab's opener is set to the active tab. If not |
| 111 // set the tab may still inherit the group/opener under certain situations. | 111 // set the tab may still inherit the group/opener under certain situations. |
| 112 // NOTE: this is ignored if ADD_INHERIT_GROUP is set. | 112 // NOTE: this is ignored if ADD_INHERIT_GROUP is set. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 127 void AddObserver(TabStripModelObserver* observer); | 127 void AddObserver(TabStripModelObserver* observer); |
| 128 void RemoveObserver(TabStripModelObserver* observer); | 128 void RemoveObserver(TabStripModelObserver* observer); |
| 129 | 129 |
| 130 // Retrieve the number of TabContentses/emptiness of the TabStripModel. | 130 // Retrieve the number of TabContentses/emptiness of the TabStripModel. |
| 131 int count() const { return static_cast<int>(contents_data_.size()); } | 131 int count() const { return static_cast<int>(contents_data_.size()); } |
| 132 bool empty() const { return contents_data_.empty(); } | 132 bool empty() const { return contents_data_.empty(); } |
| 133 | 133 |
| 134 // Retrieve the Profile associated with this TabStripModel. | 134 // Retrieve the Profile associated with this TabStripModel. |
| 135 Profile* profile() const { return profile_; } | 135 Profile* profile() const { return profile_; } |
| 136 | 136 |
| 137 // Retrieve the index of the currently active TabContents. | 137 // Retrieve the index of the currently active TabContentsWrapper. |
| 138 int active_index() const { return selection_model_.active(); } | 138 int active_index() const { return selection_model_.active(); } |
| 139 | 139 |
| 140 // Returns true if the tabstrip is currently closing all open tabs (via a | 140 // Returns true if the tabstrip is currently closing all open tabs (via a |
| 141 // call to CloseAllTabs). As tabs close, the selection in the tabstrip | 141 // call to CloseAllTabs). As tabs close, the selection in the tabstrip |
| 142 // changes which notifies observers, which can use this as an optimization to | 142 // changes which notifies observers, which can use this as an optimization to |
| 143 // avoid doing meaningless or unhelpful work. | 143 // avoid doing meaningless or unhelpful work. |
| 144 bool closing_all() const { return closing_all_; } | 144 bool closing_all() const { return closing_all_; } |
| 145 | 145 |
| 146 // Access the order controller. Exposed only for unit tests. | 146 // Access the order controller. Exposed only for unit tests. |
| 147 TabStripModelOrderController* order_controller() const { | 147 TabStripModelOrderController* order_controller() const { |
| 148 return order_controller_; | 148 return order_controller_; |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Sets the insertion policy. Default is INSERT_AFTER. | 151 // Sets the insertion policy. Default is INSERT_AFTER. |
| 152 void SetInsertionPolicy(InsertionPolicy policy); | 152 void SetInsertionPolicy(InsertionPolicy policy); |
| 153 InsertionPolicy insertion_policy() const; | 153 InsertionPolicy insertion_policy() const; |
| 154 | 154 |
| 155 // Returns true if |observer| is in the list of observers. This is intended | 155 // Returns true if |observer| is in the list of observers. This is intended |
| 156 // for debugging. | 156 // for debugging. |
| 157 bool HasObserver(TabStripModelObserver* observer); | 157 bool HasObserver(TabStripModelObserver* observer); |
| 158 | 158 |
| 159 // Basic API ///////////////////////////////////////////////////////////////// | 159 // Basic API ///////////////////////////////////////////////////////////////// |
| 160 | 160 |
| 161 // Determines if the specified index is contained within the TabStripModel. | 161 // Determines if the specified index is contained within the TabStripModel. |
| 162 bool ContainsIndex(int index) const; | 162 bool ContainsIndex(int index) const; |
| 163 | 163 |
| 164 // Adds the specified TabContents in the default location. Tabs opened in the | 164 // Adds the specified TabContentsWrapper in the default location. Tabs opened |
| 165 // foreground inherit the group of the previously active tab. | 165 // in the foreground inherit the group of the previously active tab. |
| 166 void AppendTabContents(TabContentsWrapper* contents, bool foreground); | 166 void AppendTabContents(TabContentsWrapper* contents, bool foreground); |
| 167 | 167 |
| 168 // Adds the specified TabContents at the specified location. |add_types| is a | 168 // Adds the specified TabContentsWrapper at the specified location. |
| 169 // bitmask of AddTypes; see it for details. | 169 // |add_types| is a bitmask of AddTypes; see it for details. |
| 170 // | 170 // |
| 171 // All append/insert methods end up in this method. | 171 // All append/insert methods end up in this method. |
| 172 // | 172 // |
| 173 // NOTE: adding a tab using this method does NOT query the order controller, | 173 // NOTE: adding a tab using this method does NOT query the order controller, |
| 174 // as such the ADD_FORCE_INDEX AddType is meaningless here. The only time the | 174 // as such the ADD_FORCE_INDEX AddType is meaningless here. The only time the |
| 175 // |index| is changed is if using the index would result in breaking the | 175 // |index| is changed is if using the index would result in breaking the |
| 176 // constraint that all mini-tabs occur before non-mini-tabs. | 176 // constraint that all mini-tabs occur before non-mini-tabs. |
| 177 // See also AddTabContents. | 177 // See also AddTabContents. |
| 178 void InsertTabContentsAt(int index, | 178 void InsertTabContentsAt(int index, |
| 179 TabContentsWrapper* contents, | 179 TabContentsWrapper* contents, |
| 180 int add_types); | 180 int add_types); |
| 181 | 181 |
| 182 // Closes the TabContents at the specified index. This causes the TabContents | 182 // Closes the TabContentsWrapper at the specified index. This causes the |
| 183 // to be destroyed, but it may not happen immediately (e.g. if it's a | 183 // TabContentsWrapper to be destroyed, but it may not happen immediately. |
| 184 // TabContents). |close_types| is a bitmask of CloseTypes. | 184 // |close_types| is a bitmask of CloseTypes. Returns true if the |
| 185 // Returns true if the TabContents was closed immediately, false if it was not | 185 // TabContentsWrapper was closed immediately, false if it was not closed (we |
| 186 // closed (we may be waiting for a response from an onunload handler, or | 186 // may be waiting for a response from an onunload handler, or waiting for the |
| 187 // waiting for the user to confirm closure). | 187 // user to confirm closure). |
| 188 bool CloseTabContentsAt(int index, uint32 close_types); | 188 bool CloseTabContentsAt(int index, uint32 close_types); |
| 189 | 189 |
| 190 // Replaces the entire state of a the tab at index by switching in a | 190 // Replaces the entire state of a the tab at index by switching in a |
| 191 // different NavigationController. This is used through the recently | 191 // different NavigationController. This is used through the recently |
| 192 // closed tabs list, which needs to replace a tab's current state | 192 // closed tabs list, which needs to replace a tab's current state |
| 193 // and history with another set of contents and history. | 193 // and history with another set of contents and history. |
| 194 // | 194 // |
| 195 // The old NavigationController is deallocated and this object takes | 195 // The old NavigationController is deallocated and this object takes |
| 196 // ownership of the passed in controller. | 196 // ownership of the passed in controller. |
| 197 // XXXPINK This API is weird and wrong. Remove it or change it or rename it? | 197 // XXXPINK This API is weird and wrong. Remove it or change it or rename it? |
| 198 void ReplaceNavigationControllerAt(int index, | 198 void ReplaceNavigationControllerAt(int index, |
| 199 TabContentsWrapper* contents); | 199 TabContentsWrapper* contents); |
| 200 | 200 |
| 201 // Replaces the tab contents at |index| with |new_contents|. The | 201 // Replaces the tab contents at |index| with |new_contents|. The |
| 202 // TabContentsWrapper that was at |index| is returned and ownership returns | 202 // TabContentsWrapper that was at |index| is returned and ownership returns |
| 203 // to the caller. | 203 // to the caller. |
| 204 TabContentsWrapper* ReplaceTabContentsAt(int index, | 204 TabContentsWrapper* ReplaceTabContentsAt(int index, |
| 205 TabContentsWrapper* new_contents); | 205 TabContentsWrapper* new_contents); |
| 206 | 206 |
| 207 // Destroys the TabContents at the specified index, but keeps the tab visible | 207 // Destroys the TabContentsWrapper at the specified index, but keeps the tab |
| 208 // in the tab strip. Used to free memory in low-memory conditions, especially | 208 // visible in the tab strip. Used to free memory in low-memory conditions, |
| 209 // on Chrome OS. The tab reloads if the user clicks on it. | 209 // especially on Chrome OS. The tab reloads if the user clicks on it. |
| 210 // Returns an empty TabContentsWrapper, used only for testing. | 210 // Returns an empty TabContentsWrapper, used only for testing. |
| 211 TabContentsWrapper* DiscardTabContentsAt(int index); | 211 TabContentsWrapper* DiscardTabContentsAt(int index); |
| 212 | 212 |
| 213 // Detaches the TabContents at the specified index from this strip. The | 213 // Detaches the TabContentsWrapper at the specified index from this strip. The |
| 214 // TabContents is not destroyed, just removed from display. The caller is | 214 // TabContentsWrapper is not destroyed, just removed from display. The caller |
| 215 // responsible for doing something with it (e.g. stuffing it into another | 215 // is responsible for doing something with it (e.g. stuffing it into another |
| 216 // strip). | 216 // strip). |
| 217 TabContentsWrapper* DetachTabContentsAt(int index); | 217 TabContentsWrapper* DetachTabContentsAt(int index); |
| 218 | 218 |
| 219 // Makes the tab at the specified index the active tab. |user_gesture| is true | 219 // Makes the tab at the specified index the active tab. |user_gesture| is true |
| 220 // if the user actually clicked on the tab or navigated to it using a keyboard | 220 // if the user actually clicked on the tab or navigated to it using a keyboard |
| 221 // command, false if the tab was activated as a by-product of some other | 221 // command, false if the tab was activated as a by-product of some other |
| 222 // action. | 222 // action. |
| 223 void ActivateTabAt(int index, bool user_gesture); | 223 void ActivateTabAt(int index, bool user_gesture); |
| 224 | 224 |
| 225 // Adds tab at |index| to the currently selected tabs, without changing the | 225 // Adds tab at |index| to the currently selected tabs, without changing the |
| 226 // active tab index. | 226 // active tab index. |
| 227 void AddTabAtToSelection(int index); | 227 void AddTabAtToSelection(int index); |
| 228 | 228 |
| 229 // Move the TabContents at the specified index to another index. This method | 229 // Move the TabContentsWrapper at the specified index to another index. This |
| 230 // does NOT send Detached/Attached notifications, rather it moves the | 230 // method does NOT send Detached/Attached notifications, rather it moves the |
| 231 // TabContents inline and sends a Moved notification instead. | 231 // TabContentsWrapper inline and sends a Moved notification instead. |
| 232 // If |select_after_move| is false, whatever tab was selected before the move | 232 // If |select_after_move| is false, whatever tab was selected before the move |
| 233 // will still be selected, but it's index may have incremented or decremented | 233 // will still be selected, but it's index may have incremented or decremented |
| 234 // one slot. | 234 // one slot. |
| 235 // NOTE: this does nothing if the move would result in app tabs and non-app | 235 // NOTE: this does nothing if the move would result in app tabs and non-app |
| 236 // tabs mixing. | 236 // tabs mixing. |
| 237 void MoveTabContentsAt(int index, int to_position, bool select_after_move); | 237 void MoveTabContentsAt(int index, int to_position, bool select_after_move); |
| 238 | 238 |
| 239 // Moves the selected tabs to |index|. |index| is treated as if the tab strip | 239 // Moves the selected tabs to |index|. |index| is treated as if the tab strip |
| 240 // did not contain any of the selected tabs. For example, if the tabstrip | 240 // did not contain any of the selected tabs. For example, if the tabstrip |
| 241 // contains [A b c D E f] (upper case selected) and this is invoked with 1 the | 241 // contains [A b c D E f] (upper case selected) and this is invoked with 1 the |
| 242 // result is [b A D E c f]. | 242 // result is [b A D E c f]. |
| 243 // This method maintains that all mini-tabs occur before non-mini-tabs. When | 243 // This method maintains that all mini-tabs occur before non-mini-tabs. When |
| 244 // mini-tabs are selected the move is processed in two chunks: first mini-tabs | 244 // mini-tabs are selected the move is processed in two chunks: first mini-tabs |
| 245 // are moved, then non-mini-tabs are moved. If the index is after | 245 // are moved, then non-mini-tabs are moved. If the index is after |
| 246 // (mini-tab-count - selected-mini-tab-count), then the index the non-mini | 246 // (mini-tab-count - selected-mini-tab-count), then the index the non-mini |
| 247 // selected tabs are moved to is (index + selected-mini-tab-count). For | 247 // selected tabs are moved to is (index + selected-mini-tab-count). For |
| 248 // example, if the model consists of [A b c D E f] (A b c are mini) and this | 248 // example, if the model consists of [A b c D E f] (A b c are mini) and this |
| 249 // is inokved with 2, the result is [b c A D E f]. In this example nothing | 249 // is inokved with 2, the result is [b c A D E f]. In this example nothing |
| 250 // special happened because the target index was <= (mini-tab-count - | 250 // special happened because the target index was <= (mini-tab-count - |
| 251 // selected-mini-tab-count). If the target index were 3, then the result would | 251 // selected-mini-tab-count). If the target index were 3, then the result would |
| 252 // be [b c A f D F]. A, being mini, can move no further than index 2. The | 252 // be [b c A f D F]. A, being mini, can move no further than index 2. The |
| 253 // non-mini-tabs are moved to the target index + selected-mini-tab-count (3 + | 253 // non-mini-tabs are moved to the target index + selected-mini-tab-count (3 + |
| 254 // 1) | 254 // 1) |
| 255 void MoveSelectedTabsTo(int index); | 255 void MoveSelectedTabsTo(int index); |
| 256 | 256 |
| 257 // Returns the currently active TabContents, or NULL if there is none. | 257 // Returns the currently active TabContentsWrapper, or NULL if there is none. |
| 258 TabContentsWrapper* GetActiveTabContents() const; | 258 TabContentsWrapper* GetActiveTabContents() const; |
| 259 | 259 |
| 260 // Returns the TabContentsWrapper at the specified index, or NULL if there is | 260 // Returns the TabContentsWrapper at the specified index, or NULL if there is |
| 261 // none. | 261 // none. |
| 262 TabContentsWrapper* GetTabContentsAt(int index) const; | 262 TabContentsWrapper* GetTabContentsAt(int index) const; |
| 263 | 263 |
| 264 // Returns the index of the specified TabContents wrapper, or | 264 // Returns the index of the specified TabContentsWrapper, or |
| 265 // TabStripModel::kNoTab if the TabContents is not in this TabStripModel. | 265 // TabStripModel::kNoTab if the TabContentsWrapper is not in this |
| 266 // TabStripModel. |
| 266 int GetIndexOfTabContents(const TabContentsWrapper* contents) const; | 267 int GetIndexOfTabContents(const TabContentsWrapper* contents) const; |
| 267 | 268 |
| 268 // Returns the index of the specified WebContents wrapper given its raw | 269 // Returns the index of the specified TabContentsWrapper given its raw |
| 269 // WebContents, or TabStripModel::kNoTab if the TabContents is not in this | 270 // WebContents, or TabStripModel::kNoTab if the WebContents is not in this |
| 270 // TabStripModel. Note: This is only needed in rare cases where the wrapper | 271 // TabStripModel. Note: This is only needed in rare cases where the wrapper |
| 271 // is not already present (such as implementing WebContentsDelegate methods, | 272 // is not already present (such as implementing WebContentsDelegate methods, |
| 272 // which don't know about the wrapper. Returns NULL if |contents| is not | 273 // which don't know about the wrapper. Returns NULL if |contents| is not |
| 273 // associated with any wrapper in the model. | 274 // associated with any TabContentsWrapper in the model. |
| 274 int GetWrapperIndex(const content::WebContents* contents) const; | 275 int GetWrapperIndex(const content::WebContents* contents) const; |
| 275 | 276 |
| 276 // Returns the index of the specified NavigationController, or kNoTab if it is | 277 // Returns the index of the specified NavigationController, or kNoTab if it is |
| 277 // not in this TabStripModel. | 278 // not in this TabStripModel. |
| 278 int GetIndexOfController( | 279 int GetIndexOfController( |
| 279 const content::NavigationController* controller) const; | 280 const content::NavigationController* controller) const; |
| 280 | 281 |
| 281 // Notify any observers that the TabContents at the specified index has | 282 // Notify any observers that the TabContentsWrapper at the specified index has |
| 282 // changed in some way. See TabChangeType for details of |change_type|. | 283 // changed in some way. See TabChangeType for details of |change_type|. |
| 283 void UpdateTabContentsStateAt( | 284 void UpdateTabContentsStateAt( |
| 284 int index, | 285 int index, |
| 285 TabStripModelObserver::TabChangeType change_type); | 286 TabStripModelObserver::TabChangeType change_type); |
| 286 | 287 |
| 287 // Make sure there is an auto-generated New Tab tab in the TabStripModel. | 288 // Make sure there is an auto-generated New Tab tab in the TabStripModel. |
| 288 // If |force_create| is true, the New Tab will be created even if the | 289 // If |force_create| is true, the New Tab will be created even if the |
| 289 // preference is set to false (used by startup). | 290 // preference is set to false (used by startup). |
| 290 void EnsureNewTabVisible(bool force_create); | 291 void EnsureNewTabVisible(bool force_create); |
| 291 | 292 |
| 292 // Close all tabs at once. Code can use closing_all() above to defer | 293 // Close all tabs at once. Code can use closing_all() above to defer |
| 293 // operations that might otherwise by invoked by the flurry of detach/select | 294 // operations that might otherwise by invoked by the flurry of detach/select |
| 294 // notifications this method causes. | 295 // notifications this method causes. |
| 295 void CloseAllTabs(); | 296 void CloseAllTabs(); |
| 296 | 297 |
| 297 // Returns true if there are any TabContents that are currently loading. | 298 // Returns true if there are any TabContentsWrappers that are currently |
| 299 // loading. |
| 298 bool TabsAreLoading() const; | 300 bool TabsAreLoading() const; |
| 299 | 301 |
| 300 // Returns the controller controller that opened the TabContents at |index|. | 302 // Returns the controller controller that opened the TabContentsWrapper at |
| 303 // |index|. |
| 301 content::NavigationController* GetOpenerOfTabContentsAt(int index); | 304 content::NavigationController* GetOpenerOfTabContentsAt(int index); |
| 302 | 305 |
| 303 // Changes the |opener| of the TabContents at |index|. | 306 // Changes the |opener| of the TabContentsWrapper at |index|. |
| 304 // Note: |opener| must be in this tab strip. | 307 // Note: |opener| must be in this tab strip. |
| 305 void SetOpenerOfTabContentsAt( | 308 void SetOpenerOfTabContentsAt( |
| 306 int index, | 309 int index, |
| 307 content::NavigationController* opener); | 310 content::NavigationController* opener); |
| 308 | 311 |
| 309 // Returns the index of the next TabContents in the sequence of TabContentses | 312 // Returns the index of the next TabContentsWrapper in the sequence of |
| 310 // spawned by the specified NavigationController after |start_index|. | 313 // TabContentsWrappers spawned by the specified NavigationController after |
| 311 // If |use_group| is true, the group property of the tab is used instead of | 314 // |start_index|. If |use_group| is true, the group property of the tab is |
| 312 // the opener to find the next tab. Under some circumstances the group | 315 // used instead of the opener to find the next tab. Under some circumstances |
| 313 // relationship may exist but the opener may not. | 316 // the group relationship may exist but the opener may not. |
| 314 int GetIndexOfNextTabContentsOpenedBy( | 317 int GetIndexOfNextTabContentsOpenedBy( |
| 315 const content::NavigationController* opener, | 318 const content::NavigationController* opener, |
| 316 int start_index, | 319 int start_index, |
| 317 bool use_group) const; | 320 bool use_group) const; |
| 318 | 321 |
| 319 // Returns the index of the first TabContents in the model opened by the | 322 // Returns the index of the first TabContentsWrapper in the model opened by |
| 320 // specified opener. | 323 // the specified opener. |
| 321 int GetIndexOfFirstTabContentsOpenedBy( | 324 int GetIndexOfFirstTabContentsOpenedBy( |
| 322 const content::NavigationController* opener, | 325 const content::NavigationController* opener, |
| 323 int start_index) const; | 326 int start_index) const; |
| 324 | 327 |
| 325 // Returns the index of the last TabContents in the model opened by the | 328 // Returns the index of the last TabContentsWrapper in the model opened by the |
| 326 // specified opener, starting at |start_index|. | 329 // specified opener, starting at |start_index|. |
| 327 int GetIndexOfLastTabContentsOpenedBy( | 330 int GetIndexOfLastTabContentsOpenedBy( |
| 328 const content::NavigationController* opener, | 331 const content::NavigationController* opener, |
| 329 int start_index) const; | 332 int start_index) const; |
| 330 | 333 |
| 331 // Called by the Browser when a navigation is about to occur in the specified | 334 // Called by the Browser when a navigation is about to occur in the specified |
| 332 // TabContents. Depending on the tab, and the transition type of the | 335 // TabContentsWrapper. Depending on the tab, and the transition type of the |
| 333 // navigation, the TabStripModel may adjust its selection and grouping | 336 // navigation, the TabStripModel may adjust its selection and grouping |
| 334 // behavior. | 337 // behavior. |
| 335 void TabNavigating(TabContentsWrapper* contents, | 338 void TabNavigating(TabContentsWrapper* contents, |
| 336 content::PageTransition transition); | 339 content::PageTransition transition); |
| 337 | 340 |
| 338 // Forget all Opener relationships that are stored (but _not_ group | 341 // Forget all Opener relationships that are stored (but _not_ group |
| 339 // relationships!) This is to reduce unpredictable tab switching behavior | 342 // relationships!) This is to reduce unpredictable tab switching behavior |
| 340 // in complex session states. The exact circumstances under which this method | 343 // in complex session states. The exact circumstances under which this method |
| 341 // is called are left up to the implementation of the selected | 344 // is called are left up to the implementation of the selected |
| 342 // TabStripModelOrderController. | 345 // TabStripModelOrderController. |
| 343 void ForgetAllOpeners(); | 346 void ForgetAllOpeners(); |
| 344 | 347 |
| 345 // Forgets the group affiliation of the specified TabContents. This should be | 348 // Forgets the group affiliation of the specified TabContentsWrapper. This |
| 346 // called when a TabContents that is part of a logical group of tabs is | 349 // should be called when a TabContentsWrapper that is part of a logical group |
| 347 // moved to a new logical context by the user (e.g. by typing a new URL or | 350 // of tabs is moved to a new logical context by the user (e.g. by typing a new |
| 348 // selecting a bookmark). This also forgets the opener, which is considered | 351 // URL or selecting a bookmark). This also forgets the opener, which is |
| 349 // a weaker relationship than group. | 352 // considered a weaker relationship than group. |
| 350 void ForgetGroup(TabContentsWrapper* contents); | 353 void ForgetGroup(TabContentsWrapper* contents); |
| 351 | 354 |
| 352 // Returns true if the group/opener relationships present for |contents| | 355 // Returns true if the group/opener relationships present for |contents| |
| 353 // should be reset when _any_ selection change occurs in the model. | 356 // should be reset when _any_ selection change occurs in the model. |
| 354 bool ShouldResetGroupOnSelect(TabContentsWrapper* contents) const; | 357 bool ShouldResetGroupOnSelect(TabContentsWrapper* contents) const; |
| 355 | 358 |
| 356 // Changes the blocked state of the tab at |index|. | 359 // Changes the blocked state of the tab at |index|. |
| 357 void SetTabBlocked(int index, bool blocked); | 360 void SetTabBlocked(int index, bool blocked); |
| 358 | 361 |
| 359 // Changes the pinned state of the tab at |index|. See description above | 362 // Changes the pinned state of the tab at |index|. See description above |
| 360 // class for details on this. | 363 // class for details on this. |
| 361 void SetTabPinned(int index, bool pinned); | 364 void SetTabPinned(int index, bool pinned); |
| 362 | 365 |
| 363 // Returns true if the tab at |index| is pinned. | 366 // Returns true if the tab at |index| is pinned. |
| 364 // See description above class for details on pinned tabs. | 367 // See description above class for details on pinned tabs. |
| 365 bool IsTabPinned(int index) const; | 368 bool IsTabPinned(int index) const; |
| 366 | 369 |
| 367 // Is the tab a mini-tab? | 370 // Is the tab a mini-tab? |
| 368 // See description above class for details on this. | 371 // See description above class for details on this. |
| 369 bool IsMiniTab(int index) const; | 372 bool IsMiniTab(int index) const; |
| 370 | 373 |
| 371 // Is the tab at |index| an app? | 374 // Is the tab at |index| an app? |
| 372 // See description above class for details on app tabs. | 375 // See description above class for details on app tabs. |
| 373 bool IsAppTab(int index) const; | 376 bool IsAppTab(int index) const; |
| 374 | 377 |
| 375 // Returns true if the tab at |index| is blocked by a tab modal dialog. | 378 // Returns true if the tab at |index| is blocked by a tab modal dialog. |
| 376 bool IsTabBlocked(int index) const; | 379 bool IsTabBlocked(int index) const; |
| 377 | 380 |
| 378 // Returns true if the TabContents at |index| has been discarded to save | 381 // Returns true if the TabContentsWrapper at |index| has been discarded to |
| 379 // memory. See DiscardTabContentsAt() for details. | 382 // save memory. See DiscardTabContentsAt() for details. |
| 380 bool IsTabDiscarded(int index) const; | 383 bool IsTabDiscarded(int index) const; |
| 381 | 384 |
| 382 // Returns the index of the first tab that is not a mini-tab. This returns | 385 // Returns the index of the first tab that is not a mini-tab. This returns |
| 383 // |count()| if all of the tabs are mini-tabs, and 0 if none of the tabs are | 386 // |count()| if all of the tabs are mini-tabs, and 0 if none of the tabs are |
| 384 // mini-tabs. | 387 // mini-tabs. |
| 385 int IndexOfFirstNonMiniTab() const; | 388 int IndexOfFirstNonMiniTab() const; |
| 386 | 389 |
| 387 // Returns a valid index for inserting a new tab into this model. |index| is | 390 // Returns a valid index for inserting a new tab into this model. |index| is |
| 388 // the proposed index and |mini_tab| is true if inserting a tab will become | 391 // the proposed index and |mini_tab| is true if inserting a tab will become |
| 389 // mini (pinned or app). If |mini_tab| is true, the returned index is between | 392 // mini (pinned or app). If |mini_tab| is true, the returned index is between |
| (...skipping 17 matching lines...) Expand all Loading... |
| 407 | 410 |
| 408 // Sets the selection to match that of |source|. | 411 // Sets the selection to match that of |source|. |
| 409 void SetSelectionFromModel(const TabStripSelectionModel& source); | 412 void SetSelectionFromModel(const TabStripSelectionModel& source); |
| 410 | 413 |
| 411 const TabStripSelectionModel& selection_model() const { | 414 const TabStripSelectionModel& selection_model() const { |
| 412 return selection_model_; | 415 return selection_model_; |
| 413 } | 416 } |
| 414 | 417 |
| 415 // Command level API ///////////////////////////////////////////////////////// | 418 // Command level API ///////////////////////////////////////////////////////// |
| 416 | 419 |
| 417 // Adds a TabContents at the best position in the TabStripModel given the | 420 // Adds a TabContentsWrapper at the best position in the TabStripModel given |
| 418 // specified insertion index, transition, etc. |add_types| is a bitmask of | 421 // the specified insertion index, transition, etc. |add_types| is a bitmask of |
| 419 // AddTypes; see it for details. This method ends up calling into | 422 // AddTypes; see it for details. This method ends up calling into |
| 420 // InsertTabContentsAt to do the actual inertion. | 423 // InsertTabContentsAt to do the actual insertion. |
| 421 void AddTabContents(TabContentsWrapper* contents, | 424 void AddTabContents(TabContentsWrapper* contents, |
| 422 int index, | 425 int index, |
| 423 content::PageTransition transition, | 426 content::PageTransition transition, |
| 424 int add_types); | 427 int add_types); |
| 425 | 428 |
| 426 // Closes the selected tabs. | 429 // Closes the selected tabs. |
| 427 void CloseSelectedTabs(); | 430 void CloseSelectedTabs(); |
| 428 | 431 |
| 429 // Select adjacent tabs | 432 // Select adjacent tabs |
| 430 void SelectNextTab(); | 433 void SelectNextTab(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 508 |
| 506 // Gets the set of tab indices that have the same opener as the tab at | 509 // Gets the set of tab indices that have the same opener as the tab at |
| 507 // |index|. | 510 // |index|. |
| 508 void GetIndicesWithSameOpener(int index, std::vector<int>* indices); | 511 void GetIndicesWithSameOpener(int index, std::vector<int>* indices); |
| 509 | 512 |
| 510 // If |index| is selected all the selected indices are returned, otherwise a | 513 // If |index| is selected all the selected indices are returned, otherwise a |
| 511 // vector with |index| is returned. This is used when executing commands to | 514 // vector with |index| is returned. This is used when executing commands to |
| 512 // determine which indices the command applies to. | 515 // determine which indices the command applies to. |
| 513 std::vector<int> GetIndicesForCommand(int index) const; | 516 std::vector<int> GetIndicesForCommand(int index) const; |
| 514 | 517 |
| 515 // Returns true if the specified TabContents is a New Tab at the end of the | 518 // Returns true if the specified TabContentsWrapper is a New Tab at the end of |
| 516 // TabStrip. We check for this because opener relationships are _not_ | 519 // the TabStrip. We check for this because opener relationships are _not_ |
| 517 // forgotten for the New Tab page opened as a result of a New Tab gesture | 520 // forgotten for the New Tab page opened as a result of a New Tab gesture |
| 518 // (e.g. Ctrl+T, etc) since the user may open a tab transiently to look up | 521 // (e.g. Ctrl+T, etc) since the user may open a tab transiently to look up |
| 519 // something related to their current activity. | 522 // something related to their current activity. |
| 520 bool IsNewTabAtEndOfTabStrip(TabContentsWrapper* contents) const; | 523 bool IsNewTabAtEndOfTabStrip(TabContentsWrapper* contents) const; |
| 521 | 524 |
| 522 // Closes the TabContents at the specified indices. This causes the | 525 // Closes the TabContentsWrappers at the specified indices. This causes the |
| 523 // TabContents to be destroyed, but it may not happen immediately. If the | 526 // TabContentsWrappers to be destroyed, but it may not happen immediately. If |
| 524 // page in question has an unload event the TabContents will not be destroyed | 527 // the page in question has an unload event the WebContents will not be |
| 525 // until after the event has completed, which will then call back into this | 528 // destroyed until after the event has completed, which will then call back |
| 526 // method. | 529 // into this method. |
| 527 // | 530 // |
| 528 // Returns true if the TabContents were closed immediately, false if we are | 531 // Returns true if the TabContentsWrapper were closed immediately, false if we |
| 529 // waiting for the result of an onunload handler. | 532 // are waiting for the result of an onunload handler. |
| 530 bool InternalCloseTabs(const std::vector<int>& in_indices, | 533 bool InternalCloseTabs(const std::vector<int>& in_indices, |
| 531 uint32 close_types); | 534 uint32 close_types); |
| 532 | 535 |
| 533 // Invoked from InternalCloseTabs and when an extension is removed for an app | 536 // Invoked from InternalCloseTabs and when an extension is removed for an app |
| 534 // tab. Notifies observers of TabClosingAt and deletes |contents|. If | 537 // tab. Notifies observers of TabClosingAt and deletes |contents|. If |
| 535 // |create_historical_tabs| is true, CreateHistoricalTab is invoked on the | 538 // |create_historical_tabs| is true, CreateHistoricalTab is invoked on the |
| 536 // delegate. | 539 // delegate. |
| 537 // | 540 // |
| 538 // The boolean parameter create_historical_tab controls whether to | 541 // The boolean parameter create_historical_tab controls whether to |
| 539 // record these tabs and their history for reopening recently closed | 542 // record these tabs and their history for reopening recently closed |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 const content::NavigationController* opener, | 594 const content::NavigationController* opener, |
| 592 bool use_group); | 595 bool use_group); |
| 593 | 596 |
| 594 // Sets the group/opener of any tabs that reference |tab| to NULL. | 597 // Sets the group/opener of any tabs that reference |tab| to NULL. |
| 595 void ForgetOpenersAndGroupsReferencing( | 598 void ForgetOpenersAndGroupsReferencing( |
| 596 const content::NavigationController* tab); | 599 const content::NavigationController* tab); |
| 597 | 600 |
| 598 // Our delegate. | 601 // Our delegate. |
| 599 TabStripModelDelegate* delegate_; | 602 TabStripModelDelegate* delegate_; |
| 600 | 603 |
| 601 // A hunk of data representing a TabContents and (optionally) the | 604 // A hunk of data representing a TabContentsWrapper and (optionally) the |
| 602 // NavigationController that spawned it. This memory only sticks around while | 605 // NavigationController that spawned it. This memory only sticks around while |
| 603 // the TabContents is in the current TabStripModel, unless otherwise | 606 // the TabContentsWrapper is in the current TabStripModel, unless otherwise |
| 604 // specified in code. | 607 // specified in code. |
| 605 struct TabContentsData { | 608 struct TabContentsData { |
| 606 explicit TabContentsData(TabContentsWrapper* a_contents) | 609 explicit TabContentsData(TabContentsWrapper* a_contents) |
| 607 : contents(a_contents), | 610 : contents(a_contents), |
| 608 reset_group_on_select(false), | 611 reset_group_on_select(false), |
| 609 pinned(false), | 612 pinned(false), |
| 610 blocked(false), | 613 blocked(false), |
| 611 discarded(false) { | 614 discarded(false) { |
| 612 SetGroup(NULL); | 615 SetGroup(NULL); |
| 613 } | 616 } |
| 614 | 617 |
| 615 // Create a relationship between this TabContents and other TabContentses. | 618 // Create a relationship between this TabContentsWrapper and other |
| 616 // Used to identify which TabContents to select next after one is closed. | 619 // TabContentsWrappers. Used to identify which TabContentsWrapper to select |
| 620 // next after one is closed. |
| 617 void SetGroup(content::NavigationController* a_group) { | 621 void SetGroup(content::NavigationController* a_group) { |
| 618 group = a_group; | 622 group = a_group; |
| 619 opener = a_group; | 623 opener = a_group; |
| 620 } | 624 } |
| 621 | 625 |
| 622 // Forget the opener relationship so that when this TabContents is closed | 626 // Forget the opener relationship so that when this TabContentsWrapper is |
| 623 // unpredictable re-selection does not occur. | 627 // closed unpredictable re-selection does not occur. |
| 624 void ForgetOpener() { | 628 void ForgetOpener() { |
| 625 opener = NULL; | 629 opener = NULL; |
| 626 } | 630 } |
| 627 | 631 |
| 628 TabContentsWrapper* contents; | 632 TabContentsWrapper* contents; |
| 629 // We use NavigationControllers here since they more closely model the | 633 // We use NavigationControllers here since they more closely model the |
| 630 // "identity" of a Tab, TabContents can change depending on the URL loaded | 634 // "identity" of a Tab, TabContentsWrappers can change depending on the URL |
| 631 // in the Tab. | 635 // loaded in the Tab. |
| 632 // The group is used to model a set of tabs spawned from a single parent | 636 // The group is used to model a set of tabs spawned from a single parent |
| 633 // tab. This value is preserved for a given tab as long as the tab remains | 637 // tab. This value is preserved for a given tab as long as the tab remains |
| 634 // navigated to the link it was initially opened at or some navigation from | 638 // navigated to the link it was initially opened at or some navigation from |
| 635 // that page (i.e. if the user types or visits a bookmark or some other | 639 // that page (i.e. if the user types or visits a bookmark or some other |
| 636 // navigation within that tab, the group relationship is lost). This | 640 // navigation within that tab, the group relationship is lost). This |
| 637 // property can safely be used to implement features that depend on a | 641 // property can safely be used to implement features that depend on a |
| 638 // logical group of related tabs. | 642 // logical group of related tabs. |
| 639 content::NavigationController* group; | 643 content::NavigationController* group; |
| 640 // The owner models the same relationship as group, except it is more | 644 // The owner models the same relationship as group, except it is more |
| 641 // easily discarded, e.g. when the user switches to a tab not part of the | 645 // easily discarded, e.g. when the user switches to a tab not part of the |
| (...skipping 11 matching lines...) Expand all Loading... |
| 653 // Is the tab pinned? | 657 // Is the tab pinned? |
| 654 bool pinned; | 658 bool pinned; |
| 655 | 659 |
| 656 // Is the tab interaction blocked by a modal dialog? | 660 // Is the tab interaction blocked by a modal dialog? |
| 657 bool blocked; | 661 bool blocked; |
| 658 | 662 |
| 659 // Has the tab data been discarded to save memory? | 663 // Has the tab data been discarded to save memory? |
| 660 bool discarded; | 664 bool discarded; |
| 661 }; | 665 }; |
| 662 | 666 |
| 663 // The TabContents data currently hosted within this TabStripModel. | 667 // The TabContentsWrapper data currently hosted within this TabStripModel. |
| 664 typedef std::vector<TabContentsData*> TabContentsDataVector; | 668 typedef std::vector<TabContentsData*> TabContentsDataVector; |
| 665 TabContentsDataVector contents_data_; | 669 TabContentsDataVector contents_data_; |
| 666 | 670 |
| 667 // A profile associated with this TabStripModel, used when creating new Tabs. | 671 // A profile associated with this TabStripModel, used when creating new Tabs. |
| 668 Profile* profile_; | 672 Profile* profile_; |
| 669 | 673 |
| 670 // True if all tabs are currently being closed via CloseAllTabs. | 674 // True if all tabs are currently being closed via CloseAllTabs. |
| 671 bool closing_all_; | 675 bool closing_all_; |
| 672 | 676 |
| 673 // An object that determines where new Tabs should be inserted and where | 677 // An object that determines where new Tabs should be inserted and where |
| 674 // selection should move when a Tab is closed. | 678 // selection should move when a Tab is closed. |
| 675 TabStripModelOrderController* order_controller_; | 679 TabStripModelOrderController* order_controller_; |
| 676 | 680 |
| 677 // Our observers. | 681 // Our observers. |
| 678 typedef ObserverList<TabStripModelObserver> TabStripModelObservers; | 682 typedef ObserverList<TabStripModelObserver> TabStripModelObservers; |
| 679 TabStripModelObservers observers_; | 683 TabStripModelObservers observers_; |
| 680 | 684 |
| 681 // A scoped container for notification registries. | 685 // A scoped container for notification registries. |
| 682 content::NotificationRegistrar registrar_; | 686 content::NotificationRegistrar registrar_; |
| 683 | 687 |
| 684 TabStripSelectionModel selection_model_; | 688 TabStripSelectionModel selection_model_; |
| 685 | 689 |
| 686 DISALLOW_IMPLICIT_CONSTRUCTORS(TabStripModel); | 690 DISALLOW_IMPLICIT_CONSTRUCTORS(TabStripModel); |
| 687 }; | 691 }; |
| 688 | 692 |
| 689 #endif // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ | 693 #endif // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ |
| OLD | NEW |