1 // Copyright 2012 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 #ifndef CHROME_COMMON_INSTANT_TYPES_H_ 6 #define CHROME_COMMON_INSTANT_TYPES_H_ 7 8 #include <string> 9 #include <utility> 10 11 #include "base/basictypes.h" 12 #include "base/strings/string16.h" 13 #include "chrome/common/autocomplete_match_type.h" 14 #include "content/public/common/page_transition_types.h" 15 #include "url/gurl.h" 16 17 // ID used by Instant code to refer to objects (e.g. Autocomplete results, Most 18 // Visited items) that the Instant page needs access to. 19 typedef int InstantRestrictedID; 20 21 const size_t kNoMatchIndex = -1; 22 23 // Ways that the Instant suggested text is autocompleted into the omnibox. 24 enum InstantCompleteBehavior { 25 // Autocomplete the suggestion immediately. 26 INSTANT_COMPLETE_NOW, 27 28 // Do not autocomplete the suggestion. The suggestion may still be displayed 29 // in the omnibox, but not made a part of the omnibox text by default (e.g., 30 // by displaying the suggestion as non-highlighted, non-selected gray text). 31 INSTANT_COMPLETE_NEVER, 32 33 // Treat the suggested text as the entire omnibox text, effectively replacing 34 // whatever the user has typed. 35 INSTANT_COMPLETE_REPLACE, 36 }; 37 38 // The type of suggestion provided by Instant. For example, if Instant suggests 39 // "yahoo.com", should that be considered a search string or a URL? 40 enum InstantSuggestionType { 41 INSTANT_SUGGESTION_SEARCH, 42 INSTANT_SUGGESTION_URL, 43 }; 44 45 // A wrapper to hold Instant suggested text and its metadata. 46 struct InstantSuggestion { 47 InstantSuggestion(); 48 InstantSuggestion(const string16& text, 49 InstantCompleteBehavior behavior, 50 InstantSuggestionType type, 51 const string16& query, 52 size_t autocomplete_match_index); 53 ~InstantSuggestion(); 54 55 // Full suggested text. 56 string16 text; 57 58 // Completion behavior for the suggestion. 59 InstantCompleteBehavior behavior; 60 61 // Is this a search or a URL suggestion? 62 InstantSuggestionType type; 63 64 // Query for which this suggestion was generated. May be set to empty string 65 // if unknown. 66 string16 query; 67 68 // Index of the AutocompleteMatch in AutocompleteResult. Used to get the 69 // metadata details of the suggested text from AutocompleteResult. Set to a 70 // positive value if the suggestion is displayed on the Local NTP and 71 // set to kNoMatchIndex if the suggestion is displayed on the 72 // Instant NTP. 73 size_t autocomplete_match_index; 74 }; 75 76 // Omnibox dropdown matches provided by the native autocomplete providers. 77 struct InstantAutocompleteResult { 78 InstantAutocompleteResult(); 79 ~InstantAutocompleteResult(); 80 81 // The provider name, as returned by AutocompleteProvider::GetName(). 82 string16 provider; 83 84 // The type of the result. 85 AutocompleteMatchType::Type type; 86 87 // The description (title), same as AutocompleteMatch::description. 88 string16 description; 89 90 // The URL of the match, same as AutocompleteMatch::destination_url. 91 string16 destination_url; 92 93 // The search query for this match. Only set for matches coming from 94 // SearchProvider. Populated using AutocompleteMatch::contents. 95 string16 search_query; 96 97 // The transition type to use when the user opens this match. Same as 98 // AutocompleteMatch::transition. 99 content::PageTransition transition; 100 101 // The relevance score of this match, same as AutocompleteMatch::relevance. 102 int relevance; 103 104 // The index of the match in AutocompleteResult. Used to get the instant 105 // suggestion metadata details. Set to kNoMatchIndex if the 106 // suggestion is displayed on the Instant NTP and set to a positive value if 107 // the suggestion is displayed on the Local NTP. 108 size_t autocomplete_match_index; 109 }; 110 111 // An InstantAutocompleteResult along with its assigned restricted ID. 112 typedef std::pair<InstantRestrictedID, InstantAutocompleteResult> 113 InstantAutocompleteResultIDPair; 114 115 // The alignment of the theme background image. 116 enum ThemeBackgroundImageAlignment { 117 THEME_BKGRND_IMAGE_ALIGN_CENTER, 118 THEME_BKGRND_IMAGE_ALIGN_LEFT, 119 THEME_BKGRND_IMAGE_ALIGN_TOP, 120 THEME_BKGRND_IMAGE_ALIGN_RIGHT, 121 THEME_BKGRND_IMAGE_ALIGN_BOTTOM, 122 }; 123 124 // The tiling of the theme background image. 125 enum ThemeBackgroundImageTiling { 126 THEME_BKGRND_IMAGE_NO_REPEAT, 127 THEME_BKGRND_IMAGE_REPEAT_X, 128 THEME_BKGRND_IMAGE_REPEAT_Y, 129 THEME_BKGRND_IMAGE_REPEAT, 130 }; 131 132 // The RGBA color components for the text and links of the theme. 133 struct RGBAColor { 134 RGBAColor(); 135 ~RGBAColor(); 136 137 bool operator==(const RGBAColor& rhs) const; 138 139 // The color in RGBA format where the R, G, B and A values 140 // are between 0 and 255 inclusive and always valid. 141 uint8 r; 142 uint8 g; 143 uint8 b; 144 uint8 a; 145 }; 146 147 // Theme background settings for the NTP. 148 struct ThemeBackgroundInfo { 149 ThemeBackgroundInfo(); 150 ~ThemeBackgroundInfo(); 151 152 bool operator==(const ThemeBackgroundInfo& rhs) const; 153 154 // True if the default theme is selected. 155 bool using_default_theme; 156 157 // The theme background color in RGBA format always valid. 158 RGBAColor background_color; 159 160 // The theme text color in RGBA format. 161 RGBAColor text_color; 162 163 // The theme link color in RGBA format. 164 RGBAColor link_color; 165 166 // The theme text color light in RGBA format. 167 RGBAColor text_color_light; 168 169 // The theme color for the header in RGBA format. 170 RGBAColor header_color; 171 172 // The theme color for the section border in RGBA format. 173 RGBAColor section_border_color; 174 175 // The theme id for the theme background image. 176 // Value is only valid if there's a custom theme background image. 177 std::string theme_id; 178 179 // The theme background image horizontal alignment is only valid if |theme_id| 180 // is valid. 181 ThemeBackgroundImageAlignment image_horizontal_alignment; 182 183 // The theme background image vertical alignment is only valid if |theme_id| 184 // is valid. 185 ThemeBackgroundImageAlignment image_vertical_alignment; 186 187 // The theme background image tiling is only valid if |theme_id| is valid. 188 ThemeBackgroundImageTiling image_tiling; 189 190 // The theme background image height. 191 // Value is only valid if |theme_id| is valid. 192 uint16 image_height; 193 194 // True if theme has attribution logo. 195 // Value is only valid if |theme_id| is valid. 196 bool has_attribution; 197 198 // True if theme has an alternate logo. 199 bool logo_alternate; 200 }; 201 202 struct InstantMostVisitedItem { 203 // The URL of the Most Visited item. 204 GURL url; 205 206 // The title of the Most Visited page. May be empty, in which case the |url| 207 // is used as the title. 208 string16 title; 209 }; 210 211 // An InstantMostVisitedItem along with its assigned restricted ID. 212 typedef std::pair<InstantRestrictedID, InstantMostVisitedItem> 213 InstantMostVisitedItemIDPair; 214 215 #endif // CHROME_COMMON_INSTANT_TYPES_H_ 216