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_ROOT_WINDOW_WIN_H_
|
|
|
|
#define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_WIN_H_
|
|
|
|
#pragma once
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
#include <windows.h>
|
2017-05-17 11:29:28 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
#include <commdlg.h>
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include <memory>
|
2015-01-27 01:03:25 +01:00
|
|
|
#include <string>
|
|
|
|
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/cefclient/browser/browser_window.h"
|
|
|
|
#include "tests/cefclient/browser/root_window.h"
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
namespace client {
|
|
|
|
|
|
|
|
// Windows implementation of a top-level native window in the browser process.
|
|
|
|
// The methods of this class must be called on the main thread unless otherwise
|
|
|
|
// indicated.
|
2017-05-17 11:29:28 +02:00
|
|
|
class RootWindowWin : public RootWindow, public BrowserWindow::Delegate {
|
2015-01-27 01:03:25 +01:00
|
|
|
public:
|
|
|
|
// Constructor may be called on any thread.
|
|
|
|
RootWindowWin();
|
|
|
|
~RootWindowWin();
|
|
|
|
|
|
|
|
// RootWindow methods.
|
|
|
|
void Init(RootWindow::Delegate* delegate,
|
2021-06-19 21:54:45 +02:00
|
|
|
std::unique_ptr<RootWindowConfig> config,
|
2021-06-17 21:43:06 +02:00
|
|
|
const CefBrowserSettings& settings) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
void InitAsPopup(RootWindow::Delegate* delegate,
|
|
|
|
bool with_controls,
|
|
|
|
bool with_osr,
|
|
|
|
const CefPopupFeatures& popupFeatures,
|
|
|
|
CefWindowInfo& windowInfo,
|
|
|
|
CefRefPtr<CefClient>& client,
|
2021-06-17 21:43:06 +02:00
|
|
|
CefBrowserSettings& settings) override;
|
|
|
|
void Show(ShowMode mode) override;
|
|
|
|
void Hide() override;
|
|
|
|
void SetBounds(int x, int y, size_t width, size_t height) override;
|
|
|
|
void Close(bool force) override;
|
|
|
|
void SetDeviceScaleFactor(float device_scale_factor) override;
|
|
|
|
float GetDeviceScaleFactor() const override;
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() const override;
|
|
|
|
ClientWindowHandle GetWindowHandle() const override;
|
|
|
|
bool WithWindowlessRendering() const override;
|
|
|
|
bool WithExtension() const override;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
private:
|
2022-11-07 21:21:44 +01:00
|
|
|
void ContinueInitOnUIThread(std::unique_ptr<RootWindowConfig> config,
|
|
|
|
const CefBrowserSettings& settings);
|
|
|
|
void ContinueInitOnMainThread(std::unique_ptr<RootWindowConfig> config,
|
|
|
|
const CefBrowserSettings& settings);
|
|
|
|
|
2015-05-13 17:43:50 +02:00
|
|
|
void CreateBrowserWindow(const std::string& startup_url);
|
2017-08-04 00:55:19 +02:00
|
|
|
void CreateRootWindow(const CefBrowserSettings& settings,
|
|
|
|
bool initially_hidden);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Register the root window class.
|
|
|
|
static void RegisterRootClass(HINSTANCE hInstance,
|
2015-04-09 16:59:34 +02:00
|
|
|
const std::wstring& window_class,
|
|
|
|
HBRUSH background_brush);
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Window procedure for the edit field.
|
2017-05-17 11:29:28 +02:00
|
|
|
static LRESULT CALLBACK EditWndProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
2015-01-27 01:03:25 +01:00
|
|
|
LPARAM lParam);
|
|
|
|
|
|
|
|
// Window procedure for the find dialog.
|
2017-05-17 11:29:28 +02:00
|
|
|
static LRESULT CALLBACK FindWndProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
2015-01-27 01:03:25 +01:00
|
|
|
LPARAM lParam);
|
|
|
|
|
|
|
|
// Window procedure for the root window.
|
2017-05-17 11:29:28 +02:00
|
|
|
static LRESULT CALLBACK RootWndProc(HWND hWnd,
|
|
|
|
UINT message,
|
|
|
|
WPARAM wParam,
|
2015-01-27 01:03:25 +01:00
|
|
|
LPARAM lParam);
|
|
|
|
|
|
|
|
// Event handlers.
|
|
|
|
void OnPaint();
|
|
|
|
void OnFocus();
|
2017-08-04 00:55:19 +02:00
|
|
|
void OnActivate(bool active);
|
2015-01-27 01:03:25 +01:00
|
|
|
void OnSize(bool minimized);
|
|
|
|
void OnMove();
|
2018-02-20 23:24:59 +01:00
|
|
|
void OnDpiChanged(WPARAM wParam, LPARAM lParam);
|
2015-04-09 16:59:34 +02:00
|
|
|
bool OnEraseBkgnd();
|
2015-01-27 01:03:25 +01:00
|
|
|
bool OnCommand(UINT id);
|
|
|
|
void OnFind();
|
|
|
|
void OnFindEvent();
|
|
|
|
void OnAbout();
|
2018-02-20 23:24:59 +01:00
|
|
|
void OnNCCreate(LPCREATESTRUCT lpCreateStruct);
|
|
|
|
void OnCreate(LPCREATESTRUCT lpCreateStruct);
|
2015-01-27 01:03:25 +01:00
|
|
|
bool OnClose();
|
|
|
|
void OnDestroyed();
|
|
|
|
|
2015-01-29 21:53:53 +01:00
|
|
|
// BrowserWindow::Delegate methods.
|
2021-06-17 21:43:06 +02:00
|
|
|
void OnBrowserCreated(CefRefPtr<CefBrowser> browser) override;
|
|
|
|
void OnBrowserWindowDestroyed() override;
|
|
|
|
void OnSetAddress(const std::string& url) override;
|
|
|
|
void OnSetTitle(const std::string& title) override;
|
|
|
|
void OnSetFullscreen(bool fullscreen) override;
|
|
|
|
void OnAutoResize(const CefSize& new_size) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
void OnSetLoadingState(bool isLoading,
|
|
|
|
bool canGoBack,
|
2021-06-17 21:43:06 +02:00
|
|
|
bool canGoForward) override;
|
2015-04-24 15:48:32 +02:00
|
|
|
void OnSetDraggableRegions(
|
2021-06-17 21:43:06 +02:00
|
|
|
const std::vector<CefDraggableRegion>& regions) override;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
void NotifyDestroyedIfDone();
|
|
|
|
|
2022-11-07 21:21:44 +01:00
|
|
|
static void SaveWindowRestoreOnUIThread(const WINDOWPLACEMENT& placement);
|
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// After initialization all members are only accessed on the main thread.
|
|
|
|
// Members set during initialization.
|
2022-11-07 21:21:44 +01:00
|
|
|
bool with_controls_ = false;
|
|
|
|
bool always_on_top_ = false;
|
|
|
|
bool with_osr_ = false;
|
|
|
|
bool with_extension_ = false;
|
|
|
|
bool is_popup_ = false;
|
|
|
|
CefRect initial_bounds_;
|
|
|
|
cef_show_state_t initial_show_state_ = CEF_SHOW_STATE_NORMAL;
|
2021-06-17 22:08:01 +02:00
|
|
|
std::unique_ptr<BrowserWindow> browser_window_;
|
2018-02-20 23:24:59 +01:00
|
|
|
CefBrowserSettings browser_settings_;
|
2022-11-07 21:21:44 +01:00
|
|
|
bool initialized_ = false;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Main window.
|
2022-11-07 21:21:44 +01:00
|
|
|
HWND hwnd_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2015-04-24 15:48:32 +02:00
|
|
|
// Draggable region.
|
2022-11-07 21:21:44 +01:00
|
|
|
HRGN draggable_region_ = nullptr;
|
2015-04-24 15:48:32 +02:00
|
|
|
|
2015-08-08 01:00:07 +02:00
|
|
|
// Font for buttons and text fields.
|
2022-11-07 21:21:44 +01:00
|
|
|
HFONT font_ = nullptr;
|
|
|
|
int font_height_ = 0;
|
2015-08-08 01:00:07 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Buttons.
|
2022-11-07 21:21:44 +01:00
|
|
|
HWND back_hwnd_ = nullptr;
|
|
|
|
HWND forward_hwnd_ = nullptr;
|
|
|
|
HWND reload_hwnd_ = nullptr;
|
|
|
|
HWND stop_hwnd_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// URL text field.
|
2022-11-07 21:21:44 +01:00
|
|
|
HWND edit_hwnd_ = nullptr;
|
|
|
|
WNDPROC edit_wndproc_old_ = nullptr;
|
2015-04-24 15:48:32 +02:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
// Find dialog.
|
2022-11-07 21:21:44 +01:00
|
|
|
HWND find_hwnd_ = nullptr;
|
|
|
|
UINT find_message_id_ = 0;
|
|
|
|
WNDPROC find_wndproc_old_ = nullptr;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
|
|
|
// Find dialog state.
|
2022-11-07 21:21:44 +01:00
|
|
|
FINDREPLACE find_state_ = {0};
|
|
|
|
WCHAR find_buff_[80] = {0};
|
2015-01-27 01:03:25 +01:00
|
|
|
std::wstring find_what_last_;
|
2022-11-07 21:21:44 +01:00
|
|
|
bool find_next_ = false;
|
|
|
|
bool find_match_case_last_ = false;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2022-11-07 21:21:44 +01:00
|
|
|
bool window_destroyed_ = false;
|
|
|
|
bool browser_destroyed_ = false;
|
2015-01-27 01:03:25 +01:00
|
|
|
|
2022-11-07 21:21:44 +01:00
|
|
|
bool called_enable_non_client_dpi_scaling_ = false;
|
2018-02-20 23:24:59 +01:00
|
|
|
|
2015-01-27 01:03:25 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RootWindowWin);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace client
|
|
|
|
|
2015-01-31 01:55:56 +01:00
|
|
|
#endif // CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_WIN_H_
|