1 | /* |
2 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
3 | * Copyright (C) 2010 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Library General Public License |
16 | * along with this library; see the file COPYING.LIB. If not, write to |
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | * Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "EditingBehaviorTypes.h" |
24 | |
25 | namespace WebCore { |
26 | |
27 | class EditingBehavior { |
28 | |
29 | public: |
30 | explicit EditingBehavior(EditingBehaviorType type) |
31 | : m_type(type) |
32 | { |
33 | } |
34 | |
35 | // Individual functions for each case where we have more than one style of editing behavior. |
36 | // Create a new function for any platform difference so we can control it here. |
37 | |
38 | // When extending a selection beyond the top or bottom boundary of an editable area, |
39 | // maintain the horizontal position on Windows but extend it to the boundary of the editable |
40 | // content on Mac. |
41 | bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const |
42 | { |
43 | return m_type != EditingWindowsBehavior; |
44 | } |
45 | |
46 | // On Windows, selections should always be considered as directional, regardless if it is |
47 | // mouse-based or keyboard-based. |
48 | bool shouldConsiderSelectionAsDirectional() const { return m_type != EditingMacBehavior && m_type != EditingIOSBehavior; } |
49 | |
50 | // On Mac, when revealing a selection (for example as a result of a Find operation on the Browser), |
51 | // content should be scrolled such that the selection gets certer aligned. |
52 | bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; } |
53 | |
54 | // On Mac, style is considered present when present at the beginning of selection. On other platforms, |
55 | // style has to be present throughout the selection. |
56 | bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; } |
57 | |
58 | // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the base |
59 | // in place and moving the extent. Matches NSTextView. |
60 | bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; } |
61 | |
62 | // On Mac, when processing a contextual click, the object being clicked upon should be selected. |
63 | bool () const { return m_type == EditingMacBehavior || m_type == EditingIOSBehavior; } |
64 | |
65 | // On Linux, should be able to get and insert spelling suggestions without selecting the misspelled word. |
66 | bool shouldAllowSpellingSuggestionsWithoutSelection() const |
67 | { |
68 | return m_type == EditingUnixBehavior; |
69 | } |
70 | |
71 | // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back. |
72 | bool shouldNavigateBackOnBackspace() const |
73 | { |
74 | return m_type != EditingUnixBehavior; |
75 | } |
76 | |
77 | // On Mac, selecting backwards by word/line from the middle of a word/line, and then going |
78 | // forward leaves the caret back in the middle with no selection, instead of directly selecting |
79 | // to the other end of the line/word (Unix/Windows behavior). |
80 | bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior && m_type != EditingIOSBehavior; } |
81 | |
82 | // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, ctrl(alt)+left arrow moves caret to |
83 | // immediately before the word in all platforms, for example, the word break positions are: "|abc |def |hij |opq". |
84 | // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "abc| def| hij| opq|" on Mac and Linux. |
85 | bool shouldSkipSpaceWhenMovingRight() const { return m_type == EditingWindowsBehavior; } |
86 | |
87 | // On iOS the last entered character in a secure filed is shown momentarily, removing and adding back the |
88 | // space when deleting password cause space been showed insecurely. |
89 | bool shouldRebalanceWhiteSpacesInSecureField() const { return m_type != EditingIOSBehavior; } |
90 | |
91 | bool shouldSelectBasedOnDictionaryLookup() const { return m_type == EditingMacBehavior; } |
92 | |
93 | // Linux and Windows always extend selections from the extent endpoint. |
94 | bool shouldAlwaysExtendSelectionFromExtentEndpoint() const { return m_type != EditingMacBehavior && m_type != EditingIOSBehavior; } |
95 | |
96 | // On iOS, we don't want to select all the text when focusing a field. Instead, match platform behavior by going to the end of the line. |
97 | bool shouldMoveSelectionToEndWhenFocusingTextInput() const { return m_type == EditingIOSBehavior; } |
98 | |
99 | // On iOS, when smart delete is on, it is always on, and should do not additional checks (i.e. WordGranularity). |
100 | bool shouldAlwaysSmartDelete() const { return m_type == EditingIOSBehavior; } |
101 | |
102 | // On iOS, we should turn on smart insert and delete and newlines around paragraphs to match UIKit behaviour. |
103 | bool shouldSmartInsertDeleteParagraphs() const { return m_type == EditingIOSBehavior; } |
104 | |
105 | private: |
106 | EditingBehaviorType m_type; |
107 | }; |
108 | |
109 | } // namespace WebCore |
110 | |