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

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

Issue 2911943002: [vr] Add incognito coloring (Closed)
Patch Set: Created 3 years, 6 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 "chrome/browser/android/vr_shell/color_scheme.h"
9 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h" 10 #include "chrome/browser/android/vr_shell/textures/render_text_wrapper.h"
10 #include "components/url_formatter/url_formatter.h" 11 #include "components/url_formatter/url_formatter.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_palette.h"
13 #include "ui/gfx/font.h" 13 #include "ui/gfx/font.h"
14 #include "ui/gfx/font_list.h" 14 #include "ui/gfx/font_list.h"
15 #include "ui/gfx/geometry/point_f.h" 15 #include "ui/gfx/geometry/point_f.h"
16 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/rect_f.h" 17 #include "ui/gfx/geometry/rect_f.h"
18 #include "ui/gfx/paint_vector_icon.h" 18 #include "ui/gfx/paint_vector_icon.h"
19 #include "ui/gfx/render_text.h" 19 #include "ui/gfx/render_text.h"
20 #include "ui/gfx/vector_icon_types.h" 20 #include "ui/gfx/vector_icon_types.h"
21 #include "ui/vector_icons/vector_icons.h" 21 #include "ui/vector_icons/vector_icons.h"
22 22
23 namespace vr_shell { 23 namespace vr_shell {
24 24
25 namespace { 25 namespace {
26 26
27 static constexpr SkColor kBackground = 0x66EBEBEB;
28 static constexpr SkColor kBackgroundHover = 0xFFEAEAEA;
29 static constexpr SkColor kBackgroundDown = 0xFFFAFAFA;
30 static constexpr SkColor kForeground = 0xFF333333;
31 static constexpr SkColor kSeparatorColor = 0x33000000;
32
33 static constexpr SkColor kUrlTextColor = 0xFF000000;
34 static constexpr SkColor kUrlDeemphasizedTextColor = 0xFF5A5A5A;
35 static const SkColor kSecureColor = gfx::kGoogleGreen700;
36 static const SkColor kWarningColor = gfx::kGoogleRed700;
37
38 static constexpr float kWidth = 0.672; 27 static constexpr float kWidth = 0.672;
39 static constexpr float kHeight = 0.088; 28 static constexpr float kHeight = 0.088;
40 static constexpr float kFontHeight = 0.027; 29 static constexpr float kFontHeight = 0.027;
41 static constexpr float kBackButtonWidth = kHeight; 30 static constexpr float kBackButtonWidth = kHeight;
42 static constexpr float kBackIconHeight = 0.0375; 31 static constexpr float kBackIconHeight = 0.0375;
43 static constexpr float kBackIconOffset = 0.005; 32 static constexpr float kBackIconOffset = 0.005;
44 static constexpr float kSecurityFieldWidth = 0.06; 33 static constexpr float kSecurityFieldWidth = 0.06;
45 static constexpr float kSecurityIconHeight = 0.03; 34 static constexpr float kSecurityIconHeight = 0.03;
46 static constexpr float kUrlRightMargin = 0.02; 35 static constexpr float kUrlRightMargin = 0.02;
47 static constexpr float kSeparatorWidth = 0.002; 36 static constexpr float kSeparatorWidth = 0.002;
(...skipping 12 matching lines...) Expand all
60 case SecurityLevel::DANGEROUS: 49 case SecurityLevel::DANGEROUS:
61 return ui::kWarningIcon; 50 return ui::kWarningIcon;
62 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 51 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
63 default: 52 default:
64 NOTREACHED(); 53 NOTREACHED();
65 return ui::kWarningIcon; 54 return ui::kWarningIcon;
66 } 55 }
67 } 56 }
68 57
69 // See LocationBarView::GetSecureTextColor(). 58 // See LocationBarView::GetSecureTextColor().
70 SkColor getSchemeColor(SecurityLevel level) { 59 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) {
71 switch (level) { 60 switch (level) {
72 case SecurityLevel::NONE: 61 case SecurityLevel::NONE:
73 case SecurityLevel::HTTP_SHOW_WARNING: 62 case SecurityLevel::HTTP_SHOW_WARNING:
74 case SecurityLevel::SECURITY_WARNING: 63 case SecurityLevel::SECURITY_WARNING:
75 return kUrlDeemphasizedTextColor; 64 return color_scheme.deemphasized;
76 case SecurityLevel::SECURE: 65 case SecurityLevel::SECURE:
77 case SecurityLevel::EV_SECURE: 66 case SecurityLevel::EV_SECURE:
78 return kSecureColor; 67 return color_scheme.secure;
79 case SecurityLevel::DANGEROUS: 68 case SecurityLevel::DANGEROUS:
80 return kWarningColor; 69 return color_scheme.insecure;
81 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
82 default: 71 default:
83 NOTREACHED(); 72 NOTREACHED();
84 return kWarningColor; 73 return color_scheme.warning;
85 } 74 }
86 } 75 }
87 76
88 void setEmphasis(vr_shell::RenderTextWrapper* render_text, 77 void setEmphasis(vr_shell::RenderTextWrapper* render_text,
89 bool emphasis, 78 bool emphasis,
90 const gfx::Range& range) { 79 const gfx::Range& range,
91 SkColor color = emphasis ? kUrlTextColor : kUrlDeemphasizedTextColor; 80 const ColorScheme& color_scheme) {
81 SkColor color =
82 emphasis ? color_scheme.emphasized : color_scheme.deemphasized;
92 if (range.IsValid()) { 83 if (range.IsValid()) {
93 render_text->ApplyColor(color, range); 84 render_text->ApplyColor(color, range);
94 } else { 85 } else {
95 render_text->SetColor(color); 86 render_text->SetColor(color);
96 } 87 }
97 } 88 }
98 89
99 gfx::PointF percentToMeters(const gfx::PointF& percent) { 90 gfx::PointF percentToMeters(const gfx::PointF& percent) {
100 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); 91 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight);
101 } 92 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 set_dirty(); 145 set_dirty();
155 hovered_ = hovered; 146 hovered_ = hovered;
156 } 147 }
157 148
158 void UrlBarTexture::SetPressed(bool pressed) { 149 void UrlBarTexture::SetPressed(bool pressed) {
159 if (pressed_ != pressed) 150 if (pressed_ != pressed)
160 set_dirty(); 151 set_dirty();
161 pressed_ = pressed; 152 pressed_ = pressed;
162 } 153 }
163 154
155 void UrlBarTexture::OnSetMode() {
156 set_dirty();
157 }
158
159 const ColorScheme& UrlBarTexture::color_scheme() const {
160 return ColorScheme::GetColorScheme(mode());
161 }
162
164 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 163 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
165 size_.set_height(texture_size.height()); 164 size_.set_height(texture_size.height());
166 size_.set_width(texture_size.width()); 165 size_.set_width(texture_size.width());
167 166
168 canvas->save(); 167 canvas->save();
169 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 168 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
170 169
171 // Make a gfx canvas to support utility drawing methods. 170 // Make a gfx canvas to support utility drawing methods.
172 cc::SkiaPaintCanvas paint_canvas(canvas); 171 cc::SkiaPaintCanvas paint_canvas(canvas);
173 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 172 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
174 173
175 // Back button area. 174 // Back button area.
176 SkRRect round_rect; 175 SkRRect round_rect;
177 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 176 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
178 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 177 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
179 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 178 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
180 SkColor color = hovered_ ? kBackgroundHover : kBackground; 179 SkColor color =
181 color = pressed_ ? kBackgroundDown : color; 180 hovered_ ? color_scheme().background_hover : color_scheme().background;
181 color = pressed_ ? color_scheme().background_down : color;
182 SkPaint paint; 182 SkPaint paint;
183 paint.setColor(color); 183 paint.setColor(color);
184 canvas->drawRRect(round_rect, paint); 184 canvas->drawRRect(round_rect, paint);
185 185
186 // URL area. 186 // URL area.
187 paint.setColor(kBackground); 187 paint.setColor(color_scheme().background);
188 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 188 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
189 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 189 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
190 canvas->drawRRect(round_rect, paint); 190 canvas->drawRRect(round_rect, paint);
191 191
192 // Back button / URL separator vertical line. 192 // Back button / URL separator vertical line.
193 paint.setColor(kSeparatorColor); 193 paint.setColor(color_scheme().separator);
194 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), 194 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight),
195 paint); 195 paint);
196 196
197 // Back button icon. 197 // Back button icon.
198 canvas->save(); 198 canvas->save();
199 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 199 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
200 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 200 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
201 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 201 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
202 float icon_scale = kBackIconHeight / icon_default_height; 202 float icon_scale = kBackIconHeight / icon_default_height;
203 canvas->scale(icon_scale, icon_scale); 203 canvas->scale(icon_scale, icon_scale);
204 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, kForeground); 204 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, color_scheme().foreground);
205 canvas->restore(); 205 canvas->restore();
206 206
207 // Site security state icon. 207 // Site security state icon.
208 if (!gurl_.is_empty()) { 208 if (!gurl_.is_empty()) {
209 canvas->save(); 209 canvas->save();
210 canvas->translate( 210 canvas->translate(
211 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 211 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
212 kHeight / 2); 212 kHeight / 2);
213 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 213 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
214 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); 214 const gfx::VectorIcon& icon = getSecurityIcon(security_level_);
215 icon_default_height = GetDefaultSizeOfVectorIcon(icon); 215 icon_default_height = GetDefaultSizeOfVectorIcon(icon);
216 icon_scale = kSecurityIconHeight / icon_default_height; 216 icon_scale = kSecurityIconHeight / icon_default_height;
217 SkColor icon_color = getSchemeColor(security_level_); 217 SkColor icon_color = getSchemeColor(security_level_, color_scheme());
218 canvas->scale(icon_scale, icon_scale); 218 canvas->scale(icon_scale, icon_scale);
219 PaintVectorIcon(&gfx_canvas, icon, icon_color); 219 PaintVectorIcon(&gfx_canvas, icon, icon_color);
220 canvas->restore(); 220 canvas->restore();
221 } 221 }
222 222
223 canvas->restore(); 223 canvas->restore();
224 224
225 if (!gurl_.is_empty()) { 225 if (!gurl_.is_empty()) {
226 if (last_drawn_gurl_ != gurl_ || 226 if (last_drawn_gurl_ != gurl_ ||
227 last_drawn_security_level_ != security_level_) { 227 last_drawn_security_level_ != security_level_) {
(...skipping 25 matching lines...) Expand all
253 std::unique_ptr<gfx::RenderText> render_text( 253 std::unique_ptr<gfx::RenderText> render_text(
254 gfx::RenderText::CreateInstance()); 254 gfx::RenderText::CreateInstance());
255 render_text->SetText(text); 255 render_text->SetText(text);
256 render_text->SetFontList(font_list); 256 render_text->SetFontList(font_list);
257 render_text->SetColor(SK_ColorBLACK); 257 render_text->SetColor(SK_ColorBLACK);
258 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT); 258 render_text->SetHorizontalAlignment(gfx::ALIGN_LEFT);
259 render_text->SetDisplayRect(bounds); 259 render_text->SetDisplayRect(bounds);
260 render_text->SetElideBehavior(gfx::TRUNCATE); 260 render_text->SetElideBehavior(gfx::TRUNCATE);
261 261
262 vr_shell::RenderTextWrapper vr_render_text(render_text.get()); 262 vr_shell::RenderTextWrapper vr_render_text(render_text.get());
263 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text); 263 ApplyUrlStyling(text, parsed, security_level_, &vr_render_text,
264 color_scheme());
264 265
265 url_render_text_ = std::move(render_text); 266 url_render_text_ = std::move(render_text);
266 } 267 }
267 268
268 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and 269 // This method replicates behavior in OmniboxView::UpdateTextStyle(), and
269 // attempts to maintain similar code structure. 270 // attempts to maintain similar code structure.
270 void UrlBarTexture::ApplyUrlStyling( 271 void UrlBarTexture::ApplyUrlStyling(
271 const base::string16& formatted_url, 272 const base::string16& formatted_url,
272 const url::Parsed& parsed, 273 const url::Parsed& parsed,
273 const security_state::SecurityLevel security_level, 274 const security_state::SecurityLevel security_level,
274 vr_shell::RenderTextWrapper* render_text) { 275 vr_shell::RenderTextWrapper* render_text,
276 const ColorScheme& color_scheme) {
275 const url::Component& scheme = parsed.scheme; 277 const url::Component& scheme = parsed.scheme;
276 const url::Component& host = parsed.host; 278 const url::Component& host = parsed.host;
277 279
278 enum DeemphasizeComponents { 280 enum DeemphasizeComponents {
279 EVERYTHING, 281 EVERYTHING,
280 ALL_BUT_SCHEME, 282 ALL_BUT_SCHEME,
281 ALL_BUT_HOST, 283 ALL_BUT_HOST,
282 NOTHING, 284 NOTHING,
283 } deemphasize = NOTHING; 285 } deemphasize = NOTHING;
284 286
285 const base::string16 url_scheme = 287 const base::string16 url_scheme =
286 formatted_url.substr(scheme.begin, scheme.len); 288 formatted_url.substr(scheme.begin, scheme.len);
287 289
288 // Data URLs are rarely human-readable and can be used for spoofing, so draw 290 // Data URLs are rarely human-readable and can be used for spoofing, so draw
289 // attention to the scheme to emphasize "this is just a bunch of data". For 291 // attention to the scheme to emphasize "this is just a bunch of data". For
290 // normal URLs, the host is the best proxy for "identity". 292 // normal URLs, the host is the best proxy for "identity".
291 // TODO(cjgrant): Handle extensions, if required, for desktop. 293 // TODO(cjgrant): Handle extensions, if required, for desktop.
292 if (url_scheme == base::UTF8ToUTF16(url::kDataScheme)) 294 if (url_scheme == base::UTF8ToUTF16(url::kDataScheme))
293 deemphasize = ALL_BUT_SCHEME; 295 deemphasize = ALL_BUT_SCHEME;
294 else if (host.is_nonempty()) 296 else if (host.is_nonempty())
295 deemphasize = ALL_BUT_HOST; 297 deemphasize = ALL_BUT_HOST;
296 298
297 gfx::Range scheme_range = scheme.is_nonempty() 299 gfx::Range scheme_range = scheme.is_nonempty()
298 ? gfx::Range(scheme.begin, scheme.end()) 300 ? gfx::Range(scheme.begin, scheme.end())
299 : gfx::Range::InvalidRange(); 301 : gfx::Range::InvalidRange();
300 switch (deemphasize) { 302 switch (deemphasize) {
301 case EVERYTHING: 303 case EVERYTHING:
302 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 304 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
303 break; 305 break;
304 case NOTHING: 306 case NOTHING:
305 setEmphasis(render_text, true, gfx::Range::InvalidRange()); 307 setEmphasis(render_text, true, gfx::Range::InvalidRange(), color_scheme);
306 break; 308 break;
307 case ALL_BUT_SCHEME: 309 case ALL_BUT_SCHEME:
308 DCHECK(scheme_range.IsValid()); 310 DCHECK(scheme_range.IsValid());
309 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 311 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
310 setEmphasis(render_text, true, scheme_range); 312 setEmphasis(render_text, true, scheme_range, color_scheme);
311 break; 313 break;
312 case ALL_BUT_HOST: 314 case ALL_BUT_HOST:
313 setEmphasis(render_text, false, gfx::Range::InvalidRange()); 315 setEmphasis(render_text, false, gfx::Range::InvalidRange(), color_scheme);
314 setEmphasis(render_text, true, gfx::Range(host.begin, host.end())); 316 setEmphasis(render_text, true, gfx::Range(host.begin, host.end()),
317 color_scheme);
315 break; 318 break;
316 } 319 }
317 320
318 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by 321 // Only SECURE and DANGEROUS levels (pages served over HTTPS or flagged by
319 // SafeBrowsing) get a special scheme color treatment. If the security level 322 // SafeBrowsing) get a special scheme color treatment. If the security level
320 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously 323 // is NONE or HTTP_SHOW_WARNING, we do not override the text style previously
321 // applied to the scheme text range by setEmphasis(). 324 // applied to the scheme text range by setEmphasis().
322 if (scheme_range.IsValid() && security_level != security_state::NONE && 325 if (scheme_range.IsValid() && security_level != security_state::NONE &&
323 security_level != security_state::HTTP_SHOW_WARNING) { 326 security_level != security_state::HTTP_SHOW_WARNING) {
324 render_text->ApplyColor(getSchemeColor(security_level), scheme_range); 327 render_text->ApplyColor(getSchemeColor(security_level, color_scheme),
328 scheme_range);
325 if (security_level == SecurityLevel::DANGEROUS) { 329 if (security_level == SecurityLevel::DANGEROUS) {
326 render_text->ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true, 330 render_text->ApplyStyle(gfx::TextStyle::DIAGONAL_STRIKE, true,
327 scheme_range); 331 scheme_range);
328 } 332 }
329 } 333 }
330 } 334 }
331 335
332 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 336 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
333 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 337 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
334 } 338 }
335 339
336 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 340 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
337 return size_; 341 return size_;
338 } 342 }
339 343
340 } // namespace vr_shell 344 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698