Changeset 70313 in webkit


Ignore:
Timestamp:
Oct 22, 2010 9:57:55 AM (14 years ago)
Author:
Patrick Gansterer
Message:

2010-10-22 Patrick Gansterer <Patrick Gansterer>

Reviewed by Adam Roben.

[WINCE] Implement EditorClient::handleKeyboardEvent
https://bugs.webkit.org/show_bug.cgi?id=48118

Copy the implementation from the EFL port.

  • WebCoreSupport/EditorClientWinCE.cpp: (WebKit::EditorClientWinCE::interpretKeyEvent): (WebKit::EditorClientWinCE::handleEditingKeyboardEvent): (WebKit::EditorClientWinCE::handleKeyboardEvent):
  • WebCoreSupport/EditorClientWinCE.h:
Location:
trunk/WebKit/wince
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/wince/ChangeLog

    r69850 r70313  
     12010-10-22  Patrick Gansterer  <paroga@webkit.org>
     2
     3        Reviewed by Adam Roben.
     4
     5        [WINCE] Implement EditorClient::handleKeyboardEvent
     6        https://bugs.webkit.org/show_bug.cgi?id=48118
     7
     8        Copy the implementation from the EFL port.
     9
     10        * WebCoreSupport/EditorClientWinCE.cpp:
     11        (WebKit::EditorClientWinCE::interpretKeyEvent):
     12        (WebKit::EditorClientWinCE::handleEditingKeyboardEvent):
     13        (WebKit::EditorClientWinCE::handleKeyboardEvent):
     14        * WebCoreSupport/EditorClientWinCE.h:
     15
    1162010-10-15  Nikolas Zimmermann  <nzimmermann@rim.com>
    217
  • trunk/WebKit/wince/WebCoreSupport/EditorClientWinCE.cpp

    r67948 r70313  
    11/*
    2  * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
     2 *  Copyright (C) 2007 Alp Toker <alp@atoker.com>
     3 *  Copyright (C) 2008 Nuanti Ltd.
     4 *  Copyright (C) 2008 INdT - Instituto Nokia de Tecnologia
     5 *  Copyright (C) 2009-2010 ProFUSION embedded systems
     6 *  Copyright (C) 2009-2010 Samsung Electronics
     7 *  Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
    38 *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
    10  *    notice, this list of conditions and the following disclaimer in the
    11  *    documentation and/or other materials provided with the distribution.
     9 *  This library is free software; you can redistribute it and/or
     10 *  modify it under the terms of the GNU Lesser General Public
     11 *  License as published by the Free Software Foundation; either
     12 *  version 2 of the License, or (at your option) any later version.
    1213 *
    13  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
    14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    15  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    16  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
    17  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    18  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    19  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    20  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     14 *  This library is distributed in the hope that it will be useful,
     15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 *  Lesser General Public License for more details.
     18 *
     19 *  You should have received a copy of the GNU Lesser General Public
     20 *  License along with this library; if not, write to the Free Software
     21 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    2322 */
    2423
     
    2726
    2827#include "EditCommand.h"
     28#include "Frame.h"
     29#include "KeyboardEvent.h"
    2930#include "NotImplemented.h"
     31#include "PlatformKeyboardEvent.h"
     32#include "Settings.h"
    3033
    3134using namespace WebCore;
     
    218221}
    219222
     223static const unsigned CtrlKey = 1 << 0;
     224static const unsigned AltKey = 1 << 1;
     225static const unsigned ShiftKey = 1 << 2;
     226
     227struct KeyDownEntry {
     228    unsigned virtualKey;
     229    unsigned modifiers;
     230    const char* name;
     231};
     232
     233struct KeyPressEntry {
     234    unsigned charCode;
     235    unsigned modifiers;
     236    const char* name;
     237};
     238
     239static const KeyDownEntry keyDownEntries[] = {
     240    { VK_LEFT,   0,                  "MoveLeft"                                    },
     241    { VK_LEFT,   ShiftKey,           "MoveLeftAndModifySelection"                  },
     242    { VK_LEFT,   CtrlKey,            "MoveWordLeft"                                },
     243    { VK_LEFT,   CtrlKey | ShiftKey, "MoveWordLeftAndModifySelection"              },
     244    { VK_RIGHT,  0,                  "MoveRight"                                   },
     245    { VK_RIGHT,  ShiftKey,           "MoveRightAndModifySelection"                 },
     246    { VK_RIGHT,  CtrlKey,            "MoveWordRight"                               },
     247    { VK_RIGHT,  CtrlKey | ShiftKey, "MoveWordRightAndModifySelection"             },
     248    { VK_UP,     0,                  "MoveUp"                                      },
     249    { VK_UP,     ShiftKey,           "MoveUpAndModifySelection"                    },
     250    { VK_PRIOR,  ShiftKey,           "MovePageUpAndModifySelection"                },
     251    { VK_DOWN,   0,                  "MoveDown"                                    },
     252    { VK_DOWN,   ShiftKey,           "MoveDownAndModifySelection"                  },
     253    { VK_NEXT,   ShiftKey,           "MovePageDownAndModifySelection"              },
     254    { VK_PRIOR,  0,                  "MovePageUp"                                  },
     255    { VK_NEXT,   0,                  "MovePageDown"                                },
     256    { VK_HOME,   0,                  "MoveToBeginningOfLine"                       },
     257    { VK_HOME,   ShiftKey,           "MoveToBeginningOfLineAndModifySelection"     },
     258    { VK_HOME,   CtrlKey,            "MoveToBeginningOfDocument"                   },
     259    { VK_HOME,   CtrlKey | ShiftKey, "MoveToBeginningOfDocumentAndModifySelection" },
     260
     261    { VK_END,    0,                  "MoveToEndOfLine"                             },
     262    { VK_END,    ShiftKey,           "MoveToEndOfLineAndModifySelection"           },
     263    { VK_END,    CtrlKey,            "MoveToEndOfDocument"                         },
     264    { VK_END,    CtrlKey | ShiftKey, "MoveToEndOfDocumentAndModifySelection"       },
     265
     266    { VK_BACK,   0,                  "DeleteBackward"                              },
     267    { VK_BACK,   ShiftKey,           "DeleteBackward"                              },
     268    { VK_DELETE, 0,                  "DeleteForward"                               },
     269    { VK_BACK,   CtrlKey,            "DeleteWordBackward"                          },
     270    { VK_DELETE, CtrlKey,            "DeleteWordForward"                           },
     271
     272    { 'B',       CtrlKey,            "ToggleBold"                                  },
     273    { 'I',       CtrlKey,            "ToggleItalic"                                },
     274
     275    { VK_ESCAPE, 0,                  "Cancel"                                      },
     276    { VK_TAB,    0,                  "InsertTab"                                   },
     277    { VK_TAB,    ShiftKey,           "InsertBacktab"                               },
     278    { VK_RETURN, 0,                  "InsertNewline"                               },
     279    { VK_RETURN, CtrlKey,            "InsertNewline"                               },
     280    { VK_RETURN, AltKey,             "InsertNewline"                               },
     281    { VK_RETURN, AltKey | ShiftKey,  "InsertNewline"                               },
     282
     283    // It's not quite clear whether clipboard shortcuts and Undo/Redo should be handled
     284    // in the application or in WebKit. We chose WebKit for now.
     285    { 'C',       CtrlKey,            "Copy"                                        },
     286    { 'V',       CtrlKey,            "Paste"                                       },
     287    { 'X',       CtrlKey,            "Cut"                                         },
     288    { 'A',       CtrlKey,            "SelectAll"                                   },
     289    { VK_INSERT, CtrlKey,            "Copy"                                        },
     290    { VK_DELETE, ShiftKey,           "Cut"                                         },
     291    { VK_INSERT, ShiftKey,           "Paste"                                       },
     292    { 'Z',       CtrlKey,            "Undo"                                        },
     293    { 'Z',       CtrlKey | ShiftKey, "Redo"                                        }
     294};
     295
     296static const KeyPressEntry keyPressEntries[] = {
     297    { '\t',   0,                  "InsertTab"                                   },
     298    { '\t',   ShiftKey,           "InsertBacktab"                               },
     299    { '\r',   0,                  "InsertNewline"                               },
     300    { '\r',   CtrlKey,            "InsertNewline"                               },
     301    { '\r',   AltKey,             "InsertNewline"                               },
     302    { '\r',   AltKey | ShiftKey,  "InsertNewline"                               }
     303};
     304
     305const char* EditorClientWinCE::interpretKeyEvent(const KeyboardEvent* event)
     306{
     307    ASSERT(event->type() == eventNames().keydownEvent || event->type() == eventNames().keypressEvent);
     308
     309    static HashMap<int, const char*>* keyDownCommandsMap = 0;
     310    static HashMap<int, const char*>* keyPressCommandsMap = 0;
     311
     312    if (!keyDownCommandsMap) {
     313        keyDownCommandsMap = new HashMap<int, const char*>;
     314        keyPressCommandsMap = new HashMap<int, const char*>;
     315
     316        for (unsigned i = 0; i < _countof(keyDownEntries); i++)
     317            keyDownCommandsMap->set(keyDownEntries[i].modifiers << 16 | keyDownEntries[i].virtualKey, keyDownEntries[i].name);
     318
     319        for (unsigned i = 0; i < _countof(keyPressEntries); i++)
     320            keyPressCommandsMap->set(keyPressEntries[i].modifiers << 16 | keyPressEntries[i].charCode, keyPressEntries[i].name);
     321    }
     322
     323    unsigned modifiers = 0;
     324    if (event->shiftKey())
     325        modifiers |= ShiftKey;
     326    if (event->altKey())
     327        modifiers |= AltKey;
     328    if (event->ctrlKey())
     329        modifiers |= CtrlKey;
     330
     331    if (event->type() == eventNames().keydownEvent) {
     332        int mapKey = modifiers << 16 | event->keyCode();
     333        return mapKey ? keyDownCommandsMap->get(mapKey) : 0;
     334    }
     335
     336    int mapKey = modifiers << 16 | event->charCode();
     337    return mapKey ? keyPressCommandsMap->get(mapKey) : 0;
     338}
     339
     340bool EditorClientWinCE::handleEditingKeyboardEvent(KeyboardEvent* event)
     341{
     342    Node* node = event->target()->toNode();
     343    ASSERT(node);
     344    Frame* frame = node->document()->frame();
     345    ASSERT(frame);
     346
     347    const PlatformKeyboardEvent* keyEvent = event->keyEvent();
     348    if (!keyEvent)
     349        return false;
     350
     351    bool caretBrowsing = frame->settings()->caretBrowsingEnabled();
     352    if (caretBrowsing) {
     353        switch (keyEvent->windowsVirtualKeyCode()) {
     354        case VK_LEFT:
     355            frame->selection()->modify(keyEvent->shiftKey() ? SelectionController::AlterationExtend : SelectionController::AlterationMove,
     356                    SelectionController::DirectionLeft,
     357                    keyEvent->ctrlKey() ? WordGranularity : CharacterGranularity,
     358                    true);
     359            return true;
     360        case VK_RIGHT:
     361            frame->selection()->modify(keyEvent->shiftKey() ? SelectionController::AlterationExtend : SelectionController::AlterationMove,
     362                    SelectionController::DirectionRight,
     363                    keyEvent->ctrlKey() ? WordGranularity : CharacterGranularity,
     364                    true);
     365            return true;
     366        case VK_UP:
     367            frame->selection()->modify(keyEvent->shiftKey() ? SelectionController::AlterationExtend : SelectionController::AlterationMove,
     368                    SelectionController::DirectionBackward,
     369                    keyEvent->ctrlKey() ? ParagraphGranularity : LineGranularity,
     370                    true);
     371            return true;
     372        case VK_DOWN:
     373            frame->selection()->modify(keyEvent->shiftKey() ? SelectionController::AlterationExtend : SelectionController::AlterationMove,
     374                    SelectionController::DirectionForward,
     375                    keyEvent->ctrlKey() ? ParagraphGranularity : LineGranularity,
     376                    true);
     377            return true;
     378        }
     379    }
     380
     381    Editor::Command command = frame->editor()->command(interpretKeyEvent(event));
     382
     383    if (keyEvent->type() == PlatformKeyboardEvent::RawKeyDown) {
     384        // WebKit doesn't have enough information about mode to decide how commands that just insert text if executed via Editor should be treated,
     385        // so we leave it upon WebCore to either handle them immediately (e.g. Tab that changes focus) or let a keypress event be generated
     386        // (e.g. Tab that inserts a Tab character, or Enter).
     387        return !command.isTextInsertion() && command.execute(event);
     388    }
     389
     390    if (command.execute(event))
     391        return true;
     392
     393    // Don't insert null or control characters as they can result in unexpected behaviour
     394    if (event->charCode() < ' ')
     395        return false;
     396
     397    // Don't insert anything if a modifier is pressed
     398    if (keyEvent->ctrlKey() || keyEvent->altKey())
     399        return false;
     400
     401    return frame->editor()->insertText(event->keyEvent()->text(), event);
     402}
     403
    220404void EditorClientWinCE::handleKeyboardEvent(KeyboardEvent* event)
    221405{
    222     notImplemented();
     406    if (handleEditingKeyboardEvent(event))
     407        event->setDefaultHandled();
    223408}
    224409
  • trunk/WebKit/wince/WebCoreSupport/EditorClientWinCE.h

    r67948 r70313  
    7777    virtual void redo();
    7878
     79    virtual const char* interpretKeyEvent(const WebCore::KeyboardEvent*);
     80    virtual bool handleEditingKeyboardEvent(WebCore::KeyboardEvent*);
    7981    virtual void handleKeyboardEvent(WebCore::KeyboardEvent*);
    8082    virtual void handleInputMethodKeydown(WebCore::KeyboardEvent*);
Note: See TracChangeset for help on using the changeset viewer.