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

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

Issue 2914623003: [VrShell] Centralize color handling and enable close button on fullscreen (Closed)
Patch Set: clean up after rebase 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/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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 return ui::kWarningIcon; 54 return ui::kWarningIcon;
55 } 55 }
56 } 56 }
57 57
58 // See LocationBarView::GetSecureTextColor(). 58 // See LocationBarView::GetSecureTextColor().
59 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { 59 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) {
60 switch (level) { 60 switch (level) {
61 case SecurityLevel::NONE: 61 case SecurityLevel::NONE:
62 case SecurityLevel::HTTP_SHOW_WARNING: 62 case SecurityLevel::HTTP_SHOW_WARNING:
63 case SecurityLevel::SECURITY_WARNING: 63 case SecurityLevel::SECURITY_WARNING:
64 return color_scheme.deemphasized; 64 return color_scheme.text_deemphasized;
65 case SecurityLevel::SECURE: 65 case SecurityLevel::SECURE:
66 case SecurityLevel::EV_SECURE: 66 case SecurityLevel::EV_SECURE:
67 return color_scheme.secure; 67 return color_scheme.secure;
68 case SecurityLevel::DANGEROUS: 68 case SecurityLevel::DANGEROUS:
69 return color_scheme.insecure; 69 return color_scheme.insecure;
70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. 70 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only.
71 default: 71 default:
72 NOTREACHED(); 72 NOTREACHED();
73 return color_scheme.warning; 73 return color_scheme.warning;
74 } 74 }
75 } 75 }
76 76
77 void setEmphasis(vr_shell::RenderTextWrapper* render_text, 77 void setEmphasis(vr_shell::RenderTextWrapper* render_text,
78 bool emphasis, 78 bool emphasis,
79 const gfx::Range& range, 79 const gfx::Range& range,
80 const ColorScheme& color_scheme) { 80 const ColorScheme& color_scheme) {
81 SkColor color = 81 SkColor color =
82 emphasis ? color_scheme.emphasized : color_scheme.deemphasized; 82 emphasis ? color_scheme.text_emphasized : color_scheme.text_deemphasized;
cjgrant 2017/06/05 17:57:08 Could these be url_emphasized, etc, to call out th
amp 2017/06/05 21:40:58 Done. sgtm since they aren't used anywhere else.
83 if (range.IsValid()) { 83 if (range.IsValid()) {
84 render_text->ApplyColor(color, range); 84 render_text->ApplyColor(color, range);
85 } else { 85 } else {
86 render_text->SetColor(color); 86 render_text->SetColor(color);
87 } 87 }
88 } 88 }
89 89
90 gfx::PointF percentToMeters(const gfx::PointF& percent) { 90 gfx::PointF percentToMeters(const gfx::PointF& percent) {
91 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); 91 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight);
92 } 92 }
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void UrlBarTexture::SetPressed(bool pressed) { 155 void UrlBarTexture::SetPressed(bool pressed) {
156 if (pressed_ != pressed) 156 if (pressed_ != pressed)
157 set_dirty(); 157 set_dirty();
158 pressed_ = pressed; 158 pressed_ = pressed;
159 } 159 }
160 160
161 void UrlBarTexture::OnSetMode() { 161 void UrlBarTexture::OnSetMode() {
162 set_dirty(); 162 set_dirty();
163 } 163 }
164 164
165 const ColorScheme& UrlBarTexture::color_scheme() const {
166 return ColorScheme::GetColorScheme(mode());
167 }
168
169 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 165 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
170 size_.set_height(texture_size.height()); 166 size_.set_height(texture_size.height());
171 size_.set_width(texture_size.width()); 167 size_.set_width(texture_size.width());
172 168
173 canvas->save(); 169 canvas->save();
174 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 170 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
175 171
176 // Make a gfx canvas to support utility drawing methods. 172 // Make a gfx canvas to support utility drawing methods.
177 cc::SkiaPaintCanvas paint_canvas(canvas); 173 cc::SkiaPaintCanvas paint_canvas(canvas);
178 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 174 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
179 175
180 // Back button area. 176 // Back button area.
181 SkRRect round_rect; 177 SkRRect round_rect;
182 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 178 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
183 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 179 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
184 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 180 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
185 SkColor color = color_scheme().background; 181 SkColor color = color_scheme().element_background;
186 if (can_go_back_) { 182 if (can_go_back_) {
187 if (pressed_) 183 if (pressed_)
188 color = color_scheme().background_down; 184 color = color_scheme().element_background_down;
189 else if (hovered_) 185 else if (hovered_)
190 color = color_scheme().background_hover; 186 color = color_scheme().element_background_hover;
191 } 187 }
192 SkPaint paint; 188 SkPaint paint;
193 paint.setColor(color); 189 paint.setColor(color);
194 canvas->drawRRect(round_rect, paint); 190 canvas->drawRRect(round_rect, paint);
195 191
196 // URL area. 192 // URL area.
197 paint.setColor(color_scheme().background); 193 paint.setColor(color_scheme().element_background);
198 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 194 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
199 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 195 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
200 canvas->drawRRect(round_rect, paint); 196 canvas->drawRRect(round_rect, paint);
201 197
202 // Back button / URL separator vertical line. 198 // Back button / URL separator vertical line.
203 paint.setColor(color_scheme().separator); 199 paint.setColor(color_scheme().separator);
204 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), 200 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight),
205 paint); 201 paint);
206 202
207 // Back button icon. 203 // Back button icon.
208 canvas->save(); 204 canvas->save();
209 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 205 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
210 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 206 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
211 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 207 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
212 float icon_scale = kBackIconHeight / icon_default_height; 208 float icon_scale = kBackIconHeight / icon_default_height;
213 canvas->scale(icon_scale, icon_scale); 209 canvas->scale(icon_scale, icon_scale);
214 PaintVectorIcon( 210 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon,
215 &gfx_canvas, ui::kBackArrowIcon, 211 can_go_back_ ? color_scheme().element_foreground
216 can_go_back_ ? color_scheme().foreground : color_scheme().disabled); 212 : color_scheme().disabled);
217 canvas->restore(); 213 canvas->restore();
218 214
219 // Site security state icon. 215 // Site security state icon.
220 if (!gurl_.is_empty()) { 216 if (!gurl_.is_empty()) {
221 canvas->save(); 217 canvas->save();
222 canvas->translate( 218 canvas->translate(
223 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 219 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
224 kHeight / 2); 220 kHeight / 2);
225 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 221 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
226 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); 222 const gfx::VectorIcon& icon = getSecurityIcon(security_level_);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 356
361 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 357 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
362 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 358 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
363 } 359 }
364 360
365 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 361 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
366 return size_; 362 return size_;
367 } 363 }
368 364
369 } // namespace vr_shell 365 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698