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 #include "content/renderer/text_input_client_observer.h" | 5 #include "content/renderer/text_input_client_observer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "content/common/text_input_client_messages.h" | 12 #include "content/common/text_input_client_messages.h" |
| 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 14 #include "content/renderer/render_frame_impl.h" | 14 #include "content/renderer/render_frame_impl.h" |
| 15 #include "content/renderer/render_view_impl.h" | 15 #include "content/renderer/render_view_impl.h" |
| 16 #include "content/renderer/render_widget.h" | 16 #include "content/renderer/render_widget.h" |
| 17 #include "ipc/ipc_message.h" | 17 #include "ipc/ipc_message.h" |
| 18 #include "ppapi/features/features.h" | 18 #include "ppapi/features/features.h" |
| 19 #include "third_party/WebKit/public/platform/WebPoint.h" | 19 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 20 #include "third_party/WebKit/public/platform/WebRect.h" | 20 #include "third_party/WebKit/public/platform/WebRect.h" |
| 21 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 22 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
| 24 #include "third_party/WebKit/public/web/mac/WebSubstringUtil.h" | 24 #include "third_party/WebKit/public/web/mac/WebSubstringUtil.h" |
| 25 #include "ui/gfx/geometry/rect.h" | 25 #include "ui/gfx/geometry/rect.h" |
| 26 | 26 |
| 27 namespace content { | 27 namespace content { |
| 28 | 28 |
| 29 namespace { | |
| 30 uint32_t GetCurrentCursorPositionInFrame(blink::WebLocalFrame* localFrame) { | |
| 31 blink::WebRange range = localFrame->selectionRange(); | |
| 32 return range.startOffset() != -1 ? static_cast<uint32_t>(range.startOffset()) | |
|
erikchen
2016/11/30 15:24:33
should this be an IsNull check instead of != -1?
EhsanK
2016/11/30 16:40:52
I believe yes. Thanks!
| |
| 33 : 0U; | |
| 34 } | |
| 35 } | |
| 36 | |
| 29 TextInputClientObserver::TextInputClientObserver(RenderWidget* render_widget) | 37 TextInputClientObserver::TextInputClientObserver(RenderWidget* render_widget) |
| 30 : render_widget_(render_widget) {} | 38 : render_widget_(render_widget) {} |
| 31 | 39 |
| 32 TextInputClientObserver::~TextInputClientObserver() { | 40 TextInputClientObserver::~TextInputClientObserver() { |
| 33 } | 41 } |
| 34 | 42 |
| 35 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { | 43 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |
| 36 bool handled = true; | 44 bool handled = true; |
| 37 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) | 45 IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |
| 38 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, | 46 IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 if (focused_plugin) { | 134 if (focused_plugin) { |
| 127 rect = focused_plugin->GetCaretBounds(); | 135 rect = focused_plugin->GetCaretBounds(); |
| 128 } else | 136 } else |
| 129 #endif | 137 #endif |
| 130 { | 138 { |
| 131 blink::WebLocalFrame* frame = GetFocusedFrame(); | 139 blink::WebLocalFrame* frame = GetFocusedFrame(); |
| 132 // TODO(yabinh): Null check should not be necessary. | 140 // TODO(yabinh): Null check should not be necessary. |
| 133 // See crbug.com/304341 | 141 // See crbug.com/304341 |
| 134 if (frame) { | 142 if (frame) { |
| 135 blink::WebRect web_rect; | 143 blink::WebRect web_rect; |
| 136 frame->firstRectForCharacterRange(range.start(), range.length(), | 144 uint32_t start = range.IsValid() ? range.start() |
| 137 web_rect); | 145 : GetCurrentCursorPositionInFrame(frame); |
| 146 frame->firstRectForCharacterRange(start, range.length(), web_rect); | |
| 138 rect = web_rect; | 147 rect = web_rect; |
| 139 } | 148 } |
| 140 } | 149 } |
| 141 Send(new TextInputClientReplyMsg_GotFirstRectForRange( | 150 Send(new TextInputClientReplyMsg_GotFirstRectForRange( |
| 142 render_widget_->routing_id(), rect)); | 151 render_widget_->routing_id(), rect)); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void TextInputClientObserver::OnStringForRange(gfx::Range range) { | 154 void TextInputClientObserver::OnStringForRange(gfx::Range range) { |
| 146 #if defined(OS_MACOSX) | 155 #if defined(OS_MACOSX) |
| 147 blink::WebPoint baselinePoint; | 156 blink::WebPoint baselinePoint; |
| 148 NSAttributedString* string = nil; | 157 NSAttributedString* string = nil; |
| 149 blink::WebLocalFrame* frame = GetFocusedFrame(); | 158 blink::WebLocalFrame* frame = GetFocusedFrame(); |
| 150 // TODO(yabinh): Null check should not be necessary. | 159 // TODO(yabinh): Null check should not be necessary. |
| 151 // See crbug.com/304341 | 160 // See crbug.com/304341 |
| 152 if (frame) { | 161 if (frame) { |
| 153 string = blink::WebSubstringUtil::attributedSubstringInRange( | 162 string = blink::WebSubstringUtil::attributedSubstringInRange( |
| 154 frame, range.start(), range.length(), &baselinePoint); | 163 frame, range.start(), range.length(), &baselinePoint); |
| 155 } | 164 } |
| 156 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 165 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| 157 mac::AttributedStringCoder::Encode(string)); | 166 mac::AttributedStringCoder::Encode(string)); |
| 158 Send(new TextInputClientReplyMsg_GotStringForRange( | 167 Send(new TextInputClientReplyMsg_GotStringForRange( |
| 159 render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 168 render_widget_->routing_id(), *encoded.get(), baselinePoint)); |
| 160 #else | 169 #else |
| 161 NOTIMPLEMENTED(); | 170 NOTIMPLEMENTED(); |
| 162 #endif | 171 #endif |
| 163 } | 172 } |
| 164 | 173 |
| 165 } // namespace content | 174 } // namespace content |
| OLD | NEW |