Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2138)

Unified Diff: content/renderer/text_input_client_observer.cc

Issue 2278283002: Implement Mac Pop-up Dictionary for OOPIF. (Closed)
Patch Set: Addressing lfg@'s comment Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/renderer/text_input_client_observer.cc
diff --git a/content/renderer/text_input_client_observer.cc b/content/renderer/text_input_client_observer.cc
index c18d1273294100df05dd1827ba804b91051524ba..7ddcd23a48af593403b4b505e9c2928dafd379c8 100644
--- a/content/renderer/text_input_client_observer.cc
+++ b/content/renderer/text_input_client_observer.cc
@@ -11,7 +11,10 @@
#include "build/build_config.h"
#include "content/common/text_input_client_messages.h"
#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
+#include "content/renderer/render_frame_impl.h"
#include "content/renderer/render_view_impl.h"
+#include "content/renderer/render_widget.h"
+#include "ipc/ipc_message.h"
#include "third_party/WebKit/public/platform/WebPoint.h"
#include "third_party/WebKit/public/platform/WebRect.h"
#include "third_party/WebKit/public/platform/WebString.h"
@@ -22,13 +25,8 @@
namespace content {
-TextInputClientObserver::TextInputClientObserver(RenderViewImpl* render_view)
-#if defined(ENABLE_PLUGINS)
- : RenderViewObserver(render_view), render_view_impl_(render_view) {
-#else
- : RenderViewObserver(render_view) {
-#endif
-}
+TextInputClientObserver::TextInputClientObserver(RenderFrameImpl* render_frame)
+ : render_frame_(render_frame) {}
TextInputClientObserver::~TextInputClientObserver() {
}
@@ -48,46 +46,69 @@ bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) {
return handled;
}
-void TextInputClientObserver::OnDestruct() {
- delete this;
+bool TextInputClientObserver::Send(IPC::Message* message) {
+ return GetRenderWidget() && GetRenderWidget()->Send(message);
+}
+
+RenderWidget* TextInputClientObserver::GetRenderWidget() {
+ return render_frame_->GetRenderWidget();
}
-blink::WebView* TextInputClientObserver::webview() {
- return render_view()->GetWebView();
+blink::WebView* TextInputClientObserver::GetWebView() {
+ return (render_frame_->render_view() &&
+ render_frame_->render_view()->webview())
Charlie Reis 2016/09/02 21:57:47 Are there ever cases that render_view() or webview
EhsanK 2016/09/08 17:10:40 The stuff with checking GetRenderWidget() was abso
+ ? render_frame_->render_view()->webview()
+ : nullptr;
+}
+
+int32_t TextInputClientObserver::GetRoutingID() {
+ return GetRenderWidget() ? GetRenderWidget()->routing_id() : MSG_ROUTING_NONE;
}
void TextInputClientObserver::OnStringAtPoint(gfx::Point point) {
#if defined(OS_MACOSX)
+ if (!GetRenderWidget() || !GetWebView())
+ return;
+
blink::WebPoint baselinePoint;
NSAttributedString* string = blink::WebSubstringUtil::attributedWordAtPoint(
- webview(), point, baselinePoint);
+ GetWebView(), GetRenderWidget()->webwidget(), point, baselinePoint);
std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
mac::AttributedStringCoder::Encode(string));
Send(new TextInputClientReplyMsg_GotStringAtPoint(
- routing_id(), *encoded.get(), baselinePoint));
+ GetRoutingID(), *encoded.get(), baselinePoint));
#else
NOTIMPLEMENTED();
#endif
}
void TextInputClientObserver::OnCharacterIndexForPoint(gfx::Point point) {
+ if (!GetWebView())
+ return;
+
blink::WebPoint web_point(point);
uint32_t index = static_cast<uint32_t>(
- webview()->focusedFrame()->characterIndexForPoint(web_point));
- Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(routing_id(),
- index));
+ GetWebView()->focusedFrame()->characterIndexForPoint(web_point));
+ Send(new TextInputClientReplyMsg_GotCharacterIndexForPoint(GetRoutingID(),
+ index));
}
void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) {
gfx::Rect rect;
+ if (!GetWebView())
+ return;
#if defined(ENABLE_PLUGINS)
- if (render_view_impl_->GetFocusedPepperPlugin()) {
- rect = render_view_impl_->GetFocusedPepperPlugin()->GetCaretBounds();
+ PepperPluginInstanceImpl* focused_plugin =
+ render_frame_->render_view()
+ ? render_frame_->render_view()->GetFocusedPepperPlugin()
+ : nullptr;
+ if (focused_plugin) {
+ rect = focused_plugin->GetCaretBounds();
} else
#endif
{
- blink::WebLocalFrame* frame = webview()->focusedFrame();
+ blink::WebLocalFrame* frame = GetWebView()->focusedFrame();
// TODO(yabinh): Null check should not be necessary.
// See crbug.com/304341
if (frame) {
@@ -97,14 +118,17 @@ void TextInputClientObserver::OnFirstRectForCharacterRange(gfx::Range range) {
rect = web_rect;
}
}
- Send(new TextInputClientReplyMsg_GotFirstRectForRange(routing_id(), rect));
+ Send(new TextInputClientReplyMsg_GotFirstRectForRange(GetRoutingID(), rect));
}
void TextInputClientObserver::OnStringForRange(gfx::Range range) {
#if defined(OS_MACOSX)
+ if (!GetWebView())
+ return;
+
blink::WebPoint baselinePoint;
NSAttributedString* string = nil;
- blink::WebLocalFrame* frame = webview()->focusedFrame();
+ blink::WebLocalFrame* frame = GetWebView()->focusedFrame();
// TODO(yabinh): Null check should not be necessary.
// See crbug.com/304341
if (frame) {
@@ -113,8 +137,8 @@ void TextInputClientObserver::OnStringForRange(gfx::Range range) {
}
std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded(
mac::AttributedStringCoder::Encode(string));
- Send(new TextInputClientReplyMsg_GotStringForRange(routing_id(),
- *encoded.get(), baselinePoint));
+ Send(new TextInputClientReplyMsg_GotStringForRange(
+ GetRoutingID(), *encoded.get(), baselinePoint));
#else
NOTIMPLEMENTED();
#endif

Powered by Google App Engine
This is Rietveld 408576698