Flutter Engine
The Flutter Engine
focus_delegate.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_SHELL_PLATFORM_FUCHSIA_FLUTTER_FOCUS_DELEGATE_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FOCUS_DELEGATE_H_
7
8#include <fuchsia/ui/views/cpp/fidl.h>
9
10#include <unordered_map>
11
12#include "flutter/fml/macros.h"
13#include "flutter/lib/ui/window/platform_message.h"
14#include "third_party/rapidjson/include/rapidjson/document.h"
15
16namespace flutter_runner {
17
19 public:
20 FocusDelegate(fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
21 fuchsia::ui::views::FocuserHandle focuser)
22 : view_ref_focused_(view_ref_focused.Bind()), focuser_(focuser.Bind()) {}
23
24 /// Continuously watches the host viewRef for focus events, invoking a
25 /// callback each time.
26 ///
27 /// The callback is invoked on each Watch() call, which consumes the callback
28 /// argument. Hence, the callback argument must be copyable, so that a copy
29 /// can be freely moved into the Watch() call.
30 ///
31 /// This method can only be called once.
32 void WatchLoop(std::function<void(bool)> callback);
33
34 /// Handles the following focus-related platform message requests:
35 /// View.focus.getCurrent
36 /// - Completes with the FocusDelegate's most recent focus state, either
37 /// [true] or [false].
38 /// View.focus.getNext
39 /// - Completes with the FocusDelegate's next focus state, either [true] or
40 /// [false].
41 /// - Only one outstanding request may exist at a time. Any others will be
42 /// completed with [null].
43 /// View.focus.request
44 /// - Attempts to give focus for a given viewRef. Completes with [0] on
45 /// success, or [fuchsia::ui::views::Error] on failure.
46 ///
47 /// Returns false if a malformed/invalid request needs to be completed empty.
49 rapidjson::Value request,
51
52 void OnChildViewViewRef(uint64_t view_id,
53 fuchsia::ui::views::ViewRef view_ref);
54
55 void OnDisposeChildView(uint64_t view_id);
56
57 private:
58 fuchsia::ui::views::ViewRefFocusedPtr view_ref_focused_;
59 fuchsia::ui::views::FocuserPtr focuser_;
60
61 std::unordered_map<uint64_t /*fuchsia::ui::composition::ContentId*/,
62 fuchsia::ui::views::ViewRef>
63 child_view_view_refs_;
64
65 std::function<void(fuchsia::ui::views::FocusState)> watch_loop_;
66 bool is_focused_ = false;
68
70 std::string value);
71
72 /// Completes a platform message request by attempting to give focus for a
73 /// given view.
74 bool RequestFocusById(uint64_t view_id,
76 bool RequestFocusByViewRef(
77 fuchsia::ui::views::ViewRef view_ref,
79
80 FML_DISALLOW_COPY_AND_ASSIGN(FocusDelegate);
81};
82
83} // namespace flutter_runner
84#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_FOCUS_DELEGATE_H_
FocusDelegate(fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused, fuchsia::ui::views::FocuserHandle focuser)
bool HandlePlatformMessage(rapidjson::Value request, fml::RefPtr< flutter::PlatformMessageResponse > response)
void OnChildViewViewRef(uint64_t view_id, fuchsia::ui::views::ViewRef view_ref)
void WatchLoop(std::function< void(bool)> callback)
void OnDisposeChildView(uint64_t view_id)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint8_t value
Dart_NativeFunction function
Definition: fuchsia.cc:51
static bool Bind(PassBindingsCacheMTL &pass, ShaderStage stage, size_t bind_index, const BufferView &view)