| 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 "chrome/browser/android/vr_shell/color_scheme.h" | 9 #include "chrome/browser/android/vr_shell/color_scheme.h" |
| 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" | 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 return rect.Contains(meters) && !HitsTransparentRegion(meters, true); | 128 return rect.Contains(meters) && !HitsTransparentRegion(meters, true); |
| 129 } | 129 } |
| 130 | 130 |
| 131 bool UrlBarTexture::HitsUrlBar(const gfx::PointF& position) const { | 131 bool UrlBarTexture::HitsUrlBar(const gfx::PointF& position) const { |
| 132 const gfx::PointF& meters = percentToMeters(position); | 132 const gfx::PointF& meters = percentToMeters(position); |
| 133 gfx::RectF rect(gfx::PointF(kBackButtonWidth, 0), | 133 gfx::RectF rect(gfx::PointF(kBackButtonWidth, 0), |
| 134 gfx::SizeF(kWidth - kBackButtonWidth, kHeight)); | 134 gfx::SizeF(kWidth - kBackButtonWidth, kHeight)); |
| 135 return rect.Contains(meters) && !HitsTransparentRegion(meters, false); | 135 return rect.Contains(meters) && !HitsTransparentRegion(meters, false); |
| 136 } | 136 } |
| 137 | 137 |
| 138 gfx::PointF UrlBarTexture::SecurityIconPositionMeters() const { |
| 139 float x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2 - |
| 140 kSecurityIconHeight / 2; |
| 141 float y = kHeight / 2 - kSecurityIconHeight / 2; |
| 142 return gfx::PointF(x, y); |
| 143 } |
| 144 |
| 145 bool UrlBarTexture::HitsSecurityIcon(const gfx::PointF& position) const { |
| 146 gfx::RectF rect(SecurityIconPositionMeters(), |
| 147 gfx::SizeF(kSecurityIconHeight, kSecurityIconHeight)); |
| 148 return rect.Contains(percentToMeters(position)); |
| 149 } |
| 150 |
| 138 bool UrlBarTexture::HitsTransparentRegion(const gfx::PointF& meters, | 151 bool UrlBarTexture::HitsTransparentRegion(const gfx::PointF& meters, |
| 139 bool left) const { | 152 bool left) const { |
| 140 const float radius = kHeight / 2.0f; | 153 const float radius = kHeight / 2.0f; |
| 141 gfx::PointF circle_center(left ? radius : kWidth - radius, radius); | 154 gfx::PointF circle_center(left ? radius : kWidth - radius, radius); |
| 142 if (!left && meters.x() < circle_center.x()) | 155 if (!left && meters.x() < circle_center.x()) |
| 143 return false; | 156 return false; |
| 144 if (left && meters.x() > circle_center.x()) | 157 if (left && meters.x() > circle_center.x()) |
| 145 return false; | 158 return false; |
| 146 return (meters - circle_center).LengthSquared() > radius * radius; | 159 return (meters - circle_center).LengthSquared() > radius * radius; |
| 147 } | 160 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 float icon_scale = kBackIconHeight / icon_default_height; | 225 float icon_scale = kBackIconHeight / icon_default_height; |
| 213 canvas->scale(icon_scale, icon_scale); | 226 canvas->scale(icon_scale, icon_scale); |
| 214 PaintVectorIcon( | 227 PaintVectorIcon( |
| 215 &gfx_canvas, ui::kBackArrowIcon, | 228 &gfx_canvas, ui::kBackArrowIcon, |
| 216 can_go_back_ ? color_scheme().foreground : color_scheme().disabled); | 229 can_go_back_ ? color_scheme().foreground : color_scheme().disabled); |
| 217 canvas->restore(); | 230 canvas->restore(); |
| 218 | 231 |
| 219 // Site security state icon. | 232 // Site security state icon. |
| 220 if (!gurl_.is_empty()) { | 233 if (!gurl_.is_empty()) { |
| 221 canvas->save(); | 234 canvas->save(); |
| 222 canvas->translate( | 235 gfx::PointF icon_position = SecurityIconPositionMeters(); |
| 223 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, | 236 canvas->translate(icon_position.x(), icon_position.y()); |
| 224 kHeight / 2); | |
| 225 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); | |
| 226 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); | 237 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); |
| 227 icon_default_height = GetDefaultSizeOfVectorIcon(icon); | 238 icon_default_height = GetDefaultSizeOfVectorIcon(icon); |
| 228 icon_scale = kSecurityIconHeight / icon_default_height; | 239 icon_scale = kSecurityIconHeight / icon_default_height; |
| 229 SkColor icon_color = getSchemeColor(security_level_, color_scheme()); | 240 SkColor icon_color = getSchemeColor(security_level_, color_scheme()); |
| 230 canvas->scale(icon_scale, icon_scale); | 241 canvas->scale(icon_scale, icon_scale); |
| 231 PaintVectorIcon(&gfx_canvas, icon, icon_color); | 242 PaintVectorIcon(&gfx_canvas, icon, icon_color); |
| 232 canvas->restore(); | 243 canvas->restore(); |
| 233 } | 244 } |
| 234 | 245 |
| 235 canvas->restore(); | 246 canvas->restore(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 | 371 |
| 361 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 372 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 362 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 373 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 363 } | 374 } |
| 364 | 375 |
| 365 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 376 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 366 return size_; | 377 return size_; |
| 367 } | 378 } |
| 368 | 379 |
| 369 } // namespace vr_shell | 380 } // namespace vr_shell |
| OLD | NEW |