Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: chrome/browser/android/vr_shell/textures/url_bar_texture.cc

Issue 2885433003: VR: Implement Omnibox input targeting. (Closed)
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/point_f.h"
13 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/geometry/rect_f.h"
14 #include "ui/gfx/paint_vector_icon.h" 16 #include "ui/gfx/paint_vector_icon.h"
15 #include "ui/gfx/render_text.h" 17 #include "ui/gfx/render_text.h"
16 #include "ui/gfx/vector_icon_types.h" 18 #include "ui/gfx/vector_icon_types.h"
17 #include "ui/vector_icons/vector_icons.h" 19 #include "ui/vector_icons/vector_icons.h"
18 20
19 namespace vr_shell { 21 namespace vr_shell {
20 22
21 namespace { 23 namespace {
22 24
23 static constexpr SkColor kBackground = 0xCCAAAAAA; 25 // TODO(mthiesse): These values are all wrong. The UX spec is unclear.
24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD; 26 static constexpr SkColor kBackground = 0x66D6D6D6;
25 static constexpr SkColor kForeground = 0xCC444444; 27 static constexpr SkColor kBackgroundHover = 0x6EF0F0F0;
26 static constexpr SkColor kSeparatorColor = 0x51000000; 28 static constexpr SkColor kBackgroundDown = 0x76F6F6F6;
29 static constexpr SkColor kForeground = 0xFF333333;
30 static constexpr SkColor kSeparatorColor = 0x33000000;
27 31
28 static constexpr SkColor kInfoOutlineIconColor = 0xFF5A5A5A; 32 static constexpr SkColor kInfoOutlineIconColor = 0xFF5A5A5A;
29 static constexpr SkColor kLockIconColor = 0xFF0B8043; 33 static constexpr SkColor kLockIconColor = 0xFF0B8043;
30 static constexpr SkColor kWarningIconColor = 0xFFC73821; 34 static constexpr SkColor kWarningIconColor = 0xFFC73821;
31 35
32 static constexpr float kWidth = 0.672; 36 static constexpr float kWidth = 0.672;
33 static constexpr float kHeight = 0.088; 37 static constexpr float kHeight = 0.088;
34 static constexpr float kFontHeight = 0.027; 38 static constexpr float kFontHeight = 0.027;
35 static constexpr float kBackButtonWidth = kHeight; 39 static constexpr float kBackButtonWidth = kHeight;
36 static constexpr float kBackIconHeight = 0.05; 40 static constexpr float kBackIconHeight = 0.05;
(...skipping 30 matching lines...) Expand all
67 case SecurityLevel::SECURE: 71 case SecurityLevel::SECURE:
68 case SecurityLevel::EV_SECURE: 72 case SecurityLevel::EV_SECURE:
69 return kLockIconColor; 73 return kLockIconColor;
70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: 74 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT:
71 case SecurityLevel::DANGEROUS: 75 case SecurityLevel::DANGEROUS:
72 default: 76 default:
73 return kWarningIconColor; 77 return kWarningIconColor;
74 } 78 }
75 } 79 }
76 80
81 gfx::PointF percentToMeters(const gfx::PointF& percent) {
82 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight);
83 }
84
77 } // namespace 85 } // namespace
78 86
79 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} 87 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {}
80 88
81 UrlBarTexture::~UrlBarTexture() = default; 89 UrlBarTexture::~UrlBarTexture() = default;
82 90
83 void UrlBarTexture::SetURL(const GURL& gurl) { 91 void UrlBarTexture::SetURL(const GURL& gurl) {
84 if (gurl_ != gurl) 92 if (gurl_ != gurl)
85 set_dirty(); 93 set_dirty();
86 gurl_ = gurl; 94 gurl_ = gurl;
87 } 95 }
88 96
89 void UrlBarTexture::SetSecurityLevel(int level) { 97 void UrlBarTexture::SetSecurityLevel(int level) {
90 if (&getSecurityIcon(security_level_) != &getSecurityIcon(level)) 98 if (&getSecurityIcon(security_level_) != &getSecurityIcon(level))
91 set_dirty(); 99 set_dirty();
92 security_level_ = level; 100 security_level_ = level;
93 } 101 }
94 102
95 float UrlBarTexture::ToPixels(float meters) const { 103 float UrlBarTexture::ToPixels(float meters) const {
96 return meters * size_.width() / kWidth; 104 return meters * size_.width() / kWidth;
97 } 105 }
98 106
107 bool UrlBarTexture::HitsBackButton(const gfx::PointF& position) const {
108 const gfx::PointF& meters = percentToMeters(position);
109 gfx::RectF rect(gfx::PointF(0, 0), gfx::SizeF(kBackButtonWidth, kHeight));
110 return rect.Contains(meters) && !HitsTransparentRegion(meters, true);
111 }
112
113 bool UrlBarTexture::HitsUrlBar(const gfx::PointF& position) const {
114 const gfx::PointF& meters = percentToMeters(position);
115 gfx::RectF rect(gfx::PointF(kBackButtonWidth, 0),
116 gfx::SizeF(kWidth - kBackButtonWidth, kHeight));
117 return rect.Contains(meters) && !HitsTransparentRegion(meters, false);
118 }
119
120 bool UrlBarTexture::HitsTransparentRegion(const gfx::PointF& meters,
121 bool left) const {
122 const float radius = kHeight / 2.0f;
123 gfx::PointF circle_center(left ? radius : kWidth - radius, radius);
124 if (!left && meters.x() < circle_center.x())
125 return false;
126 if (left && meters.x() > circle_center.x())
127 return false;
128 return (meters - circle_center).LengthSquared() > radius * radius;
129 }
130
99 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 131 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
100 size_.set_height(texture_size.height()); 132 size_.set_height(texture_size.height());
101 size_.set_width(texture_size.width()); 133 size_.set_width(texture_size.width());
102 134
103 canvas->save(); 135 canvas->save();
104 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 136 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
105 137
106 // Make a gfx canvas to support utility drawing methods. 138 // Make a gfx canvas to support utility drawing methods.
107 cc::SkiaPaintCanvas paint_canvas(canvas); 139 cc::SkiaPaintCanvas paint_canvas(canvas);
108 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 140 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
109 141
110 // Back button area. 142 // Back button area.
111 SkRRect round_rect; 143 SkRRect round_rect;
112 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 144 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
113 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 145 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
114 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 146 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
147 SkColor color =
148 (GetDrawFlags() & FLAG_BACK_HOVER) ? kBackgroundHover : kBackground;
149 color = (GetDrawFlags() & FLAG_BACK_DOWN) ? kBackgroundDown : color;
115 SkPaint paint; 150 SkPaint paint;
116 paint.setColor((GetDrawFlags() & FLAG_HOVER) ? kBackgroundHover 151 paint.setColor(color);
117 : kBackground);
118 canvas->drawRRect(round_rect, paint); 152 canvas->drawRRect(round_rect, paint);
119 153
120 // URL area. 154 // URL area.
121 paint.setColor(kBackground); 155 paint.setColor(kBackground);
122 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 156 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
123 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 157 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
124 canvas->drawRRect(round_rect, paint); 158 canvas->drawRRect(round_rect, paint);
125 159
126 // Back button / URL separator vertical line. 160 // Back button / URL separator vertical line.
127 paint.setColor(kSeparatorColor); 161 paint.setColor(kSeparatorColor);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 return size_; 218 return size_;
185 } 219 }
186 220
187 bool UrlBarTexture::SetDrawFlags(int draw_flags) { 221 bool UrlBarTexture::SetDrawFlags(int draw_flags) {
188 if (draw_flags != GetDrawFlags()) 222 if (draw_flags != GetDrawFlags())
189 set_dirty(); 223 set_dirty();
190 return UiTexture::SetDrawFlags(draw_flags); 224 return UiTexture::SetDrawFlags(draw_flags);
191 } 225 }
192 226
193 } // namespace vr_shell 227 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/textures/url_bar_texture.h ('k') | chrome/browser/android/vr_shell/ui_elements/url_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698