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 #import "content/browser/renderer_host/text_input_client_mac.h" | 5 #import "content/browser/renderer_host/text_input_client_mac.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
11 #include "content/browser/renderer_host/render_widget_host_impl.h" | 11 #include "content/browser/renderer_host/render_widget_host_impl.h" |
12 #include "content/common/text_input_client_messages.h" | 12 #include "content/common/text_input_client_messages.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 // The amount of time in milliseconds that the browser process will wait for a | 16 // The amount of time in milliseconds that the browser process will wait for a |
17 // response from the renderer. | 17 // response from the renderer. |
18 // TODO(rsesek): Using the histogram data, find the best upper-bound for this | 18 // TODO(rsesek): Using the histogram data, find the best upper-bound for this |
19 // value. | 19 // value. |
20 const float kWaitTimeout = 1500; | 20 const float kWaitTimeout = 1500; |
21 | 21 |
22 TextInputClientMac::TextInputClientMac() | 22 TextInputClientMac::TextInputClientMac() |
23 : character_index_(NSNotFound), | 23 : character_index_(NSNotFound), |
24 lock_(), | 24 lock_(), |
25 condition_(&lock_) { | 25 condition_(&lock_), |
| 26 replyHandler_(nil) { |
26 } | 27 } |
27 | 28 |
28 TextInputClientMac::~TextInputClientMac() { | 29 TextInputClientMac::~TextInputClientMac() { |
29 } | 30 } |
30 | 31 |
31 // static | 32 // static |
32 TextInputClientMac* TextInputClientMac::GetInstance() { | 33 TextInputClientMac* TextInputClientMac::GetInstance() { |
33 return Singleton<TextInputClientMac>::get(); | 34 return Singleton<TextInputClientMac>::get(); |
34 } | 35 } |
35 | 36 |
| 37 void TextInputClientMac::GetStringAtPoint(RenderWidgetHost* rwh, |
| 38 gfx::Point point, |
| 39 void (^replyHandler)(NSAttributedString*, NSRect)) { |
| 40 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 41 rwhi->Send(new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), |
| 42 point)); |
| 43 if (replyHandler_ != nil) |
| 44 [replyHandler_ release]; |
| 45 replyHandler_ = [replyHandler copy]; |
| 46 } |
| 47 |
| 48 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, |
| 49 NSRect rect) { |
| 50 if (replyHandler_ != nil) { |
| 51 replyHandler_(string, rect); |
| 52 [replyHandler_ release]; |
| 53 replyHandler_ = nil; |
| 54 } |
| 55 } |
| 56 |
36 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, | 57 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, |
37 gfx::Point point) { | 58 gfx::Point point) { |
38 base::TimeTicks start = base::TimeTicks::Now(); | 59 base::TimeTicks start = base::TimeTicks::Now(); |
39 | 60 |
40 BeforeRequest(); | 61 BeforeRequest(); |
41 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 62 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
42 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), | 63 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), |
43 point)); | 64 point)); |
44 // http://crbug.com/121917 | 65 // http://crbug.com/121917 |
45 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 66 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 character_index_ = NSNotFound; | 152 character_index_ = NSNotFound; |
132 first_rect_ = NSZeroRect; | 153 first_rect_ = NSZeroRect; |
133 substring_.reset(); | 154 substring_.reset(); |
134 } | 155 } |
135 | 156 |
136 void TextInputClientMac::AfterRequest() { | 157 void TextInputClientMac::AfterRequest() { |
137 lock_.Release(); | 158 lock_.Release(); |
138 } | 159 } |
139 | 160 |
140 } // namespace content | 161 } // namespace content |
OLD | NEW |