/// Run all currently active schedulers. /// If we're the only reference holder to a document, release the document and its scheduler void update( void ) { SchedulerMap::iterator it = schedulers.begin(); while( it != schedulers.end() ) { // grab the next pointer in case we erase the current one SchedulerMap::iterator next = it; next++; ElementDocument *doc = it->first; FunctionCallScheduler *scheduler = it->second; if( doc->GetReferenceCount() == 1 ) { scheduler->shutdown(); __delete__( scheduler ); doc->RemoveReference(); schedulers.erase( it ); } else { scheduler->update(); } // advance it = next; } }
/// Closes the current document if there's more than one on the stack. /// Stores exit code to be passed to suspended context if modal. void close( int code = 0 ) { WSWUI::NavigationStack *stack = UI_Main::Get()->getNavigator(); if( stack == NULL ) { return; } ElementDocument *document = GetCurrentUIDocument(); bool isModal = document->IsModal(); // can't close if there's a modal dialog on top if( !isModal && stack->isTopModal() ) { return; } // so it's a top modal dialog or there's no modal dialog on stack at all if( isModal ) { modalValue = code; stack->popDocument(); } else { // not really a modal window, clear the stack UI_Main::Get()->showUI( false ); } }
// Returns the active style sheet for this element. This may be NULL. StyleSheet* ElementStyle::GetStyleSheet() const { ElementDocument* document = element->GetOwnerDocument(); if (document != NULL) return document->GetStyleSheet(); return NULL; }
bool XMLNodeHandlerHead::ElementEnd(XMLParser* parser, const String& name) { // When the head tag closes, inject the header into the active document if (name == "head") { Element* element = parser->GetParseFrame()->element; if (!element) return true; ElementDocument* document = element->GetOwnerDocument(); if (document) document->ProcessHeader(parser->GetDocumentHeader()); } return true; }
~ASWindow() { // detatch itself from the possibly opened modal window detachAsEventListener(); // remove schedulers for all documents we hold references to for( SchedulerMap::iterator it = schedulers.begin(); it != schedulers.end(); it++ ) { ElementDocument *doc = it->first; FunctionCallScheduler *scheduler = it->second; doc->RemoveReference(); scheduler->shutdown(); __delete__( scheduler ); } schedulers.clear(); }
/// finds or creates new scheduler for the document currently on AS-stack FunctionCallScheduler *getSchedulerForCurrentUIDocument( void ) { ElementDocument *doc = GetCurrentUIDocument(); SchedulerMap::iterator it = schedulers.find( doc ); FunctionCallScheduler *scheduler; if( it == schedulers.end() ) { doc->AddReference(); scheduler = __new__( FunctionCallScheduler )(); scheduler->init( UI_Main::Get()->getAS() ); schedulers[doc] = scheduler; } else { scheduler = it->second; } return scheduler; }
void BaseEventListener::StartTargetPropertySound( Element *target, const String &property ) { String sound = target->GetProperty<String>( property ); if( sound.Empty() ) { return; } // check relative url, and add documents path if( sound[0] != '/' ) { ElementDocument *doc = target->GetOwnerDocument(); if( doc ) { URL documentURL( doc->GetSourceURL() ); URL soundURL( sound ); soundURL.PrefixPath( documentURL.GetPath() ); sound = soundURL.GetPathedFileName(); } } trap::S_StartLocalSound( sound.CString()+1 ); }
Element* XMLNodeHandlerBody::ElementStart(XMLParser* parser, const String& name, const XMLAttributes& attributes) { ROCKET_ASSERT(name == "body"); Element* element = parser->GetParseFrame()->element; // Check for and apply any template String template_name = attributes.Get<String>("template", ""); if (!template_name.Empty()) { element = XMLParseTools::ParseTemplate(element, template_name); } // Apply any attributes to the document ElementDocument* document = parser->GetParseFrame()->element->GetOwnerDocument(); if (document) document->SetAttributes(&attributes); // Tell the parser to use the element handler for all children parser->PushDefaultHandler(); return element; }
ASURL getLocation( void ) const { ElementDocument *document = GetCurrentUIDocument(); return ASURL( document->GetSourceURL().CString() ); }
ElementDocument *getDocument( void ) const { ElementDocument *document = GetCurrentUIDocument(); document->AddReference(); return document; }
virtual void ProcessEvent( Event &event ) { if( UI_Main::Get()->debugOn() ) { Com_Printf( "EventListener: Event %s, target %s, phase %i\n", event.GetType().CString(), event.GetTargetElement()->GetTagName().CString(), event.GetPhase() ); } if( event.GetType() == "keydown" && ( event.GetPhase() == Rocket::Core::Event::PHASE_TARGET || event.GetPhase() == Rocket::Core::Event::PHASE_BUBBLE ) ) { int key = event.GetParameter<int>( "key_identifier", 0 ); ElementDocument *document = event.GetTargetElement()->GetOwnerDocument(); WSWUI::Document *ui_document = static_cast<WSWUI::Document *>(document->GetScriptObject()); WSWUI::NavigationStack *stack = ui_document ? ui_document->getStack() : NULL; if( key == Input::KI_ESCAPE ) { if( stack ) { if( stack->isTopModal() ) { // pop the top document stack->popDocument(); } else if( stack->getContextId() == UI_CONTEXT_MAIN ) { // hide all documents UI_Main::Get()->showUI( false ); } } event.StopPropagation(); } else if( key == Rocket::Core::Input::KI_BROWSER_BACK || key == Rocket::Core::Input::KI_BACK ) { // act as history.back() if( stack && stack->hasAtLeastTwoDocuments() ) { stack->popDocument(); event.StopPropagation(); } } } else if( event.GetType() == "change" && ( event.GetPhase() == Rocket::Core::Event::PHASE_BUBBLE ) ) { bool linebreak = event.GetParameter<int>( "linebreak", 0 ) != 0; if( linebreak ) { // form submission String inputType; Element *target = event.GetTargetElement(); Rocket::Controls::ElementFormControl *input = dynamic_cast<Rocket::Controls::ElementFormControl *>(target); if( event.GetPhase() != Rocket::Core::Event::PHASE_BUBBLE ) { return; } if( input == NULL ) { // not a form control return; } if( input->IsDisabled() ) { // skip disabled inputs return; } if( !input->IsSubmitted() ) { // this input field isn't submitted with the form return; } inputType = input->GetAttribute<String>( "type", "" ); if( inputType != "text" && inputType != "password" ) { // not a text field return; } // find the parent form element Element *parent = target->GetParentNode(); Rocket::Controls::ElementForm *form = NULL; while( parent ) { form = dynamic_cast<Rocket::Controls::ElementForm *>(parent); if( form != NULL ) { // not a form, go up the tree break; } parent = parent->GetParentNode(); } if( form == NULL ) { if( UI_Main::Get()->debugOn() ) { Com_Printf( "EventListener: input element outside the form, what should I do?\n" ); } return; } // find the submit element Element *submit = NULL; ElementList controls; parent->GetElementsByTagName( controls, "input" ); for( size_t i = 0; i < controls.size(); i++ ) { Rocket::Controls::ElementFormControl *control = dynamic_cast< Rocket::Controls::ElementFormControl* >(controls[i]); if( !control ) { continue; } if( control->IsDisabled() ) { // skip disabled inputs continue; } String controlType = control->GetAttribute<String>( "type", "" ); if( controlType != "submit" ) { // not a text field continue; } submit = controls[i]; break; } if( submit == NULL ) { if( UI_Main::Get()->debugOn() ) { Com_Printf( "EventListener: form with no submit element, what should I do?\n" ); } return; } // finally submit the form form->Submit( submit->GetAttribute< Rocket::Core::String >("name", ""), submit->GetAttribute< Rocket::Core::String >("value", "") ); } } }