Flutter Engine
flutter::ViewHolder Class Reference

#include <view_holder.h>

Public Types

using BindCallback = std::function< void(scenic::ResourceId)>
 

Public Member Functions

 ViewHolder (fml::RefPtr< fml::TaskRunner > ui_task_runner, fuchsia::ui::views::ViewHolderToken view_holder_token, const BindCallback &on_bind_callback)
 
 ~ViewHolder ()=default
 
void SetProperties (double width, double height, double insetTop, double insetRight, double insetBottom, double insetLeft, bool focusable)
 
void UpdateScene (scenic::Session *session, scenic::ContainerNode &container_node, const SkPoint &offset, const SkSize &size, SkAlpha opacity, bool hit_testable)
 
bool hit_testable ()
 
void set_hit_testable (bool value)
 
bool focusable ()
 
void set_focusable (bool value)
 

Static Public Member Functions

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)
 
static void Destroy (zx_koid_t id)
 
static ViewHolderFromId (zx_koid_t id)
 

Detailed Description

Definition at line 30 of file view_holder.h.

Member Typedef Documentation

◆ BindCallback

using flutter::ViewHolder::BindCallback = std::function<void(scenic::ResourceId)>

Definition at line 32 of file view_holder.h.

Constructor & Destructor Documentation

◆ ViewHolder()

flutter::ViewHolder::ViewHolder ( fml::RefPtr< fml::TaskRunner ui_task_runner,
fuchsia::ui::views::ViewHolderToken  view_holder_token,
const BindCallback on_bind_callback 
)

Definition at line 94 of file view_holder.cc.

References FML_DCHECK.

