OLD | NEW |
---|---|
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 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 return ui::MaterialDesignController::IsModeMaterial() | 332 return ui::MaterialDesignController::IsModeMaterial() |
333 ? gfx::kGoogleGreen700 | 333 ? gfx::kGoogleGreen700 |
334 : SkColorSetRGB(7, 149, 0); | 334 : SkColorSetRGB(7, 149, 0); |
335 } | 335 } |
336 NOTREACHED(); | 336 NOTREACHED(); |
337 return gfx::kPlaceholderColor; | 337 return gfx::kPlaceholderColor; |
338 } | 338 } |
339 | 339 |
340 SkColor LocationBarView::GetSecureTextColor( | 340 SkColor LocationBarView::GetSecureTextColor( |
341 security_state::SecurityStateModel::SecurityLevel security_level) const { | 341 security_state::SecurityStateModel::SecurityLevel security_level) const { |
342 bool md = ui::MaterialDesignController::IsModeMaterial(); | |
342 bool inverted = color_utils::IsDark(GetColor(BACKGROUND)); | 343 bool inverted = color_utils::IsDark(GetColor(BACKGROUND)); |
343 SkColor color; | |
344 switch (security_level) { | |
345 case security_state::SecurityStateModel::EV_SECURE: | |
346 case security_state::SecurityStateModel::SECURE: | |
347 if (ui::MaterialDesignController::IsModeMaterial() && inverted) | |
348 return GetColor(TEXT); | |
349 color = GetColor(EV_BUBBLE_TEXT_AND_BORDER); | |
350 break; | |
351 | 344 |
352 case security_state::SecurityStateModel::SECURITY_POLICY_WARNING: | 345 if (security_level == security_state::SecurityStateModel::EV_SECURE || |
353 return GetColor(DEEMPHASIZED_TEXT); | 346 security_level == security_state::SecurityStateModel::SECURE) { |
354 break; | 347 if (md && inverted) |
348 return GetColor(TEXT); | |
349 return color_utils::GetReadableColor(GetColor(EV_BUBBLE_TEXT_AND_BORDER), | |
350 GetColor(BACKGROUND)); | |
351 } | |
355 | 352 |
356 case security_state::SecurityStateModel::SECURITY_ERROR: { | 353 if (security_level == |
357 bool md = ui::MaterialDesignController::IsModeMaterial(); | 354 security_state::SecurityStateModel::SECURITY_POLICY_WARNING) { |
358 if (md && inverted) | 355 return GetColor(DEEMPHASIZED_TEXT); |
359 return GetColor(TEXT); | 356 } |
360 color = md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0); | |
361 break; | |
362 } | |
363 | 357 |
364 case security_state::SecurityStateModel::SECURITY_WARNING: | 358 if (security_level == security_state::SecurityStateModel::SECURITY_ERROR) { |
359 if (md && inverted) | |
365 return GetColor(TEXT); | 360 return GetColor(TEXT); |
366 break; | 361 return color_utils::GetReadableColor( |
362 md ? gfx::kGoogleRed700 : SkColorSetRGB(162, 0, 0), | |
363 GetColor(BACKGROUND)); | |
364 } | |
367 | 365 |
368 default: | 366 DCHECK_EQ(security_state::SecurityStateModel::SECURITY_WARNING, |
369 NOTREACHED(); | 367 security_level); |
370 return gfx::kPlaceholderColor; | 368 return color_utils::GetReadableColor(GetColor(TEXT), GetColor(BACKGROUND)); |
371 } | |
372 return color_utils::GetReadableColor(color, GetColor(BACKGROUND)); | |
373 } | 369 } |
Peter Kasting
2016/05/19 20:36:25
Here's an even shorter way to write this that elim
Peter Kasting
2016/05/19 20:42:53
Even shorter:
if (security_level ==
secur
palmer
2016/05/19 20:59:06
That is good; but: it no longer has the DCHECK_EQ,
Peter Kasting
2016/05/19 21:02:28
I considered that when I wrote it and decided that
| |
374 | 370 |
375 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { | 371 void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) { |
376 DCHECK(zoom_view_); | 372 DCHECK(zoom_view_); |
377 if (RefreshZoomView()) { | 373 if (RefreshZoomView()) { |
378 Layout(); | 374 Layout(); |
379 SchedulePaint(); | 375 SchedulePaint(); |
380 } | 376 } |
381 | 377 |
382 WebContents* web_contents = GetWebContents(); | 378 WebContents* web_contents = GetWebContents(); |
383 if (can_show_bubble && zoom_view_->visible() && web_contents) | 379 if (can_show_bubble && zoom_view_->visible() && web_contents) |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
862 return; | 858 return; |
863 | 859 |
864 if (ui::MaterialDesignController::IsModeMaterial()) { | 860 if (ui::MaterialDesignController::IsModeMaterial()) { |
865 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; | 861 gfx::VectorIconId icon_id = gfx::VectorIconId::VECTOR_ICON_NONE; |
866 const int kIconSize = 16; | 862 const int kIconSize = 16; |
867 SkColor icon_color = gfx::kPlaceholderColor; | 863 SkColor icon_color = gfx::kPlaceholderColor; |
868 if (ShouldShowEVBubble()) { | 864 if (ShouldShowEVBubble()) { |
869 icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; | 865 icon_id = gfx::VectorIconId::LOCATION_BAR_HTTPS_VALID_IN_CHIP; |
870 icon_color = location_icon_view_->GetTextColor(); | 866 icon_color = location_icon_view_->GetTextColor(); |
871 } else { | 867 } else { |
872 icon_id = omnibox_view_->GetVectorIcon( | 868 icon_id = omnibox_view_->GetVectorIcon(); |
873 color_utils::IsDark(GetColor(BACKGROUND))); | 869 security_state::SecurityStateModel::SecurityLevel security_level = |
874 icon_color = color_utils::DeriveDefaultIconColor(GetColor(TEXT)); | 870 GetToolbarModel()->GetSecurityLevel(false); |
871 icon_color = (security_level == security_state::SecurityStateModel::NONE) | |
872 ? color_utils::DeriveDefaultIconColor(GetColor(TEXT)) | |
873 : GetSecureTextColor(security_level); | |
875 } | 874 } |
876 location_icon_view_->SetImage( | 875 location_icon_view_->SetImage( |
877 gfx::CreateVectorIcon(icon_id, kIconSize, icon_color)); | 876 gfx::CreateVectorIcon(icon_id, kIconSize, icon_color)); |
878 } else { | 877 } else { |
879 location_icon_view_->SetImage( | 878 location_icon_view_->SetImage( |
880 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); | 879 *GetThemeProvider()->GetImageSkiaNamed(omnibox_view_->GetIcon())); |
881 } | 880 } |
882 } | 881 } |
883 | 882 |
884 bool LocationBarView::RefreshContentSettingViews() { | 883 bool LocationBarView::RefreshContentSettingViews() { |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1384 // LocationBarView, private TemplateURLServiceObserver implementation: | 1383 // LocationBarView, private TemplateURLServiceObserver implementation: |
1385 | 1384 |
1386 void LocationBarView::OnTemplateURLServiceChanged() { | 1385 void LocationBarView::OnTemplateURLServiceChanged() { |
1387 template_url_service_->RemoveObserver(this); | 1386 template_url_service_->RemoveObserver(this); |
1388 template_url_service_ = nullptr; | 1387 template_url_service_ = nullptr; |
1389 // If the browser is no longer active, let's not show the info bubble, as this | 1388 // If the browser is no longer active, let's not show the info bubble, as this |
1390 // would make the browser the active window again. | 1389 // would make the browser the active window again. |
1391 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) | 1390 if (omnibox_view_ && omnibox_view_->GetWidget()->IsActive()) |
1392 ShowFirstRunBubble(); | 1391 ShowFirstRunBubble(); |
1393 } | 1392 } |
OLD | NEW |