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

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

Issue 1123943002: Move SecurityLevel into a class of its own (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pkasting nits Created 5 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/views/location_bar/location_bar_view.h" 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 // Determine the font for use inside the bubbles. The bubble background 205 // Determine the font for use inside the bubbles. The bubble background
206 // images have 1 px thick edges, which we don't want to overlap. 206 // images have 1 px thick edges, which we don't want to overlap.
207 const int kBubbleInteriorVerticalPadding = 1; 207 const int kBubbleInteriorVerticalPadding = 1;
208 const int bubble_vertical_padding = 208 const int bubble_vertical_padding =
209 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2; 209 (kBubblePadding + kBubbleInteriorVerticalPadding) * 2;
210 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound( 210 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound(
211 location_height - bubble_vertical_padding)); 211 location_height - bubble_vertical_padding));
212 212
213 const SkColor background_color = 213 const SkColor background_color =
214 GetColor(ToolbarModel::NONE, LocationBarView::BACKGROUND); 214 GetColor(SecurityLevelPolicy::NONE, LocationBarView::BACKGROUND);
215 ev_bubble_view_ = new EVBubbleView( 215 ev_bubble_view_ = new EVBubbleView(
216 bubble_font_list, GetColor(ToolbarModel::EV_SECURE, SECURITY_TEXT), 216 bubble_font_list, GetColor(SecurityLevelPolicy::EV_SECURE, SECURITY_TEXT),
217 background_color, this); 217 background_color, this);
218 ev_bubble_view_->set_drag_controller(this); 218 ev_bubble_view_->set_drag_controller(this);
219 AddChildView(ev_bubble_view_); 219 AddChildView(ev_bubble_view_);
220 220
221 // Initialize the Omnibox view. 221 // Initialize the Omnibox view.
222 omnibox_view_ = new OmniboxViewViews( 222 omnibox_view_ = new OmniboxViewViews(
223 this, profile(), command_updater(), is_popup_mode_, this, font_list); 223 this, profile(), command_updater(), is_popup_mode_, this, font_list);
224 omnibox_view_->Init(); 224 omnibox_view_->Init();
225 omnibox_view_->SetFocusable(true); 225 omnibox_view_->SetFocusable(true);
226 AddChildView(omnibox_view_); 226 AddChildView(omnibox_view_);
227 227
228 // Initialize the inline autocomplete view which is visible only when IME is 228 // Initialize the inline autocomplete view which is visible only when IME is
229 // turned on. Use the same font with the omnibox and highlighted background. 229 // turned on. Use the same font with the omnibox and highlighted background.
230 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); 230 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list);
231 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 231 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
232 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 232 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
233 ime_inline_autocomplete_view_->set_background( 233 ime_inline_autocomplete_view_->set_background(
234 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 234 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
235 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 235 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
236 ime_inline_autocomplete_view_->SetEnabledColor( 236 ime_inline_autocomplete_view_->SetEnabledColor(
237 GetNativeTheme()->GetSystemColor( 237 GetNativeTheme()->GetSystemColor(
238 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 238 ui::NativeTheme::kColorId_TextfieldSelectionColor));
239 ime_inline_autocomplete_view_->SetVisible(false); 239 ime_inline_autocomplete_view_->SetVisible(false);
240 AddChildView(ime_inline_autocomplete_view_); 240 AddChildView(ime_inline_autocomplete_view_);
241 241
242 const SkColor text_color = GetColor(ToolbarModel::NONE, TEXT); 242 const SkColor text_color = GetColor(SecurityLevelPolicy::NONE, TEXT);
243 selected_keyword_view_ = new SelectedKeywordView( 243 selected_keyword_view_ = new SelectedKeywordView(
244 bubble_font_list, text_color, background_color, profile()); 244 bubble_font_list, text_color, background_color, profile());
245 AddChildView(selected_keyword_view_); 245 AddChildView(selected_keyword_view_);
246 246
247 suggested_text_view_ = new views::Label(base::string16(), font_list); 247 suggested_text_view_ = new views::Label(base::string16(), font_list);
248 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 248 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
249 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 249 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
250 suggested_text_view_->SetEnabledColor(GetColor( 250 suggested_text_view_->SetEnabledColor(
251 ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 251 GetColor(SecurityLevelPolicy::NONE, LocationBarView::DEEMPHASIZED_TEXT));
252 suggested_text_view_->SetVisible(false); 252 suggested_text_view_->SetVisible(false);
253 AddChildView(suggested_text_view_); 253 AddChildView(suggested_text_view_);
254 254
255 keyword_hint_view_ = new KeywordHintView( 255 keyword_hint_view_ = new KeywordHintView(
256 profile(), font_list, 256 profile(), font_list,
257 GetColor(ToolbarModel::NONE, LocationBarView::DEEMPHASIZED_TEXT), 257 GetColor(SecurityLevelPolicy::NONE, LocationBarView::DEEMPHASIZED_TEXT),
258 background_color); 258 background_color);
259 AddChildView(keyword_hint_view_); 259 AddChildView(keyword_hint_view_);
260 260
261 mic_search_view_ = new views::ImageButton(this); 261 mic_search_view_ = new views::ImageButton(this);
262 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); 262 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON);
263 mic_search_view_->SetAccessibilityFocusable(true); 263 mic_search_view_->SetAccessibilityFocusable(true);
264 mic_search_view_->SetTooltipText( 264 mic_search_view_->SetTooltipText(
265 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); 265 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH));
266 mic_search_view_->SetImage( 266 mic_search_view_->SetImage(
267 views::Button::STATE_NORMAL, 267 views::Button::STATE_NORMAL,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 // visible when the location entry has just been initialized. 306 // visible when the location entry has just been initialized.
307 Update(NULL); 307 Update(NULL);
308 308
309 size_animation_.Reset(1); 309 size_animation_.Reset(1);
310 } 310 }
311 311
312 bool LocationBarView::IsInitialized() const { 312 bool LocationBarView::IsInitialized() const {
313 return omnibox_view_ != NULL; 313 return omnibox_view_ != NULL;
314 } 314 }
315 315
316 SkColor LocationBarView::GetColor(ToolbarModel::SecurityLevel security_level, 316 SkColor LocationBarView::GetColor(
317 ColorKind kind) const { 317 SecurityLevelPolicy::SecurityLevel security_level,
318 ColorKind kind) const {
318 const ui::NativeTheme* native_theme = GetNativeTheme(); 319 const ui::NativeTheme* native_theme = GetNativeTheme();
319 switch (kind) { 320 switch (kind) {
320 case BACKGROUND: 321 case BACKGROUND:
321 return native_theme->GetSystemColor( 322 return native_theme->GetSystemColor(
322 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 323 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
323 324
324 case TEXT: 325 case TEXT:
325 return native_theme->GetSystemColor( 326 return native_theme->GetSystemColor(
326 ui::NativeTheme::kColorId_TextfieldDefaultColor); 327 ui::NativeTheme::kColorId_TextfieldDefaultColor);
327 328
328 case SELECTED_TEXT: 329 case SELECTED_TEXT:
329 return native_theme->GetSystemColor( 330 return native_theme->GetSystemColor(
330 ui::NativeTheme::kColorId_TextfieldSelectionColor); 331 ui::NativeTheme::kColorId_TextfieldSelectionColor);
331 332
332 case DEEMPHASIZED_TEXT: 333 case DEEMPHASIZED_TEXT:
333 return color_utils::AlphaBlend( 334 return color_utils::AlphaBlend(
334 GetColor(security_level, TEXT), 335 GetColor(security_level, TEXT),
335 GetColor(security_level, BACKGROUND), 336 GetColor(security_level, BACKGROUND),
336 128); 337 128);
337 338
338 case SECURITY_TEXT: { 339 case SECURITY_TEXT: {
339 SkColor color; 340 SkColor color;
340 switch (security_level) { 341 switch (security_level) {
341 case ToolbarModel::EV_SECURE: 342 case SecurityLevelPolicy::EV_SECURE:
342 case ToolbarModel::SECURE: 343 case SecurityLevelPolicy::SECURE:
343 color = SkColorSetRGB(7, 149, 0); 344 color = SkColorSetRGB(7, 149, 0);
344 break; 345 break;
345 346
346 case ToolbarModel::SECURITY_WARNING: 347 case SecurityLevelPolicy::SECURITY_WARNING:
347 case ToolbarModel::SECURITY_POLICY_WARNING: 348 case SecurityLevelPolicy::SECURITY_POLICY_WARNING:
348 return GetColor(security_level, DEEMPHASIZED_TEXT); 349 return GetColor(security_level, DEEMPHASIZED_TEXT);
349 break; 350 break;
350 351
351 case ToolbarModel::SECURITY_ERROR: 352 case SecurityLevelPolicy::SECURITY_ERROR:
352 color = SkColorSetRGB(162, 0, 0); 353 color = SkColorSetRGB(162, 0, 0);
353 break; 354 break;
354 355
355 default: 356 default:
356 NOTREACHED(); 357 NOTREACHED();
357 return GetColor(security_level, TEXT); 358 return GetColor(security_level, TEXT);
358 } 359 }
359 return color_utils::GetReadableColor( 360 return color_utils::GetReadableColor(
360 color, GetColor(security_level, BACKGROUND)); 361 color, GetColor(security_level, BACKGROUND));
361 } 362 }
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 return suggested_text_view_->visible() && 992 return suggested_text_view_->visible() &&
992 !suggested_text_view_->size().IsEmpty(); 993 !suggested_text_view_->size().IsEmpty();
993 } 994 }
994 995
995 bool LocationBarView::ShouldShowKeywordBubble() const { 996 bool LocationBarView::ShouldShowKeywordBubble() const {
996 return !omnibox_view_->model()->keyword().empty() && 997 return !omnibox_view_->model()->keyword().empty() &&
997 !omnibox_view_->model()->is_keyword_hint(); 998 !omnibox_view_->model()->is_keyword_hint();
998 } 999 }
999 1000
1000 bool LocationBarView::ShouldShowEVBubble() const { 1001 bool LocationBarView::ShouldShowEVBubble() const {
1001 return 1002 return (GetToolbarModel()->GetSecurityLevel(false) ==
1002 (GetToolbarModel()->GetSecurityLevel(false) == ToolbarModel::EV_SECURE); 1003 SecurityLevelPolicy::EV_SECURE);
1003 } 1004 }
1004 1005
1005 //////////////////////////////////////////////////////////////////////////////// 1006 ////////////////////////////////////////////////////////////////////////////////
1006 // LocationBarView, private LocationBar implementation: 1007 // LocationBarView, private LocationBar implementation:
1007 1008
1008 void LocationBarView::ShowFirstRunBubble() { 1009 void LocationBarView::ShowFirstRunBubble() {
1009 // Wait until search engines have loaded to show the first run bubble. 1010 // Wait until search engines have loaded to show the first run bubble.
1010 TemplateURLService* url_service = 1011 TemplateURLService* url_service =
1011 TemplateURLServiceFactory::GetForProfile(profile()); 1012 TemplateURLServiceFactory::GetForProfile(profile());
1012 if (!url_service->loaded()) { 1013 if (!url_service->loaded()) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 } 1214 }
1214 1215
1215 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1216 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1216 View::OnPaint(canvas); 1217 View::OnPaint(canvas);
1217 1218
1218 // Fill the location bar background color behind the border. Parts of the 1219 // Fill the location bar background color behind the border. Parts of the
1219 // border images are meant to rest atop the toolbar background and parts atop 1220 // border images are meant to rest atop the toolbar background and parts atop
1220 // the omnibox background, so we can't just blindly fill our entire bounds. 1221 // the omnibox background, so we can't just blindly fill our entire bounds.
1221 gfx::Rect bounds(GetContentsBounds()); 1222 gfx::Rect bounds(GetContentsBounds());
1222 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness()); 1223 bounds.Inset(GetHorizontalEdgeThickness(), vertical_edge_thickness());
1223 SkColor color(GetColor(ToolbarModel::NONE, BACKGROUND)); 1224 SkColor color(GetColor(SecurityLevelPolicy::NONE, BACKGROUND));
1224 if (is_popup_mode_) { 1225 if (is_popup_mode_) {
1225 canvas->FillRect(bounds, color); 1226 canvas->FillRect(bounds, color);
1226 } else { 1227 } else {
1227 SkPaint paint; 1228 SkPaint paint;
1228 paint.setStyle(SkPaint::kFill_Style); 1229 paint.setStyle(SkPaint::kFill_Style);
1229 paint.setColor(color); 1230 paint.setColor(color);
1230 const int kBorderCornerRadius = 2; 1231 const int kBorderCornerRadius = 2;
1231 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1232 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1232 } 1233 }
1233 1234
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 1365
1365 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1366 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1366 const SearchModel::State& new_state) { 1367 const SearchModel::State& new_state) {
1367 const bool visible = !GetToolbarModel()->input_in_progress() && 1368 const bool visible = !GetToolbarModel()->input_in_progress() &&
1368 new_state.voice_search_supported; 1369 new_state.voice_search_supported;
1369 if (mic_search_view_->visible() != visible) { 1370 if (mic_search_view_->visible() != visible) {
1370 mic_search_view_->SetVisible(visible); 1371 mic_search_view_->SetVisible(visible);
1371 Layout(); 1372 Layout();
1372 } 1373 }
1373 } 1374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698