OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/views/first_run_search_engine_view.h" | 5 #include "chrome/browser/views/first_run_search_engine_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "views/controls/separator.h" | 28 #include "views/controls/separator.h" |
29 #include "views/standard_layout.h" | 29 #include "views/standard_layout.h" |
30 #include "views/view_text_utils.h" | 30 #include "views/view_text_utils.h" |
31 #include "views/window/window.h" | 31 #include "views/window/window.h" |
32 | 32 |
33 using base::Time; | 33 using base::Time; |
34 using TemplateURLPrepopulateData::SearchEngineType; | 34 using TemplateURLPrepopulateData::SearchEngineType; |
35 | 35 |
36 namespace { | 36 namespace { |
37 | 37 |
38 // Represents an id for which we have no logo. | |
39 const int kNoLogo = -1; | |
40 | |
41 // Size to scale logos down to if showing 4 instead of 3 choices. Logo images | 38 // Size to scale logos down to if showing 4 instead of 3 choices. Logo images |
42 // are all originally sized at 180 x 120 pixels, with the logo text baseline | 39 // are all originally sized at 180 x 120 pixels, with the logo text baseline |
43 // located 74 pixels beneath the top of the image. | 40 // located 74 pixels beneath the top of the image. |
44 const int kSmallLogoWidth = 132; | 41 const int kSmallLogoWidth = 132; |
45 const int kSmallLogoHeight = 88; | 42 const int kSmallLogoHeight = 88; |
46 | 43 |
47 // Used to pad text label height so it fits nicely in view. | 44 // Used to pad text label height so it fits nicely in view. |
48 const int kLabelPadding = 25; | 45 const int kLabelPadding = 25; |
49 | 46 |
50 int GetSearchEngineLogo(const TemplateURL* template_url) { | |
51 typedef std::map<SearchEngineType, int> LogoMap; | |
52 static LogoMap type_to_logo; | |
53 if (type_to_logo.empty()) { | |
54 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
55 TemplateURLPrepopulateData::SEARCH_ENGINE_GOOGLE, | |
56 IDR_SEARCH_ENGINE_LOGO_GOOGLE)); | |
57 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
58 TemplateURLPrepopulateData::SEARCH_ENGINE_YAHOO, | |
59 IDR_SEARCH_ENGINE_LOGO_YAHOO)); | |
60 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
61 TemplateURLPrepopulateData::SEARCH_ENGINE_YAHOOJP, | |
62 IDR_SEARCH_ENGINE_LOGO_YAHOOJP)); | |
63 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
64 TemplateURLPrepopulateData::SEARCH_ENGINE_BING, | |
65 IDR_SEARCH_ENGINE_LOGO_BING)); | |
66 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
67 TemplateURLPrepopulateData::SEARCH_ENGINE_ASK, | |
68 IDR_SEARCH_ENGINE_LOGO_ASK)); | |
69 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
70 TemplateURLPrepopulateData::SEARCH_ENGINE_YANDEX, | |
71 IDR_SEARCH_ENGINE_LOGO_YANDEX)); | |
72 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
73 TemplateURLPrepopulateData::SEARCH_ENGINE_SEZNAM, | |
74 IDR_SEARCH_ENGINE_LOGO_SEZNAM)); | |
75 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
76 TemplateURLPrepopulateData::SEARCH_ENGINE_CENTRUM, | |
77 IDR_SEARCH_ENGINE_LOGO_CENTRUMCZ)); | |
78 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
79 TemplateURLPrepopulateData::SEARCH_ENGINE_NETSPRINT, | |
80 IDR_SEARCH_ENGINE_LOGO_NETSPRINT)); | |
81 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
82 TemplateURLPrepopulateData::SEARCH_ENGINE_VIRGILIO, | |
83 IDR_SEARCH_ENGINE_LOGO_VIRGILIO)); | |
84 type_to_logo.insert(std::make_pair<SearchEngineType, int>( | |
85 TemplateURLPrepopulateData::SEARCH_ENGINE_MAILRU, | |
86 IDR_SEARCH_ENGINE_LOGO_MAILRU)); | |
87 } | |
88 | |
89 LogoMap::iterator logo = type_to_logo.find( | |
90 TemplateURLPrepopulateData::GetSearchEngineType(template_url)); | |
91 if (logo != type_to_logo.end()) | |
92 return logo->second; | |
93 | |
94 // Logo does not exist: | |
95 return kNoLogo; | |
96 } | |
97 | |
98 } // namespace | 47 } // namespace |
99 | 48 |
100 SearchEngineChoice::SearchEngineChoice(views::ButtonListener* listener, | 49 SearchEngineChoice::SearchEngineChoice(views::ButtonListener* listener, |
101 const TemplateURL* search_engine, | 50 const TemplateURL* search_engine, |
102 bool use_small_logos) | 51 bool use_small_logos) |
103 : NativeButton(listener, l10n_util::GetString(IDS_FR_SEARCH_CHOOSE)), | 52 : NativeButton(listener, l10n_util::GetString(IDS_FR_SEARCH_CHOOSE)), |
104 is_image_label_(false), | 53 is_image_label_(false), |
105 search_engine_(search_engine) { | 54 search_engine_(search_engine) { |
106 bool use_images = false; | 55 bool use_images = false; |
107 #if defined(GOOGLE_CHROME_BUILD) | 56 #if defined(GOOGLE_CHROME_BUILD) |
108 use_images = true; | 57 use_images = true; |
109 #endif | 58 #endif |
110 int logo_id = GetSearchEngineLogo(search_engine_); | 59 int logo_id = search_engine_->logo_id(); |
111 if (use_images && logo_id != kNoLogo) { | 60 if (use_images && logo_id > 0) { |
112 is_image_label_ = true; | 61 is_image_label_ = true; |
113 views::ImageView* logo_image = new views::ImageView(); | 62 views::ImageView* logo_image = new views::ImageView(); |
114 SkBitmap* logo_bmp = | 63 SkBitmap* logo_bmp = |
115 ResourceBundle::GetSharedInstance().GetBitmapNamed(logo_id); | 64 ResourceBundle::GetSharedInstance().GetBitmapNamed(logo_id); |
116 logo_image->SetImage(logo_bmp); | 65 logo_image->SetImage(logo_bmp); |
117 if (use_small_logos) | 66 if (use_small_logos) |
118 logo_image->SetImageSize(gfx::Size(kSmallLogoWidth, kSmallLogoHeight)); | 67 logo_image->SetImageSize(gfx::Size(kSmallLogoWidth, kSmallLogoHeight)); |
119 // Tooltip text provides accessibility. | 68 // Tooltip text provides accessibility. |
120 logo_image->SetTooltipText(search_engine_->short_name()); | 69 logo_image->SetTooltipText(search_engine_->short_name()); |
121 choice_view_ = logo_image; | 70 choice_view_ = logo_image; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 logo_padding; | 367 logo_padding; |
419 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, | 368 search_engine_choices_[3]->SetBounds(next_h_space, next_v_space, |
420 button_width, button_height); | 369 button_width, button_height); |
421 } | 370 } |
422 } // if (search_engine_choices.size() > 0) | 371 } // if (search_engine_choices.size() > 0) |
423 } | 372 } |
424 | 373 |
425 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { | 374 std::wstring FirstRunSearchEngineView::GetWindowTitle() const { |
426 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); | 375 return l10n_util::GetString(IDS_FIRSTRUN_DLG_TITLE); |
427 } | 376 } |
OLD | NEW |