Flutter Engine
view_holder.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef FLUTTER_FLOW_VIEW_HOLDER_H_
6 #define FLUTTER_FLOW_VIEW_HOLDER_H_
7 
8 #include <fuchsia/ui/gfx/cpp/fidl.h>
9 #include <fuchsia/ui/views/cpp/fidl.h>
10 #include <lib/ui/scenic/cpp/id.h>
11 #include <lib/ui/scenic/cpp/resources.h>
12 #include <lib/ui/scenic/cpp/session.h>
13 #include <zircon/types.h>
14 
15 #include <memory>
16 
17 #include "flutter/fml/macros.h"
18 #include "flutter/fml/memory/ref_counted.h"
19 #include "flutter/fml/task_runner.h"
20 #include "third_party/skia/include/core/SkColor.h"
21 #include "third_party/skia/include/core/SkPoint.h"
22 #include "third_party/skia/include/core/SkSize.h"
23 
24 namespace flutter {
25 
26 // Represents a Scenic |ViewHolder| resource that imports a |View| from another
27 // session.
28 //
29 // This object is created and destroyed on the |Rasterizer|'s thread.
30 class ViewHolder {
31  public:
32  using BindCallback = std::function<void(scenic::ResourceId)>;
33 
34  static void Create(zx_koid_t id,
35  fml::RefPtr<fml::TaskRunner> ui_task_runner,
36  fuchsia::ui::views::ViewHolderToken view_holder_token,
37  const BindCallback& on_bind_callback);
38  static void Destroy(zx_koid_t id);
39  static ViewHolder* FromId(zx_koid_t id);
40 
42  fuchsia::ui::views::ViewHolderToken view_holder_token,
43  const BindCallback& on_bind_callback);
44  ~ViewHolder() = default;
45 
46  // Sets the properties/opacity of the child view by issuing a Scenic command.
47  void SetProperties(double width,
48  double height,
49  double insetTop,
50  double insetRight,
51  double insetBottom,
52  double insetLeft,
53  bool focusable);
54 
55  // Creates or updates the contained ViewHolder resource using the specified
56  // |SceneUpdateContext|.
57  void UpdateScene(scenic::Session* session,
58  scenic::ContainerNode& container_node,
59  const SkPoint& offset,
60  const SkSize& size,
61  SkAlpha opacity,
62  bool hit_testable);
63 
64  bool hit_testable() { return hit_testable_; }
65  void set_hit_testable(bool value) { hit_testable_ = value; }
66 
67  bool focusable() { return focusable_; }
68  void set_focusable(bool value) { focusable_ = value; }
69 
70  private:
71  fml::RefPtr<fml::TaskRunner> ui_task_runner_;
72 
73  std::unique_ptr<scenic::EntityNode> entity_node_;
74  std::unique_ptr<scenic::OpacityNodeHACK> opacity_node_;
75  std::unique_ptr<scenic::ViewHolder> view_holder_;
76 
77  fuchsia::ui::views::ViewHolderToken pending_view_holder_token_;
78  BindCallback pending_bind_callback_;
79 
80  bool hit_testable_ = true;
81  bool focusable_ = true;
82 
83  fuchsia::ui::gfx::ViewProperties pending_properties_;
84  bool has_pending_properties_ = false;
85 
86  FML_DISALLOW_COPY_AND_ASSIGN(ViewHolder);
87 };
88 
89 } // namespace flutter
90 
91 #endif // FLUTTER_FLOW_VIEW_HOLDER_H_
void UpdateScene(scenic::Session *session, scenic::ContainerNode &container_node, const SkPoint &offset, const SkSize &size, SkAlpha opacity, bool hit_testable)
Definition: view_holder.cc:103
void SetProperties(double width, double height, double insetTop, double insetRight, double insetBottom, double insetLeft, bool focusable)
Definition: view_holder.cc:145
std::function< void(scenic::ResourceId)> BindCallback
Definition: view_holder.h:32
constexpr std::size_t size(T(&array)[N])
Definition: size.h:13
uint8_t value
void set_focusable(bool value)
Definition: view_holder.h:68
int32_t height
int32_t width
static void Destroy(zx_koid_t id)
Definition: view_holder.cc:73
static void Create(zx_koid_t id, fml::RefPtr< fml::TaskRunner > ui_task_runner, fuchsia::ui::views::ViewHolderToken view_holder_token, const BindCallback &on_bind_callback)
Definition: view_holder.cc:53
static ViewHolder * FromId(zx_koid_t id)
Definition: view_holder.cc:80
ViewHolder(fml::RefPtr< fml::TaskRunner > ui_task_runner, fuchsia::ui::views::ViewHolderToken view_holder_token, const BindCallback &on_bind_callback)
Definition: view_holder.cc:94
void set_hit_testable(bool value)
Definition: view_holder.h:65