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