diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f00179ca9c0d..e4ff8712e613 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -1346,6 +1346,17 @@ Enters or leaves kiosk mode. Returns `Boolean` - Whether the window is in kiosk mode. +#### `win.isTabletMode()` _Windows_ + +Returns `Boolean` - Whether the window is in Windows 10 tablet mode. + +Since Windows 10 users can [use their PC as tablet](https://support.microsoft.com/en-us/help/17210/windows-10-use-your-pc-like-a-tablet), +under this mode apps can choose to optimize their UI for tablets, such as +enlarging the titlebar and hiding titlebar buttons. + +This API returns whether the window is in tablet mode, and the `resize` event +can be be used to listen to changes to tablet mode. + #### `win.getMediaSourceId()` Returns `String` - Window id in the format of DesktopCapturerSource's id. For example "window:1234:0". diff --git a/shell/browser/api/electron_api_base_window.cc b/shell/browser/api/electron_api_base_window.cc index 5723d5835648..8a6756d44382 100644 --- a/shell/browser/api/electron_api_base_window.cc +++ b/shell/browser/api/electron_api_base_window.cc @@ -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) diff --git a/shell/browser/api/electron_api_base_window.h b/shell/browser/api/electron_api_base_window.h index bf2f1540e4b6..9ca22f164721 100644 --- a/shell/browser/api/electron_api_base_window.h +++ b/shell/browser/api/electron_api_base_window.h @@ -152,6 +152,7 @@ class BaseWindow : public gin_helper::TrackableObject, 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); diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 57e7c9130d7b..152663f4f24e 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -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() { diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index a1e16926eeda..a3a4babd1000 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -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; diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index bd5330ad618b..9751bee799da 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -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(); } diff --git a/shell/browser/native_window_views.h b/shell/browser/native_window_views.h index 597215183631..b0377ed6751c 100644 --- a/shell/browser/native_window_views.h +++ b/shell/browser/native_window_views.h @@ -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;