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

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

Issue 1314843007: Refactor connection_security into SecurityStateModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: create SecurityStateModel for chromeos login webview Created 5 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
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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // images have 1 px thick edges, which we don't want to overlap. 215 // images have 1 px thick edges, which we don't want to overlap.
216 const int kBubbleInteriorVerticalPadding = 1; 216 const int kBubbleInteriorVerticalPadding = 1;
217 const int bubble_padding = GetThemeProvider()->GetDisplayProperty( 217 const int bubble_padding = GetThemeProvider()->GetDisplayProperty(
218 ThemeProperties::PROPERTY_LOCATION_BAR_BUBBLE_VERTICAL_PADDING); 218 ThemeProperties::PROPERTY_LOCATION_BAR_BUBBLE_VERTICAL_PADDING);
219 const int bubble_vertical_padding = 219 const int bubble_vertical_padding =
220 (bubble_padding + kBubbleInteriorVerticalPadding) * 2; 220 (bubble_padding + kBubbleInteriorVerticalPadding) * 2;
221 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound( 221 const gfx::FontList bubble_font_list(font_list.DeriveWithHeightUpperBound(
222 location_height - bubble_vertical_padding)); 222 location_height - bubble_vertical_padding));
223 223
224 const SkColor background_color = 224 const SkColor background_color =
225 GetColor(connection_security::NONE, LocationBarView::BACKGROUND); 225 GetColor(SecurityStateModel::NONE, LocationBarView::BACKGROUND);
226 ev_bubble_view_ = new EVBubbleView( 226 ev_bubble_view_ = new EVBubbleView(
227 bubble_font_list, GetColor(connection_security::EV_SECURE, SECURITY_TEXT), 227 bubble_font_list, GetColor(SecurityStateModel::EV_SECURE, SECURITY_TEXT),
228 background_color, this); 228 background_color, this);
229 ev_bubble_view_->set_drag_controller(this); 229 ev_bubble_view_->set_drag_controller(this);
230 AddChildView(ev_bubble_view_); 230 AddChildView(ev_bubble_view_);
231 231
232 // Initialize the Omnibox view. 232 // Initialize the Omnibox view.
233 omnibox_view_ = new OmniboxViewViews( 233 omnibox_view_ = new OmniboxViewViews(
234 this, profile(), command_updater(), is_popup_mode_, this, font_list); 234 this, profile(), command_updater(), is_popup_mode_, this, font_list);
235 omnibox_view_->Init(); 235 omnibox_view_->Init();
236 omnibox_view_->SetFocusable(true); 236 omnibox_view_->SetFocusable(true);
237 AddChildView(omnibox_view_); 237 AddChildView(omnibox_view_);
238 238
239 // Initialize the inline autocomplete view which is visible only when IME is 239 // Initialize the inline autocomplete view which is visible only when IME is
240 // turned on. Use the same font with the omnibox and highlighted background. 240 // turned on. Use the same font with the omnibox and highlighted background.
241 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list); 241 ime_inline_autocomplete_view_ = new views::Label(base::string16(), font_list);
242 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 242 ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
243 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); 243 ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false);
244 ime_inline_autocomplete_view_->set_background( 244 ime_inline_autocomplete_view_->set_background(
245 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( 245 views::Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor(
246 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused))); 246 ui::NativeTheme::kColorId_TextfieldSelectionBackgroundFocused)));
247 ime_inline_autocomplete_view_->SetEnabledColor( 247 ime_inline_autocomplete_view_->SetEnabledColor(
248 GetNativeTheme()->GetSystemColor( 248 GetNativeTheme()->GetSystemColor(
249 ui::NativeTheme::kColorId_TextfieldSelectionColor)); 249 ui::NativeTheme::kColorId_TextfieldSelectionColor));
250 ime_inline_autocomplete_view_->SetVisible(false); 250 ime_inline_autocomplete_view_->SetVisible(false);
251 AddChildView(ime_inline_autocomplete_view_); 251 AddChildView(ime_inline_autocomplete_view_);
252 252
253 const SkColor text_color = GetColor(connection_security::NONE, TEXT); 253 const SkColor text_color = GetColor(SecurityStateModel::NONE, TEXT);
254 selected_keyword_view_ = new SelectedKeywordView( 254 selected_keyword_view_ = new SelectedKeywordView(
255 bubble_font_list, text_color, background_color, profile()); 255 bubble_font_list, text_color, background_color, profile());
256 AddChildView(selected_keyword_view_); 256 AddChildView(selected_keyword_view_);
257 257
258 suggested_text_view_ = new views::Label(base::string16(), font_list); 258 suggested_text_view_ = new views::Label(base::string16(), font_list);
259 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 259 suggested_text_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
260 suggested_text_view_->SetAutoColorReadabilityEnabled(false); 260 suggested_text_view_->SetAutoColorReadabilityEnabled(false);
261 suggested_text_view_->SetEnabledColor( 261 suggested_text_view_->SetEnabledColor(
262 GetColor(connection_security::NONE, LocationBarView::DEEMPHASIZED_TEXT)); 262 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT));
263 suggested_text_view_->SetVisible(false); 263 suggested_text_view_->SetVisible(false);
264 AddChildView(suggested_text_view_); 264 AddChildView(suggested_text_view_);
265 265
266 keyword_hint_view_ = new KeywordHintView( 266 keyword_hint_view_ = new KeywordHintView(
267 profile(), font_list, 267 profile(), font_list,
268 GetColor(connection_security::NONE, LocationBarView::DEEMPHASIZED_TEXT), 268 GetColor(SecurityStateModel::NONE, LocationBarView::DEEMPHASIZED_TEXT),
269 background_color); 269 background_color);
270 AddChildView(keyword_hint_view_); 270 AddChildView(keyword_hint_view_);
271 271
272 mic_search_view_ = new views::ImageButton(this); 272 mic_search_view_ = new views::ImageButton(this);
273 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON); 273 mic_search_view_->set_id(VIEW_ID_MIC_SEARCH_BUTTON);
274 mic_search_view_->SetAccessibilityFocusable(true); 274 mic_search_view_->SetAccessibilityFocusable(true);
275 mic_search_view_->SetTooltipText( 275 mic_search_view_->SetTooltipText(
276 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)); 276 l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH));
277 mic_search_view_->SetImage( 277 mic_search_view_->SetImage(
278 views::Button::STATE_NORMAL, 278 views::Button::STATE_NORMAL,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 Update(NULL); 315 Update(NULL);
316 316
317 size_animation_.Reset(1); 317 size_animation_.Reset(1);
318 } 318 }
319 319
320 bool LocationBarView::IsInitialized() const { 320 bool LocationBarView::IsInitialized() const {
321 return omnibox_view_ != NULL; 321 return omnibox_view_ != NULL;
322 } 322 }
323 323
324 SkColor LocationBarView::GetColor( 324 SkColor LocationBarView::GetColor(
325 connection_security::SecurityLevel security_level, 325 SecurityStateModel::SecurityLevel security_level,
326 ColorKind kind) const { 326 ColorKind kind) const {
327 const ui::NativeTheme* native_theme = GetNativeTheme(); 327 const ui::NativeTheme* native_theme = GetNativeTheme();
328 switch (kind) { 328 switch (kind) {
329 case BACKGROUND: 329 case BACKGROUND:
330 return native_theme->GetSystemColor( 330 return native_theme->GetSystemColor(
331 ui::NativeTheme::kColorId_TextfieldDefaultBackground); 331 ui::NativeTheme::kColorId_TextfieldDefaultBackground);
332 332
333 case TEXT: 333 case TEXT:
334 return native_theme->GetSystemColor( 334 return native_theme->GetSystemColor(
335 ui::NativeTheme::kColorId_TextfieldDefaultColor); 335 ui::NativeTheme::kColorId_TextfieldDefaultColor);
336 336
337 case SELECTED_TEXT: 337 case SELECTED_TEXT:
338 return native_theme->GetSystemColor( 338 return native_theme->GetSystemColor(
339 ui::NativeTheme::kColorId_TextfieldSelectionColor); 339 ui::NativeTheme::kColorId_TextfieldSelectionColor);
340 340
341 case DEEMPHASIZED_TEXT: 341 case DEEMPHASIZED_TEXT:
342 return color_utils::AlphaBlend( 342 return color_utils::AlphaBlend(
343 GetColor(security_level, TEXT), 343 GetColor(security_level, TEXT),
344 GetColor(security_level, BACKGROUND), 344 GetColor(security_level, BACKGROUND),
345 128); 345 128);
346 346
347 case SECURITY_TEXT: { 347 case SECURITY_TEXT: {
348 SkColor color; 348 SkColor color;
349 switch (security_level) { 349 switch (security_level) {
350 case connection_security::EV_SECURE: 350 case SecurityStateModel::EV_SECURE:
351 case connection_security::SECURE: 351 case SecurityStateModel::SECURE:
352 color = SkColorSetRGB(7, 149, 0); 352 color = SkColorSetRGB(7, 149, 0);
353 break; 353 break;
354 354
355 case connection_security::SECURITY_POLICY_WARNING: 355 case SecurityStateModel::SECURITY_POLICY_WARNING:
356 return GetColor(security_level, DEEMPHASIZED_TEXT); 356 return GetColor(security_level, DEEMPHASIZED_TEXT);
357 break; 357 break;
358 358
359 case connection_security::SECURITY_ERROR: 359 case SecurityStateModel::SECURITY_ERROR:
360 color = SkColorSetRGB(162, 0, 0); 360 color = SkColorSetRGB(162, 0, 0);
361 break; 361 break;
362 362
363 case connection_security::SECURITY_WARNING: 363 case SecurityStateModel::SECURITY_WARNING:
364 return GetColor(security_level, TEXT); 364 return GetColor(security_level, TEXT);
365 break; 365 break;
366 366
367 default: 367 default:
368 NOTREACHED(); 368 NOTREACHED();
369 return GetColor(security_level, TEXT); 369 return GetColor(security_level, TEXT);
370 } 370 }
371 return color_utils::GetReadableColor( 371 return color_utils::GetReadableColor(
372 color, GetColor(security_level, BACKGROUND)); 372 color, GetColor(security_level, BACKGROUND));
373 } 373 }
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1041
1042 bool LocationBarView::ShouldShowKeywordBubble() const { 1042 bool LocationBarView::ShouldShowKeywordBubble() const {
1043 return !omnibox_view_->model()->keyword().empty() && 1043 return !omnibox_view_->model()->keyword().empty() &&
1044 !omnibox_view_->model()->is_keyword_hint(); 1044 !omnibox_view_->model()->is_keyword_hint();
1045 } 1045 }
1046 1046
1047 bool LocationBarView::ShouldShowEVBubble() const { 1047 bool LocationBarView::ShouldShowEVBubble() const {
1048 const ChromeToolbarModel* chrome_toolbar_model = 1048 const ChromeToolbarModel* chrome_toolbar_model =
1049 static_cast<const ChromeToolbarModel*>(GetToolbarModel()); 1049 static_cast<const ChromeToolbarModel*>(GetToolbarModel());
1050 return (chrome_toolbar_model->GetSecurityLevel(false) == 1050 return (chrome_toolbar_model->GetSecurityLevel(false) ==
1051 connection_security::EV_SECURE); 1051 SecurityStateModel::EV_SECURE);
1052 } 1052 }
1053 1053
1054 //////////////////////////////////////////////////////////////////////////////// 1054 ////////////////////////////////////////////////////////////////////////////////
1055 // LocationBarView, private LocationBar implementation: 1055 // LocationBarView, private LocationBar implementation:
1056 1056
1057 void LocationBarView::ShowFirstRunBubble() { 1057 void LocationBarView::ShowFirstRunBubble() {
1058 // Wait until search engines have loaded to show the first run bubble. 1058 // Wait until search engines have loaded to show the first run bubble.
1059 TemplateURLService* url_service = 1059 TemplateURLService* url_service =
1060 TemplateURLServiceFactory::GetForProfile(profile()); 1060 TemplateURLServiceFactory::GetForProfile(profile());
1061 if (!url_service->loaded()) { 1061 if (!url_service->loaded()) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 } 1256 }
1257 1257
1258 void LocationBarView::OnPaint(gfx::Canvas* canvas) { 1258 void LocationBarView::OnPaint(gfx::Canvas* canvas) {
1259 View::OnPaint(canvas); 1259 View::OnPaint(canvas);
1260 1260
1261 // Fill the location bar background color behind the border. Parts of the 1261 // Fill the location bar background color behind the border. Parts of the
1262 // border images are meant to rest atop the toolbar background and parts atop 1262 // border images are meant to rest atop the toolbar background and parts atop
1263 // the omnibox background, so we can't just blindly fill our entire bounds. 1263 // the omnibox background, so we can't just blindly fill our entire bounds.
1264 gfx::Rect bounds(GetContentsBounds()); 1264 gfx::Rect bounds(GetContentsBounds());
1265 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness()); 1265 bounds.Inset(GetHorizontalEdgeThickness(), GetVerticalEdgeThickness());
1266 SkColor color(GetColor(connection_security::NONE, BACKGROUND)); 1266 SkColor color(GetColor(SecurityStateModel::NONE, BACKGROUND));
1267 if (is_popup_mode_) { 1267 if (is_popup_mode_) {
1268 canvas->FillRect(bounds, color); 1268 canvas->FillRect(bounds, color);
1269 } else { 1269 } else {
1270 SkPaint paint; 1270 SkPaint paint;
1271 paint.setStyle(SkPaint::kFill_Style); 1271 paint.setStyle(SkPaint::kFill_Style);
1272 paint.setColor(color); 1272 paint.setColor(color);
1273 const int kBorderCornerRadius = 2; 1273 const int kBorderCornerRadius = 2;
1274 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint); 1274 canvas->DrawRoundRect(bounds, kBorderCornerRadius, paint);
1275 } 1275 }
1276 1276
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1403 1403
1404 void LocationBarView::ModelChanged(const SearchModel::State& old_state, 1404 void LocationBarView::ModelChanged(const SearchModel::State& old_state,
1405 const SearchModel::State& new_state) { 1405 const SearchModel::State& new_state) {
1406 const bool visible = !GetToolbarModel()->input_in_progress() && 1406 const bool visible = !GetToolbarModel()->input_in_progress() &&
1407 new_state.voice_search_supported; 1407 new_state.voice_search_supported;
1408 if (mic_search_view_->visible() != visible) { 1408 if (mic_search_view_->visible() != visible) {
1409 mic_search_view_->SetVisible(visible); 1409 mic_search_view_->SetVisible(visible);
1410 Layout(); 1410 Layout();
1411 } 1411 }
1412 } 1412 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698