Skip to content

Commit c50ded2

Browse files
authored
feat: add BrowserWindow.isTabletMode API (electron#25209)
1 parent 2dd7ad2 commit c50ded2

File tree

7 files changed

+32
-0
lines changed

7 files changed

+32
-0
lines changed

docs/api/browser-window.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,17 @@ Enters or leaves kiosk mode.
13461346

13471347
Returns `Boolean` - Whether the window is in kiosk mode.
13481348

1349+
#### `win.isTabletMode()` _Windows_
1350+
1351+
Returns `Boolean` - Whether the window is in Windows 10 tablet mode.
1352+
1353+
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),
1354+
under this mode apps can choose to optimize their UI for tablets, such as
1355+
enlarging the titlebar and hiding titlebar buttons.
1356+
1357+
This API returns whether the window is in tablet mode, and the `resize` event
1358+
can be be used to listen to changes to tablet mode.
1359+
13491360
#### `win.getMediaSourceId()`
13501361

13511362
Returns `String` - Window id in the format of DesktopCapturerSource's id. For example "window:1234:0".

shell/browser/api/electron_api_base_window.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ bool BaseWindow::IsKiosk() {
622622
return window_->IsKiosk();
623623
}
624624

625+
bool BaseWindow::IsTabletMode() const {
626+
return window_->IsTabletMode();
627+
}
628+
625629
void BaseWindow::SetBackgroundColor(const std::string& color_name) {
626630
SkColor color = ParseHexColor(color_name);
627631
window_->SetBackgroundColor(color);
@@ -1160,6 +1164,7 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
11601164
.SetMethod("isSimpleFullScreen", &BaseWindow::IsSimpleFullScreen)
11611165
.SetMethod("setKiosk", &BaseWindow::SetKiosk)
11621166
.SetMethod("isKiosk", &BaseWindow::IsKiosk)
1167+
.SetMethod("isTabletMode", &BaseWindow::IsTabletMode)
11631168
.SetMethod("setBackgroundColor", &BaseWindow::SetBackgroundColor)
11641169
.SetMethod("getBackgroundColor", &BaseWindow::GetBackgroundColor)
11651170
.SetMethod("setHasShadow", &BaseWindow::SetHasShadow)

shell/browser/api/electron_api_base_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
152152
bool IsSimpleFullScreen();
153153
void SetKiosk(bool kiosk);
154154
bool IsKiosk();
155+
bool IsTabletMode() const;
155156
virtual void SetBackgroundColor(const std::string& color_name);
156157
std::string GetBackgroundColor();
157158
void SetHasShadow(bool has_shadow);

shell/browser/native_window.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ double NativeWindow::GetSheetOffsetY() {
310310
return sheet_offset_y_;
311311
}
312312

313+
bool NativeWindow::IsTabletMode() const {
314+
return false;
315+
}
316+
313317
void NativeWindow::SetRepresentedFilename(const std::string& filename) {}
314318

315319
std::string NativeWindow::GetRepresentedFilename() {

shell/browser/native_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class NativeWindow : public base::SupportsUserData,
148148
virtual bool IsSimpleFullScreen() = 0;
149149
virtual void SetKiosk(bool kiosk) = 0;
150150
virtual bool IsKiosk() = 0;
151+
virtual bool IsTabletMode() const;
151152
virtual void SetBackgroundColor(SkColor color) = 0;
152153
virtual SkColor GetBackgroundColor() = 0;
153154
virtual void SetHasShadow(bool has_shadow) = 0;

shell/browser/native_window_views.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_linux.h"
6161
#include "ui/views/window/native_frame_view.h"
6262
#elif defined(OS_WIN)
63+
#include "base/win/win_util.h"
6364
#include "shell/browser/ui/views/win_frame_view.h"
6465
#include "shell/browser/ui/win/electron_desktop_native_widget_aura.h"
6566
#include "skia/ext/skia_utils_win.h"
@@ -901,6 +902,14 @@ bool NativeWindowViews::IsKiosk() {
901902
return IsFullscreen();
902903
}
903904

905+
bool NativeWindowViews::IsTabletMode() const {
906+
#if defined(OS_WIN)
907+
return base::win::IsWindows10TabletMode(GetAcceleratedWidget());
908+
#else
909+
return false;
910+
#endif
911+
}
912+
904913
SkColor NativeWindowViews::GetBackgroundColor() {
905914
return root_view_->background()->get_color();
906915
}

shell/browser/native_window_views.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class NativeWindowViews : public NativeWindow,
101101
bool IsSimpleFullScreen() override;
102102
void SetKiosk(bool kiosk) override;
103103
bool IsKiosk() override;
104+
bool IsTabletMode() const override;
104105
void SetBackgroundColor(SkColor color) override;
105106
void SetHasShadow(bool has_shadow) override;
106107
bool HasShadow() override;

0 commit comments

Comments
 (0)