OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
3 * Copyright (C) 2010 Apple Inc. All rights reserved. | 3 * Copyright (C) 2010 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace blink { | 28 namespace blink { |
29 class KeyboardEvent; | 29 class KeyboardEvent; |
30 | 30 |
31 class CORE_EXPORT EditingBehavior { | 31 class CORE_EXPORT EditingBehavior { |
32 STACK_ALLOCATED(); | 32 STACK_ALLOCATED(); |
33 | 33 |
34 public: | 34 public: |
35 explicit EditingBehavior(EditingBehaviorType type) : m_type(type) {} | 35 explicit EditingBehavior(EditingBehaviorType type) : m_type(type) {} |
36 | 36 |
37 // Individual functions for each case where we have more than one style of edi
ting behavior. | 37 // Individual functions for each case where we have more than one style of |
38 // Create a new function for any platform difference so we can control it here
. | 38 // editing behavior. Create a new function for any platform difference so we |
| 39 // can control it here. |
39 | 40 |
40 // When extending a selection beyond the top or bottom boundary of an editable
area, | 41 // When extending a selection beyond the top or bottom boundary of an editable |
41 // maintain the horizontal position on Windows and Android but extend it to th
e boundary of | 42 // area, maintain the horizontal position on Windows and Android but extend it |
42 // the editable content on Mac and Linux. | 43 // to the boundary of the editable content on Mac and Linux. |
43 bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const { | 44 bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const { |
44 return m_type != EditingWindowsBehavior && m_type != EditingAndroidBehavior; | 45 return m_type != EditingWindowsBehavior && m_type != EditingAndroidBehavior; |
45 } | 46 } |
46 | 47 |
47 bool shouldSelectReplacement() const { | 48 bool shouldSelectReplacement() const { |
48 return m_type == EditingAndroidBehavior; | 49 return m_type == EditingAndroidBehavior; |
49 } | 50 } |
50 | 51 |
51 // On Windows, selections should always be considered as directional, regardle
ss if it is | 52 // On Windows, selections should always be considered as directional, |
52 // mouse-based or keyboard-based. | 53 // regardless if it is mouse-based or keyboard-based. |
53 bool shouldConsiderSelectionAsDirectional() const { | 54 bool shouldConsiderSelectionAsDirectional() const { |
54 return m_type != EditingMacBehavior; | 55 return m_type != EditingMacBehavior; |
55 } | 56 } |
56 | 57 |
57 // On Mac, when revealing a selection (for example as a result of a Find opera
tion on the Browser), | 58 // On Mac, when revealing a selection (for example as a result of a Find |
58 // content should be scrolled such that the selection gets certer aligned. | 59 // operation on the Browser), content should be scrolled such that the |
| 60 // selection gets certer aligned. |
59 bool shouldCenterAlignWhenSelectionIsRevealed() const { | 61 bool shouldCenterAlignWhenSelectionIsRevealed() const { |
60 return m_type == EditingMacBehavior; | 62 return m_type == EditingMacBehavior; |
61 } | 63 } |
62 | 64 |
63 // On Mac, style is considered present when present at the beginning of select
ion. On other platforms, | 65 // On Mac, style is considered present when present at the beginning of |
64 // style has to be present throughout the selection. | 66 // selection. On other platforms, style has to be present throughout the |
| 67 // selection. |
65 bool shouldToggleStyleBasedOnStartOfSelection() const { | 68 bool shouldToggleStyleBasedOnStartOfSelection() const { |
66 return m_type == EditingMacBehavior; | 69 return m_type == EditingMacBehavior; |
67 } | 70 } |
68 | 71 |
69 // Standard Mac behavior when extending to a boundary is grow the selection ra
ther than leaving the base | 72 // Standard Mac behavior when extending to a boundary is grow the selection |
70 // in place and moving the extent. Matches NSTextView. | 73 // rather than leaving the base in place and moving the extent. Matches |
| 74 // NSTextView. |
71 bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { | 75 bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { |
72 return m_type == EditingMacBehavior; | 76 return m_type == EditingMacBehavior; |
73 } | 77 } |
74 | 78 |
75 // On Mac, when processing a contextual click, the object being clicked upon s
hould be selected. | 79 // On Mac, when processing a contextual click, the object being clicked upon |
| 80 // should be selected. |
76 bool shouldSelectOnContextualMenuClick() const { | 81 bool shouldSelectOnContextualMenuClick() const { |
77 return m_type == EditingMacBehavior; | 82 return m_type == EditingMacBehavior; |
78 } | 83 } |
79 | 84 |
80 // On Mac and Windows, pressing backspace (when it isn't handled otherwise) sh
ould navigate back. | 85 // On Mac and Windows, pressing backspace (when it isn't handled otherwise) |
| 86 // should navigate back. |
81 bool shouldNavigateBackOnBackspace() const { | 87 bool shouldNavigateBackOnBackspace() const { |
82 return m_type != EditingUnixBehavior && m_type != EditingAndroidBehavior; | 88 return m_type != EditingUnixBehavior && m_type != EditingAndroidBehavior; |
83 } | 89 } |
84 | 90 |
85 // On Mac, selecting backwards by word/line from the middle of a word/line, an
d then going | 91 // On Mac, selecting backwards by word/line from the middle of a word/line, |
86 // forward leaves the caret back in the middle with no selection, instead of d
irectly selecting | 92 // and then going forward leaves the caret back in the middle with no |
87 // to the other end of the line/word (Unix/Windows behavior). | 93 // selection, instead of directly selecting to the other end of the line/word |
| 94 // (Unix/Windows behavior). |
88 bool shouldExtendSelectionByWordOrLineAcrossCaret() const { | 95 bool shouldExtendSelectionByWordOrLineAcrossCaret() const { |
89 return m_type != EditingMacBehavior; | 96 return m_type != EditingMacBehavior; |
90 } | 97 } |
91 | 98 |
92 // Based on native behavior, when using ctrl(alt)+arrow to move caret by word,
ctrl(alt)+left arrow moves caret to | 99 // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, |
93 // immediately before the word in all platforms, for example, the word break p
ositions are: "|abc |def |hij |opq". | 100 // ctrl(alt)+left arrow moves caret to immediately before the word in all |
94 // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "ab
c| def| hij| opq|" on Mac and Linux. | 101 // platforms. For example, the word break positions are: |
| 102 // "|abc |def |hij |opq". |
| 103 // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and |
| 104 // "abc| def| hij| opq|" on Mac and Linux. |
95 bool shouldSkipSpaceWhenMovingRight() const { | 105 bool shouldSkipSpaceWhenMovingRight() const { |
96 return m_type == EditingWindowsBehavior; | 106 return m_type == EditingWindowsBehavior; |
97 } | 107 } |
98 | 108 |
99 // On Mac, undo of delete/forward-delete of text should select the deleted tex
t. On other platforms deleted text | 109 // On Mac, undo of delete/forward-delete of text should select the deleted |
100 // should not be selected and the cursor should be placed where the deletion s
tarted. | 110 // text. On other platforms deleted text should not be selected and the cursor |
| 111 // should be placed where the deletion started. |
101 bool shouldUndoOfDeleteSelectText() const { | 112 bool shouldUndoOfDeleteSelectText() const { |
102 return m_type == EditingMacBehavior; | 113 return m_type == EditingMacBehavior; |
103 } | 114 } |
104 | 115 |
105 // Support for global selections, used on platforms like the X Window | 116 // Support for global selections, used on platforms like the X Window |
106 // System that treat selection as a type of clipboard. | 117 // System that treat selection as a type of clipboard. |
107 bool supportsGlobalSelection() const { | 118 bool supportsGlobalSelection() const { |
108 return m_type != EditingWindowsBehavior && m_type != EditingMacBehavior; | 119 return m_type != EditingWindowsBehavior && m_type != EditingMacBehavior; |
109 } | 120 } |
110 | 121 |
111 // Convert a KeyboardEvent to a command name like "Copy", "Undo" and so on. | 122 // Convert a KeyboardEvent to a command name like "Copy", "Undo" and so on. |
112 // If nothing, return empty string. | 123 // If nothing, return empty string. |
113 const char* interpretKeyEvent(const KeyboardEvent&) const; | 124 const char* interpretKeyEvent(const KeyboardEvent&) const; |
114 | 125 |
115 bool shouldInsertCharacter(const KeyboardEvent&) const; | 126 bool shouldInsertCharacter(const KeyboardEvent&) const; |
116 | 127 |
117 private: | 128 private: |
118 EditingBehaviorType m_type; | 129 EditingBehaviorType m_type; |
119 }; | 130 }; |
120 | 131 |
121 } // namespace blink | 132 } // namespace blink |
122 | 133 |
123 #endif // EditingBehavior_h | 134 #endif // EditingBehavior_h |
OLD | NEW |