electron/atom/browser/osr_render_widget_host_view_mac.mm

120 lines
3.6 KiB
Text
Raw Normal View History

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
#include <algorithm>
#include <limits>
#include <utility>
#include <iostream>
#import <Cocoa/Cocoa.h>
#include "base/compiler_specific.h"
#include "base/strings/utf_string_conversions.h"
#include "content/common/view_messages.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#include "ui/events/latency_info.h"
2016-07-29 12:50:27 +00:00
ui::AcceleratedWidgetMac* atom::OffScreenRenderWidgetHostView::GetAcceleratedWidgetMac()
const {
if (browser_compositor_)
return browser_compositor_->accelerated_widget_mac();
return nullptr;
}
2016-07-29 12:50:27 +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
// Create a borderless non-visible 1x1 window.
window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1)
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
// Create a CALayer which is used by BrowserCompositorViewMac for rendering.
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);
// CEF needs the browser compositor to remain responsive whereas normal
// rendering on OS X does not. This effectively reverts the changes from
// https://crbug.com/463988#c6
compositor_->SetLocksWillTimeOut(true);
browser_compositor_->Unsuspend();
}
2016-07-29 12:50:27 +00:00
// void atom::OffScreenRenderWidgetHostView::PlatformDestroyCompositorWidget() {
2016-07-18 14:16:23 +00:00
// DCHECK(window_);
//
// browser_compositor_->Destroy();
//
// [window_ close];
// window_ = nil;
// [background_layer_ release];
// background_layer_ = nil;
//
// browser_compositor_.reset();
//
// delete accelerated_widget_helper_;
// accelerated_widget_helper_ = nullptr;
// }