electron/atom/browser/osr_render_widget_host_view_mac.mm

115 lines
3.5 KiB
Text
Raw Normal View History

2016-07-30 19:35:14 +00:00
// Copyright (c) 2016 GitHub, Inc.
2016-07-30 19:25:49 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
2016-07-29 12:50:27 +00:00
#include "atom/browser/osr_render_widget_host_view.h"
2016-07-18 14:16:23 +00:00
#import <Cocoa/Cocoa.h>
#include "base/strings/utf_string_conversions.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
2016-08-01 11:27:39 +00:00
ui::AcceleratedWidgetMac*
atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac()
const {
if (browser_compositor_)
return browser_compositor_->accelerated_widget_mac();
return nullptr;
}
2016-07-30 19:25:49 +00:00
NSView* atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetNSView()
const {
2016-07-18 14:16:23 +00:00
return [window_ contentView];
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetGetVSyncParameters(
2016-07-18 14:16:23 +00:00
base::TimeTicks* timebase, base::TimeDelta* interval) const {
*timebase = base::TimeTicks();
*interval = base::TimeDelta();
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::AcceleratedWidgetSwapCompleted() {
2016-07-18 14:16:23 +00:00
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::SetActive(bool active) {
2016-07-18 14:16:23 +00:00
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::ShowDefinitionForSelection() {
2016-07-18 14:16:23 +00:00
}
2016-07-29 12:50:27 +00:00
bool atom::OffScreenRenderWidgetHostView::SupportsSpeech() const {
2016-07-18 14:16:23 +00:00
return false;
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::SpeakSelection() {
2016-07-18 14:16:23 +00:00
}
2016-07-29 12:50:27 +00:00
bool atom::OffScreenRenderWidgetHostView::IsSpeaking() const {
2016-07-18 14:16:23 +00:00
return false;
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::StopSpeaking() {
2016-07-18 14:16:23 +00:00
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::SelectionChanged(
2016-07-18 14:16:23 +00:00
const base::string16& text,
size_t offset,
const gfx::Range& range) {
if (range.is_empty() || text.empty()) {
selected_text_.clear();
} else {
size_t pos = range.GetMin() - offset;
size_t n = range.length();
DCHECK(pos + n <= text.length()) << "The text can not fully cover range.";
if (pos >= text.length()) {
DCHECK(false) << "The text can not cover range.";
return;
}
selected_text_ = base::UTF16ToUTF8(text.substr(pos, n));
}
RenderWidgetHostViewBase::SelectionChanged(text, offset, range);
}
2016-07-29 12:50:27 +00:00
void atom::OffScreenRenderWidgetHostView::CreatePlatformWidget() {
2016-07-18 14:16:23 +00:00
window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
background_layer_ = [[[CALayer alloc] init] retain];
[background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorClear)];
NSView* content_view = [window_ contentView];
[content_view setLayer:background_layer_];
[content_view setWantsLayer:YES];
browser_compositor_ = content::BrowserCompositorMac::Create();
compositor_.reset(browser_compositor_->compositor());
compositor_->SetRootLayer(root_layer_.get());
browser_compositor_->accelerated_widget_mac()->SetNSView(this);
browser_compositor_->compositor()->SetVisible(true);
compositor_->SetLocksWillTimeOut(true);
browser_compositor_->Unsuspend();
}
2016-07-29 22:51:19 +00:00
void atom::OffScreenRenderWidgetHostView::DestroyPlatformWidget() {
DCHECK(window_);
ui::Compositor* compositor = compositor_.release();
ALLOW_UNUSED_LOCAL(compositor);
[window_ close];
window_ = nil;
[background_layer_ release];
background_layer_ = nil;
browser_compositor_->accelerated_widget_mac()->ResetNSView();
browser_compositor_->compositor()->SetVisible(false);
browser_compositor_->compositor()->SetScaleAndSize(1.0, gfx::Size(0, 0));
browser_compositor_->compositor()->SetRootLayer(NULL);
content::BrowserCompositorMac::Recycle(std::move(browser_compositor_));
}