mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
More events, remove most of the statics, better shutdown
This commit is contained in:
parent
7adf022dfa
commit
d0436f16b6
8 changed files with 342 additions and 217 deletions
|
@ -1,55 +1,38 @@
|
|||
#include "pch.h"
|
||||
#include "Servo.h"
|
||||
|
||||
void on_load_started() {}
|
||||
void on_load_ended() {}
|
||||
void on_history_changed(bool, bool) {}
|
||||
void on_shutdown_complete() {}
|
||||
// FIXME: rename mozilla to something else
|
||||
namespace servo {
|
||||
|
||||
std::function<void()> Servo::sFlush = []() {};
|
||||
std::function<void()> Servo::sMakeCurrent = []() {};
|
||||
std::function<void()> Servo::sWakeUp = []() {};
|
||||
std::function<void(std::wstring const &)> Servo::sOnAlert =
|
||||
[](std::wstring const &) {};
|
||||
std::function<void(std::wstring const &)> Servo::sOnTitleChanged =
|
||||
[](std::wstring const &) {};
|
||||
std::function<void(std::wstring const &)> Servo::sOnURLChanged =
|
||||
[](std::wstring const &) {};
|
||||
|
||||
bool Servo::sAnimating = false;
|
||||
|
||||
std::wstring char2w(const char *c_str) {
|
||||
auto str = std::string(c_str);
|
||||
int size_needed =
|
||||
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
|
||||
std::wstring str2(size_needed, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &str2[0],
|
||||
size_needed);
|
||||
return str2;
|
||||
void on_load_started() { sServo->Delegate().OnLoadStarted(); }
|
||||
void on_load_ended() { sServo->Delegate().OnLoadEnded(); }
|
||||
void on_history_changed(bool back, bool forward) {
|
||||
sServo->Delegate().OnHistoryChanged(back, forward);
|
||||
}
|
||||
void on_shutdown_complete() { sServo->Delegate().OnShutdownComplete(); }
|
||||
void on_alert(const char *message) {
|
||||
sServo->Delegate().OnAlert(char2w(message));
|
||||
}
|
||||
|
||||
void on_alert(const char *message) { Servo::sOnAlert(char2w(message)); }
|
||||
|
||||
void on_title_changed(const char *title) {
|
||||
Servo::sOnTitleChanged(char2w(title));
|
||||
sServo->Delegate().OnTitleChanged(char2w(title));
|
||||
}
|
||||
void on_url_changed(const char *url) {
|
||||
sServo->Delegate().OnURLChanged(char2w(url));
|
||||
}
|
||||
void flush() { sServo->Delegate().Flush(); }
|
||||
void make_current() { sServo->Delegate().MakeCurrent(); }
|
||||
void wakeup() { sServo->Delegate().WakeUp(); }
|
||||
bool on_allow_navigation(const char *url) {
|
||||
return sServo->Delegate().OnAllowNavigation(char2w(url));
|
||||
};
|
||||
void on_animating_changed(bool aAnimating) {
|
||||
sServo->Delegate().OnAnimatingChanged(aAnimating);
|
||||
}
|
||||
|
||||
void on_url_changed(const char *url) { Servo::sOnURLChanged(char2w(url)); }
|
||||
Servo::Servo(GLsizei width, GLsizei height, ServoDelegate &aDelegate)
|
||||
: mWindowHeight(height), mWindowWidth(width), mDelegate(aDelegate) {
|
||||
|
||||
void flush() { Servo::sFlush(); }
|
||||
|
||||
void make_current() { Servo::sMakeCurrent(); }
|
||||
|
||||
void wakeup() { Servo::sWakeUp(); }
|
||||
|
||||
bool on_allow_navigation(const char *url) { return true; };
|
||||
|
||||
void on_animating_changed(bool aAnimating) { Servo::sAnimating = aAnimating; }
|
||||
|
||||
Servo::Servo(GLsizei width, GLsizei height)
|
||||
: mAnimating(false), mWindowHeight(height), mWindowWidth(width) {
|
||||
|
||||
CInitOptions o;
|
||||
capi::CInitOptions o;
|
||||
o.args = NULL;
|
||||
o.url = "https://servo.org";
|
||||
o.width = mWindowWidth;
|
||||
|
@ -58,7 +41,9 @@ Servo::Servo(GLsizei width, GLsizei height)
|
|||
o.enable_subpixel_text_antialiasing = false;
|
||||
o.vr_pointer = NULL;
|
||||
|
||||
CHostCallbacks c;
|
||||
sServo = this; // FIXME;
|
||||
|
||||
capi::CHostCallbacks c;
|
||||
c.flush = &flush;
|
||||
c.make_current = &make_current;
|
||||
c.on_alert = &on_alert;
|
||||
|
@ -74,23 +59,16 @@ Servo::Servo(GLsizei width, GLsizei height)
|
|||
init_with_egl(o, &wakeup, c);
|
||||
}
|
||||
|
||||
Servo::~Servo() { deinit(); }
|
||||
Servo::~Servo() { capi::deinit(); }
|
||||
|
||||
void Servo::PerformUpdates() { perform_updates(); }
|
||||
|
||||
void Servo::SetBatchMode(bool mode) { set_batch_mode(mode); }
|
||||
|
||||
void Servo::GoForward() { go_forward(); }
|
||||
|
||||
void Servo::GoBack() { go_back(); }
|
||||
|
||||
void Servo::SetSize(GLsizei width, GLsizei height) {
|
||||
if (width != mWindowWidth || height != mWindowHeight) {
|
||||
mWindowWidth = width;
|
||||
mWindowHeight = height;
|
||||
resize(mWindowWidth, mWindowHeight);
|
||||
}
|
||||
std::wstring char2w(const char *c_str) {
|
||||
auto str = std::string(c_str);
|
||||
int size_needed =
|
||||
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
|
||||
std::wstring str2(size_needed, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &str2[0],
|
||||
size_needed);
|
||||
return str2;
|
||||
}
|
||||
|
||||
void Servo::Click(float x, float y) { click(x, y); }
|
||||
void Servo::Scroll(float dx, float dy, float x, float y) { scroll(dx, dy, x, y); }
|
||||
} // namespace mozilla
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue