| OLD | NEW |
| 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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ |
| 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" |
| 14 #include "cc/animation/animation_observer.h" |
| 15 #include "cc/animation/transform_operations.h" |
| 13 #include "chrome/browser/android/vr_shell/color_scheme.h" | 16 #include "chrome/browser/android/vr_shell/color_scheme.h" |
| 14 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" | 17 #include "chrome/browser/android/vr_shell/ui_elements/ui_element_debug_id.h" |
| 15 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/gfx/geometry/point3_f.h" | 19 #include "ui/gfx/geometry/point3_f.h" |
| 17 #include "ui/gfx/geometry/quaternion.h" | 20 #include "ui/gfx/geometry/quaternion.h" |
| 18 #include "ui/gfx/geometry/vector3d_f.h" | 21 #include "ui/gfx/geometry/vector3d_f.h" |
| 19 #include "ui/gfx/transform.h" | 22 #include "ui/gfx/transform.h" |
| 20 | 23 |
| 21 namespace base { | 24 namespace base { |
| 22 class TimeTicks; | 25 class TimeTicks; |
| 23 } | 26 } // namespace base |
| 27 |
| 28 namespace cc { |
| 29 class AnimationPlayer; |
| 30 } // namespace cc |
| 24 | 31 |
| 25 namespace vr_shell { | 32 namespace vr_shell { |
| 26 | 33 |
| 27 class Animation; | |
| 28 class UiElementRenderer; | 34 class UiElementRenderer; |
| 29 | 35 |
| 30 enum XAnchoring { | 36 enum XAnchoring { |
| 31 XNONE = 0, | 37 XNONE = 0, |
| 32 XLEFT, | 38 XLEFT, |
| 33 XRIGHT, | 39 XRIGHT, |
| 34 }; | 40 }; |
| 35 | 41 |
| 36 enum YAnchoring { | 42 enum YAnchoring { |
| 37 YNONE = 0, | 43 YNONE = 0, |
| 38 YTOP, | 44 YTOP, |
| 39 YBOTTOM, | 45 YBOTTOM, |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 enum Fill { | 48 enum Fill { |
| 43 NONE = 0, | 49 NONE = 0, |
| 44 // The element is filled with the content web site. Only one content element | 50 // The element is filled with the content web site. Only one content element |
| 45 // may be added to the | 51 // may be added to the |
| 46 // scene. | 52 // scene. |
| 47 CONTENT = 1, | 53 CONTENT = 1, |
| 48 // The element is filled with a radial gradient as specified by the edge and | 54 // The element is filled with a radial gradient as specified by the edge and |
| 49 // center color. | 55 // center color. |
| 50 OPAQUE_GRADIENT = 2, | 56 OPAQUE_GRADIENT = 2, |
| 51 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. | 57 // Same as OPAQUE_GRADIENT but the element is drawn as a grid. |
| 52 GRID_GRADIENT = 3, | 58 GRID_GRADIENT = 3, |
| 53 // The element draws itself. | 59 // The element draws itself. |
| 54 SELF = 4, | 60 SELF = 4, |
| 55 }; | 61 }; |
| 56 | 62 |
| 57 class WorldRectangle { | 63 class UiElement : public cc::AnimationObserver { |
| 58 public: | 64 public: |
| 59 const gfx::Transform& transform() const { return transform_; } | 65 explicit UiElement(int id); |
| 60 void set_transform(const gfx::Transform& transform) { | 66 ~UiElement() override; |
| 61 transform_ = transform; | |
| 62 } | |
| 63 | |
| 64 gfx::Point3F GetCenter() const; | |
| 65 gfx::Vector3dF GetNormal() const; | |
| 66 | |
| 67 // Computes the distance from |ray_origin| to this rectangles's plane, along | |
| 68 // |ray_vector|. Returns true and populates |distance| if the calculation is | |
| 69 // possible, and false if the ray is parallel to the plane. | |
| 70 bool GetRayDistance(const gfx::Point3F& ray_origin, | |
| 71 const gfx::Vector3dF& ray_vector, | |
| 72 float* distance) const; | |
| 73 | |
| 74 // Projects a 3D world point onto the X and Y axes of the transformed | |
| 75 // rectangle, returning 2D coordinates relative to the un-transformed unit | |
| 76 // rectangle. This allows beam intersection points to be mapped to sprite | |
| 77 // pixel coordinates. Points that fall onto the rectangle will generate X and | |
| 78 // Y values on the interval [-0.5, 0.5]. | |
| 79 gfx::PointF GetUnitRectangleCoordinates( | |
| 80 const gfx::Point3F& world_point) const; | |
| 81 | |
| 82 private: | |
| 83 gfx::Transform transform_; | |
| 84 }; | |
| 85 | |
| 86 class UiElement : public WorldRectangle { | |
| 87 public: | |
| 88 UiElement(); | |
| 89 virtual ~UiElement(); | |
| 90 | 67 |
| 91 virtual void OnBeginFrame(const base::TimeTicks& begin_frame_time); | 68 virtual void OnBeginFrame(const base::TimeTicks& begin_frame_time); |
| 92 | 69 |
| 93 void Animate(const base::TimeTicks& time); | 70 void Animate(const base::TimeTicks& time); |
| 94 | 71 |
| 95 // Indicates whether the element should be visually rendered. | 72 // Indicates whether the element should be visually rendered. |
| 96 bool IsVisible() const; | 73 bool IsVisible() const; |
| 97 | 74 |
| 98 // Indicates whether the element should be tested for cursor input. | 75 // Indicates whether the element should be tested for cursor input. |
| 99 bool IsHitTestable() const; | 76 bool IsHitTestable() const; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 112 // Whether the point (relative to the origin of the element), should be | 89 // Whether the point (relative to the origin of the element), should be |
| 113 // considered on the element. All elements are considered rectangular by | 90 // considered on the element. All elements are considered rectangular by |
| 114 // default though elements may override this function to handle arbitrary | 91 // default though elements may override this function to handle arbitrary |
| 115 // shapes. Points within the rectangular area are mapped from 0:1 as follows, | 92 // shapes. Points within the rectangular area are mapped from 0:1 as follows, |
| 116 // though will extend outside this range when outside of the element: | 93 // though will extend outside this range when outside of the element: |
| 117 // [(0.0, 0.0), (1.0, 0.0) | 94 // [(0.0, 0.0), (1.0, 0.0) |
| 118 // (1.0, 0.0), (1.0, 1.0)] | 95 // (1.0, 0.0), (1.0, 1.0)] |
| 119 virtual bool HitTest(const gfx::PointF& point) const; | 96 virtual bool HitTest(const gfx::PointF& point) const; |
| 120 | 97 |
| 121 int id() const { return id_; } | 98 int id() const { return id_; } |
| 122 void set_id(int id) { id_ = id; } | |
| 123 | 99 |
| 124 // If a non-negative parent ID is specified, applicable transformations | 100 // If a non-negative parent ID is specified, applicable transformations |
| 125 // are applied relative to the parent, rather than absolutely. | 101 // are applied relative to the parent, rather than absolutely. |
| 126 int parent_id() const { return parent_id_; } | 102 int parent_id() const { return parent_id_; } |
| 127 void set_parent_id(int id) { parent_id_ = id; } | 103 void set_parent_id(int id) { parent_id_ = id; } |
| 128 | 104 |
| 129 // If true, this object will be visible. | 105 // If true, this object will be visible. |
| 130 bool visible() const { return visible_; } | 106 bool visible() const { return visible_; } |
| 131 void set_visible(bool visible) { visible_ = visible; } | 107 void set_visible(bool visible) { visible_ = visible; } |
| 132 | 108 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 146 // The computed lock to the FoV, incorporating lock of parent objects. | 122 // The computed lock to the FoV, incorporating lock of parent objects. |
| 147 bool computed_lock_to_fov() const { return computed_lock_to_fov_; } | 123 bool computed_lock_to_fov() const { return computed_lock_to_fov_; } |
| 148 void set_computed_lock_to_fov(bool computed_lock) { | 124 void set_computed_lock_to_fov(bool computed_lock) { |
| 149 computed_lock_to_fov_ = computed_lock; | 125 computed_lock_to_fov_ = computed_lock; |
| 150 } | 126 } |
| 151 | 127 |
| 152 // The size of the object. This does not affect children. | 128 // The size of the object. This does not affect children. |
| 153 gfx::Vector3dF size() const { return size_; } | 129 gfx::Vector3dF size() const { return size_; } |
| 154 void set_size(const gfx::Vector3dF& size) { size_ = size; } | 130 void set_size(const gfx::Vector3dF& size) { size_ = size; } |
| 155 | 131 |
| 156 // The scale of the object, and its children. | 132 // This is the local transform. It is inherited by descendants. |
| 157 gfx::Vector3dF scale() const { return scale_; } | 133 const cc::TransformOperations& transform_operations() const { |
| 158 void set_scale(const gfx::Vector3dF& scale) { scale_ = scale; } | 134 return transform_operations_; |
| 135 } |
| 159 | 136 |
| 160 // The rotation of the object, and its children. | 137 void set_transform_operations(const cc::TransformOperations& operations) { |
| 161 gfx::Quaternion rotation() const { return rotation_; } | 138 transform_operations_ = operations; |
| 162 void set_rotation(const gfx::Quaternion& rotation) { rotation_ = rotation; } | |
| 163 | |
| 164 // The translation of the object, and its children. Translation is applied | |
| 165 // after rotation and scaling. | |
| 166 gfx::Vector3dF translation() const { return translation_; } | |
| 167 void set_translation(const gfx::Vector3dF& translation) { | |
| 168 translation_ = translation; | |
| 169 } | 139 } |
| 170 | 140 |
| 171 // The opacity of the object (between 0.0 and 1.0). | 141 // The opacity of the object (between 0.0 and 1.0). |
| 172 float opacity() const { return opacity_; } | 142 float opacity() const { return opacity_; } |
| 173 void set_opacity(float opacity) { opacity_ = opacity; } | 143 void set_opacity(float opacity) { opacity_ = opacity; } |
| 174 | 144 |
| 175 // The computed opacity, incorporating opacity of parent objects. | 145 // The computed opacity, incorporating opacity of parent objects. |
| 176 float computed_opacity() const { return computed_opacity_; } | 146 float computed_opacity() const { return computed_opacity_; } |
| 177 void set_computed_opacity(float computed_opacity) { | 147 void set_computed_opacity(float computed_opacity) { |
| 178 computed_opacity_ = computed_opacity; | 148 computed_opacity_ = computed_opacity; |
| 179 } | 149 } |
| 180 | 150 |
| 181 // If anchoring is specified, the translation will be relative to the | 151 // If anchoring is specified, the translation will be relative to the |
| 182 // specified edge(s) of the parent, rather than the center. A parent object | 152 // specified edge(s) of the parent, rather than the center. A parent object |
| 183 // must be specified when using anchoring. | 153 // must be specified when using anchoring. |
| 184 XAnchoring x_anchoring() const { return x_anchoring_; } | 154 XAnchoring x_anchoring() const { return x_anchoring_; } |
| 185 void set_x_anchoring(XAnchoring x_anchoring) { x_anchoring_ = x_anchoring; } | 155 void set_x_anchoring(XAnchoring x_anchoring) { x_anchoring_ = x_anchoring; } |
| 186 | 156 |
| 187 YAnchoring y_anchoring() const { return y_anchoring_; } | 157 YAnchoring y_anchoring() const { return y_anchoring_; } |
| 188 void set_y_anchoring(YAnchoring y_anchoring) { y_anchoring_ = y_anchoring; } | 158 void set_y_anchoring(YAnchoring y_anchoring) { y_anchoring_ = y_anchoring; } |
| 189 | 159 |
| 190 // Animations that affect the properties of the object over time. | 160 // Animations that affect the properties of the object over time. |
| 191 std::vector<std::unique_ptr<Animation>>& animations() { return animations_; } | 161 cc::AnimationPlayer& animation_player() { return *animation_player_; } |
| 192 const std::vector<std::unique_ptr<Animation>>& animations() const { | |
| 193 return animations_; | |
| 194 } | |
| 195 | 162 |
| 196 Fill fill() const { return fill_; } | 163 Fill fill() const { return fill_; } |
| 197 void set_fill(Fill fill) { fill_ = fill; } | 164 void set_fill(Fill fill) { fill_ = fill; } |
| 198 | 165 |
| 199 SkColor edge_color() const { return edge_color_; } | 166 SkColor edge_color() const { return edge_color_; } |
| 200 void set_edge_color(const SkColor& edge_color) { edge_color_ = edge_color; } | 167 void set_edge_color(const SkColor& edge_color) { edge_color_ = edge_color; } |
| 201 | 168 |
| 202 SkColor center_color() const { return center_color_; } | 169 SkColor center_color() const { return center_color_; } |
| 203 void set_center_color(const SkColor& center_color) { | 170 void set_center_color(const SkColor& center_color) { |
| 204 center_color_ = center_color; | 171 center_color_ = center_color; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 231 UiElementDebugId debug_id() const { return debug_id_; } | 198 UiElementDebugId debug_id() const { return debug_id_; } |
| 232 void set_debug_id(UiElementDebugId debug_id) { debug_id_ = debug_id; } | 199 void set_debug_id(UiElementDebugId debug_id) { debug_id_ = debug_id; } |
| 233 | 200 |
| 234 // By default, sets an element to be visible or not. This may be overridden to | 201 // By default, sets an element to be visible or not. This may be overridden to |
| 235 // allow finer control of element visibility. | 202 // allow finer control of element visibility. |
| 236 virtual void SetEnabled(bool enabled); | 203 virtual void SetEnabled(bool enabled); |
| 237 | 204 |
| 238 void SetMode(ColorScheme::Mode mode); | 205 void SetMode(ColorScheme::Mode mode); |
| 239 ColorScheme::Mode mode() const { return mode_; } | 206 ColorScheme::Mode mode() const { return mode_; } |
| 240 | 207 |
| 208 const gfx::Transform& screen_space_transform() const { |
| 209 return screen_space_transform_; |
| 210 } |
| 211 void set_screen_space_transform(const gfx::Transform& transform) { |
| 212 screen_space_transform_ = transform; |
| 213 } |
| 214 |
| 215 gfx::Point3F GetCenter() const; |
| 216 gfx::Vector3dF GetNormal() const; |
| 217 |
| 218 // Computes the distance from |ray_origin| to this rectangles's plane, along |
| 219 // |ray_vector|. Returns true and populates |distance| if the calculation is |
| 220 // possible, and false if the ray is parallel to the plane. |
| 221 bool GetRayDistance(const gfx::Point3F& ray_origin, |
| 222 const gfx::Vector3dF& ray_vector, |
| 223 float* distance) const; |
| 224 |
| 225 // Projects a 3D world point onto the X and Y axes of the transformed |
| 226 // rectangle, returning 2D coordinates relative to the un-transformed unit |
| 227 // rectangle. This allows beam intersection points to be mapped to sprite |
| 228 // pixel coordinates. Points that fall onto the rectangle will generate X and |
| 229 // Y values on the interval [-0.5, 0.5]. |
| 230 gfx::PointF GetUnitRectangleCoordinates( |
| 231 const gfx::Point3F& world_point) const; |
| 232 |
| 241 protected: | 233 protected: |
| 242 virtual void OnSetMode(); | 234 virtual void OnSetMode(); |
| 243 | 235 |
| 244 private: | 236 private: |
| 237 // cc::AnimationObserver |
| 238 void NotifyClientOpacityAnimated(float opacity, |
| 239 bool notify_active_elements, |
| 240 bool notify_pending_elements) override; |
| 241 void NotifyClientTransformOperationsAnimated( |
| 242 const cc::TransformOperations& operations, |
| 243 bool notify_active_elements, |
| 244 bool notify_pending_elements) override; |
| 245 |
| 246 void NotifyClientBoundsAnimated(const gfx::SizeF& size, |
| 247 bool notify_active_elements, |
| 248 bool notify_pending_elements) override; |
| 249 |
| 245 // Valid IDs are non-negative. | 250 // Valid IDs are non-negative. |
| 246 int id_ = -1; | 251 int id_ = -1; |
| 247 | 252 |
| 248 // If a non-negative parent ID is specified, applicable transformations | 253 // If a non-negative parent ID is specified, applicable transformations |
| 249 // are applied relative to the parent, rather than absolutely. | 254 // are applied relative to the parent, rather than absolutely. |
| 250 int parent_id_ = -1; | 255 int parent_id_ = -1; |
| 251 | 256 |
| 252 // If true, this object will be visible. | 257 // If true, this object will be visible. |
| 253 bool visible_ = false; | 258 bool visible_ = false; |
| 254 | 259 |
| 255 // If false, the reticle will not hit the element, even if visible. | 260 // If false, the reticle will not hit the element, even if visible. |
| 256 bool hit_testable_ = true; | 261 bool hit_testable_ = true; |
| 257 | 262 |
| 258 // If true, transformations will be applied relative to the field of view, | 263 // If true, transformations will be applied relative to the field of view, |
| 259 // rather than the world. | 264 // rather than the world. |
| 260 bool lock_to_fov_ = false; | 265 bool lock_to_fov_ = false; |
| 261 | 266 |
| 262 // The computed lock to the FoV, incorporating lock of parent objects. | 267 // The computed lock to the FoV, incorporating lock of parent objects. |
| 263 bool computed_lock_to_fov_ = false; | 268 bool computed_lock_to_fov_ = false; |
| 264 | 269 |
| 265 // If true, then this element will be drawn in the world viewport, but above | 270 // If true, then this element will be drawn in the world viewport, but above |
| 266 // all other elements. | 271 // all other elements. |
| 267 bool is_overlay_ = false; | 272 bool is_overlay_ = false; |
| 268 | 273 |
| 269 // The size of the object. This does not affect children. | 274 // The size of the object. This does not affect children. |
| 270 gfx::Vector3dF size_ = {1.0f, 1.0f, 1.0f}; | 275 gfx::Vector3dF size_ = {1.0f, 1.0f, 1.0f}; |
| 271 | 276 |
| 272 // The scale of the object, and its children. | |
| 273 gfx::Vector3dF scale_ = {1.0f, 1.0f, 1.0f}; | |
| 274 | |
| 275 // The rotation of the object, and its children. | |
| 276 gfx::Quaternion rotation_; | |
| 277 | |
| 278 // The translation of the object, and its children. Translation is applied | |
| 279 // after rotation and scaling. | |
| 280 gfx::Vector3dF translation_ = {0.0f, 0.0f, 0.0f}; | |
| 281 | |
| 282 // The opacity of the object (between 0.0 and 1.0). | 277 // The opacity of the object (between 0.0 and 1.0). |
| 283 float opacity_ = 1.0f; | 278 float opacity_ = 1.0f; |
| 284 | 279 |
| 285 // The computed opacity, incorporating opacity of parent objects. | 280 // The computed opacity, incorporating opacity of parent objects. |
| 286 float computed_opacity_ = 1.0f; | 281 float computed_opacity_ = 1.0f; |
| 287 | 282 |
| 288 // If anchoring is specified, the translation will be relative to the | 283 // If anchoring is specified, the translation will be relative to the |
| 289 // specified edge(s) of the parent, rather than the center. A parent object | 284 // specified edge(s) of the parent, rather than the center. A parent object |
| 290 // must be specified when using anchoring. | 285 // must be specified when using anchoring. |
| 291 XAnchoring x_anchoring_ = XAnchoring::XNONE; | 286 XAnchoring x_anchoring_ = XAnchoring::XNONE; |
| 292 YAnchoring y_anchoring_ = YAnchoring::YNONE; | 287 YAnchoring y_anchoring_ = YAnchoring::YNONE; |
| 293 | 288 |
| 294 // Animations that affect the properties of the object over time. | 289 scoped_refptr<cc::AnimationPlayer> animation_player_; |
| 295 std::vector<std::unique_ptr<Animation>> animations_; | |
| 296 | 290 |
| 297 Fill fill_ = Fill::NONE; | 291 Fill fill_ = Fill::NONE; |
| 298 | 292 |
| 299 SkColor edge_color_ = SK_ColorWHITE; | 293 SkColor edge_color_ = SK_ColorWHITE; |
| 300 SkColor center_color_ = SK_ColorWHITE; | 294 SkColor center_color_ = SK_ColorWHITE; |
| 301 SkColor grid_color_ = SK_ColorWHITE; | 295 SkColor grid_color_ = SK_ColorWHITE; |
| 302 | 296 |
| 303 int gridline_count_ = 1; | 297 int gridline_count_ = 1; |
| 304 | 298 |
| 305 int draw_phase_ = 1; | 299 int draw_phase_ = 1; |
| 306 | 300 |
| 301 // This local transform operations. They are inherited by descendants and are |
| 302 // stored as a list of operations rather than a baked transform to make |
| 303 // transitions easier to implement (you may, for example, want to animate just |
| 304 // the translation, but leave the rotation and scale in tact). |
| 305 cc::TransformOperations transform_operations_; |
| 306 |
| 307 // This is the combined, local to screen transform. It includes |
| 308 // |inheritable_transform_|, |transform_|, and anchoring adjustments. |
| 309 gfx::Transform screen_space_transform_; |
| 310 |
| 307 // This transform can be used by children to derive position of its parent. | 311 // This transform can be used by children to derive position of its parent. |
| 308 gfx::Transform inheritable_transform_; | 312 gfx::Transform inheritable_transform_; |
| 309 | 313 |
| 310 // A flag usable during transformation calculates to avoid duplicate work. | 314 // A flag usable during transformation calculates to avoid duplicate work. |
| 311 bool dirty_ = false; | 315 bool dirty_ = false; |
| 312 | 316 |
| 313 // An identifier used for testing and debugging, in lieu of a string. | 317 // An identifier used for testing and debugging, in lieu of a string. |
| 314 UiElementDebugId debug_id_ = UiElementDebugId::kNone; | 318 UiElementDebugId debug_id_ = UiElementDebugId::kNone; |
| 315 | 319 |
| 316 gfx::Transform transform_; | |
| 317 | |
| 318 ColorScheme::Mode mode_ = ColorScheme::kModeNormal; | 320 ColorScheme::Mode mode_ = ColorScheme::kModeNormal; |
| 319 | 321 |
| 320 DISALLOW_COPY_AND_ASSIGN(UiElement); | 322 DISALLOW_COPY_AND_ASSIGN(UiElement); |
| 321 }; | 323 }; |
| 322 | 324 |
| 323 } // namespace vr_shell | 325 } // namespace vr_shell |
| 324 | 326 |
| 325 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ | 327 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_UI_ELEMENTS_UI_ELEMENT_H_ |
| OLD | NEW |