The processor for HtmlElement#doType(char, boolean) and HtmlElement#doType(int, boolean). @author Marc Guillemot @author Ronald Brill @author Ahmed Ashour
| 48 | * @author Ahmed Ashour |
| 49 | */ |
| 50 | class DoTypeProcessor implements Serializable { |
| 51 | |
| 52 | private static final Map<Integer, Character> SPECIAL_KEYS_MAP_ = new HashMap<>(); |
| 53 | |
| 54 | /** |
| 55 | * Either {@link HtmlElement} or {@link DomText}. |
| 56 | */ |
| 57 | private final DomNode domNode_; |
| 58 | |
| 59 | static { |
| 60 | SPECIAL_KEYS_MAP_.put(DOM_VK_ADD, '+'); |
| 61 | SPECIAL_KEYS_MAP_.put(DOM_VK_DECIMAL, '.'); |
| 62 | SPECIAL_KEYS_MAP_.put(DOM_VK_DIVIDE, '/'); |
| 63 | SPECIAL_KEYS_MAP_.put(DOM_VK_EQUALS, '='); |
| 64 | SPECIAL_KEYS_MAP_.put(DOM_VK_MULTIPLY, '*'); |
| 65 | SPECIAL_KEYS_MAP_.put(DOM_VK_SEMICOLON, ';'); |
| 66 | SPECIAL_KEYS_MAP_.put(DOM_VK_SEPARATOR, ','); |
| 67 | SPECIAL_KEYS_MAP_.put(DOM_VK_SPACE, ' '); |
| 68 | SPECIAL_KEYS_MAP_.put(DOM_VK_SUBTRACT, '-'); |
| 69 | |
| 70 | for (int i = DOM_VK_NUMPAD0; i <= DOM_VK_NUMPAD9; i++) { |
| 71 | SPECIAL_KEYS_MAP_.put(i, (char) ('0' + i - DOM_VK_NUMPAD0)); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | DoTypeProcessor(final DomNode domNode) { |
| 76 | domNode_ = domNode; |
| 77 | } |
| 78 | |
| 79 | void doType(final String currentValue, final SelectionDelegate selectionDelegate, |
| 80 | final char c, final HtmlElement element, final boolean lastType) { |
| 81 | |
| 82 | int selectionStart = selectionDelegate.getSelectionStart(); |
| 83 | selectionStart = Math.max(0, Math.min(selectionStart, currentValue.length())); |
| 84 | |
| 85 | int selectionEnd = selectionDelegate.getSelectionEnd(); |
| 86 | selectionEnd = Math.max(selectionStart, Math.min(selectionEnd, currentValue.length())); |
| 87 | |
| 88 | final StringBuilder newValue = new StringBuilder(currentValue); |
| 89 | if (c == '\b') { |
| 90 | if (selectionStart > 0) { |
| 91 | newValue.deleteCharAt(selectionStart - 1); |
| 92 | selectionStart--; |
| 93 | selectionEnd--; |
| 94 | } |
| 95 | } |
| 96 | else if (acceptChar(c)) { |
| 97 | final boolean ctrlKey = element.isCtrlPressed(); |
| 98 | if (ctrlKey && (c == 'C' || c == 'c')) { |
| 99 | final ClipboardHandler clipboardHandler = element.getPage().getWebClient().getClipboardHandler(); |
| 100 | if (clipboardHandler != null) { |
| 101 | final String content = newValue.substring(selectionStart, selectionEnd); |
| 102 | clipboardHandler.setClipboardContent(content); |
| 103 | } |
| 104 | } |
| 105 | else if (ctrlKey && (c == 'V' || c == 'v')) { |
| 106 | final ClipboardHandler clipboardHandler = element.getPage().getWebClient().getClipboardHandler(); |
| 107 | if (clipboardHandler != null) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…