void AnonymousContent::GetComputedStylePropertyValue(const nsAString& aElementId, const nsAString& aPropertyName, DOMString& aResult, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return; } nsIPresShell* shell = element->OwnerDoc()->GetShell(); if (!shell) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return; } RefPtr<nsComputedDOMStyle> cs = new nsComputedDOMStyle(element, NS_LITERAL_STRING(""), element->OwnerDoc(), nsComputedDOMStyle::eAll); aRv = cs->GetPropertyValue(aPropertyName, aResult); }
void FNavigationOctree::UpdateNode(const FOctreeElementId& Id, const FBox& NewBounds) { FNavigationOctreeElement ElementCopy = GetElementById(Id); RemoveElement(Id); ElementCopy.Bounds = NewBounds; AddElement(ElementCopy); }
void AnonymousContent::SetCutoutRectsForElement(const nsAString& aElementId, const Sequence<OwningNonNull<DOMRect>>& aRects, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return; } nsRegion cutOutRegion; for (const auto& r : aRects) { CSSRect rect(r->X(), r->Y(), r->Width(), r->Height()); cutOutRegion.OrWith(CSSRect::ToAppUnits(rect)); } element->SetProperty(nsGkAtoms::cutoutregion, new nsRegion(cutOutRegion), nsINode::DeleteProperty<nsRegion>); nsIFrame* frame = element->GetPrimaryFrame(); if (frame) { frame->SchedulePaint(); } }
void FNavigationOctree::AppendToNode(const FOctreeElementId& Id, INavRelevantInterface* NavElement, const FBox& Bounds, FNavigationOctreeElement& Element) { FNavigationOctreeElement OrgData = GetElementById(Id); Element = OrgData; Element.Bounds = Bounds + OrgData.Bounds.GetBox(); if (NavElement) { SCOPE_CYCLE_COUNTER(STAT_Navigation_GatheringNavigationModifiersSync); NavElement->GetNavigationData(*Element.Data); } // shrink arrays before counting memory // it will be reallocated when adding to octree and RemoveNode will have different value returned by GetAllocatedSize() Element.Shrink(); const int32 OrgElementMemory = OrgData.GetAllocatedSize(); const int32 NewElementMemory = Element.GetAllocatedSize(); const int32 MemoryDelta = NewElementMemory - OrgElementMemory; NodesMemory += MemoryDelta; INC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, MemoryDelta); RemoveElement(Id); AddElement(Element); }
void FNavigationOctree::RemoveNode(const FOctreeElementId& Id) { FNavigationOctreeElement& Element = GetElementById(Id); const int32 ElementMemory = Element.GetAllocatedSize(); NodesMemory -= ElementMemory; DEC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemory); RemoveElement(Id); }
const FNavigationRelevantData* FNavigationOctree::GetDataForID(const FOctreeElementId& Id) const { if (Id.IsValidId() == false) { return nullptr; } const FNavigationOctreeElement& OctreeElement = GetElementById(Id); return &*OctreeElement.Data; }
void AnonymousContent::RemoveAttributeForElement(const nsAString& aElementId, const nsAString& aName, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return; } element->RemoveAttribute(aName, aRv); }
void FNavigationOctree::RemoveNode(const FOctreeElementId* Id) { #if NAVOCTREE_CONTAINS_COLLISION_DATA FNavigationOctreeElement& Data = GetElementById(*Id); const int32 ElementMemory = Data.GetAllocatedSize(); NodesMemory -= ElementMemory; DEC_MEMORY_STAT_BY(STAT_Navigation_CollisionTreeMemory, ElementMemory); #endif RemoveElement(*Id); }
void AnonymousContent::SetAttributeForElement(const nsAString& aElementId, const nsAString& aName, const nsAString& aValue, nsIPrincipal* aSubjectPrincipal, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return; } element->SetAttribute(aName, aValue, aSubjectPrincipal, aRv); }
// Adds a log message to the debug log. void ElementLog::AddLogMessage(Core::Log::Type type, const Core::String& message) { // Add the message to the list of messages for the specified log type. LogMessage log_message; log_message.index = current_index++; log_message.message = Core::String(message).Replace("<", "<").Replace(">", ">"); log_types[type].log_messages.push_back(log_message); if (log_types[type].log_messages.size() >= MAX_LOG_MESSAGES) { log_types[type].log_messages.pop_front(); } // If this log type is invisible, and there is a button for this log type, then change its text from // "Off" to "Off*" to signal that there are unread logs. if (!log_types[type].visible) { if (!log_types[type].button_name.Empty()) { Rocket::Core::Element* button = GetElementById(log_types[type].button_name); if (button) { button->SetInnerRML("Off*"); } } } // Trigger the beacon if we're hidden. Override any lower-level log type if it is already visible. else { if (!IsVisible()) { if (beacon != NULL) { if (type < current_beacon_level) { beacon->SetProperty("visibility", "visible"); current_beacon_level = type; Rocket::Core::Element* beacon_button = beacon->GetFirstChild(); if (beacon_button) { beacon_button->SetClassNames(log_types[type].class_name); beacon_button->SetInnerRML(log_types[type].alert_contents); } } } } } // Force a refresh of the RML. dirty_logs = true; }
already_AddRefed<Animation> AnonymousContent::SetAnimationForElement( JSContext* aContext, const nsAString& aElementId, JS::Handle<JSObject*> aKeyframes, const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return nullptr; } return element->Animate(aContext, aKeyframes, aOptions, aRv); }
void SetControlBoolAttribute(IHTMLDocument2 *pDoc, CString szId, CString szAttributeName, BOOL bValue) { HRESULT hr = S_OK; IHTMLElement* pElem = NULL; hr = GetElementById(pDoc, szId, &pElem); if (hr == S_OK && pElem) { BSTR bstrAttributeName = szAttributeName.AllocSysString(); VARIANT varAttr; varAttr.vt = VT_BOOL; varAttr.boolVal = bValue; pElem->setAttribute(bstrAttributeName, varAttr); ::SysFreeString(bstrAttributeName); } }
// Initialises the log element. bool ElementLog::Initialise() { SetInnerRML(log_rml); SetId("rkt-debug-log"); message_content = GetElementById("content"); if (message_content) { message_content->AddEventListener("resize", this); } Core::StyleSheet* style_sheet = Core::Factory::Instance()->InstanceStyleSheetString(Core::String(common_rcss) + Core::String(log_rcss)); if (style_sheet == NULL) return false; SetStyleSheet(style_sheet); style_sheet->RemoveReference(); // Create the log beacon. beacon = GetContext()->CreateDocument(); if (beacon == NULL) return false; beacon->SetId("rkt-debug-log-beacon"); beacon->SetProperty("visibility", "hidden"); beacon->SetInnerRML(beacon_rml); // Remove the initial reference on the beacon. beacon->RemoveReference(); Core::Element* button = beacon->GetFirstChild(); if (button != NULL) beacon->GetFirstChild()->AddEventListener("click", this); style_sheet = Core::Factory::Instance()->InstanceStyleSheetString(Core::String(common_rcss) + Core::String(beacon_rcss)); if (style_sheet == NULL) { GetContext()->UnloadDocument(beacon); beacon = NULL; return false; } beacon->SetStyleSheet(style_sheet); style_sheet->RemoveReference(); return true; }
CString GetControlStringAttribute(IHTMLDocument2 *pDoc, CString szId, CString szAttributeName) { HRESULT hr = S_OK; IHTMLElement* pElem = NULL; hr = GetElementById(pDoc, szId, &pElem); if (hr == S_OK && pElem) { VARIANT varAttr; varAttr.vt = VT_BSTR; BSTR bstrAttributeName = szAttributeName.AllocSysString(); hr = pElem->getAttribute(bstrAttributeName, 0, &varAttr); ::SysFreeString(bstrAttributeName); if (hr == S_OK && varAttr.vt == VT_BSTR) { return CString(varAttr.bstrVal); } } return ""; }
BOOL GetControlBoolAttribute(IHTMLDocument2 *pDoc, CString szId, CString szAttributeName) { HRESULT hr = S_OK; IHTMLElement* pElem = NULL; hr = GetElementById(pDoc, szId, &pElem); if (hr == S_OK && pElem) { VARIANT varAttr; varAttr.vt = VT_BOOL; BSTR bstrAttributeName = szAttributeName.AllocSysString(); hr = pElem->getAttribute(bstrAttributeName, 0, &varAttr); ::SysFreeString(bstrAttributeName); if (hr == S_OK && varAttr.vt == VT_BOOL) { return varAttr.boolVal; } } return FALSE; }
already_AddRefed<nsISupports> AnonymousContent::GetCanvasContext( const nsAString& aElementId, const nsAString& aContextId, ErrorResult& aRv) { Element* element = GetElementById(aElementId); if (!element) { aRv.Throw(NS_ERROR_NOT_AVAILABLE); return nullptr; } if (!element->IsHTMLElement(nsGkAtoms::canvas)) { return nullptr; } nsCOMPtr<nsISupports> context; HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(element); canvas->GetContext(aContextId, getter_AddRefs(context)); return context.forget(); }
void ElementHandle::ProcessEvent(Event& event) { Element::ProcessEvent(event); if (event.GetTargetElement() == this) { // Lazy initialisation. if (!initialised && GetOwnerDocument()) { String move_target_name = GetAttribute<String>("move_target", ""); if (!move_target_name.Empty()) move_target = GetElementById(move_target_name); String size_target_name = GetAttribute<String>("size_target", ""); if (!size_target_name.Empty()) size_target = GetElementById(size_target_name); initialised = true; } if (event == DRAGSTART) { // Store the drag starting position drag_start.x = event.GetParameter< int >("mouse_x", 0); drag_start.y = event.GetParameter< int >("mouse_y", 0); // Store current element position and size if (move_target) { move_original_position.x = move_target->GetOffsetLeft(); move_original_position.y = move_target->GetOffsetTop(); } if (size_target) size_original_size = size_target->GetBox().GetSize(Box::CONTENT); } else if (event == DRAG) { // Work out the delta int x = event.GetParameter< int >("mouse_x", 0) - drag_start.x; int y = event.GetParameter< int >("mouse_y", 0) - drag_start.y; // Update the move and size objects if (move_target) { move_target->SetProperty(LEFT, Property(Math::RealToInteger(move_original_position.x + x), Property::PX)); move_target->SetProperty(TOP, Property(Math::RealToInteger(move_original_position.y + y), Property::PX)); } if (size_target) { // Check if we have auto-margins; if so, they have to be set to the current margins. if (size_target->GetProperty(MARGIN_TOP)->unit == Property::KEYWORD) size_target->SetProperty(MARGIN_TOP, Property((float) Math::RealToInteger(size_target->GetBox().GetEdge(Box::MARGIN, Box::TOP)), Property::PX)); if (size_target->GetProperty(MARGIN_RIGHT)->unit == Property::KEYWORD) size_target->SetProperty(MARGIN_RIGHT, Property((float) Math::RealToInteger(size_target->GetBox().GetEdge(Box::MARGIN, Box::RIGHT)), Property::PX)); if (size_target->GetProperty(MARGIN_BOTTOM)->unit == Property::KEYWORD) size_target->SetProperty(MARGIN_BOTTOM, Property((float) Math::RealToInteger(size_target->GetBox().GetEdge(Box::MARGIN, Box::BOTTOM)), Property::PX)); if (size_target->GetProperty(MARGIN_LEFT)->unit == Property::KEYWORD) size_target->SetProperty(MARGIN_LEFT, Property((float) Math::RealToInteger(size_target->GetBox().GetEdge(Box::MARGIN, Box::LEFT)), Property::PX)); int new_x = Math::RealToInteger(size_original_size.x + x); int new_y = Math::RealToInteger(size_original_size.y + y); size_target->SetProperty(WIDTH, Property(Math::Max< float >((float) new_x, 0), Property::PX)); size_target->SetProperty(HEIGHT, Property(Math::Max< float >((float) new_y, 0), Property::PX)); } Dictionary parameters; parameters.Set("handle_x", x); parameters.Set("handle_y", y); DispatchEvent("handledrag", parameters); } } }
void ElementInfo::UpdateSourceElement() { // Set the title: Core::Element* title_content = GetElementById("title-content"); if (title_content != NULL) { if (source_element != NULL) title_content->SetInnerRML(source_element->GetTagName()); else title_content->SetInnerRML("Element Information"); } // Set the attributes: Core::Element* attributes_content = GetElementById("attributes-content"); if (attributes_content) { int index = 0; Core::String name; Core::String value; Core::String attributes; if (source_element != NULL) { while (source_element->IterateAttributes(index, name, value)) attributes.Append(Core::String(name.Length() + value.Length() + 32, "%s: <em>%s</em><br />", name.CString(), value.CString())); } if (attributes.Empty()) { while (attributes_content->HasChildNodes()) attributes_content->RemoveChild(attributes_content->GetChild(0)); } else attributes_content->SetInnerRML(attributes); } // Set the properties: Core::Element* properties_content = GetElementById("properties-content"); if (properties_content) { Core::String properties; if (source_element != NULL) BuildElementPropertiesRML(properties, source_element, source_element); if (properties.Empty()) { while (properties_content->HasChildNodes()) properties_content->RemoveChild(properties_content->GetChild(0)); } else properties_content->SetInnerRML(properties); } // Set the position: Core::Element* position_content = GetElementById("position-content"); if (position_content) { // left, top, width, height. if (source_element != NULL) { Core::Vector2f element_offset = source_element->GetRelativeOffset(Core::Box::BORDER); Core::Vector2f element_size = source_element->GetBox().GetSize(Core::Box::BORDER); Core::String positions; positions.Append(Core::String(64, "left: <em>%.0fpx</em><br />", element_offset.x)); positions.Append(Core::String(64, "top: <em>%.0fpx</em><br />", element_offset.y)); positions.Append(Core::String(64, "width: <em>%.0fpx</em><br />", element_size.x)); positions.Append(Core::String(64, "height: <em>%.0fpx</em><br />", element_size.y)); position_content->SetInnerRML(positions); } else { while (position_content->HasChildNodes()) position_content->RemoveChild(position_content->GetFirstChild()); } } // Set the ancestors: Core::Element* ancestors_content = GetElementById("ancestors-content"); if (ancestors_content) { Core::String ancestors; Core::Element* element_ancestor = NULL; if (source_element != NULL) element_ancestor = source_element->GetParentNode(); int ancestor_depth = 1; while (element_ancestor) { Core::String ancestor_name = element_ancestor->GetTagName(); const Core::String ancestor_id = element_ancestor->GetId(); if (!ancestor_id.Empty()) { ancestor_name += "#"; ancestor_name += ancestor_id; } ancestors.Append(Core::String(ancestor_name.Length() + 32, "<p id=\"a %d\">%s</p>", ancestor_depth, ancestor_name.CString())); element_ancestor = element_ancestor->GetParentNode(); ancestor_depth++; } if (ancestors.Empty()) { while (ancestors_content->HasChildNodes()) ancestors_content->RemoveChild(ancestors_content->GetFirstChild()); } else ancestors_content->SetInnerRML(ancestors); } // Set the children: Core::Element* children_content = GetElementById("children-content"); if (children_content) { Core::String children; if (source_element != NULL) { for (int i = 0; i < source_element->GetNumChildren(); i++) { Core::Element* child = source_element->GetChild(i); // If this is a debugger document, do not show it. if (IsDebuggerElement(child)) continue; Core::String child_name = child->GetTagName(); const Core::String child_id = child->GetId(); if (!child_id.Empty()) { child_name += "#"; child_name += child_id; } children.Append(Core::String(child_name.Length() + 32, "<p id=\"c %d\">%s</p>", i, child_name.CString())); } } if (children.Empty()) { while (children_content->HasChildNodes()) children_content->RemoveChild(children_content->GetChild(0)); } else children_content->SetInnerRML(children); } }