| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 package org.chromium.chrome.browser.omnibox; | 5 package org.chromium.chrome.browser.omnibox; |
| 6 | 6 |
| 7 import android.text.TextUtils; | 7 import android.text.TextUtils; |
| 8 | 8 |
| 9 import com.google.common.annotations.VisibleForTesting; | 9 import com.google.common.annotations.VisibleForTesting; |
| 10 | 10 |
| 11 /** | 11 /** |
| 12 * Container class with information about each omnibox suggestion item. | 12 * Container class with information about each omnibox suggestion item. |
| 13 */ | 13 */ |
| 14 @VisibleForTesting | 14 @VisibleForTesting |
| 15 public class OmniboxSuggestion { | 15 public class OmniboxSuggestion { |
| 16 | 16 |
| 17 private final Type mType; | 17 private final Type mType; |
| 18 private final String mDisplayText; | 18 private final String mDisplayText; |
| 19 private final String mDescription; | 19 private final String mDescription; |
| 20 private final String mAnswerContents; |
| 21 private final String mAnswerType; |
| 20 private final String mFillIntoEdit; | 22 private final String mFillIntoEdit; |
| 21 private final String mUrl; | 23 private final String mUrl; |
| 22 private final String mFormattedUrl; | 24 private final String mFormattedUrl; |
| 23 private final int mRelevance; | 25 private final int mRelevance; |
| 24 private final int mTransition; | 26 private final int mTransition; |
| 25 private final boolean mIsStarred; | 27 private final boolean mIsStarred; |
| 26 private final boolean mIsDeletable; | 28 private final boolean mIsDeletable; |
| 27 | 29 |
| 28 /** | 30 /** |
| 29 * This should be kept in sync with AutocompleteMatch::Type | 31 * This should be kept in sync with AutocompleteMatch::Type |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 81 |
| 80 /** | 82 /** |
| 81 * @return The ID of the type used by the native code. | 83 * @return The ID of the type used by the native code. |
| 82 */ | 84 */ |
| 83 public int nativeType() { | 85 public int nativeType() { |
| 84 return mNativeType; | 86 return mNativeType; |
| 85 } | 87 } |
| 86 } | 88 } |
| 87 | 89 |
| 88 public OmniboxSuggestion(int nativeType, int relevance, int transition, | 90 public OmniboxSuggestion(int nativeType, int relevance, int transition, |
| 89 String text, String description, String fillIntoEdit, String url, | 91 String text, String description, String answerContents, |
| 92 String answerType, String fillIntoEdit, String url, |
| 90 String formattedUrl, boolean isStarred, boolean isDeletable) { | 93 String formattedUrl, boolean isStarred, boolean isDeletable) { |
| 91 mType = Type.getTypeFromNativeType(nativeType); | 94 mType = Type.getTypeFromNativeType(nativeType); |
| 92 mRelevance = relevance; | 95 mRelevance = relevance; |
| 93 mTransition = transition; | 96 mTransition = transition; |
| 94 mDisplayText = text; | 97 mDisplayText = text; |
| 95 mDescription = description; | 98 mDescription = description; |
| 99 mAnswerContents = answerContents; |
| 100 mAnswerType = answerType; |
| 96 mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? text : fillIntoEdit; | 101 mFillIntoEdit = TextUtils.isEmpty(fillIntoEdit) ? text : fillIntoEdit; |
| 97 mUrl = url; | 102 mUrl = url; |
| 98 mFormattedUrl = formattedUrl; | 103 mFormattedUrl = formattedUrl; |
| 99 mIsStarred = isStarred; | 104 mIsStarred = isStarred; |
| 100 mIsDeletable = isDeletable; | 105 mIsDeletable = isDeletable; |
| 101 } | 106 } |
| 102 | 107 |
| 108 /* TODO(groby): Remove - see http://crbug.com/375482 */ |
| 109 public OmniboxSuggestion(int nativeType, int relevance, int transition, |
| 110 String text, String description, String fillIntoEdit, String url, |
| 111 String formattedUrl, boolean isStarred, boolean isDeletable) { |
| 112 this(nativeType, relevance, transition, text, description, null, null, f
illIntoEdit, url, |
| 113 formattedUrl, isStarred, isDeletable); |
| 114 } |
| 115 |
| 103 public Type getType() { | 116 public Type getType() { |
| 104 return mType; | 117 return mType; |
| 105 } | 118 } |
| 106 | 119 |
| 107 public int getTransition() { | 120 public int getTransition() { |
| 108 return mTransition; | 121 return mTransition; |
| 109 } | 122 } |
| 110 | 123 |
| 111 public String getDisplayText() { | 124 public String getDisplayText() { |
| 112 return mDisplayText; | 125 return mDisplayText; |
| 113 } | 126 } |
| 114 | 127 |
| 115 public String getDescription() { | 128 public String getDescription() { |
| 116 return mDescription; | 129 return mDescription; |
| 117 } | 130 } |
| 118 | 131 |
| 132 public String getAnswerContents() { |
| 133 return mAnswerContents; |
| 134 } |
| 135 |
| 136 public String getAnswerType() { |
| 137 return mAnswerType; |
| 138 } |
| 139 |
| 119 public String getFillIntoEdit() { | 140 public String getFillIntoEdit() { |
| 120 return mFillIntoEdit; | 141 return mFillIntoEdit; |
| 121 } | 142 } |
| 122 | 143 |
| 123 public String getUrl() { | 144 public String getUrl() { |
| 124 return mUrl; | 145 return mUrl; |
| 125 } | 146 } |
| 126 | 147 |
| 127 public String getFormattedUrl() { | 148 public String getFormattedUrl() { |
| 128 return mFormattedUrl; | 149 return mFormattedUrl; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 143 return mIsDeletable; | 164 return mIsDeletable; |
| 144 } | 165 } |
| 145 | 166 |
| 146 @Override | 167 @Override |
| 147 public String toString() { | 168 public String toString() { |
| 148 return mType + " relevance=" + mRelevance + " \"" + mDisplayText + "\"
-> " + mUrl; | 169 return mType + " relevance=" + mRelevance + " \"" + mDisplayText + "\"
-> " + mUrl; |
| 149 } | 170 } |
| 150 | 171 |
| 151 @Override | 172 @Override |
| 152 public int hashCode() { | 173 public int hashCode() { |
| 153 return 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoEdit.
hashCode() + | 174 int hash = 37 * mType.mNativeType + mDisplayText.hashCode() + mFillIntoE
dit.hashCode() + |
| 154 (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); | 175 (mIsStarred ? 1 : 0) + (mIsDeletable ? 1 : 0); |
| 176 if (mAnswerContents != null) { |
| 177 hash = hash + mAnswerContents.hashCode(); |
| 178 } |
| 179 return hash; |
| 155 } | 180 } |
| 156 | 181 |
| 157 @Override | 182 @Override |
| 158 public boolean equals(Object obj) { | 183 public boolean equals(Object obj) { |
| 159 if (!(obj instanceof OmniboxSuggestion)) { | 184 if (!(obj instanceof OmniboxSuggestion)) { |
| 160 return false; | 185 return false; |
| 161 } | 186 } |
| 162 | 187 |
| 163 OmniboxSuggestion suggestion = (OmniboxSuggestion) obj; | 188 OmniboxSuggestion suggestion = (OmniboxSuggestion) obj; |
| 189 |
| 190 boolean answersAreEqual = |
| 191 (mAnswerContents == null && suggestion.mAnswerContents == null)
|| |
| 192 (mAnswerContents != null && |
| 193 suggestion.mAnswerContents != null && |
| 194 mAnswerContents.equals(suggestion.mAnswerContents)); |
| 164 return mType == suggestion.mType | 195 return mType == suggestion.mType |
| 165 && mFillIntoEdit.equals(suggestion.mFillIntoEdit) | 196 && mFillIntoEdit.equals(suggestion.mFillIntoEdit) |
| 166 && mDisplayText.equals(suggestion.mDisplayText) | 197 && mDisplayText.equals(suggestion.mDisplayText) |
| 198 && answersAreEqual |
| 167 && mIsStarred == suggestion.mIsStarred | 199 && mIsStarred == suggestion.mIsStarred |
| 168 && mIsDeletable == suggestion.mIsDeletable; | 200 && mIsDeletable == suggestion.mIsDeletable; |
| 169 } | 201 } |
| 170 } | 202 } |
| OLD | NEW |