2014-07-01 00:30:29 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/osr/render_widget_host_view_osr.h"
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-03-16 03:55:59 +01:00
|
|
|
#include <algorithm>
|
2016-01-06 20:20:54 +01:00
|
|
|
#include <limits>
|
|
|
|
#include <utility>
|
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_host_impl.h"
|
|
|
|
|
2015-01-08 03:42:59 +01:00
|
|
|
#include "base/compiler_specific.h"
|
2015-10-09 17:23:12 +02:00
|
|
|
#include "base/strings/utf_string_conversions.h"
|
|
|
|
#include "content/common/view_messages.h"
|
2016-06-21 00:59:23 +02:00
|
|
|
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
class MacHelper : public content::BrowserCompositorMacClient,
|
|
|
|
public ui::AcceleratedWidgetMacNSView {
|
2016-06-21 00:59:23 +02:00
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
explicit MacHelper(CefRenderWidgetHostViewOSR* view) : view_(view) {}
|
2016-07-21 23:21:32 +02:00
|
|
|
virtual ~MacHelper() {}
|
|
|
|
|
|
|
|
// BrowserCompositorMacClient methods:
|
|
|
|
|
|
|
|
NSView* BrowserCompositorMacGetNSView() const override {
|
|
|
|
// Intentionally return nil so that
|
|
|
|
// BrowserCompositorMac::DelegatedFrameHostDesiredSizeInDIP uses the layer
|
|
|
|
// size instead of the NSView size.
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkColor BrowserCompositorMacGetGutterColor(SkColor color) const override {
|
|
|
|
// When making an element on the page fullscreen the element's background
|
|
|
|
// may not match the page's, so use black as the gutter color to avoid
|
|
|
|
// flashes of brighter colors during the transition.
|
|
|
|
if (view_->render_widget_host()->delegate() &&
|
|
|
|
view_->render_widget_host()->delegate()->IsFullscreenForCurrentTab()) {
|
|
|
|
return SK_ColorBLACK;
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
void BrowserCompositorMacOnBeginFrame() override {}
|
2016-07-21 23:21:32 +02:00
|
|
|
|
2017-10-20 19:45:20 +02:00
|
|
|
viz::LocalSurfaceId GetLocalSurfaceId() const override {
|
|
|
|
return view_->local_surface_id();
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
// AcceleratedWidgetMacNSView methods:
|
2016-06-21 00:59:23 +02:00
|
|
|
|
|
|
|
NSView* AcceleratedWidgetGetNSView() const override {
|
|
|
|
return [view_->window_ contentView];
|
|
|
|
}
|
|
|
|
|
|
|
|
void AcceleratedWidgetGetVSyncParameters(
|
2017-05-17 11:29:28 +02:00
|
|
|
base::TimeTicks* timebase,
|
|
|
|
base::TimeDelta* interval) const override {
|
2016-06-21 00:59:23 +02:00
|
|
|
*timebase = base::TimeTicks();
|
|
|
|
*interval = base::TimeDelta();
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void AcceleratedWidgetSwapCompleted() override {}
|
2016-06-21 00:59:23 +02:00
|
|
|
|
2017-12-07 22:44:24 +01:00
|
|
|
void OnFrameTokenChanged(uint32_t frame_token) override {
|
|
|
|
view_->render_widget_host()->DidProcessFrame(frame_token);
|
|
|
|
}
|
|
|
|
|
2016-06-21 00:59:23 +02:00
|
|
|
private:
|
|
|
|
// Guaranteed to outlive this object.
|
|
|
|
CefRenderWidgetHostViewOSR* view_;
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(MacHelper);
|
2016-06-21 00:59:23 +02:00
|
|
|
};
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
ui::AcceleratedWidgetMac* CefRenderWidgetHostViewOSR::GetAcceleratedWidgetMac()
|
|
|
|
const {
|
|
|
|
if (browser_compositor_)
|
2016-07-06 21:34:09 +02:00
|
|
|
return browser_compositor_->GetAcceleratedWidgetMac();
|
2016-05-25 01:35:43 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SetActive(bool active) {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::ShowDefinitionForSelection() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::SupportsSpeech() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SpeakSelection() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
|
|
|
bool CefRenderWidgetHostViewOSR::IsSpeaking() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::StopSpeaking() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
ui::Compositor* CefRenderWidgetHostViewOSR::GetCompositor() const {
|
|
|
|
return browser_compositor_->GetCompositor();
|
|
|
|
}
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
ui::Layer* CefRenderWidgetHostViewOSR::GetRootLayer() const {
|
|
|
|
return browser_compositor_->GetRootLayer();
|
|
|
|
}
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
content::DelegatedFrameHost* CefRenderWidgetHostViewOSR::GetDelegatedFrameHost()
|
|
|
|
const {
|
|
|
|
return browser_compositor_->GetDelegatedFrameHost();
|
|
|
|
}
|
|
|
|
|
2017-03-03 23:37:23 +01:00
|
|
|
void CefRenderWidgetHostViewOSR::PlatformCreateCompositorWidget(
|
|
|
|
bool is_guest_view_hack) {
|
2014-07-01 00:30:29 +02:00
|
|
|
// Create a borderless non-visible 1x1 window.
|
|
|
|
window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 1, 1)
|
|
|
|
styleMask:NSBorderlessWindowMask
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
2014-09-04 19:53:40 +02:00
|
|
|
|
|
|
|
// 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];
|
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
mac_helper_ = new MacHelper(this);
|
2016-07-06 21:34:09 +02:00
|
|
|
browser_compositor_.reset(new content::BrowserCompositorMac(
|
2017-03-03 23:37:23 +01:00
|
|
|
mac_helper_, mac_helper_, render_widget_host_->is_hidden(), true,
|
|
|
|
AllocateFrameSinkId(is_guest_view_hack)));
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::PlatformResizeCompositorWidget(
|
|
|
|
const gfx::Size&) {}
|
2016-08-17 17:29:38 +02:00
|
|
|
|
2014-07-01 00:30:29 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::PlatformDestroyCompositorWidget() {
|
|
|
|
DCHECK(window_);
|
|
|
|
|
|
|
|
[window_ close];
|
|
|
|
window_ = nil;
|
2014-09-04 19:53:40 +02:00
|
|
|
[background_layer_ release];
|
|
|
|
background_layer_ = nil;
|
|
|
|
|
2016-07-06 21:34:09 +02:00
|
|
|
browser_compositor_.reset();
|
2016-06-21 00:59:23 +02:00
|
|
|
|
2016-07-21 23:21:32 +02:00
|
|
|
delete mac_helper_;
|
|
|
|
mac_helper_ = nullptr;
|
2014-07-01 00:30:29 +02:00
|
|
|
}
|