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

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

Issue 2906403002: Disable back button when stack is empty (Closed)
Patch Set: nit 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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 failure_callback_(failure_callback) {} 99 failure_callback_(failure_callback) {}
100 100
101 UrlBarTexture::~UrlBarTexture() = default; 101 UrlBarTexture::~UrlBarTexture() = default;
102 102
103 void UrlBarTexture::SetURL(const GURL& gurl) { 103 void UrlBarTexture::SetURL(const GURL& gurl) {
104 if (gurl_ != gurl) 104 if (gurl_ != gurl)
105 set_dirty(); 105 set_dirty();
106 gurl_ = gurl; 106 gurl_ = gurl;
107 } 107 }
108 108
109 void UrlBarTexture::SetHistoryButtonsEnabled(bool can_go_back) {
110 if (can_go_back != can_go_back_)
111 set_dirty();
112 can_go_back_ = can_go_back;
113 }
114
109 void UrlBarTexture::SetSecurityLevel(SecurityLevel level) { 115 void UrlBarTexture::SetSecurityLevel(SecurityLevel level) {
110 if (security_level_ != level) 116 if (security_level_ != level)
111 set_dirty(); 117 set_dirty();
112 security_level_ = level; 118 security_level_ = level;
113 } 119 }
114 120
115 float UrlBarTexture::ToPixels(float meters) const { 121 float UrlBarTexture::ToPixels(float meters) const {
116 return meters * size_.width() / kWidth; 122 return meters * size_.width() / kWidth;
117 } 123 }
118 124
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 175
170 // Make a gfx canvas to support utility drawing methods. 176 // Make a gfx canvas to support utility drawing methods.
171 cc::SkiaPaintCanvas paint_canvas(canvas); 177 cc::SkiaPaintCanvas paint_canvas(canvas);
172 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); 178 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f);
173 179
174 // Back button area. 180 // Back button area.
175 SkRRect round_rect; 181 SkRRect round_rect;
176 SkVector rounded_corner = {kHeight / 2, kHeight / 2}; 182 SkVector rounded_corner = {kHeight / 2, kHeight / 2};
177 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner}; 183 SkVector left_corners[4] = {rounded_corner, {0, 0}, {0, 0}, rounded_corner};
178 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners); 184 round_rect.setRectRadii({0, 0, kHeight, kHeight}, left_corners);
179 SkColor color = 185 SkColor color = color_scheme().background;
180 hovered_ ? color_scheme().background_hover : color_scheme().background; 186 if (can_go_back_) {
181 color = pressed_ ? color_scheme().background_down : color; 187 if (pressed_)
188 color = color_scheme().background_down;
189 else if (hovered_)
190 color = color_scheme().background_hover;
191 }
182 SkPaint paint; 192 SkPaint paint;
183 paint.setColor(color); 193 paint.setColor(color);
184 canvas->drawRRect(round_rect, paint); 194 canvas->drawRRect(round_rect, paint);
185 195
186 // URL area. 196 // URL area.
187 paint.setColor(color_scheme().background); 197 paint.setColor(color_scheme().background);
188 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}}; 198 SkVector right_corners[4] = {{0, 0}, rounded_corner, rounded_corner, {0, 0}};
189 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners); 199 round_rect.setRectRadii({kHeight, 0, kWidth, kHeight}, right_corners);
190 canvas->drawRRect(round_rect, paint); 200 canvas->drawRRect(round_rect, paint);
191 201
192 // Back button / URL separator vertical line. 202 // Back button / URL separator vertical line.
193 paint.setColor(color_scheme().separator); 203 paint.setColor(color_scheme().separator);
194 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight), 204 canvas->drawRect(SkRect::MakeXYWH(kHeight, 0, kSeparatorWidth, kHeight),
195 paint); 205 paint);
196 206
197 // Back button icon. 207 // Back button icon.
198 canvas->save(); 208 canvas->save();
199 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2); 209 canvas->translate(kHeight / 2 + kBackIconOffset, kHeight / 2);
200 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2); 210 canvas->translate(-kBackIconHeight / 2, -kBackIconHeight / 2);
201 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon); 211 int icon_default_height = GetDefaultSizeOfVectorIcon(ui::kBackArrowIcon);
202 float icon_scale = kBackIconHeight / icon_default_height; 212 float icon_scale = kBackIconHeight / icon_default_height;
203 canvas->scale(icon_scale, icon_scale); 213 canvas->scale(icon_scale, icon_scale);
204 PaintVectorIcon(&gfx_canvas, ui::kBackArrowIcon, color_scheme().foreground); 214 PaintVectorIcon(
215 &gfx_canvas, ui::kBackArrowIcon,
216 can_go_back_ ? color_scheme().foreground : color_scheme().disabled);
205 canvas->restore(); 217 canvas->restore();
206 218
207 // Site security state icon. 219 // Site security state icon.
208 if (!gurl_.is_empty()) { 220 if (!gurl_.is_empty()) {
209 canvas->save(); 221 canvas->save();
210 canvas->translate( 222 canvas->translate(
211 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2, 223 kBackButtonWidth + kSeparatorWidth + kSecurityFieldWidth / 2,
212 kHeight / 2); 224 kHeight / 2);
213 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2); 225 canvas->translate(-kSecurityIconHeight / 2, -kSecurityIconHeight / 2);
214 const gfx::VectorIcon& icon = getSecurityIcon(security_level_); 226 const gfx::VectorIcon& icon = getSecurityIcon(security_level_);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 347
336 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const { 348 gfx::Size UrlBarTexture::GetPreferredTextureSize(int maximum_width) const {
337 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth); 349 return gfx::Size(maximum_width, maximum_width * kHeight / kWidth);
338 } 350 }
339 351
340 gfx::SizeF UrlBarTexture::GetDrawnSize() const { 352 gfx::SizeF UrlBarTexture::GetDrawnSize() const {
341 return size_; 353 return size_;
342 } 354 }
343 355
344 } // namespace vr_shell 356 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/textures/url_bar_texture.h ('k') | chrome/browser/android/vr_shell/ui_elements/url_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698