CTTabStripController.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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-chromium file.
  4. #pragma once
  5. #import <Cocoa/Cocoa.h>
  6. #import "CTTabControllerTarget.h"
  7. #import "URLDropTarget.h"
  8. @class NewTabButton;
  9. @class CTTabContentsController;
  10. @class CTTabView;
  11. @class CTTabStripView;
  12. @class CTTabContents;
  13. @class CTBrowser;
  14. @class CTTabStripModel;
  15. @class CTTabController;
  16. // A class that handles managing the tab strip in a browser window. It uses
  17. // a supporting C++ bridge object to register for notifications from the
  18. // TabStripModel. The Obj-C part of this class handles drag and drop and all
  19. // the other Cocoa-y aspects.
  20. //
  21. // For a full description of the design, see
  22. // http://www.chromium.org/developers/design-documents/tab-strip-mac
  23. @interface CTTabStripController : NSObject<CTTabControllerTarget, URLDropTargetController>
  24. @property(nonatomic) CGFloat indentForControls;
  25. // Show or hide the new tab button. The button is hidden immediately, but
  26. // waits until the next call to |-layoutTabs| to show it again.
  27. @property(nonatomic, assign) BOOL showsNewTabButton;
  28. // Ensure that the new tab button is never shown if set.
  29. @property(nonatomic, assign) BOOL disableNewTabButton;
  30. // Initialize the controller with a view and browser that contains
  31. // everything else we'll need. |switchView| is the view whose contents get
  32. // "switched" every time the user switches tabs. The children of this view
  33. // will be released, so if you want them to stay around, make sure
  34. // you have retained them.
  35. - (id)initWithView:(CTTabStripView*)view
  36. switchView:(NSView*)switchView
  37. browser:(CTBrowser*)browser;
  38. // Return the view for the currently active tab.
  39. - (NSView*)activeTabView;
  40. // Set the frame of the active tab, also updates the internal frame dict.
  41. - (void)setFrameOfActiveTab:(NSRect)frame;
  42. // Move the given tab at index |from| in this window to the location of the
  43. // current placeholder.
  44. - (void)moveTabFromIndex:(NSInteger)from;
  45. // Drop a given CTTabContents at the location of the current placeholder. If there
  46. // is no placeholder, it will go at the end. Used when dragging from another
  47. // window when we don't have access to the CTTabContents as part of our strip.
  48. // |frame| is in the coordinate system of the tab strip view and represents
  49. // where the user dropped the new tab so it can be animated into its correct
  50. // location when the tab is added to the model. If the tab was pinned in its
  51. // previous window, setting |pinned| to YES will propagate that state to the
  52. // new window. Mini-tabs are either app or pinned tabs; the app state is stored
  53. // by the |contents|, but the |pinned| state is the caller's responsibility.
  54. - (void)dropTabContents:(CTTabContents*)contents
  55. withFrame:(NSRect)frame
  56. asPinnedTab:(BOOL)pinned;
  57. // Returns the index of the subview |view|. Returns -1 if not present. Takes
  58. // closing tabs into account such that this index will correctly match the tab
  59. // model. If |view| is in the process of closing, returns -1, as closing tabs
  60. // are no longer in the model.
  61. - (NSInteger)modelIndexForTabView:(NSView*)view;
  62. // Return the view at a given index.
  63. - (NSView*)viewAtIndex:(NSUInteger)index;
  64. // Return the number of tab views in the tab strip. It's same as number of tabs
  65. // in the model, except when a tab is closing, which will be counted in views
  66. // count, but no longer in the model.
  67. - (NSUInteger)viewsCount;
  68. // Set the placeholder for a dragged tab, allowing the |frame| and |strechiness|
  69. // to be specified. This causes this tab to be rendered in an arbitrary position
  70. - (void)insertPlaceholderForTab:(CTTabView*)tab
  71. frame:(NSRect)frame;
  72. // Returns whether or not |tab| can still be fully seen in the tab strip or if
  73. // its current position would cause it be obscured by things such as the edge
  74. // of the window or the window decorations. Returns YES only if the entire tab
  75. // is visible.
  76. - (BOOL)isTabFullyVisible:(CTTabView*)tab;
  77. // Force the tabs to rearrange themselves to reflect the current model.
  78. - (void)layoutTabs;
  79. - (void)layoutTabsWithoutAnimation;
  80. // Are we in rapid (tab) closure mode? I.e., is a full layout deferred (while
  81. // the user closes tabs)? Needed to overcome missing clicks during rapid tab
  82. // closure.
  83. - (BOOL)inRapidClosureMode;
  84. // Returns YES if the user is allowed to drag tabs on the strip at this moment.
  85. // For example, this returns NO if there are any pending tab close animtations.
  86. - (BOOL)tabDraggingAllowed;
  87. // Default height for tabs.
  88. + (CGFloat)defaultTabHeight;
  89. // Default indentation for tabs (see |indentForControls_|).
  90. + (CGFloat)defaultIndentForControls;
  91. // Returns the (lazily created) window sheet controller of this window. Used
  92. // for the per-tab sheets.
  93. //- (GTMWindowSheetController*)sheetController;
  94. // Destroys the window sheet controller of this window, if it exists. The sheet
  95. // controller can be recreated by a subsequent call to |-sheetController|. Must
  96. // not be called if any sheets are currently open.
  97. // TODO(viettrungluu): This is temporary code needed to allow sheets to work
  98. // (read: not crash) in fullscreen mode. Once GTMWindowSheetController is
  99. // modified to support moving sheets between windows, this code can go away.
  100. // http://crbug.com/19093.
  101. //- (void)destroySheetController;
  102. // Returns the currently active CTTabContentsController.
  103. - (CTTabContentsController*)activeTabContentsController;
  104. // See comments in browser_window_controller.h for documentation about these
  105. // functions.
  106. //- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window;
  107. //- (void)removeConstrainedWindow:(ConstrainedWindowMac*)window;
  108. //- (void)updateDevToolsForContents:(CTTabContents*)contents;
  109. @end
  110. // Notification sent when the number of tabs changes. The object will be this
  111. // controller.
  112. extern NSString* const kTabStripNumberOfTabsChanged;
  113. @interface CTTabStripController (KMExtensions)
  114. @property (nonatomic, assign) BOOL isHomeFixWidth;
  115. - (void)km_dropTabContents:(CTTabContents*)contents withFrame:(NSRect)frame asPinnedTab:(BOOL)pinned toIndex:(NSInteger)toIndex;
  116. @end