Skip to content

Commit

Permalink
[engine] Sync Flutter 3.22.0 source code
Browse files Browse the repository at this point in the history
  • Loading branch information
JSUYA committed Jun 4, 2024
1 parent 39f7d91 commit 04cd74f
Show file tree
Hide file tree
Showing 14 changed files with 167 additions and 54 deletions.
27 changes: 11 additions & 16 deletions flutter/shell/platform/common/accessibility_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void AccessibilityBridge::CommitUpdates() {
}

for (size_t i = results.size(); i > 0; i--) {
for (SemanticsNode node : results[i - 1]) {
for (const SemanticsNode& node : results[i - 1]) {
ConvertFlutterUpdate(node, update);
}
}
Expand Down Expand Up @@ -149,18 +149,6 @@ AccessibilityBridge::GetPendingEvents() const {
return result;
}

void AccessibilityBridge::RecreateNodeDelegates() {
for (const auto& [node_id, old_platform_node_delegate] : id_wrapper_map_) {
std::shared_ptr<FlutterPlatformNodeDelegate> platform_node_delegate =
CreateFlutterPlatformNodeDelegate();
platform_node_delegate->Init(
std::static_pointer_cast<FlutterPlatformNodeDelegate::OwnerBridge>(
shared_from_this()),
old_platform_node_delegate->GetAXNode());
id_wrapper_map_[node_id] = platform_node_delegate;
}
}

void AccessibilityBridge::OnNodeWillBeDeleted(ui::AXTree* tree,
ui::AXNode* node) {}

Expand Down Expand Up @@ -215,7 +203,7 @@ std::optional<ui::AXTreeUpdate>
AccessibilityBridge::CreateRemoveReparentedNodesUpdate() {
std::unordered_map<int32_t, ui::AXNodeData> updates;

for (auto node_update : pending_semantics_node_updates_) {
for (const auto& node_update : pending_semantics_node_updates_) {
for (int32_t child_id : node_update.second.children_in_traversal_order) {
// Skip nodes that don't exist or have a parent in the current tree.
ui::AXNode* child = tree_->GetFromId(child_id);
Expand Down Expand Up @@ -345,7 +333,7 @@ void AccessibilityBridge::SetRoleFromFlutterUpdate(ui::AXNodeData& node_data,
return;
}
if (flags & kFlutterSemanticsFlagHasToggledState) {
node_data.role = ax::mojom::Role::kToggleButton;
node_data.role = ax::mojom::Role::kSwitch;
return;
}
if (flags & kFlutterSemanticsFlagIsSlider) {
Expand All @@ -365,6 +353,13 @@ void AccessibilityBridge::SetStateFromFlutterUpdate(ui::AXNodeData& node_data,
const SemanticsNode& node) {
FlutterSemanticsFlag flags = node.flags;
FlutterSemanticsAction actions = node.actions;
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState &&
flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsExpanded) {
node_data.AddState(ax::mojom::State::kExpanded);
} else if (flags &
FlutterSemanticsFlag::kFlutterSemanticsFlagHasExpandedState) {
node_data.AddState(ax::mojom::State::kCollapsed);
}
if (flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsTextField &&
(flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsReadOnly) == 0) {
node_data.AddState(ax::mojom::State::kEditable);
Expand Down Expand Up @@ -482,7 +477,7 @@ void AccessibilityBridge::SetIntAttributesFromFlutterUpdate(
: flags & FlutterSemanticsFlag::kFlutterSemanticsFlagIsChecked
? ax::mojom::CheckedState::kTrue
: ax::mojom::CheckedState::kFalse));
} else if (node_data.role == ax::mojom::Role::kToggleButton) {
} else if (node_data.role == ax::mojom::Role::kSwitch) {
node_data.AddIntAttribute(
ax::mojom::IntAttribute::kCheckedState,
static_cast<int32_t>(
Expand Down
10 changes: 0 additions & 10 deletions flutter/shell/platform/common/accessibility_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ class AccessibilityBridge
virtual std::shared_ptr<FlutterPlatformNodeDelegate>
CreateFlutterPlatformNodeDelegate() = 0;

//------------------------------------------------------------------------------
/// @brief Recreate all FlutterPlatformNodeDelegates.
///
/// This can be useful for subclasses when updating some
/// properties that are used by node delegates, such as views.
/// Each node is recreated using
/// CreateFlutterPlatformNodeDelegate, then initialized using
/// AXNodes from their corresponding old one.
void RecreateNodeDelegates();

private:
// See FlutterSemanticsNode in embedder.h
typedef struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <iostream>
#include <string>
#include <utility>

#include "binary_messenger.h"
#include "message_codec.h"
Expand Down Expand Up @@ -78,7 +79,8 @@ class BasicMessageChannel {
void Send(const T& message, BinaryReply reply) {
std::unique_ptr<std::vector<uint8_t>> raw_message =
codec_->EncodeMessage(message);
messenger_->Send(name_, raw_message->data(), raw_message->size(), reply);
messenger_->Send(name_, raw_message->data(), raw_message->size(),
std::move(reply));
}

// Registers a handler that should be called any time a message is
Expand All @@ -97,7 +99,7 @@ class BasicMessageChannel {
BinaryMessageHandler binary_handler = [handler, codec, channel_name](
const uint8_t* binary_message,
const size_t binary_message_size,
BinaryReply binary_reply) {
const BinaryReply& binary_reply) {
// Use this channel's codec to decode the message and build a reply
// handler.
std::unique_ptr<T> message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EventChannel {
// Mutable state to track the handler's listening status.
is_listening = bool(false)](const uint8_t* message,
const size_t message_size,
BinaryReply reply) mutable {
const BinaryReply& reply) mutable {
constexpr char kOnListenMethod[] = "listen";
constexpr char kOnCancelMethod[] = "cancel";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <functional>
#include <string>
#include <utility>

#include "method_result.h"

Expand Down Expand Up @@ -36,7 +37,7 @@ class MethodResultFunctions : public MethodResult<T> {
ResultHandlerNotImplemented<T> on_not_implemented)
: on_success_(on_success),
on_error_(on_error),
on_not_implemented_(on_not_implemented) {}
on_not_implemented_(std::move(on_not_implemented)) {}

virtual ~MethodResultFunctions() = default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PluginRegistrar {
void AddPlugin(std::unique_ptr<Plugin> plugin);

protected:
FlutterDesktopPluginRegistrarRef registrar() { return registrar_; }
FlutterDesktopPluginRegistrarRef registrar() const { return registrar_; }

// Destroys all owned plugins. Subclasses should call this at the beginning of
// their destructors to prevent the possibility of an owned plugin trying to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstdint>
#include <functional>
#include <memory>
#include <utility>
#include <variant>

namespace flutter {
Expand All @@ -28,7 +29,7 @@ class PixelBufferTexture {
// take care of proper synchronization. It also needs to be ensured that the
// returned buffer isn't released prior to unregistering this texture.
explicit PixelBufferTexture(CopyBufferCallback copy_buffer_callback)
: copy_buffer_callback_(copy_buffer_callback) {}
: copy_buffer_callback_(std::move(copy_buffer_callback)) {}

// Returns the callback-provided FlutterDesktopPixelBuffer that contains the
// actual pixel data. The intended surface size is specified by |width| and
Expand All @@ -53,7 +54,7 @@ class GpuSurfaceTexture {
GpuSurfaceTexture(FlutterDesktopGpuSurfaceType surface_type,
ObtainDescriptorCallback obtain_descriptor_callback)
: surface_type_(surface_type),
obtain_descriptor_callback_(obtain_descriptor_callback) {}
obtain_descriptor_callback_(std::move(obtain_descriptor_callback)) {}

// Returns the callback-provided FlutterDesktopGpuSurfaceDescriptor that
// contains the surface handle. The intended surface size is specified by
Expand Down
6 changes: 3 additions & 3 deletions flutter/shell/platform/common/incoming_message_dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_CPP_INCOMING_MESSAGE_DISPATCHER_H_
#define FLUTTER_SHELL_PLATFORM_CPP_INCOMING_MESSAGE_DISPATCHER_H_
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_

#include <functional>
#include <map>
Expand Down Expand Up @@ -75,4 +75,4 @@ class IncomingMessageDispatcher {

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_CPP_INCOMING_MESSAGE_DISPATCHER_H_
#endif // FLUTTER_SHELL_PLATFORM_COMMON_INCOMING_MESSAGE_DISPATCHER_H_
6 changes: 3 additions & 3 deletions flutter/shell/platform/common/path_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
#define FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_PATH_UTILS_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_PATH_UTILS_H_

#include <filesystem>

Expand All @@ -15,4 +15,4 @@ std::filesystem::path GetExecutableDirectory();

} // namespace flutter

#endif // FLUTTER_SHELL_PLATFORM_GLFW_PATH_UTILS_H_
#endif // FLUTTER_SHELL_PLATFORM_COMMON_PATH_UTILS_H_
6 changes: 3 additions & 3 deletions flutter/shell/platform/common/platform_provided_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PLATFORM_COMMON_PLATFORM_PROVIDED_MENU_H_
#define PLATFORM_COMMON_PLATFORM_PROVIDED_MENU_H_
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_PLATFORM_PROVIDED_MENU_H_
#define FLUTTER_SHELL_PLATFORM_COMMON_PLATFORM_PROVIDED_MENU_H_

namespace flutter {

Expand Down Expand Up @@ -49,4 +49,4 @@ enum class PlatformProvidedMenu {

} // namespace flutter

#endif // PLATFORM_COMMON_PLATFORM_provided_MENU_H_
#endif // FLUTTER_SHELL_PLATFORM_COMMON_PLATFORM_PROVIDED_MENU_H_
2 changes: 2 additions & 0 deletions flutter/shell/platform/common/public/flutter_messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ FLUTTER_EXPORT bool FlutterDesktopMessengerSend(
const uint8_t* message,
const size_t message_size);

// Sends a binary message to the Flutter side on the specified channel.
// The |reply| callback will be executed when a response is received.
FLUTTER_EXPORT bool FlutterDesktopMessengerSendWithReply(
FlutterDesktopMessengerRef messenger,
const char* channel,
Expand Down
15 changes: 11 additions & 4 deletions flutter/shell/platform/common/text_input_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,22 @@ void TextInputModel::BeginComposing() {
composing_range_ = TextRange(selection_.start());
}

void TextInputModel::UpdateComposingText(const std::u16string& text) {
void TextInputModel::UpdateComposingText(const std::u16string& text,
const TextRange& selection) {
// Preserve selection if we get a no-op update to the composing region.
if (text.length() == 0 && composing_range_.collapsed()) {
return;
}
DeleteSelected();
text_.replace(composing_range_.start(), composing_range_.length(), text);
const TextRange& rangeToDelete =
composing_range_.collapsed() ? selection_ : composing_range_;
text_.replace(rangeToDelete.start(), rangeToDelete.length(), text);
composing_range_.set_end(composing_range_.start() + text.length());
selection_ = TextRange(composing_range_.end());
selection_ = TextRange(selection.start() + composing_range_.start(),
selection.extent() + composing_range_.start());
}

void TextInputModel::UpdateComposingText(const std::u16string& text) {
UpdateComposingText(text, TextRange(text.length()));
}

void TextInputModel::UpdateComposingText(const std::string& text) {
Expand Down
15 changes: 10 additions & 5 deletions flutter/shell/platform/common/text_input_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ class TextInputModel {
// are restricted to the composing range.
void BeginComposing();

// Replaces the composing range with new UTF-16 text.
// Replaces the composing range with new UTF-16 text, and sets the selection.
//
// If a selection of non-zero length exists, it is deleted if the composing
// text is non-empty. The composing range is adjusted to the length of
// |text| and the selection base and offset are set to the end of the
// composing range.
// The given |text| replaces text within the current composing range, or the
// current selection if the text wasn't composing. The composing range is
// adjusted to the length of |text|, and the |selection| describes the new
// selection range, relative to the start of the new composing range.
void UpdateComposingText(const std::u16string& text,
const TextRange& selection);

// Replaces the composing range with new UTF-16 text and sets the selection to
// the end of the composing text.
void UpdateComposingText(const std::u16string& text);

// Replaces the composing range with new UTF-8 text.
Expand Down
Loading

0 comments on commit 04cd74f

Please sign in to comment.