2015-01-27 01:03:25 +01:00
|
|
|
// Copyright (c) 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.
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/osr_window_win.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
#include <windowsx.h>
|
2024-01-20 03:22:56 +01:00
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
#include <oleacc.h>
|
|
|
|
#endif
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
#include "include/base/cef_build.h"
|
2017-04-20 21:28:17 +02:00
|
|
|
#include "tests/cefclient/browser/main_context.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "tests/cefclient/browser/osr_accessibility_helper.h"
|
|
|
|
#include "tests/cefclient/browser/osr_accessibility_node.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/osr_ime_handler_win.h"
|
2018-09-26 13:25:58 +02:00
|
|
|
#include "tests/cefclient/browser/osr_render_handler_win_d3d11.h"
|
|
|
|
#include "tests/cefclient/browser/osr_render_handler_win_gl.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "tests/cefclient/browser/resource.h"
|
2017-05-17 11:29:28 +02:00
|
|
|
#include "tests/shared/browser/geometry_util.h"
|
|
|
|
#include "tests/shared/browser/main_message_loop.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/shared/browser/util_win.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const wchar_t kWndClass[] = L"Client_OsrWindow";
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
// Helper funtion to check if it is Windows8 or greater.
|
|
|
|
// https://msdn.microsoft.com/en-us/library/ms724833(v=vs.85).aspx
|
|
|
|
inline BOOL IsWindows_8_Or_Newer() {
|
|
|
|
OSVERSIONINFOEX osvi = {0};
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
osvi.dwMajorVersion = 6;
|
|
|
|
osvi.dwMinorVersion = 2;
|
|
|
|
DWORDLONG dwlConditionMask = 0;
|
|
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
|
|
|
|
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
|
|
|
|
return ::VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION,
|
|
|
|
dwlConditionMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper function to detect mouse messages coming from emulation of touch
|
|
|
|
// events. These should be ignored.
|
|
|
|
bool IsMouseEventFromTouch(UINT message) {
|
|
|
|
#define MOUSEEVENTF_FROMTOUCH 0xFF515700
|
|
|
|
return (message >= WM_MOUSEFIRST) && (message <= WM_MOUSELAST) &&
|
|
|
|
(GetMessageExtraInfo() & MOUSEEVENTF_FROMTOUCH) ==
|
|
|
|
MOUSEEVENTF_FROMTOUCH;
|
|
|
|
}
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
class CreateBrowserHelper {
|
|
|
|
public:
|
|
|
|
CreateBrowserHelper(HWND hwnd,
|
|
|
|
const RECT& rect,
|
|
|
|
CefRefPtr<CefClient> handler,
|
|
|
|
const std::string& url,
|
|
|
|
const CefBrowserSettings& settings,
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
|
|
|
OsrWindowWin* osr_window_win)
|
|
|
|
: hwnd_(hwnd),
|
|
|
|
rect_(rect),
|
|
|
|
handler_(handler),
|
|
|
|
url_(url),
|
|
|
|
settings_(settings),
|
|
|
|
extra_info_(extra_info),
|
|
|
|
request_context_(request_context),
|
|
|
|
osr_window_win_(osr_window_win) {}
|
|
|
|
|
|
|
|
HWND hwnd_;
|
|
|
|
RECT rect_;
|
|
|
|
CefRefPtr<CefClient> handler_;
|
|
|
|
std::string url_;
|
|
|
|
CefBrowserSettings settings_;
|
|
|
|
CefRefPtr<CefDictionaryValue> extra_info_;
|
|
|
|
CefRefPtr<CefRequestContext> request_context_;
|
|
|
|
OsrWindowWin* osr_window_win_;
|
|
|
|
};
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
OsrWindowWin::OsrWindowWin(Delegate* delegate,
|
2018-09-26 13:25:58 +02:00
|
|
|
const OsrRendererSettings& settings)
|
2015-01-27 01:03:25 +01:00
|
|
|
: delegate_(delegate),
|
2018-09-26 13:25:58 +02:00
|
|
|
settings_(settings),
|
2024-01-20 03:22:56 +01:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
last_mouse_pos_(),
|
2024-01-20 03:22:56 +01:00
|
|
|
current_mouse_pos_() {
|
2015-01-27 01:03:25 +01:00
|
|
|
DCHECK(delegate_);
|
2018-09-26 15:09:46 +02:00
|
|
|
client_rect_ = {0};
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
OsrWindowWin::~OsrWindowWin() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
// The native window should have already been destroyed.
|
2018-09-26 13:25:58 +02:00
|
|
|
DCHECK(!hwnd_ && !render_handler_.get());
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2019-03-19 10:42:54 +01:00
|
|
|
void CreateBrowserWithHelper(CreateBrowserHelper* helper) {
|
|
|
|
helper->osr_window_win_->CreateBrowser(
|
|
|
|
helper->hwnd_, helper->rect_, helper->handler_, helper->settings_,
|
|
|
|
helper->extra_info_, helper->request_context_, helper->url_);
|
|
|
|
delete helper;
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
void OsrWindowWin::CreateBrowser(HWND parent_hwnd,
|
|
|
|
const RECT& rect,
|
|
|
|
CefRefPtr<CefClient> handler,
|
|
|
|
const CefBrowserSettings& settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
CefRefPtr<CefDictionaryValue> extra_info,
|
2015-02-14 00:17:08 +01:00
|
|
|
CefRefPtr<CefRequestContext> request_context,
|
2015-01-27 01:03:25 +01:00
|
|
|
const std::string& startup_url) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2019-03-19 10:42:54 +01:00
|
|
|
CreateBrowserHelper* helper =
|
|
|
|
new CreateBrowserHelper(parent_hwnd, rect, handler, startup_url,
|
|
|
|
settings, extra_info, request_context, this);
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(CreateBrowserWithHelper, helper));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the native window.
|
|
|
|
Create(parent_hwnd, rect);
|
|
|
|
|
|
|
|
CefWindowInfo window_info;
|
2017-04-20 21:28:17 +02:00
|
|
|
window_info.SetAsWindowless(hwnd_);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2019-02-07 22:36:31 +01:00
|
|
|
if (GetWindowLongPtr(parent_hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE) {
|
|
|
|
// Don't activate the browser window on creation.
|
|
|
|
window_info.ex_style |= WS_EX_NOACTIVATE;
|
|
|
|
}
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
window_info.shared_texture_enabled = settings_.shared_texture_enabled;
|
|
|
|
window_info.external_begin_frame_enabled =
|
|
|
|
settings_.external_begin_frame_enabled;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Create the browser asynchronously.
|
|
|
|
CefBrowserHost::CreateBrowser(window_info, handler, startup_url, settings,
|
2019-03-19 10:42:54 +01:00
|
|
|
extra_info, request_context);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::ShowPopup(HWND parent_hwnd,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
size_t width,
|
|
|
|
size_t height) {
|
2015-01-27 01:03:25 +01:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::ShowPopup, this,
|
|
|
|
parent_hwnd, x, y, width, height));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(browser_.get());
|
|
|
|
|
|
|
|
// Create the native window.
|
2017-05-17 11:29:28 +02:00
|
|
|
const RECT rect = {x, y, x + static_cast<int>(width),
|
2015-01-28 18:14:52 +01:00
|
|
|
y + static_cast<int>(height)};
|
2015-01-27 01:03:25 +01:00
|
|
|
Create(parent_hwnd, rect);
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
// Create the render handler.
|
|
|
|
EnsureRenderHandler();
|
|
|
|
render_handler_->SetBrowser(browser_);
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Send resize notification so the compositor is assigned the correct
|
|
|
|
// viewport size and begins rendering.
|
|
|
|
browser_->GetHost()->WasResized();
|
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::Show() {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Show, this));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Show the native window if not currently visible.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (hwnd_ && !::IsWindowVisible(hwnd_)) {
|
2015-01-27 01:03:25 +01:00
|
|
|
ShowWindow(hwnd_, SW_SHOW);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
if (hidden_) {
|
|
|
|
// Set the browser as visible.
|
|
|
|
browser_->GetHost()->WasHidden(false);
|
|
|
|
hidden_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Give focus to the browser.
|
2021-09-27 09:50:07 +02:00
|
|
|
browser_->GetHost()->SetFocus(true);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::Hide() {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Hide, this));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Remove focus from the browser.
|
2021-09-27 09:50:07 +02:00
|
|
|
browser_->GetHost()->SetFocus(false);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
if (!hidden_) {
|
|
|
|
// Set the browser as hidden.
|
|
|
|
browser_->GetHost()->WasHidden(true);
|
|
|
|
hidden_ = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::SetBounds(int x, int y, size_t width, size_t height) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetBounds, this, x, y,
|
|
|
|
width, height));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hwnd_) {
|
|
|
|
// Set the browser window bounds.
|
2021-06-17 22:08:01 +02:00
|
|
|
::SetWindowPos(hwnd_, nullptr, x, y, static_cast<int>(width),
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<int>(height), SWP_NOZORDER);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::SetFocus() {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetFocus, this));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
if (hwnd_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
// Give focus to the native window.
|
|
|
|
::SetFocus(hwnd_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
void OsrWindowWin::SetDeviceScaleFactor(float device_scale_factor) {
|
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
|
|
|
// Execute this method on the UI thread.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetDeviceScaleFactor,
|
|
|
|
this, device_scale_factor));
|
2015-08-10 22:49:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device_scale_factor == device_scale_factor_) {
|
2015-08-10 22:49:45 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-10 22:49:45 +02:00
|
|
|
|
|
|
|
device_scale_factor_ = device_scale_factor;
|
|
|
|
if (browser_) {
|
|
|
|
browser_->GetHost()->NotifyScreenInfoChanged();
|
|
|
|
browser_->GetHost()->WasResized();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
void OsrWindowWin::Create(HWND parent_hwnd, const RECT& rect) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2018-09-26 13:25:58 +02:00
|
|
|
DCHECK(!hwnd_ && !render_handler_.get());
|
2015-01-27 01:03:25 +01:00
|
|
|
DCHECK(parent_hwnd);
|
|
|
|
DCHECK(!::IsRectEmpty(&rect));
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
HINSTANCE hInst = ::GetModuleHandle(nullptr);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2017-04-20 21:28:17 +02:00
|
|
|
const cef_color_t background_color = MainContext::Get()->GetBackgroundColor();
|
2015-04-09 16:59:34 +02:00
|
|
|
const HBRUSH background_brush = CreateSolidBrush(
|
2017-05-17 11:29:28 +02:00
|
|
|
RGB(CefColorGetR(background_color), CefColorGetG(background_color),
|
2015-04-09 16:59:34 +02:00
|
|
|
CefColorGetB(background_color)));
|
|
|
|
|
|
|
|
RegisterOsrClass(hInst, background_brush);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2019-02-07 22:36:31 +01:00
|
|
|
DWORD ex_style = 0;
|
|
|
|
if (GetWindowLongPtr(parent_hwnd, GWL_EXSTYLE) & WS_EX_NOACTIVATE) {
|
|
|
|
// Don't activate the browser window on creation.
|
|
|
|
ex_style |= WS_EX_NOACTIVATE;
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Create the native window with a border so it's easier to visually identify
|
|
|
|
// OSR windows.
|
2019-02-07 22:36:31 +01:00
|
|
|
hwnd_ = ::CreateWindowEx(
|
2024-01-20 03:22:56 +01:00
|
|
|
ex_style, kWndClass, nullptr,
|
2015-01-27 01:03:25 +01:00
|
|
|
WS_BORDER | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE,
|
|
|
|
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
|
2024-01-20 03:22:56 +01:00
|
|
|
parent_hwnd, nullptr, hInst, nullptr);
|
2015-01-27 01:03:25 +01:00
|
|
|
CHECK(hwnd_);
|
|
|
|
|
|
|
|
client_rect_ = rect;
|
|
|
|
|
|
|
|
// Associate |this| with the window.
|
|
|
|
SetUserDataPtr(hwnd_, this);
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
2020-01-15 15:28:12 +01:00
|
|
|
accessibility_root_ = nullptr;
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Create/register the drag&drop handler.
|
|
|
|
drop_target_ = DropTargetWin::Create(this, hwnd_);
|
|
|
|
HRESULT register_res = RegisterDragDrop(hwnd_, drop_target_);
|
|
|
|
DCHECK_EQ(register_res, S_OK);
|
|
|
|
#endif
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
ime_handler_ = std::make_unique<OsrImeHandlerWin>(hwnd_);
|
2016-10-28 18:11:24 +02:00
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
// Enable Touch Events if requested
|
2023-01-02 23:59:03 +01:00
|
|
|
if (client::MainContext::Get()->TouchEventsEnabled()) {
|
2019-02-25 22:17:28 +01:00
|
|
|
RegisterTouchWindow(hwnd_, 0);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Notify the window owner.
|
|
|
|
NotifyNativeWindowCreated(hwnd_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::Destroy() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2021-06-17 22:08:01 +02:00
|
|
|
DCHECK(hwnd_ != nullptr);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
// Revoke/delete the drag&drop handler.
|
|
|
|
RevokeDragDrop(hwnd_);
|
2020-01-15 15:28:12 +01:00
|
|
|
drop_target_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
#endif
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
render_handler_.reset();
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Destroy the native window.
|
|
|
|
::DestroyWindow(hwnd_);
|
2016-10-28 18:11:24 +02:00
|
|
|
ime_handler_.reset();
|
2021-06-17 22:08:01 +02:00
|
|
|
hwnd_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::NotifyNativeWindowCreated(HWND hwnd) {
|
|
|
|
if (!CURRENTLY_ON_MAIN_THREAD()) {
|
|
|
|
// Execute this method on the main thread.
|
|
|
|
MAIN_POST_CLOSURE(
|
2021-06-19 21:54:45 +02:00
|
|
|
base::BindOnce(&OsrWindowWin::NotifyNativeWindowCreated, this, hwnd));
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delegate_->OnOsrNativeWindowCreated(hwnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
2015-04-09 16:59:34 +02:00
|
|
|
void OsrWindowWin::RegisterOsrClass(HINSTANCE hInstance,
|
|
|
|
HBRUSH background_brush) {
|
2015-01-27 01:03:25 +01:00
|
|
|
// Only register the class one time.
|
|
|
|
static bool class_registered = false;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (class_registered) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
class_registered = true;
|
|
|
|
|
|
|
|
WNDCLASSEX wcex;
|
|
|
|
|
|
|
|
wcex.cbSize = sizeof(WNDCLASSEX);
|
2017-05-17 11:29:28 +02:00
|
|
|
wcex.style = CS_OWNDC;
|
|
|
|
wcex.lpfnWndProc = OsrWndProc;
|
|
|
|
wcex.cbClsExtra = 0;
|
|
|
|
wcex.cbWndExtra = 0;
|
|
|
|
wcex.hInstance = hInstance;
|
2021-06-17 22:08:01 +02:00
|
|
|
wcex.hIcon = nullptr;
|
|
|
|
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
2015-04-09 16:59:34 +02:00
|
|
|
wcex.hbrBackground = background_brush;
|
2021-06-17 22:08:01 +02:00
|
|
|
wcex.lpszMenuName = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
wcex.lpszClassName = kWndClass;
|
2017-05-17 11:29:28 +02:00
|
|
|
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
RegisterClassEx(&wcex);
|
|
|
|
}
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
void OsrWindowWin::OnIMESetContext(UINT message, WPARAM wParam, LPARAM lParam) {
|
|
|
|
// We handle the IME Composition Window ourselves (but let the IME Candidates
|
|
|
|
// Window be handled by IME through DefWindowProc()), so clear the
|
|
|
|
// ISC_SHOWUICOMPOSITIONWINDOW flag:
|
|
|
|
lParam &= ~ISC_SHOWUICOMPOSITIONWINDOW;
|
|
|
|
::DefWindowProc(hwnd_, message, wParam, lParam);
|
|
|
|
|
|
|
|
// Create Caret Window if required
|
|
|
|
if (ime_handler_) {
|
|
|
|
ime_handler_->CreateImeWindow();
|
|
|
|
ime_handler_->MoveImeWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnIMEStartComposition() {
|
|
|
|
if (ime_handler_) {
|
|
|
|
ime_handler_->CreateImeWindow();
|
|
|
|
ime_handler_->MoveImeWindow();
|
|
|
|
ime_handler_->ResetComposition();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OsrWindowWin::OnIMEComposition(UINT message,
|
|
|
|
WPARAM wParam,
|
2016-10-28 18:11:24 +02:00
|
|
|
LPARAM lParam) {
|
|
|
|
if (browser_ && ime_handler_) {
|
|
|
|
CefString cTextStr;
|
|
|
|
if (ime_handler_->GetResult(lParam, cTextStr)) {
|
|
|
|
// Send the text to the browser. The |replacement_range| and
|
|
|
|
// |relative_cursor_pos| params are not used on Windows, so provide
|
|
|
|
// default invalid values.
|
2023-05-16 12:22:17 +02:00
|
|
|
browser_->GetHost()->ImeCommitText(cTextStr, CefRange::InvalidRange(), 0);
|
2016-10-28 18:11:24 +02:00
|
|
|
ime_handler_->ResetComposition();
|
|
|
|
// Continue reading the composition string - Japanese IMEs send both
|
|
|
|
// GCS_RESULTSTR and GCS_COMPSTR.
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<CefCompositionUnderline> underlines;
|
|
|
|
int composition_start = 0;
|
|
|
|
|
|
|
|
if (ime_handler_->GetComposition(lParam, cTextStr, underlines,
|
|
|
|
composition_start)) {
|
|
|
|
// Send the composition string to the browser. The |replacement_range|
|
|
|
|
// param is not used on Windows, so provide a default invalid value.
|
2017-05-17 11:29:28 +02:00
|
|
|
browser_->GetHost()->ImeSetComposition(
|
2023-05-16 12:22:17 +02:00
|
|
|
cTextStr, underlines, CefRange::InvalidRange(),
|
2016-10-28 18:11:24 +02:00
|
|
|
CefRange(composition_start,
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<int>(composition_start + cTextStr.length())));
|
2016-10-28 18:11:24 +02:00
|
|
|
|
|
|
|
// Update the Candidate Window position. The cursor is at the end so
|
|
|
|
// subtract 1. This is safe because IMM32 does not support non-zero-width
|
|
|
|
// in a composition. Also, negative values are safely ignored in
|
|
|
|
// MoveImeWindow
|
|
|
|
ime_handler_->UpdateCaretPosition(composition_start - 1);
|
|
|
|
} else {
|
|
|
|
OnIMECancelCompositionEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnIMECancelCompositionEvent() {
|
|
|
|
if (browser_ && ime_handler_) {
|
|
|
|
browser_->GetHost()->ImeCancelComposition();
|
|
|
|
ime_handler_->ResetComposition();
|
|
|
|
ime_handler_->DestroyImeWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// static
|
2017-05-17 11:29:28 +02:00
|
|
|
LRESULT CALLBACK OsrWindowWin::OsrWndProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam) {
|
2015-01-27 01:03:25 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
OsrWindowWin* self = GetUserDataPtr<OsrWindowWin*>(hWnd);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!self) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
// We want to handle IME events before the OS does any default handling.
|
2015-01-27 01:03:25 +01:00
|
|
|
switch (message) {
|
2016-10-28 18:11:24 +02:00
|
|
|
case WM_IME_SETCONTEXT:
|
|
|
|
self->OnIMESetContext(message, wParam, lParam);
|
|
|
|
return 0;
|
|
|
|
case WM_IME_STARTCOMPOSITION:
|
|
|
|
self->OnIMEStartComposition();
|
|
|
|
return 0;
|
|
|
|
case WM_IME_COMPOSITION:
|
|
|
|
self->OnIMEComposition(message, wParam, lParam);
|
|
|
|
return 0;
|
|
|
|
case WM_IME_ENDCOMPOSITION:
|
|
|
|
self->OnIMECancelCompositionEvent();
|
|
|
|
// Let WTL call::DefWindowProc() and release its resources.
|
|
|
|
break;
|
2017-05-12 20:28:25 +02:00
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
case WM_GETOBJECT: {
|
|
|
|
// Only the lower 32 bits of lParam are valid when checking the object id
|
|
|
|
// because it sometimes gets sign-extended incorrectly (but not always).
|
|
|
|
DWORD obj_id = static_cast<DWORD>(static_cast<DWORD_PTR>(lParam));
|
|
|
|
|
|
|
|
// Accessibility readers will send an OBJID_CLIENT message.
|
|
|
|
if (static_cast<DWORD>(OBJID_CLIENT) == obj_id) {
|
|
|
|
if (self->accessibility_root_) {
|
2017-05-17 11:29:28 +02:00
|
|
|
return LresultFromObject(
|
|
|
|
IID_IAccessible, wParam,
|
2017-05-12 20:28:25 +02:00
|
|
|
static_cast<IAccessible*>(self->accessibility_root_));
|
|
|
|
} else {
|
|
|
|
// Notify the renderer to enable accessibility.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (self->browser_ && self->browser_->GetHost()) {
|
2017-05-12 20:28:25 +02:00
|
|
|
self->browser_->GetHost()->SetAccessibilityState(STATE_ENABLED);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-05-12 20:28:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
#endif
|
2015-01-27 01:03:25 +01:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
case WM_MOUSEWHEEL:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnMouseEvent(message, wParam, lParam);
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SIZE:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnSize();
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
case WM_KILLFOCUS:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnFocus(message == WM_SETFOCUS);
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
case WM_CANCELMODE:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnCaptureLost();
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_SYSCHAR:
|
|
|
|
case WM_SYSKEYDOWN:
|
|
|
|
case WM_SYSKEYUP:
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
case WM_KEYUP:
|
|
|
|
case WM_CHAR:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnKeyEvent(message, wParam, lParam);
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_PAINT:
|
2015-04-09 16:59:34 +02:00
|
|
|
self->OnPaint();
|
2015-01-27 01:03:25 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case WM_ERASEBKGND:
|
2023-01-02 23:59:03 +01:00
|
|
|
if (self->OnEraseBkgnd()) {
|
2015-04-09 16:59:34 +02:00
|
|
|
break;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-04-09 16:59:34 +02:00
|
|
|
// Don't erase the background.
|
2015-01-27 01:03:25 +01:00
|
|
|
return 0;
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
// If your application does not require Win7 support, please do consider
|
|
|
|
// using WM_POINTER* messages instead of WM_TOUCH. WM_POINTER are more
|
|
|
|
// intutive, complete and simpler to code.
|
|
|
|
// https://msdn.microsoft.com/en-us/library/hh454903(v=vs.85).aspx
|
|
|
|
case WM_TOUCH:
|
2023-01-02 23:59:03 +01:00
|
|
|
if (self->OnTouchEvent(message, wParam, lParam)) {
|
2019-02-25 22:17:28 +01:00
|
|
|
return 0;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
break;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
case WM_NCDESTROY:
|
|
|
|
// Clear the reference to |self|.
|
2021-06-17 22:08:01 +02:00
|
|
|
SetUserDataPtr(hWnd, nullptr);
|
|
|
|
self->hwnd_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hWnd, message, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnMouseEvent(UINT message, WPARAM wParam, LPARAM lParam) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IsMouseEventFromTouch(message)) {
|
2019-02-25 22:17:28 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
CefRefPtr<CefBrowserHost> browser_host;
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_host = browser_->GetHost();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
LONG currentTime = 0;
|
|
|
|
bool cancelPreviousClick = false;
|
|
|
|
|
|
|
|
if (message == WM_LBUTTONDOWN || message == WM_RBUTTONDOWN ||
|
|
|
|
message == WM_MBUTTONDOWN || message == WM_MOUSEMOVE ||
|
|
|
|
message == WM_MOUSELEAVE) {
|
|
|
|
currentTime = GetMessageTime();
|
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
cancelPreviousClick =
|
2017-05-17 11:29:28 +02:00
|
|
|
(abs(last_click_x_ - x) > (GetSystemMetrics(SM_CXDOUBLECLK) / 2)) ||
|
|
|
|
(abs(last_click_y_ - y) > (GetSystemMetrics(SM_CYDOUBLECLK) / 2)) ||
|
|
|
|
((currentTime - last_click_time_) > GetDoubleClickTime());
|
2015-01-27 01:03:25 +01:00
|
|
|
if (cancelPreviousClick &&
|
|
|
|
(message == WM_MOUSEMOVE || message == WM_MOUSELEAVE)) {
|
2020-01-31 22:27:55 +01:00
|
|
|
last_click_count_ = 1;
|
2015-01-27 01:03:25 +01:00
|
|
|
last_click_x_ = 0;
|
|
|
|
last_click_y_ = 0;
|
|
|
|
last_click_time_ = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
switch (message) {
|
2015-01-27 01:03:25 +01:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN: {
|
|
|
|
::SetCapture(hwnd_);
|
|
|
|
::SetFocus(hwnd_);
|
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
if (wParam & MK_SHIFT) {
|
|
|
|
// Start rotation effect.
|
|
|
|
last_mouse_pos_.x = current_mouse_pos_.x = x;
|
|
|
|
last_mouse_pos_.y = current_mouse_pos_.y = y;
|
|
|
|
mouse_rotation_ = true;
|
|
|
|
} else {
|
|
|
|
CefBrowserHost::MouseButtonType btnType =
|
2017-05-17 11:29:28 +02:00
|
|
|
(message == WM_LBUTTONDOWN
|
|
|
|
? MBT_LEFT
|
|
|
|
: (message == WM_RBUTTONDOWN ? MBT_RIGHT : MBT_MIDDLE));
|
2015-01-27 01:03:25 +01:00
|
|
|
if (!cancelPreviousClick && (btnType == last_click_button_)) {
|
|
|
|
++last_click_count_;
|
|
|
|
} else {
|
|
|
|
last_click_count_ = 1;
|
|
|
|
last_click_x_ = x;
|
|
|
|
last_click_y_ = y;
|
|
|
|
}
|
|
|
|
last_click_time_ = currentTime;
|
|
|
|
last_click_button_ = btnType;
|
|
|
|
|
|
|
|
if (browser_host) {
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = x;
|
|
|
|
mouse_event.y = y;
|
|
|
|
last_mouse_down_on_view_ = !IsOverPopupWidget(x, y);
|
|
|
|
ApplyPopupOffset(mouse_event.x, mouse_event.y);
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(mouse_event, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
mouse_event.modifiers = GetCefMouseModifiers(wParam);
|
|
|
|
browser_host->SendMouseClickEvent(mouse_event, btnType, false,
|
|
|
|
last_click_count_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
case WM_MBUTTONUP:
|
2023-01-02 23:59:03 +01:00
|
|
|
if (GetCapture() == hwnd_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
ReleaseCapture();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
if (mouse_rotation_) {
|
|
|
|
// End rotation effect.
|
|
|
|
mouse_rotation_ = false;
|
2018-09-26 13:25:58 +02:00
|
|
|
render_handler_->SetSpin(0, 0);
|
2015-01-27 01:03:25 +01:00
|
|
|
} else {
|
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
CefBrowserHost::MouseButtonType btnType =
|
2017-05-17 11:29:28 +02:00
|
|
|
(message == WM_LBUTTONUP
|
|
|
|
? MBT_LEFT
|
|
|
|
: (message == WM_RBUTTONUP ? MBT_RIGHT : MBT_MIDDLE));
|
2015-01-27 01:03:25 +01:00
|
|
|
if (browser_host) {
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = x;
|
|
|
|
mouse_event.y = y;
|
2017-05-17 11:29:28 +02:00
|
|
|
if (last_mouse_down_on_view_ && IsOverPopupWidget(x, y) &&
|
2015-01-27 01:03:25 +01:00
|
|
|
(GetPopupXOffset() || GetPopupYOffset())) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ApplyPopupOffset(mouse_event.x, mouse_event.y);
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(mouse_event, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
mouse_event.modifiers = GetCefMouseModifiers(wParam);
|
|
|
|
browser_host->SendMouseClickEvent(mouse_event, btnType, true,
|
|
|
|
last_click_count_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_MOUSEMOVE: {
|
|
|
|
int x = GET_X_LPARAM(lParam);
|
|
|
|
int y = GET_Y_LPARAM(lParam);
|
|
|
|
if (mouse_rotation_) {
|
|
|
|
// Apply rotation effect.
|
|
|
|
current_mouse_pos_.x = x;
|
|
|
|
current_mouse_pos_.y = y;
|
2018-09-26 13:25:58 +02:00
|
|
|
render_handler_->IncrementSpin(
|
|
|
|
current_mouse_pos_.x - last_mouse_pos_.x,
|
|
|
|
current_mouse_pos_.y - last_mouse_pos_.y);
|
2015-01-27 01:03:25 +01:00
|
|
|
last_mouse_pos_.x = current_mouse_pos_.x;
|
|
|
|
last_mouse_pos_.y = current_mouse_pos_.y;
|
|
|
|
} else {
|
|
|
|
if (!mouse_tracking_) {
|
|
|
|
// Start tracking mouse leave. Required for the WM_MOUSELEAVE event to
|
|
|
|
// be generated.
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
tme.dwFlags = TME_LEAVE;
|
|
|
|
tme.hwndTrack = hwnd_;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
mouse_tracking_ = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser_host) {
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = x;
|
|
|
|
mouse_event.y = y;
|
|
|
|
ApplyPopupOffset(mouse_event.x, mouse_event.y);
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(mouse_event, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
mouse_event.modifiers = GetCefMouseModifiers(wParam);
|
|
|
|
browser_host->SendMouseMoveEvent(mouse_event, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_MOUSELEAVE: {
|
|
|
|
if (mouse_tracking_) {
|
|
|
|
// Stop tracking mouse leave.
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
tme.dwFlags = TME_LEAVE & TME_CANCEL;
|
|
|
|
tme.hwndTrack = hwnd_;
|
|
|
|
TrackMouseEvent(&tme);
|
|
|
|
mouse_tracking_ = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (browser_host) {
|
|
|
|
// Determine the cursor position in screen coordinates.
|
|
|
|
POINT p;
|
|
|
|
::GetCursorPos(&p);
|
|
|
|
::ScreenToClient(hwnd_, &p);
|
|
|
|
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = p.x;
|
|
|
|
mouse_event.y = p.y;
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(mouse_event, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
mouse_event.modifiers = GetCefMouseModifiers(wParam);
|
|
|
|
browser_host->SendMouseMoveEvent(mouse_event, true);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WM_MOUSEWHEEL:
|
|
|
|
if (browser_host) {
|
|
|
|
POINT screen_point = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
|
|
|
|
HWND scrolled_wnd = ::WindowFromPoint(screen_point);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (scrolled_wnd != hwnd_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
break;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
ScreenToClient(hwnd_, &screen_point);
|
|
|
|
int delta = GET_WHEEL_DELTA_WPARAM(wParam);
|
|
|
|
|
|
|
|
CefMouseEvent mouse_event;
|
|
|
|
mouse_event.x = screen_point.x;
|
|
|
|
mouse_event.y = screen_point.y;
|
|
|
|
ApplyPopupOffset(mouse_event.x, mouse_event.y);
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(mouse_event, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
mouse_event.modifiers = GetCefMouseModifiers(wParam);
|
|
|
|
browser_host->SendMouseWheelEvent(mouse_event,
|
|
|
|
IsKeyDown(VK_SHIFT) ? delta : 0,
|
|
|
|
!IsKeyDown(VK_SHIFT) ? delta : 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnSize() {
|
|
|
|
// Keep |client_rect_| up to date.
|
|
|
|
::GetClientRect(hwnd_, &client_rect_);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->WasResized();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnFocus(bool setFocus) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2021-09-27 09:50:07 +02:00
|
|
|
browser_->GetHost()->SetFocus(setFocus);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnCaptureLost() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (mouse_rotation_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->SendCaptureLostEvent();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
CefKeyEvent event;
|
|
|
|
event.windows_key_code = wParam;
|
|
|
|
event.native_key_code = lParam;
|
2017-05-17 11:29:28 +02:00
|
|
|
event.is_system_key = message == WM_SYSCHAR || message == WM_SYSKEYDOWN ||
|
2015-01-27 01:03:25 +01:00
|
|
|
message == WM_SYSKEYUP;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN) {
|
2015-01-27 01:03:25 +01:00
|
|
|
event.type = KEYEVENT_RAWKEYDOWN;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else if (message == WM_KEYUP || message == WM_SYSKEYUP) {
|
2015-01-27 01:03:25 +01:00
|
|
|
event.type = KEYEVENT_KEYUP;
|
2023-01-02 23:59:03 +01:00
|
|
|
} else {
|
2015-01-27 01:03:25 +01:00
|
|
|
event.type = KEYEVENT_CHAR;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
event.modifiers = GetCefKeyboardModifiers(wParam, lParam);
|
|
|
|
|
2020-04-08 17:43:39 +02:00
|
|
|
// mimic alt-gr check behaviour from
|
|
|
|
// src/ui/events/win/events_win_utils.cc: GetModifiersFromKeyState
|
|
|
|
if ((event.type == KEYEVENT_CHAR) && IsKeyDown(VK_RMENU)) {
|
|
|
|
// reverse AltGr detection taken from PlatformKeyMap::UsesAltGraph
|
|
|
|
// instead of checking all combination for ctrl-alt, just check current char
|
|
|
|
HKL current_layout = ::GetKeyboardLayout(0);
|
|
|
|
|
|
|
|
// https://docs.microsoft.com/en-gb/windows/win32/api/winuser/nf-winuser-vkkeyscanexw
|
|
|
|
// ... high-order byte contains the shift state,
|
|
|
|
// which can be a combination of the following flag bits.
|
2021-07-19 17:55:43 +02:00
|
|
|
// 1 Either SHIFT key is pressed.
|
2020-04-08 17:43:39 +02:00
|
|
|
// 2 Either CTRL key is pressed.
|
|
|
|
// 4 Either ALT key is pressed.
|
|
|
|
SHORT scan_res = ::VkKeyScanExW(wParam, current_layout);
|
2021-07-19 17:55:43 +02:00
|
|
|
constexpr auto ctrlAlt = (2 | 4);
|
|
|
|
if (((scan_res >> 8) & ctrlAlt) == ctrlAlt) { // ctrl-alt pressed
|
2020-04-08 17:43:39 +02:00
|
|
|
event.modifiers &= ~(EVENTFLAG_CONTROL_DOWN | EVENTFLAG_ALT_DOWN);
|
|
|
|
event.modifiers |= EVENTFLAG_ALTGR_DOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->SendKeyEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnPaint() {
|
|
|
|
// Paint nothing here. Invalidate will cause OnPaint to be called for the
|
|
|
|
// render handler.
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
BeginPaint(hwnd_, &ps);
|
|
|
|
EndPaint(hwnd_, &ps);
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->Invalidate(PET_VIEW);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 16:59:34 +02:00
|
|
|
bool OsrWindowWin::OnEraseBkgnd() {
|
|
|
|
// Erase the background when the browser does not exist.
|
2020-01-15 15:28:12 +01:00
|
|
|
return (browser_ == nullptr);
|
2015-04-09 16:59:34 +02:00
|
|
|
}
|
|
|
|
|
2019-02-25 22:17:28 +01:00
|
|
|
bool OsrWindowWin::OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam) {
|
|
|
|
// Handle touch events on Windows.
|
|
|
|
int num_points = LOWORD(wParam);
|
|
|
|
// Chromium only supports upto 16 touch points.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (num_points < 0 || num_points > 16) {
|
2019-02-25 22:17:28 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
std::unique_ptr<TOUCHINPUT[]> input(new TOUCHINPUT[num_points]);
|
|
|
|
if (GetTouchInputInfo(reinterpret_cast<HTOUCHINPUT>(lParam), num_points,
|
|
|
|
input.get(), sizeof(TOUCHINPUT))) {
|
|
|
|
CefTouchEvent touch_event;
|
|
|
|
for (int i = 0; i < num_points; ++i) {
|
|
|
|
POINT point;
|
|
|
|
point.x = TOUCH_COORD_TO_PIXEL(input[i].x);
|
|
|
|
point.y = TOUCH_COORD_TO_PIXEL(input[i].y);
|
|
|
|
|
|
|
|
if (!IsWindows_8_Or_Newer()) {
|
|
|
|
// Windows 7 sends touch events for touches in the non-client area,
|
|
|
|
// whereas Windows 8 does not. In order to unify the behaviour, always
|
|
|
|
// ignore touch events in the non-client area.
|
|
|
|
LPARAM l_param_ht = MAKELPARAM(point.x, point.y);
|
|
|
|
LRESULT hittest = SendMessage(hwnd_, WM_NCHITTEST, 0, l_param_ht);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (hittest != HTCLIENT) {
|
2019-02-25 22:17:28 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ScreenToClient(hwnd_, &point);
|
|
|
|
touch_event.x = DeviceToLogical(point.x, device_scale_factor_);
|
|
|
|
touch_event.y = DeviceToLogical(point.y, device_scale_factor_);
|
|
|
|
|
|
|
|
// Touch point identifier stays consistent in a touch contact sequence
|
|
|
|
touch_event.id = input[i].dwID;
|
|
|
|
|
|
|
|
if (input[i].dwFlags & TOUCHEVENTF_DOWN) {
|
|
|
|
touch_event.type = CEF_TET_PRESSED;
|
|
|
|
} else if (input[i].dwFlags & TOUCHEVENTF_MOVE) {
|
|
|
|
touch_event.type = CEF_TET_MOVED;
|
|
|
|
} else if (input[i].dwFlags & TOUCHEVENTF_UP) {
|
|
|
|
touch_event.type = CEF_TET_RELEASED;
|
|
|
|
}
|
|
|
|
|
|
|
|
touch_event.radius_x = 0;
|
|
|
|
touch_event.radius_y = 0;
|
|
|
|
touch_event.rotation_angle = 0;
|
|
|
|
touch_event.pressure = 0;
|
|
|
|
touch_event.modifiers = 0;
|
|
|
|
|
|
|
|
// Notify the browser of touch event
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2019-02-25 22:17:28 +01:00
|
|
|
browser_->GetHost()->SendTouchEvent(touch_event);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2019-02-25 22:17:28 +01:00
|
|
|
}
|
|
|
|
CloseTouchInputHandle(reinterpret_cast<HTOUCHINPUT>(lParam));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
bool OsrWindowWin::IsOverPopupWidget(int x, int y) const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!render_handler_) {
|
2018-09-26 13:25:58 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2018-09-26 13:25:58 +02:00
|
|
|
return render_handler_->IsOverPopupWidget(x, y);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int OsrWindowWin::GetPopupXOffset() const {
|
2018-09-26 13:25:58 +02:00
|
|
|
return render_handler_->GetPopupXOffset();
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int OsrWindowWin::GetPopupYOffset() const {
|
2018-09-26 13:25:58 +02:00
|
|
|
return render_handler_->GetPopupYOffset();
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::ApplyPopupOffset(int& x, int& y) const {
|
|
|
|
if (IsOverPopupWidget(x, y)) {
|
|
|
|
x += GetPopupXOffset();
|
|
|
|
y += GetPopupYOffset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
DCHECK(!browser_);
|
|
|
|
browser_ = browser;
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
if (hwnd_) {
|
|
|
|
// The native window will already exist for non-popup browsers.
|
|
|
|
EnsureRenderHandler();
|
|
|
|
render_handler_->SetBrowser(browser);
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
if (hwnd_) {
|
|
|
|
// Show the browser window. Called asynchronously so that the browser has
|
|
|
|
// time to create associated internal objects.
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Show, this));
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2015-01-29 21:53:53 +01:00
|
|
|
// Detach |this| from the ClientHandlerOsr.
|
2017-05-17 11:29:28 +02:00
|
|
|
static_cast<ClientHandlerOsr*>(browser_->GetHost()->GetClient().get())
|
|
|
|
->DetachOsrDelegate();
|
2020-01-15 15:28:12 +01:00
|
|
|
browser_ = nullptr;
|
|
|
|
render_handler_->SetBrowser(nullptr);
|
2015-01-27 01:03:25 +01:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OsrWindowWin::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRect& rect) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-25 15:40:02 +02:00
|
|
|
void OsrWindowWin::GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) {
|
2015-01-27 01:03:25 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2018-02-20 23:24:59 +01:00
|
|
|
DCHECK_GT(device_scale_factor_, 0);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2015-08-08 01:00:07 +02:00
|
|
|
rect.x = rect.y = 0;
|
|
|
|
rect.width = DeviceToLogical(client_rect_.right - client_rect_.left,
|
2015-08-10 22:49:45 +02:00
|
|
|
device_scale_factor_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (rect.width == 0) {
|
2018-09-26 15:09:46 +02:00
|
|
|
rect.width = 1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-08 01:00:07 +02:00
|
|
|
rect.height = DeviceToLogical(client_rect_.bottom - client_rect_.top,
|
2015-08-10 22:49:45 +02:00
|
|
|
device_scale_factor_);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (rect.height == 0) {
|
2018-09-26 15:09:46 +02:00
|
|
|
rect.height = 1;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool OsrWindowWin::GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
|
|
|
int& screenY) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2018-02-20 23:24:59 +01:00
|
|
|
DCHECK_GT(device_scale_factor_, 0);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!::IsWindow(hwnd_)) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2022-05-13 13:38:41 +02:00
|
|
|
// Convert from view DIP coordinates to screen device (pixel) coordinates.
|
2017-05-17 11:29:28 +02:00
|
|
|
POINT screen_pt = {LogicalToDevice(viewX, device_scale_factor_),
|
|
|
|
LogicalToDevice(viewY, device_scale_factor_)};
|
2015-01-27 01:03:25 +01:00
|
|
|
ClientToScreen(hwnd_, &screen_pt);
|
|
|
|
screenX = screen_pt.x;
|
|
|
|
screenY = screen_pt.y;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OsrWindowWin::GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefScreenInfo& screen_info) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
2018-02-20 23:24:59 +01:00
|
|
|
DCHECK_GT(device_scale_factor_, 0);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!::IsWindow(hwnd_)) {
|
2015-08-08 01:00:07 +02:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-08 01:00:07 +02:00
|
|
|
|
|
|
|
CefRect view_rect;
|
|
|
|
GetViewRect(browser, view_rect);
|
|
|
|
|
2015-08-10 22:49:45 +02:00
|
|
|
screen_info.device_scale_factor = device_scale_factor_;
|
2015-08-08 01:00:07 +02:00
|
|
|
|
|
|
|
// The screen info rectangles are used by the renderer to create and position
|
|
|
|
// popups. Keep popups inside the view rectangle.
|
|
|
|
screen_info.rect = view_rect;
|
|
|
|
screen_info.available_rect = view_rect;
|
|
|
|
return true;
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OsrWindowWin::OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) {
|
2018-09-26 13:25:58 +02:00
|
|
|
render_handler_->OnPopupShow(browser, show);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnPopupSize(CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRect& rect) {
|
2018-09-26 13:25:58 +02:00
|
|
|
render_handler_->OnPopupSize(browser,
|
|
|
|
LogicalToDevice(rect, device_scale_factor_));
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
|
|
|
int height) {
|
2018-09-26 13:25:58 +02:00
|
|
|
EnsureRenderHandler();
|
|
|
|
render_handler_->OnPaint(browser, type, dirtyRects, buffer, width, height);
|
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
void OsrWindowWin::OnAcceleratedPaint(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
2024-03-08 13:44:56 +01:00
|
|
|
const CefAcceleratedPaintInfo& info) {
|
2018-09-26 13:25:58 +02:00
|
|
|
EnsureRenderHandler();
|
2024-03-08 13:44:56 +01:00
|
|
|
render_handler_->OnAcceleratedPaint(browser, type, dirtyRects, info);
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OsrWindowWin::OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_type_t type,
|
2017-05-17 11:29:28 +02:00
|
|
|
const CefCursorInfo& custom_cursor_info) {
|
2015-01-27 01:03:25 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!::IsWindow(hwnd_)) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2022-02-18 21:43:30 +01:00
|
|
|
// Change the window's cursor.
|
2015-01-27 01:03:25 +01:00
|
|
|
SetClassLongPtr(hwnd_, GCLP_HCURSOR,
|
|
|
|
static_cast<LONG>(reinterpret_cast<LONG_PTR>(cursor)));
|
|
|
|
SetCursor(cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OsrWindowWin::StartDragging(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
|
|
|
int y) {
|
2015-01-27 01:03:25 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!drop_target_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-08-08 01:00:07 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
current_drag_op_ = DRAG_OPERATION_NONE;
|
|
|
|
CefBrowserHost::DragOperationsMask result =
|
|
|
|
drop_target_->StartDragging(browser, drag_data, allowed_ops, x, y);
|
|
|
|
current_drag_op_ = DRAG_OPERATION_NONE;
|
|
|
|
POINT pt = {};
|
|
|
|
GetCursorPos(&pt);
|
|
|
|
ScreenToClient(hwnd_, &pt);
|
2015-08-08 01:00:07 +02:00
|
|
|
|
|
|
|
browser->GetHost()->DragSourceEndedAt(
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(pt.x, device_scale_factor_),
|
2017-05-17 11:29:28 +02:00
|
|
|
DeviceToLogical(pt.y, device_scale_factor_), result);
|
2015-01-27 01:03:25 +01:00
|
|
|
browser->GetHost()->DragSourceSystemDragEnded();
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
// Cancel the drag. The dragging implementation requires ATL support.
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void OsrWindowWin::UpdateDragCursor(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::DragOperation operation) {
|
2015-01-27 01:03:25 +01:00
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
current_drag_op_ = operation;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
void OsrWindowWin::OnImeCompositionRangeChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRange& selection_range,
|
|
|
|
const CefRenderHandler::RectList& character_bounds) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
if (ime_handler_) {
|
|
|
|
// Convert from view coordinates to device coordinates.
|
|
|
|
CefRenderHandler::RectList device_bounds;
|
|
|
|
CefRenderHandler::RectList::const_iterator it = character_bounds.begin();
|
|
|
|
for (; it != character_bounds.end(); ++it) {
|
|
|
|
device_bounds.push_back(LogicalToDevice(*it, device_scale_factor_));
|
|
|
|
}
|
|
|
|
|
|
|
|
ime_handler_->ChangeCompositionRange(selection_range, device_bounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
void OsrWindowWin::UpdateAccessibilityTree(CefRefPtr<CefValue> value) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
if (!accessibility_handler_) {
|
2024-01-20 03:22:56 +01:00
|
|
|
accessibility_handler_ =
|
|
|
|
std::make_unique<OsrAccessibilityHelper>(value, browser_);
|
2017-05-12 20:28:25 +02:00
|
|
|
} else {
|
|
|
|
accessibility_handler_->UpdateAccessibilityTree(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update |accessibility_root_| because UpdateAccessibilityTree may have
|
|
|
|
// cleared it.
|
|
|
|
OsrAXNode* root = accessibility_handler_->GetRootNode();
|
2020-01-15 15:28:12 +01:00
|
|
|
accessibility_root_ =
|
|
|
|
root ? root->GetNativeAccessibleObject(nullptr) : nullptr;
|
2017-05-12 20:28:25 +02:00
|
|
|
#endif // defined(CEF_USE_ATL)
|
|
|
|
}
|
|
|
|
|
2019-03-21 17:56:06 +01:00
|
|
|
void OsrWindowWin::UpdateAccessibilityLocation(CefRefPtr<CefValue> value) {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
if (accessibility_handler_) {
|
|
|
|
accessibility_handler_->UpdateAccessibilityLocation(value);
|
|
|
|
}
|
|
|
|
#endif // defined(CEF_USE_ATL)
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserHost::DragOperationsMask OsrWindowWin::OnDragEnter(
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefMouseEvent ev,
|
|
|
|
CefBrowserHost::DragOperationsMask effect) {
|
2015-01-27 01:03:25 +01:00
|
|
|
if (browser_) {
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(ev, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->DragTargetDragEnter(drag_data, ev, effect);
|
|
|
|
browser_->GetHost()->DragTargetDragOver(ev, effect);
|
|
|
|
}
|
|
|
|
return current_drag_op_;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserHost::DragOperationsMask OsrWindowWin::OnDragOver(
|
|
|
|
CefMouseEvent ev,
|
|
|
|
CefBrowserHost::DragOperationsMask effect) {
|
2015-08-08 01:00:07 +02:00
|
|
|
if (browser_) {
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(ev, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->DragTargetDragOver(ev, effect);
|
2015-08-08 01:00:07 +02:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
return current_drag_op_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OsrWindowWin::OnDragLeave() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (browser_) {
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->DragTargetDragLeave();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2015-01-27 01:03:25 +01:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserHost::DragOperationsMask OsrWindowWin::OnDrop(
|
|
|
|
CefMouseEvent ev,
|
|
|
|
CefBrowserHost::DragOperationsMask effect) {
|
2015-01-27 01:03:25 +01:00
|
|
|
if (browser_) {
|
2015-08-10 22:49:45 +02:00
|
|
|
DeviceToLogical(ev, device_scale_factor_);
|
2015-01-27 01:03:25 +01:00
|
|
|
browser_->GetHost()->DragTargetDragOver(ev, effect);
|
|
|
|
browser_->GetHost()->DragTargetDrop(ev);
|
|
|
|
}
|
|
|
|
return current_drag_op_;
|
|
|
|
}
|
|
|
|
|
2019-02-13 18:43:55 +01:00
|
|
|
#endif // defined(CEF_USE_ATL)
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
void OsrWindowWin::EnsureRenderHandler() {
|
|
|
|
CEF_REQUIRE_UI_THREAD();
|
|
|
|
if (!render_handler_) {
|
|
|
|
if (settings_.shared_texture_enabled) {
|
|
|
|
// Try to initialize D3D11 rendering.
|
|
|
|
auto render_handler = new OsrRenderHandlerWinD3D11(settings_, hwnd_);
|
|
|
|
if (render_handler->Initialize(browser_,
|
|
|
|
client_rect_.right - client_rect_.left,
|
|
|
|
client_rect_.bottom - client_rect_.top)) {
|
|
|
|
render_handler_.reset(render_handler);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR) << "Failed to initialize D3D11 rendering.";
|
|
|
|
delete render_handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fall back to GL rendering.
|
|
|
|
if (!render_handler_) {
|
|
|
|
auto render_handler = new OsrRenderHandlerWinGL(settings_, hwnd_);
|
|
|
|
render_handler->Initialize(browser_);
|
|
|
|
render_handler_.reset(render_handler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
} // namespace client
|