18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This file is part of the DOM implementation for WebCore.
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2006 Apple Computer, Inc.
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is free software; you can redistribute it and/or
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modify it under the terms of the GNU Library General Public
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * License as published by the Free Software Foundation; either
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * version 2 of the License, or (at your option) any later version.
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * This library is distributed in the hope that it will be useful,
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * but WITHOUT ANY WARRANTY; without even the implied warranty of
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Library General Public License for more details.
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * You should have received a copy of the GNU Library General Public License
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * along with this library; see the file COPYING.LIB.  If not, write to
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Boston, MA 02110-1301, USA.
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef DocumentMarker_h
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define DocumentMarker_h
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "PlatformString.h"
27dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch#include <wtf/Forward.h>
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// A range of a node within a document that is "marked", such as the range of a misspelled word.
328e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project// It optionally includes a description that could be displayed in the user interface.
335f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian// It also optionally includes a flag specifying whether the match is active, which is ignored
345f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian// for all types other than type TextMatch.
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectstruct DocumentMarker {
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    enum MarkerType {
37e14391e94c850b8bd03680c23b38978db68687a8John Reck        Spelling = 1 << 0,
38e14391e94c850b8bd03680c23b38978db68687a8John Reck        Grammar = 1 << 1,
39e14391e94c850b8bd03680c23b38978db68687a8John Reck        TextMatch = 1 << 2,
402daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // Text has been modified by spell correction, reversion of spell correction or other type of substitution.
412daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // On some platforms, this prevents the text from being autocorrected again. On post Snow Leopard Mac OS X,
422daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // if a Replacement marker contains non-empty description, a reversion UI will be shown.
43e14391e94c850b8bd03680c23b38978db68687a8John Reck        Replacement = 1 << 3,
442fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // Renderer needs to add underline indicating that the text has been modified by spell
452fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // correction. Text with Replacement marker doesn't necessarily has CorrectionIndicator
462fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // marker. For instance, after some text has been corrected, it will have both Replacement
472fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // and CorrectionIndicator. However, if user further modifies such text, we would remove
482fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // CorrectionIndicator marker, but retain Replacement marker.
49e14391e94c850b8bd03680c23b38978db68687a8John Reck        CorrectionIndicator = 1 << 4,
502fc2651226baac27029e38c9d6ef883fa32084dbSteve Block        // Correction suggestion has been offered, but got rejected by user.
51e14391e94c850b8bd03680c23b38978db68687a8John Reck        RejectedCorrection = 1 << 5,
522daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // Text has been modified by autocorrection. The description of this marker is the original text before autocorrection.
532daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        Autocorrected = 1 << 6,
542daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // On some platforms, this prevents the text from being spellchecked again.
552daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        SpellCheckingExemption = 1 << 7,
568e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    };
572daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
582daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    class MarkerTypes {
592daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    public:
602daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        // The constructor is intentionally implicit to allow conversion from the bit-wise sum of above types
612daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        MarkerTypes(unsigned mask) : m_mask(mask) { }
622daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
632daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        bool contains(MarkerType type) const { return m_mask & type; }
642daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        bool intersects(const MarkerTypes& types) const { return (m_mask & types.m_mask); }
652daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        bool operator==(const MarkerTypes& other) const { return m_mask == other.m_mask; }
662daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
672daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        void add(const MarkerTypes& types) { m_mask |= types.m_mask; }
682daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; }
692daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
702daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    private:
712daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        unsigned m_mask;
722daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    };
732daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
742daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    class AllMarkers : public MarkerTypes {
752daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    public:
762daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        AllMarkers()
772daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch            : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption)
782daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        {
792daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch        }
802daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch    };
812daae5fd11344eaa88a0d92b0f6d65f8d2255c00Ben Murdoch
828e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    MarkerType type;
838e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned startOffset;
848e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned endOffset;
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    String description;
865f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian    bool activeMatch;
878e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
888e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool operator==(const DocumentMarker& o) const
898e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    {
908e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return type == o.type && startOffset == o.startOffset && endOffset == o.endOffset;
918e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
928e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
938e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool operator!=(const DocumentMarker& o) const
948e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    {
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project        return !(*this == o);
968e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    }
978e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
998e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1018e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // DocumentMarker_h
102