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

Side by Side Diff: chrome/browser/ui/cocoa/lookup_in_dictionary.mm

Issue 6289009: [Mac] Implement the system dictionary popup by implementing NSTextInput methods. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/browser/ui/cocoa/lookup_in_dictionary.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/singleton.h"
9 #include "base/time.h"
10
11 // The amount of time in milliseconds that the browser process will wait for a
12 // response from the renderer.
13 // TODO(rsesek): Using the histogram data, find the best upper-bound for this
14 // value.
15 const float kWaitTimeout = 1500;
16
17 LookupInDictionary::LookupInDictionary()
18 : character_index_(NSNotFound),
19 lock_(),
20 condition_(&lock_) {
21 }
22
23 // static
24 LookupInDictionary* LookupInDictionary::GetInstance() {
25 return Singleton<LookupInDictionary>::get();
26 }
27
28 void LookupInDictionary::BeforeRequest() {
29 lock_.Acquire();
30 character_index_ = NSNotFound;
31 first_rect_ = NSZeroRect;
32 substring_.reset();
33 }
34
35 void LookupInDictionary::AfterRequest() {
36 lock_.Release();
37 }
38
39 NSUInteger LookupInDictionary::WaitForCharacterIndex() {
40 base::TimeTicks start = base::TimeTicks::Now();
41
42 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
43
44 base::TimeDelta delta(base::TimeTicks::Now() - start);
45 UMA_HISTOGRAM_TIMES("LookupInDictionary.CharacterIndex",
46 delta * base::Time::kMicrosecondsPerMillisecond);
47
48 return character_index_;
49 }
50
51 NSRect LookupInDictionary::WaitForFirstRect() {
52 base::TimeTicks start = base::TimeTicks::Now();
53
54 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
55
56 base::TimeDelta delta(base::TimeTicks::Now() - start);
57 UMA_HISTOGRAM_TIMES("LookupInDictionary.FirstRect",
58 delta * base::Time::kMicrosecondsPerMillisecond);
59
60 return first_rect_;
61 }
62
63 NSAttributedString* LookupInDictionary::WaitForSubstring() {
64 base::TimeTicks start = base::TimeTicks::Now();
65
66 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
67
68 base::TimeDelta delta(base::TimeTicks::Now() - start);
69 UMA_HISTOGRAM_TIMES("LookupInDictionary.Substring",
70 delta * base::Time::kMicrosecondsPerMillisecond);
71
72 return substring_.get();
73 }
74
75 void LookupInDictionary::SetCharacterIndexAndSignal(NSUInteger index) {
76 lock_.Acquire();
77 character_index_ = index;
78 lock_.Release();
79 condition_.Signal();
80 }
81
82 void LookupInDictionary::SetFirstRectAndSignal(NSRect first_rect) {
83 lock_.Acquire();
84 first_rect_ = first_rect;
85 lock_.Release();
86 condition_.Signal();
87 }
88
89 void LookupInDictionary::SetSubstringAndSignal(NSAttributedString* string) {
90 lock_.Acquire();
91 substring_.reset([string copy]);
92 lock_.Release();
93 condition_.Signal();
94 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698