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/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "cc/paint/skia_paint_canvas.h" | 9 #include "cc/paint/skia_paint_canvas.h" |
| 10 #include "chrome/browser/android/vr_shell/color_scheme.h" | 10 #include "chrome/browser/android/vr_shell/color_scheme.h" |
| 11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | 11 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| 12 #include "components/strings/grit/components_strings.h" | |
| 12 #include "components/toolbar/vector_icons.h" | 13 #include "components/toolbar/vector_icons.h" |
| 13 #include "components/url_formatter/url_formatter.h" | 14 #include "components/url_formatter/url_formatter.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | |
| 14 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/font.h" | 17 #include "ui/gfx/font.h" |
| 16 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 17 #include "ui/gfx/geometry/point_f.h" | 19 #include "ui/gfx/geometry/point_f.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/rect_f.h" | |
| 20 #include "ui/gfx/paint_vector_icon.h" | 21 #include "ui/gfx/paint_vector_icon.h" |
| 21 #include "ui/gfx/render_text.h" | 22 #include "ui/gfx/render_text.h" |
| 22 #include "ui/gfx/vector_icon_types.h" | 23 #include "ui/gfx/vector_icon_types.h" |
| 23 #include "ui/vector_icons/vector_icons.h" | 24 #include "ui/vector_icons/vector_icons.h" |
| 24 | 25 |
| 25 namespace vr_shell { | 26 namespace vr_shell { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 static constexpr float kWidth = 0.672; | 30 static constexpr float kWidth = 0.672; |
| 30 static constexpr float kHeight = 0.088; | 31 static constexpr float kHeight = 0.088; |
| 31 static constexpr float kFontHeight = 0.027; | 32 static constexpr float kFontHeight = 0.027; |
| 32 static constexpr float kBackButtonWidth = kHeight; | 33 static constexpr float kBackButtonWidth = kHeight; |
| 33 static constexpr float kBackIconHeight = 0.0375; | 34 static constexpr float kBackIconHeight = 0.0375; |
| 34 static constexpr float kBackIconOffset = 0.005; | 35 static constexpr float kBackIconOffset = 0.005; |
| 35 static constexpr float kSecurityFieldWidth = 0.06; | 36 static constexpr float kFieldSpacing = 0.014; |
| 36 static constexpr float kSecurityIconHeight = 0.03; | 37 static constexpr float kSecurityIconHeight = 0.03; |
| 37 static constexpr float kUrlRightMargin = 0.02; | 38 static constexpr float kUrlRightMargin = 0.02; |
| 38 static constexpr float kSeparatorWidth = 0.002; | 39 static constexpr float kSeparatorWidth = 0.002; |
| 40 static constexpr float kChipTextLineMargin = kHeight * 0.3; | |
| 39 | 41 |
| 40 using security_state::SecurityLevel; | 42 using security_state::SecurityLevel; |
| 41 | 43 |
| 42 // See ToolbarModelImpl::GetVectorIcon(). | 44 // See ToolbarModelImpl::GetVectorIcon(). |
| 43 const struct gfx::VectorIcon& getSecurityIcon(SecurityLevel level) { | 45 const struct gfx::VectorIcon& GetSecurityIcon(SecurityLevel level) { |
| 44 switch (level) { | 46 switch (level) { |
| 45 case security_state::NONE: | 47 case security_state::NONE: |
| 46 case security_state::HTTP_SHOW_WARNING: | 48 case security_state::HTTP_SHOW_WARNING: |
| 47 return toolbar::kHttpIcon; | 49 return toolbar::kHttpIcon; |
| 48 case security_state::EV_SECURE: | 50 case security_state::EV_SECURE: |
| 49 case security_state::SECURE: | 51 case security_state::SECURE: |
| 50 return toolbar::kHttpsValidIcon; | 52 return toolbar::kHttpsValidIcon; |
| 51 case security_state::SECURITY_WARNING: | 53 case security_state::SECURITY_WARNING: |
| 52 // Surface Dubious as Neutral. | 54 // Surface Dubious as Neutral. |
| 53 return toolbar::kHttpIcon; | 55 return toolbar::kHttpIcon; |
| 54 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. | 56 case security_state::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. |
| 55 return ui::kBusinessIcon; | 57 return ui::kBusinessIcon; |
| 56 case security_state::DANGEROUS: | 58 case security_state::DANGEROUS: |
| 57 return toolbar::kHttpsInvalidIcon; | 59 return toolbar::kHttpsInvalidIcon; |
| 58 default: | 60 default: |
| 59 NOTREACHED(); | 61 NOTREACHED(); |
| 60 return toolbar::kHttpsInvalidIcon; | 62 return toolbar::kHttpsInvalidIcon; |
| 61 } | 63 } |
| 62 } | 64 } |
| 63 | 65 |
| 64 // See LocationBarView::GetSecureTextColor(). | 66 // See LocationBarView::GetSecureTextColor(). |
| 65 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { | 67 SkColor GetSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { |
| 66 switch (level) { | 68 switch (level) { |
| 67 case SecurityLevel::NONE: | 69 case SecurityLevel::NONE: |
| 68 case SecurityLevel::HTTP_SHOW_WARNING: | 70 case SecurityLevel::HTTP_SHOW_WARNING: |
| 69 return color_scheme.url_deemphasized; | 71 return color_scheme.url_deemphasized; |
| 70 case SecurityLevel::EV_SECURE: | 72 case SecurityLevel::EV_SECURE: |
| 71 case SecurityLevel::SECURE: | 73 case SecurityLevel::SECURE: |
| 72 return color_scheme.secure; | 74 return color_scheme.secure; |
| 73 case SecurityLevel::SECURITY_WARNING: | 75 case SecurityLevel::SECURITY_WARNING: |
| 74 return color_scheme.url_deemphasized; | 76 return color_scheme.url_deemphasized; |
| 75 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. | 77 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. |
| 76 return color_scheme.insecure; | 78 return color_scheme.insecure; |
| 77 case SecurityLevel::DANGEROUS: | 79 case SecurityLevel::DANGEROUS: |
| 78 return color_scheme.insecure; | 80 return color_scheme.insecure; |
| 79 default: | 81 default: |
| 80 NOTREACHED(); | 82 NOTREACHED(); |
| 81 return color_scheme.insecure; | 83 return color_scheme.insecure; |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 | 86 |
| 87 // See ToolbarModelImpl::GetSecureVerboseText(). | |
| 88 int GetSecurityTextId(SecurityLevel level, bool malware) { | |
| 89 switch (level) { | |
| 90 case security_state::HTTP_SHOW_WARNING: | |
| 91 return IDS_NOT_SECURE_VERBOSE_STATE; | |
| 92 case security_state::SECURE: | |
| 93 return IDS_SECURE_VERBOSE_STATE; | |
| 94 case security_state::DANGEROUS: | |
| 95 return (malware ? IDS_DANGEROUS_VERBOSE_STATE | |
| 96 : IDS_NOT_SECURE_VERBOSE_STATE); | |
| 97 default: | |
| 98 return 0; | |
| 99 } | |
| 100 } | |
| 101 | |
| 85 void setEmphasis(vr_shell::RenderTextWrapper* render_text, | 102 void setEmphasis(vr_shell::RenderTextWrapper* render_text, |
| 86 bool emphasis, | 103 bool emphasis, |
| 87 const gfx::Range& range, | 104 const gfx::Range& range, |
| 88 const ColorScheme& color_scheme) { | 105 const ColorScheme& color_scheme) { |
| 89 SkColor color = | 106 SkColor color = |
| 90 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; | 107 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; |
| 91 if (range.IsValid()) { | 108 if (range.IsValid()) { |
| 92 render_text->ApplyColor(color, range); | 109 render_text->ApplyColor(color, range); |
| 93 } else { | 110 } else { |
| 94 render_text->SetColor(color); | 111 render_text->SetColor(color); |
| 95 } | 112 } |
| 96 } | 113 } |
| 97 | 114 |
| 98 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 115 gfx::PointF percentToMeters(const gfx::PointF& percent) { |
| 99 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 116 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); |
| 100 } | 117 } |
| 101 | 118 |
| 102 } // namespace | 119 } // namespace |
| 103 | 120 |
| 104 UrlBarTexture::UrlBarTexture( | 121 UrlBarTexture::UrlBarTexture( |
| 105 bool web_vr, | 122 bool web_vr, |
| 106 const base::Callback<void(UiUnsupportedMode)>& failure_callback) | 123 const base::Callback<void(UiUnsupportedMode)>& failure_callback) |
| 107 : security_level_(SecurityLevel::DANGEROUS), | 124 : security_level_(SecurityLevel::DANGEROUS), |
| 108 has_back_button_(!web_vr), | 125 has_back_button_(!web_vr), |
| 126 has_security_chip_(false), | |
|
cjgrant
2017/06/19 15:39:39
I'm leaving this feature disabled until enamel/UX/
ymalik
2017/06/19 15:54:20
Acknowledged.
| |
| 109 failure_callback_(failure_callback) {} | 127 failure_callback_(failure_callback) {} |
| 110 | 128 |
| 111 UrlBarTexture::~UrlBarTexture() = default; | 129 UrlBarTexture::~UrlBarTexture() = default; |
| 112 | 130 |
| 113 void UrlBarTexture::SetURL(const GURL& gurl) { | 131 void UrlBarTexture::SetURL(const GURL& gurl) { |
| 114 if (gurl_ != gurl) | 132 if (gurl_ != gurl) |
| 115 set_dirty(); | 133 set_dirty(); |
| 116 gurl_ = gurl; | 134 gurl_ = gurl; |
| 117 } | 135 } |
| 118 | 136 |
| 119 void UrlBarTexture::SetHistoryButtonsEnabled(bool can_go_back) { | 137 void UrlBarTexture::SetHistoryButtonsEnabled(bool can_go_back) { |
| 120 if (can_go_back != can_go_back_) | 138 if (can_go_back != can_go_back_) |
| 121 set_dirty(); | 139 set_dirty(); |
| 122 can_go_back_ = can_go_back; | 140 can_go_back_ = can_go_back; |
| 123 } | 141 } |
| 124 | 142 |
| 125 void UrlBarTexture::SetSecurityLevel(SecurityLevel level) { | 143 void UrlBarTexture::SetSecurityInfo(SecurityLevel level, bool malware) { |
| 126 if (security_level_ != level) | 144 if (security_level_ != level || malware_ != malware) |
| 127 set_dirty(); | 145 set_dirty(); |
| 128 security_level_ = level; | 146 security_level_ = level; |
| 147 malware_ = malware; | |
| 129 } | 148 } |
| 130 | 149 |
| 131 float UrlBarTexture::ToPixels(float meters) const { | 150 float UrlBarTexture::ToPixels(float meters) const { |
| 132 return meters * size_.width() / kWidth; | 151 return meters * size_.width() / kWidth; |
| 133 } | 152 } |
| 134 | 153 |
| 154 float UrlBarTexture::ToMeters(float pixels) const { | |
| 155 return pixels * kWidth / size_.width(); | |
| 156 } | |
| 157 | |
| 135 bool UrlBarTexture::HitsBackButton(const gfx::PointF& position) const { | 158 bool UrlBarTexture::HitsBackButton(const gfx::PointF& position) const { |
| 136 const gfx::PointF& meters = percentToMeters(position); | 159 const gfx::PointF& meters = percentToMeters(position); |
| 137 gfx::RectF rect(gfx::PointF(0, 0), gfx::SizeF(kBackButtonWidth, kHeight)); | 160 return back_button_hit_region_.Contains(meters) && |
| 138 return rect.Contains(meters) && !HitsTransparentRegion(meters, true); | 161 !HitsTransparentRegion(meters, true); |
| 139 } | 162 } |
| 140 | 163 |
| 141 bool UrlBarTexture::HitsUrlBar(const gfx::PointF& position) const { | 164 bool UrlBarTexture::HitsUrlBar(const gfx::PointF& position) const { |
| 142 const gfx::PointF& meters = percentToMeters(position); | 165 const gfx::PointF& meters = percentToMeters(position); |
| 143 gfx::RectF rect(gfx::PointF(kBackButtonWidth, 0), | 166 gfx::RectF rect(gfx::PointF(kBackButtonWidth, 0), |
| 144 gfx::SizeF(kWidth - kBackButtonWidth, kHeight)); | 167 gfx::SizeF(kWidth - kBackButtonWidth, kHeight)); |
| 145 return rect.Contains(meters) && !HitsTransparentRegion(meters, false); | 168 return rect.Contains(meters) && !HitsTransparentRegion(meters, false); |
| 146 } | 169 } |
| 147 | 170 |
| 148 gfx::PointF UrlBarTexture::SecurityIconPositionMeters() const { | 171 bool UrlBarTexture::HitsSecurityRegion(const gfx::PointF& position) const { |
| 149 float x = has_back_button_ ? kBackButtonWidth + kSeparatorWidth : 0.0f; | 172 return security_hit_region_.Contains(percentToMeters(position)); |
| 150 x += kSecurityFieldWidth / 2 - kSecurityIconHeight / 2; | |
| 151 float y = kHeight / 2 - kSecurityIconHeight / 2; | |
| 152 return gfx::PointF(x, y); | |
| 153 } | |
| 154 | |
| 155 gfx::PointF UrlBarTexture::UrlBarPositionMeters() const { | |
| 156 float x = has_back_button_ ? kBackButtonWidth + kSeparatorWidth : 0.0f; | |
| 157 x += kSecurityFieldWidth; | |
| 158 return gfx::PointF(x, 0); | |
| 159 } | |
| 160 | |
| 161 bool UrlBarTexture::HitsSecurityIcon(const gfx::PointF& position) const { | |
| 162 gfx::RectF rect(SecurityIconPositionMeters(), | |
| 163 gfx::SizeF(kSecurityIconHeight, kSecurityIconHeight)); | |
| 164 return rect.Contains(percentToMeters(position)); | |
| 165 } | 173 } |
| 166 | 174 |
| 167 bool UrlBarTexture::HitsTransparentRegion(const gfx::PointF& meters, | 175 bool UrlBarTexture::HitsTransparentRegion(const gfx::PointF& meters, |
| 168 bool left) const { | 176 bool left) const { |
| 169 const float radius = kHeight / 2.0f; | 177 const float radius = kHeight / 2.0f; |
| 170 gfx::PointF circle_center(left ? radius : kWidth - radius, radius); | 178 gfx::PointF circle_center(left ? radius : kWidth - radius, radius); |
| 171 if (!left && meters.x() < circle_center.x()) | 179 if (!left && meters.x() < circle_center.x()) |
| 172 return false; | 180 return false; |
| 173 if (left && meters.x() > circle_center.x()) | 181 if (left && meters.x() > circle_center.x()) |
| 174 return false; | 182 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 SkPaint paint; | 229 SkPaint paint; |
| 222 paint.setColor(GetLeftCornerColor()); | 230 paint.setColor(GetLeftCornerColor()); |
| 223 canvas->drawRRect(round_rect, paint); | 231 canvas->drawRRect(round_rect, paint); |
| 224 | 232 |
| 225 // URL area. | 233 // URL area. |
| 226 paint.setColor(color_scheme().element_background); | 234 paint.setColor(color_scheme().element_background); |
| 227 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; | 235 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; |
| 228 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); | 236 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); |
| 229 canvas->drawRRect(round_rect, paint); | 237 canvas->drawRRect(round_rect, paint); |
| 230 | 238 |
| 239 back_button_hit_region_.SetRect(0, 0, 0, 0); | |
| 240 security_hit_region_.SetRect(0, 0, 0, 0); | |
| 241 | |
| 242 // Keep track of a left edge as we selectively render components of the URL | |
| 243 // bar left-to-right. | |
| 244 float left_edge = 0; | |
| 245 | |
| 231 if (has_back_button_) { | 246 if (has_back_button_) { |
| 232 // Back button / URL separator vertical line. | 247 // Back button / URL separator vertical line. |
| 233 paint.setColor(color_scheme().separator); | 248 paint.setColor(color_scheme().separator); |
| 234 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), | 249 canvas->drawRect( |
| 235 paint); | 250 SkRect::MakeXYWH(kBackButtonWidth, 0, kSeparatorWidth, kHeight), paint); |
| 236 | 251 |
| 237 // Back button icon. | 252 // Back button icon. |
| 238 canvas->save(); | 253 canvas->save(); |
| 239 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); | 254 canvas->translate(kBackButtonWidth / 2 + kBackIconOffset, kHeight / 2); |
| 240 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); | 255 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); |
| 241 float icon_scale = | 256 float icon_scale = |
| 242 kBackIconHeight / GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); | 257 kBackIconHeight / GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); |
| 243 canvas->scale(icon_scale, icon_scale); | 258 canvas->scale(icon_scale, icon_scale); |
| 244 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, | 259 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, |
| 245 can_go_back_ ? color_scheme().element_foreground | 260 can_go_back_ ? color_scheme().element_foreground |
| 246 : color_scheme().disabled); | 261 : color_scheme().disabled); |
| 247 canvas->restore(); | 262 canvas->restore(); |
| 263 | |
| 264 back_button_hit_region_.SetRect(left_edge, 0, left_edge + kBackButtonWidth, | |
| 265 kHeight); | |
| 266 left_edge += kBackButtonWidth + kSeparatorWidth; | |
| 248 } | 267 } |
| 249 | 268 |
| 250 // Site security state icon. | 269 // Site security state icon. |
| 251 if (!gurl_.is_empty()) { | 270 if (!gurl_.is_empty()) { |
| 271 left_edge += kFieldSpacing; | |
| 272 | |
| 273 gfx::RectF icon_region(left_edge, kHeight / 2 - kSecurityIconHeight / 2, | |
| 274 kSecurityIconHeight, kSecurityIconHeight); | |
| 252 canvas->save(); | 275 canvas->save(); |
| 253 gfx::PointF icon_position = SecurityIconPositionMeters(); | 276 canvas->translate(icon_region.x(), icon_region.y()); |
| 254 canvas->translate(icon_position.x(), icon_position.y()); | 277 const gfx::VectorIcon& icon = GetSecurityIcon(security_level_); |
| 255 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); | |
| 256 float icon_scale = kSecurityIconHeight / GetDefaultSizeOfVectorIcon(icon); | 278 float icon_scale = kSecurityIconHeight / GetDefaultSizeOfVectorIcon(icon); |
| 257 canvas->scale(icon_scale, icon_scale); | 279 canvas->scale(icon_scale, icon_scale); |
| 258 PaintVectorIcon(&gfx_canvas, icon, | 280 PaintVectorIcon(&gfx_canvas, icon, |
| 259 getSchemeColor(security_level_, color_scheme())); | 281 GetSchemeColor(security_level_, color_scheme())); |
| 260 canvas->restore(); | 282 canvas->restore(); |
| 283 | |
| 284 security_hit_region_ = icon_region; | |
| 285 left_edge += kSecurityIconHeight + kFieldSpacing; | |
| 261 } | 286 } |
| 262 | 287 |
| 263 canvas->restore(); | 288 canvas->restore(); |
| 264 | 289 |
| 290 // Draw security chip text (eg. "Not secure") next to the security icon. | |
| 291 int chip_string_id = GetSecurityTextId(security_level_, malware_); | |
| 292 if (has_security_chip_ && !gurl_.is_empty() && chip_string_id != 0) { | |
| 293 float chip_max_width = kWidth - left_edge - kUrlRightMargin; | |
| 294 gfx::Rect text_bounds(ToPixels(left_edge), 0, ToPixels(chip_max_width), | |
| 295 ToPixels(kHeight)); | |
| 296 | |
| 297 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; | |
| 298 SkColor chip_color = GetSchemeColor(security_level_, color_scheme()); | |
| 299 auto chip_text = l10n_util::GetStringUTF16(chip_string_id); | |
| 300 DCHECK(!chip_text.empty()); | |
| 301 | |
| 302 gfx::FontList font_list; | |
| 303 if (!GetFontList(pixel_font_height, chip_text, &font_list)) | |
| 304 failure_callback_.Run(UiUnsupportedMode::kUnhandledCodePoint); | |
| 305 | |
| 306 std::unique_ptr<gfx::RenderText> render_text( | |
| 307 gfx::RenderText::CreateInstance()); | |
| 308 render_text->SetFontList(font_list); | |
| 309 render_text->SetColor(chip_color); | |
| 310 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 311 render_text->SetText(chip_text); | |
| 312 render_text->SetDisplayRect(text_bounds); | |
| 313 render_text->Draw(&gfx_canvas); | |
| 314 | |
| 315 // Capture the rendered text region for future hit testing. | |
| 316 gfx::Size string_size = render_text->GetStringSize(); | |
| 317 gfx::RectF hit_bounds( | |
| 318 left_edge, kHeight / 2 - ToMeters(string_size.height()) / 2, | |
| 319 ToMeters(string_size.width()), ToMeters(string_size.height())); | |
| 320 security_hit_region_.Union(hit_bounds); | |
| 321 left_edge += ToMeters(string_size.width()); | |
| 322 | |
| 323 // Separator line between security text and URL. | |
| 324 left_edge += kFieldSpacing; | |
| 325 paint.setColor(color_scheme().url_deemphasized); | |
| 326 canvas->drawRect( | |
| 327 SkRect::MakeXYWH(ToPixels(left_edge), ToPixels(kChipTextLineMargin), | |
| 328 ToPixels(kSeparatorWidth), | |
| 329 ToPixels(kHeight - 2 * kChipTextLineMargin)), | |
| 330 paint); | |
| 331 left_edge += kFieldSpacing + kSeparatorWidth; | |
| 332 } | |
| 333 | |
| 265 if (!gurl_.is_empty()) { | 334 if (!gurl_.is_empty()) { |
| 266 if (last_drawn_gurl_ != gurl_ || | 335 if (last_drawn_gurl_ != gurl_ || |
| 267 last_drawn_security_level_ != security_level_) { | 336 last_drawn_security_level_ != security_level_) { |
| 268 gfx::PointF url_position = UrlBarPositionMeters(); | 337 float url_x = left_edge; |
| 269 gfx::Rect text_bounds( | 338 float url_width = kWidth - url_x - kUrlRightMargin; |
| 270 ToPixels(url_position.x()), ToPixels(url_position.y()), | 339 gfx::Rect text_bounds(ToPixels(url_x), 0, ToPixels(url_width), |
| 271 ToPixels(kWidth - url_position.x() - kUrlRightMargin), | 340 ToPixels(kHeight)); |
| 272 ToPixels(kHeight)); | |
| 273 RenderUrl(texture_size, text_bounds); | 341 RenderUrl(texture_size, text_bounds); |
| 274 last_drawn_gurl_ = gurl_; | 342 last_drawn_gurl_ = gurl_; |
| 275 last_drawn_security_level_ = security_level_; | 343 last_drawn_security_level_ = security_level_; |
| 276 } | 344 } |
| 277 url_render_text_->Draw(&gfx_canvas); | 345 url_render_text_->Draw(&gfx_canvas); |
| 278 } | 346 } |
| 279 } | 347 } |
| 280 | 348 |
| 281 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, | 349 void UrlBarTexture::RenderUrl(const gfx::Size& texture_size, |
| 282 const gfx::Rect& bounds) { | 350 const gfx::Rect& bounds) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 374 color_scheme); | 442 color_scheme); |
| 375 break; | 443 break; |
| 376 } | 444 } |
| 377 | 445 |
| 378 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by | 446 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by |
| 379 // SafeBrowsing) get a special scheme color treatment. If the security level | 447 // SafeBrowsing) get a special scheme color treatment. If the security level |
| 380 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously | 448 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously |
| 381 // applied to the scheme text range by setEmphasis(). | 449 // applied to the scheme text range by setEmphasis(). |
| 382 if (scheme_range.IsValid() && security_level != security_state::NONE && | 450 if (scheme_range.IsValid() && security_level != security_state::NONE && |
| 383 security_level != security_state::HTTP_SHOW_WARNING) { | 451 security_level != security_state::HTTP_SHOW_WARNING) { |
| 384 render_text->ApplyColor(getSchemeColor(security_level, color_scheme), | 452 render_text->ApplyColor(GetSchemeColor(security_level, color_scheme), |
| 385 scheme_range); | 453 scheme_range); |
| 386 if (security_level == SecurityLevel::DANGEROUS) { | 454 if (security_level == SecurityLevel::DANGEROUS) { |
| 387 render_text->ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, | 455 render_text->ApplyStyle(gfx::TextStyle::STRIKE, true, scheme_range); |
| 388 scheme_range); | |
| 389 } | 456 } |
| 390 } | 457 } |
| 391 } | 458 } |
| 392 | 459 |
| 393 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 460 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 394 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 461 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 395 } | 462 } |
| 396 | 463 |
| 397 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 464 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 398 return size_; | 465 return size_; |
| 399 } | 466 } |
| 400 | 467 |
| 401 } // namespace vr_shell | 468 } // namespace vr_shell |
| OLD | NEW |