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

Side by Side Diff: chrome/browser/android/vr_shell/ui_scene_manager.cc

Issue 2913633002: [vr] Clicking on the security icon should prompt the user to bail out of VR (Closed)
Patch Set: address amp's comments 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/ui_scene_manager.h" 5 #include "chrome/browser/android/vr_shell/ui_scene_manager.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" 9 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h"
10 #include "chrome/browser/android/vr_shell/textures/ui_texture.h" 10 #include "chrome/browser/android/vr_shell/textures/ui_texture.h"
11 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" 11 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h"
12 #include "chrome/browser/android/vr_shell/ui_elements/button.h" 12 #include "chrome/browser/android/vr_shell/ui_elements/button.h"
13 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h"
13 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" 14 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h"
14 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" 15 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h"
15 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h" 16 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h"
16 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h " 17 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h "
17 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h"
18 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h" 19 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h"
19 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h"
21 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" 22 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h"
22 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" 23 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h"
(...skipping 16 matching lines...) Expand all
39 static constexpr float kExitWarningHeight = 0.160; 40 static constexpr float kExitWarningHeight = 0.160;
40 static constexpr float kExitWarningWidth = 0.512; 41 static constexpr float kExitWarningWidth = 0.512;
41 42
42 static constexpr float kContentDistance = 2.5; 43 static constexpr float kContentDistance = 2.5;
43 static constexpr float kContentWidth = 0.96 * kContentDistance; 44 static constexpr float kContentWidth = 0.96 * kContentDistance;
44 static constexpr float kContentHeight = 0.64 * kContentDistance; 45 static constexpr float kContentHeight = 0.64 * kContentDistance;
45 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance; 46 static constexpr float kContentVerticalOffset = -0.1 * kContentDistance;
46 static constexpr float kBackplaneSize = 1000.0; 47 static constexpr float kBackplaneSize = 1000.0;
47 static constexpr float kBackgroundDistanceMultiplier = 1.414; 48 static constexpr float kBackgroundDistanceMultiplier = 1.414;
48 49
50 static constexpr float kExitPromptWidth = 0.672 * kContentDistance;
51 static constexpr float kExitPromptHeight = 0.2 * kContentDistance;
52
49 static constexpr float kUrlBarDistance = 2.4; 53 static constexpr float kUrlBarDistance = 2.4;
50 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; 54 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance;
51 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; 55 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance;
52 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; 56 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance;
53 57
54 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance; 58 static constexpr float kLoadingIndicatorWidth = 0.24 * kUrlBarDistance;
55 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance; 59 static constexpr float kLoadingIndicatorHeight = 0.008 * kUrlBarDistance;
56 static constexpr float kLoadingIndicatorOffset = 60 static constexpr float kLoadingIndicatorOffset =
57 -0.016 * kUrlBarDistance - kLoadingIndicatorHeight / 2; 61 -0.016 * kUrlBarDistance - kLoadingIndicatorHeight / 2;
58 62
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 208
205 // Place an invisible but hittable plane behind the content quad, to keep the 209 // Place an invisible but hittable plane behind the content quad, to keep the
206 // reticle roughly planar with the content if near content. 210 // reticle roughly planar with the content if near content.
207 element = base::MakeUnique<UiElement>(); 211 element = base::MakeUnique<UiElement>();
208 element->set_debug_id(kBackplane); 212 element->set_debug_id(kBackplane);
209 element->set_id(AllocateId()); 213 element->set_id(AllocateId());
210 element->set_fill(vr_shell::Fill::NONE); 214 element->set_fill(vr_shell::Fill::NONE);
211 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); 215 element->set_size({kBackplaneSize, kBackplaneSize, 1.0});
212 element->set_translation({0.0, 0.0, -kTextureOffset}); 216 element->set_translation({0.0, 0.0, -kTextureOffset});
213 element->set_parent_id(main_content_->id()); 217 element->set_parent_id(main_content_->id());
218 main_content_backplane_ = element.get();
214 content_elements_.push_back(element.get()); 219 content_elements_.push_back(element.get());
215 scene_->AddUiElement(std::move(element)); 220 scene_->AddUiElement(std::move(element));
216 221
222 element = base::MakeUnique<ExitPrompt>(
223 512,
224 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked,
225 base::Unretained(this)),
226 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked,
227 base::Unretained(this)));
228 element->set_debug_id(kExitPrompt);
229 element->set_id(AllocateId());
230 element->set_fill(vr_shell::Fill::NONE);
231 element->set_size({kExitPromptWidth, kExitPromptHeight, 1});
232 element->set_translation({0.0, 0.0, kTextureOffset});
233 element->set_parent_id(main_content_->id());
234 element->set_visible(false);
235 exit_prompt_ = element.get();
236 scene_->AddUiElement(std::move(element));
237
217 // Limit reticle distance to a sphere based on content distance. 238 // Limit reticle distance to a sphere based on content distance.
218 scene_->SetBackgroundDistance(main_content_->translation().z() * 239 scene_->SetBackgroundDistance(main_content_->translation().z() *
219 -kBackgroundDistanceMultiplier); 240 -kBackgroundDistanceMultiplier);
220 } 241 }
221 242
222 void UiSceneManager::CreateBackground() { 243 void UiSceneManager::CreateBackground() {
223 std::unique_ptr<UiElement> element; 244 std::unique_ptr<UiElement> element;
224 245
225 // Floor. 246 // Floor.
226 element = base::MakeUnique<UiElement>(); 247 element = base::MakeUnique<UiElement>();
227 element->set_debug_id(kFloor); 248 element->set_debug_id(kFloor);
228 element->set_id(AllocateId()); 249 element->set_id(AllocateId());
229 element->set_size({kSceneSize, kSceneSize, 1.0}); 250 element->set_size({kSceneSize, kSceneSize, 1.0});
230 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); 251 element->set_translation({0.0, -kSceneHeight / 2, 0.0});
231 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); 252 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0});
232 element->set_fill(vr_shell::Fill::GRID_GRADIENT); 253 element->set_fill(vr_shell::Fill::GRID_GRADIENT);
233 element->set_draw_phase(0); 254 element->set_draw_phase(0);
234 element->set_gridline_count(kFloorGridlineCount); 255 element->set_gridline_count(kFloorGridlineCount);
235 floor_ = element.get(); 256 floor_ = element.get();
236 content_elements_.push_back(element.get()); 257 background_elements_.push_back(element.get());
237 scene_->AddUiElement(std::move(element)); 258 scene_->AddUiElement(std::move(element));
238 259
239 // Ceiling. 260 // Ceiling.
240 element = base::MakeUnique<UiElement>(); 261 element = base::MakeUnique<UiElement>();
241 element->set_debug_id(kCeiling); 262 element->set_debug_id(kCeiling);
242 element->set_id(AllocateId()); 263 element->set_id(AllocateId());
243 element->set_size({kSceneSize, kSceneSize, 1.0}); 264 element->set_size({kSceneSize, kSceneSize, 1.0});
244 element->set_translation({0.0, kSceneHeight / 2, 0.0}); 265 element->set_translation({0.0, kSceneHeight / 2, 0.0});
245 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); 266 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2});
246 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); 267 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT);
247 element->set_draw_phase(0); 268 element->set_draw_phase(0);
248 ceiling_ = element.get(); 269 ceiling_ = element.get();
249 content_elements_.push_back(element.get()); 270 background_elements_.push_back(element.get());
250 scene_->AddUiElement(std::move(element)); 271 scene_->AddUiElement(std::move(element));
251 272
252 UpdateBackgroundColor(); 273 UpdateBackgroundColor();
253 } 274 }
254 275
255 void UiSceneManager::CreateUrlBar() { 276 void UiSceneManager::CreateUrlBar() {
256 // TODO(cjgrant): Incorporate final size and position. 277 // TODO(cjgrant): Incorporate final size and position.
257 auto url_bar = base::MakeUnique<UrlBar>( 278 auto url_bar = base::MakeUnique<UrlBar>(
258 512, 279 512,
280 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)),
281 base::Bind(&UiSceneManager::OnSecurityIconClicked,
282 base::Unretained(this)),
259 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this))); 283 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this)));
260 url_bar->set_debug_id(kUrlBar); 284 url_bar->set_debug_id(kUrlBar);
261 url_bar->set_id(AllocateId()); 285 url_bar->set_id(AllocateId());
262 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance}); 286 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance});
263 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1}); 287 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1});
264 url_bar->SetBackButtonCallback(
265 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)));
266 url_bar_ = url_bar.get(); 288 url_bar_ = url_bar.get();
267 control_elements_.push_back(url_bar.get()); 289 control_elements_.push_back(url_bar.get());
268 scene_->AddUiElement(std::move(url_bar)); 290 scene_->AddUiElement(std::move(url_bar));
269 291
270 auto indicator = base::MakeUnique<LoadingIndicator>(256); 292 auto indicator = base::MakeUnique<LoadingIndicator>(256);
271 indicator->set_debug_id(kLoadingIndicator); 293 indicator->set_debug_id(kLoadingIndicator);
272 indicator->set_id(AllocateId()); 294 indicator->set_id(AllocateId());
273 indicator->set_translation({0, 0, kLoadingIndicatorOffset}); 295 indicator->set_translation({0, 0, kLoadingIndicatorOffset});
274 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1}); 296 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1});
275 indicator->set_parent_id(url_bar_->id()); 297 indicator->set_parent_id(url_bar_->id());
(...skipping 28 matching lines...) Expand all
304 web_vr_mode_ = web_vr; 326 web_vr_mode_ = web_vr;
305 ConfigureScene(); 327 ConfigureScene();
306 ConfigureSecurityWarnings(); 328 ConfigureSecurityWarnings();
307 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); 329 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_);
308 video_capture_indicator_->set_visible(!web_vr && video_capturing_); 330 video_capture_indicator_->set_visible(!web_vr && video_capturing_);
309 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); 331 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_);
310 } 332 }
311 333
312 void UiSceneManager::ConfigureScene() { 334 void UiSceneManager::ConfigureScene() {
313 exit_warning_->SetEnabled(scene_->is_exiting()); 335 exit_warning_->SetEnabled(scene_->is_exiting());
336 exit_prompt_->SetEnabled(scene_->is_prompting_to_exit());
314 screen_dimmer_->SetEnabled(scene_->is_exiting()); 337 screen_dimmer_->SetEnabled(scene_->is_exiting());
315 338
316 // Controls (URL bar, loading progress, etc). 339 // Controls (URL bar, loading progress, etc).
317 bool controls_visible = !web_vr_mode_ && !fullscreen_; 340 bool controls_visible = !web_vr_mode_ && !fullscreen_;
318 for (UiElement* element : control_elements_) { 341 for (UiElement* element : control_elements_) {
319 element->SetEnabled(controls_visible); 342 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit());
320 } 343 }
321 344
322 // Content elements. 345 // Content elements.
323 for (UiElement* element : content_elements_) { 346 for (UiElement* element : content_elements_) {
347 // We don't want to show the content elements when the exit prompt is
348 // visible. The only content element visible in this case is the invisible
349 // backplane that we add right behind the content rect so that the reticle
350 // doesn't jump when it transitions between the content rect (and the exit
351 // prompt in this case) and the background.
352 bool disabled_for_exit_prompt =
cjgrant 2017/06/05 17:33:53 It looks like we now have two content elements, an
ymalik 2017/06/05 20:02:42 Totally, good catch.
353 element != main_content_backplane_ && scene_->is_prompting_to_exit();
354 element->SetEnabled(!web_vr_mode_ && !disabled_for_exit_prompt);
355 }
356
357 // Background elements.
358 for (UiElement* element : background_elements_) {
324 element->SetEnabled(!web_vr_mode_); 359 element->SetEnabled(!web_vr_mode_);
325 } 360 }
326 361
327 // Update content quad parameters depending on fullscreen. 362 // Update content quad parameters depending on fullscreen.
328 // TODO(http://crbug.com/642937): Animate fullscreen transitions. 363 // TODO(http://crbug.com/642937): Animate fullscreen transitions.
329 if (fullscreen_) { 364 if (fullscreen_) {
330 main_content_->set_translation( 365 main_content_->set_translation(
331 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); 366 {0, kFullscreenVerticalOffset, -kFullscreenDistance});
332 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); 367 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1});
333 } else { 368 } else {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 } 445 }
411 446
412 void UiSceneManager::OnSecurityWarningTimer() { 447 void UiSceneManager::OnSecurityWarningTimer() {
413 transient_security_warning_->set_visible(false); 448 transient_security_warning_->set_visible(false);
414 } 449 }
415 450
416 void UiSceneManager::OnBackButtonClicked() { 451 void UiSceneManager::OnBackButtonClicked() {
417 browser_->NavigateBack(); 452 browser_->NavigateBack();
418 } 453 }
419 454
455 void UiSceneManager::OnSecurityIconClicked() {
456 if (scene_->is_prompting_to_exit())
cjgrant 2017/06/05 17:33:53 In this method and the next, why is the initial if
ymalik 2017/06/05 20:02:42 This is there for safety and you're right that thi
457 return;
458 scene_->set_is_prompting_to_exit(true);
459 ConfigureScene();
460 }
461
462 void UiSceneManager::OnExitPromptPrimaryButtonClicked() {
463 if (!scene_->is_prompting_to_exit())
464 return;
465 scene_->set_is_prompting_to_exit(false);
466 ConfigureScene();
467 }
468
469 void UiSceneManager::OnExitPromptSecondaryButtonClicked() {
470 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo);
471 }
472
420 void UiSceneManager::SetURL(const GURL& gurl) { 473 void UiSceneManager::SetURL(const GURL& gurl) {
421 url_bar_->SetURL(gurl); 474 url_bar_->SetURL(gurl);
422 } 475 }
423 476
424 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { 477 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) {
425 url_bar_->SetSecurityLevel(level); 478 url_bar_->SetSecurityLevel(level);
426 } 479 }
427 480
428 void UiSceneManager::SetLoading(bool loading) { 481 void UiSceneManager::SetLoading(bool loading) {
429 loading_indicator_->SetLoading(loading); 482 loading_indicator_->SetLoading(loading);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (fullscreen_) 516 if (fullscreen_)
464 return ColorScheme::kModeFullscreen; 517 return ColorScheme::kModeFullscreen;
465 return ColorScheme::kModeNormal; 518 return ColorScheme::kModeNormal;
466 } 519 }
467 520
468 const ColorScheme& UiSceneManager::color_scheme() const { 521 const ColorScheme& UiSceneManager::color_scheme() const {
469 return ColorScheme::GetColorScheme(mode()); 522 return ColorScheme::GetColorScheme(mode());
470 } 523 }
471 524
472 } // namespace vr_shell 525 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698