• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // A wrapper to hold Instant suggested text and its metadata. Used to tell the
22 // server what suggestion to prefetch.
23 struct InstantSuggestion {
24   InstantSuggestion();
25   InstantSuggestion(const base::string16& in_text,
26                     const std::string& in_metadata);
27   ~InstantSuggestion();
28 
29   // Full suggested text.
30   base::string16 text;
31 
32   // JSON metadata from the server response which produced this suggestion.
33   std::string metadata;
34 };
35 
36 // Omnibox dropdown matches provided by the native autocomplete providers.
37 struct InstantAutocompleteResult {
38   InstantAutocompleteResult();
39   ~InstantAutocompleteResult();
40 
41   // The provider name, as returned by AutocompleteProvider::GetName().
42   base::string16 provider;
43 
44   // The type of the result.
45   AutocompleteMatchType::Type type;
46 
47   // The description (title), same as AutocompleteMatch::description.
48   base::string16 description;
49 
50   // The URL of the match, same as AutocompleteMatch::destination_url.
51   base::string16 destination_url;
52 
53   // The search query for this match. Only set for matches coming from
54   // SearchProvider. Populated using AutocompleteMatch::contents.
55   base::string16 search_query;
56 
57   // The transition type to use when the user opens this match. Same as
58   // AutocompleteMatch::transition.
59   content::PageTransition transition;
60 
61   // The relevance score of this match, same as AutocompleteMatch::relevance.
62   int relevance;
63 
64   // The index of the match in AutocompleteResult. Used to get the instant
65   // suggestion metadata details. Set to kNoMatchIndex if the
66   // suggestion is displayed on the Instant NTP and set to a positive value if
67   // the suggestion is displayed on the Local NTP.
68   size_t autocomplete_match_index;
69 };
70 
71 // An InstantAutocompleteResult along with its assigned restricted ID.
72 typedef std::pair<InstantRestrictedID, InstantAutocompleteResult>
73     InstantAutocompleteResultIDPair;
74 
75 // The alignment of the theme background image.
76 enum ThemeBackgroundImageAlignment {
77   THEME_BKGRND_IMAGE_ALIGN_CENTER,
78   THEME_BKGRND_IMAGE_ALIGN_LEFT,
79   THEME_BKGRND_IMAGE_ALIGN_TOP,
80   THEME_BKGRND_IMAGE_ALIGN_RIGHT,
81   THEME_BKGRND_IMAGE_ALIGN_BOTTOM,
82 };
83 
84 // The tiling of the theme background image.
85 enum ThemeBackgroundImageTiling {
86   THEME_BKGRND_IMAGE_NO_REPEAT,
87   THEME_BKGRND_IMAGE_REPEAT_X,
88   THEME_BKGRND_IMAGE_REPEAT_Y,
89   THEME_BKGRND_IMAGE_REPEAT,
90 };
91 
92 // The RGBA color components for the text and links of the theme.
93 struct RGBAColor {
94   RGBAColor();
95   ~RGBAColor();
96 
97   bool operator==(const RGBAColor& rhs) const;
98 
99   // The color in RGBA format where the R, G, B and A values
100   // are between 0 and 255 inclusive and always valid.
101   uint8 r;
102   uint8 g;
103   uint8 b;
104   uint8 a;
105 };
106 
107 // Theme background settings for the NTP.
108 struct ThemeBackgroundInfo {
109   ThemeBackgroundInfo();
110   ~ThemeBackgroundInfo();
111 
112   bool operator==(const ThemeBackgroundInfo& rhs) const;
113 
114   // True if the default theme is selected.
115   bool using_default_theme;
116 
117   // The theme background color in RGBA format always valid.
118   RGBAColor background_color;
119 
120   // The theme text color in RGBA format.
121   RGBAColor text_color;
122 
123   // The theme link color in RGBA format.
124   RGBAColor link_color;
125 
126   // The theme text color light in RGBA format.
127   RGBAColor text_color_light;
128 
129   // The theme color for the header in RGBA format.
130   RGBAColor header_color;
131 
132   // The theme color for the section border in RGBA format.
133   RGBAColor section_border_color;
134 
135   // The theme id for the theme background image.
136   // Value is only valid if there's a custom theme background image.
137   std::string theme_id;
138 
139   // The theme background image horizontal alignment is only valid if |theme_id|
140   // is valid.
141   ThemeBackgroundImageAlignment image_horizontal_alignment;
142 
143   // The theme background image vertical alignment is only valid if |theme_id|
144   // is valid.
145   ThemeBackgroundImageAlignment image_vertical_alignment;
146 
147   // The theme background image tiling is only valid if |theme_id| is valid.
148   ThemeBackgroundImageTiling image_tiling;
149 
150   // The theme background image height.
151   // Value is only valid if |theme_id| is valid.
152   uint16 image_height;
153 
154   // True if theme has attribution logo.
155   // Value is only valid if |theme_id| is valid.
156   bool has_attribution;
157 
158   // True if theme has an alternate logo.
159   bool logo_alternate;
160 };
161 
162 struct InstantMostVisitedItem {
163   // The URL of the Most Visited item.
164   GURL url;
165 
166   // The title of the Most Visited page.  May be empty, in which case the |url|
167   // is used as the title.
168   base::string16 title;
169 };
170 
171 // An InstantMostVisitedItem along with its assigned restricted ID.
172 typedef std::pair<InstantRestrictedID, InstantMostVisitedItem>
173     InstantMostVisitedItemIDPair;
174 
175 #endif  // CHROME_COMMON_INSTANT_TYPES_H_
176