mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-21 10:28:44 -05:00
Code cleanup branch (#618)
* Make height map fallback layer work again * Add documentation to joystick button bindings * Removed grouped property headers * Add new version number constant generated by CMake * Make Joystick deadzone work properly * Change the startup date on Earth to today * Fix key modifier handling * Add debugging indices for TreeNodeDebugging * Fix script schedule for OsirisRex * Do not open Mission schedule automatically * Upload default projection texture automatically * General code cleanup * Fix check_style_guide warnings * Remove .clang-format * MacOS compile fixes * Clang analyzer fixes
This commit is contained in:
@@ -22,30 +22,36 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include <webbrowsermodule.h>
|
||||
#include "include/browserinstance.h"
|
||||
#include <modules/webbrowser/include/browserinstance.h>
|
||||
|
||||
#include <modules/webbrowser/include/browserclient.h>
|
||||
#include <modules/webbrowser/include/webrenderhandler.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <ghoul/fmt.h>
|
||||
#include <ghoul/filesystem/file.h>
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
namespace {
|
||||
const char* _loggerCat = "CEF BrowserInstance";
|
||||
const bool DID_NOT_LEAVE_WINDOW = false;
|
||||
}
|
||||
constexpr const char* _loggerCat = "CEF BrowserInstance";
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
BrowserInstance::BrowserInstance(WebRenderHandler* renderer)
|
||||
: _isInitialized(false)
|
||||
: _renderHandler(renderer)
|
||||
{
|
||||
_renderHandler = renderer;
|
||||
_client = new BrowserClient(_renderHandler);
|
||||
|
||||
CefWindowInfo windowInfo;
|
||||
bool renderTransparent = true;
|
||||
const bool renderTransparent = true;
|
||||
windowInfo.SetAsWindowless(nullptr, renderTransparent);
|
||||
|
||||
CefBrowserSettings browserSettings;
|
||||
browserSettings.windowless_frame_rate = 60;
|
||||
|
||||
std::string url = "";
|
||||
std::string url;
|
||||
_browser = CefBrowserHost::CreateBrowserSync(
|
||||
windowInfo,
|
||||
_client.get(),
|
||||
@@ -60,13 +66,12 @@ BrowserInstance::~BrowserInstance() {
|
||||
}
|
||||
|
||||
void BrowserInstance::initialize() {
|
||||
auto& wrapper = OsEng.windowWrapper();
|
||||
reshape(wrapper.currentWindowSize());
|
||||
|
||||
reshape(OsEng.windowWrapper().currentWindowSize());
|
||||
_isInitialized = true;
|
||||
}
|
||||
|
||||
void BrowserInstance::loadUrl(const std::string &url) {
|
||||
void BrowserInstance::loadUrl(const std::string& url) {
|
||||
// @TODO: This should be removed
|
||||
if (!_isInitialized) {
|
||||
initialize();
|
||||
}
|
||||
@@ -75,52 +80,45 @@ void BrowserInstance::loadUrl(const std::string &url) {
|
||||
_browser->GetMainFrame()->LoadURL(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a local file
|
||||
* @param path - the path to load
|
||||
* @return true if the path exists, false otherwise
|
||||
*/
|
||||
bool BrowserInstance::loadLocalPath(std::string path) {
|
||||
if (!FileSys.fileExists(path)) {
|
||||
LDEBUG(fmt::format("Could not find path `{}`, verify that it is correct.", path));
|
||||
return false;
|
||||
}
|
||||
|
||||
loadUrl(absPath(path));
|
||||
loadUrl(absPath(std::move(path)));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when the window has been reshaped
|
||||
* @param wrapper the windowWrapper capable of
|
||||
*/
|
||||
void BrowserInstance::reshape(const glm::ivec2 &windowSize) {
|
||||
void BrowserInstance::reshape(const glm::ivec2& windowSize) {
|
||||
_renderHandler->reshape(windowSize.x, windowSize.y);
|
||||
_browser->GetHost()->WasResized();
|
||||
}
|
||||
|
||||
/**
|
||||
* encapsulate renderHandler's draw method
|
||||
*/
|
||||
void BrowserInstance::draw() {
|
||||
_renderHandler->draw();
|
||||
}
|
||||
|
||||
void BrowserInstance::close(bool force) {
|
||||
LDEBUG(fmt::format("Closing browser. {}", force ? "Forcing." : ""));
|
||||
if (force) {
|
||||
LDEBUG("Force closing browser");
|
||||
}
|
||||
else {
|
||||
LDEBUG("Closing browser");
|
||||
}
|
||||
_browser->GetHost()->CloseBrowser(force);
|
||||
}
|
||||
|
||||
const CefRefPtr<CefBrowser> &BrowserInstance::getBrowser() const {
|
||||
const CefRefPtr<CefBrowser>& BrowserInstance::getBrowser() const {
|
||||
return _browser;
|
||||
}
|
||||
|
||||
bool BrowserInstance::sendKeyEvent(const CefKeyEvent &event) {
|
||||
bool BrowserInstance::sendKeyEvent(const CefKeyEvent& event) {
|
||||
_browser->GetHost()->SendKeyEvent(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BrowserInstance::sendMouseClickEvent(const CefMouseEvent &event,
|
||||
bool BrowserInstance::sendMouseClickEvent(const CefMouseEvent& event,
|
||||
CefBrowserHost::MouseButtonType button,
|
||||
bool mouseUp, int clickCount)
|
||||
{
|
||||
@@ -128,18 +126,16 @@ bool BrowserInstance::sendMouseClickEvent(const CefMouseEvent &event,
|
||||
return hasContent(event.x, event.y);
|
||||
}
|
||||
|
||||
bool BrowserInstance::sendMouseMoveEvent(const CefMouseEvent &event) {
|
||||
_browser->GetHost()->SendMouseMoveEvent(event, DID_NOT_LEAVE_WINDOW);
|
||||
bool BrowserInstance::sendMouseMoveEvent(const CefMouseEvent& event) {
|
||||
constexpr const bool DidNotLeaveWindow = false;
|
||||
|
||||
_browser->GetHost()->SendMouseMoveEvent(event, DidNotLeaveWindow);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* send scroll wheel event to browser
|
||||
* @param event - key event with position
|
||||
* @param delta - the scroll amount in pixels
|
||||
* @return if this scroll should be blocked or not
|
||||
*/
|
||||
bool BrowserInstance::sendMouseWheelEvent(const CefMouseEvent &event, glm::ivec2 delta) {
|
||||
bool BrowserInstance::sendMouseWheelEvent(const CefMouseEvent& event,
|
||||
const glm::ivec2& delta)
|
||||
{
|
||||
_browser->GetHost()->SendMouseWheelEvent(event, delta.x, delta.y);
|
||||
return hasContent(event.x, event.y);
|
||||
}
|
||||
@@ -152,4 +148,4 @@ bool BrowserInstance::hasContent(int x, int y) {
|
||||
return _renderHandler->hasContent(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user