Changeset 19579 in webkit


Ignore:
Timestamp:
Feb 12, 2007, 11:05:07 AM (18 years ago)
Author:
darin
Message:

WebCore:

Reviewed by Oliver.

This area still needs work because keypress events are being sent for all the
events before they go to the input methods, and it seems that this is not
compatible with what other browsers do and with what sites assume. That's covered
by this bug:

http://bugs.webkit.org/show_bug.cgi?id=10871
<rdar://problem/4823129> REGRESSION: IME key events different in nightly (10871)

which is still open.

  • bindings/objc/ExceptionHandlers.h: Remove selectRange helper that doesn't really belong here, and also isn't needed since the callers don't want to raise ObjC exceptions.
  • bindings/objc/ExceptionHandlers.mm: Ditto. Also removed unneeded external globals that aren't exported anyway and unneeded includes.
  • bridge/EditorClient.h: Added Mac-specific function, markedTextAbandoned. Long term this might move into platform instead, but it's fine to have it on the client for now as long as it doesn't cause trouble for platforms other than Mac.
  • dom/EventTargetNode.cpp: (WebCore::EventTargetNode::defaultEventHandler): Since all the event handling code in this function is intended to run on the node itself, not parent nodes, check and do nothing if this event is bubbling up from another node. Added code to call a function on EventHandler for default handling of text input events.
  • dom/KeyboardEvent.h:
  • dom/KeyboardEvent.cpp: (WebCore::findKeyboardEvent): Added. Just like the findUIEventWithKeyState function, but specific to keyboard events.
  • dom/TextEvent.h: Added isLineBreak and isBackTab flags so that we can carry additional information about what a text input event is trying to do, but still go through the DOM event machinery.
  • dom/TextEvent.cpp: Ditto.
  • editing/Editor.h:
  • editing/Editor.cpp: (WebCore::Editor::handleKeyPress): Removed unneeded check of isCaretOrRange, since isContentEditable already checks that. (WebCore::Editor::canEdit): Ditto. (WebCore::Editor::canEditRichly): Ditto. (WebCore::Editor::canPaste): Changed to call canEdit for brevity. (WebCore::Editor::replaceSelectionWithText): Changed to take a const String&. (WebCore::Editor::shouldInsertText): Ditto. (WebCore::hasEditableSelection): Removed unneeded check of isCaretOrRange, since isContentEditable already checks that. (WebCore::Editor::Editor): Initialize the new m_ignoreMarkedTextSelectionChange flag. Moved here from WebHTMLView. (WebCore::Editor::insertText): Moved most of the code from -[WebHTMLView insertText:] here, since this needs to be done in response to a text input event and we don't want to go back over the WebKit side for that. (WebCore::Editor::insertLineBreak): Added. Moved here from -[WebHTMLView insertLineBreak:] for the same reason -- needs to be done in response to text input events. (WebCore::Editor::insertParagraphSeparator): Ditto. (WebCore::Editor::selectMarkedText): Added. Used by insertText. (WebCore::Editor::discardMarkedText): Added. Used by insertText. (WebCore::Editor::unmarkText): Added. Used by insertText.
  • editing/mac/EditorMac.mm: (WebCore::Editor::unmarkText): Added. Used by insertText.
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::canHaveSelection): Changed to use isTextField to avoid repeating the switch statement. (WebCore::HTMLInputElement::selectionStart): Ditto. (WebCore::HTMLInputElement::selectionEnd): Ditto. (WebCore::HTMLInputElement::setSelectionStart): Ditto. (WebCore::HTMLInputElement::setSelectionEnd): Ditto. (WebCore::HTMLInputElement::select): Ditto. (WebCore::HTMLInputElement::setSelectionRange): Ditto. (WebCore::HTMLInputElement::createRenderer): Resorted cases alphaebtically. (WebCore::HTMLInputElement::defaultEventHandler): Added code to make hitting return cause the form to be submitted when it comes through as a text input event. This is now the normal case on Macintosh, because enter key presses normally turn into this. In addition, change the other event handling to run only after trying the base defaultEventHandler. That makes the key handling done in EventTargetNode take precedence over the event handling here for editable text fields, which is what we want. This gets rid of the need for the hack where we check inputManagerHasMarkedText and suppress the handling of the enter key.
  • page/EventHandler.h: Removed unneeded includes. Moved EventHandlerDragState down into the private part of the class. Changed sendContextMenuEvent to take a const&. Added new handleTextInputEvent and defaultTextInputEventHandler functions. Made eventLoopHandleMouseUp and eventLoopHandleMouseDragged private. Added private defaultTabEventHandler function.
  • page/EventHandler.cpp: (WebCore::EventHandler::sendContextMenuEvent): Changed parameter to be a const&. (WebCore::EventHandler::defaultKeyboardEventHandler): Rearranged things so that the key bindings handling in handleKeyPress comes before special tab event handling. In cases where the tab turns into text to insert, we now handle it in the text input event handler. (WebCore::EventHandler::handleTextInputEvent): Added. Creates and dispatches a text input event. (WebCore::EventHandler::defaultTextInputEventHandler): Added. Inserts text, but has special cases for the tab and newline character cases. (WebCore::EventHandler::defaultTabEventHandler): Added. Shared by the tab-handling code in the keyboard event and text input event handlers.
  • page/mac/EventHandlerMac.mm: Tweak formatting, remove some unused functions.
  • page/FocusController.h: Removed unnneded includes and forwards, and added an overload of advanceFocus that takes a FocusDirection parameter.
  • page/FocusController.cpp: (WebCore::FocusController::advanceFocus): Changed to allow a 0 for the event pointer. Also added a version where the direction is passed explicitly, to be used for cases where we want to tab backward even if the event doesn't have a shift modifier key set.
  • platform/graphics/svg/SVGImageEmptyClients.h: Updated for change to EditorClient. This should really probably just use 0 for the EditorClient.
  • WebCore.exp: Update both for newly used and no-longer-used entry points.
  • page/mac/WebCoreFrameBridge.h:
  • page/mac/WebCoreFrameBridge.mm: Removed two unused methods.

WebKit:

Reviewed by Oliver.

  • WebCoreSupport/WebEditorClient.h:
  • WebCoreSupport/WebEditorClient.mm: (WebEditorClient::markedTextAbandoned): Added.
  • WebView/WebHTMLView.mm: (-[WebHTMLView menuForEvent:]): Added explicit constructor needed now that the function takes a const&. (-[WebHTMLView becomeFirstResponder]): Removed fake event code, no longer needed since advanceFocus now works fine with 0 for a DOM event. (-[WebHTMLView _expandSelectionToGranularity:]): Changed to use the normal selection controller function instead of selectRange. (-[WebHTMLView insertTab:]): Changed to call bottleneck that receives the DOM event. (-[WebHTMLView insertBacktab:]): Ditto. (-[WebHTMLView insertNewline:]): Ditto. (-[WebHTMLView insertLineBreak:]): Ditto. (-[WebHTMLView insertParagraphSeparator:]): Ditto. (-[WebHTMLView insertNewlineIgnoringFieldEditor:]): Ditto. (-[WebHTMLView insertTabIgnoringFieldEditor:]): Ditto. (-[WebHTMLView yank:]): Updated to call Editor directly since the insertText code now works via a text input event which is not what we want for paste-like things such as yank. (-[WebHTMLView yankAndSelect:]): Ditto. (-[WebHTMLView selectToMark:]): Changed to use the normal selection controller function instead of selectRange, which also allows us to remove the ObjC exception handling code. (-[WebHTMLView swapWithMark:]): Ditto. (-[WebHTMLView transpose:]): Ditto. (-[WebHTMLView unmarkText]): Since this is one of the calls back from the input manager, added code to set the "event was handled" flag. Moved the actual work into the Editor class in WebCore and just call that from here. (-[WebHTMLView _selectRangeInMarkedText:]): Changed to use the normal selection controller function instead of selectRange. (-[WebHTMLView setMarkedText:selectedRange:]): Since this is one of the calls back from the input manager, added code to set the "event was handled" flag. Also changed the ignoreMarkedTextSelectionChange to use the flag over on the WebCore side, since we moved it there and to call selectMarkedText over on the WebCore side too. (-[WebHTMLView doCommandBySelector:]): Added special cases for newline and tab selectors so that the event is passed along. These selectors are special because they are ones that turn into text input events. (-[WebHTMLView _discardMarkedText]): Moved the body of this function into the Editor class in WebCore and just call that from here. (-[WebHTMLView insertText:]): Added code to send a text input event instead of calling the editor to do text insertion. The insertion is then done in the default handler for the text input event. (-[WebHTMLView _insertNewlineWithEvent:isLineBreak:]): Added. Sends a text input event. (-[WebHTMLView _insertTabWithEvent:isBackTab:]): Ditto. (-[WebHTMLView _updateSelectionForInputManager]): Changed to use the ignoreMarkedTextSelectionChange flag in Editor now that the one here is gone.
  • WebView/WebHTMLViewInternal.h: Remove ignoreMarkedTextSelectionChange field.
  • WebView/WebView.mm: (-[WebView setSelectedDOMRange:affinity:]): Changed to use the normal selection controller function instead of selectRange.
