Chromium html<lable>c++接口定义
HTML <label>
元素(标签)表示用户界面中某个元素的说明。
1、<label
> 在html_tag_names.json5中接口定义:
(third_party\blink\renderer\core\html\html_tag_names.json5)
{
name: "label",
interfaceHeaderDir: "third_party/blink/renderer/core/html/forms",
},
2、html_label_element.idl接口定义:
// https://html.spec.whatwg.org/C/#the-label-element
[
Exposed=Window,
HTMLConstructor
] interface HTMLLabelElement : HTMLElement {
readonly attribute HTMLFormElement? form;
[CEReactions, Reflect=for] attribute DOMString htmlFor;
readonly attribute HTMLElement? control;
};
2、html_label_element.idl接口blink实现:
third_party\blink\renderer\core\html\forms\html_label_element.h
third_party\blink\renderer\core\html\forms\html_label_element.cc
namespace blink {
class CORE_EXPORT HTMLLabelElement final : public HTMLElement {
DEFINE_WRAPPERTYPEINFO();
public:
explicit HTMLLabelElement(Document&);
HTMLElement* control() const;
HTMLFormElement* form() const;
bool WillRespondToMouseClickEvents() override;
private:
bool IsInInteractiveContent(Node*) const;
bool IsInteractiveContent() const override;
void AccessKeyAction(SimulatedClickCreationScope creation_scope) override;
// Overridden to update the hover/active state of the corresponding control.
void SetActive(bool active) override;
void SetHovered(bool hovered) override;
// Overridden to either click() or focus() the corresponding control.
void DefaultEventHandler(Event&) override;
bool HasActivationBehavior() const override;
void Focus(const FocusParams&) override;
bool processing_click_;
};
} // namespace blink
3、html_label_element.idl接口v8实现:
out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_html_label_element.h
out\Debug\gen\third_party\blink\renderer\bindings\core\v8\v8_html_label_element.cc
namespace blink {
bool V8HTMLLabelElement::IsExposed(ExecutionContext* execution_context) {
return execution_context->IsWindow();
}
// Construction of WrapperTypeInfo may require non-trivial initialization due
// to cross-component address resolution in order to load the pointer to the
// parent interface's WrapperTypeInfo. We ignore this issue because the issue
// happens only on component builds and the official release builds
// (statically-linked builds) are never affected by this issue.
#if defined(COMPONENT_BUILD) && defined(WIN32) && defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wglobal-constructors"
#endif
const WrapperTypeInfo V8HTMLLabelElement::wrapper_type_info_{
gin::kEmbedderBlink,
V8HTMLLabelElement::InstallInterfaceTemplate,
nullptr,
"HTMLLabelElement",
V8HTMLElement::GetWrapperTypeInfo(),
WrapperTypeInfo::kWrapperTypeObjectPrototype,
WrapperTypeInfo::kNodeClassId,
WrapperTypeInfo::kNotInheritFromActiveScriptWrappable,
WrapperTypeInfo::kIdlInterface,
false,
};
#if defined(COMPONENT_BUILD) && defined(WIN32) && defined(__clang__)
#pragma clang diagnostic pop
#endif
const WrapperTypeInfo& HTMLLabelElement::wrapper_type_info_ =
V8HTMLLabelElement::wrapper_type_info_;
// non-[ActiveScriptWrappable]
static_assert(
!std::is_base_of<ActiveScriptWrappableBase, HTMLLabelElement>::value,
"HTMLLabelElement inherits from ActiveScriptWrappable<> without "
"[ActiveScriptWrappable] extended attribute.");
namespace {
namespace v8_html_label_element {
void FormAttributeGetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_HTMLLabelElement_form_Getter");
BLINK_BINDINGS_TRACE_EVENT("HTMLLabelElement.form.get");
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> v8_receiver = info.This();
HTMLLabelElement* blink_receiver = V8HTMLLabelElement::ToWrappableUnsafe(isolate, v8_receiver);
auto&& return_value = blink_receiver->form();
bindings::V8SetReturnValue(info, return_value, blink_receiver);
}
void HTMLForAttributeGetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_HTMLLabelElement_htmlFor_Getter");
BLINK_BINDINGS_TRACE_EVENT("HTMLLabelElement.htmlFor.get");
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> v8_receiver = info.This();
HTMLLabelElement* blink_receiver = V8HTMLLabelElement::ToWrappableUnsafe(isolate, v8_receiver);
auto&& return_value = blink_receiver->FastGetAttribute(html_names::kForAttr);
bindings::V8SetReturnValue(info, return_value, isolate, bindings::V8ReturnValue::kNonNullable);
}
void HTMLForAttributeSetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_HTMLLabelElement_htmlFor_Setter");
BLINK_BINDINGS_TRACE_EVENT("HTMLLabelElement.htmlFor.set");
const char* const class_like_name = "HTMLLabelElement";
const char* const property_name = "htmlFor";
bindings::PerformAttributeSetCEReactionsReflectTypeString(info, html_names::kForAttr, class_like_name, property_name);
}
void ControlAttributeGetCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_HTMLLabelElement_control_Getter");
BLINK_BINDINGS_TRACE_EVENT("HTMLLabelElement.control.get");
v8::Isolate* isolate = info.GetIsolate();
v8::Local<v8::Object> v8_receiver = info.This();
HTMLLabelElement* blink_receiver = V8HTMLLabelElement::ToWrappableUnsafe(isolate, v8_receiver);
auto&& return_value = blink_receiver->control();
bindings::V8SetReturnValue(info, return_value, blink_receiver);
}
void ConstructorCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {
RUNTIME_CALL_TIMER_SCOPE_DISABLED_BY_DEFAULT(info.GetIsolate(), "Blink_HTMLLabelElement_constructor");
BLINK_BINDINGS_TRACE_EVENT("HTMLLabelElement.constructor");
v8::Isolate* isolate = info.GetIsolate();
if (!info.IsConstructCall()) {
const ExceptionContextType exception_context_type = ExceptionContextType::kConstructorOperationInvoke;
const char* const class_like_name = "HTMLLabelElement";
ExceptionState exception_state(isolate, exception_context_type, class_like_name);
exception_state.ThrowTypeError(ExceptionMessages::ConstructorCalledAsFunction());
return;
}
if (ConstructorMode::Current(isolate) == ConstructorMode::kWrapExistingObject) {
v8::Local<v8::Object> v8_receiver = info.This();
bindings::V8SetReturnValue(info, v8_receiver);
return;
}
// [HTMLConstructor]
V8HTMLConstructor::HtmlConstructor(info, *V8HTMLLabelElement::GetWrapperTypeInfo(), HTMLElementType::kHTMLLabelElement);
}
} // namespace v8_html_label_element
using namespace v8_html_label_element;
} // namespace
void V8HTMLLabelElement::InstallInterfaceTemplate(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::Template> interface_template) {
const WrapperTypeInfo* const wrapper_type_info = V8HTMLLabelElement::GetWrapperTypeInfo();
v8::Local<v8::FunctionTemplate> interface_function_template = interface_template.As<v8::FunctionTemplate>();
v8::Local<v8::ObjectTemplate> instance_object_template = interface_function_template->InstanceTemplate();
v8::Local<v8::ObjectTemplate> prototype_object_template = interface_function_template->PrototypeTemplate();
v8::Local<v8::FunctionTemplate> parent_interface_template = wrapper_type_info->parent_class->GetV8ClassTemplate(isolate, world).As<v8::FunctionTemplate>();
bindings::SetupIDLInterfaceTemplate(isolate, wrapper_type_info, instance_object_template, prototype_object_template, interface_function_template, parent_interface_template);
interface_function_template->SetCallHandler(ConstructorCallback);
interface_function_template->SetLength(0);
v8::Local<v8::Template> instance_template = instance_object_template;
v8::Local<v8::Template> prototype_template = prototype_object_template;
InstallUnconditionalProperties(isolate, world, instance_template, prototype_template, interface_template);
}
void V8HTMLLabelElement::InstallUnconditionalProperties(v8::Isolate* isolate, const DOMWrapperWorld& world, v8::Local<v8::Template> instance_template, v8::Local<v8::Template> prototype_template, v8::Local<v8::Template> interface_template) {
using bindings::IDLMemberInstaller;
{
static const IDLMemberInstaller::AttributeConfig kAttributeTable[] = {
{"form", FormAttributeGetCallback, nullptr, unsigned(v8::None), unsigned(IDLMemberInstaller::FlagLocation::kPrototype), unsigned(IDLMemberInstaller::FlagWorld::kAllWorlds), unsigned(IDLMemberInstaller::FlagReceiverCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(v8::SideEffectType::kHasNoSideEffect), unsigned(V8PrivateProperty::CachedAccessor::kNone)},
{"htmlFor", HTMLForAttributeGetCallback, HTMLForAttributeSetCallback, unsigned(v8::None), unsigned(IDLMemberInstaller::FlagLocation::kPrototype), unsigned(IDLMemberInstaller::FlagWorld::kAllWorlds), unsigned(IDLMemberInstaller::FlagReceiverCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(v8::SideEffectType::kHasNoSideEffect), unsigned(V8PrivateProperty::CachedAccessor::kNone)},
{"control", ControlAttributeGetCallback, nullptr, unsigned(v8::None), unsigned(IDLMemberInstaller::FlagLocation::kPrototype), unsigned(IDLMemberInstaller::FlagWorld::kAllWorlds), unsigned(IDLMemberInstaller::FlagReceiverCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(IDLMemberInstaller::FlagCrossOriginCheck::kCheck), unsigned(v8::SideEffectType::kHasNoSideEffect), unsigned(V8PrivateProperty::CachedAccessor::kNone)},
};
v8::Local<v8::FunctionTemplate> interface_function_template = interface_template.As<v8::FunctionTemplate>();
v8::Local<v8::Signature> signature = v8::Signature::New(isolate, interface_function_template);
IDLMemberInstaller::InstallAttributes(isolate, world, instance_template, prototype_template, interface_template, signature, kAttributeTable);
}
}
} // namespace blink