Changeset 83320 in webkit


Ignore:
Timestamp:
Apr 8, 2011 11:53:21 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

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:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r83301 r83320  
     12011-04-08  Varun Jain  <varunjain@chromium.org>
     2
     3        Reviewed by Darin Fisher.
     4
     5        Need to extend WebKit chromium API to access text selection
     6        https://bugs.webkit.org/show_bug.cgi?id=57888
     7
     8        *  Source/WebKit/chromium/public/WebFrame.h:
     9        *  Source/WebKit/chromium/public/WebWidget.h:
     10        *  Source/WebKit/chromium/src/WebFrameImpl.cpp:
     11        *  Source/WebKit/chromium/src/WebFrameImpl.h:
     12        *  Source/WebKit/chromium/src/WebPopupMenuImpl.h:
     13        *  Source/WebKit/chromium/src/WebViewImpl.cpp:
     14        *  Source/WebKit/chromium/src/WebViewImpl.h:
     15        *  Source/WebKit/chromium/tests/PopupMenuTest.cpp:
     16
    1172011-04-08  Jon Lee  <jonlee@apple.com>
    218
  • trunk/Source/WebKit/chromium/public/WebFrame.h

    r83021 r83320  
    6868struct WebConsoleMessage;
    6969struct WebFindOptions;
     70struct WebPoint;
    7071struct WebRect;
    7172struct WebScriptSource;
     
    408409    // there is ranged selection.
    409410    virtual bool selectWordAroundCaret() = 0;
     411
     412    virtual void selectRange(const WebPoint& start, const WebPoint& end) = 0;
    410413
    411414
  • trunk/Source/WebKit/chromium/public/WebWidget.h

    r76278 r83320  
    4242class WebInputEvent;
    4343class WebString;
     44struct WebPoint;
    4445struct WebRect;
    4546struct WebSize;
     
    127128    virtual WebRect caretOrSelectionBounds() = 0;
    128129
     130    // Returns the start and end point for the current selection, aligned to the
     131    // bottom of the selected line.
     132    // FIXME: make this pure virtual after all downstream classes have
     133    // implemented it.
     134    virtual bool selectionRange(WebPoint& start, WebPoint& end) const
     135    {
     136        return false;
     137    }
     138
    129139    // Changes the text direction of the selected input node.
    130140    virtual void setTextDirection(WebTextDirection) = 0;
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.cpp

    r83021 r83320  
    9191#include "FrameTree.h"
    9292#include "FrameView.h"
     93#include "HitTestResult.h"
    9394#include "HTMLCollection.h"
    9495#include "HTMLFormElement.h"
     
    107108#include "PrintContext.h"
    108109#include "RenderFrame.h"
     110#include "RenderLayer.h"
    109111#include "RenderObject.h"
    110112#include "RenderTreeAsText.h"
     
    141143#include "WebPlugin.h"
    142144#include "WebPluginContainerImpl.h"
     145#include "WebPoint.h"
    143146#include "WebRange.h"
    144147#include "WebRect.h"
     
    13041307    selectWordAroundPosition(frame(), controller->selection().visibleStart());
    13051308    return true;
     1309}
     1310
     1311void WebFrameImpl::selectRange(const WebPoint& start, const WebPoint& end)
     1312{
     1313    VisibleSelection selection(visiblePositionForWindowPoint(start),
     1314                               visiblePositionForWindowPoint(end));
     1315
     1316    if (frame()->selection()->shouldChangeSelection(selection))
     1317        frame()->selection()->setSelection(selection, CharacterGranularity,
     1318                                           MakeNonDirectionalSelection);
     1319}
     1320
     1321VisiblePosition WebFrameImpl::visiblePositionForWindowPoint(const WebPoint& point)
     1322{
     1323    HitTestRequest::HitTestRequestType hitType = HitTestRequest::MouseMove;
     1324    hitType |= HitTestRequest::ReadOnly;
     1325    hitType |= HitTestRequest::Active;
     1326    HitTestRequest request(hitType);
     1327    FrameView* view = frame()->view();
     1328    HitTestResult result(view->windowToContents(
     1329        view->convertFromContainingWindow(IntPoint(point.x, point.y))));
     1330
     1331    frame()->document()->renderView()->layer()->hitTest(request, result);
     1332
     1333    // Matching the logic in MouseEventWithHitTestResults::targetNode()
     1334    Node* node = result.innerNode();
     1335    if (!node)
     1336        return VisiblePosition();
     1337    Element* element = node->parentElement();
     1338    if (!node->inDocument() && element && element->inDocument())
     1339        node = element;
     1340
     1341    return node->renderer()->positionForPoint(result.localPoint());
    13061342}
    13071343
  • trunk/Source/WebKit/chromium/src/WebFrameImpl.h

    r81913 r83320  
    158158    virtual WebString selectionAsMarkup() const;
    159159    virtual bool selectWordAroundCaret();
     160    virtual void selectRange(const WebPoint& start, const WebPoint& end);
    160161    virtual int printBegin(const WebSize& pageSize,
    161162                           const WebNode& constrainToNode,
     
    327328    void loadJavaScriptURL(const WebCore::KURL&);
    328329
     330    // Returns a hit-tested VisiblePosition for the given point
     331    WebCore::VisiblePosition visiblePositionForWindowPoint(const WebPoint&);
     332
    329333    FrameLoaderClientImpl m_frameLoaderClient;
    330334
  • trunk/Source/WebKit/chromium/src/WebPopupMenuImpl.h

    r76278 r83320  
    7979    virtual WebTextInputType textInputType();
    8080    virtual WebRect caretOrSelectionBounds();
     81    virtual bool selectionRange(WebPoint& start, WebPoint& end) const { return false; }
    8182    virtual void setTextDirection(WebTextDirection direction);
    8283    virtual bool isAcceleratedCompositingActive() const { return false; }
  • trunk/Source/WebKit/chromium/src/WebViewImpl.cpp

    r82886 r83320  
    14551455}
    14561456
     1457bool WebViewImpl::selectionRange(WebPoint& start, WebPoint& end) const
     1458{
     1459    const Frame* frame = focusedWebCoreFrame();
     1460    if (!frame)
     1461        return false;
     1462    RefPtr<Range> selectedRange = frame->selection()->toNormalizedRange();
     1463    RefPtr<Range> range(Range::create(selectedRange->startContainer()->document(),
     1464                                      selectedRange->startContainer(),
     1465                                      selectedRange->startOffset(),
     1466                                      selectedRange->startContainer(),
     1467                                      selectedRange->startOffset()));
     1468
     1469    IntRect rect = frame->editor()->firstRectForRange(range.get());
     1470    start.x = rect.x();
     1471    start.y = rect.y() + rect.height() - 1;
     1472
     1473    range = Range::create(selectedRange->endContainer()->document(),
     1474                          selectedRange->endContainer(),
     1475                          selectedRange->endOffset(),
     1476                          selectedRange->endContainer(),
     1477                          selectedRange->endOffset());
     1478
     1479    rect = frame->editor()->firstRectForRange(range.get());
     1480    end.x = rect.x() + rect.width() - 1;
     1481    end.y = rect.y() + rect.height() - 1;
     1482
     1483    start = frame->view()->contentsToWindow(start);
     1484    end = frame->view()->contentsToWindow(end);
     1485    return true;
     1486}
     1487
    14571488void WebViewImpl::setTextDirection(WebTextDirection direction)
    14581489{
  • trunk/Source/WebKit/chromium/src/WebViewImpl.h

    r82481 r83320  
    110110    virtual WebTextInputType textInputType();
    111111    virtual WebRect caretOrSelectionBounds();
     112    virtual bool selectionRange(WebPoint& start, WebPoint& end) const;
    112113    virtual void setTextDirection(WebTextDirection direction);
    113114    virtual bool isAcceleratedCompositingActive() const;
  • trunk/Source/WebKit/chromium/tests/PopupMenuTest.cpp

    r82481 r83320  
    143143    virtual WebTextInputType textInputType() { return WebKit::WebTextInputTypeNone; }
    144144    virtual WebRect caretOrSelectionBounds() { return WebRect(); }
     145    virtual bool selectionRange(WebPoint& start, WebPoint& end) const { return false; }
    145146    virtual void setTextDirection(WebTextDirection) { }
    146147};
Note: See TracChangeset for help on using the changeset viewer.