2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3 * Copyright (C) 2010 Apple Inc. All rights reserved.
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.
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.
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.
21 #ifndef EditingBehavior_h
22 #define EditingBehavior_h
24 #include "core/CoreExport.h"
25 #include "core/editing/EditingBehaviorTypes.h"
26 #include "wtf/Allocator.h"
31 class CORE_EXPORT EditingBehavior
{
34 explicit EditingBehavior(EditingBehaviorType type
)
39 // Individual functions for each case where we have more than one style of editing behavior.
40 // Create a new function for any platform difference so we can control it here.
42 // When extending a selection beyond the top or bottom boundary of an editable area,
43 // maintain the horizontal position on Windows and Android but extend it to the boundary of
44 // the editable content on Mac and Linux.
45 bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const
47 return m_type
!= EditingWindowsBehavior
&& m_type
!= EditingAndroidBehavior
;
50 // On Windows, selections should always be considered as directional, regardless if it is
51 // mouse-based or keyboard-based.
52 bool shouldConsiderSelectionAsDirectional() const { return m_type
!= EditingMacBehavior
; }
54 // On Mac, when revealing a selection (for example as a result of a Find operation on the Browser),
55 // content should be scrolled such that the selection gets certer aligned.
56 bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type
== EditingMacBehavior
; }
58 // On Mac, style is considered present when present at the beginning of selection. On other platforms,
59 // style has to be present throughout the selection.
60 bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type
== EditingMacBehavior
; }
62 // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the base
63 // in place and moving the extent. Matches NSTextView.
64 bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type
== EditingMacBehavior
; }
66 // On Mac, when processing a contextual click, the object being clicked upon should be selected.
67 bool shouldSelectOnContextualMenuClick() const { return m_type
== EditingMacBehavior
; }
69 // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back.
70 bool shouldNavigateBackOnBackspace() const
72 return m_type
!= EditingUnixBehavior
&& m_type
!= EditingAndroidBehavior
;
75 // On Mac, selecting backwards by word/line from the middle of a word/line, and then going
76 // forward leaves the caret back in the middle with no selection, instead of directly selecting
77 // to the other end of the line/word (Unix/Windows behavior).
78 bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type
!= EditingMacBehavior
; }
80 // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, ctrl(alt)+left arrow moves caret to
81 // immediately before the word in all platforms, for example, the word break positions are: "|abc |def |hij |opq".
82 // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "abc| def| hij| opq|" on Mac and Linux.
83 bool shouldSkipSpaceWhenMovingRight() const { return m_type
== EditingWindowsBehavior
; }
85 // On Mac, undo of delete/forward-delete of text should select the deleted text. On other platforms deleted text
86 // should not be selected and the cursor should be placed where the deletion started.
87 bool shouldUndoOfDeleteSelectText() const { return m_type
== EditingMacBehavior
; }
89 // Support for global selections, used on platforms like the X Window
90 // System that treat selection as a type of clipboard.
91 bool supportsGlobalSelection() const
93 return m_type
!= EditingWindowsBehavior
&& m_type
!= EditingMacBehavior
;
96 // Convert a KeyboardEvent to a command name like "Copy", "Undo" and so on.
97 // If nothing, return empty string.
98 const char* interpretKeyEvent(const KeyboardEvent
&) const;
100 bool shouldInsertCharacter(const KeyboardEvent
&) const;
102 EditingBehaviorType m_type
;
107 #endif // EditingBehavior_h