Commit d0fd7b14 authored by ellyjones's avatar ellyjones Committed by Commit bot

mac: use NSUserDefaults values for caret blink rate if present

The main use of these by end-users is to disable cursor blink by setting them
to extremely large values.

BUG=500168

Review-Url: https://codereview.chromium.org/2282533002
Cr-Commit-Position: refs/heads/master@{#414752}
parent f408e22e
......@@ -26,6 +26,10 @@
#include "ui/views/controls/textfield/textfield.h"
#endif
#if defined(OS_MACOSX)
#include "ui/base/cocoa/defaults_utils.h"
#endif
#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
......@@ -120,6 +124,12 @@ void UpdateFromSystemSettings(content::RendererPreferences* prefs,
prefs->caret_blink_interval = views::Textfield::GetCaretBlinkMs() / 1000.0;
#endif
#if defined(OS_MACOSX)
base::TimeDelta interval;
if (ui::TextInsertionCaretBlinkPeriod(&interval))
prefs->caret_blink_interval = interval.InSecondsF();
#endif
#if defined(USE_AURA) && defined(OS_LINUX) && !defined(OS_CHROMEOS)
views::LinuxUI* linux_ui = views::LinuxUI::instance();
if (linux_ui) {
......
......@@ -96,6 +96,8 @@ component("base") {
"cocoa/controls/hyperlink_button_cell.mm",
"cocoa/controls/hyperlink_text_view.h",
"cocoa/controls/hyperlink_text_view.mm",
"cocoa/defaults_utils.h",
"cocoa/defaults_utils.mm",
"cocoa/find_pasteboard.h",
"cocoa/find_pasteboard.mm",
"cocoa/flipped_view.h",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_BASE_COCOA_DEFAULTS_UTILS_H_
#define UI_BASE_COCOA_DEFAULTS_UTILS_H_
#include "base/time/time.h"
#include "ui/base/ui_base_export.h"
namespace ui {
// Returns the text insertion caret blink period, if one is configured in
// NSUserDefaults.
UI_BASE_EXPORT bool TextInsertionCaretBlinkPeriod(base::TimeDelta* period);
}
#endif
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <AppKit/AppKit.h>
#include "base/logging.h"
#include "ui/base/cocoa/defaults_utils.h"
namespace ui {
bool TextInsertionCaretBlinkPeriod(base::TimeDelta* delta) {
const int kMaximumReasonableIntervalMs = 60 * 1000;
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// 10.10+
double on_period_ms = [defaults
doubleForKey:@"NSTextInsertionPointBlinkPeriodOn"];
double off_period_ms = [defaults
doubleForKey:@"NSTextInsertionPointBlinkPeriodOff"];
// 10.9
double period_ms = [defaults
doubleForKey:@"NSTextInsertionPointBlinkPeriod"];
if (on_period_ms == 0.0 && off_period_ms == 0.0 && period_ms == 0.0)
return false;
// Neither Blink nor Views support having separate on and off intervals, so
// this function takes the average. There's a special case: setting
// on_period_ms very high functions to permanently enable the cursor, which is
// what happens when the blink period in Blink/Views is set to 0. Setting
// off_period_ms very high would disable the cursor entirely, but Blink/Views
// do not support that so it's not implemented here.
if (on_period_ms > kMaximumReasonableIntervalMs ||
period_ms > kMaximumReasonableIntervalMs) {
*delta = base::TimeDelta();
} else if (on_period_ms || off_period_ms) {
*delta = base::TimeDelta::FromMillisecondsD(
(on_period_ms + off_period_ms) / 2);
} else {
*delta = base::TimeDelta::FromMilliseconds(period_ms);
}
return true;
}
} // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment