Index: Source/web/WebViewImpl.cpp |
diff --git a/Source/web/WebViewImpl.cpp b/Source/web/WebViewImpl.cpp |
index 8836341267581ea88fede135a0af516a7b3bfb95..84bf1280003174f64e65eada81cd86d4a4fac294 100644 |
--- a/Source/web/WebViewImpl.cpp |
+++ b/Source/web/WebViewImpl.cpp |
@@ -2144,6 +2144,34 @@ bool WebViewImpl::selectionBounds(WebRect& anchor, WebRect& focus) const |
return true; |
} |
+bool WebViewImpl::selectionRootBounds(WebRect& bounds) const |
+{ |
+ const LocalFrame* frame = focusedWebCoreFrame(); |
+ if (!frame) |
+ return false; |
+ |
+ Element* root = frame->selection().rootEditableElementOrDocumentElement(); |
+ if (!root) |
+ return false; |
+ |
+ // If the selection is inside a form control, the root will be a <div> that |
+ // behaves as the editor but we want to return the actual element's bounds. |
+ // In practice, that means <textarea> and <input> controls that behave like |
+ // a text field. |
+ if (root->shadowHost() |
+ && (root->shadowHost()->hasTagName(HTMLNames::textareaTag) |
+ || (root->shadowHost()->hasTagName(HTMLNames::inputTag) |
+ && toHTMLInputElement(root->shadowHost())->isText()))) |
+ root = root->shadowHost(); |
+ |
+ IntRect boundingBox = root->pixelSnappedBoundingBox(); |
+ boundingBox = root->document().frame()->view()->contentsToWindow(boundingBox); |
+ boundingBox.scale(pageScaleFactor()); |
+ bounds = boundingBox; |
+ |
+ return true; |
+} |
+ |
InputMethodContext* WebViewImpl::inputMethodContext() |
{ |
if (!m_imeAcceptEvents) |