Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1316)

Side by Side Diff: ui/base/cocoa/defaults_utils.mm

Issue 2282533002: mac: use NSUserDefaults values for caret blink rate if present (Closed)
Patch Set: more comments! Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/cocoa/defaults_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <AppKit/AppKit.h>
6
7 #include "base/logging.h"
8 #include "ui/base/cocoa/defaults_utils.h"
9
10 namespace ui {
11
12 bool TextInsertionCaretBlinkPeriod(base::TimeDelta* delta) {
13 const int kMaximumReasonableIntervalMs = 60 * 1000;
14 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
15 // 10.10+
16 double on_period_ms = [defaults
17 doubleForKey:@"NSTextInsertionPointBlinkPeriodOn"];
18 double off_period_ms = [defaults
19 doubleForKey:@"NSTextInsertionPointBlinkPeriodOff"];
20 // 10.9
21 double period_ms = [defaults
22 doubleForKey:@"NSTextInsertionPointBlinkPeriod"];
23 if (on_period_ms == 0.0 && off_period_ms == 0.0 && period_ms == 0.0)
24 return false;
25 // Neither Blink nor Views support having separate on and off intervals, so
26 // this function takes the average. There's a special case: setting
27 // on_period_ms very high functions to permanently enable the cursor, which is
28 // what happens when the blink period in Blink/Views is set to 0. Setting
29 // off_period_ms very high would disable the cursor entirely, but Blink/Views
30 // do not support that so it's not implemented here.
31 if (on_period_ms > kMaximumReasonableIntervalMs ||
32 period_ms > kMaximumReasonableIntervalMs) {
33 *delta = base::TimeDelta();
34 } else if (on_period_ms || off_period_ms) {
35 *delta = base::TimeDelta::FromMillisecondsD(
36 (on_period_ms + off_period_ms) / 2);
37 } else {
38 *delta = base::TimeDelta::FromMilliseconds(period_ms);
39 }
40 return true;
41 }
42
43 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cocoa/defaults_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698