Commit 55cc92b5 authored by oliver's avatar oliver

WebCore:

        Reviewed by Adam and Justin.

        <rdar://problem/5141779> WebView editableDOMRangeForPoint: & moveDragCaretToPoint: returns last position in DOMText range

        Remove bridge implementation for editableDOMRangeForPoint: and moveDragCaretToPoint:. 
        Now use cross-platform code Editor::rangeForPoint and DragController::placeDragCaret instead.
        This required lifting local code from DragController.cpp into the shared methods
        Frame::visiblePositionForPoint and Frame::documentAtPoint.

        * WebCore.exp:
        * editing/Editor.cpp:
        (WebCore::Editor::rangeForPoint):
        * editing/Editor.h:
        * page/DragController.cpp:
        (WebCore::DragController::dragEnded):
        (WebCore::DragController::performDrag):
        (WebCore::DragController::dragEnteredOrUpdated):
        (WebCore::DragController::tryDocumentDrag):
        (WebCore::DragController::operationForLoad):
        (WebCore::setSelectionToDragCaret):
        (WebCore::DragController::concludeDrag):
        (WebCore::DragController::placeDragCaret):
        * page/DragController.h:
        * page/Frame.cpp:
        (WebCore::Frame::visiblePositionForPoint):
        (WebCore::Frame::documentAtPoint):
        * page/Frame.h:
        * page/mac/WebCoreFrameBridge.h:
        * page/mac/WebCoreFrameBridge.mm:

WebKit:

        Reviewed by Adam and Justin.

        <rdar://problem/5141779> WebView editableDOMRangeForPoint: & moveDragCaretToPoint: returns last position in DOMText range

        editableDOMRangeForPoint:, moveDragCaretToPoint:, and removeDragCaret now call directly into
        WebCore without relying on bridge look up through the now removed _bridgeAtPoint:.

        * WebKit.xcodeproj/project.pbxproj:
        * WebView/WebView.mm:
        (-[WebView moveDragCaretToPoint:]):
        (-[WebView removeDragCaret]):
        (-[WebView editableDOMRangeForPoint:]):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@24616 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1d2d42fe
