blob: 36a9cdbee01a406e981105790ed60e2c4971f966 [file] [log] [blame]
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +01001// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Ben Murdochbb1529c2013-08-08 10:24:53 +01004//
5// An object to store user feedback to a single spellcheck suggestion.
6//
7// Stores the spellcheck suggestion, its uint32 hash identifier, and user's
8// feedback. The feedback is indirect, in the sense that we record user's
9// |action| instead of asking them how they feel about a spellcheck suggestion.
10// The object can serialize itself.
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010011
12#ifndef CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_
13#define CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_
14
15#include <vector>
16
Ben Murdocheb525c52013-07-10 11:40:50 +010017#include "base/time/time.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010018#include "chrome/browser/spellchecker/spellcheck_action.h"
19
Ben Murdochbb1529c2013-08-08 10:24:53 +010020// Stores user feedback to a spellcheck suggestion. Sample usage:
21// Misspelling misspelling.
22// misspelling.context = ASCIIToUTF16("Helllo world");
23// misspelling.location = 0;
24// misspelling.length = 6;
25// misspelling.suggestions = std::vector<string16>(1, ASCIIToUTF16("Hello"));
26// misspelling.hash = GenerateRandomHash();
27// misspelling.action.type = SpellcheckAction::TYPE_SELECT;
28// misspelling.action.index = 0;
29// Process(misspelling.Serialize());
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010030class Misspelling {
31 public:
32 Misspelling();
33 Misspelling(const string16& context,
34 size_t location,
35 size_t length,
36 const std::vector<string16>& suggestions,
37 uint32 hash);
38 ~Misspelling();
39
40 // Serializes the data in this object into a dictionary value. The caller owns
41 // the result.
42 base::DictionaryValue* Serialize() const;
43
Ben Murdochbb1529c2013-08-08 10:24:53 +010044 // Returns the substring of |context| that begins at |location| and contains
45 // |length| characters.
46 string16 GetMisspelledString() const;
47
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010048 // A several-word text snippet that immediately surrounds the misspelling.
49 string16 context;
50
51 // The number of characters between the beginning of |context| and the first
52 // misspelled character.
53 size_t location;
54
55 // The number of characters in the misspelling.
56 size_t length;
57
58 // Spelling suggestions.
59 std::vector<string16> suggestions;
60
61 // The hash that identifies the misspelling.
62 uint32 hash;
63
64 // User action.
65 SpellcheckAction action;
66
67 // The time when the user applied the action.
68 base::Time timestamp;
69};
70
71#endif // CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_