Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting page zoom for browser sources #432

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions browser-client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,12 @@ void BrowserClient::OnAudioStreamStopped(CefRefPtr<CefBrowser> browser, int id)
}
#endif

void BrowserClient::OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame>, TransitionType)
{
browser->GetHost()->SetZoomLevel(bs->zoom);
}

void BrowserClient::OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame> frame,
int)
{
Expand Down
4 changes: 4 additions & 0 deletions browser-client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ class BrowserClient : public CefClient,
int frames_per_buffer) override;
#endif
/* CefLoadHandler */
virtual void OnLoadStart(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
TransitionType transition_type) override;

virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) override;
Expand Down
2 changes: 2 additions & 0 deletions obs-browser-plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ static obs_properties_t *browser_source_get_properties(void *data)
8192, 1);
obs_properties_add_int(props, "height", obs_module_text("Height"), 1,
8192, 1);
obs_properties_add_int(props, "zoom", obs_module_text("Zoom"), -6, 9,
1);

obs_properties_add_bool(props, "reroute_audio",
obs_module_text("RerouteAudio"));
Expand Down
9 changes: 8 additions & 1 deletion obs-browser-source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ void BrowserSource::Update(obs_data_t *settings)
bool n_is_local;
int n_width;
int n_height;
int n_zoom;
bool n_fps_custom;
int n_fps;
bool n_shutdown;
Expand All @@ -524,6 +525,7 @@ void BrowserSource::Update(obs_data_t *settings)
n_is_local = obs_data_get_bool(settings, "is_local_file");
n_width = (int)obs_data_get_int(settings, "width");
n_height = (int)obs_data_get_int(settings, "height");
n_zoom = (int)obs_data_get_int(settings, "zoom");
n_fps_custom = obs_data_get_bool(settings, "fps_custom");
n_fps = (int)obs_data_get_int(settings, "fps");
n_shutdown = obs_data_get_bool(settings, "shutdown");
Expand Down Expand Up @@ -582,11 +584,13 @@ void BrowserSource::Update(obs_data_t *settings)
n_reroute == reroute_audio &&
n_webpage_control_level == webpage_control_level) {

if (n_width == width && n_height == height)
if (n_width == width && n_height == height &&
n_zoom == zoom)
return;

width = n_width;
height = n_height;
zoom = n_zoom;
ExecuteOnBrowser(
[=](CefRefPtr<CefBrowser> cefBrowser) {
const CefSize cefSize(width, height);
Expand All @@ -596,6 +600,8 @@ void BrowserSource::Update(obs_data_t *settings)
->OnAutoResize(cefBrowser,
cefSize);
cefBrowser->GetHost()->WasResized();
cefBrowser->GetHost()->SetZoomLevel(
zoom);
cefBrowser->GetHost()->Invalidate(
PET_VIEW);
},
Expand All @@ -606,6 +612,7 @@ void BrowserSource::Update(obs_data_t *settings)
is_local = n_is_local;
width = n_width;
height = n_height;
zoom = n_zoom;
fps = n_fps;
fps_custom = n_fps_custom;
shutdown_on_invisible = n_shutdown;
Expand Down
1 change: 1 addition & 0 deletions obs-browser-source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ struct BrowserSource {

int width = 0;
int height = 0;
int zoom = 0;
bool fps_custom = false;
int fps = 0;
double canvas_fps = 0;
Expand Down