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"
|
2018-04-19 17:44:42 +02:00
|
|
|
#include "ui/display/screen.h"
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
display::Display GetDisplay() {
|
|
|
|
// TODO(cef): Get display info from callbacks.
|
|
|
|
return display::Screen::GetScreen()->GetDisplayNearestView(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2016-06-21 00:59:23 +02:00
|
|
|
|
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:
|
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
SkColor BrowserCompositorMacGetGutterColor() const override {
|
2016-07-21 23:21:32 +02:00
|
|
|
// 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;
|
|
|
|
}
|
2018-05-21 14:54:08 +02:00
|
|
|
return *view_->GetBackgroundColor();
|
2016-07-21 23:21:32 +02:00
|
|
|
}
|
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
void BrowserCompositorMacOnBeginFrame(base::TimeTicks frame_time) override {}
|
2016-07-21 23:21:32 +02:00
|
|
|
|
2018-02-15 01:12:09 +01:00
|
|
|
void OnFrameTokenChanged(uint32_t frame_token) override {
|
|
|
|
view_->render_widget_host()->DidProcessFrame(frame_token);
|
2017-10-20 19:45:20 +02:00
|
|
|
}
|
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
void DidReceiveFirstFrameAfterNavigation() override {
|
|
|
|
view_->render_widget_host()->DidReceiveFirstFrameAfterNavigation();
|
|
|
|
}
|
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
void DestroyCompositorForShutdown() override {}
|
|
|
|
|
2018-05-20 15:51:42 +02:00
|
|
|
bool SynchronizeVisualProperties() override {
|
|
|
|
return view_->render_widget_host()->SynchronizeVisualProperties();
|
2018-05-17 10:58:21 +02:00
|
|
|
}
|
2018-04-19 17:44:42 +02:00
|
|
|
|
2018-07-06 19:11:55 +02:00
|
|
|
// AcceleratedWidgetMacNSView methods:
|
|
|
|
|
|
|
|
void AcceleratedWidgetCALayerParamsUpdated() override {}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefRenderWidgetHostViewOSR::SpeakSelection() {}
|
2014-07-01 00:30:29 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
bool CefRenderWidgetHostViewOSR::ShouldContinueToPauseForFrame() {
|
|
|
|
return browser_compositor_->ShouldContinueToPauseForFrame();
|
|
|
|
}
|
|
|
|
|
2018-05-31 22:34:44 +02:00
|
|
|
viz::LocalSurfaceId CefRenderWidgetHostViewOSR::GetLocalSurfaceId() const {
|
|
|
|
return browser_compositor_->GetRendererLocalSurfaceId();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-04-19 17:44:42 +02:00
|
|
|
bool CefRenderWidgetHostViewOSR::UpdateNSViewAndDisplay() {
|
|
|
|
return browser_compositor_->UpdateNSViewAndDisplay(
|
|
|
|
GetRootLayer()->bounds().size(), GetDisplay());
|
|
|
|
}
|
|
|
|
|
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,
|
2018-04-19 17:44:42 +02:00
|
|
|
GetDisplay(), AllocateFrameSinkId(is_guest_view_hack)));
|
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
|
|
|
}
|