2016-01-19 21:09:01 +01:00
|
|
|
// Copyright (c) 2016 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.
|
|
|
|
|
2021-06-19 21:54:45 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2016-11-16 00:22:34 +01:00
|
|
|
#include "include/base/cef_callback.h"
|
2024-04-10 23:34:11 +02:00
|
|
|
#include "include/base/cef_callback_helpers.h"
|
2016-11-16 00:22:34 +01:00
|
|
|
#include "include/base/cef_weak_ptr.h"
|
2016-11-15 22:18:41 +01:00
|
|
|
#include "include/cef_waitable_event.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "include/views/cef_window.h"
|
|
|
|
#include "include/views/cef_window_delegate.h"
|
|
|
|
|
|
|
|
class TestWindowDelegate : public CefWindowDelegate {
|
|
|
|
public:
|
|
|
|
// Default window size.
|
|
|
|
static const int kWSize;
|
|
|
|
|
|
|
|
// Test execution callback.
|
2021-06-19 21:54:45 +02:00
|
|
|
using OnWindowCreatedCallback =
|
|
|
|
base::OnceCallback<void(CefRefPtr<CefWindow>)>;
|
|
|
|
using OnWindowDestroyedCallback =
|
|
|
|
base::OnceCallback<void(CefRefPtr<CefWindow>)>;
|
2023-09-25 21:40:17 +02:00
|
|
|
using OnWindowFullscreenTransitionCompleteCallback =
|
|
|
|
base::RepeatingCallback<void(CefRefPtr<CefWindow>, size_t /*count*/)>;
|
2021-06-19 21:54:45 +02:00
|
|
|
using OnAcceleratorCallback =
|
|
|
|
base::RepeatingCallback<bool(CefRefPtr<CefWindow>, int)>;
|
|
|
|
using OnKeyEventCallback =
|
|
|
|
base::RepeatingCallback<bool(CefRefPtr<CefWindow>, const CefKeyEvent&)>;
|
2017-02-17 00:19:43 +01:00
|
|
|
|
|
|
|
struct Config {
|
|
|
|
OnWindowCreatedCallback on_window_created;
|
|
|
|
OnWindowDestroyedCallback on_window_destroyed;
|
2023-09-25 21:40:17 +02:00
|
|
|
OnWindowFullscreenTransitionCompleteCallback
|
|
|
|
on_window_fullscreen_transition_complete;
|
2017-02-17 00:19:43 +01:00
|
|
|
OnAcceleratorCallback on_accelerator;
|
|
|
|
OnKeyEventCallback on_key_event;
|
|
|
|
bool frameless = false;
|
|
|
|
bool close_window = true;
|
|
|
|
int window_size = kWSize;
|
2020-09-02 20:25:25 +02:00
|
|
|
CefPoint window_origin = {};
|
2023-09-25 21:40:17 +02:00
|
|
|
cef_show_state_t initial_show_state = CEF_SHOW_STATE_NORMAL;
|
2017-02-17 00:19:43 +01:00
|
|
|
};
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-10 23:34:11 +02:00
|
|
|
using TestWindowDelegateFactory =
|
|
|
|
base::OnceCallback<TestWindowDelegate*(CefRefPtr<CefWaitableEvent> event,
|
|
|
|
std::unique_ptr<Config> config,
|
|
|
|
const CefSize& window_size)>;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Creates a Window with a new TestWindowDelegate instance and executes
|
|
|
|
// |window_test| after the Window is created. |event| will be signaled once
|
|
|
|
// the Window is closed. If |frameless| is true the Window will be created
|
|
|
|
// without a frame. If |close_window| is true the Window will be closed
|
|
|
|
// immediately after |window_test| returns. Otherwise, the caller is
|
|
|
|
// responsible for closing the Window passed to |window_test|.
|
2021-06-19 21:54:45 +02:00
|
|
|
static void RunTest(CefRefPtr<CefWaitableEvent> event,
|
2024-04-10 23:34:11 +02:00
|
|
|
std::unique_ptr<Config> config,
|
|
|
|
TestWindowDelegateFactory factory = base::NullCallback());
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// CefWindowDelegate methods:
|
|
|
|
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
|
|
|
|
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override;
|
2023-09-25 21:40:17 +02:00
|
|
|
void OnWindowFullscreenTransition(CefRefPtr<CefWindow> window,
|
|
|
|
bool is_completed) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
bool IsFrameless(CefRefPtr<CefWindow> window) override;
|
2020-09-02 20:25:25 +02:00
|
|
|
CefRect GetInitialBounds(CefRefPtr<CefWindow> window) override;
|
2023-09-25 21:40:17 +02:00
|
|
|
cef_show_state_t GetInitialShowState(CefRefPtr<CefWindow> window) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
CefSize GetPreferredSize(CefRefPtr<CefView> view) override;
|
2017-02-17 00:19:43 +01:00
|
|
|
bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id) override;
|
|
|
|
bool OnKeyEvent(CefRefPtr<CefWindow> window,
|
|
|
|
const CefKeyEvent& event) override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-10 23:34:11 +02:00
|
|
|
protected:
|
2019-10-04 16:23:58 +02:00
|
|
|
TestWindowDelegate(CefRefPtr<CefWaitableEvent> event,
|
2021-06-19 21:54:45 +02:00
|
|
|
std::unique_ptr<Config> config,
|
2019-10-04 16:23:58 +02:00
|
|
|
const CefSize& window_size);
|
2016-01-19 21:09:01 +01:00
|
|
|
~TestWindowDelegate() override;
|
|
|
|
|
2024-04-10 23:34:11 +02:00
|
|
|
Config* config() const { return config_.get(); }
|
|
|
|
CefRefPtr<CefWindow> window() const { return window_; }
|
|
|
|
|
|
|
|
private:
|
2016-01-19 21:09:01 +01:00
|
|
|
void OnCloseWindow();
|
|
|
|
void OnTimeoutWindow();
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event_;
|
2021-06-19 21:54:45 +02:00
|
|
|
std::unique_ptr<Config> config_;
|
2019-10-04 16:23:58 +02:00
|
|
|
const CefSize window_size_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
CefRefPtr<CefWindow> window_;
|
|
|
|
|
2020-09-02 20:25:25 +02:00
|
|
|
bool got_get_initial_bounds_ = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
bool got_get_preferred_size_ = false;
|
|
|
|
|
2023-09-25 21:40:17 +02:00
|
|
|
size_t fullscreen_transition_callback_count_ = 0;
|
|
|
|
size_t fullscreen_transition_complete_count_ = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Must be the last member.
|
|
|
|
base::WeakPtrFactory<TestWindowDelegate> weak_ptr_factory_;
|
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(TestWindowDelegate);
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
|
|
|
|
};
|