| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // An object to store user feedback to a single spellcheck suggestion. | 5 // An object to store user feedback to a single spellcheck suggestion. |
| 6 // | 6 // |
| 7 // Stores the spellcheck suggestion, its uint32 hash identifier, and user's | 7 // Stores the spellcheck suggestion, its uint32_t hash identifier, and user's |
| 8 // feedback. The feedback is indirect, in the sense that we record 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. | 9 // |action| instead of asking them how they feel about a spellcheck suggestion. |
| 10 // The object can serialize itself. | 10 // The object can serialize itself. |
| 11 | 11 |
| 12 #ifndef CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ | 12 #ifndef CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ |
| 13 #define CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ | 13 #define CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ |
| 14 | 14 |
| 15 #include <stddef.h> |
| 16 #include <stdint.h> |
| 17 |
| 15 #include <vector> | 18 #include <vector> |
| 16 | 19 |
| 17 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 18 #include "chrome/browser/spellchecker/spellcheck_action.h" | 21 #include "chrome/browser/spellchecker/spellcheck_action.h" |
| 19 | 22 |
| 20 // Stores user feedback to a spellcheck suggestion. Sample usage: | 23 // Stores user feedback to a spellcheck suggestion. Sample usage: |
| 21 // Misspelling misspelling. | 24 // Misspelling misspelling. |
| 22 // misspelling.context = base::ASCIIToUTF16("Helllo world"); | 25 // misspelling.context = base::ASCIIToUTF16("Helllo world"); |
| 23 // misspelling.location = 0; | 26 // misspelling.location = 0; |
| 24 // misspelling.length = 6; | 27 // misspelling.length = 6; |
| 25 // misspelling.suggestions = | 28 // misspelling.suggestions = |
| 26 // std::vector<base::string16>(1, base::ASCIIToUTF16("Hello")); | 29 // std::vector<base::string16>(1, base::ASCIIToUTF16("Hello")); |
| 27 // misspelling.hash = GenerateRandomHash(); | 30 // misspelling.hash = GenerateRandomHash(); |
| 28 // misspelling.action.set_type(SpellcheckAction::TYPE_SELECT); | 31 // misspelling.action.set_type(SpellcheckAction::TYPE_SELECT); |
| 29 // misspelling.action.set_index(0); | 32 // misspelling.action.set_index(0); |
| 30 // Process(SerializeMisspelling(misspelling)); | 33 // Process(SerializeMisspelling(misspelling)); |
| 31 struct Misspelling { | 34 struct Misspelling { |
| 32 Misspelling(); | 35 Misspelling(); |
| 33 Misspelling(const base::string16& context, | 36 Misspelling(const base::string16& context, |
| 34 size_t location, | 37 size_t location, |
| 35 size_t length, | 38 size_t length, |
| 36 const std::vector<base::string16>& suggestions, | 39 const std::vector<base::string16>& suggestions, |
| 37 uint32 hash); | 40 uint32_t hash); |
| 38 ~Misspelling(); | 41 ~Misspelling(); |
| 39 | 42 |
| 40 // A several-word text snippet that immediately surrounds the misspelling. | 43 // A several-word text snippet that immediately surrounds the misspelling. |
| 41 base::string16 context; | 44 base::string16 context; |
| 42 | 45 |
| 43 // The number of characters between the beginning of |context| and the first | 46 // The number of characters between the beginning of |context| and the first |
| 44 // misspelled character. | 47 // misspelled character. |
| 45 size_t location; | 48 size_t location; |
| 46 | 49 |
| 47 // The number of characters in the misspelling. | 50 // The number of characters in the misspelling. |
| 48 size_t length; | 51 size_t length; |
| 49 | 52 |
| 50 // Spelling suggestions. | 53 // Spelling suggestions. |
| 51 std::vector<base::string16> suggestions; | 54 std::vector<base::string16> suggestions; |
| 52 | 55 |
| 53 // The hash that identifies the misspelling. | 56 // The hash that identifies the misspelling. |
| 54 uint32 hash; | 57 uint32_t hash; |
| 55 | 58 |
| 56 // User action. | 59 // User action. |
| 57 SpellcheckAction action; | 60 SpellcheckAction action; |
| 58 | 61 |
| 59 // The time when the user applied the action. | 62 // The time when the user applied the action. |
| 60 base::Time timestamp; | 63 base::Time timestamp; |
| 61 }; | 64 }; |
| 62 | 65 |
| 63 // Serializes the data in this object into a dictionary value. The caller owns | 66 // Serializes the data in this object into a dictionary value. The caller owns |
| 64 // the result. | 67 // the result. |
| 65 base::DictionaryValue* SerializeMisspelling(const Misspelling& misspelling); | 68 base::DictionaryValue* SerializeMisspelling(const Misspelling& misspelling); |
| 66 | 69 |
| 67 // Returns the substring of |context| that begins at |location| and contains | 70 // Returns the substring of |context| that begins at |location| and contains |
| 68 // |length| characters. | 71 // |length| characters. |
| 69 base::string16 GetMisspelledString(const Misspelling& misspelling); | 72 base::string16 GetMisspelledString(const Misspelling& misspelling); |
| 70 | 73 |
| 71 // Returns the approximate size of the misspelling when serialized. | 74 // Returns the approximate size of the misspelling when serialized. |
| 72 size_t ApproximateSerializedSize(const Misspelling& misspelling); | 75 size_t ApproximateSerializedSize(const Misspelling& misspelling); |
| 73 | 76 |
| 74 #endif // CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ | 77 #endif // CHROME_BROWSER_SPELLCHECKER_MISSPELLING_H_ |
| OLD | NEW |