| 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/time.h" | 9 #include "base/time.h" |
| 10 #include "content/browser/renderer_host/render_widget_host.h" | 10 #include "content/browser/renderer_host/render_widget_host.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // static | 28 // static |
| 29 TextInputClientMac* TextInputClientMac::GetInstance() { | 29 TextInputClientMac* TextInputClientMac::GetInstance() { |
| 30 return Singleton<TextInputClientMac>::get(); | 30 return Singleton<TextInputClientMac>::get(); |
| 31 } | 31 } |
| 32 | 32 |
| 33 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, | 33 NSUInteger TextInputClientMac::GetCharacterIndexAtPoint(RenderWidgetHost* rwh, |
| 34 gfx::Point point) { | 34 gfx::Point point) { |
| 35 base::TimeTicks start = base::TimeTicks::Now(); | 35 base::TimeTicks start = base::TimeTicks::Now(); |
| 36 | 36 |
| 37 BeforeRequest(); | 37 BeforeRequest(); |
| 38 RenderWidgetHostImpl* rwhi = static_cast<RenderWidgetHostImpl*>(rwh); | 38 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 39 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->routing_id(), | 39 rwhi->Send(new TextInputClientMsg_CharacterIndexForPoint(rwhi->GetRoutingID(), |
| 40 point)); | 40 point)); |
| 41 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 41 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 42 AfterRequest(); | 42 AfterRequest(); |
| 43 | 43 |
| 44 base::TimeDelta delta(base::TimeTicks::Now() - start); | 44 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 45 UMA_HISTOGRAM_TIMES("TextInputClient.CharacterIndex", | 45 UMA_HISTOGRAM_TIMES("TextInputClient.CharacterIndex", |
| 46 delta * base::Time::kMicrosecondsPerMillisecond); | 46 delta * base::Time::kMicrosecondsPerMillisecond); |
| 47 | 47 |
| 48 return character_index_; | 48 return character_index_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, | 51 NSRect TextInputClientMac::GetFirstRectForRange(RenderWidgetHost* rwh, |
| 52 NSRange range) { | 52 NSRange range) { |
| 53 base::TimeTicks start = base::TimeTicks::Now(); | 53 base::TimeTicks start = base::TimeTicks::Now(); |
| 54 | 54 |
| 55 BeforeRequest(); | 55 BeforeRequest(); |
| 56 RenderWidgetHostImpl* rwhi = static_cast<RenderWidgetHostImpl*>(rwh); | 56 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 57 rwhi->Send( | 57 rwhi->Send( |
| 58 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->routing_id(), | 58 new TextInputClientMsg_FirstRectForCharacterRange(rwhi->GetRoutingID(), |
| 59 ui::Range(range))); | 59 ui::Range(range))); |
| 60 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 60 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 61 AfterRequest(); | 61 AfterRequest(); |
| 62 | 62 |
| 63 base::TimeDelta delta(base::TimeTicks::Now() - start); | 63 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 64 UMA_HISTOGRAM_TIMES("TextInputClient.FirstRect", | 64 UMA_HISTOGRAM_TIMES("TextInputClient.FirstRect", |
| 65 delta * base::Time::kMicrosecondsPerMillisecond); | 65 delta * base::Time::kMicrosecondsPerMillisecond); |
| 66 | 66 |
| 67 return first_rect_; | 67 return first_rect_; |
| 68 } | 68 } |
| 69 | 69 |
| 70 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( | 70 NSAttributedString* TextInputClientMac::GetAttributedSubstringFromRange( |
| 71 RenderWidgetHost* rwh, | 71 RenderWidgetHost* rwh, |
| 72 NSRange range) { | 72 NSRange range) { |
| 73 base::TimeTicks start = base::TimeTicks::Now(); | 73 base::TimeTicks start = base::TimeTicks::Now(); |
| 74 | 74 |
| 75 BeforeRequest(); | 75 BeforeRequest(); |
| 76 RenderWidgetHostImpl* rwhi = static_cast<RenderWidgetHostImpl*>(rwh); | 76 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
| 77 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->routing_id(), | 77 rwhi->Send(new TextInputClientMsg_StringForRange(rwhi->GetRoutingID(), |
| 78 ui::Range(range))); | 78 ui::Range(range))); |
| 79 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); | 79 condition_.TimedWait(base::TimeDelta::FromMilliseconds(kWaitTimeout)); |
| 80 AfterRequest(); | 80 AfterRequest(); |
| 81 | 81 |
| 82 base::TimeDelta delta(base::TimeTicks::Now() - start); | 82 base::TimeDelta delta(base::TimeTicks::Now() - start); |
| 83 UMA_HISTOGRAM_TIMES("TextInputClient.Substring", | 83 UMA_HISTOGRAM_TIMES("TextInputClient.Substring", |
| 84 delta * base::Time::kMicrosecondsPerMillisecond); | 84 delta * base::Time::kMicrosecondsPerMillisecond); |
| 85 | 85 |
| 86 // Lookup.framework calls this method repeatedly and expects that repeated | 86 // Lookup.framework calls this method repeatedly and expects that repeated |
| 87 // calls don't deallocate previous results immediately. Returning an | 87 // calls don't deallocate previous results immediately. Returning an |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 delta * base::Time::kMicrosecondsPerMillisecond); | 120 delta * base::Time::kMicrosecondsPerMillisecond); |
| 121 | 121 |
| 122 character_index_ = NSNotFound; | 122 character_index_ = NSNotFound; |
| 123 first_rect_ = NSZeroRect; | 123 first_rect_ = NSZeroRect; |
| 124 substring_.reset(); | 124 substring_.reset(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void TextInputClientMac::AfterRequest() { | 127 void TextInputClientMac::AfterRequest() { |
| 128 lock_.Release(); | 128 lock_.Release(); |
| 129 } | 129 } |
| OLD | NEW |