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