view_holder.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_FLOW_VIEW_HOLDER_H_
#define FLUTTER_FLOW_VIEW_HOLDER_H_

#include <fuchsia/ui/gfx/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/ui/scenic/cpp/id.h>
#include <lib/ui/scenic/cpp/resources.h>
12
#include <lib/ui/scenic/cpp/session.h>
13 14 15 16 17 18 19
#include <zircon/types.h>

#include <memory>

#include "flutter/fml/macros.h"
#include "flutter/fml/memory/ref_counted.h"
#include "flutter/fml/task_runner.h"
20 21 22
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPoint.h"
#include "third_party/skia/include/core/SkSize.h"
23

24
namespace flutter {
25 26 27 28 29 30 31

// Represents a Scenic |ViewHolder| resource that imports a |View| from another
// session.
//
// This object is created and destroyed on the |Rasterizer|'s thread.
class ViewHolder {
 public:
32 33 34 35 36 37 38 39
  using ViewIdCallback = std::function<void(scenic::ResourceId)>;

  // `Create`, `Destroy`, and `FromId` must be executed on the raster thread or
  // errors will occur.
  //
  // `on_bind_callback` and `on_unbind_callback` will likewise execute on the
  // raster thread; clients are responsible for re-threading the callback if
  // needed.
40
  static void Create(zx_koid_t id,
41 42 43
                     ViewIdCallback on_view_created,
                     fuchsia::ui::views::ViewHolderToken view_holder_token);
  static void Destroy(zx_koid_t id, ViewIdCallback on_view_destroyed);
44 45
  static ViewHolder* FromId(zx_koid_t id);

46 47 48
  ~ViewHolder() = default;

  // Sets the properties/opacity of the child view by issuing a Scenic command.
49 50 51 52 53 54 55 56 57 58
  void SetProperties(double width,
                     double height,
                     double insetTop,
                     double insetRight,
                     double insetBottom,
                     double insetLeft,
                     bool focusable);

  // Creates or updates the contained ViewHolder resource using the specified
  // |SceneUpdateContext|.
59 60
  void UpdateScene(scenic::Session* session,
                   scenic::ContainerNode& container_node,
61 62
                   const SkPoint& offset,
                   const SkSize& size,
63
                   SkAlpha opacity,
64 65
                   bool hit_testable);

66 67 68 69 70 71
  bool hit_testable() { return hit_testable_; }
  void set_hit_testable(bool value) { hit_testable_ = value; }

  bool focusable() { return focusable_; }
  void set_focusable(bool value) { focusable_ = value; }

72
 private:
73 74
  ViewHolder(fuchsia::ui::views::ViewHolderToken view_holder_token,
             ViewIdCallback on_view_created);
75

76
  std::unique_ptr<scenic::EntityNode> entity_node_;
77
  std::unique_ptr<scenic::OpacityNodeHACK> opacity_node_;
78
  std::unique_ptr<scenic::ViewHolder> view_holder_;
79 80 81

  fuchsia::ui::views::ViewHolderToken pending_view_holder_token_;

82 83 84
  bool hit_testable_ = true;
  bool focusable_ = true;

85 86
  ViewIdCallback on_view_created_;

87
  fuchsia::ui::gfx::ViewProperties pending_properties_;
88 89 90 91 92
  bool has_pending_properties_ = false;

  FML_DISALLOW_COPY_AND_ASSIGN(ViewHolder);
};

93
}  // namespace flutter
94 95

#endif  // FLUTTER_FLOW_VIEW_HOLDER_H_