2011-04-08 Varun Jain <varunjain@chromium.org>

        Reviewed by Darin Fisher.

        Need to extend WebKit chromium API to access text selection
        https://bugs.webkit.org/show_bug.cgi?id=57888

        *  Source/WebKit/chromium/public/WebFrame.h:
        *  Source/WebKit/chromium/public/WebWidget.h:
        *  Source/WebKit/chromium/src/WebFrameImpl.cpp:
        *  Source/WebKit/chromium/src/WebFrameImpl.h:
        *  Source/WebKit/chromium/src/WebPopupMenuImpl.h:
        *  Source/WebKit/chromium/src/WebViewImpl.cpp:
        *  Source/WebKit/chromium/src/WebViewImpl.h:
        *  Source/WebKit/chromium/tests/PopupMenuTest.cpp:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@83320 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 55cb70aa
2011-04-08 Varun Jain <varunjain@chromium.org>
Reviewed by Darin Fisher.
Need to extend WebKit chromium API to access text selection
https://bugs.webkit.org/show_bug.cgi?id=57888
* Source/WebKit/chromium/public/WebFrame.h:
* Source/WebKit/chromium/public/WebWidget.h:
* Source/WebKit/chromium/src/WebFrameImpl.cpp:
* Source/WebKit/chromium/src/WebFrameImpl.h:
* Source/WebKit/chromium/src/WebPopupMenuImpl.h:
* Source/WebKit/chromium/src/WebViewImpl.cpp:
* Source/WebKit/chromium/src/WebViewImpl.h:
* Source/WebKit/chromium/tests/PopupMenuTest.cpp:
2011-04-08 Jon Lee <jonlee@apple.com>
Reviewed by David Levin.
......
......@@ -67,6 +67,7 @@ class WebURLRequest;
class WebView;
struct WebConsoleMessage;
struct WebFindOptions;
struct WebPoint;
struct WebRect;
struct WebScriptSource;
struct WebSize;
......@@ -408,6 +409,8 @@ public:
// there is ranged selection.
virtual bool selectWordAroundCaret() = 0;
virtual void selectRange(const WebPoint& start, const WebPoint& end) = 0;
// Printing ------------------------------------------------------------
......
......@@ -41,6 +41,7 @@ namespace WebKit {
class WebInputEvent;
class WebString;
struct WebPoint;
struct WebRect;
struct WebSize;
template <typename T> class WebVector;
......@@ -126,6 +127,15 @@ public:
// will be returned if a selection range is available.
virtual WebRect caretOrSelectionBounds() = 0;
// Returns the start and end point for the current selection, aligned to the
// bottom of the selected line.
// FIXME: make this pure virtual after all downstream classes have
// implemented it.
virtual bool selectionRange(WebPoint& start, WebPoint& end) const
{
return false;
}
// Changes the text direction of the selected input node.
virtual void setTextDirection(WebTextDirection) = 0;
......
......@@ -90,6 +90,7 @@
#include "FrameLoader.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HitTestResult.h"
#include "HTMLCollection.h"
#include "HTMLFormElement.h"
#include "HTMLFrameOwnerElement.h"
......@@ -106,6 +107,7 @@
#include "PluginDocument.h"
#include "PrintContext.h"
#include "RenderFrame.h"
#include "RenderLayer.h"
#include "RenderObject.h"
#include "RenderTreeAsText.h"
#include "RenderView.h"
......@@ -140,6 +142,7 @@
#include "WebPerformance.h"
#include "WebPlugin.h"
#include "WebPluginContainerImpl.h"
#include "WebPoint.h"
#include "WebRange.h"
#include "WebRect.h"
#include "WebScriptSource.h"
......@@ -1305,6 +1308,39 @@ bool WebFrameImpl::selectWordAroundCaret()
return true;
}
void WebFrameImpl::selectRange(const WebPoint& start, const WebPoint& end)
{
VisibleSelection selection(visiblePositionForWindowPoint(start),
visiblePositionForWindowPoint(end));
if (frame()->selection()->shouldChangeSelection(selection))
frame()->selection()->setSelection(selection, CharacterGranularity,
MakeNonDirectionalSelection);
}
VisiblePosition WebFrameImpl::visiblePositionForWindowPoint(const WebPoint& point)
{
HitTestRequest::HitTestRequestType hitType = HitTestRequest::MouseMove;
hitType |= HitTestRequest::ReadOnly;
hitType |= HitTestRequest::Active;
HitTestRequest request(hitType);
FrameView* view = frame()->view();
HitTestResult result(view->windowToContents(
view->convertFromContainingWindow(IntPoint(point.x, point.y))));
frame()->document()->renderView()->layer()->hitTest(request, result);
// Matching the logic in MouseEventWithHitTestResults::targetNode()
Node* node = result.innerNode();
if (!node)
return VisiblePosition();
Element* element = node->parentElement();
if (!node->inDocument() && element && element->inDocument())
node = element;
return node->renderer()->positionForPoint(result.localPoint());
}
int WebFrameImpl::printBegin(const WebSize& pageSize,
const WebNode& constrainToNode,
int printerDPI,
......
......@@ -157,6 +157,7 @@ public:
virtual WebString selectionAsText() const;
virtual WebString selectionAsMarkup() const;
virtual bool selectWordAroundCaret();
virtual void selectRange(const WebPoint& start, const WebPoint& end);
virtual int printBegin(const WebSize& pageSize,
const WebNode& constrainToNode,
int printerDPI,
......@@ -326,6 +327,9 @@ private:
void loadJavaScriptURL(const WebCore::KURL&);
// Returns a hit-tested VisiblePosition for the given point
WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
FrameLoaderClientImpl m_frameLoaderClient;
WebFrameClient* m_client;
......
......@@ -78,6 +78,7 @@ public:
virtual bool confirmComposition(const WebString& text);
virtual WebTextInputType textInputType();
virtual WebRect caretOrSelectionBounds();
virtual bool selectionRange(WebPoint& start, WebPoint& end) const { return false; }
virtual void setTextDirection(WebTextDirection direction);
virtual bool isAcceleratedCompositingActive() const { return false; }
......
......@@ -1454,6 +1454,37 @@ WebRect WebViewImpl::caretOrSelectionBounds()
return rect;
}
bool WebViewImpl::selectionRange(WebPoint& start, WebPoint& end) const
{
const Frame* frame = focusedWebCoreFrame();
if (!frame)
return false;
RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange();
RefPtr<Range> range(Range::create(selectedRange->startContainer()->document(),
selectedRange->startContainer(),
selectedRange->startOffset(),
selectedRange->startContainer(),
selectedRange->startOffset()));
IntRect rect = frame->editor()->firstRectForRange(range.get());
start.x = rect.x();
start.y = rect.y() + rect.height() - 1;
range = Range::create(selectedRange->endContainer()->document(),
selectedRange->endContainer(),
selectedRange->endOffset(),
selectedRange->endContainer(),
selectedRange->endOffset());
rect = frame->editor()->firstRectForRange(range.get());
end.x = rect.x() + rect.width() - 1;
end.y = rect.y() + rect.height() - 1;
start = frame->view()->contentsToWindow(start);
end = frame->view()->contentsToWindow(end);
return true;
}
void WebViewImpl::setTextDirection(WebTextDirection direction)
{
// The Editor::setBaseWritingDirection() function checks if we can change
......
......@@ -109,6 +109,7 @@ public:
virtual bool confirmComposition(const WebString& text);
virtual WebTextInputType textInputType();
virtual WebRect caretOrSelectionBounds();
virtual bool selectionRange(WebPoint& start, WebPoint& end) const;
virtual void setTextDirection(WebTextDirection direction);
virtual bool isAcceleratedCompositingActive() const;
......
......@@ -142,6 +142,7 @@ public:
virtual bool confirmComposition(const WebString& text) { return true; }
virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; }
virtual WebRect caretOrSelectionBounds() { return WebRect(); }
virtual bool selectionRange(WebPoint& start, WebPoint& end) const { return false; }
virtual void setTextDirection(WebTextDirection) { }
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment