From 5cbbd489d51fe917d432f73325b0da44664bc4a3 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 30 Aug 2019 07:39:46 -0700 Subject: [PATCH] fix: honor cursor blink rate (#20020) * fix: honor cursor blink rate on macOS * fix: honor cursor blink rate on Linux * fix: honor cursor blink rate on Windows * refactor: clean up os_win cursor blink logic * remove unneeded include --- shell/browser/api/atom_api_web_contents.cc | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/shell/browser/api/atom_api_web_contents.cc b/shell/browser/api/atom_api_web_contents.cc index 791cde93799..6103315050e 100644 --- a/shell/browser/api/atom_api_web_contents.cc +++ b/shell/browser/api/atom_api_web_contents.cc @@ -100,6 +100,12 @@ #if !defined(OS_MACOSX) #include "ui/aura/window.h" +#else +#include "ui/base/cocoa/defaults_utils.h" +#endif + +#if defined(OS_LINUX) +#include "ui/views/linux_ui/linux_ui.h" #endif #if defined(OS_LINUX) || defined(OS_WIN) @@ -458,6 +464,25 @@ void WebContents::InitWithSessionAndOptions( prefs->subpixel_rendering = params->subpixel_rendering; #endif +// Honor the system's cursor blink rate settings +#if defined(OS_MACOSX) + base::TimeDelta interval; + if (ui::TextInsertionCaretBlinkPeriod(&interval)) + prefs->caret_blink_interval = interval; +#elif defined(OS_LINUX) + views::LinuxUI* linux_ui = views::LinuxUI::instance(); + if (linux_ui) + prefs->caret_blink_interval = linux_ui->GetCursorBlinkInterval(); +#elif defined(OS_WIN) + const auto system_msec = ::GetCaretBlinkTime(); + if (system_msec != 0) { + prefs->caret_blink_interval = + (system_msec == INFINITE) + ? base::TimeDelta() + : base::TimeDelta::FromMilliseconds(system_msec); + } +#endif + // Save the preferences in C++. new WebContentsPreferences(web_contents(), options);