Enable screen.availHeight/availWidth/Height/Width

This commit is contained in:
Shing Lyu 2017-09-27 10:32:51 +02:00
parent 657b2339a1
commit c120234f0e
16 changed files with 138 additions and 84 deletions

View file

@ -373,6 +373,7 @@ pub struct cef_point {
//
// Structure representing a rectangle.
//
#[derive(Default)]
pub struct cef_rect {
pub x: c_int,
pub y: c_int,
@ -1599,6 +1600,7 @@ pub enum cef_cursor_type_t {
// passed as a parameter to CefRenderHandler::GetScreenInfo and should be filled
// in by the client.
///
#[derive(Default)]
pub struct _cef_screen_info {
///
// Device scale factor. Specifies the ratio between physical and logical

View file

@ -14,7 +14,7 @@ use eutil::Downcast;
use interfaces::CefApp;
use interfaces::CefBrowser;
use render_handler::CefRenderHandlerExtensions;
use types::{cef_cursor_handle_t, cef_cursor_type_t, cef_rect_t};
use types::{cef_cursor_handle_t, cef_cursor_type_t, cef_rect_t, CefScreenInfo};
use wrappers::CefWrap;
use compositing::compositor_thread::EventLoopWaker;
@ -169,6 +169,19 @@ impl Window {
fn cursor_handle_for_cursor(&self, _: Cursor) -> cef_cursor_handle_t {
0
}
fn screen_info(&self) -> CefScreenInfo {
let mut screen_info = CefScreenInfo::default();
let browser = self.cef_browser.borrow();
if let Some(ref browser) = *browser {
browser.get_host()
.get_client()
.get_render_handler()
.get_screen_info(browser.clone(), &mut screen_info);
}
screen_info
}
}
impl WindowMethods for Window {
@ -501,6 +514,16 @@ impl WindowMethods for Window {
fn supports_clipboard(&self) -> bool {
false
}
fn screen_size(&self, _: BrowserId) -> Size2D<u32> {
let screen_info = self.screen_info();
Size2D::new(screen_info.rect.width as u32, screen_info.rect.height as u32)
}
fn screen_avail_size(&self, _: BrowserId) -> Size2D<u32> {
let screen_info = self.screen_info();
Size2D::new(screen_info.available_rect.width as u32, screen_info.available_rect.height as u32)
}
}
#[cfg(target_os="macos")]

View file

@ -1033,6 +1033,31 @@ impl WindowMethods for Window {
}
fn screen_size(&self, _: BrowserId) -> Size2D<u32> {
match self.kind {
WindowKind::Window(_) => {
let (width, height) = glutin::get_primary_monitor().get_dimensions();
Size2D::new(width, height)
}
WindowKind::Headless(ref context) => {
Size2D::new(context.width, context.height)
}
}
}
fn screen_avail_size(&self, _: BrowserId) -> Size2D<u32> {
// FIXME: Glutin doesn't have API for available size. Fallback to screen size
match self.kind {
WindowKind::Window(_) => {
let (width, height) = glutin::get_primary_monitor().get_dimensions();
Size2D::new(width, height)
}
WindowKind::Headless(ref context) => {
Size2D::new(context.width, context.height)
}
}
}
fn set_animation_state(&self, state: AnimationState) {
self.animation_state.set(state);
}