CTTabWindowController.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. // A class acting as the Objective-C window controller for a window that has
  6. // tabs which can be dragged around. Tabs can be re-arranged within the same
  7. // window or dragged into other CTTabWindowController windows. This class doesn't
  8. // know anything about the actual tab implementation or model, as that is fairly
  9. // application-specific. It only provides an API to be overridden by subclasses
  10. // to fill in the details.
  11. //
  12. // This assumes that there will be a view in the nib, connected to
  13. // |tabContentArea_|, that indicates the content that it switched when switching
  14. // between tabs. It needs to be a regular NSView, not something like an NSBox
  15. // because the CTTabStripController makes certain assumptions about how it can
  16. // swap out subviews.
  17. //
  18. // The tab strip is placed outside the window's content area, overlapping the
  19. // title area and window controls and will be stretched to fill the width
  20. // of the window.
  21. #import <Cocoa/Cocoa.h>
  22. @class CTTabStripView;
  23. @class CTTabView;
  24. @class KMToolbarRightView;
  25. @class KMUploadFilePanel;
  26. @class KMFileSearchView;
  27. @interface CTTabWindowController : NSWindowController<NSWindowDelegate>
  28. @property(readonly, nonatomic) CTTabStripView* tabStripView;
  29. @property(readonly, nonatomic) NSView* tabContentArea;
  30. @property(readonly, nonatomic) NSView* rightStripView;
  31. @property(readonly, nonatomic) NSView* homeRightStripView;
  32. @property(readonly, nonatomic) NSView* fileSearchView;
  33. @property (strong) IBOutlet KMToolbarRightView *rightTabStripView_;
  34. @property(strong) IBOutlet KMToolbarRightView* homeRightTabStripView_;
  35. @property(weak, nonatomic) IBOutlet KMUploadFilePanel *fileUploadPanel;
  36. @property(weak, nonatomic) IBOutlet KMFileSearchView *fileSearchView_;
  37. // Used during tab dragging to turn on/off the overlay window when a tab
  38. // is torn off. If -deferPerformClose (below) is used, -removeOverlay will
  39. // cause the controller to be autoreleased before returning.
  40. - (void)showOverlay;
  41. - (void)removeOverlay;
  42. - (NSWindow*)overlayWindow;
  43. // Returns YES if it is ok to constrain the window's frame to fit the screen.
  44. - (BOOL)shouldConstrainFrameRect;
  45. // A collection of methods, stubbed out in this base class, that provide
  46. // the implementation of tab dragging based on whatever model is most
  47. // appropriate.
  48. // Layout the tabs based on the current ordering of the model.
  49. - (void)layoutTabs;
  50. // Creates a new window by pulling the given tab out and placing it in
  51. // the new window. Returns the controller for the new window. The size of the
  52. // new window will be the same size as this window.
  53. - (CTTabWindowController*)detachTabToNewWindow:(CTTabView*)tabView;
  54. // Make room in the tab strip for |tab| at the given x coordinate. Will hide the
  55. // new tab button while there's a placeholder. Subclasses need to call the
  56. // superclass implementation.
  57. - (void)insertPlaceholderForTab:(CTTabView*)tab
  58. frame:(NSRect)frame;
  59. // Removes the placeholder installed by |-insertPlaceholderForTab:atLocation:|
  60. // and restores the new tab button. Subclasses need to call the superclass
  61. // implementation.
  62. - (void)removePlaceholder;
  63. // The follow return YES if tab dragging/tab tearing (off the tab strip)/window
  64. // movement is currently allowed. Any number of things can choose to disable it,
  65. // such as pending animations. The default implementations always return YES.
  66. // Subclasses should override as appropriate.
  67. - (BOOL)tabDraggingAllowed;
  68. - (BOOL)tabTearingAllowed;
  69. - (BOOL)windowMovementAllowed;
  70. // Called when dragging of teared tab in an overlay window occurs
  71. -(void)willStartTearingTab;
  72. -(void)willEndTearingTab;
  73. -(void)didEndTearingTab;
  74. // Show or hide the new tab button. The button is hidden immediately, but
  75. // waits until the next call to |-layoutTabs| to show it again.
  76. @property(nonatomic, assign) BOOL showsNewTabButton;
  77. // Enables the content views to be transparent, showing the desktop behind the
  78. // window if set. Also controls how the CTTabStripView draws itself (so that it
  79. // will NOT draw transparently)
  80. @property(nonatomic, assign) BOOL enableTransparentContent;
  81. // Returns whether or not |tab| can still be fully seen in the tab strip or if
  82. // its current position would cause it be obscured by things such as the edge
  83. // of the window or the window decorations. Returns YES only if the entire tab
  84. // is visible. The default implementation always returns YES.
  85. - (BOOL)isTabFullyVisible:(CTTabView*)tab;
  86. // Called to check if the receiver can receive dragged tabs from
  87. // source. Return YES if so. The default implementation returns NO.
  88. - (BOOL)canReceiveFrom:(CTTabWindowController*)source;
  89. // Move a given tab view to the location of the current placeholder. If there is
  90. // no placeholder, it will go at the end. |controller| is the window controller
  91. // of a tab being dropped from a different window. It will be nil if the drag is
  92. // within the window, otherwise the tab is removed from that window before being
  93. // placed into this one. The implementation will call |-removePlaceholder| since
  94. // the drag is now complete. This also calls |-layoutTabs| internally so
  95. // clients do not need to call it again.
  96. - (void)moveTabView:(NSView*)view
  97. fromController:(CTTabWindowController*)controller;
  98. // Number of tabs in the tab strip. Useful, for example, to know if we're
  99. // dragging the only tab in the window. This includes pinned tabs (both live
  100. // and not).
  101. - (NSInteger)numberOfTabs;
  102. // YES if there are tabs in the tab strip which have content, allowing for
  103. // the notion of tabs in the tab strip that are placeholders, but
  104. // currently have no content.
  105. - (BOOL)hasLiveTabs;
  106. // Return the view of the active tab.
  107. - (NSView *)activeTabView;
  108. // The title of the active tab.
  109. - (NSString*)activeTabTitle;
  110. // Called to check whether or not this controller's window has a tab strip (YES
  111. // if it does, NO otherwise). The default implementation returns YES.
  112. - (BOOL)hasTabStrip;
  113. // Get/set whether a particular tab is draggable between windows.
  114. - (BOOL)isTabDraggable:(NSView*)tabView;
  115. - (void)setTab:(NSView*)tabView isDraggable:(BOOL)draggable;
  116. // Tell the window that it needs to call performClose: as soon as the current
  117. // drag is complete. This prevents a window (and its overlay) from going away
  118. // during a drag.
  119. - (void)deferPerformClose;
  120. @end
  121. @interface CTTabWindowController(ProtectedMethods)
  122. // Tells the tab strip to forget about this tab in preparation for it being
  123. // put into a different tab strip, such as during a drop on another window.
  124. - (void)detachTabView:(NSView*)view;
  125. // Called when the size of the window content area has changed. Override to
  126. // position specific views. Base class implementation does nothing.
  127. - (void)layoutSubviews;
  128. @end