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 "base/strings/utf_string_conversions.h" | |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "content/common/text_input_client_messages.h" | 13 #include "content/common/text_input_client_messages.h" |
| 13 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 14 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 14 #include "content/renderer/render_frame_impl.h" | 15 #include "content/renderer/render_frame_impl.h" |
| 15 #include "content/renderer/render_view_impl.h" | 16 #include "content/renderer/render_view_impl.h" |
| 16 #include "content/renderer/render_widget.h" | 17 #include "content/renderer/render_widget.h" |
| 17 #include "ipc/ipc_message.h" | 18 #include "ipc/ipc_message.h" |
| 18 #include "third_party/WebKit/public/platform/WebPoint.h" | 19 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 19 #include "third_party/WebKit/public/platform/WebRect.h" | 20 #include "third_party/WebKit/public/platform/WebRect.h" |
| 20 #include "third_party/WebKit/public/platform/WebString.h" | 21 #include "third_party/WebKit/public/platform/WebString.h" |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 45 IPC_END_MESSAGE_MAP() | 46 IPC_END_MESSAGE_MAP() |
| 46 return handled; | 47 return handled; |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool TextInputClientObserver::Send(IPC::Message* message) { | 50 bool TextInputClientObserver::Send(IPC::Message* message) { |
| 50 return render_widget_->Send(message); | 51 return render_widget_->Send(message); |
| 51 } | 52 } |
| 52 | 53 |
| 53 blink::WebFrameWidget* TextInputClientObserver::GetWebFrameWidget() const { | 54 blink::WebFrameWidget* TextInputClientObserver::GetWebFrameWidget() const { |
| 54 blink::WebWidget* widget = render_widget_->GetWebWidget(); | 55 blink::WebWidget* widget = render_widget_->GetWebWidget(); |
| 55 // We should always receive a WebFrameWidget in the call above. RenderViewImpl | 56 // |widget| should only be a WebFrameWidget. It is however possible to get |
| 56 // however might return a WebView if the main frame is destroyed, but as long | 57 // here through a fullscreen flash plugin where the |widget| is not a |
| 57 // as there is a rendered page, we should not be in that state and the RVImpl | 58 // WebFrameWidget. |
| 58 // should be returning a frame widget. | 59 return widget->isWebFrameWidget() |
| 59 DCHECK(widget->isWebFrameWidget()); | 60 ? static_cast<blink::WebFrameWidget*>(widget) |
| 60 return static_cast<blink::WebFrameWidget*>(render_widget_->GetWebWidget()); | 61 : nullptr; |
| 61 } | 62 } |
| 62 | 63 |
| 63 blink::WebLocalFrame* TextInputClientObserver::GetFocusedFrame() const { | 64 blink::WebLocalFrame* TextInputClientObserver::GetFocusedFrame() const { |
| 64 blink::WebLocalFrame* focused = | 65 blink::WebLocalFrame* focused = |
| 65 RenderFrameImpl::FromWebFrame(GetWebFrameWidget()->localRoot()) | 66 RenderFrameImpl::FromWebFrame(GetWebFrameWidget()->localRoot()) |
| 66 ->render_view() | 67 ->render_view() |
| 67 ->webview() | 68 ->webview() |
| 68 ->focusedFrame(); | 69 ->focusedFrame(); |
| 69 return focused->localRoot() == GetWebFrameWidget()->localRoot() ? focused | 70 return focused->localRoot() == GetWebFrameWidget()->localRoot() ? focused |
| 70 : nullptr; | 71 : nullptr; |
| 71 } | 72 } |
| 72 | 73 |
| 73 #if defined(ENABLE_PLUGINS) | 74 #if defined(ENABLE_PLUGINS) |
| 74 PepperPluginInstanceImpl* TextInputClientObserver::GetFocusedPepperPlugin() | 75 PepperPluginInstanceImpl* TextInputClientObserver::GetFocusedPepperPlugin() |
| 75 const { | 76 const { |
| 76 blink::WebLocalFrame* focusedFrame = GetFocusedFrame(); | 77 blink::WebLocalFrame* focusedFrame = GetFocusedFrame(); |
| 77 return focusedFrame | 78 return focusedFrame |
| 78 ? RenderFrameImpl::FromWebFrame(focusedFrame) | 79 ? RenderFrameImpl::FromWebFrame(focusedFrame) |
| 79 ->focused_pepper_plugin() | 80 ->focused_pepper_plugin() |
| 80 : nullptr; | 81 : nullptr; |
| 81 } | 82 } |
| 82 #endif | 83 #endif |
| 83 | 84 |
| 84 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { | 85 void TextInputClientObserver::OnStringAtPoint(gfx::Point point) { |
| 85 #if defined(OS_MACOSX) | 86 #if defined(OS_MACOSX) |
| 87 NSAttributedString* string = nil; | |
| 86 blink::WebPoint baselinePoint; | 88 blink::WebPoint baselinePoint; |
| 87 NSAttributedString* string = blink::WebSubstringUtil::attributedWordAtPoint( | 89 if (GetWebFrameWidget()) { |
|
EhsanK
2016/10/18 01:59:37
When this is false, it is not necessarily because
Avi (use Gerrit)
2016/10/18 02:04:08
Can we find out?
alexmos
2016/10/18 17:52:01
Just to clarify, is this whole class for Mac dicti
EhsanK
2016/11/03 07:13:19
Except for OnCharacterIndexForPoint which is for I
alexmos
2016/11/04 20:34:03
Yes, I think you could opener_id_ to get the the p
EhsanK
2016/11/08 16:59:44
Acknowledged.
| |
| 88 GetWebFrameWidget(), point, baselinePoint); | 90 string = blink::WebSubstringUtil::attributedWordAtPoint( |
| 89 | 91 GetWebFrameWidget(), point, baselinePoint); |
| 92 } | |
| 90 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 93 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| 91 mac::AttributedStringCoder::Encode(string)); | 94 mac::AttributedStringCoder::Encode(string)); |
| 92 Send(new TextInputClientReplyMsg_GotStringAtPoint( | 95 Send(new TextInputClientReplyMsg_GotStringAtPoint( |
| 93 render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 96 render_widget_->routing_id(), *encoded.get(), baselinePoint)); |
| 94 #else | 97 #else |
| 95 NOTIMPLEMENTED(); | 98 NOTIMPLEMENTED(); |
| 96 #endif | 99 #endif |
| 97 } | 100 } |
| 98 | 101 |
| 99 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { | 102 void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) { |
| 100 blink::WebPoint web_point(point); | 103 blink::WebPoint web_point(point); |
| 101 uint32_t index = static_cast<uint32_t>( | 104 uint32_t index = 0; |
| 105 if (GetWebFrameWidget()) { | |
| 106 index = static_cast<uint32_t>( | |
| 102 GetFocusedFrame()->characterIndexForPoint(web_point)); | 107 GetFocusedFrame()->characterIndexForPoint(web_point)); |
| 108 } | |
| 103 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( | 109 Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint( |
| 104 render_widget_->routing_id(), index)); | 110 render_widget_->routing_id(), index)); |
| 105 } | 111 } |
| 106 | 112 |
| 107 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { | 113 void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) { |
| 108 gfx::Rect rect; | 114 gfx::Rect rect; |
| 115 if (GetWebFrameWidget()) { | |
| 109 #if defined(ENABLE_PLUGINS) | 116 #if defined(ENABLE_PLUGINS) |
| 110 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); | 117 PepperPluginInstanceImpl* focused_plugin = GetFocusedPepperPlugin(); |
|
lfg
2016/10/19 17:40:32
This looks strange to me. Why would flash receive
EhsanK
2016/11/03 07:13:19
This is why I think we should send the IPC to the
| |
| 111 if (focused_plugin) { | 118 if (focused_plugin) { |
| 112 rect = focused_plugin->GetCaretBounds(); | 119 rect = focused_plugin->GetCaretBounds(); |
| 113 } else | 120 } else |
| 114 #endif | 121 #endif |
| 115 { | 122 { |
| 116 blink::WebLocalFrame* frame = GetFocusedFrame(); | 123 blink::WebLocalFrame* frame = GetFocusedFrame(); |
| 117 // TODO(yabinh): Null check should not be necessary. | 124 // TODO(yabinh): Null check should not be necessary. |
| 118 // See crbug.com/304341 | 125 // See crbug.com/304341 |
| 119 if (frame) { | 126 if (frame) { |
| 120 blink::WebRect web_rect; | 127 blink::WebRect web_rect; |
| 121 frame->firstRectForCharacterRange(range.start(), range.length(), | 128 frame->firstRectForCharacterRange(range.start(), range.length(), |
| 122 web_rect); | 129 web_rect); |
| 123 rect = web_rect; | 130 rect = web_rect; |
| 131 } | |
| 124 } | 132 } |
| 125 } | 133 } |
| 126 Send(new TextInputClientReplyMsg_GotFirstRectForRange( | 134 Send(new TextInputClientReplyMsg_GotFirstRectForRange( |
| 127 render_widget_->routing_id(), rect)); | 135 render_widget_->routing_id(), rect)); |
| 128 } | 136 } |
| 129 | 137 |
| 130 void TextInputClientObserver::OnStringForRange(gfx::Range range) { | 138 void TextInputClientObserver::OnStringForRange(gfx::Range range) { |
| 131 #if defined(OS_MACOSX) | 139 #if defined(OS_MACOSX) |
| 132 blink::WebPoint baselinePoint; | 140 blink::WebPoint baselinePoint; |
| 133 NSAttributedString* string = nil; | 141 NSAttributedString* string = nil; |
| 134 blink::WebLocalFrame* frame = GetFocusedFrame(); | 142 if (GetWebFrameWidget()) { |
| 135 // TODO(yabinh): Null check should not be necessary. | 143 blink::WebLocalFrame* frame = GetFocusedFrame(); |
| 136 // See crbug.com/304341 | 144 // TODO(yabinh): Null check should not be necessary. |
| 137 if (frame) { | 145 // See crbug.com/304341 |
| 138 string = blink::WebSubstringUtil::attributedSubstringInRange( | 146 if (frame) { |
| 139 frame, range.start(), range.length(), &baselinePoint); | 147 string = blink::WebSubstringUtil::attributedSubstringInRange( |
| 148 frame, range.start(), range.length(), &baselinePoint); | |
| 149 } | |
| 140 } | 150 } |
| 141 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 151 std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |
| 142 mac::AttributedStringCoder::Encode(string)); | 152 mac::AttributedStringCoder::Encode(string)); |
| 143 Send(new TextInputClientReplyMsg_GotStringForRange( | 153 Send(new TextInputClientReplyMsg_GotStringForRange( |
| 144 render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 154 render_widget_->routing_id(), *encoded.get(), baselinePoint)); |
| 145 #else | 155 #else |
| 146 NOTIMPLEMENTED(); | 156 NOTIMPLEMENTED(); |
| 147 #endif | 157 #endif |
| 148 } | 158 } |
| 149 | 159 |
| 150 } // namespace content | 160 } // namespace content |
| OLD | NEW |