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

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

Issue 2878543002: Refactor VR Shell Input. Locks input to click/scroll targets. (Closed)
Patch Set: 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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return ui::kWarningIcon; 56 return ui::kWarningIcon;
57 } 57 }
58 } 58 }
59 59
60 } // namespace 60 } // namespace
61 61
62 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {} 62 UrlBarTexture::UrlBarTexture() : security_level_(SecurityLevel::DANGEROUS) {}
63 63
64 UrlBarTexture::~UrlBarTexture() = default; 64 UrlBarTexture::~UrlBarTexture() = default;
65 65
66 void UrlBarTexture::SetHover(bool hover) {
67 hover_ = hover;
68 }
69
70 void UrlBarTexture::SetURL(const GURL& gurl) { 66 void UrlBarTexture::SetURL(const GURL& gurl) {
71 gurl_ = gurl; 67 gurl_ = gurl;
72 } 68 }
73 69
74 void UrlBarTexture::SetSecurityLevel(int level) { 70 void UrlBarTexture::SetSecurityLevel(int level) {
75 security_level_ = level; 71 security_level_ = level;
76 } 72 }
77 73
78 float UrlBarTexture::ToPixels(float meters) const { 74 float UrlBarTexture::ToPixels(float meters) const {
79 return meters * size_.width() / kWidth; 75 return meters * size_.width() / kWidth;
(...skipping 11 matching lines...) Expand all
91 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 87 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
92 88
93 canvas->drawColor(kTextureBackground); 89 canvas->drawColor(kTextureBackground);
94 90
95 // Back button area. 91 // Back button area.
96 SkRRect round_rect; 92 SkRRect round_rect;
97 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 93 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
98 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 94 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
99 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 95 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
100 SkPaint paint; 96 SkPaint paint;
101 paint.setColor(hover_ ? kBackgroundHover : kBackground); 97 paint.setColor((draw_flags_ & FLAG_HOVER) ? kBackgroundHover : kBackground);
102 canvas->drawRRect(round_rect, paint); 98 canvas->drawRRect(round_rect, paint);
103 99
104 // URL area. 100 // URL area.
105 paint.setColor(kBackground); 101 paint.setColor(kBackground);
106 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 102 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
107 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 103 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
108 canvas->drawRRect(round_rect, paint); 104 canvas->drawRRect(round_rect, paint);
109 105
110 // Back button / URL separator vertical line. 106 // Back button / URL separator vertical line.
111 paint.setColor(kSeparatorColor); 107 paint.setColor(kSeparatorColor);
(...skipping 19 matching lines...) Expand all
131 kHeight / 2); 127 kHeight / 2);
132 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 128 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
133 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_); 129 const gfx::VectorIcon& security_icon = getSecurityIcon(security_level_);
134 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon); 130 icon_default_height = GetDefaultSizeOfVectorIcon(security_icon);
135 icon_scale = kSecurityIconHeight / icon_default_height; 131 icon_scale = kSecurityIconHeight / icon_default_height;
136 canvas->scale(icon_scale, icon_scale); 132 canvas->scale(icon_scale, icon_scale);
137 PaintVectorIcon(&gfx_canvas, security_icon, kForeground); 133 PaintVectorIcon(&gfx_canvas, security_icon, kForeground);
138 canvas->restore(); 134 canvas->restore();
139 } 135 }
140 136
141 canvas->restore();
cjgrant 2017/05/10 20:16:25 Why are you removing this? It removes the scale o
mthiesse 2017/05/10 21:09:08 Rebasing error, good catch.
142
143 // Draw text based on pixel sizes rather than meters, for correct font sizing. 137 // Draw text based on pixel sizes rather than meters, for correct font sizing.
144 int pixel_font_height = texture_size.height() * kFontHeight / kHeight; 138 int pixel_font_height = texture_size.height() * kFontHeight / kHeight;
145 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT; 139 int text_flags = gfx::Canvas::TEXT_ALIGN_LEFT;
146 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth; 140 float url_x = kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth;
147 float url_width = kWidth - url_x - kUrlRightMargin; 141 float url_width = kWidth - url_x - kUrlRightMargin;
148 gfx_canvas.DrawStringRectWithFlags( 142 gfx_canvas.DrawStringRectWithFlags(
149 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height), 143 base::UTF8ToUTF16(gurl_.spec()), GetDefaultFontList(pixel_font_height),
150 SK_ColorBLACK, 144 SK_ColorBLACK,
151 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)), 145 gfx::Rect(ToPixels(url_x), 0, ToPixels(url_width), ToPixels(kHeight)),
152 text_flags); 146 text_flags);
153 } 147 }
154 148
155 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 149 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
156 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 150 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
157 } 151 }
158 152
159 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 153 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
160 return size_; 154 return size_;
161 } 155 }
162 156
163 } // namespace vr_shell 157 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698