Interactor Tree. Edith Law & Mike Terry

Similar documents
CITS3403 Agile Web Development Semester 1, 2018

JavaScript and XHTML. Prof. D. Krupesha, PESIT, Bangalore

CISC 1600 Lecture 2.4 Introduction to JavaScript

INLEDANDE WEBBPROGRAMMERING MED JAVASCRIPT INTRODUCTION TO WEB PROGRAMING USING JAVASCRIPT

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety?

CSC Web Programming. JavaScript Browser Objects

5. Strict mode use strict ; 6. Statement without semicolon, with semicolon 7. Keywords 8. Variables var keyword and global scope variable 9.

INTRODUCTION TO WEB DEVELOPMENT AND HTML. Lecture 13: Intro to JavaScript - Spring 2011

JavaScript!= Java. Intro to JavaScript. What is JavaScript? Intro to JavaScript 4/17/2013 INTRODUCTION TO WEB DEVELOPMENT AND HTML

Outline. Lecture 4: Document Object Model (DOM) What is DOM Traversal and Modification Events and Event Handling

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. 2.4 Event Dispatch 1

Programming in HTML5 with JavaScript and CSS3

widgetjs Documentation

Event Dispatch. Dispatching events to windows and widgets.

Client vs Server Scripting

JavaScript for WordPress. Zac

Sample CS 142 Midterm Examination

Event Dispatch. Interactor Tree Lightweight vs. Heavyweight Positional Dispatch Focus Dispatch. Event Architecture. A pipeline: Event Capture

Best Practices Chapter 5

Web Security, Summer Term 2012

Web Security, Summer Term 2012

CSI 3140 WWW Structures, Techniques and Standards. Browsers and the DOM

Introduction to using HTML to design webpages

COMP519 Web Programming Lecture 16: JavaScript (Part 7) Handouts

INTRODUCTION TO JAVASCRIPT

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

Stencil: The Time for Vanilla Web Components has Arrived

JavaServer Faces Technology, AJAX, and Portlets: It s Easy if You Know How!

Overview. Event Handling. Introduction. Reviewing the load Event. Event mousemove and the event Object. Rollovers with mouseover and mouseout

Web Development & Design Foundations with HTML5

Interactive Programming

Fall UI Design and Implementation 1

Affine Transformation. Edith Law & Mike Terry

E-Applications. XML and DOM in Javascript. Michail Lampis

EVENT-DRIVEN PROGRAMMING

Session 6. JavaScript Part 1. Reading

A Brief Introduction to a web browser's HTML. and the Document Object Model (DOM) Lecture 28

Lecture 4: UI Software Architecture. Fall UI Design and Implementation 1

CS142 Winter 2017 Midterm Grading Solutions and Rubric

Events: another simple example

welcome to BOILERCAMP HOW TO WEB DEV

DOM Primer Part 2. Contents

Use Web Event Bubbling

Understanding this structure is pretty straightforward, but nonetheless crucial to working with HTML, CSS, and JavaScript.

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Sample CS 142 Midterm Examination

Today s Hall of Fame or Shame example is a feature of Microsoft Office 2007 that gives a preview of what a style command will do to the document

Quick XPath Guide. Introduction. What is XPath? Nodes

Apache Wicket. Java Web Application Framework

Uniform Resource Locators (URL)

Lecture 8. ReactJS 1 / 24

MVC: Model View Controller

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

JavaScript II CSCI 311 SPRING 2017

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2018)

Project 3 Web Security Part 1. Outline

1. Setup a root folder for the website 2. Create a wireframe 3. Add content 4. Create hyperlinks between pages and to external websites

Events. Mendel Rosenblum. CS142 Lecture Notes - Events

Model-view-controller View hierarchy Observer

Frontend Frameworks Part 2. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Advanced Angular & Angular 6 Preview. Bibhas Bhattacharya

As we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.

Trees. Carlos Moreno uwaterloo.ca EIT

Elementary Computing CSC 100. M. Cheng, Computer Science

Bonus Lesson: Working with Code

Revision for Grade 7 ASP in Unit :1&2 Design & Technology Subject

Fundamentals of Web Programming

CS 4300 Computer Graphics

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

(Refer Slide Time: 01:40)

An updated events syntax for XML-based markup languages

Reagent. a ClojureScript interface to React. React Amsterdam Meetup 12 Feb. 2015

Photo from DOM

Events. Dispatch, event-to-code binding. Review: Events Defined 1/17/2014. occurrence.

The DOM and jquery functions and selectors. Lesson 3

Welcome to CS50 section! This is Week 10 :(

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

CE212 Web Application Programming Part 2

Lecture 5. Connecting Code to Web Page Events

Produced by. App Development & Modeling. BSc in Applied Computing. Eamonn de Leastar

Lecture 8: JavaScript

5/19/2015. Objectives. JavaScript, Sixth Edition. Understanding Syntax Errors. Introduction to Debugging. Handling Run-Time Errors

IN4MATX 133: User Interface Software

Cut, Paste, Drag-and-Drop. Benefits, data formats, and Java implementation

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

GUI Programming. Chapter. A Fresh Graduate s Guide to Software Development Tools and Technologies

Session 7. JavaScript Part 2. W3C DOM Reading and Reference

Session 3: JavaScript - Structured Programming

Pearson Education Limited Edinburgh Gate Harlow Essex CM20 2JE England and Associated Companies throughout the world

JavaScript Fundamentals_

IN Development in Platform Ecosystems Lecture 2: HTML, CSS, JavaScript

JavaScript: Events, DOM and Attaching Handlers

New Perspectives on Creating Web Pages with HTML. Tutorial Objectives

React.js. a crash course. Jake Zimmerman January 29th, 2016

Netscape Introduction to the JavaScript Language

Widget. Widget is a generic name for parts of an interface that have their own behaviour. e.g., buttons, progress bars, sliders, drop-down

dhtml2010.pdf February 25,

Northern Arizona University. Capstone Team Project. Design Document. Bit Tag. Temitope Alaga, John Dance, Joshua Frampton, Jun Rao.

Design Importer User Guide

Transcription:

Interactor Tree Edith Law & Mike Terry

Today s YouTube Break https://www.youtube.com/watch?v=mqqo-iog4qw

Routing Events to Widgets Say I click on the CS349 button, which produces a mouse event that is dispatched. How do I get that event to the CS349 button? option 1: maintain a flat list of all the components in the window and figure out which one intersects with that point option 2: interactor tree, which is a hierarchical, tree-based organization of widgets

Interactor Tree The idea: add components as children of other components a child component s locations are expressed relative to its parent To assist with this, we can create components, called containers, whose sole purpose is to contain other components. In the Java GUI toolkit, containers includes components like panels, panes, boxes, etc. Containers have little or no visual representation, and server primarily to group components together.

Interactor Tree We can have two panels of components, one containing the list of classes buttons and the other containing the settings for the currently selected group. We can move these panels around, and the child widgets should move around with them, and react to input events in their new positions.

Routing Events Through the Interactor Tree When it comes time to paint or interpret an event, we need to ensure that the coordinates are relative to the parent. x

Interactor Tree: Summary We build an interactor tree of components, a hierarchical ordering of widgets, and use the interactor tree to specify widget locations relative to the parent component pass events down the interactor tree ask components to paint themselves and their children Finally, we can make the window itself an instance of a component, and place all other controls within that component. The window then becomes the root of the tree. To deliver an event, we just pass it to the window, and it recursively passes it down the tree to the proper widget (i.e., top-down dispatch)

Interactor Tree in the Web Browser This strategy for delivery events leads to a very elegant, recursive algorithm for routing events to components likely able to act on and interpret events. And, this idea is also analogous to how the Web browser handles the rendering of visual components and routes events to them.

HTML as DOM tree <html> <head> <title>cs349</title> </head> <body> <a href= http://uwaterloo.ca > UWaterloo </a> <h1>welcome!</h1> </body> </html>

HTML as DOM tree <html> <head> <title>cs349</title> </head> <body> Element: <head> <a href= http://uwaterloo.ca > UWaterloo </a> <h1>welcome!</h1> </body> </html> Element: <title> Text: CS349 Document Root element: <html> Attribute: <href> Element: <a> Text: UWaterloo Element: <body> Element: <h1> Text: Welcome!

DOM tree The Document Object Model (DOM) defines the structure of the HTML document as well as the behaviour of the objects it contains. The DOM serves as a standard, which enables Javascript to manipulate (e.g., add, remove, change) HTML elements and handle events in a portable way across different Web browsers.

Demo (1) Manipulating the DOM tree (2) Event Handling (3) Debugging Tools (4) Event Propagation

Manipulating the DOM Tree document.getelementbyid() document.getelementsbytagname() document.getelementsbyclassname() element.innerhtml = element.attribute= document.createelement() document.removechild() document.appendchild() document.replacechild() document.title document.images finding elements modifying elements adding/deleting elements finding HTML objects

DOM tree Besides manipulating HTML elements, the DOM enables Javascript to handle events. This allows us to create interactive webpages. The user does something and the page reacts. Javascript needs a way to detect user actions so it knows when to react. But how?

Event Handling To add interactivity to a widget (e.g., button), we can add an event handler to the widget. The eventhandler is a function that waits until a certain event (e.g., mouse click), then handles the event by executing some program that you have defined.

Demo (1) Manipulating the DOM tree (2) Event Handling (3) Debugging Tools (4) Event Propagation

Event Handling DOM Level 0 <button onclick= alert( hello ); > Say Hello! </button> DOM Level 1 document.getelementbyid( mybutton ).onclick = function() { alert( Hello! ); } DOM Level 2 var el = document.getelementbyid( mybutton ) el.addeventlistener( click, function() { alert( Hello ); }, false);

Event Handling DOM Level 2 events allow you to create as many handlers for an event as you want. addeventlistener allows registration of event listeners on the event target. removeeventlistener allows removal of event listeners from the event target. dispatchevent allows sending the event to the subscribed event listener.

Demo (1) Manipulating the DOM tree (2) Event Handling (3) Debugging Tools (4) Event Propagation

Chrome Debugging Tools DOM breakpoint printout, error

Event Propagation var el = document.getelementbyid( mybutton ) el.addeventlistener( click, function() { alert( Hello ); }, false); what is the meaning of this flag?

Event Propagation Events travel through the document in two phases: capture and bubble phase. <html> <head> <title>cs349</title> </head> <body> <div id= mydiv > <a href= http://www.uwaterloo.ca > UWaterloo </a> <h1>welcome!</h1> </div> </body> </html> Suppose that you click on the anchor tag UWaterloo, the click events drills down the document through the anchor s parent to reach it (capture phase), then circles around and goes back up to the document root (called Bubble phase).

Event Propagation Event objects are dispatched to an event target through a propagation path. capture: the event propagates from the document root to the target s parent. Event listeners registered for this phase handle the event before it reaches its target. target: the event arrives at the final target element. Event listeners registered for this phase handle the event at the target. bubble: the event propagates in reverse order, starting with the target s parents and ending with the document root. Event listeners registered for this phase just handle the event after it has reached its target. image source: W3C

Demo (1) Manipulating the DOM tree (2) Event Handling (3) Debugging Tools (4) Event Propagation

Event Propagation: Summary A component (e.g., a hyperlink) adds an event listener for a particular event (e.g., mouse click), and specify whether it should be executed in the capture or bubble phase. When the event happens: (1) calculate the parent node path to the target. (2) loop through the parent node path, and execute all the capture phase handlers. Any of the event handlers can stop the propagation by calling event.stoppropagation(). (3) execute DOM level 1 event handler (e.g., onmouseclick) (4) execute the bubble phase handlers. Any of the event handlers can stop the propagation by calling event.stoppropagation(). (5) execute the default browser behaviour. You can override the default behaviour by calling event.preventdefault().

Assignment 1: UTrack App How is your mental and physical health affected by your activities? Good question! In this assignment, you will create a "quantified self" web application called UTrack, which allows users to track their daily activities and various health measures. They will also be able to visualize the data to spot trends and correlations over time. The assignment will reinforce the ideas of event handling as well as model-view-control architecture, which we will visit during the next lecture.