CTTabContents.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #pragma once
  2. #import <Cocoa/Cocoa.h>
  3. @class CTTabStripModel;
  4. @class CTBrowser;
  5. extern NSString *const CTTabContentsDidCloseNotification;
  6. //
  7. // Visibility states:
  8. //
  9. // - isVisible: if the tab is visible (on screen). You may implement the
  10. // callbacks in order to enable/disable "background" tasks like
  11. // animations.
  12. // Callbacks:
  13. // - tabDidBecomeVisible
  14. // - tabDidResignVisible
  15. //
  16. // - isActive: if the tab is the active tab in its window. Note that a tab
  17. // can be active withouth being visible (i.e. the window is
  18. // minimized or the app is hidden). If your tabs contain
  19. // user-interactive components, you should save and restore focus
  20. // by sublcassing the callbacks.
  21. // Callbacks:
  22. // - tabDidBecomeActive
  23. // - tabDidResignActive
  24. //
  25. // - isKey: if the tab has the users focus. Only one tab in the application
  26. // can be key at a given time. (Note that the OS will automatically
  27. // restore any focus to user-interactive components.)
  28. // Callbacks:
  29. // - tabDidBecomeKey
  30. // - tabDidResignKey
  31. //
  32. @protocol TabContentsDelegate;
  33. @interface CTTabContents : NSDocument {
  34. BOOL isApp_;
  35. BOOL isLoading_;
  36. BOOL isWaitingForResponse_;
  37. BOOL isCrashed_;
  38. BOOL isVisible_;
  39. BOOL isActive_;
  40. BOOL isTeared_; // YES while being "teared" (dragged between windows)
  41. BOOL isPinned_;
  42. BOOL isBlocked_;
  43. id delegate_;
  44. unsigned int closedByUserGesture_; // TabStripModel::CloseTypes
  45. NSView *view_; // the actual content
  46. NSString *title_; // title of this tab
  47. NSImage *icon_; // tab icon (nil means no or default icon)
  48. CTBrowser *browser_;
  49. CTTabContents* parentOpener_; // the tab which opened this tab (unless nil)
  50. }
  51. @property(assign, nonatomic) BOOL isApp;
  52. @property(assign, nonatomic) BOOL isLoading;
  53. @property(assign, nonatomic) BOOL isCrashed;
  54. @property(assign, nonatomic) BOOL isHome;
  55. @property(assign, nonatomic) BOOL isWaitingForResponse;
  56. @property(assign, nonatomic, setter = setVisible:) BOOL isVisible;
  57. @property(assign, nonatomic, setter = setActive:) BOOL isActive;
  58. @property(assign, nonatomic, setter = setTeared:) BOOL isTeared;
  59. @property(retain, nonatomic) id <TabContentsDelegate> delegate;
  60. @property(assign, nonatomic) unsigned int closedByUserGesture;
  61. @property(retain, nonatomic) IBOutlet NSView *view;
  62. @property(retain, nonatomic) NSString *title;
  63. @property(retain, nonatomic) NSImage *icon;
  64. @property(retain, nonatomic) CTBrowser *browser;
  65. @property(strong, nonatomic) CTTabContents* parentOpener;
  66. // If this returns YES, special icons like throbbers and "crashed" is
  67. // displayed, even if |icon| is nil. By default this returns YES.
  68. @property(readonly, nonatomic) BOOL hasIcon;
  69. // Initialize a new CTTabContents object.
  70. // The default implementation does nothing with |baseContents| but subclasses
  71. // can use |baseContents| (the active CTTabContents, if any) to perform
  72. // customized initialization.
  73. -(id)initWithBaseTabContents:(CTTabContents*)baseContents;
  74. // Called when the tab should be destroyed (involves some finalization).
  75. //-(void)destroy:(CTTabStripModel *)sender;
  76. #pragma mark Action
  77. // Selects the tab in it's window and brings the window to front
  78. - (void)makeKeyAndOrderFront:(id)sender;
  79. // Give first-responder status to view_ if isVisible
  80. - (BOOL)becomeFirstResponder;
  81. #pragma mark -
  82. #pragma mark Callbacks
  83. // Called when this tab may be closing (unless CTBrowser respond no to
  84. // canCloseTab).
  85. -(void)closingOfTabDidStart:(CTTabStripModel *)model;
  86. // The following three callbacks are meant to be implemented by subclasses:
  87. // Called when this tab was inserted into a browser
  88. - (void)tabDidInsertIntoBrowser:(CTBrowser*)browser
  89. atIndex:(NSInteger)index
  90. inForeground:(BOOL)foreground;
  91. // Called when this tab replaced another tab
  92. - (void)tabReplaced:(CTTabContents*)oldContents
  93. inBrowser:(CTBrowser*)browser
  94. atIndex:(NSInteger)index;
  95. // Called when this tab is about to close
  96. - (void)tabWillCloseInBrowser:(CTBrowser*)browser atIndex:(NSInteger)index;
  97. // Called when this tab was removed from a browser
  98. - (void)tabDidDetachFromBrowser:(CTBrowser*)browser atIndex:(NSInteger)index;
  99. // The following callbacks called when the tab's visible state changes. If you
  100. // override, be sure and invoke super's implementation. See "Visibility states"
  101. // in the header of this file for details.
  102. // Called when this tab become visible on screen. This is a good place to resume
  103. // animations.
  104. -(void)tabDidBecomeVisible;
  105. // Called when this tab is no longer visible on screen. This is a good place to
  106. // pause animations.
  107. -(void)tabDidResignVisible;
  108. // Called when this tab is about to become the active tab. Followed by a call
  109. // to |tabDidBecomeActive|
  110. -(void)tabWillBecomeActive;
  111. // Called when this tab is about to resign as the active tab. Followed by a
  112. // call to |tabDidResignActive|
  113. -(void)tabWillResignActive;
  114. // Called when this tab became the active tab in its window. This does
  115. // neccessarily not mean it's visible (app might be hidden or window might be
  116. // minimized). The default implementation makes our view the first responder, if
  117. // visible.
  118. -(void)tabDidBecomeActive;
  119. // Called when another tab in our window "stole" the selection.
  120. -(void)tabDidResignActive;
  121. // Called when this tab is about to being "teared" (when dragging a tab from one
  122. // window to another).
  123. -(void)tabWillBecomeTeared;
  124. // Called when this tab is teared and is about to "land" into a window.
  125. -(void)tabWillResignTeared;
  126. // Called when this tab was teared and just landed in a window. The default
  127. // implementation makes our view the first responder, restoring focus.
  128. -(void)tabDidResignTeared;
  129. // Called when the frame has changed, which isn't too often.
  130. // There are at least two cases when it's called:
  131. // - When the tab's view is first inserted into the view hiearchy
  132. // - When a torn off tab is moves into a window with other dimensions than the
  133. // initial window.
  134. -(void)viewFrameDidChange:(NSRect)newFrame;
  135. @end
  136. @protocol TabContentsDelegate
  137. -(BOOL)canReloadContents:(CTTabContents*)contents;
  138. -(BOOL)reload; // should set contents->isLoading_ = YES
  139. @end
  140. @interface CTTabContents(KMExtensions)
  141. @property (nonatomic, assign) BOOL isNewTab;
  142. @end