OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "chrome/browser/tab_contents/web_contents_view_mac.h" | 5 #include "chrome/browser/tab_contents/web_contents_view_mac.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. | 7 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. |
| 8 #include "chrome/browser/cocoa/sad_tab_view.h" |
8 #include "chrome/browser/renderer_host/render_widget_host.h" | 9 #include "chrome/browser/renderer_host/render_widget_host.h" |
9 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 10 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
10 #include "chrome/browser/tab_contents/web_contents.h" | 11 #include "chrome/browser/tab_contents/web_contents.h" |
11 | 12 |
12 #include "chrome/common/temp_scaffolding_stubs.h" | 13 #include "chrome/common/temp_scaffolding_stubs.h" |
13 | 14 |
14 // static | 15 // static |
15 WebContentsView* WebContentsView::Create(WebContents* web_contents) { | 16 WebContentsView* WebContentsView::Create(WebContents* web_contents) { |
16 return new WebContentsViewMac(web_contents); | 17 return new WebContentsViewMac(web_contents); |
17 } | 18 } |
18 | 19 |
19 WebContentsViewMac::WebContentsViewMac(WebContents* web_contents) | 20 WebContentsViewMac::WebContentsViewMac(WebContents* web_contents) |
20 : web_contents_(web_contents) { | 21 : web_contents_(web_contents) { |
| 22 registrar_.Add(this, NotificationType::WEB_CONTENTS_CONNECTED, |
| 23 Source<WebContents>(web_contents)); |
| 24 registrar_.Add(this, NotificationType::WEB_CONTENTS_DISCONNECTED, |
| 25 Source<WebContents>(web_contents)); |
21 } | 26 } |
22 | 27 |
23 WebContentsViewMac::~WebContentsViewMac() { | 28 WebContentsViewMac::~WebContentsViewMac() { |
24 } | 29 } |
25 | 30 |
26 WebContents* WebContentsViewMac::GetWebContents() { | 31 WebContents* WebContentsViewMac::GetWebContents() { |
27 return web_contents_; | 32 return web_contents_; |
28 } | 33 } |
29 | 34 |
30 void WebContentsViewMac::CreateView() { | 35 void WebContentsViewMac::CreateView() { |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 if (!widget_host->process()->channel()) { | 230 if (!widget_host->process()->channel()) { |
226 // The view has gone away or the renderer crashed. Nothing to do. | 231 // The view has gone away or the renderer crashed. Nothing to do. |
227 return; | 232 return; |
228 } | 233 } |
229 | 234 |
230 // Reparenting magic goes here. TODO(avi): fix | 235 // Reparenting magic goes here. TODO(avi): fix |
231 | 236 |
232 widget_host->Init(); | 237 widget_host->Init(); |
233 } | 238 } |
234 | 239 |
| 240 void WebContentsViewMac::Observe(NotificationType type, |
| 241 const NotificationSource& source, |
| 242 const NotificationDetails& details) { |
| 243 switch (type.value) { |
| 244 case NotificationType::WEB_CONTENTS_CONNECTED: { |
| 245 if (sad_tab_.get()) { |
| 246 [sad_tab_.get() removeFromSuperview]; |
| 247 sad_tab_.reset(); |
| 248 } |
| 249 break; |
| 250 } |
| 251 case NotificationType::WEB_CONTENTS_DISCONNECTED: { |
| 252 SadTabView* view = [[SadTabView alloc] initWithFrame:NSZeroRect]; |
| 253 CFRetain(view); |
| 254 [view release]; |
| 255 sad_tab_.reset(view); |
| 256 |
| 257 // Set as the dominant child. |
| 258 [cocoa_view_.get() addSubview:view]; |
| 259 [view setFrame:[cocoa_view_.get() bounds]]; |
| 260 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 261 break; |
| 262 } |
| 263 default: |
| 264 NOTREACHED() << "Got a notification we didn't register for."; |
| 265 } |
| 266 } |
| 267 |
235 @implementation WebContentsViewCocoa | 268 @implementation WebContentsViewCocoa |
236 | 269 |
237 // Tons of stuff goes here, where we grab events going on in Cocoaland and send | 270 // Tons of stuff goes here, where we grab events going on in Cocoaland and send |
238 // them into the C++ system. TODO(avi): all that jazz | 271 // them into the C++ system. TODO(avi): all that jazz |
239 | 272 |
240 @end | 273 @end |
OLD | NEW |