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

Unified Diff: Source/WebKit/chromium/src/WebFrameImpl.cpp

Issue 6532004: DO NOT SUBMIT (Closed) Base URL: git://git.webkit.org/WebKit.git@master
Patch Set: Migrate WebTextHelper Created 9 years, 10 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: Source/WebKit/chromium/src/WebFrameImpl.cpp
diff --git a/Source/WebKit/chromium/src/WebFrameImpl.cpp b/Source/WebKit/chromium/src/WebFrameImpl.cpp
index 849b55cd57bd9508a36e838157a401dbf93ba911..b6c122b9b2743f3939d8bf02333c19a0c94fe651 100644
--- a/Source/WebKit/chromium/src/WebFrameImpl.cpp
+++ b/Source/WebKit/chromium/src/WebFrameImpl.cpp
@@ -85,6 +85,7 @@
#include "DocumentMarkerController.h"
#include "Editor.h"
#include "EventHandler.h"
+#include "FocusController.h"
#include "FormState.h"
#include "FrameLoadRequest.h"
#include "FrameLoader.h"
@@ -98,6 +99,7 @@
#include "HTMLLinkElement.h"
#include "HTMLNames.h"
#include "HistoryItem.h"
+#include "HitTestResult.h"
#include "InspectorController.h"
#include "Page.h"
#include "painting/GraphicsContextBuilder.h"
@@ -1112,10 +1114,29 @@ bool WebFrameImpl::firstRectForCharacterRange(unsigned location, unsigned length
return false;
IntRect intRect = frame()->editor()->firstRectForRange(range.get());
rect = WebRect(intRect.x(), intRect.y(), intRect.width(), intRect.height());
+ // When inside an text control, don't adjust the range.
+ if (!selectionRoot)
+ rect = frame()->view()->contentsToWindow(rect);
James Su 2011/03/03 04:08:03 IMHO, we should return frame based position in Web
Robert Sesek 2011/03/18 21:33:36 Why? That seems unnecessary and makes this CL more
return true;
}
+unsigned WebFrameImpl::characterIndexForPoint(const WebPoint& webPoint) const
+{
+ if (!frame())
+ return notFound;
+
+ IntPoint point = frame()->view()->windowToContents(webPoint);
James Su 2011/03/03 04:08:03 Same as above.
+ HitTestResult result = frame()->eventHandler()->hitTestResultAtPoint(point, false);
+ Range* range = characterRangeAtPoint(result.point());
+ if (!range)
+ return notFound;
+
+ unsigned location, length;
+ getLocationAndLengthFromRange(range, location, length);
+ return location;
+}
+
bool WebFrameImpl::executeCommand(const WebString& name)
{
ASSERT(frame());
@@ -2274,4 +2295,61 @@ void WebFrameImpl::loadJavaScriptURL(const KURL& url)
m_frame->document()->loader()->writer()->replaceDocument(scriptResult);
}
+// This function is copied from /WebKit2/WebPage/mac/WebPageMac.mm.
+Range* WebFrameImpl::characterRangeAtPoint(const IntPoint& point) const
+{
+ VisiblePosition position = frame()->visiblePositionForPoint(point);
+ if (position.isNull())
+ return NULL;
+
+ VisiblePosition previous = position.previous();
+ if (previous.isNotNull()) {
+ Range* previousCharacterRange = makeRange(previous, position).get();
+ IntRect rect = frame()->editor()->firstRectForRange(previousCharacterRange);
+ if (rect.contains(point))
+ return previousCharacterRange;
+ }
+
+ VisiblePosition next = position.next();
+ if (next.isNotNull()) {
+ Range* nextCharacterRange = makeRange(position, next).get();
+ IntRect rect = frame()->editor()->firstRectForRange(nextCharacterRange);
+ if (rect.contains(point))
+ return nextCharacterRange;
+ }
+
+ return NULL;
+}
+
+// This function is copied from /WebKit2/WebPage/WebPage.cpp.
+bool WebFrameImpl::getLocationAndLengthFromRange(Range* range, unsigned& location, unsigned& length) const
+{
+ location = notFound;
+ length = 0;
+
+ if (!range || !range->startContainer())
+ return false;
+
+ Element* selectionRoot = range->ownerDocument()->frame()->selection()->rootEditableElement();
+ Element* scope = selectionRoot ? selectionRoot : range->ownerDocument()->documentElement();
+
+ // Mouse events may cause TSM to attempt to create an NSRange for a portion of the view
+ // that is not inside the current editable region. These checks ensure we don't produce
+ // potentially invalid data when responding to such requests.
+ if (range->startContainer() != scope && !range->startContainer()->isDescendantOf(scope))
+ return false;
+ if (range->endContainer() != scope && !range->endContainer()->isDescendantOf(scope))
+ return false;
+
+ RefPtr<Range> testRange = Range::create(scope->document(), scope, 0, range->startContainer(), range->startOffset());
+ ASSERT(testRange->startContainer() == scope);
+ location = TextIterator::rangeLength(testRange.get());
+
+ ExceptionCode ec;
+ testRange->setEnd(range->endContainer(), range->endOffset(), ec);
+ ASSERT(testRange->startContainer() == scope);
+ length = TextIterator::rangeLength(testRange.get()) - location;
+ return true;
+}
+
} // namespace WebKit

Powered by Google App Engine
This is Rietveld 408576698