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

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: 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/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_browser_interface.h" 11 #include "chrome/browser/android/vr_shell/ui_browser_interface.h"
12 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h" 12 #include "chrome/browser/android/vr_shell/ui_elements/audio_capture_indicator.h"
13 #include "chrome/browser/android/vr_shell/ui_elements/button.h" 13 #include "chrome/browser/android/vr_shell/ui_elements/button.h"
14 #include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h"
14 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h" 15 #include "chrome/browser/android/vr_shell/ui_elements/exit_warning.h"
15 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h" 16 #include "chrome/browser/android/vr_shell/ui_elements/loading_indicator.h"
16 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h" 17 #include "chrome/browser/android/vr_shell/ui_elements/permanent_security_warning .h"
17 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h " 18 #include "chrome/browser/android/vr_shell/ui_elements/screen_capture_indicator.h "
18 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h" 19 #include "chrome/browser/android/vr_shell/ui_elements/screen_dimmer.h"
19 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h" 20 #include "chrome/browser/android/vr_shell/ui_elements/transient_security_warning .h"
20 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h" 21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
21 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" 22 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h"
22 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h" 23 #include "chrome/browser/android/vr_shell/ui_elements/url_bar.h"
23 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h" 24 #include "chrome/browser/android/vr_shell/ui_elements/video_capture_indicator.h"
(...skipping 20 matching lines...) Expand all
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
49 static constexpr float kFullscreenDistance = 3; 50 static constexpr float kFullscreenDistance = 3;
50 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance; 51 static constexpr float kFullscreenHeight = 0.64 * kFullscreenDistance;
51 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance; 52 static constexpr float kFullscreenWidth = 1.138 * kFullscreenDistance;
52 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance; 53 static constexpr float kFullscreenVerticalOffset = -0.1 * kFullscreenDistance;
53 54
55 static constexpr float kExitPromptWidth = 0.672 * kContentDistance;
56 static constexpr float kExitPromptHeight = 0.2 * kContentDistance;
57 static constexpr float kExitPromptVerticalOffset = -0.09 * kContentDistance;
58
54 static constexpr float kUrlBarDistance = 2.4; 59 static constexpr float kUrlBarDistance = 2.4;
55 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance; 60 static constexpr float kUrlBarWidth = 0.672 * kUrlBarDistance;
56 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance; 61 static constexpr float kUrlBarHeight = 0.088 * kUrlBarDistance;
57 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance; 62 static constexpr float kUrlBarVerticalOffset = -0.516 * kUrlBarDistance;
58 static constexpr float kUrlBarRotationRad = -0.175; 63 static constexpr float kUrlBarRotationRad = -0.175;
59 64
60 static constexpr float kCloseButtonDistance = 2.4; 65 static constexpr float kCloseButtonDistance = 2.4;
61 static constexpr float kCloseButtonHeight = 0.088 * kCloseButtonDistance; 66 static constexpr float kCloseButtonHeight = 0.088 * kCloseButtonDistance;
62 static constexpr float kCloseButtonWidth = 0.088 * kCloseButtonDistance; 67 static constexpr float kCloseButtonWidth = 0.088 * kCloseButtonDistance;
63 static constexpr float kCloseButtonFullscreenDistance = 2.9; 68 static constexpr float kCloseButtonFullscreenDistance = 2.9;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 222
218 // Place an invisible but hittable plane behind the content quad, to keep the 223 // Place an invisible but hittable plane behind the content quad, to keep the
219 // reticle roughly planar with the content if near content. 224 // reticle roughly planar with the content if near content.
220 element = base::MakeUnique<UiElement>(); 225 element = base::MakeUnique<UiElement>();
221 element->set_debug_id(kBackplane); 226 element->set_debug_id(kBackplane);
222 element->set_id(AllocateId()); 227 element->set_id(AllocateId());
223 element->set_fill(vr_shell::Fill::NONE); 228 element->set_fill(vr_shell::Fill::NONE);
224 element->set_size({kBackplaneSize, kBackplaneSize, 1.0}); 229 element->set_size({kBackplaneSize, kBackplaneSize, 1.0});
225 element->set_translation({0.0, 0.0, -kTextureOffset}); 230 element->set_translation({0.0, 0.0, -kTextureOffset});
226 element->set_parent_id(main_content_->id()); 231 element->set_parent_id(main_content_->id());
232 main_content_backplane_ = element.get();
227 content_elements_.push_back(element.get()); 233 content_elements_.push_back(element.get());
228 scene_->AddUiElement(std::move(element)); 234 scene_->AddUiElement(std::move(element));
229 235
236 element = base::MakeUnique<ExitPrompt>(
237 512,
238 base::Bind(&UiSceneManager::OnExitPromptPrimaryButtonClicked,
239 base::Unretained(this)),
240 base::Bind(&UiSceneManager::OnExitPromptSecondaryButtonClicked,
241 base::Unretained(this)));
242 element->set_debug_id(kExitPrompt);
243 element->set_id(AllocateId());
244 element->set_fill(vr_shell::Fill::NONE);
245 element->set_size({kExitPromptWidth, kExitPromptHeight, 1});
246 element->set_translation({0.0, kExitPromptVerticalOffset, kTextureOffset});
247 element->set_parent_id(main_content_->id());
248 element->set_visible(false);
249 exit_prompt_ = element.get();
250 scene_->AddUiElement(std::move(element));
251
230 // Limit reticle distance to a sphere based on content distance. 252 // Limit reticle distance to a sphere based on content distance.
231 scene_->SetBackgroundDistance(main_content_->translation().z() * 253 scene_->SetBackgroundDistance(main_content_->translation().z() *
232 -kBackgroundDistanceMultiplier); 254 -kBackgroundDistanceMultiplier);
233 } 255 }
234 256
235 void UiSceneManager::CreateBackground() { 257 void UiSceneManager::CreateBackground() {
236 std::unique_ptr<UiElement> element; 258 std::unique_ptr<UiElement> element;
237 259
238 // Floor. 260 // Floor.
239 element = base::MakeUnique<UiElement>(); 261 element = base::MakeUnique<UiElement>();
240 element->set_debug_id(kFloor); 262 element->set_debug_id(kFloor);
241 element->set_id(AllocateId()); 263 element->set_id(AllocateId());
242 element->set_size({kSceneSize, kSceneSize, 1.0}); 264 element->set_size({kSceneSize, kSceneSize, 1.0});
243 element->set_translation({0.0, -kSceneHeight / 2, 0.0}); 265 element->set_translation({0.0, -kSceneHeight / 2, 0.0});
244 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0}); 266 element->set_rotation({1.0, 0.0, 0.0, -M_PI / 2.0});
245 element->set_fill(vr_shell::Fill::GRID_GRADIENT); 267 element->set_fill(vr_shell::Fill::GRID_GRADIENT);
246 element->set_draw_phase(0); 268 element->set_draw_phase(0);
247 element->set_gridline_count(kFloorGridlineCount); 269 element->set_gridline_count(kFloorGridlineCount);
248 floor_ = element.get(); 270 floor_ = element.get();
249 content_elements_.push_back(element.get()); 271 background_elements_.push_back(element.get());
250 scene_->AddUiElement(std::move(element)); 272 scene_->AddUiElement(std::move(element));
251 273
252 // Ceiling. 274 // Ceiling.
253 element = base::MakeUnique<UiElement>(); 275 element = base::MakeUnique<UiElement>();
254 element->set_debug_id(kCeiling); 276 element->set_debug_id(kCeiling);
255 element->set_id(AllocateId()); 277 element->set_id(AllocateId());
256 element->set_size({kSceneSize, kSceneSize, 1.0}); 278 element->set_size({kSceneSize, kSceneSize, 1.0});
257 element->set_translation({0.0, kSceneHeight / 2, 0.0}); 279 element->set_translation({0.0, kSceneHeight / 2, 0.0});
258 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2}); 280 element->set_rotation({1.0, 0.0, 0.0, M_PI / 2});
259 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT); 281 element->set_fill(vr_shell::Fill::OPAQUE_GRADIENT);
260 element->set_draw_phase(0); 282 element->set_draw_phase(0);
261 ceiling_ = element.get(); 283 ceiling_ = element.get();
262 content_elements_.push_back(element.get()); 284 background_elements_.push_back(element.get());
263 scene_->AddUiElement(std::move(element)); 285 scene_->AddUiElement(std::move(element));
264 286
265 UpdateBackgroundColor(); 287 UpdateBackgroundColor();
266 } 288 }
267 289
268 void UiSceneManager::CreateUrlBar() { 290 void UiSceneManager::CreateUrlBar() {
269 // TODO(cjgrant): Incorporate final size and position. 291 // TODO(cjgrant): Incorporate final size and position.
270 auto url_bar = base::MakeUnique<UrlBar>( 292 auto url_bar = base::MakeUnique<UrlBar>(
271 512, 293 512,
294 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)),
295 base::Bind(&UiSceneManager::OnSecurityIconClicked,
296 base::Unretained(this)),
272 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this))); 297 base::Bind(&UiSceneManager::OnUnsupportedMode, base::Unretained(this)));
273 url_bar->set_debug_id(kUrlBar); 298 url_bar->set_debug_id(kUrlBar);
274 url_bar->set_id(AllocateId()); 299 url_bar->set_id(AllocateId());
275 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance}); 300 url_bar->set_translation({0, kUrlBarVerticalOffset, -kUrlBarDistance});
276 url_bar->set_rotation({1.0, 0.0, 0.0, kUrlBarRotationRad}); 301 url_bar->set_rotation({1.0, 0.0, 0.0, kUrlBarRotationRad});
277 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1}); 302 url_bar->set_size({kUrlBarWidth, kUrlBarHeight, 1});
278 url_bar->SetBackButtonCallback(
279 base::Bind(&UiSceneManager::OnBackButtonClicked, base::Unretained(this)));
280 url_bar_ = url_bar.get(); 303 url_bar_ = url_bar.get();
281 control_elements_.push_back(url_bar.get()); 304 control_elements_.push_back(url_bar.get());
282 scene_->AddUiElement(std::move(url_bar)); 305 scene_->AddUiElement(std::move(url_bar));
283 306
284 auto indicator = base::MakeUnique<LoadingIndicator>(256); 307 auto indicator = base::MakeUnique<LoadingIndicator>(256);
285 indicator->set_debug_id(kLoadingIndicator); 308 indicator->set_debug_id(kLoadingIndicator);
286 indicator->set_id(AllocateId()); 309 indicator->set_id(AllocateId());
287 indicator->set_translation( 310 indicator->set_translation(
288 {0, kLoadingIndicatorVerticalOffset, kLoadingIndicatorDepthOffset}); 311 {0, kLoadingIndicatorVerticalOffset, kLoadingIndicatorDepthOffset});
289 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1}); 312 indicator->set_size({kLoadingIndicatorWidth, kLoadingIndicatorHeight, 1});
(...skipping 29 matching lines...) Expand all
319 web_vr_mode_ = web_vr; 342 web_vr_mode_ = web_vr;
320 ConfigureScene(); 343 ConfigureScene();
321 ConfigureSecurityWarnings(); 344 ConfigureSecurityWarnings();
322 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_); 345 audio_capture_indicator_->set_visible(!web_vr && audio_capturing_);
323 video_capture_indicator_->set_visible(!web_vr && video_capturing_); 346 video_capture_indicator_->set_visible(!web_vr && video_capturing_);
324 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_); 347 screen_capture_indicator_->set_visible(!web_vr && screen_capturing_);
325 } 348 }
326 349
327 void UiSceneManager::ConfigureScene() { 350 void UiSceneManager::ConfigureScene() {
328 exit_warning_->SetEnabled(scene_->is_exiting()); 351 exit_warning_->SetEnabled(scene_->is_exiting());
352 exit_prompt_->SetEnabled(scene_->is_prompting_to_exit());
329 screen_dimmer_->SetEnabled(scene_->is_exiting()); 353 screen_dimmer_->SetEnabled(scene_->is_exiting());
330 354
331 // Controls (URL bar, loading progress, etc). 355 // Controls (URL bar, loading progress, etc).
332 bool controls_visible = !web_vr_mode_ && !fullscreen_; 356 bool controls_visible = !web_vr_mode_ && !fullscreen_;
333 for (UiElement* element : control_elements_) { 357 for (UiElement* element : control_elements_) {
334 element->SetEnabled(controls_visible); 358 element->SetEnabled(controls_visible && !scene_->is_prompting_to_exit());
335 } 359 }
336 360
337 // Close button is a special control element that needs to be hidden when in 361 // Close button is a special control element that needs to be hidden when in
338 // WebVR, but it needs to be visible when in cct or fullscreen. 362 // WebVR, but it needs to be visible when in cct or fullscreen.
339 close_button_->SetEnabled(!web_vr_mode_ && (fullscreen_ || in_cct_)); 363 close_button_->SetEnabled(!web_vr_mode_ && (fullscreen_ || in_cct_));
340 364
341 // Content elements. 365 // Content elements.
342 for (UiElement* element : content_elements_) { 366 main_content_->SetEnabled(!web_vr_mode_ && !scene_->is_prompting_to_exit());
367 main_content_backplane_->SetEnabled(!web_vr_mode_);
368 // Background elements.
369 for (UiElement* element : background_elements_) {
343 element->SetEnabled(!web_vr_mode_); 370 element->SetEnabled(!web_vr_mode_);
344 } 371 }
345 372
346 // Update content quad parameters depending on fullscreen. 373 // Update content quad parameters depending on fullscreen.
347 // TODO(http://crbug.com/642937): Animate fullscreen transitions. 374 // TODO(http://crbug.com/642937): Animate fullscreen transitions.
348 if (fullscreen_) { 375 if (fullscreen_) {
349 main_content_->set_translation( 376 main_content_->set_translation(
350 {0, kFullscreenVerticalOffset, -kFullscreenDistance}); 377 {0, kFullscreenVerticalOffset, -kFullscreenDistance});
351 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1}); 378 main_content_->set_size({kFullscreenWidth, kFullscreenHeight, 1});
352 379
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 } 468 }
442 469
443 void UiSceneManager::OnSecurityWarningTimer() { 470 void UiSceneManager::OnSecurityWarningTimer() {
444 transient_security_warning_->set_visible(false); 471 transient_security_warning_->set_visible(false);
445 } 472 }
446 473
447 void UiSceneManager::OnBackButtonClicked() { 474 void UiSceneManager::OnBackButtonClicked() {
448 browser_->NavigateBack(); 475 browser_->NavigateBack();
449 } 476 }
450 477
478 void UiSceneManager::OnSecurityIconClicked() {
479 if (scene_->is_prompting_to_exit())
480 return;
481 scene_->set_is_prompting_to_exit(true);
482 ConfigureScene();
483 }
484
485 void UiSceneManager::OnExitPromptPrimaryButtonClicked() {
486 if (!scene_->is_prompting_to_exit())
487 return;
488 scene_->set_is_prompting_to_exit(false);
489 ConfigureScene();
490 }
491
492 void UiSceneManager::OnExitPromptSecondaryButtonClicked() {
493 OnUnsupportedMode(UiUnsupportedMode::kUnhandledPageInfo);
494 }
495
451 void UiSceneManager::SetURL(const GURL& gurl) { 496 void UiSceneManager::SetURL(const GURL& gurl) {
452 url_bar_->SetURL(gurl); 497 url_bar_->SetURL(gurl);
453 } 498 }
454 499
455 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) { 500 void UiSceneManager::SetSecurityLevel(security_state::SecurityLevel level) {
456 url_bar_->SetSecurityLevel(level); 501 url_bar_->SetSecurityLevel(level);
457 } 502 }
458 503
459 void UiSceneManager::SetLoading(bool loading) { 504 void UiSceneManager::SetLoading(bool loading) {
460 loading_indicator_->SetLoading(loading); 505 loading_indicator_->SetLoading(loading);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (fullscreen_) 544 if (fullscreen_)
500 return ColorScheme::kModeFullscreen; 545 return ColorScheme::kModeFullscreen;
501 return ColorScheme::kModeNormal; 546 return ColorScheme::kModeNormal;
502 } 547 }
503 548
504 const ColorScheme& UiSceneManager::color_scheme() const { 549 const ColorScheme& UiSceneManager::color_scheme() const {
505 return ColorScheme::GetColorScheme(mode()); 550 return ColorScheme::GetColorScheme(mode());
506 } 551 }
507 552
508 } // namespace vr_shell 553 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene_manager.h ('k') | chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698