97  : ui_task_runner_(std::move(ui_task_runner)),
98  pending_view_holder_token_(std::move(view_holder_token)),
99  pending_bind_callback_(on_bind_callback) {
100  FML_DCHECK(pending_view_holder_token_.value);
101 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ ~ViewHolder()

flutter::ViewHolder::~ViewHolder ( )
default

Member Function Documentation

◆ Create()

void flutter::ViewHolder::Create ( zx_koid_t  id,
fml::RefPtr< fml::TaskRunner ui_task_runner,
fuchsia::ui::views::ViewHolderToken  view_holder_token,
const BindCallback on_bind_callback 
)
static

Definition at line 53 of file view_holder.cc.

References FML_DCHECK.

Referenced by flutter::SceneUpdateContext::CreateView(), flutter::SceneHost::OnViewStateChanged(), and flutter::testing::TEST_F().

56  {
57  // This raster thread contains at least 1 ViewHolder. Initialize the
58  // per-thread bindings.
59  if (tls_view_holder_bindings.get() == nullptr) {
60  tls_view_holder_bindings.reset(new ViewHolderBindings());
61  }
62 
63  auto* bindings = tls_view_holder_bindings.get();
64  FML_DCHECK(bindings);
65  FML_DCHECK(bindings->find(id) == bindings->end());
66 
67  auto view_holder = std::make_unique<ViewHolder>(std::move(ui_task_runner),
68  std::move(view_holder_token),
69  on_bind_callback);
70  bindings->emplace(id, std::move(view_holder));
71 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ Destroy()

void flutter::ViewHolder::Destroy ( zx_koid_t  id)
static

Definition at line 73 of file view_holder.cc.

References FML_DCHECK.

Referenced by flutter::SceneUpdateContext::DestroyView(), flutter::testing::AutoDestroyChildLayerId::~AutoDestroyChildLayerId(), and flutter::SceneHost::~SceneHost().

73  {
74  auto* bindings = tls_view_holder_bindings.get();
75  FML_DCHECK(bindings);
76 
77  bindings->erase(id);
78 }
#define FML_DCHECK(condition)
Definition: logging.h:86

◆ focusable()

bool flutter::ViewHolder::focusable ( )
inline

Definition at line 67 of file view_holder.h.

67 { return focusable_; }

◆ FromId()

ViewHolder * flutter::ViewHolder::FromId ( zx_koid_t  id)
static

Definition at line 80 of file view_holder.cc.

Referenced by flutter::SceneUpdateContext::CreateView(), flutter::SceneHost::setProperties(), and flutter::SceneUpdateContext::UpdateView().

80  {
81  auto* bindings = tls_view_holder_bindings.get();
82  if (!bindings) {
83  return nullptr;
84  }
85 
86  auto binding = bindings->find(id);
87  if (binding == bindings->end()) {
88  return nullptr;
89  }
90 
91  return binding->second.get();
92 }

◆ hit_testable()

bool flutter::ViewHolder::hit_testable ( )
inline

Definition at line 64 of file view_holder.h.

64 { return hit_testable_; }

◆ set_focusable()

void flutter::ViewHolder::set_focusable ( bool  value)
inline

Definition at line 68 of file view_holder.h.

References value.

68 { focusable_ = value; }
uint8_t value

◆ set_hit_testable()

void flutter::ViewHolder::set_hit_testable ( bool  value)
inline

Definition at line 65 of file view_holder.h.

References value.

65 { hit_testable_ = value; }
uint8_t value

◆ SetProperties()

void flutter::ViewHolder::SetProperties ( double  width,
double  height,
double  insetTop,
double  insetRight,
double  insetBottom,
double  insetLeft,
bool  focusable 
)

Definition at line 145 of file view_holder.cc.

151  {
152  pending_properties_ = ToViewProperties(width, height, insetTop, insetRight,
153  insetBottom, insetLeft, focusable);
154  has_pending_properties_ = true;
155 }
int32_t height
int32_t width

◆ UpdateScene()

void flutter::ViewHolder::UpdateScene ( scenic::Session *  session,
scenic::ContainerNode &  container_node,
const SkPoint &  offset,
const SkSize &  size,
SkAlpha  opacity,
bool  hit_testable 
)

Definition at line 103 of file view_holder.cc.

References FML_DCHECK, and fml::TaskRunner::PostTask().

108  {
109  if (pending_view_holder_token_.value) {
110  entity_node_ = std::make_unique<scenic::EntityNode>(session);
111  opacity_node_ = std::make_unique<scenic::OpacityNodeHACK>(session);
112  view_holder_ = std::make_unique<scenic::ViewHolder>(
113  session, std::move(pending_view_holder_token_), "Flutter SceneHost");
114  opacity_node_->AddChild(*entity_node_);
115  opacity_node_->SetLabel("flutter::ViewHolder");
116  entity_node_->Attach(*view_holder_);
117  if (ui_task_runner_ && pending_view_holder_token_.value) {
118  ui_task_runner_->PostTask(
119  [bind_callback = std::move(pending_bind_callback_),
120  view_holder_id = view_holder_->id()]() {
121  bind_callback(view_holder_id);
122  });
123  }
124  }
125  FML_DCHECK(entity_node_);
126  FML_DCHECK(opacity_node_);
127  FML_DCHECK(view_holder_);
128 
129  container_node.AddChild(*opacity_node_);
130  opacity_node_->SetOpacity(opacity / 255.0f);
131  entity_node_->SetTranslation(offset.x(), offset.y(), -0.1f);
132  entity_node_->SetHitTestBehavior(
133  hit_testable ? fuchsia::ui::gfx::HitTestBehavior::kDefault
134  : fuchsia::ui::gfx::HitTestBehavior::kSuppress);
135  if (has_pending_properties_) {
136  // TODO(dworsham): This should be derived from size and elevation. We
137  // should be able to Z-limit the view's box but otherwise it uses all of the
138  // available airspace.
139  view_holder_->SetViewProperties(std::move(pending_properties_));
140 
141  has_pending_properties_ = false;
142  }
143 }
#define FML_DCHECK(condition)
Definition: logging.h:86
virtual void PostTask(const fml::closure &task)
Definition: task_runner.cc:24

The documentation for this class was generated from the following files: