Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.mm

Issue 23477051: Embed Flash Fullscreen widget within browser window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" 5 #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/mac/scoped_nsobject.h" 9 #include "base/mac/scoped_nsobject.h"
10 #include "chrome/browser/devtools/devtools_window.h" 10 #include "chrome/browser/devtools/devtools_window.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/render_widget_host_view.h" 12 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/browser/web_contents_observer.h"
14 #include "content/public/browser/web_contents_view.h" 15 #include "content/public/browser/web_contents_view.h"
15 16
16 using content::WebContents; 17 using content::WebContents;
18 using content::WebContentsObserver;
19
20 class FullscreenObserver : public WebContentsObserver {
21 public:
22 explicit FullscreenObserver(TabContentsController* controller)
23 : controller_(controller) {}
24
25 void Observe(content::WebContents* new_web_contents) {
26 WebContentsObserver::Observe(new_web_contents);
27 }
28
29 virtual void DidShowFullscreenWidget(int routing_id) OVERRIDE {
30 [controller_ toggleFullscreenWidget:YES];
31 }
32
33 virtual void DidDestroyFullscreenWidget(int routing_id) OVERRIDE {
34 [controller_ toggleFullscreenWidget:NO];
35 }
36
37 private:
38 TabContentsController* const controller_;
39 };
17 40
18 @implementation TabContentsController 41 @implementation TabContentsController
19 @synthesize webContents = contents_; 42 @synthesize webContents = contents_;
20 43
21 - (id)initWithContents:(WebContents*)contents { 44 - (id)initWithContents:(WebContents*)contents
45 andAutoEmbedFullscreen:(BOOL)enableEmbeddedFullscreen {
22 if ((self = [super initWithNibName:nil bundle:nil])) { 46 if ((self = [super initWithNibName:nil bundle:nil])) {
23 contents_ = contents; 47 contents_ = contents;
48 if (enableEmbeddedFullscreen) {
49 fullscreenObserver_.reset(new FullscreenObserver(self));
50 fullscreenObserver_->Observe(contents_);
51 }
52 isEmbeddingFullscreenWidget_ = NO;
24 } 53 }
25 return self; 54 return self;
26 } 55 }
27 56
28 - (void)dealloc { 57 - (void)dealloc {
29 // make sure our contents have been removed from the window 58 // make sure our contents have been removed from the window
30 [[self view] removeFromSuperview]; 59 [[self view] removeFromSuperview];
31 [super dealloc]; 60 [super dealloc];
32 } 61 }
33 62
34 - (void)loadView { 63 - (void)loadView {
35 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]); 64 base::scoped_nsobject<NSView> view([[NSView alloc] initWithFrame:NSZeroRect]);
36 [view setAutoresizingMask:NSViewHeightSizable|NSViewWidthSizable]; 65 [view setAutoresizingMask:NSViewHeightSizable|NSViewWidthSizable];
37 [self setView:view]; 66 [self setView:view];
38 } 67 }
39 68
40 - (void)ensureContentsSizeDoesNotChange { 69 - (void)ensureContentsSizeDoesNotChange {
41 NSView* contentsContainer = [self view]; 70 NSView* contentsContainer = [self view];
42 NSArray* subviews = [contentsContainer subviews]; 71 NSArray* subviews = [contentsContainer subviews];
43 if ([subviews count] > 0) { 72 if ([subviews count] > 0)
44 [contents_->GetView()->GetNativeView() 73 [[subviews objectAtIndex:0] setAutoresizingMask:NSViewNotSizable];
45 setAutoresizingMask:NSViewNotSizable];
46 }
47 } 74 }
48 75
49 // Call when the tab view is properly sized and the render widget host view 76 // Call when the tab view is properly sized and the render widget host view
50 // should be put into the view hierarchy. 77 // should be put into the view hierarchy.
51 - (void)ensureContentsVisible { 78 - (void)ensureContentsVisible {
52 if (!contents_) 79 if (!contents_)
53 return; 80 return;
54 NSView* contentsContainer = [self view]; 81 NSView* contentsContainer = [self view];
55 NSArray* subviews = [contentsContainer subviews]; 82 NSArray* subviews = [contentsContainer subviews];
56 NSView* contentsNativeView = contents_->GetView()->GetNativeView(); 83 NSView* contentsNativeView;
84 content::RenderWidgetHostView* const fullscreen_view =
85 isEmbeddingFullscreenWidget_ ?
86 contents_->GetFullscreenRenderWidgetHostView() : NULL;
87 if (fullscreen_view) {
88 contentsNativeView = fullscreen_view->GetNativeView();
89 } else {
90 isEmbeddingFullscreenWidget_ = NO;
91 contentsNativeView = contents_->GetView()->GetNativeView();
92 }
57 [contentsNativeView setFrame:[contentsContainer frame]]; 93 [contentsNativeView setFrame:[contentsContainer frame]];
58 if ([subviews count] == 0) { 94 if ([subviews count] == 0) {
59 [contentsContainer addSubview:contentsNativeView]; 95 [contentsContainer addSubview:contentsNativeView];
60 } else if ([subviews objectAtIndex:0] != contentsNativeView) { 96 } else if ([subviews objectAtIndex:0] != contentsNativeView) {
61 [contentsContainer replaceSubview:[subviews objectAtIndex:0] 97 [contentsContainer replaceSubview:[subviews objectAtIndex:0]
62 with:contentsNativeView]; 98 with:contentsNativeView];
63 } 99 }
64 [contentsNativeView setAutoresizingMask:NSViewWidthSizable| 100 [contentsNativeView setAutoresizingMask:NSViewWidthSizable|
65 NSViewHeightSizable]; 101 NSViewHeightSizable];
66 // The rendering path with overlapping views disabled causes bugs when 102 // The rendering path with overlapping views disabled causes bugs when
67 // transitioning between composited and non-composited mode. 103 // transitioning between composited and non-composited mode.
68 // http://crbug.com/279472 104 // http://crbug.com/279472
69 contents_->GetView()->SetAllowOverlappingViews(true); 105 if (!fullscreen_view)
106 contents_->GetView()->SetAllowOverlappingViews(true);
70 } 107 }
71 108
72 - (void)changeWebContents:(WebContents*)newContents { 109 - (void)changeWebContents:(WebContents*)newContents {
73 contents_ = newContents; 110 contents_ = newContents;
111 if (fullscreenObserver_) {
112 fullscreenObserver_->Observe(contents_);
113 isEmbeddingFullscreenWidget_ =
114 contents_ && contents_->GetFullscreenRenderWidgetHostView();
115 } else {
116 isEmbeddingFullscreenWidget_ = NO;
117 }
74 } 118 }
75 119
76 // Returns YES if the tab represented by this controller is the front-most. 120 // Returns YES if the tab represented by this controller is the front-most.
77 - (BOOL)isCurrentTab { 121 - (BOOL)isCurrentTab {
78 // We're the current tab if we're in the view hierarchy, otherwise some other 122 // We're the current tab if we're in the view hierarchy, otherwise some other
79 // tab is. 123 // tab is.
80 return [[self view] superview] ? YES : NO; 124 return [[self view] superview] ? YES : NO;
81 } 125 }
82 126
83 - (void)willBecomeUnselectedTab { 127 - (void)willBecomeUnselectedTab {
(...skipping 23 matching lines...) Expand all
107 // Do not explicitly call Focus() here, as the RWHV may not actually have 151 // Do not explicitly call Focus() here, as the RWHV may not actually have
108 // focus (for example, if the omnibox has focus instead). The WebContents 152 // focus (for example, if the omnibox has focus instead). The WebContents
109 // logic will restore focus to the appropriate view. 153 // logic will restore focus to the appropriate view.
110 } 154 }
111 155
112 - (void)tabDidChange:(WebContents*)updatedContents { 156 - (void)tabDidChange:(WebContents*)updatedContents {
113 // Calling setContentView: here removes any first responder status 157 // Calling setContentView: here removes any first responder status
114 // the view may have, so avoid changing the view hierarchy unless 158 // the view may have, so avoid changing the view hierarchy unless
115 // the view is different. 159 // the view is different.
116 if ([self webContents] != updatedContents) { 160 if ([self webContents] != updatedContents) {
117 contents_ = updatedContents; 161 [self changeWebContents:updatedContents];
118 [self ensureContentsVisible]; 162 [self ensureContentsVisible];
119 } 163 }
120 } 164 }
121 165
166 - (void)toggleFullscreenWidget:(BOOL)enterFullscreen {
167 isEmbeddingFullscreenWidget_ = enterFullscreen &&
168 contents_ && contents_->GetFullscreenRenderWidgetHostView();
169 [self ensureContentsVisible];
170 }
171
122 @end 172 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698