2007-07-24 Oliver Hunt <oliver@apple.com>
Reviewed by Adam and Justin.
<rdar://problem/5141779> WebView editableDOMRangeForPoint: & moveDragCaretToPoint: returns last position in DOMText range
Remove bridge implementation for editableDOMRangeForPoint: and moveDragCaretToPoint:.
Now use cross-platform code Editor::rangeForPoint and DragController::placeDragCaret instead.
This required lifting local code from DragController.cpp into the shared methods
Frame::visiblePositionForPoint and Frame::documentAtPoint.
* WebCore.exp:
* editing/Editor.cpp:
(WebCore::Editor::rangeForPoint):
* editing/Editor.h:
* page/DragController.cpp:
(WebCore::DragController::dragEnded):
(WebCore::DragController::performDrag):
(WebCore::DragController::dragEnteredOrUpdated):
(WebCore::DragController::tryDocumentDrag):
(WebCore::DragController::operationForLoad):
(WebCore::setSelectionToDragCaret):
(WebCore::DragController::concludeDrag):
(WebCore::DragController::placeDragCaret):
* page/DragController.h:
* page/Frame.cpp:
(WebCore::Frame::visiblePositionForPoint):
(WebCore::Frame::documentAtPoint):
* page/Frame.h:
* page/mac/WebCoreFrameBridge.h:
* page/mac/WebCoreFrameBridge.mm:
2007-07-24 Sam Weinig <sam@webkit.org>
Rubber-stamped by Adam Roben.
......@@ -254,6 +254,8 @@ __ZN7WebCore14DragController10dragExitedEPNS_8DragDataE
__ZN7WebCore14DragController11dragEnteredEPNS_8DragDataE
__ZN7WebCore14DragController11dragUpdatedEPNS_8DragDataE
__ZN7WebCore14DragController11performDragEPNS_8DragDataE
__ZN7WebCore14DragController14placeDragCaretERKNS_8IntPointE
__ZN7WebCore14DragController9dragEndedEv
__ZN7WebCore14ResourceHandle12releaseProxyEv
__ZN7WebCore14ResourceLoader14cancelledErrorEv
__ZN7WebCore15BackForwardList10removeItemEPNS_11HistoryItemE
......@@ -386,6 +388,7 @@ __ZN7WebCore6Editor12canDHTMLCopyEv
__ZN7WebCore6Editor12tryDHTMLCopyEv
__ZN7WebCore6Editor13canDHTMLPasteEv
__ZN7WebCore6Editor13performDeleteEv
__ZN7WebCore6Editor13rangeForPointERKNS_8IntPointE
__ZN7WebCore6Editor13tryDHTMLPasteEv
__ZN7WebCore6Editor16pasteAsPlainTextEv
__ZN7WebCore6Editor16selectMarkedTextEv
......
......@@ -47,6 +47,7 @@
#include "EventHandler.h"
#include "EventNames.h"
#include "FocusController.h"
#include "FrameView.h"
#include "HTMLElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
......@@ -2269,5 +2270,22 @@ void Editor::markBadGrammar(const Selection& selection)
markMisspellingsOrBadGrammar(this, selection, false);
#endif
}
PassRefPtr<Range> Editor::rangeForPoint(const IntPoint& windowPoint)
{
Document* document = m_frame->documentAtPoint(windowPoint);
if (!document)
return 0;
Frame* frame = document->frame();
ASSERT(frame);
FrameView* frameView = frame->view();
if (!frameView)
return 0;
IntPoint framePoint = frameView->windowToContents(windowPoint);
Selection selection(frame->visiblePositionForPoint(framePoint));
return selection.toRange();
}
} // namespace WebCore
......@@ -208,6 +208,7 @@ public:
void setStartNewKillRingSequence(bool) { }
#endif
PassRefPtr<Range> rangeForPoint(const IntPoint& windowPoint);
private:
Frame* m_frame;
OwnPtr<DeleteButtonController> m_deleteButtonController;
......
......@@ -133,40 +133,18 @@ bool DragController::dragIsMove(SelectionController* selectionController, DragDa
&& !isCopyKeyDown();
}
static VisiblePosition visiblePositionForPoint(Frame* frame, IntPoint outerPoint)
{
ASSERT(frame);
HitTestResult result = frame->eventHandler()->hitTestResultAtPoint(outerPoint, true);
Node* node = result.innerNode();
if (!node)
return VisiblePosition();
RenderObject* renderer = node->renderer();
if (!renderer)
return VisiblePosition();
VisiblePosition visiblePos = renderer->positionForCoordinates(result.localPoint().x(), result.localPoint().y());
if (visiblePos.isNull())
visiblePos = VisiblePosition(Position(node, 0));
return visiblePos;
}
void DragController::cancelDrag()
{
m_page->dragCaretController()->clear();
}
static Document* documentAtPoint(Frame* frame, const IntPoint& point)
{
if (!frame || !frame->view())
return 0;
void DragController::dragEnded()
{
m_dragInitiator = 0;
m_didInitiateDrag = false;
m_page->dragCaretController()->clear();
}
IntPoint pt = frame->view()->windowToContents(point);
HitTestResult result = HitTestResult(pt);
if (frame->renderer())
result = frame->eventHandler()->hitTestResultAtPoint(pt, false);
return result.innerNode() ? result.innerNode()->document() : 0;
}
DragOperation DragController::dragEntered(DragData* dragData)
{
return dragEnteredOrUpdated(dragData);
......@@ -197,7 +175,7 @@ DragOperation DragController::dragUpdated(DragData* dragData)
bool DragController::performDrag(DragData* dragData)
{
ASSERT(dragData);
ASSERT(m_document == documentAtPoint(m_page->mainFrame(), dragData->clientPosition()));
ASSERT(m_document == m_page->mainFrame()->documentAtPoint(dragData->clientPosition()));
if (m_isHandlingDrag) {
ASSERT(m_dragDestinationAction & DragDestinationActionDHTML);
m_client->willPerformDragDestinationAction(DragDestinationActionDHTML, dragData);
......@@ -231,7 +209,10 @@ DragOperation DragController::dragEnteredOrUpdated(DragData* dragData)
{
ASSERT(dragData);
IntPoint windowPoint = dragData->clientPosition();
Document* newDraggingDoc = documentAtPoint(m_page->mainFrame(), windowPoint);
Document* newDraggingDoc = 0;
if (Frame* frame = m_page->mainFrame())
newDraggingDoc = frame->documentAtPoint(windowPoint);
if (m_document != newDraggingDoc) {
if (m_document)
cancelDrag();
......@@ -300,7 +281,9 @@ DragOperation DragController::tryDocumentDrag(DragData* dragData, DragDestinatio
Frame* innerFrame = element->document()->frame();
ASSERT(innerFrame);
if (!asFileInput(element)) {
Selection dragCaret(visiblePositionForPoint(m_document->frame(), point));
Selection dragCaret;
if (Frame* frame = m_document->frame())
dragCaret = frame->visiblePositionForPoint(point);
m_page->dragCaretController()->setSelection(dragCaret);
}
......@@ -320,7 +303,8 @@ DragSourceAction DragController::delegateDragSourceAction(const IntPoint& window
DragOperation DragController::operationForLoad(DragData* dragData)
{
ASSERT(dragData);
Document* doc = documentAtPoint(m_page->mainFrame(), dragData->clientPosition());
Document* doc = 0;
doc = m_page->mainFrame()->documentAtPoint(dragData->clientPosition());
if (doc && (m_didInitiateDrag || doc->isPluginDocument() || (doc->frame() && doc->frame()->editor()->clientIsEditable())))
return DragOperationNone;
return dragOperation(dragData);
......@@ -330,7 +314,7 @@ static bool setSelectionToDragCaret(Frame* frame, Selection& dragCaret, RefPtr<R
{
frame->selectionController()->setSelection(dragCaret);
if (frame->selectionController()->isNone()) {
dragCaret = visiblePositionForPoint(frame, point);
dragCaret = frame->visiblePositionForPoint(point);
frame->selectionController()->setSelection(dragCaret);
range = dragCaret.toRange();
}
......@@ -399,6 +383,11 @@ bool DragController::concludeDrag(DragData* dragData, DragDestinationAction acti
Selection dragCaret(m_page->dragCaretController()->selection());
m_page->dragCaretController()->clear();
RefPtr<Range> range = dragCaret.toRange();
// For range to be null a WebKit client must have done something bad while
// manually controlling drag behaviour
if (!range)
return false;
DocLoader* loader = range->ownerDocument()->docLoader();
loader->setAllowStaleResources(true);
if (dragIsMove(innerFrame->selectionController(), dragData) || dragCaret.isContentRichlyEditable()) {
......@@ -754,4 +743,26 @@ void DragController::doSystemDrag(DragImageRef image, const IntPoint& dragLoc, c
dragEnded();
}
// Manual drag caret manipulation
void DragController::placeDragCaret(const IntPoint& windowPoint)
{
Frame* mainFrame = m_page->mainFrame();
Document* newDraggingDoc = mainFrame->documentAtPoint(windowPoint);
if (m_document != newDraggingDoc) {
if (m_document)
cancelDrag();
m_document = newDraggingDoc;
}
if (!m_document)
return;
Frame* frame = m_document->frame();
ASSERT(frame);
FrameView* frameView = frame->view();
if (!frameView)
return;
IntPoint framePoint = frameView->windowToContents(windowPoint);
Selection dragCaret(frame->visiblePositionForPoint(framePoint));
m_page->dragCaretController()->setSelection(dragCaret);
}
}
......@@ -79,7 +79,9 @@ namespace WebCore {
DragSourceAction delegateDragSourceAction(const IntPoint& pagePoint);
bool mayStartDragAtEventLocation(const Frame*, const IntPoint& framePos);
void dragEnded() { m_dragInitiator = 0; m_didInitiateDrag = false; }
void dragEnded();
void placeDragCaret(const IntPoint&);
bool startDrag(Frame* src, Clipboard*, DragOperation srcOp, const PlatformMouseEvent& dragEvent, const IntPoint& dragOrigin, bool isDHTMLDrag);
static const IntSize& maxDragImageSize();
......
......@@ -45,6 +45,7 @@
#include "FrameLoader.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "HitTestResult.h"
#include "HTMLDocument.h"
#include "HTMLFormElement.h"
#include "HTMLFrameElementBase.h"
......@@ -1936,6 +1937,34 @@ void Frame::respondToChangedSelection(const Selection& oldSelection, bool closeT
editor()->respondToChangedSelection(oldSelection);
}
VisiblePosition Frame::visiblePositionForPoint(const IntPoint& framePoint)
{
HitTestResult result = eventHandler()->hitTestResultAtPoint(framePoint, true);
Node* node = result.innerNode();
if (!node)
return VisiblePosition();
RenderObject* renderer = node->renderer();
if (!renderer)
return VisiblePosition();
VisiblePosition visiblePos = renderer->positionForCoordinates(result.localPoint().x(), result.localPoint().y());
if (visiblePos.isNull())
visiblePos = VisiblePosition(Position(node, 0));
return visiblePos;
}
Document* Frame::documentAtPoint(const IntPoint& point)
{
if (!view())
return 0;
IntPoint pt = view()->windowToContents(point);
HitTestResult result = HitTestResult(pt);
if (renderer())
result = eventHandler()->hitTestResultAtPoint(pt, false);
return result.innerNode() ? result.innerNode()->document() : 0;
}
FramePrivate::FramePrivate(Page* page, Frame* parent, Frame* thisFrame, HTMLFrameOwnerElement* ownerElement,
FrameLoaderClient* frameLoaderClient)
: m_page(page)
......
......@@ -33,6 +33,7 @@
#include "DragImage.h"
#include "RenderLayer.h"
#include "TextGranularity.h"
#include "VisiblePosition.h"
#include <wtf/unicode/Unicode.h>
#include <wtf/Forward.h>
#include <wtf/Vector.h>
......@@ -347,7 +348,9 @@ public:
String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
String searchForLabelsBeforeElement(const Vector<String>& labels, Element*);
String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
Document* documentAtPoint(const IntPoint& windowPoint);
#if PLATFORM(MAC)
// === undecided, may or may not belong here
......
......@@ -216,10 +216,8 @@ typedef enum ObjectElementType {
- (void)setSelectionToDragCaret;
- (void)moveSelectionToDragCaret:(DOMDocumentFragment *)selectionFragment smartMove:(BOOL)smartMove;
- (void)moveDragCaretToPoint:(NSPoint)point;
- (DOMRange *)dragCaretDOMRange;
- (BOOL)isDragCaretRichlyEditable;
- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point;
- (DOMRange *)characterRangeAtPoint:(NSPoint)point;
- (void)deleteKeyPressedWithSmartDelete:(BOOL)smartDelete granularity:(WebCore::TextGranularity)granularity;
......
......@@ -1119,12 +1119,6 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
return visiblePos;
}
- (void)moveDragCaretToPoint:(NSPoint)point
{
Selection dragCaret([self _visiblePositionForPoint:point]);
m_frame->dragCaretController()->setSelection(dragCaret);
}
- (DOMRange *)dragCaretDOMRange
{
return [DOMRange _wrapRange:m_frame->dragCaretController()->toRange().get()];
......@@ -1135,12 +1129,6 @@ static HTMLFormElement *formElementFromDOMElement(DOMElement *element)
return m_frame->dragCaretController()->isContentRichlyEditable();
}
- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
{
VisiblePosition position = [self _visiblePositionForPoint:point];
return position.isNull() ? nil : [DOMRange _wrapRange:Selection(position).toRange().get()];
}
- (DOMRange *)characterRangeAtPoint:(NSPoint)point
{
VisiblePosition position = [self _visiblePositionForPoint:point];
......
2007-07-24 Oliver Hunt <oliver@apple.com>
Reviewed by Adam and Justin.
<rdar://problem/5141779> WebView editableDOMRangeForPoint: & moveDragCaretToPoint: returns last position in DOMText range
editableDOMRangeForPoint:, moveDragCaretToPoint:, and removeDragCaret now call directly into
WebCore without relying on bridge look up through the now removed _bridgeAtPoint:.
* WebKit.xcodeproj/project.pbxproj:
* WebView/WebView.mm:
(-[WebView moveDragCaretToPoint:]):
(-[WebView removeDragCaret]):
(-[WebView editableDOMRangeForPoint:]):
2007-07-24 Kevin Decker <kdecker@apple.com>
Reviewed by Anders.
......
......@@ -1319,6 +1319,7 @@
0867D690FE84028FC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 149C283208902B0F008A9EFC /* Build configuration list for PBXProject "WebKit" */;
compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 1;
knownRegions = (
English,
......@@ -1658,6 +1659,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 1C904FD50BA9DD0F0081E9D0 /* Base.xcconfig */;
buildSettings = {
LINKER_DISPLAYS_MANGLED_NAMES = YES;
};
name = Production;
};
......
......@@ -335,7 +335,6 @@ static int pluginDatabaseClientCount = 0;
- (WebFrameBridge *)_bridgeForSelectedOrMainFrame;
- (BOOL)_isLoading;
- (WebFrameView *)_frameViewAtWindowPoint:(NSPoint)point;
- (WebFrameBridge *)_bridgeAtPoint:(NSPoint)point;
- (WebFrame *)_focusedFrame;
+ (void)_preflightSpellChecker;
- (BOOL)_continuousCheckingAllowed;
......@@ -2537,14 +2536,14 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
- (void)moveDragCaretToPoint:(NSPoint)point
{
[[[self mainFrame] _bridge] moveDragCaretToPoint:[self convertPoint:point toView:[[[self mainFrame] frameView] documentView]]];
if (Page* page = core(self))
page->dragController()->placeDragCaret(IntPoint([self convertPoint:point toView:nil]));
}
- (void)removeDragCaret
{
if (!_private->page)
return;
_private->page->dragCaretController()->clear();
if (Page* page = core(self))
page->dragController()->dragEnded();
}
- (void)setMainFrameURL:(NSString *)URLString
......@@ -3181,8 +3180,10 @@ static WebFrame *incrementFrame(WebFrame *curr, BOOL forward, BOOL wrapFlag)
- (DOMRange *)editableDOMRangeForPoint:(NSPoint)point
{
WebFrameBridge *bridge = [self _bridgeAtPoint:point];
return [bridge editableDOMRangeForPoint:[self convertPoint:point toView:[[[bridge webFrame] frameView] documentView]]];
Page* page = core(self);
if (!page)
return nil;
return kit(page->mainFrame()->editor()->rangeForPoint(IntPoint([self convertPoint:point toView:nil])).get());
}
- (BOOL)_shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag;
......@@ -3562,11 +3563,6 @@ static WebFrameView *containingFrameView(NSView *view)
return frameView;
}
- (WebFrameBridge *)_bridgeAtPoint:(NSPoint)point
{
return [[[self _frameViewAtWindowPoint:[self convertPoint:point toView:nil]] webFrame] _bridge];
}
+ (void)_preflightSpellCheckerNow:(id)sender
{
[[NSSpellChecker sharedSpellChecker] _preflightChosenSpellServer];
......
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