Home | History | Annotate | Download | only in spellchecker
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chrome/browser/spellchecker/spellcheck_action.h"
      6 
      7 #include "base/logging.h"
      8 #include "base/values.h"
      9 
     10 SpellcheckAction::SpellcheckAction() : type(TYPE_PENDING), index(-1) {}
     11 
     12 SpellcheckAction::SpellcheckAction(SpellcheckActionType type,
     13                                    int index,
     14                                    string16 value)
     15     : type(type), index(index), value(value) {}
     16 
     17 SpellcheckAction::~SpellcheckAction() {}
     18 
     19 bool SpellcheckAction::IsFinal() const {
     20   return type == TYPE_ADD_TO_DICT ||
     21          type == TYPE_IGNORE ||
     22          type == TYPE_IN_DICTIONARY ||
     23          type == TYPE_MANUALLY_CORRECTED ||
     24          type == TYPE_NO_ACTION ||
     25          type == TYPE_SELECT;
     26 }
     27 
     28 void SpellcheckAction::Finalize() {
     29   switch (type) {
     30     case TYPE_PENDING:
     31       type = TYPE_NO_ACTION;
     32       break;
     33     case TYPE_PENDING_IGNORE:
     34       type = TYPE_IGNORE;
     35       break;
     36     default:
     37       DCHECK(IsFinal());
     38       break;
     39   }
     40 }
     41 
     42 base::DictionaryValue* SpellcheckAction::Serialize() const {
     43   base::DictionaryValue* result = new base::DictionaryValue;
     44   switch (type) {
     45     case TYPE_SELECT:
     46       result->SetString("actionType", "SELECT");
     47       result->SetInteger("actionTargetIndex", index);
     48       break;
     49     case TYPE_ADD_TO_DICT:
     50       result->SetString("actionType", "ADD_TO_DICT");
     51       break;
     52     case TYPE_IGNORE:
     53       result->SetString("actionType", "IGNORE");
     54       break;
     55     case TYPE_IN_DICTIONARY:
     56       result->SetString("actionType", "IN_DICTIONARY");
     57       break;
     58     case TYPE_NO_ACTION:
     59       result->SetString("actionType", "NO_ACTION");
     60       break;
     61     case TYPE_MANUALLY_CORRECTED:
     62       result->SetString("actionType", "MANUALLY_CORRECTED");
     63       result->SetString("actionTargetValue", value);
     64       break;
     65     case TYPE_PENDING:
     66     case TYPE_PENDING_IGNORE:
     67       result->SetString("actionType", "PENDING");
     68       break;
     69     default:
     70       NOTREACHED();
     71       break;
     72   }
     73   return result;
     74 }
     75