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

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

Issue 2834543006: Hook up insecure content warnings for http webVR presentation. (Closed)
Patch Set: rebase 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.h" 5 #include "chrome/browser/android/vr_shell/ui_scene.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/android/vr_shell/animation.h" 13 #include "chrome/browser/android/vr_shell/animation.h"
14 #include "chrome/browser/android/vr_shell/easing.h" 14 #include "chrome/browser/android/vr_shell/easing.h"
15 #include "chrome/browser/android/vr_shell/ui_element.h" 15 #include "chrome/browser/android/vr_shell/ui_elements/ui_element.h"
16 #include "device/vr/vr_math.h" 16 #include "device/vr/vr_math.h"
17 17
18 namespace vr_shell { 18 namespace vr_shell {
19 19
20 namespace { 20 namespace {
21 21
22 void ApplyAnchoring(const UiElement& parent, 22 void ApplyAnchoring(const UiElement& parent,
23 XAnchoring x_anchoring, 23 XAnchoring x_anchoring,
24 YAnchoring y_anchoring, 24 YAnchoring y_anchoring,
25 Transform* transform) { 25 Transform* transform) {
(...skipping 29 matching lines...) Expand all
55 55
56 void UiScene::AddUiElement(std::unique_ptr<UiElement> element) { 56 void UiScene::AddUiElement(std::unique_ptr<UiElement> element) {
57 CHECK_GE(element->id, 0); 57 CHECK_GE(element->id, 0);
58 CHECK_EQ(GetUiElementById(element->id), nullptr); 58 CHECK_EQ(GetUiElementById(element->id), nullptr);
59 if (element->parent_id >= 0) { 59 if (element->parent_id >= 0) {
60 CHECK_NE(GetUiElementById(element->parent_id), nullptr); 60 CHECK_NE(GetUiElementById(element->parent_id), nullptr);
61 } else { 61 } else {
62 CHECK_EQ(element->x_anchoring, XAnchoring::XNONE); 62 CHECK_EQ(element->x_anchoring, XAnchoring::XNONE);
63 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE); 63 CHECK_EQ(element->y_anchoring, YAnchoring::YNONE);
64 } 64 }
65 if (gl_initialized_)
66 element->Initialize();
65 ui_elements_.push_back(std::move(element)); 67 ui_elements_.push_back(std::move(element));
66 } 68 }
67 69
68 void UiScene::RemoveUiElement(int element_id) { 70 void UiScene::RemoveUiElement(int element_id) {
69 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) { 71 for (auto it = ui_elements_.begin(); it != ui_elements_.end(); ++it) {
70 if ((*it)->id == element_id) { 72 if ((*it)->id == element_id) {
71 if ((*it)->fill == Fill::CONTENT) { 73 if ((*it)->fill == Fill::CONTENT) {
72 content_element_ = nullptr; 74 content_element_ = nullptr;
73 } 75 }
74 ui_elements_.erase(it); 76 ui_elements_.erase(it);
75 return; 77 return;
76 } 78 }
77 } 79 }
78 } 80 }
79 81
80 void UiScene::AddAnimation(int element_id, 82 void UiScene::AddAnimation(int element_id,
81 std::unique_ptr<Animation> animation) { 83 std::unique_ptr<Animation> animation) {
82 UiElement* element = GetUiElementById(element_id); 84 UiElement* element = GetUiElementById(element_id);
83 CHECK_NE(element, nullptr); 85 CHECK_NE(element, nullptr);
84 for (auto& existing_animation : element->animations) { 86 for (const std::unique_ptr<Animation>& existing : element->animations) {
85 CHECK_NE(existing_animation->id, animation->id); 87 CHECK_NE(existing->id, animation->id);
86 } 88 }
87 element->animations.emplace_back(std::move(animation)); 89 element->animations.emplace_back(std::move(animation));
88 } 90 }
89 91
90 void UiScene::RemoveAnimation(int element_id, int animation_id) { 92 void UiScene::RemoveAnimation(int element_id, int animation_id) {
91 UiElement* element = GetUiElementById(element_id); 93 UiElement* element = GetUiElementById(element_id);
92 CHECK_NE(element, nullptr); 94 CHECK_NE(element, nullptr);
93 auto& animations = element->animations; 95 auto& animations = element->animations;
94 for (auto it = animations.begin(); it != animations.end(); ++it) { 96 for (auto it = animations.begin(); it != animations.end(); ++it) {
95 const Animation& existing_animation = **it; 97 const Animation& existing_animation = **it;
96 if (existing_animation.id == animation_id) { 98 if (existing_animation.id == animation_id) {
97 animations.erase(it); 99 animations.erase(it);
98 return; 100 return;
99 } 101 }
100 } 102 }
101 } 103 }
102 104
103 void UiScene::UpdateTransforms(const base::TimeTicks& time) { 105 void UiScene::UpdateTransforms(const base::TimeTicks& time) {
104 for (auto& element : ui_elements_) { 106 for (const std::unique_ptr<UiElement>& element : ui_elements_) {
105 // Process all animations before calculating object transforms. 107 // Process all animations before calculating object transforms.
106 element->Animate(time); 108 element->Animate(time);
107 element->dirty = true; 109 element->dirty = true;
108 } 110 }
109 for (auto& element : ui_elements_) { 111 for (auto& element : ui_elements_) {
110 ApplyRecursiveTransforms(element.get()); 112 ApplyRecursiveTransforms(element.get());
111 } 113 }
112 } 114 }
113 115
114 UiElement* UiScene::GetUiElementById(int element_id) { 116 UiElement* UiScene::GetUiElementById(int element_id) {
115 for (auto& element : ui_elements_) { 117 for (const std::unique_ptr<UiElement>& element : ui_elements_) {
116 if (element->id == element_id) { 118 if (element->id == element_id) {
117 return element.get(); 119 return element.get();
118 } 120 }
119 } 121 }
120 return nullptr; 122 return nullptr;
121 } 123 }
122 124
123 std::vector<const UiElement*> UiScene::GetWorldElements() const { 125 std::vector<const UiElement*> UiScene::GetWorldElements() const {
124 std::vector<const UiElement*> elements; 126 std::vector<const UiElement*> elements;
125 for (const auto& element : ui_elements_) { 127 for (const std::unique_ptr<UiElement>& element : ui_elements_) {
126 if (element->IsVisible() && !element->lock_to_fov) { 128 if (element->IsVisible() && !element->lock_to_fov) {
127 elements.push_back(element.get()); 129 elements.push_back(element.get());
128 } 130 }
129 } 131 }
130 return elements; 132 return elements;
131 } 133 }
132 134
133 std::vector<const UiElement*> UiScene::GetHeadLockedElements() const { 135 std::vector<const UiElement*> UiScene::GetHeadLockedElements() const {
134 std::vector<const UiElement*> elements; 136 std::vector<const UiElement*> elements;
135 for (const auto& element : ui_elements_) { 137 for (const std::unique_ptr<UiElement>& element : ui_elements_) {
136 if (element->IsVisible() && element->lock_to_fov) { 138 if (element->IsVisible() && element->lock_to_fov) {
137 elements.push_back(element.get()); 139 elements.push_back(element.get());
138 } 140 }
139 } 141 }
140 return elements; 142 return elements;
141 } 143 }
142 144
143 bool UiScene::HasVisibleHeadLockedElements() const { 145 bool UiScene::HasVisibleHeadLockedElements() const {
144 return !GetHeadLockedElements().empty(); 146 return !GetHeadLockedElements().empty();
145 } 147 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 198
197 element->computed_opacity *= parent->opacity; 199 element->computed_opacity *= parent->opacity;
198 element->computed_lock_to_fov = parent->lock_to_fov; 200 element->computed_lock_to_fov = parent->lock_to_fov;
199 } 201 }
200 202
201 vr::MatrixMul(inheritable->to_world, transform->to_world, 203 vr::MatrixMul(inheritable->to_world, transform->to_world,
202 &transform->to_world); 204 &transform->to_world);
203 element->dirty = false; 205 element->dirty = false;
204 } 206 }
205 207
208 // TODO(mthiesse): Move this to UiSceneManager.
209 void UiScene::OnGLInitialized() {
210 gl_initialized_ = true;
211 for (const std::unique_ptr<UiElement>& element : ui_elements_) {
212 element->Initialize();
213 }
214 }
215
206 } // namespace vr_shell 216 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_scene.h ('k') | chrome/browser/android/vr_shell/ui_scene_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698