Skip to content

Commit

Permalink
feat(dom): remove dom value
Browse files Browse the repository at this point in the history
  • Loading branch information
ilikethese authored and hippy-actions[bot] committed Aug 29, 2023
1 parent 638ed17 commit 59fb750
Show file tree
Hide file tree
Showing 36 changed files with 443 additions and 443 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DevToolsUtil {
static void AppendDomKeyValue(std::string& node_str,
bool& first_object,
const std::string& node_key,
const HippyValue& dom_value);
const HippyValue& hippy_value);
static LayoutResult GetLayoutOnScreen(const std::shared_ptr<DomNode>& root_node, const std::shared_ptr<DomNode>& dom_node);
};
} // namespace hippy::devtools
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ void HippyScreenAdapter::RemovePostFrameCallback(uint64_t id) {
}

hippy::dom::DomArgument HippyScreenAdapter::makeFrameCallbackArgument(uint64_t id) const {
footstone::value::HippyValue::HippyValueObjectType dom_value_object;
dom_value_object[kFrameCallbackId] = footstone::value::HippyValue(static_cast<int32_t>(id));
footstone::value::HippyValue::DomValueArrayType dom_value_array;
dom_value_array.push_back(footstone::value::HippyValue(dom_value_object));
footstone::value::HippyValue argument_dom_value(dom_value_array);
hippy::dom::DomArgument argument(argument_dom_value);
footstone::value::HippyValue::HippyValueObjectType hippy_value_object;
hippy_value_object[kFrameCallbackId] = footstone::value::HippyValue(static_cast<int32_t>(id));
footstone::value::HippyValue::HippyValueArrayType hippy_value_array;
hippy_value_array.push_back(footstone::value::HippyValue(hippy_value_object));
footstone::value::HippyValue argument_hippy_value(hippy_value_array);
hippy::dom::DomArgument argument(argument_hippy_value);
return argument;
}

Expand All @@ -97,36 +97,36 @@ void HippyScreenAdapter::GetScreenShot(const hippy::devtools::ScreenRequest& req
hippy::dom::DomArgument argument = makeScreenRequestArgument(request);
auto screen_shot_callback = [WEAK_THIS, callback](std::shared_ptr<hippy::dom::DomArgument> arg) {
DEFINE_AND_CHECK_SELF(HippyScreenAdapter)
footstone::value::HippyValue result_dom_value;
arg->ToObject(result_dom_value);
footstone::value::HippyValue::HippyValueObjectType base64_dom_value;
if (result_dom_value.IsArray() && !result_dom_value.ToArrayChecked().empty()) {
base64_dom_value = result_dom_value.ToArrayChecked()[0].ToObjectChecked();
} else if (result_dom_value.IsObject()) {
base64_dom_value = result_dom_value.ToObjectChecked();
footstone::value::HippyValue result_hippy_value;
arg->ToObject(result_hippy_value);
footstone::value::HippyValue::HippyValueObjectType base64_hippy_value;
if (result_hippy_value.IsArray() && !result_hippy_value.ToArrayChecked().empty()) {
base64_hippy_value = result_hippy_value.ToArrayChecked()[0].ToObjectChecked();
} else if (result_hippy_value.IsObject()) {
base64_hippy_value = result_hippy_value.ToObjectChecked();
} else {
// don't have screenshot
return;
}
std::string base64_str = base64_dom_value.find(kScreenShot)->second.ToStringChecked();
int32_t width = base64_dom_value.find(kScreenWidth)->second.ToInt32Checked();
int32_t height = base64_dom_value.find(kScreenHeight)->second.ToInt32Checked();
self->screen_scale_ = base64_dom_value.find(kScreenScale)->second.ToDoubleChecked();
std::string base64_str = base64_hippy_value.find(kScreenShot)->second.ToStringChecked();
int32_t width = base64_hippy_value.find(kScreenWidth)->second.ToInt32Checked();
int32_t height = base64_hippy_value.find(kScreenHeight)->second.ToInt32Checked();
self->screen_scale_ = base64_hippy_value.find(kScreenScale)->second.ToDoubleChecked();
callback(base64_str, width, height);
};
children[0]->CallFunction(kGetScreenShot, argument, screen_shot_callback);
}
}

hippy::dom::DomArgument HippyScreenAdapter::makeScreenRequestArgument(const ScreenRequest& request) const {
footstone::value::HippyValue::HippyValueObjectType dom_value_object;
dom_value_object[kRequestMaxWidth] = footstone::value::HippyValue(request.req_width);
dom_value_object[kRequestMaxHeight] = footstone::value::HippyValue(request.req_height);
dom_value_object[kQuality] = footstone::value::HippyValue(request.quality);
footstone::value::HippyValue::DomValueArrayType dom_value_array;
dom_value_array.push_back(footstone::value::HippyValue(dom_value_object));
footstone::value::HippyValue argument_dom_value(dom_value_array);
hippy::dom::DomArgument argument(argument_dom_value);
footstone::value::HippyValue::HippyValueObjectType hippy_value_object;
hippy_value_object[kRequestMaxWidth] = footstone::value::HippyValue(request.req_width);
hippy_value_object[kRequestMaxHeight] = footstone::value::HippyValue(request.req_height);
hippy_value_object[kQuality] = footstone::value::HippyValue(request.quality);
footstone::value::HippyValue::HippyValueArrayType hippy_value_array;
hippy_value_array.push_back(footstone::value::HippyValue(hippy_value_object));
footstone::value::HippyValue argument_hippy_value(hippy_value_array);
hippy::dom::DomArgument argument(argument_hippy_value);
return argument;
}
} // namespace hippy::devtools
60 changes: 30 additions & 30 deletions devtools/devtools-integration/native/src/devtools_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -181,22 +181,22 @@ LayoutResult DevToolsUtil::GetLayoutOnScreen(const std::shared_ptr<DomNode>& roo
if (!find_node) {
return layout_result;
}
footstone::value::HippyValue::HippyValueObjectType dom_value_object;
dom_value_object["id"] = footstone::value::HippyValue(1);
footstone::value::HippyValue::DomValueArrayType dom_value_array;
dom_value_array.push_back(footstone::value::HippyValue(dom_value_object));
footstone::value::HippyValue argument_dom_value(dom_value_array);
hippy::dom::DomArgument argument(argument_dom_value);
footstone::value::HippyValue::HippyValueObjectType hippy_value_object;
hippy_value_object["id"] = footstone::value::HippyValue(1);
footstone::value::HippyValue::HippyValueArrayType hippy_value_array;
hippy_value_array.push_back(footstone::value::HippyValue(hippy_value_object));
footstone::value::HippyValue argument_hippy_value(hippy_value_array);
hippy::dom::DomArgument argument(argument_hippy_value);
auto screen_shot_callback =
MakeCopyable([promise = std::move(layout_promise)](std::shared_ptr<hippy::dom::DomArgument> arg) mutable {
footstone::value::HippyValue result_dom_value;
arg->ToObject(result_dom_value);
footstone::value::HippyValue result_hippy_value;
arg->ToObject(result_hippy_value);
footstone::value::HippyValue::HippyValueObjectType result_dom_object;
LayoutResult result;
if (result_dom_value.IsArray() && !result_dom_value.ToArrayChecked().empty()) {
result_dom_object = result_dom_value.ToArrayChecked()[0].ToObjectChecked();
} else if (result_dom_value.IsObject()) {
result_dom_object = result_dom_value.ToObjectChecked();
if (result_hippy_value.IsArray() && !result_hippy_value.ToArrayChecked().empty()) {
result_dom_object = result_hippy_value.ToArrayChecked()[0].ToObjectChecked();
} else if (result_hippy_value.IsObject()) {
result_dom_object = result_hippy_value.ToObjectChecked();
} else {
// maybe flat ui optimization and remove it
promise.set_value(result);
Expand All @@ -218,14 +218,14 @@ LayoutResult DevToolsUtil::GetLayoutOnScreen(const std::shared_ptr<DomNode>& roo
return layout_result;
}

std::string DevToolsUtil::ParseDomValue(const HippyValue& dom_value) {
if (!dom_value.IsObject()) {
std::string DevToolsUtil::ParseDomValue(const HippyValue& hippy_value) {
if (!hippy_value.IsObject()) {
FOOTSTONE_DLOG(INFO) << kDevToolsTag << "ParseTotalProps, node props is not object";
return "{}";
}
std::string node_str = "{";
bool first_object = true;
for (auto iterator : dom_value.ToObjectChecked()) {
for (auto iterator : hippy_value.ToObjectChecked()) {
if (iterator.first == "uri" || iterator.first == "src") {
iterator.second = "";
}
Expand Down Expand Up @@ -347,40 +347,40 @@ std::string DevToolsUtil::ParseNodeProps(const std::unordered_map<std::string, H
void DevToolsUtil::AppendDomKeyValue(std::string& node_str,
bool& first_object,
const std::string& node_key,
const HippyValue& dom_value) {
if (dom_value.IsBoolean()) {
const HippyValue& hippy_value) {
if (hippy_value.IsBoolean()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":";
node_str += dom_value.ToBooleanChecked() ? "true" : "false";
node_str += hippy_value.ToBooleanChecked() ? "true" : "false";
first_object = false;
} else if (dom_value.IsInt32()) {
} else if (hippy_value.IsInt32()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":";
node_str += std::to_string(dom_value.ToInt32Checked());
node_str += std::to_string(hippy_value.ToInt32Checked());
first_object = false;
} else if (dom_value.IsUInt32()) {
} else if (hippy_value.IsUInt32()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":";
node_str += std::to_string(dom_value.IsUInt32());
node_str += std::to_string(hippy_value.IsUInt32());
first_object = false;
} else if (dom_value.IsDouble()) {
} else if (hippy_value.IsDouble()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":";
node_str += std::to_string(dom_value.ToDoubleChecked());
node_str += std::to_string(hippy_value.ToDoubleChecked());
first_object = false;
} else if (dom_value.IsString()) {
} else if (hippy_value.IsString()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":\"";
node_str += dom_value.ToStringChecked();
node_str += hippy_value.ToStringChecked();
node_str += "\"";
first_object = false;
} else if (dom_value.IsArray()) {
auto props_array = dom_value.ToArrayChecked();
} else if (hippy_value.IsArray()) {
auto props_array = hippy_value.ToArrayChecked();
std::string array = "[";
for (auto it = props_array.begin(); it != props_array.end(); ++it) {
if (it->IsNull() || it->IsUndefined()) {
Expand All @@ -397,11 +397,11 @@ void DevToolsUtil::AppendDomKeyValue(std::string& node_str,
node_str += "\":";
node_str += array;
first_object = false;
} else if (dom_value.IsObject()) {
} else if (hippy_value.IsObject()) {
node_str += first_object ? "\"" : ",\"";
node_str += node_key;
node_str += "\":";
node_str += ParseDomValue(dom_value);
node_str += ParseDomValue(hippy_value);
first_object = false;
}
}
Expand Down
10 changes: 5 additions & 5 deletions dom/include/dom/dom_argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class DomArgument {
DomArgument(){}
DomArgument(const DomArgument& source);

DomArgument(const footstone::value::HippyValue& dom_value)
: data_(std::make_any<footstone::value::HippyValue>(dom_value)), argument_type_(ArgumentType::OBJECT){}
DomArgument(const footstone::value::HippyValue& hippy_value)
: data_(std::make_any<footstone::value::HippyValue>(hippy_value)), argument_type_(ArgumentType::OBJECT){}
DomArgument(const std::vector<uint8_t>& bson_value)
: data_(std::make_any<std::vector<uint8_t>>(bson_value)), argument_type_(ArgumentType::BSON){}
DomArgument(const std::pair<uint8_t*, size_t>& bson_value)
Expand All @@ -52,12 +52,12 @@ class DomArgument {
DomArgument& operator=(const DomArgument& rhs) noexcept = default;

bool ToBson(std::vector<uint8_t>& bson) const;
bool ToObject(footstone::value::HippyValue& dom_value) const;
bool ToObject(footstone::value::HippyValue& hippy_value) const;

private:
static bool ConvertObjectToBson(const footstone::value::HippyValue& dom_value, std::vector<uint8_t>& bson) ;
static bool ConvertObjectToBson(const footstone::value::HippyValue& hippy_value, std::vector<uint8_t>& bson) ;

static bool ConvertBsonToObject(const std::vector<const uint8_t>& bson, footstone::value::HippyValue& dom_value) ;
static bool ConvertBsonToObject(const std::vector<const uint8_t>& bson, footstone::value::HippyValue& hippy_value) ;

std::any data_;
ArgumentType argument_type_;
Expand Down
2 changes: 1 addition & 1 deletion dom/include/dom/dom_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ class DomNode : public std::enable_shared_from_this<DomNode> {
void UpdateObjectStyle(HippyValue& style_map, const HippyValue& update_style);
bool ReplaceStyle(HippyValue& object, const std::string& key, const HippyValue& value);

friend std::ostream& operator<<(std::ostream& os, const DomNode& dom_value);
friend std::ostream& operator<<(std::ostream& os, const DomNode& hippy_value);

private:
uint32_t id_{}; // node id
Expand Down
20 changes: 10 additions & 10 deletions dom/include/dom/yoga_layout_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,19 @@ class YogaLayoutNode : public LayoutNode, public std::enable_shared_from_this<Yo
void Parser(const std::unordered_map<std::string, std::shared_ptr<footstone::value::HippyValue>>& style_update,
const std::vector<std::string>& style_delete);

void SetYGWidth(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGWidth(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGHeight(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGHeight(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetDirection(YGDirection direction);

void SetYGMaxWidth(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGMaxWidth(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGMaxHeight(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGMaxHeight(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGMinWidth(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGMinWidth(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGMinHeight(std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGMinHeight(std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetFlexBasis(float flex_basis);

Expand All @@ -131,13 +131,13 @@ class YogaLayoutNode : public LayoutNode, public std::enable_shared_from_this<Yo

void SetPositionType(YGPositionType position_type);

void SetYGPosition(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGPosition(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGMargin(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGMargin(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGPadding(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGPadding(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetYGBorder(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> dom_value);
void SetYGBorder(YGEdge edge, std::shared_ptr<footstone::value::HippyValue> hippy_value);

void SetFlexWrap(YGWrap wrap_mode);

Expand Down
2 changes: 1 addition & 1 deletion dom/src/dom/animation/animation_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void AnimationManager::FetchAnimationsFromObject(
void AnimationManager::FetchAnimationsFromArray(HippyValue& value,
std::unordered_map<uint32_t, std::string>& result) {
if (value.IsArray()) {
footstone::value::HippyValue::DomValueArrayType array;
footstone::value::HippyValue::HippyValueArrayType array;
if (value.ToArray(array)) {
for (auto& val: array) {
if (val.IsObject()) {
Expand Down
Loading

0 comments on commit 59fb750

Please sign in to comment.