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" |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 // static | 31 // static |
32 TextInputClientMac* TextInputClientMac::GetInstance() { | 32 TextInputClientMac* TextInputClientMac::GetInstance() { |
33 return base::Singleton<TextInputClientMac>::get(); | 33 return base::Singleton<TextInputClientMac>::get(); |
34 } | 34 } |
35 | 35 |
36 void TextInputClientMac::GetStringAtPoint( | 36 void TextInputClientMac::GetStringAtPoint( |
37 RenderWidgetHost* rwh, | 37 RenderWidgetHost* rwh, |
38 gfx::Point point, | 38 gfx::Point point, |
39 void (^replyHandler)(NSAttributedString*, NSPoint)) { | 39 void (^reply_handler)(NSAttributedString*, NSPoint)) { |
40 DCHECK(replyHandler_.get() == nil); | 40 DCHECK(replyForPointHandler_.get() == nil); |
41 replyHandler_.reset(replyHandler, base::scoped_policy::RETAIN); | 41 replyForPointHandler_.reset(reply_handler, base::scoped_policy::RETAIN); |
42 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 42 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
43 rwhi->Send(new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point)); | 43 rwhi->Send(new TextInputClientMsg_StringAtPoint(rwhi->GetRoutingID(), point)); |
44 } | 44 } |
45 | 45 |
46 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, | 46 void TextInputClientMac::GetStringAtPointReply(NSAttributedString* string, |
47 NSPoint point) { | 47 NSPoint point) { |
48 if (replyHandler_.get()) { | 48 if (replyForPointHandler_.get()) { |
49 replyHandler_.get()(string, point); | 49 replyForPointHandler_.get()(string, point); |
50 replyHandler_.reset(); | 50 replyForPointHandler_.reset(); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
| 54 void TextInputClientMac::GetStringFromRange( |
| 55 RenderWidgetHost* rwh, |
| 56 NSRange range, |
| 57 void (^reply_handler)(NSAttributedString*, NSPoint)) { |
| 58 DCHECK(replyForRangeHandler_.get() == nil); |
| 59 replyForRangeHandler_.reset(reply_handler, base::scoped_policy::RETAIN); |
| 60 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 61 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), |
| 62 gfx::Range(range))); |
| 63 } |
| 64 |
| 65 void TextInputClientMac::GetStringFromRangeReply(NSAttributedString* string, |
| 66 NSPoint point) { |
| 67 SetSubstringAndSignal(string); |
| 68 if (replyForRangeHandler_.get()) { |
| 69 replyForRangeHandler_.get()(string, point); |
| 70 replyForRangeHandler_.reset(); |
| 71 } |
| 72 } |
| 73 |
54 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, | 74 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, |
55 gfx::Point point) { | 75 gfx::Point point) { |
56 base::TimeTicks start = base::TimeTicks::Now(); | 76 base::TimeTicks start = base::TimeTicks::Now(); |
57 | 77 |
58 BeforeRequest(); | 78 BeforeRequest(); |
59 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 79 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
60 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), | 80 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), |
61 point)); | 81 point)); |
62 // http://crbug.com/121917 | 82 // http://crbug.com/121917 |
63 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 83 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 character_index_ = NSNotFound; | 169 character_index_ = NSNotFound; |
150 first_rect_ = NSZeroRect; | 170 first_rect_ = NSZeroRect; |
151 substring_.reset(); | 171 substring_.reset(); |
152 } | 172 } |
153 | 173 |
154 void TextInputClientMac::AfterRequest() { | 174 void TextInputClientMac::AfterRequest() { |
155 lock_.Release(); | 175 lock_.Release(); |
156 } | 176 } |
157 | 177 |
158 } // namespace content | 178 } // namespace content |
OLD | NEW |