| 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.isNull() ? 0U : static_cast<uint32_t>(range.startOffset()); | 
 |   33 } | 
 |   34 } | 
 |   35  | 
|   29 TextInputClientObserver::TextInputClientObserver(RenderWidget* render_widget) |   36 TextInputClientObserver::TextInputClientObserver(RenderWidget* render_widget) | 
|   30     : render_widget_(render_widget) {} |   37     : render_widget_(render_widget) {} | 
|   31  |   38  | 
|   32 TextInputClientObserver::~TextInputClientObserver() { |   39 TextInputClientObserver::~TextInputClientObserver() { | 
|   33 } |   40 } | 
|   34  |   41  | 
|   35 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { |   42 bool TextInputClientObserver::OnMessageReceived(const IPC::Message& message) { | 
|   36   bool handled = true; |   43   bool handled = true; | 
|   37   IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) |   44   IPC_BEGIN_MESSAGE_MAP(TextInputClientObserver, message) | 
|   38     IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, |   45     IPC_MESSAGE_HANDLER(TextInputClientMsg_StringAtPoint, | 
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  126   if (focused_plugin) { |  133   if (focused_plugin) { | 
|  127     rect = focused_plugin->GetCaretBounds(); |  134     rect = focused_plugin->GetCaretBounds(); | 
|  128   } else |  135   } else | 
|  129 #endif |  136 #endif | 
|  130   { |  137   { | 
|  131     blink::WebLocalFrame* frame = GetFocusedFrame(); |  138     blink::WebLocalFrame* frame = GetFocusedFrame(); | 
|  132     // TODO(yabinh): Null check should not be necessary. |  139     // TODO(yabinh): Null check should not be necessary. | 
|  133     // See crbug.com/304341 |  140     // See crbug.com/304341 | 
|  134     if (frame) { |  141     if (frame) { | 
|  135       blink::WebRect web_rect; |  142       blink::WebRect web_rect; | 
|  136       frame->firstRectForCharacterRange(range.start(), range.length(), |  143       // When request range is invalid we will try to obtain it from current | 
|  137                                         web_rect); |  144       // frame selection. The fallback value will be 0. | 
 |  145       uint32_t start = range.IsValid() ? range.start() | 
 |  146                                        : GetCurrentCursorPositionInFrame(frame); | 
 |  147       frame->firstRectForCharacterRange(start, range.length(), web_rect); | 
|  138       rect = web_rect; |  148       rect = web_rect; | 
|  139     } |  149     } | 
|  140   } |  150   } | 
|  141   Send(new TextInputClientReplyMsg_GotFirstRectForRange( |  151   Send(new TextInputClientReplyMsg_GotFirstRectForRange( | 
|  142       render_widget_->routing_id(), rect)); |  152       render_widget_->routing_id(), rect)); | 
|  143 } |  153 } | 
|  144  |  154  | 
|  145 void TextInputClientObserver::OnStringForRange(gfx::Range range) { |  155 void TextInputClientObserver::OnStringForRange(gfx::Range range) { | 
|  146 #if defined(OS_MACOSX) |  156 #if defined(OS_MACOSX) | 
|  147   blink::WebPoint baselinePoint; |  157   blink::WebPoint baselinePoint; | 
|  148   NSAttributedString* string = nil; |  158   NSAttributedString* string = nil; | 
|  149   blink::WebLocalFrame* frame = GetFocusedFrame(); |  159   blink::WebLocalFrame* frame = GetFocusedFrame(); | 
|  150   // TODO(yabinh): Null check should not be necessary. |  160   // TODO(yabinh): Null check should not be necessary. | 
|  151   // See crbug.com/304341 |  161   // See crbug.com/304341 | 
|  152   if (frame) { |  162   if (frame) { | 
|  153     string = blink::WebSubstringUtil::attributedSubstringInRange( |  163     string = blink::WebSubstringUtil::attributedSubstringInRange( | 
|  154         frame, range.start(), range.length(), &baselinePoint); |  164         frame, range.start(), range.length(), &baselinePoint); | 
|  155   } |  165   } | 
|  156   std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( |  166   std::unique_ptr<const mac::AttributedStringCoder::EncodedString> encoded( | 
|  157       mac::AttributedStringCoder::Encode(string)); |  167       mac::AttributedStringCoder::Encode(string)); | 
|  158   Send(new TextInputClientReplyMsg_GotStringForRange( |  168   Send(new TextInputClientReplyMsg_GotStringForRange( | 
|  159       render_widget_->routing_id(), *encoded.get(), baselinePoint)); |  169       render_widget_->routing_id(), *encoded.get(), baselinePoint)); | 
|  160 #else |  170 #else | 
|  161   NOTIMPLEMENTED(); |  171   NOTIMPLEMENTED(); | 
|  162 #endif |  172 #endif | 
|  163 } |  173 } | 
|  164  |  174  | 
|  165 }  // namespace content |  175 }  // namespace content | 
| OLD | NEW |