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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_TAB_CONTENTS_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_TAB_CONTENTS_CONTROLLER_H_
8 #include <Cocoa/Cocoa.h>
10 #include "base/memory/scoped_ptr.h"
12 class FullscreenObserver
;
18 // A class that controls the WebContents view. It internally creates a container
19 // view (the NSView accessed by calling |-view|) which manages the layout and
20 // display of the WebContents view.
22 // Client code that inserts [controller view] into the view hierarchy needs to
23 // beforehand call the |-ensureContentsSizeDoesNotChange| method. This will
24 // avoid multiple resize messages being sent to the renderer and triggering
25 // redundant and costly layouts. After the view has been inserted, client code
26 // calls |-ensureContentsVisible| to display the WebContents view.
28 // AutoEmbedFullscreen mode: When enabled, TabContentsController will observe
29 // for WebContents fullscreen changes and automatically swap the normal
30 // WebContents view with the fullscreen view (if different). In addition, if a
31 // WebContents is being screen-captured, the view will be centered within the
32 // container view, sized to the aspect ratio of the capture video resolution,
33 // and scaling will be avoided whenever possible.
34 @interface TabContentsController
: NSViewController
{
36 content::WebContents
* contents_
; // weak
37 // When |fullscreenObserver_| is not-NULL, TabContentsController monitors for
38 // and auto-embeds fullscreen widgets as a subview.
39 scoped_ptr
<FullscreenObserver
> fullscreenObserver_
;
40 // Set to true while TabContentsController is embedding a fullscreen widget
41 // view as a subview instead of the normal WebContentsView render view. Note:
42 // This will be false in the case of non-Flash fullscreen.
43 BOOL isEmbeddingFullscreenWidget_
;
45 @
property(readonly
, nonatomic
) content::WebContents
* webContents
;
47 // Create the contents of a tab represented by |contents|.
48 - (id
)initWithContents
:(content::WebContents
*)contents
;
50 // Call when the container view owned by TabContentsController is about to be
51 // resized and inserted into the view hierarchy, so as to not trigger
52 // unnecessary content re-layout.
53 - (void)ensureContentsSizeDoesNotChange
;
55 // Call after the container view is inserted into the view hierarchy and
56 // properly sized. Then, this method will select either the WebContents view or
57 // the fullscreen view and swap it into the view hierarchy for display.
58 - (void)ensureContentsVisible
;
60 // Call to change the underlying web contents object. View is not changed,
61 // call |-ensureContentsVisible| to display the |newContents|'s render widget
63 - (void)changeWebContents
:(content::WebContents
*)newContents
;
65 // Called when the tab contents is the currently selected tab and is about to be
66 // removed from the view hierarchy.
67 - (void)willBecomeUnselectedTab
;
69 // Called when the tab contents is about to be put into the view hierarchy as
70 // the selected tab. Handles things such as ensuring the toolbar is correctly
72 - (void)willBecomeSelectedTab
;
74 // Called when the tab contents is updated in some non-descript way (the
75 // notification from the model isn't specific). |updatedContents| could reflect
76 // an entirely new tab contents object.
77 - (void)tabDidChange
:(content::WebContents
*)updatedContents
;
79 // Called to switch the container's subview to the WebContents-owned fullscreen
80 // widget or back to WebContentsView's widget.
81 - (void)toggleFullscreenWidget
:(BOOL
)enterFullscreen
;
85 #endif // CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_TAB_CONTENTS_CONTROLLER_H_