summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/layout/ng/custom/custom_layout_constraints.cc
blob: 9ed31898a5cff75d854540ffbd5d32263d5bdc93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright 2018 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.

#include "third_party/blink/renderer/core/layout/ng/custom/custom_layout_constraints.h"

#include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/bindings/core/v8/serialization/serialized_script_value.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/layout/geometry/logical_size.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h"

namespace blink {

CustomLayoutConstraints::CustomLayoutConstraints(
    const LogicalSize& border_box_size,
    SerializedScriptValue* data,
    v8::Isolate* isolate)
    : fixed_inline_size_(border_box_size.inline_size),
      fixed_block_size_(border_box_size.block_size) {
  if (data)
    layout_worklet_world_v8_data_.Set(isolate, data->Deserialize(isolate));
}

CustomLayoutConstraints::~CustomLayoutConstraints() = default;

base::Optional<double> CustomLayoutConstraints::fixedBlockSize() const {
  // Check if we've been passed an indefinite block-size.
  if (fixed_block_size_ < 0.0)
    return base::nullopt;
  return fixed_block_size_;
}

ScriptValue CustomLayoutConstraints::data(ScriptState* script_state) const {
  // "data" is *only* exposed to the LayoutWorkletGlobalScope, and we are able
  // to return the same deserialized object. We don't need to check which world
  // it is being accessed from.
  DCHECK(ExecutionContext::From(script_state)->IsLayoutWorkletGlobalScope());
  DCHECK(script_state->World().IsWorkerWorld());

  if (layout_worklet_world_v8_data_.IsEmpty())
    return ScriptValue::CreateNull(script_state->GetIsolate());

  return ScriptValue(
      script_state->GetIsolate(),
      layout_worklet_world_v8_data_.NewLocal(script_state->GetIsolate()));
}

void CustomLayoutConstraints::Trace(Visitor* visitor) {
  visitor->Trace(layout_worklet_world_v8_data_);
  ScriptWrappable::Trace(visitor);
}

}  // namespace blink