• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef EditingBehavior_h
22 #define EditingBehavior_h
23 
24 #include "EditingBehaviorTypes.h"
25 
26 namespace WebCore {
27 
28 class EditingBehavior {
29 
30 public:
EditingBehavior(EditingBehaviorType type)31     EditingBehavior(EditingBehaviorType type)
32         : m_type(type)
33     {
34     }
35 
36     // Individual functions for each case where we have more than one style of editing behavior.
37     // Create a new function for any platform difference so we can control it here.
38 
39     // When extending a selection beyond the top or bottom boundary of an editable area,
40     // maintain the horizontal position on Windows but extend it to the boundary of the editable
41     // content on Mac.
shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom()42     bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const { return m_type != EditingWindowsBehavior; }
43 
44     // On Windows, selections should always be considered as directional, regardless if it is
45     // mouse-based or keyboard-based.
shouldConsiderSelectionAsDirectional()46     bool shouldConsiderSelectionAsDirectional() const { return m_type != EditingMacBehavior; }
47 
48     // On Mac, when revealing a selection (for example as a result of a Find operation on the Browser),
49     // content should be scrolled such that the selection gets certer aligned.
shouldCenterAlignWhenSelectionIsRevealed()50     bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type == EditingMacBehavior; }
51 
52     // On Mac, style is considered present when present at the beginning of selection. On other platforms,
53     // style has to be present throughout the selection.
shouldToggleStyleBasedOnStartOfSelection()54     bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type == EditingMacBehavior; }
55 
56     // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the base
57     // in place and moving the extent. Matches NSTextView.
shouldAlwaysGrowSelectionWhenExtendingToBoundary()58     bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior; }
59 
60     // On Mac, when processing a contextual click, the object being clicked upon should be selected.
shouldSelectOnContextualMenuClick()61     bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
62 
63     // On Mac, when the web view loses focus, any active selection clears. On Windows, the selection
64     // should remain highlighted, just in an inactive state.
shouldClearSelectionWhenLosingWebPageFocus()65     bool shouldClearSelectionWhenLosingWebPageFocus() const { return m_type == EditingMacBehavior; }
66 
67 private:
68     EditingBehaviorType m_type;
69 };
70 
71 } // namespace WebCore
72 
73 #endif // EditingBehavior_h
74