Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: chrome/browser/views/location_bar_view.cc

Issue 193026: Merge 25494 - Use system themes where possible in Omnibox edit and dropdown; ... (Closed) Base URL: svn://chrome-svn/chrome/branches/195/src/
Patch Set: Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Modified: svn:mergeinfo
Merged /trunk/src/chrome/browser/views/location_bar_view.cc:r25494
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/location_bar_view.h" 5 #include "chrome/browser/views/location_bar_view.h"
6 6
7 #if defined(OS_LINUX) 7 #if defined(OS_LINUX)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #include "app/gfx/canvas.h" 13 #include "app/gfx/canvas.h"
14 #include "app/gfx/color_utils.h"
14 #include "app/gfx/favicon_size.h" 15 #include "app/gfx/favicon_size.h"
15 #include "app/l10n_util.h" 16 #include "app/l10n_util.h"
16 #include "app/resource_bundle.h" 17 #include "app/resource_bundle.h"
17 #include "base/file_util.h" 18 #include "base/file_util.h"
18 #include "base/path_service.h" 19 #include "base/path_service.h"
19 #include "base/string_util.h" 20 #include "base/string_util.h"
20 #include "chrome/app/chrome_dll_resource.h" 21 #include "chrome/app/chrome_dll_resource.h"
21 #include "chrome/browser/alternate_nav_url_fetcher.h" 22 #include "chrome/browser/alternate_nav_url_fetcher.h"
22 #include "chrome/browser/browser.h" 23 #include "chrome/browser/browser.h"
23 #include "chrome/browser/browser_list.h" 24 #include "chrome/browser/browser_list.h"
(...skipping 15 matching lines...) Expand all
39 #include "grit/theme_resources.h" 40 #include "grit/theme_resources.h"
40 #include "skia/ext/image_operations.h" 41 #include "skia/ext/image_operations.h"
41 #include "views/focus/focus_manager.h" 42 #include "views/focus/focus_manager.h"
42 #include "views/widget/root_view.h" 43 #include "views/widget/root_view.h"
43 #include "views/widget/widget.h" 44 #include "views/widget/widget.h"
44 #include "webkit/glue/image_decoder.h" 45 #include "webkit/glue/image_decoder.h"
45 46
46 #if defined(OS_WIN) 47 #if defined(OS_WIN)
47 #include "app/win_util.h" 48 #include "app/win_util.h"
48 #include "chrome/browser/views/first_run_bubble.h" 49 #include "chrome/browser/views/first_run_bubble.h"
49 #else
50 #include "base/gfx/gtk_util.h"
51 #include "chrome/browser/gtk/location_bar_view_gtk.h"
52 #endif 50 #endif
53 51
54 using views::View; 52 using views::View;
55 53
54 // static
56 const int LocationBarView::kVertMargin = 2; 55 const int LocationBarView::kVertMargin = 2;
57 56
58 const SkColor LocationBarView::kBackgroundColorByLevel[] = {
59 SkColorSetRGB(255, 245, 195), // SecurityLevel SECURE: Yellow.
60 SkColorSetRGB(255, 255, 255), // SecurityLevel NORMAL: White.
61 SkColorSetRGB(255, 255, 255), // SecurityLevel INSECURE: White.
62 };
63 #if defined(OS_LINUX)
64 // static
65 const GdkColor LocationBarViewGtk::kBackgroundColorByLevel[3] = {
66 GDK_COLOR_RGB(255, 245, 195), // SecurityLevel SECURE: Yellow.
67 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel NORMAL: White.
68 GDK_COLOR_RGB(255, 255, 255), // SecurityLevel INSECURE: White.
69 };
70 #endif
71
72 // Padding on the right and left of the entry field. 57 // Padding on the right and left of the entry field.
73 static const int kEntryPadding = 3; 58 static const int kEntryPadding = 3;
74 59
75 // Padding between the entry and the leading/trailing views. 60 // Padding between the entry and the leading/trailing views.
76 static const int kInnerPadding = 3; 61 static const int kInnerPadding = 3;
77 62
78 static const SkBitmap* kBackground = NULL; 63 static const SkBitmap* kBackground = NULL;
79 64
80 static const SkBitmap* kPopupBackground = NULL; 65 static const SkBitmap* kPopupBackground = NULL;
81 66
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); 111 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
127 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG); 112 kBackground = rb.GetBitmapNamed(IDR_LOCATIONBG);
128 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER); 113 kPopupBackground = rb.GetBitmapNamed(IDR_LOCATIONBG_POPUPMODE_CENTER);
129 } 114 }
130 } 115 }
131 116
132 LocationBarView::~LocationBarView() { 117 LocationBarView::~LocationBarView() {
133 DeletePageActionViews(); 118 DeletePageActionViews();
134 } 119 }
135 120
136 bool LocationBarView::IsInitialized() const {
137 return location_entry_view_ != NULL;
138 }
139
140 void LocationBarView::Init() { 121 void LocationBarView::Init() {
141 if (popup_window_mode_) { 122 if (popup_window_mode_) {
142 font_ = ResourceBundle::GetSharedInstance().GetFont( 123 font_ = ResourceBundle::GetSharedInstance().GetFont(
143 ResourceBundle::BaseFont); 124 ResourceBundle::BaseFont);
144 } else { 125 } else {
145 // Use a larger version of the system font. 126 // Use a larger version of the system font.
146 font_ = font_.DeriveFont(3); 127 font_ = font_.DeriveFont(3);
147 } 128 }
148 129
149 // URL edit field. 130 // URL edit field.
(...skipping 27 matching lines...) Expand all
177 #else 158 #else
178 location_entry_->widget() 159 location_entry_->widget()
179 #endif 160 #endif
180 ); 161 );
181 162
182 AddChildView(&selected_keyword_view_); 163 AddChildView(&selected_keyword_view_);
183 selected_keyword_view_.SetFont(font_); 164 selected_keyword_view_.SetFont(font_);
184 selected_keyword_view_.SetVisible(false); 165 selected_keyword_view_.SetVisible(false);
185 selected_keyword_view_.SetParentOwned(false); 166 selected_keyword_view_.SetParentOwned(false);
186 167
187 #if defined(OS_WIN) 168 SkColor dimmed_text = GetColor(false, DEEMPHASIZED_TEXT);
188 DWORD sys_color = GetSysColor(COLOR_GRAYTEXT);
189 SkColor gray = SkColorSetRGB(GetRValue(sys_color), GetGValue(sys_color),
190 GetBValue(sys_color));
191 #else
192 NOTIMPLEMENTED();
193 SkColor gray = SK_ColorGRAY;
194 #endif
195 169
196 AddChildView(&type_to_search_view_); 170 AddChildView(&type_to_search_view_);
197 type_to_search_view_.SetVisible(false); 171 type_to_search_view_.SetVisible(false);
198 type_to_search_view_.SetFont(font_); 172 type_to_search_view_.SetFont(font_);
199 type_to_search_view_.SetColor(gray); 173 type_to_search_view_.SetColor(dimmed_text);
200 type_to_search_view_.SetParentOwned(false); 174 type_to_search_view_.SetParentOwned(false);
201 175
202 AddChildView(&keyword_hint_view_); 176 AddChildView(&keyword_hint_view_);
203 keyword_hint_view_.SetVisible(false); 177 keyword_hint_view_.SetVisible(false);
204 keyword_hint_view_.SetFont(font_); 178 keyword_hint_view_.SetFont(font_);
205 keyword_hint_view_.SetColor(gray); 179 keyword_hint_view_.SetColor(dimmed_text);
206 keyword_hint_view_.SetParentOwned(false); 180 keyword_hint_view_.SetParentOwned(false);
207 181
208 AddChildView(&security_image_view_); 182 AddChildView(&security_image_view_);
209 security_image_view_.SetVisible(false); 183 security_image_view_.SetVisible(false);
210 security_image_view_.SetParentOwned(false); 184 security_image_view_.SetParentOwned(false);
211 185
212 AddChildView(&info_label_); 186 AddChildView(&info_label_);
213 info_label_.SetVisible(false); 187 info_label_.SetVisible(false);
214 info_label_.SetParentOwned(false); 188 info_label_.SetParentOwned(false);
215 189
216 // Notify us when any ancestor is resized. In this case we want to tell the 190 // Notify us when any ancestor is resized. In this case we want to tell the
217 // AutocompleteEditView to close its popup. 191 // AutocompleteEditView to close its popup.
218 SetNotifyWhenVisibleBoundsInRootChanges(true); 192 SetNotifyWhenVisibleBoundsInRootChanges(true);
219 193
220 // Initialize the location entry. We do this to avoid a black flash which is 194 // Initialize the location entry. We do this to avoid a black flash which is
221 // visible when the location entry has just been initialized. 195 // visible when the location entry has just been initialized.
222 Update(NULL); 196 Update(NULL);
223 197
224 OnChanged(); 198 OnChanged();
225 } 199 }
226 200
201 bool LocationBarView::IsInitialized() const {
202 return location_entry_view_ != NULL;
203 }
204
205 // static
206 SkColor LocationBarView::GetColor(bool is_secure, ColorKind kind) {
207 enum SecurityState {
208 NOT_SECURE = 0,
209 SECURE,
210 NUM_STATES
211 };
212
213 static bool initialized = false;
214 static SkColor colors[NUM_STATES][NUM_KINDS];
215 if (!initialized) {
216 #if defined(OS_WIN)
217 colors[NOT_SECURE][BACKGROUND] = color_utils::GetSysSkColor(COLOR_WINDOW);
218 colors[NOT_SECURE][TEXT] = color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
219 colors[NOT_SECURE][SELECTED_TEXT] =
220 color_utils::GetSysSkColor(COLOR_HIGHLIGHTTEXT);
221 #else
222 // TODO(beng): source from theme provider.
223 colors[NOT_SECURE][BACKGROUND] = SK_ColorWHITE;
224 colors[NOT_SECURE][TEXT] = SK_ColorBLACK;
225 colors[NOT_SECURE][SELECTED_TEXT] = SK_ColorWHITE;
226 #endif
227 colors[SECURE][BACKGROUND] = SkColorSetRGB(255, 245, 195);
228 colors[SECURE][TEXT] = SkColorSetRGB(0, 0, 0);
229 colors[SECURE][SELECTED_TEXT] = 0; // Unused
230 colors[NOT_SECURE][DEEMPHASIZED_TEXT] =
231 color_utils::AlphaBlend(colors[NOT_SECURE][TEXT],
232 colors[NOT_SECURE][BACKGROUND], 128);
233 colors[SECURE][DEEMPHASIZED_TEXT] =
234 color_utils::AlphaBlend(colors[SECURE][TEXT],
235 colors[SECURE][BACKGROUND], 128);
236 const SkColor kDarkNotSecureText = SkColorSetRGB(200, 0, 0);
237 const SkColor kLightNotSecureText = SkColorSetRGB(255, 55, 55);
238 colors[NOT_SECURE][SECURITY_TEXT] =
239 color_utils::PickMoreReadableColor(kDarkNotSecureText,
240 kLightNotSecureText,
241 colors[NOT_SECURE][BACKGROUND]);
242 colors[SECURE][SECURITY_TEXT] = SkColorSetRGB(0, 150, 20);
243 #if 0 // Info bubble background color is system theme window background color
244 colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] =
245 colors[NOT_SECURE][SECURITY_TEXT];
246 const SkColor kDarkSecureInfoBubbleText = SkColorSetRGB(0, 153, 51);
247 const SkColor kLightSecureInfoBubbleText = SkColorSetRGB(102, 255, 152);
248 colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] =
249 color_utils::PickMoreReadableColor(kDarkSecureInfoBubbleText,
250 kLightSecureInfoBubbleText,
251 colors[NOT_SECURE][BACKGROUND]);
252 #else // Info bubble background color is white
253 colors[NOT_SECURE][SECURITY_INFO_BUBBLE_TEXT] = kDarkNotSecureText;
254 colors[SECURE][SECURITY_INFO_BUBBLE_TEXT] = SkColorSetRGB(0, 153, 51);
255 #endif
256 const SkColor kDarkSchemeStrikeout = SkColorSetRGB(210, 0, 0);
257 const SkColor kLightSchemeStrikeout = SkColorSetRGB(255, 45, 45);
258 colors[NOT_SECURE][SCHEME_STRIKEOUT] =
259 color_utils::PickMoreReadableColor(kDarkSchemeStrikeout,
260 kLightSchemeStrikeout,
261 colors[NOT_SECURE][BACKGROUND]);
262 colors[SECURE][SCHEME_STRIKEOUT] = 0; // Unused
263 initialized = true;
264 }
265
266 return colors[is_secure ? SECURE : NOT_SECURE][kind];
267 }
268
227 void LocationBarView::Update(const TabContents* tab_for_state_restoring) { 269 void LocationBarView::Update(const TabContents* tab_for_state_restoring) {
228 SetSecurityIcon(model_->GetIcon()); 270 SetSecurityIcon(model_->GetIcon());
229 RefreshPageActionViews(); 271 RefreshPageActionViews();
230 std::wstring info_text, info_tooltip; 272 std::wstring info_text, info_tooltip;
231 ToolbarModel::InfoTextType info_text_type = 273 ToolbarModel::InfoTextType info_text_type =
232 model_->GetInfoText(&info_text, &info_tooltip); 274 model_->GetInfoText(&info_text, &info_tooltip);
233 SetInfoText(info_text, info_text_type, info_tooltip); 275 SetInfoText(info_text, info_text_type, info_tooltip);
234 location_entry_->Update(tab_for_state_restoring); 276 location_entry_->Update(tab_for_state_restoring);
235 Layout(); 277 Layout();
236 SchedulePaint(); 278 SchedulePaint();
(...skipping 30 matching lines...) Expand all
267 (popup_window_mode_ ? kPopupBackground : kBackground)->height()); 309 (popup_window_mode_ ? kPopupBackground : kBackground)->height());
268 } 310 }
269 311
270 void LocationBarView::Layout() { 312 void LocationBarView::Layout() {
271 DoLayout(true); 313 DoLayout(true);
272 } 314 }
273 315
274 void LocationBarView::Paint(gfx::Canvas* canvas) { 316 void LocationBarView::Paint(gfx::Canvas* canvas) {
275 View::Paint(canvas); 317 View::Paint(canvas);
276 318
277 SkColor bg = kBackgroundColorByLevel[model_->GetSchemeSecurityLevel()];
278
279 const SkBitmap* background = 319 const SkBitmap* background =
280 popup_window_mode_ ? 320 popup_window_mode_ ?
281 kPopupBackground : 321 kPopupBackground :
282 GetThemeProvider()->GetBitmapNamed(IDR_LOCATIONBG); 322 GetThemeProvider()->GetBitmapNamed(IDR_LOCATIONBG);
283 323
284 canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height()); 324 canvas->TileImageInt(*background, 0, 0, 0, 0, width(), height());
285 int top_margin = TopMargin(); 325 int top_margin = TopMargin();
286 canvas->FillRectInt(bg, 0, top_margin, width(), 326 canvas->FillRectInt(
287 std::max(height() - top_margin - kVertMargin, 0)); 327 GetColor(model_->GetSchemeSecurityLevel() == ToolbarModel::SECURE,
328 BACKGROUND),
329 0, top_margin, width(), std::max(height() - top_margin - kVertMargin, 0));
288 } 330 }
289 331
290 void LocationBarView::VisibleBoundsInRootChanged() { 332 void LocationBarView::VisibleBoundsInRootChanged() {
291 location_entry_->ClosePopup(); 333 location_entry_->ClosePopup();
292 } 334 }
293 335
294 #if defined(OS_WIN) 336 #if defined(OS_WIN)
295 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) { 337 bool LocationBarView::OnMousePressed(const views::MouseEvent& event) {
296 UINT msg; 338 UINT msg;
297 if (event.IsLeftMouseButton()) { 339 if (event.IsLeftMouseButton()) {
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 page_action_image_views_[i]->UpdateVisibility(contents, url); 693 page_action_image_views_[i]->UpdateVisibility(contents, url);
652 } 694 }
653 } 695 }
654 696
655 void LocationBarView::SetInfoText(const std::wstring& text, 697 void LocationBarView::SetInfoText(const std::wstring& text,
656 ToolbarModel::InfoTextType text_type, 698 ToolbarModel::InfoTextType text_type,
657 const std::wstring& tooltip_text) { 699 const std::wstring& tooltip_text) {
658 info_label_.SetVisible(!text.empty()); 700 info_label_.SetVisible(!text.empty());
659 info_label_.SetText(text); 701 info_label_.SetText(text);
660 if (text_type == ToolbarModel::INFO_EV_TEXT) 702 if (text_type == ToolbarModel::INFO_EV_TEXT)
661 info_label_.SetColor(SkColorSetRGB(0, 150, 20)); // Green. 703 info_label_.SetColor(GetColor(true, SECURITY_TEXT));
662 info_label_.SetTooltipText(tooltip_text); 704 info_label_.SetTooltipText(tooltip_text);
663 } 705 }
664 706
665 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) { 707 bool LocationBarView::ToggleVisibility(bool new_vis, View* view) {
666 DCHECK(view); 708 DCHECK(view);
667 if (view->IsVisible() != new_vis) { 709 if (view->IsVisible() != new_vis) {
668 view->SetVisible(new_vis); 710 view->SetVisible(new_vis);
669 return true; 711 return true;
670 } 712 }
671 return false; 713 return false;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 if (!nav_entry) { 1160 if (!nav_entry) {
1119 NOTREACHED(); 1161 NOTREACHED();
1120 return true; 1162 return true;
1121 } 1163 }
1122 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true); 1164 tab->ShowPageInfo(nav_entry->url(), nav_entry->ssl(), true);
1123 return true; 1165 return true;
1124 } 1166 }
1125 1167
1126 void LocationBarView::SecurityImageView::ShowInfoBubble() { 1168 void LocationBarView::SecurityImageView::ShowInfoBubble() {
1127 std::wstring text; 1169 std::wstring text;
1128 SkColor text_color; 1170 model_->GetIconHoverText(&text);
1129 model_->GetIconHoverText(&text, &text_color); 1171 ShowInfoBubbleImpl(text, GetColor(
1130 1172 model_->GetSecurityLevel() == ToolbarModel::SECURE,
1131 ShowInfoBubbleImpl(text, text_color); 1173 SECURITY_INFO_BUBBLE_TEXT));
1132 } 1174 }
1133 1175
1134 // PageActionImageView---------------------------------------------------------- 1176 // PageActionImageView----------------------------------------------------------
1135 1177
1136 // The views need to load their icons asynchronously but might be deleted before 1178 // The views need to load their icons asynchronously but might be deleted before
1137 // the images have loaded. This class stays alive while the request is in 1179 // the images have loaded. This class stays alive while the request is in
1138 // progress (manages its own lifetime) and keeps track of whether the view still 1180 // progress (manages its own lifetime) and keeps track of whether the view still
1139 // cares about the icon loading. 1181 // cares about the icon loading.
1140 class LocationBarView::PageActionImageView::ImageLoadingTracker 1182 class LocationBarView::PageActionImageView::ImageLoadingTracker
1141 : public base::RefCountedThreadSafe<ImageLoadingTracker> { 1183 : public base::RefCountedThreadSafe<ImageLoadingTracker> {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 bool LocationBarView::PageActionImageView::OnMousePressed( 1326 bool LocationBarView::PageActionImageView::OnMousePressed(
1285 const views::MouseEvent& event) { 1327 const views::MouseEvent& event) {
1286 // Our PageAction icon was clicked on, notify proper authorities. 1328 // Our PageAction icon was clicked on, notify proper authorities.
1287 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted( 1329 ExtensionBrowserEventRouter::GetInstance()->PageActionExecuted(
1288 profile_, page_action_->extension_id(), page_action_->id(), 1330 profile_, page_action_->extension_id(), page_action_->id(),
1289 current_tab_id_, current_url_.spec()); 1331 current_tab_id_, current_url_.spec());
1290 return true; 1332 return true;
1291 } 1333 }
1292 1334
1293 void LocationBarView::PageActionImageView::ShowInfoBubble() { 1335 void LocationBarView::PageActionImageView::ShowInfoBubble() {
1294 SkColor text_color = SK_ColorBLACK; 1336 #if 0 // Info bubble background color is system theme window background color
1295 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), text_color); 1337 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), GetColor(false, TEXT));
1338 #else // Info bubble background color is white
1339 ShowInfoBubbleImpl(ASCIIToWide(tooltip_), SK_ColorBLACK);
1340 #endif
1296 } 1341 }
1297 1342
1298 void LocationBarView::PageActionImageView::UpdateVisibility( 1343 void LocationBarView::PageActionImageView::UpdateVisibility(
1299 TabContents* contents, GURL url) { 1344 TabContents* contents, GURL url) {
1300 // Save this off so we can pass it back to the extension when the action gets 1345 // Save this off so we can pass it back to the extension when the action gets
1301 // executed. See PageActionImageView::OnMousePressed. 1346 // executed. See PageActionImageView::OnMousePressed.
1302 current_tab_id_ = ExtensionTabUtil::GetTabId(contents); 1347 current_tab_id_ = ExtensionTabUtil::GetTabId(contents);
1303 current_url_ = url; 1348 current_url_ = url;
1304 1349
1305 const PageActionState* state = contents->GetPageActionState(page_action_); 1350 const PageActionState* state = contents->GetPageActionState(page_action_);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 } 1423 }
1379 1424
1380 int LocationBarView::PageActionVisibleCount() { 1425 int LocationBarView::PageActionVisibleCount() {
1381 int result = 0; 1426 int result = 0;
1382 for (size_t i = 0; i < page_action_image_views_.size(); i++) { 1427 for (size_t i = 0; i < page_action_image_views_.size(); i++) {
1383 if (page_action_image_views_[i]->IsVisible()) 1428 if (page_action_image_views_[i]->IsVisible())
1384 ++result; 1429 ++result;
1385 } 1430 }
1386 return result; 1431 return result;
1387 } 1432 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698