| 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 "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/font.h" | 11 #include "ui/gfx/font.h" |
| 11 #include "ui/gfx/font_list.h" | 12 #include "ui/gfx/font_list.h" |
| 12 #include "ui/gfx/geometry/rect.h" | 13 #include "ui/gfx/geometry/rect.h" |
| 13 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 14 #include "ui/gfx/vector_icon_types.h" | 15 #include "ui/gfx/vector_icon_types.h" |
| 15 #include "ui/vector_icons/vector_icons.h" | 16 #include "ui/vector_icons/vector_icons.h" |
| 16 | 17 |
| 17 namespace vr_shell { | 18 namespace vr_shell { |
| 18 | 19 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 29 static constexpr float kHeight = 0.088; | 30 static constexpr float kHeight = 0.088; |
| 30 static constexpr float kFontHeight = 0.027; | 31 static constexpr float kFontHeight = 0.027; |
| 31 static constexpr float kBackButtonWidth = kHeight; | 32 static constexpr float kBackButtonWidth = kHeight; |
| 32 static constexpr float kBackIconHeight = 0.05; | 33 static constexpr float kBackIconHeight = 0.05; |
| 33 static constexpr float kBackIconOffset = 0.005; | 34 static constexpr float kBackIconOffset = 0.005; |
| 34 static constexpr float kSecurityFieldWidth = 0.06; | 35 static constexpr float kSecurityFieldWidth = 0.06; |
| 35 static constexpr float kSecurityIconHeight = 0.03; | 36 static constexpr float kSecurityIconHeight = 0.03; |
| 36 static constexpr float kUrlRightMargin = 0.02; | 37 static constexpr float kUrlRightMargin = 0.02; |
| 37 static constexpr float kSeparatorWidth = 0.002; | 38 static constexpr float kSeparatorWidth = 0.002; |
| 38 | 39 |
| 40 using security_state::SecurityLevel; |
| 41 |
| 42 const struct gfx::VectorIcon& getSecurityIcon(int level) { |
| 43 switch (level) { |
| 44 case SecurityLevel::NONE: |
| 45 case SecurityLevel::HTTP_SHOW_WARNING: |
| 46 case SecurityLevel::SECURITY_WARNING: |
| 47 return ui::kInfoOutlineIcon; |
| 48 case SecurityLevel::SECURE: |
| 49 case SecurityLevel::EV_SECURE: |
| 50 // TODO(cjgrant): Use the lock icon when available. |
| 51 // return ui::kLockIcon; |
| 52 return ui::kInfoOutlineIcon; |
| 53 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: |
| 54 case SecurityLevel::DANGEROUS: |
| 55 default: |
| 56 return ui::kWarningIcon; |
| 57 } |
| 58 } |
| 59 |
| 39 } // namespace | 60 } // namespace |
| 40 | 61 |
| 41 UrlBarTexture::UrlBarTexture() = default; | 62 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} |
| 42 | 63 |
| 43 UrlBarTexture::~UrlBarTexture() = default; | 64 UrlBarTexture::~UrlBarTexture() = default; |
| 44 | 65 |
| 45 void UrlBarTexture::SetHover(bool hover) { | 66 void UrlBarTexture::SetHover(bool hover) { |
| 46 hover_ = hover; | 67 hover_ = hover; |
| 47 } | 68 } |
| 48 | 69 |
| 49 void UrlBarTexture::SetURL(const GURL& gurl) { | 70 void UrlBarTexture::SetURL(const GURL& gurl) { |
| 50 gurl_ = gurl; | 71 gurl_ = gurl; |
| 51 } | 72 } |
| 52 | 73 |
| 74 void UrlBarTexture::SetSecurityLevel(int level) { |
| 75 security_level_ = level; |
| 76 } |
| 77 |
| 53 float UrlBarTexture::ToPixels(float meters) const { | 78 float UrlBarTexture::ToPixels(float meters) const { |
| 54 return meters * size_.width() / kWidth; | 79 return meters * size_.width() / kWidth; |
| 55 } | 80 } |
| 56 | 81 |
| 57 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { | 82 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { |
| 58 size_.set_height(texture_size.height()); | 83 size_.set_height(texture_size.height()); |
| 59 size_.set_width(texture_size.width()); | 84 size_.set_width(texture_size.width()); |
| 60 | 85 |
| 61 canvas->save(); | 86 canvas->save(); |
| 62 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); | 87 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); | 117 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); |
| 93 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); | 118 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); |
| 94 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); | 119 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); |
| 95 float icon_scale = kBackIconHeight / icon_default_height; | 120 float icon_scale = kBackIconHeight / icon_default_height; |
| 96 canvas->scale(icon_scale, icon_scale); | 121 canvas->scale(icon_scale, icon_scale); |
| 97 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); | 122 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); |
| 98 canvas->restore(); | 123 canvas->restore(); |
| 99 | 124 |
| 100 // Site security state icon. | 125 // Site security state icon. |
| 101 // TODO(cjgrant): Plug in the correct icons based on security level. | 126 // TODO(cjgrant): Plug in the correct icons based on security level. |
| 102 canvas->save(); | 127 if (!gurl_.spec().empty()) { |
| 103 canvas->translate( | 128 canvas->save(); |
| 104 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, | 129 canvas->translate( |
| 105 kHeight / 2); | 130 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, |
| 106 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); | 131 kHeight / 2); |
| 107 icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); | 132 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); |
| 108 icon_scale = kSecurityIconHeight / icon_default_height; | 133 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_); |
| 109 canvas->scale(icon_scale, icon_scale); | 134 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon); |
| 110 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); | 135 icon_scale = kSecurityIconHeight / icon_default_height; |
| 111 canvas->restore(); | 136 canvas->scale(icon_scale, icon_scale); |
| 137 PaintVectorIcon(&gfx_canvas, security_icon, kForeground); |
| 138 canvas->restore(); |
| 139 } |
| 112 | 140 |
| 113 canvas->restore(); | 141 canvas->restore(); |
| 114 | 142 |
| 115 // Draw text based on pixel sizes rather than meters, for correct font sizing. | 143 // Draw text based on pixel sizes rather than meters, for correct font sizing. |
| 116 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | 144 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; |
| 117 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT; | 145 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT; |
| 118 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; | 146 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; |
| 119 float url_width = kWidth - url_x - kUrlRightMargin; | 147 float url_width = kWidth - url_x - kUrlRightMargin; |
| 120 gfx_canvas.DrawStringRectWithFlags( | 148 gfx_canvas.DrawStringRectWithFlags( |
| 121 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height), | 149 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height), |
| 122 SK_ColorBLACK, | 150 SK_ColorBLACK, |
| 123 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)), | 151 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)), |
| 124 text_flags); | 152 text_flags); |
| 125 } | 153 } |
| 126 | 154 |
| 127 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 155 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 128 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 156 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 129 } | 157 } |
| 130 | 158 |
| 131 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 159 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 132 return size_; | 160 return size_; |
| 133 } | 161 } |
| 134 | 162 |
| 135 } // namespace vr_shell | 163 } // namespace vr_shell |
| OLD | NEW |