feat: add BrowserWindow.isTabletMode API (#25209)

This commit is contained in:
Cheng Zhao 2020-09-22 14:40:42 +09:00 committed by GitHub
parent 2dd7ad268b
commit c50ded2b71
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 32 additions and 0 deletions

View file

@ -622,6 +622,10 @@ bool BaseWindow::IsKiosk() {
return window_->IsKiosk();
}
bool BaseWindow::IsTabletMode() const {
return window_->IsTabletMode();
}
void BaseWindow::SetBackgroundColor(const std::string& color_name) {
SkColor color = ParseHexColor(color_name);
window_->SetBackgroundColor(color);
@ -1160,6 +1164,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
.SetMethod("isSimpleFullScreen", &BaseWindow::IsSimpleFullScreen)
.SetMethod("setKiosk", &BaseWindow::SetKiosk)
.SetMethod("isKiosk", &BaseWindow::IsKiosk)
.SetMethod("isTabletMode", &BaseWindow::IsTabletMode)
.SetMethod("setBackgroundColor", &BaseWindow::SetBackgroundColor)
.SetMethod("getBackgroundColor", &BaseWindow::GetBackgroundColor)
.SetMethod("setHasShadow", &BaseWindow::SetHasShadow)

View file

@ -152,6 +152,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
bool IsSimpleFullScreen();
void SetKiosk(bool kiosk);
bool IsKiosk();
bool IsTabletMode() const;
virtual void SetBackgroundColor(const std::string& color_name);
std::string GetBackgroundColor();
void SetHasShadow(bool has_shadow);

View file

@ -310,6 +310,10 @@ double NativeWindow::GetSheetOffsetY() {
return sheet_offset_y_;
}
bool NativeWindow::IsTabletMode() const {
return false;
}
void NativeWindow::SetRepresentedFilename(const std::string& filename) {}
std::string NativeWindow::GetRepresentedFilename() {

View file

@ -148,6 +148,7 @@ class NativeWindow : public base::SupportsUserData,
virtual bool IsSimpleFullScreen() = 0;
virtual void SetKiosk(bool kiosk) = 0;
virtual bool IsKiosk() = 0;
virtual bool IsTabletMode() const;
virtual void SetBackgroundColor(SkColor color) = 0;
virtual SkColor GetBackgroundColor() = 0;
virtual void SetHasShadow(bool has_shadow) = 0;

View file

@ -60,6 +60,7 @@
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
#include "ui/views/window/native_frame_view.h"
#elif defined(OS_WIN)
#include "base/win/win_util.h"
#include "shell/browser/ui/views/win_frame_view.h"
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
#include "skia/ext/skia_utils_win.h"
@ -901,6 +902,14 @@ bool NativeWindowViews::IsKiosk() {
return IsFullscreen();
}
bool NativeWindowViews::IsTabletMode() const {
#if defined(OS_WIN)
return base::win::IsWindows10TabletMode(GetAcceleratedWidget());
#else
return false;
#endif
}
SkColor NativeWindowViews::GetBackgroundColor() {
return root_view_->background()->get_color();
}

View file

@ -101,6 +101,7 @@ class NativeWindowViews : public NativeWindow,
bool IsSimpleFullScreen() override;
void SetKiosk(bool kiosk) override;
bool IsKiosk() override;
bool IsTabletMode() const override;
void SetBackgroundColor(SkColor color) override;
void SetHasShadow(bool has_shadow) override;
bool HasShadow() override;