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

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

Issue 2885433003: VR: Implement Omnibox input targeting. (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"
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 static constexpr SkColor kBackground = 0xCCD6D6D6;
cjgrant 2017/05/16 14:07:23 Where is this one from?
mthiesse 2017/05/16 18:11:02 I pulled it out of my a- There wasn't any in the
24 static constexpr SkColor kBackgroundHover = 0xCCDDDDDD; 26 static constexpr SkColor kBackgroundHover = 0xCCE1E1E1;
cjgrant 2017/05/16 14:07:23 Should we drop the 0xCC?
mthiesse 2017/05/16 18:11:01 Spec maaaaybe suggests using 0x66. so I'll switch
27 static constexpr SkColor kBackgroundDown = 0xCCECECEC;
25 static constexpr SkColor kForeground = 0xCC444444; 28 static constexpr SkColor kForeground = 0xCC444444;
26 static constexpr SkColor kSeparatorColor = 29 static constexpr SkColor kSeparatorColor =
27 SkColorSetARGBMacro(256 * 0.2, 0, 0, 0); 30 SkColorSetARGBMacro(256 * 0.2, 0, 0, 0);
28 31
cjgrant 2017/05/16 14:07:23 We also have to add "inactive back button" colorin
mthiesse 2017/05/16 18:11:01 l8r
29 static constexpr float kWidth = 0.672; 32 static constexpr float kWidth = 0.672;
30 static constexpr float kHeight = 0.088; 33 static constexpr float kHeight = 0.088;
31 static constexpr float kFontHeight = 0.027; 34 static constexpr float kFontHeight = 0.027;
32 static constexpr float kBackButtonWidth = kHeight; 35 static constexpr float kBackButtonWidth = kHeight;
33 static constexpr float kBackIconHeight = 0.05; 36 static constexpr float kBackIconHeight = 0.05;
34 static constexpr float kBackIconOffset = 0.005; 37 static constexpr float kBackIconOffset = 0.005;
35 static constexpr float kSecurityFieldWidth = 0.06; 38 static constexpr float kSecurityFieldWidth = 0.06;
36 static constexpr float kSecurityIconHeight = 0.03; 39 static constexpr float kSecurityIconHeight = 0.03;
37 static constexpr float kUrlRightMargin = 0.02; 40 static constexpr float kUrlRightMargin = 0.02;
38 static constexpr float kSeparatorWidth = 0.002; 41 static constexpr float kSeparatorWidth = 0.002;
42 static constexpr float kBackHitTargetSize = 0.128;
39 43
40 using security_state::SecurityLevel; 44 using security_state::SecurityLevel;
41 45
42 const struct gfx::VectorIcon& getSecurityIcon(int level) { 46 const struct gfx::VectorIcon& getSecurityIcon(int level) {
43 switch (level) { 47 switch (level) {
44 case SecurityLevel::NONE: 48 case SecurityLevel::NONE:
45 case SecurityLevel::HTTP_SHOW_WARNING: 49 case SecurityLevel::HTTP_SHOW_WARNING:
46 case SecurityLevel::SECURITY_WARNING: 50 case SecurityLevel::SECURITY_WARNING:
47 return ui::kInfoOutlineIcon; 51 return ui::kInfoOutlineIcon;
48 case SecurityLevel::SECURE: 52 case SecurityLevel::SECURE:
(...skipping 21 matching lines...) Expand all
70 void UrlBarTexture::SetSecurityLevel(int level) { 74 void UrlBarTexture::SetSecurityLevel(int level) {
71 if (&getSecurityIcon(security_level_) != &getSecurityIcon(level)) 75 if (&getSecurityIcon(security_level_) != &getSecurityIcon(level))
72 set_dirty(); 76 set_dirty();
73 security_level_ = level; 77 security_level_ = level;
74 } 78 }
75 79
76 float UrlBarTexture::ToPixels(float meters) const { 80 float UrlBarTexture::ToPixels(float meters) const {
77 return meters * size_.width() / kWidth; 81 return meters * size_.width() / kWidth;
78 } 82 }
79 83
84 bool UrlBarTexture::HitsBackButton(const gfx::PointF& position) const {
85 float margin = (kBackHitTargetSize - kBackButtonWidth) / 2;
86 gfx::RectF rect(-margin, -margin, kBackHitTargetSize, kBackHitTargetSize);
87 rect.Scale(1.0f / (kWidth - kBackButtonWidth), 1.0f / kBackButtonWidth);
88 return rect.Contains(position);
89 }
90
91 bool UrlBarTexture::HitsURLBar(const gfx::PointF& position) const {
92 gfx::RectF rect(0, 0, 1, 1);
93 return rect.Contains(position) && !HitsRightTransparentRegion(position);
94 }
95
96 bool UrlBarTexture::HitsRightTransparentRegion(
97 const gfx::PointF& position) const {
98 float rounded_radius = kHeight / kWidth / 2;
cjgrant 2017/05/16 14:07:23 This is fine if it works, but alternatively, would
mthiesse 2017/05/16 18:11:01 Yeah, looks clearer when you convert everything to
cjgrant 2017/05/16 18:22:21 Acknowledged.
99 if (position.x() < 1.0f - rounded_radius)
100 return false;
101 float x = (position.x() - (1.0f - rounded_radius)) / rounded_radius / 2 + 0.5;
102 gfx::Vector2dF diff = gfx::PointF(x, position.y()) - gfx::PointF(0.5, 0.5);
103 return diff.LengthSquared() > 0.25;
104 }
105
80 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) { 106 void UrlBarTexture::Draw(SkCanvas* canvas, const gfx::Size& texture_size) {
81 size_.set_height(texture_size.height()); 107 size_.set_height(texture_size.height());
82 size_.set_width(texture_size.width()); 108 size_.set_width(texture_size.width());
83 109
84 canvas->save(); 110 canvas->save();
85 canvas->scale(size_.width() / kWidth, size_.width() / kWidth); 111 canvas->scale(size_.width() / kWidth, size_.width() / kWidth);
86 112
87 // Make a gfx canvas to support utility drawing methods. 113 // Make a gfx canvas to support utility drawing methods.
88 cc::SkiaPaintCanvas paint_canvas(canvas); 114 cc::SkiaPaintCanvas paint_canvas(canvas);
89 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 115 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
90 116
91 // Back button area. 117 // Back button area.
92 SkRRect round_rect; 118 SkRRect round_rect;
93 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 119 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
94 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 120 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
95 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 121 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
122 SkColor color =
123 (GetDrawFlags() & FLAG_BACK_HOVER) ? kBackgroundHover : kBackground;
124 color = (GetDrawFlags() & FLAG_BACK_DOWN) ? kBackgroundDown : color;
96 SkPaint paint; 125 SkPaint paint;
97 paint.setColor((GetDrawFlags() & FLAG_HOVER) ? kBackgroundHover 126 paint.setColor(color);
98 : kBackground);
99 canvas->drawRRect(round_rect, paint); 127 canvas->drawRRect(round_rect, paint);
100 128
101 // URL area. 129 // URL area.
102 paint.setColor(kBackground); 130 paint.setColor(kBackground);
103 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 131 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
104 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 132 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
105 canvas->drawRRect(round_rect, paint); 133 canvas->drawRRect(round_rect, paint);
106 134
107 // Back button / URL separator vertical line. 135 // Back button / URL separator vertical line.
108 paint.setColor(kSeparatorColor); 136 paint.setColor(kSeparatorColor);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 return size_; 192 return size_;
165 } 193 }
166 194
167 bool UrlBarTexture::SetDrawFlags(int draw_flags) { 195 bool UrlBarTexture::SetDrawFlags(int draw_flags) {
168 if (draw_flags != GetDrawFlags()) 196 if (draw_flags != GetDrawFlags())
169 set_dirty(); 197 set_dirty();
170 return UiTexture::SetDrawFlags(draw_flags); 198 return UiTexture::SetDrawFlags(draw_flags);
171 } 199 }
172 200
173 } // namespace vr_shell 201 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698