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.
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#ifndef CEF_TESTS_CEFCLIENT_BROWSER_OSR_WINDOW_WIN_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_BROWSER_OSR_WINDOW_WIN_H_
|
|
|
|
#pragma once
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
#include "include/base/cef_ref_counted.h"
|
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
|
|
|
#include "include/wrapper/cef_helpers.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/client_handler_osr.h"
|
2017-05-12 20:28:25 +02:00
|
|
|
#include "tests/cefclient/browser/osr_accessibility_node.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/osr_dragdrop_win.h"
|
2018-09-26 13:25:58 +02:00
|
|
|
#include "tests/cefclient/browser/osr_render_handler_win.h"
|
|
|
|
#include "tests/cefclient/browser/osr_renderer_settings.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
2017-05-12 20:28:25 +02:00
|
|
|
class OsrAccessibilityHelper;
|
2016-10-28 18:11:24 +02:00
|
|
|
class OsrImeHandlerWin;
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Represents the native parent window for an off-screen browser. This object
|
|
|
|
// must live on the CEF UI thread in order to handle CefRenderHandler callbacks.
|
|
|
|
// The methods of this class are thread-safe unless otherwise indicated.
|
2017-05-17 11:29:28 +02:00
|
|
|
class OsrWindowWin
|
|
|
|
: public base::RefCountedThreadSafe<OsrWindowWin, CefDeleteOnUIThread>,
|
|
|
|
public ClientHandlerOsr::OsrDelegate
|
2017-05-12 20:28:25 +02:00
|
|
|
#if defined(CEF_USE_ATL)
|
2018-09-25 15:40:02 +02:00
|
|
|
,
|
2017-05-17 11:29:28 +02:00
|
|
|
public OsrDragEvents
|
2015-01-27 01:03:25 +01:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// This interface is implemented by the owner of the OsrWindowWin. The
|
|
|
|
// methods of this class will be called on the main thread.
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
// Called after the native window has been created.
|
|
|
|
virtual void OnOsrNativeWindowCreated(HWND hwnd) = 0;
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 03:22:56 +01:00
|
|
|
virtual ~Delegate() = default;
|
2015-01-27 01:03:25 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// |delegate| must outlive this object.
|
2018-09-26 13:25:58 +02:00
|
|
|
OsrWindowWin(Delegate* delegate, const OsrRendererSettings& settings);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Create a new browser and native window.
|
|
|
|
void 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);
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Show the popup window with correct parent and bounds in parent coordinates.
|
|
|
|
void ShowPopup(HWND parent_hwnd, int x, int y, size_t width, size_t height);
|
|
|
|
|
|
|
|
void Show();
|
|
|
|
void Hide();
|
|
|
|
void SetBounds(int x, int y, size_t width, size_t height);
|
|
|
|
void SetFocus();
|
2015-08-10 22:49:45 +02:00
|
|
|
void SetDeviceScaleFactor(float device_scale_factor);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
const OsrRendererSettings& settings() const { return settings_; }
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
private:
|
|
|
|
// Only allow deletion via scoped_refptr.
|
|
|
|
friend struct CefDeleteOnThread<TID_UI>;
|
|
|
|
friend class base::RefCountedThreadSafe<OsrWindowWin, CefDeleteOnUIThread>;
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
~OsrWindowWin() override;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Manage native window lifespan.
|
|
|
|
void Create(HWND parent_hwnd, const RECT& rect);
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
void NotifyNativeWindowCreated(HWND hwnd);
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
static void RegisterOsrClass(HINSTANCE hInstance, HBRUSH background_brush);
|
|
|
|
static LRESULT CALLBACK OsrWndProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
2015-01-27 01:03:25 +01:00
|
|
|
LPARAM lParam);
|
|
|
|
|
|
|
|
// WndProc message handlers.
|
|
|
|
void OnMouseEvent(UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
void OnSize();
|
|
|
|
void OnFocus(bool setFocus);
|
|
|
|
void OnCaptureLost();
|
|
|
|
void OnKeyEvent(UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
void OnPaint();
|
2015-04-09 16:59:34 +02:00
|
|
|
bool OnEraseBkgnd();
|
2019-02-25 22:17:28 +01:00
|
|
|
bool OnTouchEvent(UINT message, WPARAM wParam, LPARAM lParam);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
void OnIMESetContext(UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
void OnIMEStartComposition();
|
|
|
|
void OnIMEComposition(UINT message, WPARAM wParam, LPARAM lParam);
|
|
|
|
void OnIMECancelCompositionEvent();
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Manage popup bounds.
|
|
|
|
bool IsOverPopupWidget(int x, int y) const;
|
|
|
|
int GetPopupXOffset() const;
|
|
|
|
int GetPopupYOffset() const;
|
|
|
|
void ApplyPopupOffset(int& x, int& y) const;
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// ClientHandlerOsr::OsrDelegate methods.
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnAfterCreated(CefRefPtr<CefBrowser> browser) override;
|
|
|
|
void OnBeforeClose(CefRefPtr<CefBrowser> browser) override;
|
|
|
|
bool GetRootScreenRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override;
|
|
|
|
void GetViewRect(CefRefPtr<CefBrowser> browser, CefRect& rect) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
|
|
|
|
int viewX,
|
|
|
|
int viewY,
|
|
|
|
int& screenX,
|
2021-06-17 21:43:06 +02:00
|
|
|
int& screenY) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefScreenInfo& screen_info) override;
|
|
|
|
void OnPopupShow(CefRefPtr<CefBrowser> browser, bool show) override;
|
|
|
|
void OnPopupSize(CefRefPtr<CefBrowser> browser, const CefRect& rect) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
void OnPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
|
|
|
const void* buffer,
|
|
|
|
int width,
|
2021-06-17 21:43:06 +02:00
|
|
|
int height) override;
|
2018-09-26 13:25:58 +02:00
|
|
|
void OnAcceleratedPaint(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRenderHandler::PaintElementType type,
|
|
|
|
const CefRenderHandler::RectList& dirtyRects,
|
2024-03-08 13:44:56 +01:00
|
|
|
const CefAcceleratedPaintInfo& info) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
void OnCursorChange(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefCursorHandle cursor,
|
2020-10-28 17:30:54 +01:00
|
|
|
cef_cursor_type_t type,
|
2021-06-17 21:43:06 +02:00
|
|
|
const CefCursorInfo& custom_cursor_info) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
bool StartDragging(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefRenderHandler::DragOperationsMask allowed_ops,
|
2017-05-17 11:29:28 +02:00
|
|
|
int x,
|
2021-06-17 21:43:06 +02:00
|
|
|
int y) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
void UpdateDragCursor(CefRefPtr<CefBrowser> browser,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefRenderHandler::DragOperation operation) override;
|
2016-10-28 18:11:24 +02:00
|
|
|
void OnImeCompositionRangeChanged(
|
|
|
|
CefRefPtr<CefBrowser> browser,
|
|
|
|
const CefRange& selection_range,
|
2021-06-17 21:43:06 +02:00
|
|
|
const CefRenderHandler::RectList& character_bounds) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void UpdateAccessibilityTree(CefRefPtr<CefValue> value) override;
|
2019-03-21 17:56:06 +01:00
|
|
|
|
2021-06-17 21:43:06 +02:00
|
|
|
void UpdateAccessibilityLocation(CefRefPtr<CefValue> value) override;
|
2017-05-12 20:28:25 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
// OsrDragEvents methods.
|
|
|
|
CefBrowserHost::DragOperationsMask OnDragEnter(
|
|
|
|
CefRefPtr<CefDragData> drag_data,
|
|
|
|
CefMouseEvent ev,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefBrowserHost::DragOperationsMask effect) override;
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserHost::DragOperationsMask OnDragOver(
|
|
|
|
CefMouseEvent ev,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefBrowserHost::DragOperationsMask effect) override;
|
|
|
|
void OnDragLeave() override;
|
2017-05-17 11:29:28 +02:00
|
|
|
CefBrowserHost::DragOperationsMask OnDrop(
|
|
|
|
CefMouseEvent ev,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefBrowserHost::DragOperationsMask effect) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
#endif // defined(CEF_USE_ATL)
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
void EnsureRenderHandler();
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Only accessed on the main thread.
|
|
|
|
Delegate* delegate_;
|
|
|
|
|
2018-09-26 13:25:58 +02:00
|
|
|
const OsrRendererSettings settings_;
|
2024-01-20 03:22:56 +01:00
|
|
|
HWND hwnd_ = nullptr;
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<OsrRenderHandlerWin> render_handler_;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2016-10-28 18:11:24 +02:00
|
|
|
// Class that encapsulates IMM32 APIs and controls IMEs attached to a window.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<OsrImeHandlerWin> ime_handler_;
|
2016-10-28 18:11:24 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
RECT client_rect_;
|
2024-01-20 03:22:56 +01:00
|
|
|
float device_scale_factor_ = 0;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
|
|
|
|
#if defined(CEF_USE_ATL)
|
|
|
|
CComPtr<DropTargetWin> drop_target_;
|
|
|
|
CefRenderHandler::DragOperation current_drag_op_;
|
2017-05-12 20:28:25 +02:00
|
|
|
|
|
|
|
// Class that abstracts the accessibility information received from the
|
|
|
|
// renderer.
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<OsrAccessibilityHelper> accessibility_handler_;
|
2017-05-12 20:28:25 +02:00
|
|
|
IAccessible* accessibility_root_;
|
2015-01-27 01:03:25 +01:00
|
|
|
#endif
|
|
|
|
|
2024-01-20 03:22:56 +01:00
|
|
|
bool hidden_ = false;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Mouse state tracking.
|
|
|
|
POINT last_mouse_pos_;
|
|
|
|
POINT current_mouse_pos_;
|
2024-01-20 03:22:56 +01:00
|
|
|
bool mouse_rotation_ = false;
|
|
|
|
bool mouse_tracking_ = false;
|
|
|
|
int last_click_x_ = 0;
|
|
|
|
int last_click_y_ = 0;
|
|
|
|
CefBrowserHost::MouseButtonType last_click_button_ = MBT_LEFT;
|
|
|
|
int last_click_count_ = 1;
|
|
|
|
double last_click_time_ = 0;
|
|
|
|
bool last_mouse_down_on_view_ = false;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(OsrWindowWin);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace client
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_OSR_WINDOW_WIN_H_
|