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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/lookup_in_dictionary.mm
diff --git a/chrome/browser/ui/cocoa/lookup_in_dictionary.mm b/chrome/browser/ui/cocoa/lookup_in_dictionary.mm
new file mode 100644
index 0000000000000000000000000000000000000000..229d094c853a9383add86c7aee736f72377de8a9
--- /dev/null
+++ b/chrome/browser/ui/cocoa/lookup_in_dictionary.mm
@@ -0,0 +1,94 @@
+// Copyright (c) 2011 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 "chrome/browser/ui/cocoa/lookup_in_dictionary.h"
+
+#include "base/metrics/histogram.h"
+#include "base/singleton.h"
+#include "base/time.h"
+
+// The amount of time in milliseconds that the browser process will wait for a
+// response from the renderer.
+// TODO(rsesek): Using the histogram data, find the best upper-bound for this
+// value.
+const float kWaitTimeout = 1500;
+
+LookupInDictionary::LookupInDictionary()
+ : character_index_(NSNotFound),
+ lock_(),
+ condition_(&lock_) {
+}
+
+// static
+LookupInDictionary* LookupInDictionary::GetInstance() {
+ return Singleton<LookupInDictionary>::get();
+}
+
+void LookupInDictionary::BeforeRequest() {
+ lock_.Acquire();
+ character_index_ = NSNotFound;
+ first_rect_ = NSZeroRect;
+ substring_.reset();
+}
+
+void LookupInDictionary::AfterRequest() {
+ lock_.Release();
+}
+
+NSUInteger LookupInDictionary::WaitForCharacterIndex() {
+ base::TimeTicks start = base::TimeTicks::Now();
+
+ condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
+
+ base::TimeDelta delta(base::TimeTicks::Now() - start);
+ UMA_HISTOGRAM_TIMES("LookupInDictionary.CharacterIndex",
+ delta * base::Time::kMicrosecondsPerMillisecond);
+
+ return character_index_;
+}
+
+NSRect LookupInDictionary::WaitForFirstRect() {
+ base::TimeTicks start = base::TimeTicks::Now();
+
+ condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
+
+ base::TimeDelta delta(base::TimeTicks::Now() - start);
+ UMA_HISTOGRAM_TIMES("LookupInDictionary.FirstRect",
+ delta * base::Time::kMicrosecondsPerMillisecond);
+
+ return first_rect_;
+}
+
+NSAttributedString* LookupInDictionary::WaitForSubstring() {
+ base::TimeTicks start = base::TimeTicks::Now();
+
+ condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout));
+
+ base::TimeDelta delta(base::TimeTicks::Now() - start);
+ UMA_HISTOGRAM_TIMES("LookupInDictionary.Substring",
+ delta * base::Time::kMicrosecondsPerMillisecond);
+
+ return substring_.get();
+}
+
+void LookupInDictionary::SetCharacterIndexAndSignal(NSUInteger index) {
+ lock_.Acquire();
+ character_index_ = index;
+ lock_.Release();
+ condition_.Signal();
+}
+
+void LookupInDictionary::SetFirstRectAndSignal(NSRect first_rect) {
+ lock_.Acquire();
+ first_rect_ = first_rect;
+ lock_.Release();
+ condition_.Signal();
+}
+
+void LookupInDictionary::SetSubstringAndSignal(NSAttributedString* string) {
+ lock_.Acquire();
+ substring_.reset([string copy]);
+ lock_.Release();
+ condition_.Signal();
+}

Powered by Google App Engine
This is Rietveld 408576698