| 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 NOTREACHED(); | 58 NOTREACHED(); |
| 59 return toolbar::kHttpsInvalidIcon; | 59 return toolbar::kHttpsInvalidIcon; |
| 60 } | 60 } |
| 61 } | 61 } |
| 62 | 62 |
| 63 // See LocationBarView::GetSecureTextColor(). | 63 // See LocationBarView::GetSecureTextColor(). |
| 64 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { | 64 SkColor getSchemeColor(SecurityLevel level, const ColorScheme& color_scheme) { |
| 65 switch (level) { | 65 switch (level) { |
| 66 case SecurityLevel::NONE: | 66 case SecurityLevel::NONE: |
| 67 case SecurityLevel::HTTP_SHOW_WARNING: | 67 case SecurityLevel::HTTP_SHOW_WARNING: |
| 68 return color_scheme.deemphasized; | 68 return color_scheme.url_deemphasized; |
| 69 case SecurityLevel::EV_SECURE: | 69 case SecurityLevel::EV_SECURE: |
| 70 case SecurityLevel::SECURE: | 70 case SecurityLevel::SECURE: |
| 71 return color_scheme.secure; | 71 return color_scheme.secure; |
| 72 case SecurityLevel::SECURITY_WARNING: | 72 case SecurityLevel::SECURITY_WARNING: |
| 73 return color_scheme.deemphasized; | 73 return color_scheme.url_deemphasized; |
| 74 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. | 74 case SecurityLevel::SECURE_WITH_POLICY_INSTALLED_CERT: // ChromeOS only. |
| 75 return color_scheme.insecure; | 75 return color_scheme.insecure; |
| 76 case SecurityLevel::DANGEROUS: | 76 case SecurityLevel::DANGEROUS: |
| 77 return color_scheme.insecure; | 77 return color_scheme.insecure; |
| 78 default: | 78 default: |
| 79 NOTREACHED(); | 79 NOTREACHED(); |
| 80 return color_scheme.insecure; | 80 return color_scheme.insecure; |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 | 83 |
| 84 void setEmphasis(vr_shell::RenderTextWrapper* render_text, | 84 void setEmphasis(vr_shell::RenderTextWrapper* render_text, |
| 85 bool emphasis, | 85 bool emphasis, |
| 86 const gfx::Range& range, | 86 const gfx::Range& range, |
| 87 const ColorScheme& color_scheme) { | 87 const ColorScheme& color_scheme) { |
| 88 SkColor color = | 88 SkColor color = |
| 89 emphasis ? color_scheme.emphasized : color_scheme.deemphasized; | 89 emphasis ? color_scheme.url_emphasized : color_scheme.url_deemphasized; |
| 90 if (range.IsValid()) { | 90 if (range.IsValid()) { |
| 91 render_text->ApplyColor(color, range); | 91 render_text->ApplyColor(color, range); |
| 92 } else { | 92 } else { |
| 93 render_text->SetColor(color); | 93 render_text->SetColor(color); |
| 94 } | 94 } |
| 95 } | 95 } |
| 96 | 96 |
| 97 gfx::PointF percentToMeters(const gfx::PointF& percent) { | 97 gfx::PointF percentToMeters(const gfx::PointF& percent) { |
| 98 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); | 98 return gfx::PointF(percent.x() * kWidth, percent.y() * kHeight); |
| 99 } | 99 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 void UrlBarTexture::SetPressed(bool pressed) { | 162 void UrlBarTexture::SetPressed(bool pressed) { |
| 163 if (pressed_ != pressed) | 163 if (pressed_ != pressed) |
| 164 set_dirty(); | 164 set_dirty(); |
| 165 pressed_ = pressed; | 165 pressed_ = pressed; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void UrlBarTexture::OnSetMode() { | 168 void UrlBarTexture::OnSetMode() { |
| 169 set_dirty(); | 169 set_dirty(); |
| 170 } | 170 } |
| 171 | 171 |
| 172 const ColorScheme& UrlBarTexture::color_scheme() const { | |
| 173 return ColorScheme::GetColorScheme(mode()); | |
| 174 } | |
| 175 | |
| 176 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { | 172 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { |
| 177 size_.set_height(texture_size.height()); | 173 size_.set_height(texture_size.height()); |
| 178 size_.set_width(texture_size.width()); | 174 size_.set_width(texture_size.width()); |
| 179 | 175 |
| 180 canvas->save(); | 176 canvas->save(); |
| 181 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); | 177 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); |
| 182 | 178 |
| 183 // Make a gfx canvas to support utility drawing methods. | 179 // Make a gfx canvas to support utility drawing methods. |
| 184 cc::SkiaPaintCanvas paint_canvas(canvas); | 180 cc::SkiaPaintCanvas paint_canvas(canvas); |
| 185 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 181 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
| 186 | 182 |
| 187 // Back button area. | 183 // Back button area. |
| 188 SkRRect round_rect; | 184 SkRRect round_rect; |
| 189 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; | 185 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; |
| 190 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; | 186 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; |
| 191 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); | 187 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); |
| 192 SkColor color = color_scheme().background; | 188 SkColor color = color_scheme().element_background; |
| 193 if (can_go_back_) { | 189 if (can_go_back_) { |
| 194 if (pressed_) | 190 if (pressed_) |
| 195 color = color_scheme().background_down; | 191 color = color_scheme().element_background_down; |
| 196 else if (hovered_) | 192 else if (hovered_) |
| 197 color = color_scheme().background_hover; | 193 color = color_scheme().element_background_hover; |
| 198 } | 194 } |
| 199 SkPaint paint; | 195 SkPaint paint; |
| 200 paint.setColor(color); | 196 paint.setColor(color); |
| 201 canvas->drawRRect(round_rect, paint); | 197 canvas->drawRRect(round_rect, paint); |
| 202 | 198 |
| 203 // URL area. | 199 // URL area. |
| 204 paint.setColor(color_scheme().background); | 200 paint.setColor(color_scheme().element_background); |
| 205 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; | 201 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; |
| 206 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); | 202 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); |
| 207 canvas->drawRRect(round_rect, paint); | 203 canvas->drawRRect(round_rect, paint); |
| 208 | 204 |
| 209 // Back button / URL separator vertical line. | 205 // Back button / URL separator vertical line. |
| 210 paint.setColor(color_scheme().separator); | 206 paint.setColor(color_scheme().separator); |
| 211 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), | 207 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), |
| 212 paint); | 208 paint); |
| 213 | 209 |
| 214 // Back button icon. | 210 // Back button icon. |
| 215 canvas->save(); | 211 canvas->save(); |
| 216 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); | 212 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); |
| 217 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); | 213 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); |
| 218 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); | 214 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); |
| 219 float icon_scale = kBackIconHeight / icon_default_height; | 215 float icon_scale = kBackIconHeight / icon_default_height; |
| 220 canvas->scale(icon_scale, icon_scale); | 216 canvas->scale(icon_scale, icon_scale); |
| 221 PaintVectorIcon( | 217 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, |
| 222 &gfx_canvas, ui::kBackArrowIcon, | 218 can_go_back_ ? color_scheme().element_foreground |
| 223 can_go_back_ ? color_scheme().foreground : color_scheme().disabled); | 219 : color_scheme().disabled); |
| 224 canvas->restore(); | 220 canvas->restore(); |
| 225 | 221 |
| 226 // Site security state icon. | 222 // Site security state icon. |
| 227 if (!gurl_.is_empty()) { | 223 if (!gurl_.is_empty()) { |
| 228 canvas->save(); | 224 canvas->save(); |
| 229 canvas->translate( | 225 canvas->translate( |
| 230 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, | 226 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, |
| 231 kHeight / 2); | 227 kHeight / 2); |
| 232 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); | 228 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); |
| 233 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); | 229 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 363 |
| 368 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { | 364 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { |
| 369 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); | 365 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); |
| 370 } | 366 } |
| 371 | 367 |
| 372 gfx::SizeF UrlBarTexture::GetDrawnSize() const { | 368 gfx::SizeF UrlBarTexture::GetDrawnSize() const { |
| 373 return size_; | 369 return size_; |
| 374 } | 370 } |
| 375 | 371 |
| 376 } // namespace vr_shell | 372 } // namespace vr_shell |
| OLD | NEW |