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

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

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 #ifndef CHROME_BROWSER_UI_COCOA_LOOKUP_IN_DICTIONARY_H_
6 #define CHROME_BROWSER_UI_COCOA_LOOKUP_IN_DICTIONARY_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #include "base/scoped_nsobject.h"
11 #include "base/synchronization/condition_variable.h"
12 #include "base/synchronization/lock.h"
13
14 template <typename T> struct DefaultSingletonTraits;
15
16 // This class helps with the Mac OS X dictionary popup. For the design overview,
17 // look at this document:
18 // http://dev.chromium.org/developers/design-documents/system-dictionary-pop-u p-architecture
19 //
20 // This service is used to marshall information for these three methods that are
21 // implemented in RenderWidgetHostViewMac:
22 // -[NSTextInput characterIndexForPoint:]
23 // -[NSTextInput attributedSubstringFromRange:]
24 // -[NSTextInput firstRectForCharacterRange:]
25 //
26 // Because these methods are part of a synchronous system API, implementing them
27 // requires getting information from the renderer synchronously. Rather than
28 // using an actual sync IPC message, a normal async ViewMsg is used with a lock
29 // and condition (managed by this service).
30 class LookupInDictionary {
31 public:
32 // Returns the singleton instance.
33 static LookupInDictionary* GetInstance();
34
35 // The critical sections that the Condition guards are in RWHVM, specifically
36 // three methods that are part of the NSTextInput protocol that the dictionary
37 // service uses to display the popup. These methods lock the internal
38 // condition for use before the asynchronous message is sent to the renderer
39 // to lookup the required information. These are only used on the UI thread.
40 void BeforeRequest();
41 // Called at the end of a critical section. This will release the lock and
42 // condition.
43 void AfterRequest();
44
45 // Each of the three methods mentioned above has an associated pair of methods
46 // to get data from the renderer. The Wait*() methods block the calling thread
47 // (always the UI thread) with a short timeout after the async message has
48 // been sent to the renderer to lookup the information needed to respond to
49 // the system. The Set*AndSignal() methods store the looked up information in
50 // this service and signal the condition to allow the Wait*() methods to
51 // unlock and return that stored value.
52 //
53 // Returns NSNotFound if the request times out or is not completed.
54 NSUInteger WaitForCharacterIndex();
55 // Returns nil if the request times out or is completed.
56 NSAttributedString* WaitForSubstring();
57 // Returns NSZeroRect if the request times out or is not completed. The result
58 // is in WebKit coordinates.
59 NSRect WaitForFirstRect();
60
61 // When the renderer sends the ViewHostMsg reply, the RenderMessageFilter will
62 // call the corresponding method on the IO thread to unlock the condition and
63 // allow the Wait*() methods to continue/return.
64 void SetCharacterIndexAndSignal(NSUInteger index);
65 void SetFirstRectAndSignal(NSRect first_rect);
66 void SetSubstringAndSignal(NSAttributedString* string);
67
68 private:
69 friend struct DefaultSingletonTraits<LookupInDictionary>;
70 LookupInDictionary();
71
72 NSUInteger character_index_;
73 NSRect first_rect_;
74 scoped_nsobject<NSAttributedString> substring_;
75
76 base::Lock lock_;
77 base::ConditionVariable condition_;
78
79 DISALLOW_COPY_AND_ASSIGN(LookupInDictionary);
80 };
81
82 #endif // CHROME_BROWSER_UI_COCOA_LOOKUP_IN_DICTIONARY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698