Home | History | Annotate | Download | only in editing
      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 "core/editing/EditingBehaviorTypes.h"
     25 
     26 namespace WebCore {
     27 
     28 class EditingBehavior {
     29 
     30 public:
     31     explicit 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.
     42     bool shouldMoveCaretToHorizontalBoundaryWhenPastTopOrBottom() const
     43     {
     44         return m_type != EditingWindowsBehavior && m_type != EditingAndroidBehavior && m_type != EditingUnixBehavior;
     45     }
     46 
     47     // On Windows, selections should always be considered as directional, regardless if it is
     48     // mouse-based or keyboard-based.
     49     bool shouldConsiderSelectionAsDirectional() const { return m_type != EditingMacBehavior; }
     50 
     51     // On Mac, when revealing a selection (for example as a result of a Find operation on the Browser),
     52     // content should be scrolled such that the selection gets certer aligned.
     53     bool shouldCenterAlignWhenSelectionIsRevealed() const { return m_type == EditingMacBehavior; }
     54 
     55     // On Mac, style is considered present when present at the beginning of selection. On other platforms,
     56     // style has to be present throughout the selection.
     57     bool shouldToggleStyleBasedOnStartOfSelection() const { return m_type == EditingMacBehavior; }
     58 
     59     // Standard Mac behavior when extending to a boundary is grow the selection rather than leaving the base
     60     // in place and moving the extent. Matches NSTextView.
     61     bool shouldAlwaysGrowSelectionWhenExtendingToBoundary() const { return m_type == EditingMacBehavior; }
     62 
     63     // On Mac, when processing a contextual click, the object being clicked upon should be selected.
     64     bool shouldSelectOnContextualMenuClick() const { return m_type == EditingMacBehavior; }
     65 
     66     // On Mac and Windows, pressing backspace (when it isn't handled otherwise) should navigate back.
     67     bool shouldNavigateBackOnBackspace() const
     68     {
     69         return m_type != EditingUnixBehavior && m_type != EditingAndroidBehavior;
     70     }
     71 
     72     // On Mac, selecting backwards by word/line from the middle of a word/line, and then going
     73     // forward leaves the caret back in the middle with no selection, instead of directly selecting
     74     // to the other end of the line/word (Unix/Windows behavior).
     75     bool shouldExtendSelectionByWordOrLineAcrossCaret() const { return m_type != EditingMacBehavior; }
     76 
     77     // Based on native behavior, when using ctrl(alt)+arrow to move caret by word, ctrl(alt)+left arrow moves caret to
     78     // immediately before the word in all platforms, for example, the word break positions are: "|abc |def |hij |opq".
     79     // But ctrl+right arrow moves caret to "abc |def |hij |opq" on Windows and "abc| def| hij| opq|" on Mac and Linux.
     80     bool shouldSkipSpaceWhenMovingRight() const { return m_type == EditingWindowsBehavior; }
     81 
     82 private:
     83     EditingBehaviorType m_type;
     84 };
     85 
     86 } // namespace WebCore
     87 
     88 #endif // EditingBehavior_h
     89