cef/libcef/browser/osr/browser_platform_delegate_o...

315 lines
9.7 KiB
C++
Raw Normal View History

// Copyright 2015 The Chromium Embedded Framework Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "libcef/browser/osr/browser_platform_delegate_osr.h"
#include <utility>
#include "libcef/browser/browser_host_impl.h"
#include "libcef/browser/osr/render_widget_host_view_osr.h"
#include "libcef/browser/osr/web_contents_view_osr.h"
#include "libcef/common/drag_data_impl.h"
#include "content/public/browser/render_view_host.h"
CefBrowserPlatformDelegateOsr::CefBrowserPlatformDelegateOsr(
scoped_ptr<CefBrowserPlatformDelegateNative> native_delegate)
: native_delegate_(std::move(native_delegate)),
view_osr_(nullptr) {
native_delegate_->set_windowless_handler(this);
}
void CefBrowserPlatformDelegateOsr::CreateViewForWebContents(
content::WebContentsView** view,
content::RenderViewHostDelegateView** delegate_view) {
DCHECK(!view_osr_);
// Use the OSR view instead of the default platform view.
view_osr_ = new CefWebContentsViewOSR(
!!native_delegate_->window_info().transparent_painting_enabled);
*view = view_osr_;
*delegate_view = view_osr_;
}
void CefBrowserPlatformDelegateOsr::WebContentsCreated(
content::WebContents* web_contents) {
DCHECK(view_osr_);
DCHECK(!view_osr_->web_contents());
// Associate the WebContents with the OSR view.
view_osr_->set_web_contents(web_contents);
}
void CefBrowserPlatformDelegateOsr::BrowserCreated(
CefBrowserHostImpl* browser) {
CefBrowserPlatformDelegate::BrowserCreated(browser);
if (browser->IsPopup()) {
// Associate the RenderWidget host view with the browser now because the
// browser wasn't known at the time that the host view was created.
content::RenderViewHost* host =
browser->web_contents()->GetRenderViewHost();
DCHECK(host);
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(host->GetWidget()->GetView());
// |view| will be null if the popup is a DevTools window.
if (view)
view->set_browser_impl(browser);
}
}
void CefBrowserPlatformDelegateOsr::BrowserDestroyed(
CefBrowserHostImpl* browser) {
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
view_osr_ = nullptr;
}
void CefBrowserPlatformDelegateOsr::WasResized() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->WasResized();
}
void CefBrowserPlatformDelegateOsr::SendKeyEvent(
const content::NativeWebKeyboardEvent& event) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->SendKeyEvent(event);
}
void CefBrowserPlatformDelegateOsr::SendMouseEvent(
const blink::WebMouseEvent& event) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->SendMouseEvent(event);
}
void CefBrowserPlatformDelegateOsr::SendMouseWheelEvent(
const blink::WebMouseWheelEvent& event) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->SendMouseWheelEvent(event);
}
void CefBrowserPlatformDelegateOsr::SendFocusEvent(bool setFocus) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->SendFocusEvent(setFocus);
}
gfx::Point CefBrowserPlatformDelegateOsr::GetScreenPoint(
const gfx::Point& view) const {
CefRefPtr<CefRenderHandler> handler = browser_->client()->GetRenderHandler();
if (handler.get()) {
int screenX = 0, screenY = 0;
if (handler->GetScreenPoint(browser_, view.x(), view.y(),
screenX, screenY)) {
return gfx::Point(screenX, screenY);
}
}
return view;
}
void CefBrowserPlatformDelegateOsr::ViewText(const std::string& text) {
native_delegate_->ViewText(text);
}
void CefBrowserPlatformDelegateOsr::HandleKeyboardEvent(
const content::NativeWebKeyboardEvent& event) {
native_delegate_->HandleKeyboardEvent(event);
}
void CefBrowserPlatformDelegateOsr::HandleExternalProtocol(const GURL& url) {
native_delegate_->HandleExternalProtocol(url);
}
void CefBrowserPlatformDelegateOsr::TranslateKeyEvent(
content::NativeWebKeyboardEvent& result,
const CefKeyEvent& key_event) const {
native_delegate_->TranslateKeyEvent(result, key_event);
}
void CefBrowserPlatformDelegateOsr::TranslateClickEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
CefBrowserHost::MouseButtonType type,
bool mouseUp, int clickCount) const {
native_delegate_->TranslateClickEvent(result, mouse_event, type, mouseUp,
clickCount);
}
void CefBrowserPlatformDelegateOsr::TranslateMoveEvent(
blink::WebMouseEvent& result,
const CefMouseEvent& mouse_event,
bool mouseLeave) const {
native_delegate_->TranslateMoveEvent(result, mouse_event, mouseLeave);
}
void CefBrowserPlatformDelegateOsr::TranslateWheelEvent(
blink::WebMouseWheelEvent& result,
const CefMouseEvent& mouse_event,
int deltaX, int deltaY) const {
native_delegate_->TranslateWheelEvent(result, mouse_event, deltaX, deltaY);
}
CefEventHandle CefBrowserPlatformDelegateOsr::GetEventHandle(
const content::NativeWebKeyboardEvent& event) const {
return native_delegate_->GetEventHandle(event);
}
scoped_ptr<CefFileDialogRunner>
CefBrowserPlatformDelegateOsr::CreateFileDialogRunner() {
return native_delegate_->CreateFileDialogRunner();
}
scoped_ptr<CefJavaScriptDialogRunner>
CefBrowserPlatformDelegateOsr::CreateJavaScriptDialogRunner() {
return native_delegate_->CreateJavaScriptDialogRunner();
}
scoped_ptr<CefMenuRunner> CefBrowserPlatformDelegateOsr::CreateMenuRunner() {
return native_delegate_->CreateMenuRunner();
}
bool CefBrowserPlatformDelegateOsr::IsWindowless() const {
return true;
}
Implement Views framework on Windows and Linux (issue #1749). - Add Views header files in a new include/views directory. - Add initial top-level window (CefWindow), control (CefBrowserView, CefLabelButton, CefMenuButton, CefPanel, CefScrollView, CefTextfield) and layout (CefBoxLayout, CefFlowLayout) support. See libcef/browser/views/view_impl.h comments for implementation details. - Add Views example usage in cefclient and cefsimple and Views unit tests in cef_unittests. Pass the `--use-views` command-line flag to cefclient, cefsimple and cef_unittests to run using the Views framework instead of platform APIs. For cefclient and cefsimple this will create the browser window and all related functionality using the Views framework. For cef_unittests this will run all tests (except OSR tests) in a Views-based browser window. Views- specific unit tests (`--gtest_filter=Views*`) will be run even if the the `--use-views` flag is not specified. - Pass the `--hide-frame` command-line flag to cefclient to demo a frameless Views-based browser window. - Pass the `--hide-controls` command-line flag to cefclient to demo a browser window without top controls. This also works in non-Views mode. - Pass the `--enable-high-dpi-support` command-line flag to cef_unittests on Windows to test high-DPI support on a display that supports it. - Add CefImage for reading/writing image file formats. - Add CefBrowser::DownloadImage() for downloading image URLs as a CefImage representation. This is primarily for loading favicons. - Add CefMenuModel::CreateMenuModel() and CefMenuModelDelegate for creating custom menus. This is primarily for use with CefMenuButton. - Add CefBrowser::TryCloseBrowser() helper for closing a browser. Also improve related documentation in cef_life_span_handler.h. - Rename cef_page_range_t to cef_range_t. It is now also used by CefTextfield. - Remove CefLifeSpanHandler::RunModal() which is never called. - Add draggable regions example to cefclient.
2016-01-19 21:09:01 +01:00
bool CefBrowserPlatformDelegateOsr::IsViewsHosted() const {
return false;
}
void CefBrowserPlatformDelegateOsr::WasHidden(bool hidden) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view) {
if (hidden)
view->Hide();
else
view->Show();
}
}
void CefBrowserPlatformDelegateOsr::NotifyScreenInfoChanged() {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->OnScreenInfoChanged();
}
void CefBrowserPlatformDelegateOsr::Invalidate(cef_paint_element_type_t type) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->Invalidate(type);
}
void CefBrowserPlatformDelegateOsr::SetWindowlessFrameRate(int frame_rate) {
CefRenderWidgetHostViewOSR* view = GetOSRHostView();
if (view)
view->UpdateFrameRate();
}
void CefBrowserPlatformDelegateOsr::DragTargetDragEnter(
CefRefPtr<CefDragData> drag_data,
const CefMouseEvent& event,
cef_drag_operations_mask_t allowed_ops) {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
CefDragDataImpl* data_impl = static_cast<CefDragDataImpl*>(drag_data.get());
base::AutoLock lock_scope(data_impl->lock());
const content::DropData& drop_data = data_impl->drop_data();
const gfx::Point client_pt(event.x, event.y);
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
blink::WebDragOperationsMask ops =
static_cast<blink::WebDragOperationsMask>(allowed_ops);
int modifiers = TranslateModifiers(event.modifiers);
rvh->DragTargetDragEnter(drop_data, client_pt, screen_pt, ops, modifiers);
}
void CefBrowserPlatformDelegateOsr::DragTargetDragOver(
const CefMouseEvent& event,
cef_drag_operations_mask_t allowed_ops) {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
const gfx::Point client_pt(event.x, event.y);
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
blink::WebDragOperationsMask ops =
static_cast<blink::WebDragOperationsMask>(allowed_ops);
int modifiers = TranslateModifiers(event.modifiers);
rvh->DragTargetDragOver(client_pt, screen_pt, ops, modifiers);
}
void CefBrowserPlatformDelegateOsr::DragTargetDragLeave() {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
rvh->DragTargetDragLeave();
}
void CefBrowserPlatformDelegateOsr::DragTargetDrop(const CefMouseEvent& event) {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
const gfx::Point client_pt(event.x, event.y);
const gfx::Point& screen_pt = GetScreenPoint(client_pt);
int modifiers = TranslateModifiers(event.modifiers);
rvh->DragTargetDrop(client_pt, screen_pt, modifiers);
}
void CefBrowserPlatformDelegateOsr::DragSourceEndedAt(
int x, int y,
cef_drag_operations_mask_t op) {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
const gfx::Point& screen_pt = GetScreenPoint(gfx::Point(x, y));
blink::WebDragOperation drag_op = static_cast<blink::WebDragOperation>(op);
rvh->DragSourceEndedAt(x, y, screen_pt.x(), screen_pt.y(), drag_op);
}
void CefBrowserPlatformDelegateOsr::DragSourceSystemDragEnded() {
content::RenderViewHost* rvh = browser_->web_contents()->GetRenderViewHost();
if (!rvh)
return;
rvh->DragSourceSystemDragEnded();
}
CefWindowHandle CefBrowserPlatformDelegateOsr::GetParentWindowHandle() const {
return GetHostWindowHandle();
}
gfx::Point CefBrowserPlatformDelegateOsr::GetParentScreenPoint(
const gfx::Point& view) const {
return GetScreenPoint(view);
}
CefRenderWidgetHostViewOSR*
CefBrowserPlatformDelegateOsr::GetOSRHostView() const {
content::WebContents* web_contents = browser_->web_contents();
CefRenderWidgetHostViewOSR* fs_view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents->GetFullscreenRenderWidgetHostView());
if (fs_view)
return fs_view;
content::RenderViewHost* host = web_contents->GetRenderViewHost();
if (host) {
return static_cast<CefRenderWidgetHostViewOSR*>(
host->GetWidget()->GetView());
}
return nullptr;
}