| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 int to_index) {} | 90 int to_index) {} |
| 91 | 91 |
| 92 // The specified TabContents at |index| changed in some way. |contents| may | 92 // The specified TabContents at |index| changed in some way. |contents| may |
| 93 // be an entirely different object and the old value is no longer available | 93 // be an entirely different object and the old value is no longer available |
| 94 // by the time this message is delivered. | 94 // by the time this message is delivered. |
| 95 // | 95 // |
| 96 // See TabChangeType for a description of |change_type|. | 96 // See TabChangeType for a description of |change_type|. |
| 97 virtual void TabChangedAt(TabContents* contents, int index, | 97 virtual void TabChangedAt(TabContents* contents, int index, |
| 98 TabChangeType change_type) {} | 98 TabChangeType change_type) {} |
| 99 | 99 |
| 100 // The tab contents was replaced at the specified index. This is invoked when | |
| 101 // a tab becomes phantom. See description of phantom tabs in class description | |
| 102 // of TabStripModel for details. | |
| 103 virtual void TabReplacedAt(TabContents* old_contents, | |
| 104 TabContents* new_contents, int index) {} | |
| 105 | |
| 106 // Invoked when the pinned state of a tab changes. This is not invoked if the | 100 // Invoked when the pinned state of a tab changes. This is not invoked if the |
| 107 // tab ends up moving as a result of the mini state changing. | 101 // tab ends up moving as a result of the mini state changing. |
| 108 // See note in TabMiniStateChanged as to how this relates to | 102 // See note in TabMiniStateChanged as to how this relates to |
| 109 // TabMiniStateChanged. | 103 // TabMiniStateChanged. |
| 110 virtual void TabPinnedStateChanged(TabContents* contents, int index) {} | 104 virtual void TabPinnedStateChanged(TabContents* contents, int index) {} |
| 111 | 105 |
| 112 // Invoked if the mini state of a tab changes. This is not invoked if the | 106 // Invoked if the mini state of a tab changes. This is not invoked if the |
| 113 // tab ends up moving as a result of the mini state changing. | 107 // tab ends up moving as a result of the mini state changing. |
| 114 // NOTE: this is sent when the pinned state of a non-app tab changes and is | 108 // NOTE: this is sent when the pinned state of a non-app tab changes and is |
| 115 // sent in addition to TabPinnedStateChanged. UI code typically need not care | 109 // sent in addition to TabPinnedStateChanged. UI code typically need not care |
| 116 // about TabPinnedStateChanged, but instead this. | 110 // about TabPinnedStateChanged, but instead this. |
| 117 virtual void TabMiniStateChanged(TabContents* contents, int index) {} | 111 virtual void TabMiniStateChanged(TabContents* contents, int index) {} |
| 118 | 112 |
| 119 // Invoked when the blocked state of a tab changes. | 113 // Invoked when the blocked state of a tab changes. |
| 120 // NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal | 114 // NOTE: This is invoked when a tab becomes blocked/unblocked by a tab modal |
| 121 // window. | 115 // window. |
| 122 virtual void TabBlockedStateChanged(TabContents* contents, int index) {} | 116 virtual void TabBlockedStateChanged(TabContents* contents, int index) {} |
| 123 | 117 |
| 124 // The TabStripModel now no longer has any phantom tabs. The implementer may | 118 // The TabStripModel now no longer has any tabs. The implementer may use this |
| 125 // use this as a trigger to try and close the window containing the | 119 // as a trigger to try and close the window containing the TabStripModel, for |
| 126 // TabStripModel, for example... | 120 // example... |
| 127 virtual void TabStripEmpty() {} | 121 virtual void TabStripEmpty() {} |
| 128 }; | 122 }; |
| 129 | 123 |
| 130 /////////////////////////////////////////////////////////////////////////////// | 124 /////////////////////////////////////////////////////////////////////////////// |
| 131 // | 125 // |
| 132 // TabStripModelDelegate | 126 // TabStripModelDelegate |
| 133 // | 127 // |
| 134 // A delegate interface that the TabStripModel uses to perform work that it | 128 // A delegate interface that the TabStripModel uses to perform work that it |
| 135 // can't do itself, such as obtain a container HWND for creating new | 129 // can't do itself, such as obtain a container HWND for creating new |
| 136 // TabContents, creating new TabStripModels for detached tabs, etc. | 130 // TabContents, creating new TabStripModels for detached tabs, etc. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // . Mini-tab. Mini tabs are locked to the left side of the tab strip and | 241 // . Mini-tab. Mini tabs are locked to the left side of the tab strip and |
| 248 // rendered differently (small tabs with only a favicon). The model makes | 242 // rendered differently (small tabs with only a favicon). The model makes |
| 249 // sure all mini-tabs are at the beginning of the tab strip. For example, | 243 // sure all mini-tabs are at the beginning of the tab strip. For example, |
| 250 // if a non-mini tab is added it is forced to be with non-mini tabs. Requests | 244 // if a non-mini tab is added it is forced to be with non-mini tabs. Requests |
| 251 // to move tabs outside the range of the tab type are ignored. For example, | 245 // to move tabs outside the range of the tab type are ignored. For example, |
| 252 // a request to move a mini-tab after non-mini-tabs is ignored. | 246 // a request to move a mini-tab after non-mini-tabs is ignored. |
| 253 // You'll notice there is no explcit api for making a tab a mini-tab, rather | 247 // You'll notice there is no explcit api for making a tab a mini-tab, rather |
| 254 // there are two tab types that are implicitly mini-tabs: | 248 // there are two tab types that are implicitly mini-tabs: |
| 255 // . App. Corresponds to an extension that wants an app tab. App tabs are | 249 // . App. Corresponds to an extension that wants an app tab. App tabs are |
| 256 // identified by TabContents::is_app(). | 250 // identified by TabContents::is_app(). |
| 257 // . Pinned. Any tab can be pinned. A pinned tab is made phantom when closed. | 251 // . Pinned. Any tab can be pinned. Non-app tabs whose pinned state is |
| 258 // Non-app tabs whose pinned state is changed are moved to be with other | 252 // changed are moved to be with other mini-tabs or non-mini tabs. |
| 259 // mini-tabs or non-mini tabs. | |
| 260 // . Phantom. Only pinned tabs may be made phantom. When a tab that can be made | |
| 261 // phantom is closed the renderer is shutdown, a new | |
| 262 // TabContents/NavigationController is created that has not yet loaded the | |
| 263 // renderer and observers are notified via the TabReplacedAt method. When a | |
| 264 // phantom tab is selected the renderer is loaded and the tab is no longer | |
| 265 // phantom. | |
| 266 // Phantom tabs do not prevent the tabstrip from closing, for example if the | |
| 267 // tabstrip has one phantom and one non-phantom tab and the non-phantom tab is | |
| 268 // closed, then the tabstrip/browser are closed. | |
| 269 // | 253 // |
| 270 // A TabStripModel has one delegate that it relies on to perform certain tasks | 254 // A TabStripModel has one delegate that it relies on to perform certain tasks |
| 271 // like creating new TabStripModels (probably hosted in Browser windows) when | 255 // like creating new TabStripModels (probably hosted in Browser windows) when |
| 272 // required. See TabStripDelegate above for more information. | 256 // required. See TabStripDelegate above for more information. |
| 273 // | 257 // |
| 274 // A TabStripModel also has N observers (see TabStripModelObserver above), | 258 // A TabStripModel also has N observers (see TabStripModelObserver above), |
| 275 // which can be registered via Add/RemoveObserver. An Observer is notified of | 259 // which can be registered via Add/RemoveObserver. An Observer is notified of |
| 276 // tab creations, removals, moves, and other interesting events. The | 260 // tab creations, removals, moves, and other interesting events. The |
| 277 // TabStrip implements this interface to know when to create new tabs in | 261 // TabStrip implements this interface to know when to create new tabs in |
| 278 // the View, and the Browser object likewise implements to be able to update | 262 // the View, and the Browser object likewise implements to be able to update |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 TabStripModelDelegate* delegate() const { return delegate_; } | 298 TabStripModelDelegate* delegate() const { return delegate_; } |
| 315 | 299 |
| 316 // Add and remove observers to changes within this TabStripModel. | 300 // Add and remove observers to changes within this TabStripModel. |
| 317 void AddObserver(TabStripModelObserver* observer); | 301 void AddObserver(TabStripModelObserver* observer); |
| 318 void RemoveObserver(TabStripModelObserver* observer); | 302 void RemoveObserver(TabStripModelObserver* observer); |
| 319 | 303 |
| 320 // Retrieve the number of TabContentses/emptiness of the TabStripModel. | 304 // Retrieve the number of TabContentses/emptiness of the TabStripModel. |
| 321 int count() const { return static_cast<int>(contents_data_.size()); } | 305 int count() const { return static_cast<int>(contents_data_.size()); } |
| 322 bool empty() const { return contents_data_.empty(); } | 306 bool empty() const { return contents_data_.empty(); } |
| 323 | 307 |
| 324 // Returns true if there are any non-phantom tabs. When there are no | |
| 325 // non-phantom tabs the delegate is notified by way of TabStripEmpty and the | |
| 326 // browser closes. | |
| 327 bool HasNonPhantomTabs() const; | |
| 328 | |
| 329 // Retrieve the Profile associated with this TabStripModel. | 308 // Retrieve the Profile associated with this TabStripModel. |
| 330 Profile* profile() const { return profile_; } | 309 Profile* profile() const { return profile_; } |
| 331 | 310 |
| 332 // Retrieve the index of the currently selected TabContents. | 311 // Retrieve the index of the currently selected TabContents. |
| 333 int selected_index() const { return selected_index_; } | 312 int selected_index() const { return selected_index_; } |
| 334 | 313 |
| 335 // Returns true if the tabstrip is currently closing all open tabs (via a | 314 // Returns true if the tabstrip is currently closing all open tabs (via a |
| 336 // call to CloseAllTabs). As tabs close, the selection in the tabstrip | 315 // call to CloseAllTabs). As tabs close, the selection in the tabstrip |
| 337 // changes which notifies observers, which can use this as an optimization to | 316 // changes which notifies observers, which can use this as an optimization to |
| 338 // avoid doing meaningless or unhelpful work. | 317 // avoid doing meaningless or unhelpful work. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 bool TabsAreLoading() const; | 432 bool TabsAreLoading() const; |
| 454 | 433 |
| 455 // Returns the controller controller that opened the TabContents at |index|. | 434 // Returns the controller controller that opened the TabContents at |index|. |
| 456 NavigationController* GetOpenerOfTabContentsAt(int index); | 435 NavigationController* GetOpenerOfTabContentsAt(int index); |
| 457 | 436 |
| 458 // Returns the index of the next TabContents in the sequence of TabContentses | 437 // Returns the index of the next TabContents in the sequence of TabContentses |
| 459 // spawned by the specified NavigationController after |start_index|. | 438 // spawned by the specified NavigationController after |start_index|. |
| 460 // If |use_group| is true, the group property of the tab is used instead of | 439 // If |use_group| is true, the group property of the tab is used instead of |
| 461 // the opener to find the next tab. Under some circumstances the group | 440 // the opener to find the next tab. Under some circumstances the group |
| 462 // relationship may exist but the opener may not. | 441 // relationship may exist but the opener may not. |
| 463 // NOTE: this skips phantom tabs. | |
| 464 int GetIndexOfNextTabContentsOpenedBy(const NavigationController* opener, | 442 int GetIndexOfNextTabContentsOpenedBy(const NavigationController* opener, |
| 465 int start_index, | 443 int start_index, |
| 466 bool use_group) const; | 444 bool use_group) const; |
| 467 | 445 |
| 468 // Returns the index of the first TabContents in the model opened by the | 446 // Returns the index of the first TabContents in the model opened by the |
| 469 // specified opener. | 447 // specified opener. |
| 470 // NOTE: this skips phantom tabs. | |
| 471 int GetIndexOfFirstTabContentsOpenedBy(const NavigationController* opener, | 448 int GetIndexOfFirstTabContentsOpenedBy(const NavigationController* opener, |
| 472 int start_index) const; | 449 int start_index) const; |
| 473 | 450 |
| 474 // Returns the index of the last TabContents in the model opened by the | 451 // Returns the index of the last TabContents in the model opened by the |
| 475 // specified opener, starting at |start_index|. | 452 // specified opener, starting at |start_index|. |
| 476 // NOTE: this skips phantom tabs. | |
| 477 int GetIndexOfLastTabContentsOpenedBy(const NavigationController* opener, | 453 int GetIndexOfLastTabContentsOpenedBy(const NavigationController* opener, |
| 478 int start_index) const; | 454 int start_index) const; |
| 479 | 455 |
| 480 // Called by the Browser when a navigation is about to occur in the specified | 456 // Called by the Browser when a navigation is about to occur in the specified |
| 481 // TabContents. Depending on the tab, and the transition type of the | 457 // TabContents. Depending on the tab, and the transition type of the |
| 482 // navigation, the TabStripModel may adjust its selection and grouping | 458 // navigation, the TabStripModel may adjust its selection and grouping |
| 483 // behavior. | 459 // behavior. |
| 484 void TabNavigating(TabContents* contents, PageTransition::Type transition); | 460 void TabNavigating(TabContents* contents, PageTransition::Type transition); |
| 485 | 461 |
| 486 // Forget all Opener relationships that are stored (but _not_ group | 462 // Forget all Opener relationships that are stored (but _not_ group |
| (...skipping 29 matching lines...) Expand all Loading... |
| 516 // See description above class for details on this. | 492 // See description above class for details on this. |
| 517 bool IsMiniTab(int index) const; | 493 bool IsMiniTab(int index) const; |
| 518 | 494 |
| 519 // Is the tab at |index| an app? | 495 // Is the tab at |index| an app? |
| 520 // See description above class for details on app tabs. | 496 // See description above class for details on app tabs. |
| 521 bool IsAppTab(int index) const; | 497 bool IsAppTab(int index) const; |
| 522 | 498 |
| 523 // Returns true if the toolbar is visible for the tab at |index|. | 499 // Returns true if the toolbar is visible for the tab at |index|. |
| 524 bool IsToolbarVisible(int index) const; | 500 bool IsToolbarVisible(int index) const; |
| 525 | 501 |
| 526 // Returns true if the tab is a phantom tab. A phantom tab is one where the | |
| 527 // renderer has not been loaded. | |
| 528 // See description above class for details on phantom tabs. | |
| 529 bool IsPhantomTab(int index) const; | |
| 530 | |
| 531 // Returns true if the tab at |index| is blocked by a tab modal dialog. | 502 // Returns true if the tab at |index| is blocked by a tab modal dialog. |
| 532 bool IsTabBlocked(int index) const; | 503 bool IsTabBlocked(int index) const; |
| 533 | 504 |
| 534 // Returns the index of the first tab that is not a mini-tab. This returns | 505 // Returns the index of the first tab that is not a mini-tab. This returns |
| 535 // |count()| if all of the tabs are mini-tabs, and 0 if none of the tabs are | 506 // |count()| if all of the tabs are mini-tabs, and 0 if none of the tabs are |
| 536 // mini-tabs. | 507 // mini-tabs. |
| 537 int IndexOfFirstNonMiniTab() const; | 508 int IndexOfFirstNonMiniTab() const; |
| 538 | 509 |
| 539 // Returns a valid index for inserting a new tab into this model. |index| is | 510 // Returns a valid index for inserting a new tab into this model. |index| is |
| 540 // the proposed index and |mini_tab| is true if inserting a tab will become | 511 // the proposed index and |mini_tab| is true if inserting a tab will become |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 int GetNewTabCount() const; | 637 int GetNewTabCount() const; |
| 667 | 638 |
| 668 // Convenience for setting the opener pointer for the specified |contents| to | 639 // Convenience for setting the opener pointer for the specified |contents| to |
| 669 // be |opener|'s NavigationController. | 640 // be |opener|'s NavigationController. |
| 670 void SetOpenerForContents(TabContents* contents, TabContents* opener); | 641 void SetOpenerForContents(TabContents* contents, TabContents* opener); |
| 671 | 642 |
| 672 // Selects either the next tab (|foward| is true), or the previous tab | 643 // Selects either the next tab (|foward| is true), or the previous tab |
| 673 // (|forward| is false). | 644 // (|forward| is false). |
| 674 void SelectRelativeTab(bool forward); | 645 void SelectRelativeTab(bool forward); |
| 675 | 646 |
| 676 // Returns the first non-phantom tab starting at |index|, skipping the tab at | 647 // Returns the first tab starting at |index|. |
| 677 // |ignore_index|. | 648 int IndexOfNextTab(int index); |
| 678 int IndexOfNextNonPhantomTab(int index, int ignore_index); | |
| 679 | |
| 680 // Returns true if the tab at the specified index should be made phantom when | |
| 681 // the tab is closing. | |
| 682 bool ShouldMakePhantomOnClose(int index); | |
| 683 | |
| 684 // Makes the tab a phantom tab. | |
| 685 void MakePhantom(int index); | |
| 686 | 649 |
| 687 // Does the work of MoveTabContentsAt. This has no checks to make sure the | 650 // Does the work of MoveTabContentsAt. This has no checks to make sure the |
| 688 // position is valid, those are done in MoveTabContentsAt. | 651 // position is valid, those are done in MoveTabContentsAt. |
| 689 void MoveTabContentsAtImpl(int index, | 652 void MoveTabContentsAtImpl(int index, |
| 690 int to_position, | 653 int to_position, |
| 691 bool select_after_move); | 654 bool select_after_move); |
| 692 | 655 |
| 693 // Returns true if the tab represented by the specified data has an opener | 656 // Returns true if the tab represented by the specified data has an opener |
| 694 // that matches the specified one. If |use_group| is true, then this will | 657 // that matches the specified one. If |use_group| is true, then this will |
| 695 // fall back to check the group relationship as well. | 658 // fall back to check the group relationship as well. |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 typedef ObserverList<TabStripModelObserver> TabStripModelObservers; | 743 typedef ObserverList<TabStripModelObserver> TabStripModelObservers; |
| 781 TabStripModelObservers observers_; | 744 TabStripModelObservers observers_; |
| 782 | 745 |
| 783 // A scoped container for notification registries. | 746 // A scoped container for notification registries. |
| 784 NotificationRegistrar registrar_; | 747 NotificationRegistrar registrar_; |
| 785 | 748 |
| 786 DISALLOW_COPY_AND_ASSIGN(TabStripModel); | 749 DISALLOW_COPY_AND_ASSIGN(TabStripModel); |
| 787 }; | 750 }; |
| 788 | 751 |
| 789 #endif // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ | 752 #endif // CHROME_BROWSER_TABS_TAB_STRIP_MODEL_H_ |
| OLD | NEW |