Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/android/vr_shell/textures/url_bar_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/url_bar_texture.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "cc/paint/skia_paint_canvas.h" | 8 #include "cc/paint/skia_paint_canvas.h" |
| 9 #include "components/security_state/core/security_state.h" | 9 #include "components/security_state/core/security_state.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
| 12 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" |
| 13 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 15 #include "ui/gfx/render_text.h" | 15 #include "ui/gfx/render_text.h" |
| 16 #include "ui/gfx/vector_icon_types.h" | 16 #include "ui/gfx/vector_icon_types.h" |
| 17 #include "ui/vector_icons/vector_icons.h" | 17 #include "ui/vector_icons/vector_icons.h" |
| 18 | 18 |
| 19 namespace vr_shell { | 19 namespace vr_shell { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 static constexpr SkColor kBackground = 0xCCAAAAAA; | 23 static constexpr SkColor kBackground = 0xCCAAAAAA; |
| 24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD; | 24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD; |
| 25 static constexpr SkColor kForeground = 0xCC444444; | 25 static constexpr SkColor kForeground = 0xCC444444; |
| 26 static constexpr SkColor kSeparatorColor = | 26 static constexpr SkColor kSeparatorColor = 0x51000000; |
| 27 SkColorSetARGBMacro(256 * 0.2, 0, 0, 0); | 27 |
| 28 static constexpr SkColor kInfoOutlineIconColor = 0xFF5A5A5A; | |
| 29 static constexpr SkColor kLockIconColor = 0xFF0B8043; | |
| 30 static constexpr SkColor kWarningIconColor = 0xFFC73821; | |
| 28 | 31 |
| 29 static constexpr float kWidth = 0.672; | 32 static constexpr float kWidth = 0.672; |
| 30 static constexpr float kHeight = 0.088; | 33 static constexpr float kHeight = 0.088; |
| 31 static constexpr float kFontHeight = 0.027; | 34 static constexpr float kFontHeight = 0.027; |
| 32 static constexpr float kBackButtonWidth = kHeight; | 35 static constexpr float kBackButtonWidth = kHeight; |
| 33 static constexpr float kBackIconHeight = 0.05; | 36 static constexpr float kBackIconHeight = 0.05; |
| 34 static constexpr float kBackIconOffset = 0.005; | 37 static constexpr float kBackIconOffset = 0.005; |
| 35 static constexpr float kSecurityFieldWidth = 0.06; | 38 static constexpr float kSecurityFieldWidth = 0.06; |
| 36 static constexpr float kSecurityIconHeight = 0.03; | 39 static constexpr float kSecurityIconHeight = 0.03; |
| 37 static constexpr float kUrlRightMargin = 0.02; | 40 static constexpr float kUrlRightMargin = 0.02; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 48 case SecurityLevel::SECURE: | 51 case SecurityLevel::SECURE: |
| 49 case SecurityLevel::EV_SECURE: | 52 case SecurityLevel::EV_SECURE: |
| 50 return ui::kLockIcon; | 53 return ui::kLockIcon; |
| 51 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: | 54 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: |
| 52 case SecurityLevel::DANGEROUS: | 55 case SecurityLevel::DANGEROUS: |
| 53 default: | 56 default: |
| 54 return ui::kWarningIcon; | 57 return ui::kWarningIcon; |
| 55 } | 58 } |
| 56 } | 59 } |
| 57 | 60 |
| 61 SkColor getSecurityIconColor(int level) { | |
|
cjgrant
2017/05/15 21:53:17
This seems cleaner than the above function return
| |
| 62 switch (level) { | |
| 63 case SecurityLevel::NONE: | |
| 64 case SecurityLevel::HTTP_SHOW_WARNING: | |
| 65 case SecurityLevel::SECURITY_WARNING: | |
| 66 return kInfoOutlineIconColor; | |
| 67 case SecurityLevel::SECURE: | |
| 68 case SecurityLevel::EV_SECURE: | |
| 69 return kLockIconColor; | |
| 70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: | |
| 71 case SecurityLevel::DANGEROUS: | |
| 72 default: | |
| 73 return kWarningIconColor; | |
| 74 } | |
| 75 } | |
| 76 | |
| 58 } // namespace | 77 } // namespace |
| 59 | 78 |
| 60 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} | 79 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} |
| 61 | 80 |
| 62 UrlBarTexture::~UrlBarTexture() = default; | 81 UrlBarTexture::~UrlBarTexture() = default; |
| 63 | 82 |
| 64 void UrlBarTexture::SetURL(const GURL& gurl) { | 83 void UrlBarTexture::SetURL(const GURL& gurl) { |
| 65 if (gurl_ != gurl) | 84 if (gurl_ != gurl) |
| 66 set_dirty(); | 85 set_dirty(); |
| 67 gurl_ = gurl; | 86 gurl_ = gurl; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); | 138 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); |
| 120 canvas->restore(); | 139 canvas->restore(); |
| 121 | 140 |
| 122 // Site security state icon. | 141 // Site security state icon. |
| 123 if (!gurl_.is_empty()) { | 142 if (!gurl_.is_empty()) { |
| 124 canvas->save(); | 143 canvas->save(); |
| 125 canvas->translate( | 144 canvas->translate( |
| 126 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, | 145 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, |
| 127 kHeight / 2); | 146 kHeight / 2); |
| 128 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); | 147 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); |
| 129 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_); | 148 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); |
| 130 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon); | 149 icon_default_height = GetDefaultSizeOfVectorIcon(icon); |
| 131 icon_scale = kSecurityIconHeight / icon_default_height; | 150 icon_scale = kSecurityIconHeight / icon_default_height; |
| 151 SkColor icon_color = getSecurityIconColor(security_level_); | |
| 132 canvas->scale(icon_scale, icon_scale); | 152 canvas->scale(icon_scale, icon_scale); |
| 133 PaintVectorIcon(&gfx_canvas, security_icon, kForeground); | 153 PaintVectorIcon(&gfx_canvas, icon, icon_color); |
| 134 canvas->restore(); | 154 canvas->restore(); |
| 135 } | 155 } |
| 136 | 156 |
| 137 canvas->restore(); | 157 canvas->restore(); |
| 138 | 158 |
| 139 if (!gurl_.is_empty()) { | 159 if (!gurl_.is_empty()) { |
| 140 if (last_drawn_gurl_ != gurl_) { | 160 if (last_drawn_gurl_ != gurl_) { |
| 141 // Draw text based on pixel sizes rather than meters, for correct font | 161 // Draw text based on pixel sizes rather than meters, for correct font |
| 142 // sizing. | 162 // sizing. |
| 143 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 163 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 164 return size_; | 184 return size_; |
| 165 } | 185 } |
| 166 | 186 |
| 167 bool UrlBarTexture::SetDrawFlags(int draw_flags) { | 187 bool UrlBarTexture::SetDrawFlags(int draw_flags) { |
| 168 if (draw_flags != GetDrawFlags()) | 188 if (draw_flags != GetDrawFlags()) |
| 169 set_dirty(); | 189 set_dirty(); |
| 170 return UiTexture::SetDrawFlags(draw_flags); | 190 return UiTexture::SetDrawFlags(draw_flags); |
| 171 } | 191 } |
| 172 | 192 |
| 173 } // namespace vr_shell | 193 } // namespace vr_shell |
| OLD | NEW |