window.h 2.5 KB
Newer Older
1 2 3 4
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5 6
#ifndef FLUTTER_LIB_UI_WINDOW_WINDOW_H_
#define FLUTTER_LIB_UI_WINDOW_WINDOW_H_
7

A
Adam Barth 已提交
8 9
#include <unordered_map>

10
#include "flutter/lib/ui/semantics/semantics_update.h"
11
#include "flutter/lib/ui/window/platform_message.h"
12
#include "flutter/lib/ui/window/pointer_data_packet.h"
13
#include "flutter/lib/ui/window/viewport_metrics.h"
14
#include "lib/fxl/time/time_point.h"
15
#include "lib/tonic/dart_persistent_value.h"
16
#include "third_party/skia/include/gpu/GrContext.h"
17

18 19 20 21
namespace tonic {
class DartLibraryNatives;
}  // namespace tonic

22 23 24
namespace blink {
class Scene;

25 26
Dart_Handle ToByteData(const std::vector<uint8_t>& buffer);

27 28
class WindowClient {
 public:
29
  virtual std::string DefaultRouteName() = 0;
30 31
  virtual void ScheduleFrame() = 0;
  virtual void Render(Scene* scene) = 0;
32
  virtual void UpdateSemantics(SemanticsUpdate* update) = 0;
33
  virtual void HandlePlatformMessage(fxl::RefPtr<PlatformMessage> message) = 0;
34 35 36 37 38

 protected:
  virtual ~WindowClient();
};

39
class Window final {
40 41
 public:
  explicit Window(WindowClient* client);
42

43 44 45
  ~Window();

  WindowClient* client() const { return client_; }
46

47
  const ViewportMetrics& viewport_metrics() { return viewport_metrics_; }
48 49

  void DidCreateIsolate();
50
  void UpdateWindowMetrics(const ViewportMetrics& metrics);
51 52
  void UpdateLocale(const std::string& language_code,
                    const std::string& country_code);
53
  void UpdateUserSettingsData(const std::string& data);
54
  void UpdateSemanticsEnabled(bool enabled);
55
  void DispatchPlatformMessage(fxl::RefPtr<PlatformMessage> message);
56
  void DispatchPointerDataPacket(const PointerDataPacket& packet);
57 58 59
  void DispatchSemanticsAction(int32_t id,
                               SemanticsAction action,
                               std::vector<uint8_t> args);
60
  void BeginFrame(fxl::TimePoint frameTime);
61

62 63
  void CompletePlatformMessageResponse(int response_id,
                                       std::vector<uint8_t> data);
64
  void CompletePlatformMessageEmptyResponse(int response_id);
A
Adam Barth 已提交
65

66
  static void RegisterNatives(tonic::DartLibraryNatives* natives);
67 68 69

 private:
  WindowClient* client_;
70
  tonic::DartPersistentValue library_;
71
  ViewportMetrics viewport_metrics_;
A
Adam Barth 已提交
72 73 74

  // We use id 0 to mean that no response is expected.
  int next_response_id_ = 1;
75
  std::unordered_map<int, fxl::RefPtr<blink::PlatformMessageResponse>>
A
Adam Barth 已提交
76
      pending_responses_;
77 78 79 80
};

}  // namespace blink

81
#endif  // FLUTTER_LIB_UI_WINDOW_WINDOW_H_