Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 double on_period_ms = [defaults | |
| 16 doubleForKey:@"NSTextInsertionPointBlinkPeriodOn"]; | |
| 17 double off_period_ms = [defaults | |
| 18 doubleForKey:@"NSTextInsertionPointBlinkPeriodOff"]; | |
| 19 double period_ms = [defaults | |
| 20 doubleForKey:@"NSTextInsertionPointBlinkPeriod"]; | |
|
Nico
2016/08/25 19:59:12
Add comment "// 10.9" and add comment "// 10.10+"
| |
| 21 if (on_period_ms == 0.0 && off_period_ms == 0.0 && period_ms == 0.0) | |
| 22 return false; | |
| 23 // Neither Blink nor Views support having separate on and off intervals, so | |
| 24 // this function takes the average. There's a special case: setting | |
| 25 // on_period_ms very high functions to permanently enable the cursor, which is | |
| 26 // what happens when the blink period in Blink/Views is set to 0. Setting | |
| 27 // off_period_ms very high would disable the cursor entirely, but Blink/Views | |
| 28 // do not support that so it's not implemented here. | |
| 29 if (on_period_ms > kMaximumReasonableIntervalMs || | |
| 30 period_ms > kMaximumReasonableIntervalMs) { | |
| 31 *delta = base::TimeDelta(); | |
| 32 } else if (on_period_ms || off_period_ms) { | |
| 33 *delta = base::TimeDelta::FromMillisecondsD( | |
| 34 (on_period_ms + off_period_ms) / 2); | |
| 35 } else { | |
| 36 *delta = base::TimeDelta::FromMilliseconds(period_ms); | |
| 37 } | |
| 38 return true; | |
| 39 } | |
| 40 | |
| 41 } // namespace ui | |
| OLD | NEW |