Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ |
| 7 | 7 |
| 8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
| 9 | 9 |
| 10 #include "base/mac/scoped_block.h" | |
| 10 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/synchronization/condition_variable.h" | 12 #include "base/synchronization/condition_variable.h" |
| 12 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 15 | 16 |
| 16 template <typename T> struct DefaultSingletonTraits; | 17 template <typename T> struct DefaultSingletonTraits; |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class RenderWidgetHost; | 20 class RenderWidgetHost; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 30 // | 31 // |
| 31 // Because these methods are part of a synchronous system API, implementing them | 32 // Because these methods are part of a synchronous system API, implementing them |
| 32 // requires getting information from the renderer synchronously. Rather than | 33 // requires getting information from the renderer synchronously. Rather than |
| 33 // using an actual sync IPC message, a normal async ViewMsg is used with a lock | 34 // using an actual sync IPC message, a normal async ViewMsg is used with a lock |
| 34 // and condition (managed by this service). | 35 // and condition (managed by this service). |
| 35 class CONTENT_EXPORT TextInputClientMac { | 36 class CONTENT_EXPORT TextInputClientMac { |
| 36 public: | 37 public: |
| 37 // Returns the singleton instance. | 38 // Returns the singleton instance. |
| 38 static TextInputClientMac* GetInstance(); | 39 static TextInputClientMac* GetInstance(); |
| 39 | 40 |
| 41 void GetStringAtPoint(RenderWidgetHost* rwh, | |
| 42 gfx::Point point, | |
| 43 void (^replyHandler)(NSAttributedString*, NSPoint)); | |
|
Avi (use Gerrit)
2014/03/12 04:55:40
Two questions:
1. Is this async, given the callba
Andre
2014/03/12 16:59:26
1. Yes, this is async. Updated comments accordingl
| |
| 44 void GetStringAtPointReply(NSAttributedString*, NSPoint); | |
| 45 | |
| 40 // Each of the three methods mentioned above has an associated pair of methods | 46 // Each of the three methods mentioned above has an associated pair of methods |
| 41 // to get data from the renderer. The Get*() methods block the calling thread | 47 // to get data from the renderer. The Get*() methods block the calling thread |
| 42 // (always the UI thread) with a short timeout after the async message has | 48 // (always the UI thread) with a short timeout after the async message has |
| 43 // been sent to the renderer to lookup the information needed to respond to | 49 // been sent to the renderer to lookup the information needed to respond to |
| 44 // the system. The Set*AndSignal() methods store the looked up information in | 50 // the system. The Set*AndSignal() methods store the looked up information in |
| 45 // this service and signal the condition to allow the Get*() methods to | 51 // this service and signal the condition to allow the Get*() methods to |
| 46 // unlock and return that stored value. | 52 // unlock and return that stored value. |
| 47 // | 53 // |
| 48 // Returns NSNotFound if the request times out or is not completed. | 54 // Returns NSNotFound if the request times out or is not completed. |
| 49 NSUInteger GetCharacterIndexAtPoint(RenderWidgetHost* rwh, gfx::Point point); | 55 NSUInteger GetCharacterIndexAtPoint(RenderWidgetHost* rwh, gfx::Point point); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 75 // condition. | 81 // condition. |
| 76 void AfterRequest(); | 82 void AfterRequest(); |
| 77 | 83 |
| 78 NSUInteger character_index_; | 84 NSUInteger character_index_; |
| 79 NSRect first_rect_; | 85 NSRect first_rect_; |
| 80 base::scoped_nsobject<NSAttributedString> substring_; | 86 base::scoped_nsobject<NSAttributedString> substring_; |
| 81 | 87 |
| 82 base::Lock lock_; | 88 base::Lock lock_; |
| 83 base::ConditionVariable condition_; | 89 base::ConditionVariable condition_; |
| 84 | 90 |
| 91 base::mac::ScopedBlock<void(^)(NSAttributedString*, NSPoint)> replyHandler_; | |
| 92 | |
| 85 DISALLOW_COPY_AND_ASSIGN(TextInputClientMac); | 93 DISALLOW_COPY_AND_ASSIGN(TextInputClientMac); |
| 86 }; | 94 }; |
| 87 | 95 |
| 88 } // namespace content | 96 } // namespace content |
| 89 | 97 |
| 90 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ | 98 #endif // CONTENT_BROWSER_RENDERER_HOST_TEXT_INPUT_CLIENT_MAC_H_ |
| OLD | NEW |