OLD | NEW |
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 <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
6 | 6 |
7 #import "content/browser/web_contents/web_contents_view_mac.h" | 7 #import "content/browser/web_contents/web_contents_view_mac.h" |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); | 75 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); |
76 *render_view_host_delegate_view = rv; | 76 *render_view_host_delegate_view = rv; |
77 return rv; | 77 return rv; |
78 } | 78 } |
79 | 79 |
80 WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents, | 80 WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents, |
81 WebContentsViewDelegate* delegate) | 81 WebContentsViewDelegate* delegate) |
82 : web_contents_(web_contents), | 82 : web_contents_(web_contents), |
83 delegate_(delegate), | 83 delegate_(delegate), |
84 allow_overlapping_views_(false), | 84 allow_overlapping_views_(false), |
85 overlay_view_(NULL), | 85 allow_other_views_(false) { |
86 underlay_view_(NULL) { | |
87 } | 86 } |
88 | 87 |
89 WebContentsViewMac::~WebContentsViewMac() { | 88 WebContentsViewMac::~WebContentsViewMac() { |
90 // This handles the case where a renderer close call was deferred | 89 // This handles the case where a renderer close call was deferred |
91 // while the user was operating a UI control which resulted in a | 90 // while the user was operating a UI control which resulted in a |
92 // close. In that case, the Cocoa view outlives the | 91 // close. In that case, the Cocoa view outlives the |
93 // WebContentsViewMac instance due to Cocoa retain count. | 92 // WebContentsViewMac instance due to Cocoa retain count. |
94 [cocoa_view_ cancelDeferredClose]; | 93 [cocoa_view_ cancelDeferredClose]; |
95 [cocoa_view_ clearWebContentsView]; | 94 [cocoa_view_ clearWebContentsView]; |
96 } | 95 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( | 270 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( |
272 web_contents_->GetRenderWidgetHostView()); | 271 web_contents_->GetRenderWidgetHostView()); |
273 if (view) | 272 if (view) |
274 view->SetAllowOverlappingViews(allow_overlapping_views_); | 273 view->SetAllowOverlappingViews(allow_overlapping_views_); |
275 } | 274 } |
276 | 275 |
277 bool WebContentsViewMac::GetAllowOverlappingViews() const { | 276 bool WebContentsViewMac::GetAllowOverlappingViews() const { |
278 return allow_overlapping_views_; | 277 return allow_overlapping_views_; |
279 } | 278 } |
280 | 279 |
281 void WebContentsViewMac::SetOverlayView( | 280 void WebContentsViewMac::SetAllowOtherViews(bool allow) { |
282 WebContentsView* overlay, const gfx::Point& offset) { | 281 if (allow_other_views_ == allow) |
283 DCHECK(!underlay_view_); | 282 return; |
284 if (overlay_view_) | |
285 RemoveOverlayView(); | |
286 | 283 |
287 overlay_view_ = static_cast<WebContentsViewMac*>(overlay); | 284 allow_other_views_ = allow; |
288 DCHECK(!overlay_view_->overlay_view_); | 285 RenderWidgetHostViewMac* view = static_cast<RenderWidgetHostViewMac*>( |
289 overlay_view_->underlay_view_ = this; | 286 web_contents_->GetRenderWidgetHostView()); |
290 overlay_view_offset_ = offset; | 287 if (view) |
291 UpdateRenderWidgetHostViewOverlay(); | 288 view->SetAllowPauseForResizeOrRepaint(!allow_other_views_); |
292 } | 289 } |
293 | 290 |
294 void WebContentsViewMac::RemoveOverlayView() { | 291 bool WebContentsViewMac::GetAllowOtherViews() const { |
295 DCHECK(overlay_view_); | 292 return allow_other_views_; |
296 | |
297 RenderWidgetHostViewMac* rwhv = static_cast<RenderWidgetHostViewMac*>( | |
298 web_contents_->GetRenderWidgetHostView()); | |
299 if (rwhv) | |
300 rwhv->RemoveOverlayView(); | |
301 | |
302 overlay_view_->underlay_view_ = NULL; | |
303 overlay_view_ = NULL; | |
304 } | |
305 | |
306 void WebContentsViewMac::UpdateRenderWidgetHostViewOverlay() { | |
307 RenderWidgetHostViewMac* rwhv = static_cast<RenderWidgetHostViewMac*>( | |
308 web_contents_->GetRenderWidgetHostView()); | |
309 if (!rwhv) | |
310 return; | |
311 | |
312 if (overlay_view_) { | |
313 RenderWidgetHostViewMac* overlay_rwhv = | |
314 static_cast<RenderWidgetHostViewMac*>( | |
315 overlay_view_->web_contents_->GetRenderWidgetHostView()); | |
316 if (overlay_rwhv) | |
317 rwhv->SetOverlayView(overlay_rwhv, overlay_view_offset_); | |
318 } | |
319 | |
320 if (underlay_view_) { | |
321 RenderWidgetHostViewMac* underlay_rwhv = | |
322 static_cast<RenderWidgetHostViewMac*>( | |
323 underlay_view_->web_contents_->GetRenderWidgetHostView()); | |
324 if (underlay_rwhv) | |
325 underlay_rwhv->SetOverlayView(rwhv, underlay_view_->overlay_view_offset_); | |
326 } | |
327 } | 293 } |
328 | 294 |
329 void WebContentsViewMac::CreateView( | 295 void WebContentsViewMac::CreateView( |
330 const gfx::Size& initial_size, gfx::NativeView context) { | 296 const gfx::Size& initial_size, gfx::NativeView context) { |
331 WebContentsViewCocoa* view = | 297 WebContentsViewCocoa* view = |
332 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this]; | 298 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this]; |
333 cocoa_view_.reset(view); | 299 cocoa_view_.reset(view); |
334 } | 300 } |
335 | 301 |
336 RenderWidgetHostViewBase* WebContentsViewMac::CreateViewForWidget( | 302 RenderWidgetHostViewBase* WebContentsViewMac::CreateViewForWidget( |
(...skipping 12 matching lines...) Expand all Loading... |
349 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac( | 315 RenderWidgetHostViewMac* view = new RenderWidgetHostViewMac( |
350 render_widget_host); | 316 render_widget_host); |
351 if (delegate()) { | 317 if (delegate()) { |
352 base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate> > | 318 base::scoped_nsobject<NSObject<RenderWidgetHostViewMacDelegate> > |
353 rw_delegate( | 319 rw_delegate( |
354 delegate()->CreateRenderWidgetHostViewDelegate(render_widget_host)); | 320 delegate()->CreateRenderWidgetHostViewDelegate(render_widget_host)); |
355 | 321 |
356 view->SetDelegate(rw_delegate.get()); | 322 view->SetDelegate(rw_delegate.get()); |
357 } | 323 } |
358 view->SetAllowOverlappingViews(allow_overlapping_views_); | 324 view->SetAllowOverlappingViews(allow_overlapping_views_); |
| 325 view->SetAllowPauseForResizeOrRepaint(!allow_other_views_); |
359 | 326 |
360 // Fancy layout comes later; for now just make it our size and resize it | 327 // Fancy layout comes later; for now just make it our size and resize it |
361 // with us. In case there are other siblings of the content area, we want | 328 // with us. In case there are other siblings of the content area, we want |
362 // to make sure the content area is on the bottom so other things draw over | 329 // to make sure the content area is on the bottom so other things draw over |
363 // it. | 330 // it. |
364 NSView* view_view = view->GetNativeView(); | 331 NSView* view_view = view->GetNativeView(); |
365 [view_view setFrame:[cocoa_view_.get() bounds]]; | 332 [view_view setFrame:[cocoa_view_.get() bounds]]; |
366 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 333 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
367 // Add the new view below all other views; this also keeps it below any | 334 // Add the new view below all other views; this also keeps it below any |
368 // overlay view installed. | 335 // overlay view installed. |
(...skipping 21 matching lines...) Expand all Loading... |
390 | 357 |
391 | 358 |
392 void WebContentsViewMac::RenderViewCreated(RenderViewHost* host) { | 359 void WebContentsViewMac::RenderViewCreated(RenderViewHost* host) { |
393 // We want updates whenever the intrinsic width of the webpage changes. | 360 // We want updates whenever the intrinsic width of the webpage changes. |
394 // Put the RenderView into that mode. The preferred width is used for example | 361 // Put the RenderView into that mode. The preferred width is used for example |
395 // when the "zoom" button in the browser window is clicked. | 362 // when the "zoom" button in the browser window is clicked. |
396 host->EnablePreferredSizeMode(); | 363 host->EnablePreferredSizeMode(); |
397 } | 364 } |
398 | 365 |
399 void WebContentsViewMac::RenderViewSwappedIn(RenderViewHost* host) { | 366 void WebContentsViewMac::RenderViewSwappedIn(RenderViewHost* host) { |
400 UpdateRenderWidgetHostViewOverlay(); | |
401 } | 367 } |
402 | 368 |
403 void WebContentsViewMac::SetOverscrollControllerEnabled(bool enabled) { | 369 void WebContentsViewMac::SetOverscrollControllerEnabled(bool enabled) { |
404 } | 370 } |
405 | 371 |
406 bool WebContentsViewMac::IsEventTracking() const { | 372 bool WebContentsViewMac::IsEventTracking() const { |
407 return base::MessagePumpMac::IsHandlingSendEvent(); | 373 return base::MessagePumpMac::IsHandlingSendEvent(); |
408 } | 374 } |
409 | 375 |
410 // Arrange to call CloseTab() after we're back to the main event loop. | 376 // Arrange to call CloseTab() after we're back to the main event loop. |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // When the subviews require a layout, their size should be reset to the size | 594 // When the subviews require a layout, their size should be reset to the size |
629 // of this view. (It is possible for the size to get out of sync as an | 595 // of this view. (It is possible for the size to get out of sync as an |
630 // optimization in preparation for an upcoming WebContentsView resize. | 596 // optimization in preparation for an upcoming WebContentsView resize. |
631 // http://crbug.com/264207) | 597 // http://crbug.com/264207) |
632 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { | 598 - (void)resizeSubviewsWithOldSize:(NSSize)oldBoundsSize { |
633 for (NSView* subview in self.subviews) | 599 for (NSView* subview in self.subviews) |
634 [subview setFrame:self.bounds]; | 600 [subview setFrame:self.bounds]; |
635 } | 601 } |
636 | 602 |
637 @end | 603 @end |
OLD | NEW |