Location:
trunk
Files:
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r19578 r19579  
     12007-02-12  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=12677
     6          <rdar://problem/4759563> REGRESSION: Return key is always sent when you confirm
     7          a clause in kotoeri (12677)
     8
     9        - fix http://bugs.webkit.org/show_bug.cgi?id=12596
     10          <rdar://problem/4794346> REGRESSION: Tab key shifts form field focus instead of
     11          navigating prediction window (12596)
     12
     13        - fix http://bugs.webkit.org/show_bug.cgi?id=10010
     14          <rdar://problem/4822935> REGRESSION: Pressing Return with unconfirmed text in
     15          Hangul inserts carriage return (10010)
     16
     17        - fix http://bugs.webkit.org/show_bug.cgi?id=12531
     18          <rdar://problem/4975126> REGRESSION: Inline text input types repeated keys in
     19          latest nightly (r19336) (12531)
     20
     21        - fix http://bugs.webkit.org/show_bug.cgi?id=12539
     22          <rdar://problem/4975130> REGRESSION: Pressing Backspace while in inline input
     23          area moves to the previous page in history (12539)
     24
     25        This area still needs work because keypress events are being sent for all the
     26        events before they go to the input methods, and it seems that this is not
     27        compatible with what other browsers do and with what sites assume. That's covered
     28        by this bug:
     29
     30            http://bugs.webkit.org/show_bug.cgi?id=10871
     31            <rdar://problem/4823129> REGRESSION: IME key events different in nightly (10871)
     32
     33        which is still open.
     34
     35        * bindings/objc/ExceptionHandlers.h: Remove selectRange helper that doesn't really
     36        belong here, and also isn't needed since the callers don't want to raise ObjC
     37        exceptions.
     38        * bindings/objc/ExceptionHandlers.mm: Ditto. Also removed unneeded external globals
     39        that aren't exported anyway and unneeded includes.
     40
     41        * bridge/EditorClient.h: Added Mac-specific function, markedTextAbandoned. Long term
     42        this might move into platform instead, but it's fine to have it on the client for now
     43        as long as it doesn't cause trouble for platforms other than Mac.
     44
     45        * dom/EventTargetNode.cpp: (WebCore::EventTargetNode::defaultEventHandler): Since
     46        all the event handling code in this function is intended to run on the node itself,
     47        not parent nodes, check and do nothing if this event is bubbling up from another
     48        node. Added code to call a function on EventHandler for default handling of text
     49        input events.
     50
     51        * dom/KeyboardEvent.h:
     52        * dom/KeyboardEvent.cpp: (WebCore::findKeyboardEvent): Added. Just like the
     53        findUIEventWithKeyState function, but specific to keyboard events.
     54
     55        * dom/TextEvent.h: Added isLineBreak and isBackTab flags so that we can carry
     56        additional information about what a text input event is trying to do, but still
     57        go through the DOM event machinery.
     58        * dom/TextEvent.cpp: Ditto.
     59
     60        * editing/Editor.h:
     61        * editing/Editor.cpp:
     62        (WebCore::Editor::handleKeyPress): Removed unneeded check of isCaretOrRange, since
     63        isContentEditable already checks that.
     64        (WebCore::Editor::canEdit): Ditto.
     65        (WebCore::Editor::canEditRichly): Ditto.
     66        (WebCore::Editor::canPaste): Changed to call canEdit for brevity.
     67        (WebCore::Editor::replaceSelectionWithText): Changed to take a const String&.
     68        (WebCore::Editor::shouldInsertText): Ditto.
     69        (WebCore::hasEditableSelection): Removed unneeded check of isCaretOrRange, since
     70        isContentEditable already checks that.
     71        (WebCore::Editor::Editor): Initialize the new m_ignoreMarkedTextSelectionChange
     72        flag. Moved here from WebHTMLView.
     73        (WebCore::Editor::insertText): Moved most of the code from -[WebHTMLView insertText:]
     74        here, since this needs to be done in response to a text input event and we don't want
     75        to go back over the WebKit side for that.
     76        (WebCore::Editor::insertLineBreak): Added. Moved here from -[WebHTMLView insertLineBreak:]
     77        for the same reason -- needs to be done in response to text input events.
     78        (WebCore::Editor::insertParagraphSeparator): Ditto.
     79        (WebCore::Editor::selectMarkedText): Added. Used by insertText.
     80        (WebCore::Editor::discardMarkedText): Added. Used by insertText.
     81        (WebCore::Editor::unmarkText): Added. Used by insertText.
     82        * editing/mac/EditorMac.mm:
     83        (WebCore::Editor::unmarkText): Added. Used by insertText.
     84
     85        * html/HTMLInputElement.cpp:
     86        (WebCore::HTMLInputElement::canHaveSelection): Changed to use isTextField to avoid repeating
     87        the switch statement.
     88        (WebCore::HTMLInputElement::selectionStart): Ditto.
     89        (WebCore::HTMLInputElement::selectionEnd): Ditto.
     90        (WebCore::HTMLInputElement::setSelectionStart): Ditto.
     91        (WebCore::HTMLInputElement::setSelectionEnd): Ditto.
     92        (WebCore::HTMLInputElement::select): Ditto.
     93        (WebCore::HTMLInputElement::setSelectionRange): Ditto.
     94        (WebCore::HTMLInputElement::createRenderer): Resorted cases alphaebtically.
     95        (WebCore::HTMLInputElement::defaultEventHandler): Added code to make hitting return cause the
     96        form to be submitted when it comes through as a text input event. This is now the normal case
     97        on Macintosh, because enter key presses normally turn into this. In addition, change the other
     98        event handling to run only after trying the base defaultEventHandler. That makes the key
     99        handling done in EventTargetNode take precedence over the event handling here for editable text
     100        fields, which is what we want. This gets rid of the need for the hack where we check
     101        inputManagerHasMarkedText and suppress the handling of the enter key.
     102
     103        * page/EventHandler.h: Removed unneeded includes. Moved EventHandlerDragState down into the
     104        private part of the class. Changed sendContextMenuEvent to take a const&. Added new
     105        handleTextInputEvent and defaultTextInputEventHandler functions. Made eventLoopHandleMouseUp
     106        and eventLoopHandleMouseDragged private. Added private defaultTabEventHandler function.
     107        * page/EventHandler.cpp:
     108        (WebCore::EventHandler::sendContextMenuEvent): Changed parameter to be a const&.
     109        (WebCore::EventHandler::defaultKeyboardEventHandler): Rearranged things so that the key bindings
     110        handling in handleKeyPress comes before special tab event handling. In cases where the tab turns
     111        into text to insert, we now handle it in the text input event handler.
     112        (WebCore::EventHandler::handleTextInputEvent): Added. Creates and dispatches a text input event.
     113        (WebCore::EventHandler::defaultTextInputEventHandler): Added. Inserts text, but has special cases
     114        for the tab and newline character cases.
     115        (WebCore::EventHandler::defaultTabEventHandler): Added. Shared by the tab-handling code in
     116        the keyboard event and text input event handlers.
     117        * page/mac/EventHandlerMac.mm: Tweak formatting, remove some unused functions.
     118
     119        * page/FocusController.h: Removed unnneded includes and forwards, and added an overload of
     120        advanceFocus that takes a FocusDirection parameter.
     121        * page/FocusController.cpp: (WebCore::FocusController::advanceFocus): Changed to allow a 0 for
     122        the event pointer. Also added a version where the direction is passed explicitly, to be used
     123        for cases where we want to tab backward even if the event doesn't have a shift modifier key set.
     124
     125        * platform/graphics/svg/SVGImageEmptyClients.h: Updated for change to EditorClient.
     126        This should really probably just use 0 for the EditorClient.
     127
     128        * WebCore.exp: Update both for newly used and no-longer-used entry points.
     129
     130        * page/mac/WebCoreFrameBridge.h:
     131        * page/mac/WebCoreFrameBridge.mm: Removed two unused methods.
     132
    11332007-02-12  Antti Koivisto  <antti@apple.com>
    2134
  • trunk/WebCore/WebCore.exp

    r19538 r19579  
    128128__ZN7WebCore10EventNames12keydownEventE
    129129__ZN7WebCore10MouseEventC1ERKNS_12AtomicStringEbbPNS_9DOMWindowEiiiiibbbbtPNS_15EventTargetNodeEPNS_9ClipboardEb
     130__ZN7WebCore10StringImpl7replaceEtt
    130131__ZN7WebCore10StringImplD1Ev
    131132__ZN7WebCore11ContextMenu22setPlatformDescriptionEP14NSMutableArray
     
    191192__ZN7WebCore11RenderLayer18gAlignCenterAlwaysE
    192193__ZN7WebCore11globalPointERK8_NSPointP8NSWindow
    193 __ZN7WebCore11selectRangeEPNS_19SelectionControllerEPNS_5RangeENS_9EAffinityEb
    194194__ZN7WebCore11toUserSpaceERK7_NSRectP8NSWindow
    195195__ZN7WebCore12AtomicString3addEPKc
     
    198198__ZN7WebCore12EventHandler10wheelEventEP7NSEvent
    199199__ZN7WebCore12EventHandler12mouseDraggedEP7NSEvent
     200__ZN7WebCore12EventHandler20handleTextInputEventERKNS_6StringEPNS_5EventEbb
    200201__ZN7WebCore12EventHandler20hitTestResultAtPointERKNS_8IntPointEb
    201 __ZN7WebCore12EventHandler20sendContextMenuEventENS_18PlatformMouseEventE
     202__ZN7WebCore12EventHandler20sendContextMenuEventERKNS_18PlatformMouseEventE
    202203__ZN7WebCore12EventHandler7mouseUpEP7NSEvent
    203204__ZN7WebCore12EventHandler8keyEventEP7NSEvent
     
    290291__ZN7WebCore16NavigationActionC1Ev
    291292__ZN7WebCore18PlatformMouseEventC1EP7NSEvent
     293__ZN7WebCore19SelectionController16setSelectedRangeEPNS_5RangeENS_9EAffinityEbRi
    292294__ZN7WebCore19SelectionController5clearEv
    293295__ZN7WebCore19SelectionController9selectAllEv
     
    332334__ZN7WebCore6Editor10applyStyleEPNS_19CSSStyleDeclarationENS_10EditActionE
    333335__ZN7WebCore6Editor10insertTextERKNS_6StringEbPNS_5EventE
     336__ZN7WebCore6Editor10unmarkTextEv
    334337__ZN7WebCore6Editor11canDHTMLCutEv
    335338__ZN7WebCore6Editor11deleteRangeEPNS_5RangeEbbbNS_18EditorDeleteActionENS_15TextGranularityE
     
    341344__ZN7WebCore6Editor13performDeleteEv
    342345__ZN7WebCore6Editor13tryDHTMLPasteEv
     346__ZN7WebCore6Editor16selectMarkedTextEv
     347__ZN7WebCore6Editor17discardMarkedTextEv
    343348__ZN7WebCore6Editor19deleteWithDirectionENS_19SelectionController10EDirectionENS_15TextGranularityEbb
    344349__ZN7WebCore6Editor21applyStyleToSelectionEPNS_19CSSStyleDeclarationENS_10EditActionE
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r19548 r19579  
    1115311153                        isa = PBXProject;
    1115411154                        buildConfigurationList = 149C284308902B11008A9EFC /* Build configuration list for PBXProject "WebCore" */;
    11155                         compatibilityVersion = "Xcode 2.4";
    1115611155                        hasScannedForEncodings = 1;
    1115711156                        knownRegions = (
     
    1116811167                        projectDirPath = "";
    1116911168                        projectRoot = "";
    11170                         shouldCheckCompatibility = 1;
    1117111169                        targets = (
    1117211170                                93F198A508245E59001E9ABC /* WebCore */,
  • trunk/WebCore/bindings/objc/ExceptionHandlers.h

    r19503 r19579  
    11/*
    2  * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define ExceptionHandlers_h
    2828
    29 #include "TextAffinity.h"
    3029#include <JavaScriptCore/Assertions.h>
    3130
     
    5554    }
    5655
    57     void selectRange(SelectionController*, Range*, EAffinity, bool closeTyping);
    58 
    5956} // namespace WebCore
    6057
  • trunk/WebCore/bindings/objc/ExceptionHandlers.mm

    r17455 r19579  
    11/*
    2  * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#include "ExceptionHandlers.h"
    2828
    29 #include "Document.h"
    30 #include "Node.h"
    31 #include "SelectionController.h"
    32 #include "PlatformString.h"
     29#include "Event.h"
    3330#include "RangeException.h"
    34 #include "Event.h"
    3531#include "SVGException.h"
    3632#include "XPathEvaluator.h"
    37 
    38 NSString * const DOMException = @"DOMException";
    39 NSString * const DOMRangeException = @"DOMRangeException";
    40 NSString * const DOMEventException = @"DOMEventException";
    41 #ifdef SVG_SUPPORT
    42 NSString * const DOMSVGException = @"DOMSVGException";
    43 #endif // SVG_SUPPORT
    44 #ifdef XPATH_SUPPORT
    45 NSString * const DOMXPathException = @"DOMXPathException";
    46 #endif // XPATH_SUPPORT
    4733
    4834namespace WebCore {
     
    5238    ASSERT(ec);
    5339
    54     NSString *name = ::DOMException;
     40    NSString *name = @"DOMException";
    5541
    5642    int code = ec;
    5743    if (ec >= RangeExceptionOffset && ec <= RangeExceptionMax) {
    58         name = DOMRangeException;
     44        name = @"DOMRangeException";
    5945        code -= RangeExceptionOffset;
    6046    } else if (ec >= EventExceptionOffset && ec <= EventExceptionMax) {
    61         name = DOMEventException;
     47        name = @"DOMEventException";
    6248        code -= EventExceptionOffset;
    6349#ifdef SVG_SUPPORT
    6450    } else if (ec >= SVGExceptionOffset && ec <= SVGExceptionMax) {
    65         name = DOMSVGException;
     51        name = @"DOMSVGException";
    6652        code -= SVGExceptionOffset;
    67 #endif // SVG_SUPPORT
     53#endif
    6854#ifdef XPATH_SUPPORT
    6955    } else if (ec >= XPathExceptionOffset && ec <= XPathExceptionMax) {
    70         name = DOMXPathException;
     56        name = @"DOMXPathException";
    7157        code -= XPathExceptionOffset;
    72 #endif // XPATH_SUPPORT
     58#endif
    7359    }
    7460
     
    7965}
    8066
    81 void selectRange(SelectionController* selectionController, Range* range, EAffinity affinity, bool closeTyping)
    82 {
    83     ExceptionCode ec = 0;
    84     selectionController->setSelectedRange(range, affinity, closeTyping, ec);
    85     raiseOnDOMError(ec);
    86 }
    87 
    8867} // namespace WebCore
  • trunk/WebCore/bridge/EditorClient.h

    r19237 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929#include "EditorInsertAction.h"
    3030#include <wtf/Forward.h>
     31
    3132#if PLATFORM(MAC)
    3233class NSArray;
     
    4041class CSSStyleDeclaration;
    4142class EditCommand;
    42 class EventTargetNode;
    4343class Frame;
    4444class HTMLElement;
     
    6868    virtual bool shouldEndEditing(Range*) = 0;
    6969    virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) = 0;
    70 //  virtual bool shouldInsertNode(Node*, Range* replacingRange, WebViewInsertAction) = 0;
    7170    virtual bool shouldInsertText(String, Range*, EditorInsertAction) = 0;
    7271//  virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, NSSelectionAffinity, bool stillSelecting) = 0;
     
    7473//  virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle) = 0;
    7574//  virtual bool doCommandBySelector(SEL selector) = 0;
    76 //
     75
    7776    virtual void didBeginEditing() = 0;
    7877    virtual void respondToChangedContents() = 0;
     
    8079    virtual void didWriteSelectionToPasteboard() = 0;
    8180    virtual void didSetSelectionTypesForPasteboard() = 0;
    82 //  virtual void webViewDidChangeTypingStyle:(NSNotification *)notification = 0;
    83 //  virtual void webViewDidChangeSelection:(NSNotification *)notification = 0;
    84 //  virtual NSUndoManager* undoManagerForWebView:(WebView *)webView = 0;
     81//  virtual void didChangeTypingStyle:(NSNotification *)notification = 0;
     82//  virtual void didChangeSelection:(NSNotification *)notification = 0;
     83//  virtual NSUndoManager* undoManager:(WebView *)webView = 0;
    8584   
    8685    virtual void registerCommandForUndo(PassRefPtr<EditCommand>) = 0;
     
    9796
    9897#if PLATFORM(MAC)
     98    virtual void markedTextAbandoned(Frame*) = 0;
     99
    99100    // FIXME: This should become SelectionController::toWebArchive()
    100101    virtual NSData* dataForArchivedSelection(Frame*) = 0;
  • trunk/WebCore/dom/EventTargetNode.cpp

    r19378 r19579  
    11/*
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    64 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    7  * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
     5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    86 *
    97 * This library is free software; you can redistribute it and/or
     
    4644#include "PlatformWheelEvent.h"
    4745#include "RegisteredEventListener.h"
     46#include "TextEvent.h"
    4847#include "UIEvent.h"
    4948#include "WheelEvent.h"
     
    572571void EventTargetNode::defaultEventHandler(Event* event)
    573572{
     573    if (event->target() != this)
     574        return;
    574575    const AtomicString& eventType = event->type();
    575576    if (eventType == keypressEvent) {
     
    584585            if (Page* page = frame->page())
    585586                page->contextMenuController()->handleContextMenuEvent(event);
     587    } else if (eventType == textInputEvent) {
     588        if (event->isTextEvent())
     589            if (Frame* frame = document()->frame())
     590                frame->eventHandler()->defaultTextInputEventHandler(static_cast<TextEvent*>(event));
    586591    }
    587592}
  • trunk/WebCore/dom/KeyboardEvent.cpp

    r17064 r19579  
    11/**
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
    53 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
    64 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
    7  * Copyright (C) 2003, 2005, 2006 Apple Computer, Inc.
     5 * Copyright (C) 2003, 2005, 2006, 2007 Apple Inc. All rights reserved.
    86 *
    97 * This library is free software; you can redistribute it and/or
     
    2220 * Boston, MA 02111-1307, USA.
    2321 */
     22
    2423#include "config.h"
    2524#include "KeyboardEvent.h"
     
    127126}
    128127
     128KeyboardEvent* findKeyboardEvent(Event* event)
     129{
     130    for (Event* e = event; e; e = e->underlyingEvent())
     131        if (e->isKeyboardEvent())
     132            return static_cast<KeyboardEvent*>(e);
     133    return 0;
     134}
     135
    129136} // namespace WebCore
  • trunk/WebCore/dom/KeyboardEvent.h

    r17064 r19579  
    55 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
    66 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
    7  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
     7 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    88 *
    99 * This library is free software; you can redistribute it and/or
     
    4545        KeyboardEvent();
    4646        KeyboardEvent(const PlatformKeyboardEvent&, AbstractView*);
    47         KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
     47        KeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
    4848                      const String& keyIdentifier, unsigned keyLocation,
    4949                      bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey);
    5050        virtual ~KeyboardEvent();
    5151   
    52         void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView* view,
     52        void initKeyboardEvent(const AtomicString& type, bool canBubble, bool cancelable, AbstractView*,
    5353                               const String& keyIdentifier, unsigned keyLocation,
    5454                               bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false);
     
    7676    };
    7777
     78    KeyboardEvent* findKeyboardEvent(Event*);
     79
    7880} // namespace WebCore
    7981
  • trunk/WebCore/dom/TextEvent.cpp

    r19538 r19579  
    3535
    3636TextEvent::TextEvent()
     37    : m_isLineBreak(false)
     38    , m_isBackTab(false)
    3739{
    3840}
     
    4143    : UIEvent(textInputEvent, true, true, view, 0)
    4244    , m_data(data)
     45    , m_isLineBreak(false)
     46    , m_isBackTab(false)
    4347{
    4448}
  • trunk/WebCore/dom/TextEvent.h

    r19538 r19579  
    4444        virtual bool isTextEvent() const;
    4545
     46        // If true, any newline characters in the text are line breaks only, not paragraph separators.
     47        bool isLineBreak() const { return m_isLineBreak; }
     48        void setIsLineBreak(bool isLineBreak) { m_isLineBreak = isLineBreak; }
     49
     50        // If true, any tab characters in the text are backtabs.
     51        bool isBackTab() const { return m_isBackTab; }
     52        void setIsBackTab(bool isBackTab) { m_isBackTab = isBackTab; }
     53
    4654    private:
    4755        String m_data;
     56        bool m_isLineBreak;
     57        bool m_isBackTab;
    4858    };
    4959
  • trunk/WebCore/editing/Editor.cpp

    r19463 r19579  
    11/*
    2  * Copyright (C) 2006, 2007 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    103103void Editor::handleKeyPress(KeyboardEvent* event)
    104104{
    105     if (EditorClient* c = client()) {
    106         Selection selection = selectionForEvent(m_frame, event);
    107         if (selection.isCaretOrRange() && selection.isContentEditable())
     105    if (EditorClient* c = client())
     106        if (selectionForEvent(m_frame, event).isContentEditable())
    108107            c->handleKeyPress(event);
    109     }
    110108}
    111109
    112110bool Editor::canEdit() const
    113111{
    114     SelectionController* selectionController = m_frame->selectionController();
    115     return selectionController->isCaretOrRange() && selectionController->isContentEditable();
     112    return m_frame->selectionController()->isContentEditable();
    116113}
    117114
    118115bool Editor::canEditRichly() const
    119116{
    120     SelectionController* selectionController = m_frame->selectionController();
    121     return canEdit() && selectionController->isContentRichlyEditable();
     117    return m_frame->selectionController()->isContentRichlyEditable();
    122118}
    123119
     
    155151bool Editor::canPaste() const
    156152{
    157     SelectionController* selectionController = m_frame->selectionController();
    158     return selectionController->isCaretOrRange() && selectionController->isContentEditable();
     153    return canEdit();
    159154}
    160155
     
    333328}
    334329
    335 void Editor::replaceSelectionWithText(String text, bool selectReplacement, bool smartReplace)
     330void Editor::replaceSelectionWithText(const String& text, bool selectReplacement, bool smartReplace)
    336331{
    337332    replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), text), selectReplacement, smartReplace, true);
     
    393388}
    394389
    395 bool Editor::shouldInsertText(String text, Range* range, EditorInsertAction action) const
     390bool Editor::shouldInsertText(const String& text, Range* range, EditorInsertAction action) const
    396391{
    397392    if (client())
     
    11031098static bool hasEditableSelection(Frame* frame)
    11041099{
    1105     return frame->selectionController()->isCaretOrRange() && frame->selectionController()->isContentEditable();
     1100    return frame->selectionController()->isContentEditable();
    11061101}
    11071102
     
    12141209    : m_frame(frame)
    12151210    , m_deleteButtonController(new DeleteButtonController(frame))
     1211    , m_ignoreMarkedTextSelectionChange(false)
    12161212{
    12171213}
     
    12421238bool Editor::insertText(const String& text, bool selectInsertedText, Event* triggeringEvent)
    12431239{
     1240    if (text.isEmpty())
     1241        return false;
     1242
     1243    RefPtr<Range> range = m_frame->markedTextRange();
     1244    if (!range) {
     1245        Selection selection = selectionForEvent(m_frame, triggeringEvent);
     1246        if (!selection.isContentEditable())
     1247            return false;
     1248        range = selection.toRange();
     1249    }
     1250
     1251    if (!shouldInsertText(text, range.get(), EditorInsertActionTyped)) {
     1252        discardMarkedText();
     1253        return true;
     1254    }
     1255
     1256    setIgnoreMarkedTextSelectionChange(true);
     1257
     1258    // If we had marked text, replace that instead of the selection/caret.
     1259    selectMarkedText();
     1260
    12441261    // Get the selection to use for the event that triggered this insertText.
    12451262    // If the event handler changed the selection, we may want to use a different selection
    12461263    // that is contained in the event target.
    12471264    Selection selection = selectionForEvent(m_frame, triggeringEvent);
    1248     if (!selection.isCaretOrRange() || !selection.isContentEditable())
     1265    if (selection.isContentEditable()) {
     1266        if (Node* selectionStart = selection.start().node()) {
     1267            RefPtr<Document> document = selectionStart->document();
     1268           
     1269            // Insert the text
     1270            TypingCommand::insertText(document.get(), text, selection, selectInsertedText);
     1271
     1272            // Reveal the current selection
     1273            if (Frame* editedFrame = document->frame())
     1274                if (Page* page = editedFrame->page())
     1275                    page->focusController()->focusedOrMainFrame()->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     1276        }
     1277    }
     1278
     1279    setIgnoreMarkedTextSelectionChange(false);
     1280
     1281    // Inserting unmarks any marked text.
     1282    unmarkText();
     1283
     1284    return true;
     1285}
     1286
     1287bool Editor::insertLineBreak()
     1288{
     1289    if (!canEdit())
    12491290        return false;
    1250     Node* selectionStart = selection.start().node();
    1251     if (!selectionStart)
     1291
     1292    if (!shouldInsertText("\n", m_frame->selectionController()->toRange().get(), EditorInsertActionTyped))
     1293        return true;
     1294
     1295    TypingCommand::insertLineBreak(m_frame->document());
     1296    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     1297    return true;
     1298}
     1299
     1300bool Editor::insertParagraphSeparator()
     1301{
     1302    if (!canEdit())
    12521303        return false;
    1253     RefPtr<Document> document = selectionStart->document();
    1254    
    1255     // Insert the text
    1256     TypingCommand::insertText(document.get(), text, selection, selectInsertedText);
    1257 
    1258     // Reveal the current selection
    1259     if (Frame* editedFrame = document->frame())
    1260         if (Page* page = editedFrame->page())
    1261             page->focusController()->focusedOrMainFrame()->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
     1304
     1305    if (!canEditRichly())
     1306        return insertLineBreak();
     1307
     1308    if (!shouldInsertText("\n", m_frame->selectionController()->toRange().get(), EditorInsertActionTyped))
     1309        return true;
     1310
     1311    TypingCommand::insertParagraphSeparator(m_frame->document());
     1312    m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
    12621313    return true;
    12631314}
     
    14391490}
    14401491
     1492void Editor::selectMarkedText()
     1493{
     1494    Range* range = m_frame->markedTextRange();
     1495    if (!range)
     1496        return;
     1497    ExceptionCode ec = 0;
     1498    m_frame->selectionController()->setSelectedRange(m_frame->markedTextRange(), DOWNSTREAM, false, ec);
     1499}
     1500
     1501void Editor::discardMarkedText()
     1502{
     1503    if (!m_frame->markedTextRange())
     1504        return;
     1505
     1506    setIgnoreMarkedTextSelectionChange(true);
     1507
     1508    selectMarkedText();
     1509    unmarkText();
     1510#if PLATFORM(MAC)
     1511    if (EditorClient* c = client())
     1512        c->markedTextAbandoned(m_frame);
     1513#endif
     1514    deleteSelectionWithSmartDelete(false);
     1515
     1516    setIgnoreMarkedTextSelectionChange(false);
     1517}
     1518
     1519#if !PLATFORM(MAC)
     1520void Editor::unmarkText()
     1521{
     1522}
     1523#endif
     1524
    14411525} // namespace WebCore
  • trunk/WebCore/editing/Editor.h

    r19237 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    9595
    9696    bool shouldInsertFragment(PassRefPtr<DocumentFragment> fragment, PassRefPtr<Range> replacingDOMRange, EditorInsertAction givenAction);
    97     bool shouldInsertText(String, Range*, EditorInsertAction) const;
     97    bool shouldInsertText(const String&, Range*, EditorInsertAction) const;
    9898    bool shouldShowDeleteInterface(HTMLElement*) const;
    9999    bool shouldDeleteRange(Range*) const;
     
    140140   
    141141    bool insertText(const String&, bool selectInsertedText, Event* triggeringEvent = 0);
     142    bool insertLineBreak();
     143    bool insertParagraphSeparator();
    142144   
    143145    bool isContinuousSpellCheckingEnabled();
     
    158160    bool spellingPanelIsShowing();
    159161
    160     bool shouldBeginEditing(Range* range);
    161     bool shouldEndEditing(Range* range);
     162    bool shouldBeginEditing(Range*);
     163    bool shouldEndEditing(Range*);
    162164
    163165    void clearUndoRedoOperations();
     
    180182    bool smartInsertDeleteEnabled();
    181183   
     184    void selectMarkedText();
     185    void unmarkText();
     186    void discardMarkedText();
     187
     188    bool ignoreMarkedTextSelectionChange() const { return m_ignoreMarkedTextSelectionChange; }
     189    void setIgnoreMarkedTextSelectionChange(bool ignore) { m_ignoreMarkedTextSelectionChange = ignore; }
     190
    182191#if PLATFORM(MAC)
    183192    NSString* userVisibleString(NSURL*);
     
    190199    RefPtr<EditCommand> m_lastEditCommand;
    191200    RefPtr<Node> m_removedAnchor;
     201    bool m_ignoreMarkedTextSelectionChange;
    192202
    193203    bool canDeleteRange(Range*) const;
    194204    bool canSmartCopyOrDelete();
    195     bool canSmartReplaceWithPasteboard(Pasteboard* pasteboard);
    196     PassRefPtr<Clipboard> newGeneralClipboard(ClipboardAccessPolicy policy);
     205    bool canSmartReplaceWithPasteboard(Pasteboard*);
     206    PassRefPtr<Clipboard> newGeneralClipboard(ClipboardAccessPolicy);
    197207    PassRefPtr<Range> selectedRange();
    198208    void pasteAsPlainTextWithPasteboard(Pasteboard*);
    199209    void pasteWithPasteboard(Pasteboard*, bool allowPlainText);
    200     void replaceSelectionWithFragment(PassRefPtr<DocumentFragment> fragment, bool selectReplacement, bool smartReplace, bool matchStyle);
    201     void replaceSelectionWithText(String text, bool selectReplacement, bool smartReplace);
     210    void replaceSelectionWithFragment(PassRefPtr<DocumentFragment>, bool selectReplacement, bool smartReplace, bool matchStyle);
     211    void replaceSelectionWithText(const String&, bool selectReplacement, bool smartReplace);
    202212    void writeSelectionToPasteboard(Pasteboard*);
    203213
  • trunk/WebCore/editing/mac/EditorMac.mm

    r19049 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3434#import "Element.h"
    3535#import "ExceptionHandlers.h"
     36#import "FrameMac.h"
    3637#import "PlatformString.h"
    3738#import "Selection.h"
     
    646647}
    647648
     649void Editor::unmarkText()
     650{
     651    Mac(m_frame)->setMarkedTextRange(0, nil, nil);
     652}
     653
    648654} // namespace WebCore
  • trunk/WebCore/html/HTMLInputElement.cpp

    r19418 r19579  
    11/*
    2  * This file is part of the DOM implementation for KDE.
    3  *
    42 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    53 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    64 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    7  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc.
     5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    86 *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
    97 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
     
    5250#include "SelectionController.h"
    5351#include "TextBreakIterator.h"
     52#include "TextEvent.h"
    5453
    5554using namespace std;
     
    453452bool HTMLInputElement::canHaveSelection() const
    454453{
    455     switch (inputType()) {
    456         case BUTTON:
    457         case CHECKBOX:
    458         case FILE:
    459         case HIDDEN:
    460         case IMAGE:
    461         case RADIO:
    462         case RANGE:
    463         case RESET:
    464         case SUBMIT:
    465             return false;
    466         case PASSWORD:
    467         case SEARCH:
    468         case ISINDEX:
    469         case TEXT:
    470             return true;
    471     }
    472     return false;
     454    return isTextField();
    473455}
    474456
    475457int HTMLInputElement::selectionStart() const
    476458{
     459    if (!isTextField())
     460        return 0;
     461    if (document()->focusedNode() != this && cachedSelStart != -1)
     462        return cachedSelStart;
    477463    if (!renderer())
    478464        return 0;
    479    
    480     switch (inputType()) {
    481         case BUTTON:
    482         case CHECKBOX:
    483         case FILE:
    484         case HIDDEN:
    485         case IMAGE:
    486         case RADIO:
    487         case RANGE:
    488         case RESET:
    489         case SUBMIT:
    490             break;
    491         case ISINDEX:
    492         case PASSWORD:
    493         case SEARCH:
    494         case TEXT:
    495             if (document()->focusedNode() != this && cachedSelStart != -1)
    496                 return cachedSelStart;
    497             return static_cast<RenderTextControl*>(renderer())->selectionStart();
    498     }
    499     return 0;
     465    return static_cast<RenderTextControl*>(renderer())->selectionStart();
    500466}
    501467
    502468int HTMLInputElement::selectionEnd() const
    503469{
     470    if (!isTextField())
     471        return 0;
     472    if (document()->focusedNode() != this && cachedSelEnd != -1)
     473        return cachedSelEnd;
    504474    if (!renderer())
    505475        return 0;
    506 
    507     switch (inputType()) {
    508         case BUTTON:
    509         case CHECKBOX:
    510         case FILE:
    511         case HIDDEN:
    512         case IMAGE:
    513         case RADIO:
    514         case RANGE:
    515         case RESET:
    516         case SUBMIT:
    517             break;
    518         case ISINDEX:
    519         case PASSWORD:
    520         case TEXT:
    521         case SEARCH:
    522             if (document()->focusedNode() != this && cachedSelEnd != -1)
    523                 return cachedSelEnd;
    524             return static_cast<RenderTextControl*>(renderer())->selectionEnd();
    525     }
    526     return 0;
     476    return static_cast<RenderTextControl*>(renderer())->selectionEnd();
    527477}
    528478
    529479void HTMLInputElement::setSelectionStart(int start)
    530480{
     481    if (!isTextField())
     482        return;
    531483    if (!renderer())
    532484        return;
    533 
    534     switch (inputType()) {
    535         case BUTTON:
    536         case CHECKBOX:
    537         case FILE:
    538         case HIDDEN:
    539         case IMAGE:
    540         case RADIO:
    541         case RANGE:
    542         case RESET:
    543         case SUBMIT:
    544             break;
    545         case ISINDEX:
    546         case PASSWORD:
    547         case TEXT:
    548         case SEARCH:
    549             static_cast<RenderTextControl*>(renderer())->setSelectionStart(start);
    550             break;
    551     }
     485    static_cast<RenderTextControl*>(renderer())->setSelectionStart(start);
    552486}
    553487
    554488void HTMLInputElement::setSelectionEnd(int end)
    555489{
     490    if (!isTextField())
     491        return;
    556492    if (!renderer())
    557493        return;
    558    
    559     switch (inputType()) {
    560         case BUTTON:
    561         case CHECKBOX:
    562         case FILE:
    563         case HIDDEN:
    564         case IMAGE:
    565         case RADIO:
    566         case RANGE:
    567         case RESET:
    568         case SUBMIT:
    569             break;
    570         case ISINDEX:
    571         case PASSWORD:
    572         case TEXT:
    573         case SEARCH:
    574             static_cast<RenderTextControl*>(renderer())->setSelectionEnd(end);
    575             break;
    576     }
     494    static_cast<RenderTextControl*>(renderer())->setSelectionEnd(end);
    577495}
    578496
    579497void HTMLInputElement::select()
    580498{
     499    if (!isTextField())
     500        return;
    581501    if (!renderer())
    582502        return;
    583 
    584     switch (inputType()) {
    585         case BUTTON:
    586         case CHECKBOX:
    587         case HIDDEN:
    588         case IMAGE:
    589         case RADIO:
    590         case RANGE:
    591         case RESET:
    592         case SUBMIT:
    593         case FILE:
    594             break;
    595         case ISINDEX:
    596         case PASSWORD:
    597         case TEXT:
    598         case SEARCH:
    599             static_cast<RenderTextControl*>(renderer())->select();
    600             break;
    601     }
     503    static_cast<RenderTextControl*>(renderer())->select();
    602504}
    603505
    604506void HTMLInputElement::setSelectionRange(int start, int end)
    605507{
     508    if (!isTextField())
     509        return;
    606510    if (!renderer())
    607511        return;
    608    
    609     switch (inputType()) {
    610         case BUTTON:
    611         case CHECKBOX:
    612         case FILE:
    613         case HIDDEN:
    614         case IMAGE:
    615         case RADIO:
    616         case RANGE:
    617         case RESET:
    618         case SUBMIT:
    619             break;
    620         case ISINDEX:
    621         case PASSWORD:
    622         case TEXT:
    623         case SEARCH:
    624             static_cast<RenderTextControl*>(renderer())->setSelectionRange(start, end);
    625             break;
    626     }
     512    static_cast<RenderTextControl*>(renderer())->setSelectionRange(start, end);
    627513}
    628514
     
    826712        case ISINDEX:
    827713        case PASSWORD:
     714        case SEARCH:
    828715        case TEXT:
    829         case SEARCH:
    830716            return new (arena) RenderTextControl(this, false);             
    831717    }
     
    12131099void HTMLInputElement::defaultEventHandler(Event* evt)
    12141100{
     1101    bool clickDefaultFormButton = false;
     1102
     1103    if (isTextField() && evt->type() == textInputEvent && evt->isTextEvent() && static_cast<TextEvent*>(evt)->data() == "\n")
     1104        clickDefaultFormButton = true;
     1105
    12151106    if (inputType() == IMAGE && evt->isMouseEvent() && evt->type() == clickEvent) {
    12161107        // record the mouse position for when we get the DOMActivate event
     
    12251116            renderer()->absolutePosition(offsetX, offsetY);
    12261117            xPos = me->pageX() - offsetX;
     1118            // FIXME: Why is yPos a short?
    12271119            yPos = me->pageY() - offsetY;
    12281120        }
     1121    }
     1122
     1123    if (!clickDefaultFormButton) {
     1124        HTMLGenericFormElement::defaultEventHandler(evt);
     1125        if (evt->defaultHandled())
     1126            return;
    12291127    }
    12301128
     
    12411139            else {
    12421140                m_activeSubmit = true;
     1141                // FIXME: Would be cleaner to get xPos and yPos out of the underlying mouse
     1142                // event (if any) here instead of relying on the variables set above when
     1143                // processing the click event. Even better, appendFormData could pass the
     1144                // event in, and then we could get rid of xPos and yPos altogether!
    12431145                if (!form()->prepareSubmit(evt)) {
    12441146                    xPos = 0;
     
    12551157    if (evt->type() == keypressEvent && evt->isKeyboardEvent()) {
    12561158        bool clickElement = false;
    1257         bool clickDefaultFormButton = false;
    1258    
     1159
    12591160        if (isTextField() && document()->frame()
    12601161                && document()->frame()->doTextFieldCommandFromEvent(this, static_cast<KeyboardEvent*>(evt))) {
     
    12631164        }
    12641165
    1265         String key = static_cast<KeyboardEvent *>(evt)->keyIdentifier();
     1166        String key = static_cast<KeyboardEvent*>(evt)->keyIdentifier();
    12661167
    12671168        if (key == "U+000020") {
     
    12981199                case CHECKBOX:
    12991200                case HIDDEN:
     1201                case ISINDEX:
     1202                case PASSWORD:
    13001203                case RANGE:
     1204                case SEARCH:
     1205                case TEXT:
    13011206                    // Simulate mouse click on the default form button for enter for these types of elements.
    13021207                    clickDefaultFormButton = true;
    1303                 case ISINDEX:
    1304                 case PASSWORD:
    1305                 case SEARCH:
    1306                 case TEXT:
    1307                     if (!document()->frame()->eventHandler()->inputManagerHasMarkedText())
    1308                         // Simulate mouse click on the default form button for enter for these types of elements.
    1309                         clickDefaultFormButton = true;
    13101208                    break;
    13111209                case FILE:
     
    13591257            dispatchSimulatedClick(evt);
    13601258            evt->setDefaultHandled();
    1361         } else if (clickDefaultFormButton) {
    1362             if (isSearchField()) {
    1363                 addSearchResult();
    1364                 onSearch();
    1365             }
    1366             blur();
    1367             // Form may never have been present, or may have been destroyed by the blur event.
    1368             if (form())
    1369                 form()->submitClick(evt);
    1370             evt->setDefaultHandled();
    1371         }
     1259            return;
     1260        }       
     1261    }
     1262
     1263    if (clickDefaultFormButton) {
     1264        if (isSearchField()) {
     1265            addSearchResult();
     1266            onSearch();
     1267        }
     1268        blur();
     1269        // Form may never have been present, or may have been destroyed by the blur event.
     1270        if (form())
     1271            form()->submitClick(evt);
     1272        evt->setDefaultHandled();
     1273        return;
    13721274    }
    13731275
     
    13991301            slider->forwardEvent(evt);
    14001302    }
    1401 
    1402     if (!evt->defaultHandled())
    1403         HTMLGenericFormElement::defaultEventHandler(evt);
    14041303}
    14051304
  • trunk/WebCore/page/EventHandler.cpp

    r19500 r19579  
    5656#include "SelectionController.h"
    5757#include "Settings.h"
     58#include "TextEvent.h"
    5859
    5960#ifdef SVG_SUPPORT
     
    11701171}
    11711172
    1172 bool EventHandler::sendContextMenuEvent(PlatformMouseEvent event)
     1173bool EventHandler::sendContextMenuEvent(const PlatformMouseEvent& event)
    11731174{
    11741175    Document* doc = m_frame->document();
     
    12151216    return true;
    12161217}
    1217 
    1218 #if !PLATFORM(MAC)
    1219 bool EventHandler::inputManagerHasMarkedText() const
    1220 {
    1221     return false;
    1222 }
    1223 #endif
    12241218
    12251219void EventHandler::setResizingFrameSet(HTMLFrameSetElement* frameSet)
     
    12891283{
    12901284    if (event->type() == keypressEvent) {
    1291         if (Page* page = event->target()->toNode()->document()->page())
    1292             if (page->tabKeyCyclesThroughElements() && event->keyIdentifier() == "U+000009")
    1293                 if (page->focusController()->advanceFocus(event)) {
    1294                     event->setDefaultHandled();
    1295                     return;
    1296                 }
    12971285        m_frame->editor()->handleKeyPress(event);
    1298     }
    1299 }
    1300    
     1286        if (event->defaultHandled())
     1287            return;
     1288        if (event->keyIdentifier() == "U+000009")
     1289            defaultTabEventHandler(event, false);
     1290    }
     1291}
     1292
    13011293bool EventHandler::dragHysteresisExceeded(const FloatPoint& floatDragViewportLocation) const
    13021294{
     
    13591351}
    13601352
    1361 }
     1353bool EventHandler::handleTextInputEvent(const String& text, Event* underlyingEvent,
     1354    bool isLineBreak, bool isBackTab)
     1355{
     1356    if (!m_frame)
     1357        return false;
     1358    EventTargetNode* target = eventTargetNodeForDocument(m_frame->document());
     1359    if (!target)
     1360        return false;
     1361    RefPtr<TextEvent> event = new TextEvent(m_frame->domWindow(), text);
     1362    event->setUnderlyingEvent(underlyingEvent);
     1363    event->setIsLineBreak(isLineBreak);
     1364    event->setIsBackTab(isBackTab);
     1365    ExceptionCode ec;
     1366    return target->dispatchEvent(event.release(), ec, true);
     1367}
     1368
     1369void EventHandler::defaultTextInputEventHandler(TextEvent* event)
     1370{
     1371    String data = event->data();
     1372    if (data == "\t")
     1373        defaultTabEventHandler(event, event->isBackTab());
     1374    else if (data == "\n") {
     1375        if (event->isLineBreak()) {
     1376            if (m_frame->editor()->insertLineBreak())
     1377                event->setDefaultHandled();
     1378        } else {
     1379            if (m_frame->editor()->insertParagraphSeparator())
     1380                event->setDefaultHandled();
     1381        }
     1382    } else {
     1383        if (m_frame->editor()->insertText(data, false, event))
     1384            event->setDefaultHandled();
     1385    }
     1386}
     1387
     1388void EventHandler::defaultTabEventHandler(Event* event, bool isBackTab)
     1389{
     1390    Page* page = m_frame->page();
     1391    if (!page ||! page->tabKeyCyclesThroughElements())
     1392        return;
     1393    FocusController* focus = page->focusController();
     1394    KeyboardEvent* keyboardEvent = findKeyboardEvent(event);
     1395    bool handled;
     1396    if (isBackTab)
     1397        handled = focus->advanceFocus(FocusDirectionBackward, keyboardEvent);
     1398    else
     1399        handled = focus->advanceFocus(keyboardEvent); // get direction from keyboard event
     1400    if (handled)
     1401        event->setDefaultHandled();
     1402}
     1403
     1404}
  • trunk/WebCore/page/EventHandler.h

    r19416 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2828
    2929#include "DragActions.h"
     30#include "FocusDirection.h"
    3031#include "PlatformMouseEvent.h"
    3132#include "ScrollTypes.h"
     
    3940#include "WebCoreKeyboardUIMode.h"
    4041#ifndef __OBJC__
    41 typedef unsigned NSDragOperation;
     42class NSEvent;
    4243class NSView;
    4344#endif
     
    6465class RenderObject;
    6566class RenderWidget;
     67class String;
     68class TextEvent;
    6669class VisiblePosition;
    6770class Widget;
     
    7679
    7780class EventHandler : Noncopyable {
     81public:
     82    EventHandler(Frame*);
     83    ~EventHandler();
     84
     85    void clear();
     86
     87    void updateSelectionForMouseDragOverPosition(const VisiblePosition&);
     88
     89    Node* mousePressNode() const;
     90    void setMousePressNode(PassRefPtr<Node>);
     91
     92    void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
     93    RenderObject* autoscrollRenderer() const;
     94
     95    HitTestResult hitTestResultAtPoint(const IntPoint&, bool allowShadowContent);
     96
     97    bool mousePressed() const { return m_mousePressed; }
     98    void setMousePressed(bool pressed) { m_mousePressed = pressed; }
     99
     100    void setCapturingMouseEventsNode(PassRefPtr<Node>);
     101
     102    bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
     103    void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
     104    bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
     105
     106    void scheduleHoverStateUpdate();
     107
     108    void setResizingFrameSet(HTMLFrameSetElement*);
     109
     110    IntPoint currentMousePosition() const;
     111
     112    void setIgnoreWheelEvents(bool);
     113
     114    bool scrollOverflow(ScrollDirection, ScrollGranularity);
     115
     116    bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
     117
     118    bool tabsToLinks(KeyboardEvent*) const;
     119    bool tabsToAllControls(KeyboardEvent*) const;
     120
     121    bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
     122
     123    bool handleMousePressEvent(const PlatformMouseEvent&);
     124    bool handleMouseMoveEvent(const PlatformMouseEvent&);
     125    bool handleMouseReleaseEvent(const PlatformMouseEvent&);
     126    bool handleWheelEvent(PlatformWheelEvent&);
     127
     128    bool sendContextMenuEvent(const PlatformMouseEvent&);
     129
     130    void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }
     131
     132    bool keyEvent(const PlatformKeyboardEvent&);
     133    void defaultKeyboardEventHandler(KeyboardEvent*);
     134
     135    bool handleTextInputEvent(const String& text, Event* underlyingEvent = 0,
     136        bool isLineBreak = false, bool isBackTab = false);
     137    void defaultTextInputEventHandler(TextEvent*);
     138
     139    bool eventMayStartDrag(const PlatformMouseEvent&) const;
     140   
     141    void dragSourceMovedTo(const PlatformMouseEvent&);
     142    void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
     143
     144#if PLATFORM(MAC)
     145    PassRefPtr<KeyboardEvent> currentKeyboardEvent() const;
     146
     147    void mouseDown(NSEvent*);
     148    void mouseDragged(NSEvent*);
     149    void mouseUp(NSEvent*);
     150    void mouseMoved(NSEvent*);
     151    bool keyEvent(NSEvent*);
     152    bool wheelEvent(NSEvent*);
     153
     154    void sendFakeEventsAfterWidgetTracking(NSEvent* initiatingEvent);
     155
     156    void setActivationEventNumber(int num) { m_activationEventNumber = num; }
     157
     158    NSEvent *currentNSEvent();
     159#endif
     160
     161private:
    78162    struct EventHandlerDragState {
    79163        RefPtr<Node> m_dragSrc; // element that may be a drag source, for the current mouse gesture
     
    87171    };
    88172    static EventHandlerDragState& dragState();
    89 public:
    90     EventHandler(Frame*);
    91     ~EventHandler();
    92 
    93     void clear();
    94 
    95     void updateSelectionForMouseDragOverPosition(const VisiblePosition&);
    96 
    97     Node* mousePressNode() const;
    98     void setMousePressNode(PassRefPtr<Node>);
    99 
    100     void stopAutoscrollTimer(bool rendererIsBeingDestroyed = false);
    101     RenderObject* autoscrollRenderer() const;
    102 
    103     HitTestResult hitTestResultAtPoint(const IntPoint&, bool allowShadowContent);
    104 
    105     bool mousePressed() const { return m_mousePressed; }
    106     void setMousePressed(bool pressed) { m_mousePressed = pressed; }
    107 
    108     void setCapturingMouseEventsNode(PassRefPtr<Node>);
    109 
    110     bool updateDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    111     void cancelDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    112     bool performDragAndDrop(const PlatformMouseEvent&, Clipboard*);
    113 
    114     void scheduleHoverStateUpdate();
    115 
    116     void setResizingFrameSet(HTMLFrameSetElement*);
    117 
    118     IntPoint currentMousePosition() const;
    119 
    120     void setIgnoreWheelEvents(bool);
    121 
    122     bool scrollOverflow(ScrollDirection, ScrollGranularity);
    123 
    124     bool shouldDragAutoNode(Node*, const IntPoint&) const; // -webkit-user-drag == auto
    125 
    126     bool tabsToLinks(KeyboardEvent*) const;
    127     bool tabsToAllControls(KeyboardEvent*) const;
    128 
    129     bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
    130     bool inputManagerHasMarkedText() const;
    131 
    132     bool handleMousePressEvent(const PlatformMouseEvent&);
    133     bool handleMouseMoveEvent(const PlatformMouseEvent&);
    134     bool handleMouseReleaseEvent(const PlatformMouseEvent&);
    135     bool handleWheelEvent(PlatformWheelEvent&);
    136 
    137     bool sendContextMenuEvent(PlatformMouseEvent);
    138 
    139     void setMouseDownMayStartAutoscroll() { m_mouseDownMayStartAutoscroll = true; }
    140 
    141     bool keyEvent(const PlatformKeyboardEvent&);
    142 
    143     void defaultKeyboardEventHandler(KeyboardEvent*);
    144    
    145     bool eventMayStartDrag(const PlatformMouseEvent&) const;
    146    
    147     void dragSourceMovedTo(const PlatformMouseEvent&);
    148     void dragSourceEndedAt(const PlatformMouseEvent&, DragOperation);
    149    
    150     //The following methods are needed to allow correct event modelling on Mac
    151     //they are called at the beginning of handleMouseUp and handleDrag. 
    152     //If they return true it indicates that they have consumed the event
    153 #if PLATFORM(MAC)
    154     bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&);
    155     bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&);
    156 #else
    157     bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&) { return false; }
    158     bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&) { return false; }   
    159 #endif
    160    
    161    
    162 #if PLATFORM(MAC)
    163     PassRefPtr<KeyboardEvent> currentKeyboardEvent() const;
    164 
    165     void mouseDown(NSEvent*);
    166     void mouseDragged(NSEvent*);
    167     void mouseUp(NSEvent*);
    168     void mouseMoved(NSEvent*);
    169     bool keyEvent(NSEvent*);
    170     bool wheelEvent(NSEvent*);
    171 
    172 
    173     void sendFakeEventsAfterWidgetTracking(NSEvent* initiatingEvent);
    174 
    175     void setActivationEventNumber(int num) { m_activationEventNumber = num; }
    176 
    177     NSEvent *currentNSEvent();
    178 #endif
    179 
    180 private:
     173
    181174    bool eventActivatedView(const PlatformMouseEvent&) const;
    182175    void selectClosestWordFromMouseEvent(const MouseEventWithHitTestResults& event);
     
    205198    Node* nodeUnderMouse() const;
    206199
    207     MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest& hitTestRequest, const PlatformMouseEvent& mev);
     200    MouseEventWithHitTestResults prepareMouseEvent(const HitTestRequest&, const PlatformMouseEvent&);
    208201
    209202    bool dispatchMouseEvent(const AtomicString& eventType, Node* target,
     
    238231    bool passMouseDownEventToWidget(Widget*);
    239232    bool passWheelEventToWidget(Widget*);
    240    
     233
     234    void defaultTabEventHandler(Event*, bool isBackTab);
     235
    241236    void allowDHTMLDrag(bool& flagDHTML, bool& flagUA) const;
    242    
     237
     238    // The following are called at the beginning of handleMouseUp and handleDrag. 
     239    // If they return true it indicates that they have consumed the event.
    243240#if PLATFORM(MAC)
    244     KeyboardUIMode keyboardUIMode() const;
    245 
     241    bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&);
     242    bool eventLoopHandleMouseDragged(const MouseEventWithHitTestResults&);
    246243    NSView *mouseDownViewIfStillGood();
     244#else
     245    bool eventLoopHandleMouseUp(const MouseEventWithHitTestResults&) { return false; }
    247246#endif
    248247
  • trunk/WebCore/page/FocusController.cpp

    r19207 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3535#include "EventHandler.h"
    3636#include "EventNames.h"
    37 #include "FocusDirection.h"
    3837#include "Frame.h"
    3938#include "FrameView.h"
     
    109108}
    110109
    111 
    112110bool FocusController::advanceFocus(KeyboardEvent* event)
    113111{
    114     ASSERT(event);
    115    
     112    return advanceFocus((event && event->shiftKey()) ? FocusDirectionBackward : FocusDirectionForward, event);
     113}
     114
     115bool FocusController::advanceFocus(FocusDirection direction, KeyboardEvent* event)
     116{
    116117    Frame* frame = focusedOrMainFrame();
    117118    ASSERT(frame);
     
    119120    if (!document)
    120121        return false;
    121 
    122     FocusDirection direction = event->shiftKey() ? FocusDirectionBackward : FocusDirectionForward;
    123122
    124123    Node* node = (direction == FocusDirectionForward)
  • trunk/WebCore/page/FocusController.h

    r18610 r19579  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     2 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#define FocusController_h
    2828
    29 #include "Shared.h"
     29#include "FocusDirection.h"
    3030#include <wtf/Forward.h>
    3131#include <wtf/RefPtr.h>
     
    3535    class Frame;
    3636    class KeyboardEvent;
    37     class Node;
    3837    class Page;
    3938
     
    4746
    4847        bool advanceFocus(KeyboardEvent*);
     48        bool advanceFocus(FocusDirection, KeyboardEvent*);
    4949
    5050    private:
  • trunk/WebCore/page/mac/EventHandlerMac.mm

    r19396 r19579  
    5656using namespace EventNames;
    5757
    58 
    5958static NSEvent *currentEvent;
    6059
     
    436435       
    437436        m_mouseDownMayStartDrag = dispatchDragSrcEvent(dragstartEvent, m_mouseDown)
    438         && !m_frame->selectionController()->isInPasswordField();
     437            && !m_frame->selectionController()->isInPasswordField();
    439438       
    440439        // Invalidate clipboard here against anymore pasteboard writing for security.  The drag
     
    742741}
    743742
    744 KeyboardUIMode EventHandler::keyboardUIMode() const
    745 {
    746     BEGIN_BLOCK_OBJC_EXCEPTIONS;
    747     return [Mac(m_frame)->bridge() keyboardUIMode];
    748     END_BLOCK_OBJC_EXCEPTIONS;
    749 
    750     return KeyboardAccessDefault;
    751 }
    752 
    753 bool EventHandler::inputManagerHasMarkedText() const
    754 {
    755     BEGIN_BLOCK_OBJC_EXCEPTIONS;
    756     return [[NSInputManager currentInputManager] hasMarkedText];
    757     END_BLOCK_OBJC_EXCEPTIONS
    758     return false;
    759 }
    760 
    761743bool EventHandler::passMousePressEventToSubframe(MouseEventWithHitTestResults& mev, Frame* subframe)
    762744{
  • trunk/WebCore/page/mac/WebCoreFrameBridge.h

    r19546 r19579  
    223223- (void)decreaseSelectionListLevel;
    224224
    225 - (void)insertLineBreak;
    226 - (void)insertParagraphSeparator;
    227225- (void)insertParagraphSeparatorInQuotedContent;
    228226
  • trunk/WebCore/page/mac/WebCoreFrameBridge.mm

    r19396 r19579  
    11541154}
    11551155
    1156 - (void)insertLineBreak
    1157 {
    1158     if (m_frame->selectionController()->isNone())
    1159         return;
    1160    
    1161     TypingCommand::insertLineBreak(m_frame->document());
    1162     m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
    1163 }
    1164 
    1165 - (void)insertParagraphSeparator
    1166 {
    1167     if (m_frame->selectionController()->isNone())
    1168         return;
    1169    
    1170     TypingCommand::insertParagraphSeparator(m_frame->document());
    1171     m_frame->revealSelection(RenderLayer::gAlignToEdgeIfNeeded);
    1172 }
    1173 
    11741156- (void)insertParagraphSeparatorInQuotedContent
    11751157{
  • trunk/WebCore/platform/graphics/svg/SVGImageEmptyClients.h

    r19487 r19579  
    310310
    311311#if PLATFORM(MAC)
     312    virtual void markedTextAbandoned(Frame*) { }
     313
    312314    // FIXME: This should become SelectionController::toWebArchive()
    313315    virtual NSData* dataForArchivedSelection(Frame*) { return 0; }
  • trunk/WebKit/ChangeLog

    r19568 r19579  
     12007-02-12  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Oliver.
     4
     5        - fix http://bugs.webkit.org/show_bug.cgi?id=12677
     6          <rdar://problem/4759563> REGRESSION: Return key is always sent when you confirm
     7          a clause in kotoeri (12677)
     8
     9        - fix http://bugs.webkit.org/show_bug.cgi?id=12596
     10          <rdar://problem/4794346> REGRESSION: Tab key shifts form field focus instead of
     11          navigating prediction window (12596)
     12
     13        - fix http://bugs.webkit.org/show_bug.cgi?id=10010
     14          <rdar://problem/4822935> REGRESSION: Pressing Return with unconfirmed text in
     15          Hangul inserts carriage return (10010)
     16
     17        - fix http://bugs.webkit.org/show_bug.cgi?id=12531
     18          <rdar://problem/4975126> REGRESSION: Inline text input types repeated keys in
     19          latest nightly (r19336) (12531)
     20
     21        - fix http://bugs.webkit.org/show_bug.cgi?id=12539
     22          <rdar://problem/4975130> REGRESSION: Pressing Backspace while in inline input
     23          area moves to the previous page in history (12539)
     24
     25        * WebCoreSupport/WebEditorClient.h:
     26        * WebCoreSupport/WebEditorClient.mm: (WebEditorClient::markedTextAbandoned):
     27        Added.
     28
     29        * WebView/WebHTMLView.mm:
     30        (-[WebHTMLView menuForEvent:]): Added explicit constructor needed now that the
     31        function takes a const&.
     32        (-[WebHTMLView becomeFirstResponder]): Removed fake event code, no longer needed
     33        since advanceFocus now works fine with 0 for a DOM event.
     34        (-[WebHTMLView _expandSelectionToGranularity:]): Changed to use the normal
     35        selection controller function instead of selectRange.
     36        (-[WebHTMLView insertTab:]): Changed to call bottleneck that receives the DOM
     37        event.
     38        (-[WebHTMLView insertBacktab:]): Ditto.
     39        (-[WebHTMLView insertNewline:]): Ditto.
     40        (-[WebHTMLView insertLineBreak:]): Ditto.
     41        (-[WebHTMLView insertParagraphSeparator:]): Ditto.
     42        (-[WebHTMLView insertNewlineIgnoringFieldEditor:]): Ditto.
     43        (-[WebHTMLView insertTabIgnoringFieldEditor:]): Ditto.
     44        (-[WebHTMLView yank:]): Updated to call Editor directly since the insertText
     45        code now works via a text input event which is not what we want for paste-like
     46        things such as yank.
     47        (-[WebHTMLView yankAndSelect:]): Ditto.
     48        (-[WebHTMLView selectToMark:]): Changed to use the normal selection controller
     49        function instead of selectRange, which also allows us to remove the ObjC exception
     50        handling code.
     51        (-[WebHTMLView swapWithMark:]): Ditto.
     52        (-[WebHTMLView transpose:]): Ditto.
     53        (-[WebHTMLView unmarkText]): Since this is one of the calls back from the input
     54        manager, added code to set the "event was handled" flag. Moved the actual work
     55        into the Editor class in WebCore and just call that from here.
     56        (-[WebHTMLView _selectRangeInMarkedText:]): Changed to use the normal selection
     57        controller function instead of selectRange.
     58        (-[WebHTMLView setMarkedText:selectedRange:]): Since this is one of the calls
     59        back from the input manager, added code to set the "event was handled" flag.
     60        Also changed the ignoreMarkedTextSelectionChange to use the flag over on the
     61        WebCore side, since we moved it there and to call selectMarkedText over on
     62        the WebCore side too.
     63        (-[WebHTMLView doCommandBySelector:]): Added special cases for newline and tab
     64        selectors so that the event is passed along. These selectors are special because
     65        they are ones that turn into text input events.
     66        (-[WebHTMLView _discardMarkedText]): Moved the body of this function into the
     67        Editor class in WebCore and just call that from here.
     68        (-[WebHTMLView insertText:]): Added code to send a text input event instead of
     69        calling the editor to do text insertion. The insertion is then done in the
     70        default handler for the text input event.
     71        (-[WebHTMLView _insertNewlineWithEvent:isLineBreak:]): Added. Sends a text
     72        input event.
     73        (-[WebHTMLView _insertTabWithEvent:isBackTab:]): Ditto.
     74        (-[WebHTMLView _updateSelectionForInputManager]): Changed to use the
     75        ignoreMarkedTextSelectionChange flag in Editor now that the one here is gone.
     76
     77        * WebView/WebHTMLViewInternal.h: Remove ignoreMarkedTextSelectionChange field.
     78
     79        * WebView/WebView.mm: (-[WebView setSelectedDOMRange:affinity:]): Changed to
     80        use the normal selection controller function instead of selectRange.
     81
    1822007-02-11  Sam Weinig  <sam@webkit.org>
    283
  • trunk/WebKit/WebCoreSupport/WebEditorClient.h

    r19237 r19579  
    8585    virtual void handleKeyPress(WebCore::KeyboardEvent*);
    8686
     87    virtual void markedTextAbandoned(WebCore::Frame*);
     88
    8789private:
    8890    void registerCommandForUndoOrRedo(PassRefPtr<WebCore::EditCommand>, bool isRedo);
  • trunk/WebKit/WebCoreSupport/WebEditorClient.mm

    r19313 r19579  
    397397}
    398398
    399 /*
    400 bool WebEditorClient::shouldChangeSelectedRange(Range *currentRange, Range *toProposedRange, NSSelectionAffinity selectionAffinity, bool stillSelecting) { return false; }
    401 bool WebEditorClient::shouldChangeTypingStyle(CSSStyleDeclaration *currentStyle, CSSStyleDeclaration *toProposedStyle) { return false; }
    402 bool WebEditorClient::doCommandBySelector(SEL selector) { return false; }
    403 
    404 void WebEditorClient::webViewDidBeginEditing:(NSNotification *)notification { }
    405 void WebEditorClient::webViewDidChange:(NSNotification *)notification { }
    406 void WebEditorClient::webViewDidEndEditing:(NSNotification *)notification { }
    407 void WebEditorClient::webViewDidChangeTypingStyle:(NSNotification *)notification { }
    408 void WebEditorClient::webViewDidChangeSelection:(NSNotification *)notification { }
    409 NSUndoManager* WebEditorClient::undoManagerForWebView:(WebView *)webView { return NULL; }
    410 */
     399void WebEditorClient::markedTextAbandoned(Frame* frame)
     400{
     401    WebHTMLView *webHTMLView = [[kit(frame) frameView] documentView];
     402    [[NSInputManager currentInputManager] markedTextAbandoned:webHTMLView];
     403}
  • trunk/WebKit/WebView/WebHTMLView.mm

    r19546 r19579  
    8686#import <WebCore/Page.h>
    8787#import <WebCore/PlatformKeyboardEvent.h>
     88#import <WebCore/PlatformMouseEvent.h>
    8889#import <WebCore/Range.h>
    8990#import <WebCore/SelectionController.h>
     
    232233@interface WebHTMLView (WebNSTextInputSupport) <NSTextInput>
    233234- (void)_updateSelectionForInputManager;
    234 - (BOOL)_insertText:(NSString *)text selectInsertedText:(BOOL)selectText triggeringEvent:(KeyboardEvent*)event;
     235- (BOOL)_insertNewlineWithEvent:(KeyboardEvent*)event isLineBreak:(BOOL)isLineBreak;
     236- (BOOL)_insertTabWithEvent:(KeyboardEvent*)event isBackTab:(BOOL)isBackTab;
    235237@end
    236238
     
    25662568    }
    25672569
    2568     handledEvent = coreFrame->eventHandler()->sendContextMenuEvent(event);
     2570    handledEvent = coreFrame->eventHandler()->sendContextMenuEvent(PlatformMouseEvent(event));
    25692571    _private->handlingMouseDownEvent = NO;
    25702572
     
    30533055    if (Document* document = frame->document())
    30543056        document->setFocusedNode(0);
    3055    
    3056     BOOL createdFakeEvent = NO;
    3057     KeyboardEvent* currentEvent = frame->eventHandler()->currentKeyboardEvent().get();
    3058     if (!currentEvent) {
    3059         // If we didn't get an event (for example, when using eventSender.keyDown() under DumpRenderTree), just fake a Tab keydown.
    3060         currentEvent = new KeyboardEvent(EventNames::keydownEvent, true, true,
    3061                                          frame->document() ? frame->document()->defaultView() : 0,
    3062                                          "U+000009", KeyboardEvent::DOM_KEY_LOCATION_STANDARD, false, false, false, false, false);
    3063         createdFakeEvent = YES;
    3064     }
    3065    
    3066     page->focusController()->advanceFocus(currentEvent);
    3067    
    3068     if (createdFakeEvent)
    3069         delete currentEvent;
    3070 
     3057    page->focusController()->advanceFocus(frame->eventHandler()->currentKeyboardEvent().get());
    30713058    return YES;
    30723059}
     
    37023689    EAffinity affinity = coreFrame->selectionController()->affinity();
    37033690    WebView *webView = [self _webView];
    3704     if ([[webView _editingDelegateForwarder] webView:webView shouldChangeSelectedDOMRange:[self _selectedRange] toDOMRange:domRange affinity:kit(affinity) stillSelecting:NO])
    3705         selectRange(coreFrame->selectionController(), range.get(), affinity, true);
     3691    if ([[webView _editingDelegateForwarder] webView:webView shouldChangeSelectedDOMRange:[self _selectedRange] toDOMRange:domRange affinity:kit(affinity) stillSelecting:NO]) {
     3692        ExceptionCode ec = 0;
     3693        coreFrame->selectionController()->setSelectedRange(range.get(), affinity, true, ec);
     3694    }
    37063695}
    37073696
     
    42564245- (void)insertTab:(id)sender
    42574246{
    4258     [self insertText:@"\t"];
     4247    [self _insertTabWithEvent:0 isBackTab:NO];
    42594248}
    42604249
    42614250- (void)insertBacktab:(id)sender
    42624251{
    4263     // Doing nothing matches normal NSTextView behavior. If we ever use WebView for a field-editor-type purpose
    4264     // we might add code here.
     4252    [self _insertTabWithEvent:0 isBackTab:YES];
    42654253}
    42664254
    42674255- (void)insertNewline:(id)sender
    42684256{
    4269     if (![self _canEdit])
    4270         return;
    4271        
    4272     // Perhaps we should make this delegate call sensitive to the real DOM operation we actually do.
    4273     WebFrameBridge *bridge = [self _bridge];
    4274     if ([self _shouldReplaceSelectionWithText:@"\n" givenAction:WebViewInsertActionTyped]) {
    4275         if ([self _canEditRichly])
    4276             [bridge insertParagraphSeparator];
    4277         else
    4278             [bridge insertLineBreak];
    4279     }
     4257    [self _insertNewlineWithEvent:0 isLineBreak:NO];
    42804258}
    42814259
    42824260- (void)insertLineBreak:(id)sender
    42834261{
    4284     if (![self _canEdit])
    4285         return;
    4286        
    4287     // Perhaps we should make this delegate call sensitive to the real DOM operation we actually do.
    4288     WebFrameBridge *bridge = [self _bridge];
    4289     if ([self _shouldReplaceSelectionWithText:@"\n" givenAction:WebViewInsertActionTyped])
    4290         [bridge insertLineBreak];
     4262    [self _insertNewlineWithEvent:0 isLineBreak:YES];
    42914263}
    42924264
    42934265- (void)insertParagraphSeparator:(id)sender
    42944266{
    4295     if (![self _canEdit])
    4296         return;
    4297 
    4298     // Perhaps we should make this delegate call sensitive to the real DOM operation we actually do.
    4299     WebFrameBridge *bridge = [self _bridge];
    4300     if ([self _shouldReplaceSelectionWithText:@"\n" givenAction:WebViewInsertActionTyped]) {
    4301         if ([self _canEditRichly])
    4302             [bridge insertParagraphSeparator];
    4303         else
    4304             [bridge insertLineBreak];
    4305     }
     4267    [self _insertNewlineWithEvent:0 isLineBreak:NO];
    43064268}
    43074269
     
    45134475- (void)insertNewlineIgnoringFieldEditor:(id)sender
    45144476{
    4515     [self insertNewline:sender];
     4477    [self _insertNewlineWithEvent:0 isLineBreak:NO];
    45164478}
    45174479
    45184480- (void)insertTabIgnoringFieldEditor:(id)sender
    45194481{
    4520     [self insertTab:sender];
     4482    [self _insertTabWithEvent:0 isBackTab:NO];
    45214483}
    45224484
     
    45624524   
    45634525    NSString* yankee = _NSYankFromKillRing();
    4564     if ([yankee length])
    4565         [self insertText:yankee];
    4566     else
     4526    if ([yankee length]) {
     4527        if (Frame* coreFrame = core([self _frame]))
     4528            coreFrame->editor()->insertText(yankee, false);
     4529    } else
    45674530        [self deleteBackward:nil];
    45684531
     
    45764539
    45774540    NSString* yankee = _NSYankPreviousFromKillRing();
    4578     if ([yankee length])
    4579         [self _insertText:yankee selectInsertedText:YES triggeringEvent:0];
    4580     else
     4541    if ([yankee length]) {
     4542        if (Frame* coreFrame = core([self _frame]))
     4543            coreFrame->editor()->insertText(yankee, true);
     4544    } else
    45814545        [self deleteBackward:nil];
    45824546       
     
    46294593    WebFrameBridge *bridge = [self _bridge];
    46304594    DOMRange *mark = [bridge markDOMRange];
    4631     if (mark == nil) {
    4632         NSBeep();
    4633         return;
    4634     }
    46354595    DOMRange *selection = [self _selectedRange];
    46364596    Frame* coreFrame = core([self _frame]);
    4637     NS_DURING
    4638         if (coreFrame)
    4639             selectRange(coreFrame->selectionController(), core(unionDOMRanges(mark, selection)), DOWNSTREAM, true);
    4640     NS_HANDLER
     4597    if (!mark || !selection || !coreFrame) {
    46414598        NSBeep();
    4642     NS_ENDHANDLER
     4599        return;
     4600    }
     4601    ExceptionCode ec = 0;
     4602    coreFrame->selectionController()->setSelectedRange(core(unionDOMRanges(mark, [self _selectedRange])), DOWNSTREAM, true, ec);
    46434603}
    46444604
     
    46474607    WebFrameBridge *bridge = [self _bridge];
    46484608    DOMRange *mark = [bridge markDOMRange];
    4649 
    4650     if (mark == nil) {
    4651         NSBeep();
    4652         return;
    4653     }
    4654 
    46554609    DOMRange *selection = [self _selectedRange];
    46564610    Frame* coreFrame = core([self _frame]);
    4657     NS_DURING
    4658         if (coreFrame)
    4659             selectRange(coreFrame->selectionController(), core(mark), DOWNSTREAM, true);
    4660     NS_HANDLER
     4611    if (!mark || !selection || !coreFrame) {
    46614612        NSBeep();
    46624613        return;
    4663     NS_ENDHANDLER
    4664     [bridge setMarkDOMRange:selection];
     4614    }
     4615
     4616    ExceptionCode ec = 0;
     4617    coreFrame->selectionController()->setSelectedRange(core(mark), DOWNSTREAM, true, ec);
     4618    if (ec == 0)
     4619        [bridge setMarkDOMRange:selection];
    46654620}
    46664621
     
    46844639
    46854640    Frame* coreFrame = core([self _frame]);
    4686     if (coreFrame)
    4687         selectRange(coreFrame->selectionController(), core(r), DOWNSTREAM, true);
     4641    if (!coreFrame)
     4642        return;
     4643
     4644    ExceptionCode ec = 0;
     4645    coreFrame->selectionController()->setSelectedRange(core(r), DOWNSTREAM, true, ec);
    46884646    if ([self _shouldReplaceSelectionWithText:transposed givenAction:WebViewInsertActionTyped])
    46894647        [bridge replaceSelectionWithText:transposed selectReplacement:NO smartReplace:NO];
     
    53295287- (void)unmarkText
    53305288{
    5331     [[self _bridge] setMarkedTextDOMRange:nil customAttributes:nil ranges:nil];
    5332 }
    5333 
    5334 - (void)_selectMarkedText
    5335 {
    5336     if ([self hasMarkedText]) {
    5337         WebFrameBridge *bridge = [self _bridge];
    5338         DOMRange *markedTextRange = [bridge markedTextDOMRange];
    5339         Frame* coreFrame = core([self _frame]);
    5340         if (coreFrame)
    5341             selectRange(coreFrame->selectionController(), core(markedTextRange), DOWNSTREAM, false);
    5342     }
     5289    // Use pointer to get parameters passed to us by the caller of interpretKeyEvents.
     5290    WebHTMLViewInterpretKeyEventsParameters* parameters = _private->interpretKeyEventsParameters;
     5291    _private->interpretKeyEventsParameters = 0;
     5292
     5293    if (parameters)
     5294        parameters->eventWasHandled = YES;
     5295
     5296    if (Frame* coreFrame = core([self _frame]))
     5297        coreFrame->editor()->unmarkText();
    53435298}
    53445299
     
    53605315
    53615316    Frame* coreFrame = core([self _frame]);
    5362     if (coreFrame)
    5363         selectRange(coreFrame->selectionController(), core(selectedRange), DOWNSTREAM, false);
     5317    if (coreFrame) {
     5318        ExceptionCode ec = 0;
     5319        coreFrame->selectionController()->setSelectedRange(core(selectedRange), DOWNSTREAM, false, ec);
     5320    }
    53645321}
    53655322
     
    53835340- (void)setMarkedText:(id)string selectedRange:(NSRange)newSelRange
    53845341{
     5342    // Use pointer to get parameters passed to us by the caller of interpretKeyEvents.
     5343    WebHTMLViewInterpretKeyEventsParameters* parameters = _private->interpretKeyEventsParameters;
     5344    _private->interpretKeyEventsParameters = 0;
     5345
     5346    if (parameters)
     5347        parameters->eventWasHandled = YES;
     5348
     5349    Frame* coreFrame = core([self _frame]);
     5350    if (!coreFrame)
     5351        return;
     5352
    53855353    WebFrameBridge *bridge = [self _bridge];
    53865354
     
    54005368    }
    54015369
    5402     _private->ignoreMarkedTextSelectionChange = YES;
     5370    coreFrame->editor()->setIgnoreMarkedTextSelectionChange(true);
    54035371
    54045372    // if we had marked text already, we need to make sure to replace
    54055373    // that, instead of the selection/caret
    5406     [self _selectMarkedText];
     5374    coreFrame->editor()->selectMarkedText();
    54075375
    54085376    NSString *text = string;
     
    54195387        [self _selectRangeInMarkedText:newSelRange];
    54205388
    5421     _private->ignoreMarkedTextSelectionChange = NO;
     5389    coreFrame->editor()->setIgnoreMarkedTextSelectionChange(false);
    54225390}
    54235391
     
    54315399        return;
    54325400
     5401    KeyboardEvent* event = parameters ? parameters->event : 0;
     5402    bool eventWasHandled = true;
     5403
    54335404    WebView *webView = [self _webView];
    5434     if (![[webView _editingDelegateForwarder] webView:webView doCommandBySelector:aSelector])
    5435         [super doCommandBySelector:aSelector];
     5405    if (![[webView _editingDelegateForwarder] webView:webView doCommandBySelector:aSelector]) {
     5406        if (aSelector == @selector(insertNewline:) || aSelector == @selector(insertParagraphSeparator:) || aSelector == @selector(insertNewlineIgnoringFieldEditor:))
     5407            eventWasHandled = [self _insertNewlineWithEvent:event isLineBreak:NO];
     5408        else if (aSelector == @selector(insertLineBreak:))
     5409            eventWasHandled = [self _insertNewlineWithEvent:event isLineBreak:YES];
     5410        else if (aSelector == @selector(insertTab:) || aSelector == @selector(insertTabIgnoringFieldEditor:))
     5411            eventWasHandled = [self _insertTabWithEvent:event isBackTab:NO];
     5412        else if (aSelector == @selector(insertBacktab:))
     5413            eventWasHandled = [self _insertTabWithEvent:event isBackTab:YES];
     5414        else
     5415            [super doCommandBySelector:aSelector];
     5416    }
    54365417
    54375418    if (parameters)
    5438         parameters->eventWasHandled = YES;
    5439 }
    5440 
    5441 - (void)_discardMarkedText
    5442 {
    5443     if (![self hasMarkedText])
    5444         return;
    5445 
    5446     _private->ignoreMarkedTextSelectionChange = YES;
    5447 
    5448     [self _selectMarkedText];
    5449     [self unmarkText];
    5450     [[NSInputManager currentInputManager] markedTextAbandoned:self];
    5451     // FIXME: Should we be calling the delegate here?
    5452     if (Frame* coreFrame = core([self _frame]))
    5453         coreFrame->editor()->deleteSelectionWithSmartDelete(false);
    5454 
    5455     _private->ignoreMarkedTextSelectionChange = NO;
    5456 }
    5457 
    5458 - (BOOL)_insertText:(NSString *)text selectInsertedText:(BOOL)selectText triggeringEvent:(KeyboardEvent*)event
    5459 {
    5460     if (text == nil || [text length] == 0 || (![self _isEditable] && ![self hasMarkedText]))
    5461         return NO;
    5462 
    5463     if (![self _shouldReplaceSelectionWithText:text givenAction:WebViewInsertActionTyped]) {
    5464         [self _discardMarkedText];
    5465         return NO;
    5466     }
    5467 
    5468     _private->ignoreMarkedTextSelectionChange = YES;
    5469 
    5470     // If we had marked text, we replace that, instead of the selection/caret.
    5471     [self _selectMarkedText];
    5472 
    5473     bool eventHandled = false;
    5474 
    5475     if (Frame* coreFrame = core([self _frame]))
    5476         eventHandled = coreFrame->editor()->insertText(text, selectText, event);
    5477        
    5478     _private->ignoreMarkedTextSelectionChange = NO;
    5479 
    5480     // Inserting unmarks any marked text.
    5481     [self unmarkText];
    5482 
    5483     return eventHandled;
     5419        parameters->eventWasHandled = eventWasHandled;
    54845420}
    54855421
     
    54905426    _private->interpretKeyEventsParameters = 0;
    54915427
    5492     // We don't yet support inserting an attributed string but input methods don't appear to require this.
     5428    // We don't support inserting an attributed string but input methods don't appear to require this.
    54935429    NSString *text;
    54945430    if ([string isKindOfClass:[NSAttributedString class]])
     
    54965432    else
    54975433        text = string;
    5498     BOOL eventHandled = [self _insertText:text selectInsertedText:NO
    5499         triggeringEvent:parameters ? parameters->event : 0];
     5434
     5435    bool eventHandled = false;
     5436    if ([text length]) {
     5437        Frame* coreFrame = core([self _frame]);
     5438        KeyboardEvent* event = parameters ? parameters->event : 0;
     5439        String eventText = text;
     5440        eventText.replace(NSBackTabCharacter, NSTabCharacter); // same thing is done in KeyEventMac.mm in WebCore
     5441        eventHandled = coreFrame && coreFrame->eventHandler()->handleTextInputEvent(eventText, event);
     5442    }
    55005443
    55015444    if (parameters)
    55025445        parameters->eventWasHandled = eventHandled;
     5446}
     5447
     5448- (BOOL)_insertNewlineWithEvent:(KeyboardEvent*)event isLineBreak:(BOOL)isLineBreak
     5449{
     5450    Frame* coreFrame = core([self _frame]);
     5451    return coreFrame && coreFrame->eventHandler()->handleTextInputEvent("\n", event, isLineBreak);
     5452}
     5453
     5454- (BOOL)_insertTabWithEvent:(KeyboardEvent*)event isBackTab:(BOOL)isBackTab
     5455{
     5456    Frame* coreFrame = core([self _frame]);
     5457    return coreFrame && coreFrame->eventHandler()->handleTextInputEvent("\t", event, false, isBackTab);
    55035458}
    55045459
     
    55285483- (void)_updateSelectionForInputManager
    55295484{
    5530     if (![self hasMarkedText] || _private->ignoreMarkedTextSelectionChange)
     5485    if (![self hasMarkedText])
     5486        return;
     5487
     5488    Frame* coreFrame = core([self _frame]);
     5489    if (!coreFrame)
     5490        return;
     5491
     5492    if (coreFrame->editor()->ignoreMarkedTextSelectionChange())
    55315493        return;
    55325494
  • trunk/WebKit/WebView/WebHTMLViewInternal.h

    r19546 r19579  
    7878
    7979    BOOL resigningFirstResponder;
    80     BOOL ignoreMarkedTextSelectionChange;
    8180    BOOL nextResponderDisabledOnce;
    8281    BOOL willBecomeFirstResponderForNodeFocus;
  • trunk/WebKit/WebView/WebView.mm

    r19536 r19579  
    29802980            return;
    29812981
    2982         selectRange(coreFrame->selectionController(), [range _range], core(selectionAffinity), true);
     2982        ExceptionCode ec = 0;
     2983        coreFrame->selectionController()->setSelectedRange([range _range], core(selectionAffinity), true, ec);
    29832984    }
    29842985}
Note: See TracChangeset for help on using the changeset viewer.