Show dummy view under offscreen mode
This commit is contained in:
parent
64334fd40b
commit
41df037f64
4 changed files with 78 additions and 0 deletions
|
@ -11,9 +11,15 @@ OffScreenWebContentsView::OffScreenWebContentsView(
|
|||
: transparent_(transparent),
|
||||
callback_(callback),
|
||||
web_contents_(nullptr) {
|
||||
#if defined(OS_MACOSX)
|
||||
PlatformCreate();
|
||||
#endif
|
||||
}
|
||||
|
||||
OffScreenWebContentsView::~OffScreenWebContentsView() {
|
||||
#if defined(OS_MACOSX)
|
||||
PlatformDestroy();
|
||||
#endif
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::SetWebContents(
|
||||
|
@ -21,6 +27,7 @@ void OffScreenWebContentsView::SetWebContents(
|
|||
web_contents_ = web_contents;
|
||||
}
|
||||
|
||||
#if !defined(OS_MACOSX)
|
||||
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
||||
return gfx::NativeView();
|
||||
}
|
||||
|
@ -32,6 +39,7 @@ gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
|||
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
||||
return gfx::NativeWindow();
|
||||
}
|
||||
#endif
|
||||
|
||||
void OffScreenWebContentsView::GetContainerBounds(gfx::Rect* out) const {
|
||||
*out = GetViewBounds();
|
||||
|
|
|
@ -10,6 +10,14 @@
|
|||
#include "content/browser/web_contents/web_contents_view.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
#ifdef __OBJC__
|
||||
@class OffScreenView;
|
||||
#else
|
||||
class OffScreenView;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace atom {
|
||||
|
||||
class OffScreenWebContentsView : public content::WebContentsView,
|
||||
|
@ -61,12 +69,21 @@ class OffScreenWebContentsView : public content::WebContentsView,
|
|||
void UpdateDragCursor(blink::WebDragOperation operation) override;
|
||||
|
||||
private:
|
||||
#if defined(OS_MACOSX)
|
||||
void PlatformCreate();
|
||||
void PlatformDestroy();
|
||||
#endif
|
||||
|
||||
const bool transparent_;
|
||||
OnPaintCallback callback_;
|
||||
|
||||
// Weak refs.
|
||||
OffScreenRenderWidgetHostView* view_;
|
||||
content::WebContents* web_contents_;
|
||||
|
||||
#if defined(OS_MACOSX)
|
||||
OffScreenView* offScreenView_;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace atom
|
||||
|
|
52
atom/browser/osr/osr_web_contents_view_mac.mm
Normal file
52
atom/browser/osr/osr_web_contents_view_mac.mm
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2016 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "atom/browser/osr/osr_web_contents_view.h"
|
||||
|
||||
@interface OffScreenView : NSView
|
||||
@end
|
||||
|
||||
@implementation OffScreenView
|
||||
|
||||
- (void)drawRect:(NSRect)dirtyRect {
|
||||
NSString* str = @"No content under offscreen mode";
|
||||
NSMutableParagraphStyle* paragraphStyle =
|
||||
[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
|
||||
[paragraphStyle setAlignment:NSCenterTextAlignment];
|
||||
NSDictionary* attributes = [NSDictionary
|
||||
dictionaryWithObject:paragraphStyle
|
||||
forKey:NSParagraphStyleAttributeName];
|
||||
NSAttributedString* text =
|
||||
[[[NSAttributedString alloc] initWithString:str
|
||||
attributes:attributes] autorelease];
|
||||
NSRect frame = NSMakeRect(0, (self.frame.size.height - text.size.height) / 2,
|
||||
self.frame.size.width, text.size.height);
|
||||
[str drawInRect:frame withAttributes:attributes];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
namespace atom {
|
||||
|
||||
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
|
||||
return offScreenView_;
|
||||
}
|
||||
|
||||
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
|
||||
return offScreenView_;
|
||||
}
|
||||
|
||||
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
|
||||
return [offScreenView_ window];
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::PlatformCreate() {
|
||||
offScreenView_ = [[OffScreenView alloc] init];
|
||||
}
|
||||
|
||||
void OffScreenWebContentsView::PlatformDestroy() {
|
||||
[offScreenView_ release];
|
||||
}
|
||||
|
||||
} // namespace atom
|
|
@ -206,6 +206,7 @@
|
|||
'atom/browser/native_window_mac.h',
|
||||
'atom/browser/native_window_mac.mm',
|
||||
'atom/browser/native_window_observer.h',
|
||||
'atom/browser/osr/osr_web_contents_view_mac.mm',
|
||||
'atom/browser/osr/osr_web_contents_view.cc',
|
||||
'atom/browser/osr/osr_web_contents_view.h',
|
||||
'atom/browser/osr/osr_output_device.cc',
|
||||
|
|
Loading…
Reference in a new issue