| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131 |
- // Package dom provides GopherJS bindings for the JavaScript DOM APIs.
- //
- // This package is an in progress effort of providing idiomatic Go
- // bindings for the DOM, wrapping the JavaScript DOM APIs. The API is
- // neither complete nor frozen yet, but a great amount of the DOM is
- // already useable.
- //
- // While the package tries to be idiomatic Go, it also tries to stick
- // closely to the JavaScript APIs, so that one does not need to learn
- // a new set of APIs if one is already familiar with it.
- //
- // One decision that hasn't been made yet is what parts exactly should
- // be part of this package. It is, for example, possible that the
- // canvas APIs will live in a separate package. On the other hand,
- // types such as StorageEvent (the event that gets fired when the
- // HTML5 storage area changes) will be part of this package, simply
- // due to how the DOM is structured – even if the actual storage APIs
- // might live in a separate package. This might require special care
- // to avoid circular dependencies.
- //
- // The documentation for some of the identifiers is based on the
- // MDN Web Docs by Mozilla Contributors (https://developer.mozilla.org/en-US/docs/Web/API),
- // licensed under CC-BY-SA 2.5 (https://creativecommons.org/licenses/by-sa/2.5/).
- //
- // # Getting started
- //
- // The usual entry point of using the dom package is by using the
- // GetWindow() function which will return a Window, from which you can
- // get things such as the current Document.
- //
- // # Interfaces
- //
- // The DOM has a big amount of different element and event types, but
- // they all follow three interfaces. All functions that work on or
- // return generic elements/events will return one of the three
- // interfaces Element, HTMLElement or Event. In these interface values
- // there will be concrete implementations, such as
- // HTMLParagraphElement or FocusEvent. It's also not unusual that
- // values of type Element also implement HTMLElement. In all cases,
- // type assertions can be used.
- //
- // Example:
- //
- // el := dom.GetWindow().Document().QuerySelector(".some-element")
- // htmlEl := el.(dom.HTMLElement)
- // pEl := el.(*dom.HTMLParagraphElement)
- //
- // # Live collections
- //
- // Several functions in the JavaScript DOM return "live"
- // collections of elements, that is collections that will be
- // automatically updated when elements get removed or added to the
- // DOM. Our bindings, however, return static slices of elements that,
- // once created, will not automatically reflect updates to the DOM.
- // This is primarily done so that slices can actually be used, as
- // opposed to a form of iterator, but also because we think that
- // magically changing data isn't Go's nature and that snapshots of
- // state are a lot easier to reason about.
- //
- // This does not, however, mean that all objects are snapshots.
- // Elements, events and generally objects that aren't slices or maps
- // are simple wrappers around JavaScript objects, and as such
- // attributes as well as method calls will always return the most
- // current data. To reflect this behaviour, these bindings use
- // pointers to make the semantics clear. Consider the following
- // example:
- //
- // d := dom.GetWindow().Document()
- // e1 := d.GetElementByID("my-element")
- // e2 := d.GetElementByID("my-element")
- //
- // e1.Class().SetString("some-class")
- // println(e1.Class().String() == e2.Class().String())
- //
- // The above example will print `true`.
- //
- // # DOMTokenList
- //
- // Some objects in the JS API have two versions of attributes, one
- // that returns a string and one that returns a DOMTokenList to ease
- // manipulation of string-delimited lists. Some other objects only
- // provide DOMTokenList, sometimes DOMSettableTokenList. To simplify
- // these bindings, only the DOMTokenList variant will be made
- // available, by the type TokenList. In cases where the string
- // attribute was the only way to completely replace the value, our
- // TokenList will provide Set([]string) and SetString(string) methods,
- // which will be able to accomplish the same. Additionally, our
- // TokenList will provide methods to convert it to strings and slices.
- //
- // # Backwards compatibility
- //
- // This package has a relatively stable API. However, there will be
- // backwards incompatible changes from time to time. This is because
- // the package isn't complete yet, as well as because the DOM is a
- // moving target, and APIs do change sometimes.
- //
- // While an attempt is made to reduce changing function signatures to
- // a minimum, it can't always be guaranteed. Sometimes mistakes in the
- // bindings are found that require changing arguments or return
- // values.
- //
- // Interfaces defined in this package may also change on a
- // semi-regular basis, as new methods are added to them. This happens
- // because the bindings aren't complete and can never really be, as
- // new features are added to the DOM.
- package dom // import "honnef.co/go/js/dom"
- import (
- "image"
- "image/color"
- "strings"
- "time"
- "github.com/gopherjs/gopherjs/js"
- )
- // toString returns the string representation of o. If o is nil or
- // undefined, the empty string will be returned instead.
- func toString(o *js.Object) string {
- if o == nil || o == js.Undefined {
- return ""
- }
- return o.String()
- }
- func callRecover(o *js.Object, fn string, args ...interface{}) (err error) {
- defer func() {
- e := recover()
- if e == nil {
- return
- }
- if panicErr, ok := e.(error); ok && panicErr != nil {
- err = panicErr
- } else {
- panic(e)
- }
- }()
- o.Call(fn, args...)
- return nil
- }
- func elementConstructor(o *js.Object) *js.Object {
- if n := o.Get("node"); n != js.Undefined {
- // Support elements wrapped in Polymer's DOM APIs.
- return n.Get("constructor")
- }
- return o.Get("constructor")
- }
- func arrayToObjects(o *js.Object) []*js.Object {
- var out []*js.Object
- for i := 0; i < o.Length(); i++ {
- out = append(out, o.Index(i))
- }
- return out
- }
- func nodeListToObjects(o *js.Object) []*js.Object {
- if o.Get("constructor") == js.Global.Get("Array") {
- // Support Polymer's DOM APIs, which uses Arrays instead of
- // NodeLists
- return arrayToObjects(o)
- }
- var out []*js.Object
- length := o.Get("length").Int()
- for i := 0; i < length; i++ {
- out = append(out, o.Call("item", i))
- }
- return out
- }
- func nodeListToNodes(o *js.Object) []Node {
- var out []Node
- for _, obj := range nodeListToObjects(o) {
- out = append(out, wrapNode(obj))
- }
- return out
- }
- func nodeListToElements(o *js.Object) []Element {
- var out []Element
- for _, obj := range nodeListToObjects(o) {
- out = append(out, wrapElement(obj))
- }
- return out
- }
- func nodeListToHTMLElements(o *js.Object) []HTMLElement {
- var out []HTMLElement
- for _, obj := range nodeListToObjects(o) {
- out = append(out, wrapHTMLElement(obj))
- }
- return out
- }
- func WrapDocument(o *js.Object) Document {
- return wrapDocument(o)
- }
- func WrapDocumentFragment(o *js.Object) DocumentFragment {
- return wrapDocumentFragment(o)
- }
- func WrapNode(o *js.Object) Node {
- return wrapNode(o)
- }
- func WrapElement(o *js.Object) Element {
- return wrapElement(o)
- }
- func WrapHTMLElement(o *js.Object) HTMLElement {
- return wrapHTMLElement(o)
- }
- func wrapDocument(o *js.Object) Document {
- switch elementConstructor(o) {
- case js.Global.Get("HTMLDocument"):
- return &htmlDocument{&document{&BasicNode{o}}}
- default:
- return &document{&BasicNode{o}}
- }
- }
- func wrapDocumentFragment(o *js.Object) DocumentFragment {
- switch elementConstructor(o) {
- // TODO: do we have any other stuff we want to check
- default:
- return &documentFragment{&BasicNode{o}}
- }
- }
- func wrapNode(o *js.Object) Node {
- if o == nil || o == js.Undefined {
- return nil
- }
- switch elementConstructor(o) {
- // TODO all the non-element cases
- case js.Global.Get("Text"):
- return &Text{&BasicNode{o}}
- default:
- return wrapElement(o)
- }
- }
- func wrapElement(o *js.Object) Element {
- if o == nil || o == js.Undefined {
- return nil
- }
- switch elementConstructor(o) {
- // TODO all the non-HTML cases
- default:
- return wrapHTMLElement(o)
- }
- }
- func wrapHTMLElement(o *js.Object) HTMLElement {
- if o == nil || o == js.Undefined {
- return nil
- }
- el := &BasicHTMLElement{&BasicElement{&BasicNode{o}}}
- c := elementConstructor(o)
- switch c {
- case js.Global.Get("HTMLAnchorElement"):
- return &HTMLAnchorElement{BasicHTMLElement: el, URLUtils: &URLUtils{Object: o}}
- case js.Global.Get("HTMLAppletElement"):
- return &HTMLAppletElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLAreaElement"):
- return &HTMLAreaElement{BasicHTMLElement: el, URLUtils: &URLUtils{Object: o}}
- case js.Global.Get("HTMLAudioElement"):
- return &HTMLAudioElement{HTMLMediaElement: &HTMLMediaElement{BasicHTMLElement: el}}
- case js.Global.Get("HTMLBaseElement"):
- return &HTMLBaseElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLBodyElement"):
- return &HTMLBodyElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLBRElement"):
- return &HTMLBRElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLButtonElement"):
- return &HTMLButtonElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLCanvasElement"):
- return &HTMLCanvasElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDataElement"):
- return &HTMLDataElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDataListElement"):
- return &HTMLDataListElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDetailsElement"):
- return &HTMLDetailsElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDirectoryElement"):
- return &HTMLDirectoryElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDivElement"):
- return &HTMLDivElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLDListElement"):
- return &HTMLDListElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLEmbedElement"):
- return &HTMLEmbedElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLFieldSetElement"):
- return &HTMLFieldSetElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLFontElement"):
- return &HTMLFontElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLFormElement"):
- return &HTMLFormElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLFrameElement"):
- return &HTMLFrameElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLFrameSetElement"):
- return &HTMLFrameSetElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLHeadElement"):
- return &HTMLHeadElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLHeadingElement"):
- return &HTMLHeadingElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLHtmlElement"):
- return &HTMLHtmlElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLHRElement"):
- return &HTMLHRElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLIFrameElement"):
- return &HTMLIFrameElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLImageElement"):
- return &HTMLImageElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLInputElement"):
- return &HTMLInputElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLKeygenElement"):
- return &HTMLKeygenElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLLabelElement"):
- return &HTMLLabelElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLLegendElement"):
- return &HTMLLegendElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLLIElement"):
- return &HTMLLIElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLLinkElement"):
- return &HTMLLinkElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLMapElement"):
- return &HTMLMapElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLMediaElement"):
- return &HTMLMediaElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLMenuElement"):
- return &HTMLMenuElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLMetaElement"):
- return &HTMLMetaElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLMeterElement"):
- return &HTMLMeterElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLModElement"):
- return &HTMLModElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLObjectElement"):
- return &HTMLObjectElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLOListElement"):
- return &HTMLOListElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLOptGroupElement"):
- return &HTMLOptGroupElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLOptionElement"):
- return &HTMLOptionElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLOutputElement"):
- return &HTMLOutputElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLParagraphElement"):
- return &HTMLParagraphElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLParamElement"):
- return &HTMLParamElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLPreElement"):
- return &HTMLPreElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLProgressElement"):
- return &HTMLProgressElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLQuoteElement"):
- return &HTMLQuoteElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLScriptElement"):
- return &HTMLScriptElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLSelectElement"):
- return &HTMLSelectElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLSourceElement"):
- return &HTMLSourceElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLSpanElement"):
- return &HTMLSpanElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLStyleElement"):
- return &HTMLStyleElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableElement"):
- return &HTMLTableElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableCaptionElement"):
- return &HTMLTableCaptionElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableCellElement"):
- return &HTMLTableCellElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableDataCellElement"):
- return &HTMLTableDataCellElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableHeaderCellElement"):
- return &HTMLTableHeaderCellElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableColElement"):
- return &HTMLTableColElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableRowElement"):
- return &HTMLTableRowElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTableSectionElement"):
- return &HTMLTableSectionElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTemplateElement"):
- return &HTMLTemplateElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTextAreaElement"):
- return &HTMLTextAreaElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTimeElement"):
- return &HTMLTimeElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTitleElement"):
- return &HTMLTitleElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLTrackElement"):
- return &HTMLTrackElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLUListElement"):
- return &HTMLUListElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLUnknownElement"):
- return &HTMLUnknownElement{BasicHTMLElement: el}
- case js.Global.Get("HTMLVideoElement"):
- return &HTMLVideoElement{HTMLMediaElement: &HTMLMediaElement{BasicHTMLElement: el}}
- case js.Global.Get("HTMLElement"):
- return el
- default:
- return el
- }
- }
- func getForm(o *js.Object) *HTMLFormElement {
- form := wrapHTMLElement(o.Get("form"))
- if form == nil {
- return nil
- }
- return form.(*HTMLFormElement)
- }
- func getLabels(o *js.Object) []*HTMLLabelElement {
- labels := nodeListToElements(o.Get("labels"))
- out := make([]*HTMLLabelElement, len(labels))
- for i, label := range labels {
- out[i] = label.(*HTMLLabelElement)
- }
- return out
- }
- func getOptions(o *js.Object, attr string) []*HTMLOptionElement {
- options := nodeListToElements(o.Get(attr))
- out := make([]*HTMLOptionElement, len(options))
- for i, option := range options {
- out[i] = option.(*HTMLOptionElement)
- }
- return out
- }
- func GetWindow() Window {
- return &window{js.Global}
- }
- type TokenList struct {
- dtl *js.Object // the underlying DOMTokenList
- o *js.Object // the object to which the DOMTokenList belongs
- sa string // the name of the corresponding string attribute, empty if there isn't one
- Length int `js:"length"`
- }
- func (tl *TokenList) Item(idx int) string {
- o := tl.dtl.Call("item", idx)
- return toString(o)
- }
- func (tl *TokenList) Contains(token string) bool {
- return tl.dtl.Call("contains", token).Bool()
- }
- func (tl *TokenList) Add(token string) {
- tl.dtl.Call("add", token)
- }
- func (tl *TokenList) Remove(token string) {
- tl.dtl.Call("remove", token)
- }
- func (tl *TokenList) Toggle(token string) {
- tl.dtl.Call("toggle", token)
- }
- func (tl *TokenList) String() string {
- if tl.sa != "" {
- return tl.o.Get(tl.sa).String()
- }
- if tl.dtl.Get("constructor") == js.Global.Get("DOMSettableTokenList") {
- return tl.dtl.Get("value").String()
- }
- // We could manually construct the string, but I am not aware of
- // any case where we have neither a string attribute nor
- // DOMSettableTokenList.
- return ""
- }
- func (tl *TokenList) Slice() []string {
- var out []string
- length := tl.dtl.Get("length").Int()
- for i := 0; i < length; i++ {
- out = append(out, tl.dtl.Call("item", i).String())
- }
- return out
- }
- // SetString sets the TokenList's value to the space-separated list of
- // tokens in s.
- func (tl *TokenList) SetString(s string) {
- if tl.sa != "" {
- tl.o.Set(tl.sa, s)
- return
- }
- if tl.dtl.Get("constructor") == js.Global.Get("DOMSettableTokenList") {
- tl.dtl.Set("value", s)
- return
- }
- // This shouldn't be possible
- panic("no way to SetString on this TokenList")
- }
- // Set sets the TokenList's value to the list of tokens in s.
- //
- // Individual tokens in s shouldn't countain spaces.
- func (tl *TokenList) Set(s []string) {
- tl.SetString(strings.Join(s, " "))
- }
- type Document interface {
- Node
- ParentNode
- Async() bool
- SetAsync(bool)
- Doctype() DocumentType
- DocumentElement() Element
- DocumentURI() string
- Implementation() DOMImplementation
- LastStyleSheetSet() string
- PreferredStyleSheetSet() string // TODO correct type?
- SelectedStyleSheetSet() string // TODO correct type?
- StyleSheets() []StyleSheet // TODO s/StyleSheet/Stylesheet/ ?
- StyleSheetSets() []StyleSheet // TODO correct type?
- AdoptNode(node Node) Node
- ImportNode(node Node, deep bool) Node
- CreateElement(name string) Element
- CreateElementNS(namespace, name string) Element
- CreateTextNode(s string) *Text
- ElementFromPoint(x, y int) Element
- EnableStyleSheetsForSet(name string)
- GetElementsByClassName(name string) []Element
- GetElementsByTagName(name string) []Element
- GetElementsByTagNameNS(ns, name string) []Element
- GetElementByID(id string) Element
- QuerySelector(sel string) Element
- QuerySelectorAll(sel string) []Element
- CreateDocumentFragment() DocumentFragment
- }
- type DocumentFragment interface {
- Node
- ParentNode
- QuerySelector(sel string) Element
- QuerySelectorAll(sel string) []Element
- GetElementByID(id string) Element
- }
- type HTMLDocument interface {
- Document
- ActiveElement() HTMLElement
- Body() HTMLElement
- Cookie() string
- SetCookie(string)
- DefaultView() Window
- DesignMode() bool
- SetDesignMode(bool)
- Domain() string
- SetDomain(string)
- Forms() []*HTMLFormElement
- Head() *HTMLHeadElement
- Images() []*HTMLImageElement
- LastModified() time.Time
- Links() []HTMLElement
- Location() *Location
- Plugins() []*HTMLEmbedElement
- ReadyState() string
- Referrer() string
- Scripts() []*HTMLScriptElement
- Title() string
- SetTitle(string)
- URL() string
- // TODO HTMLDocument methods
- }
- type documentFragment struct {
- *BasicNode
- }
- func (d documentFragment) GetElementByID(id string) Element {
- return wrapElement(d.Call("getElementById", id))
- }
- func (d documentFragment) QuerySelector(sel string) Element {
- return (&BasicElement{&BasicNode{d.Object}}).QuerySelector(sel)
- }
- func (d documentFragment) QuerySelectorAll(sel string) []Element {
- return (&BasicElement{&BasicNode{d.Object}}).QuerySelectorAll(sel)
- }
- type document struct {
- *BasicNode
- }
- type htmlDocument struct {
- *document
- }
- func (d *htmlDocument) ActiveElement() HTMLElement {
- return wrapHTMLElement(d.Get("activeElement"))
- }
- func (d *htmlDocument) Body() HTMLElement {
- return wrapHTMLElement(d.Get("body"))
- }
- func (d *htmlDocument) Cookie() string {
- return d.Get("cookie").String()
- }
- func (d *htmlDocument) SetCookie(s string) {
- d.Set("cookie", s)
- }
- func (d *htmlDocument) DefaultView() Window {
- return &window{d.Get("defaultView")}
- }
- func (d *htmlDocument) DesignMode() bool {
- s := d.Get("designMode").String()
- return s != "off"
- }
- func (d *htmlDocument) SetDesignMode(b bool) {
- s := "off"
- if b {
- s = "on"
- }
- d.Set("designMode", s)
- }
- func (d *htmlDocument) Domain() string {
- return d.Get("domain").String()
- }
- func (d *htmlDocument) SetDomain(s string) {
- d.Set("domain", s)
- }
- func (d *htmlDocument) Forms() []*HTMLFormElement {
- var els []*HTMLFormElement
- forms := d.Get("forms")
- length := forms.Get("length").Int()
- for i := 0; i < length; i++ {
- els = append(els, wrapHTMLElement(forms.Call("item", i)).(*HTMLFormElement))
- }
- return els
- }
- func (d *htmlDocument) Head() *HTMLHeadElement {
- head := wrapElement(d.Get("head"))
- if head == nil {
- return nil
- }
- return head.(*HTMLHeadElement)
- }
- func (d *htmlDocument) Images() []*HTMLImageElement {
- var els []*HTMLImageElement
- images := d.Get("images")
- length := images.Get("length").Int()
- for i := 0; i < length; i++ {
- els = append(els, wrapHTMLElement(images.Call("item", i)).(*HTMLImageElement))
- }
- return els
- }
- func (d *htmlDocument) LastModified() time.Time {
- return d.Get("lastModified").Interface().(time.Time)
- }
- func (d *htmlDocument) Links() []HTMLElement {
- var els []HTMLElement
- links := d.Get("links")
- length := links.Get("length").Int()
- for i := 0; i < length; i++ {
- els = append(els, wrapHTMLElement(links.Call("item", i)))
- }
- return els
- }
- func (d *htmlDocument) Location() *Location {
- o := d.Get("location")
- return &Location{Object: o, URLUtils: &URLUtils{Object: o}}
- }
- func (d *htmlDocument) Plugins() []*HTMLEmbedElement {
- var els []*HTMLEmbedElement
- forms := d.Get("plugins")
- length := forms.Get("length").Int()
- for i := 0; i < length; i++ {
- els = append(els, wrapHTMLElement(forms.Call("item", i)).(*HTMLEmbedElement))
- }
- return els
- }
- func (d *htmlDocument) ReadyState() string {
- return d.Get("readyState").String()
- }
- func (d *htmlDocument) Referrer() string {
- return d.Get("referrer").String()
- }
- func (d *htmlDocument) Scripts() []*HTMLScriptElement {
- var els []*HTMLScriptElement
- forms := d.Get("scripts")
- length := forms.Get("length").Int()
- for i := 0; i < length; i++ {
- els = append(els, wrapHTMLElement(forms.Call("item", i)).(*HTMLScriptElement))
- }
- return els
- }
- func (d *htmlDocument) Title() string {
- return d.Get("title").String()
- }
- func (d *htmlDocument) SetTitle(s string) {
- d.Set("title", s)
- }
- func (d *htmlDocument) URL() string {
- return d.Get("URL").String()
- }
- func (d document) Async() bool {
- return d.Get("async").Bool()
- }
- func (d document) SetAsync(b bool) {
- d.Set("async", b)
- }
- func (d document) Doctype() DocumentType {
- // FIXME implement
- panic("not implemented")
- }
- func (d document) DocumentElement() Element {
- return wrapElement(d.Get("documentElement"))
- }
- func (d document) DocumentURI() string {
- return d.Get("documentURI").String()
- }
- func (d document) Implementation() DOMImplementation {
- // FIXME implement
- panic("not implemented")
- }
- func (d document) LastStyleSheetSet() string {
- return d.Get("lastStyleSheetSet").String()
- }
- func (d document) PreferredStyleSheetSet() string {
- return d.Get("preferredStyleSheetSet").String()
- }
- func (d document) SelectedStyleSheetSet() string {
- return d.Get("selectedStyleSheetSet").String()
- }
- func (d document) StyleSheets() []StyleSheet {
- // FIXME implement
- panic("not implemented")
- }
- func (d document) StyleSheetSets() []StyleSheet {
- // FIXME implement
- panic("not implemented")
- }
- func (d document) AdoptNode(node Node) Node {
- return wrapNode(d.Call("adoptNode", node.Underlying()))
- }
- func (d document) ImportNode(node Node, deep bool) Node {
- return wrapNode(d.Call("importNode", node.Underlying(), deep))
- }
- func (d document) CreateDocumentFragment() DocumentFragment {
- return wrapDocumentFragment(d.Call("createDocumentFragment"))
- }
- func (d document) CreateElement(name string) Element {
- return wrapElement(d.Call("createElement", name))
- }
- func (d document) CreateElementNS(ns string, name string) Element {
- return wrapElement(d.Call("createElementNS", ns, name))
- }
- func (d document) CreateTextNode(s string) *Text {
- return wrapNode(d.Call("createTextNode", s)).(*Text)
- }
- func (d document) ElementFromPoint(x, y int) Element {
- return wrapElement(d.Call("elementFromPoint", x, y))
- }
- func (d document) EnableStyleSheetsForSet(name string) {
- d.Call("enableStyleSheetsForSet", name)
- }
- func (d document) GetElementsByClassName(name string) []Element {
- return (&BasicElement{&BasicNode{d.Object}}).GetElementsByClassName(name)
- }
- func (d document) GetElementsByTagName(name string) []Element {
- return (&BasicElement{&BasicNode{d.Object}}).GetElementsByTagName(name)
- }
- func (d document) GetElementsByTagNameNS(ns, name string) []Element {
- return (&BasicElement{&BasicNode{d.Object}}).GetElementsByTagNameNS(ns, name)
- }
- func (d document) GetElementByID(id string) Element {
- return wrapElement(d.Call("getElementById", id))
- }
- func (d document) QuerySelector(sel string) Element {
- return (&BasicElement{&BasicNode{d.Object}}).QuerySelector(sel)
- }
- func (d document) QuerySelectorAll(sel string) []Element {
- return (&BasicElement{&BasicNode{d.Object}}).QuerySelectorAll(sel)
- }
- type URLUtils struct {
- *js.Object
- Href string `js:"href"`
- Protocol string `js:"protocol"`
- Host string `js:"host"`
- Hostname string `js:"hostname"`
- Port string `js:"port"`
- Pathname string `js:"pathname"`
- Search string `js:"search"`
- Hash string `js:"hash"`
- Username string `js:"username"`
- Password string `js:"password"`
- Origin string `js:"origin"`
- }
- // TODO Location methods
- type Location struct {
- *js.Object
- *URLUtils
- }
- type HTMLElement interface {
- Element
- GlobalEventHandlers
- AccessKey() string
- Dataset() map[string]string
- SetAccessKey(string)
- AccessKeyLabel() string
- SetAccessKeyLabel(string)
- ContentEditable() string
- SetContentEditable(string)
- IsContentEditable() bool
- Dir() string
- SetDir(string)
- Draggable() bool
- SetDraggable(bool)
- Lang() string
- SetLang(string)
- OffsetHeight() float64
- OffsetLeft() float64
- OffsetParent() HTMLElement
- OffsetTop() float64
- OffsetWidth() float64
- Style() *CSSStyleDeclaration
- Title() string
- SetTitle(string)
- Blur()
- Click()
- Focus()
- }
- type SVGElement interface {
- Element
- // TODO
- }
- type GlobalEventHandlers interface{}
- type Window interface {
- EventTarget
- Console() *Console
- Document() Document
- FrameElement() Element
- Location() *Location
- Name() string
- SetName(string)
- InnerHeight() int
- InnerWidth() int
- Length() int
- Opener() Window
- OuterHeight() int
- OuterWidth() int
- ScrollX() int
- ScrollY() int
- Parent() Window
- ScreenX() int
- ScreenY() int
- ScrollMaxX() int
- ScrollMaxY() int
- Top() Window
- History() History
- Navigator() Navigator
- Screen() *Screen
- Alert(string)
- Back()
- Blur()
- CancelAnimationFrame(int)
- ClearInterval(int)
- ClearTimeout(int)
- Close()
- Confirm(string) bool
- Focus()
- Forward()
- GetComputedStyle(el Element, pseudoElt string) *CSSStyleDeclaration
- GetSelection() Selection
- Home()
- MoveBy(dx, dy int)
- MoveTo(x, y int)
- Open(url, name, features string) Window
- OpenDialog(url, name, features string, args []interface{}) Window
- PostMessage(message string, target string, transfer []interface{})
- Print()
- Prompt(prompt string, initial string) string
- RequestAnimationFrame(callback func(time.Duration)) int
- ResizeBy(dw, dh int)
- ResizeTo(w, h int)
- Scroll(x, y int)
- ScrollBy(dx, dy int)
- ScrollByLines(int)
- ScrollTo(x, y int)
- SetCursor(name string)
- SetInterval(fn func(), delay int) int
- SetTimeout(fn func(), delay int) int
- Stop()
- // TODO constructors
- }
- type window struct {
- // TODO EventTarget
- *js.Object
- }
- func (w *window) Console() *Console {
- return &Console{w.Get("console")}
- }
- func (w *window) Document() Document {
- return wrapDocument(w.Get("document"))
- }
- func (w *window) FrameElement() Element {
- return wrapElement(w.Get("frameElement"))
- }
- func (w *window) Location() *Location {
- o := w.Get("location")
- return &Location{Object: o, URLUtils: &URLUtils{Object: o}}
- }
- func (w *window) Name() string {
- return w.Get("name").String()
- }
- func (w *window) SetName(s string) {
- w.Set("name", s)
- }
- func (w *window) InnerHeight() int {
- return w.Get("innerHeight").Int()
- }
- func (w *window) InnerWidth() int {
- return w.Get("innerWidth").Int()
- }
- func (w *window) Length() int {
- return w.Get("length").Int()
- }
- func (w *window) Opener() Window {
- return &window{w.Get("opener")}
- }
- func (w *window) OuterHeight() int {
- return w.Get("outerHeight").Int()
- }
- func (w *window) OuterWidth() int {
- return w.Get("outerWidth").Int()
- }
- func (w *window) ScrollX() int {
- return w.Get("scrollX").Int()
- }
- func (w *window) ScrollY() int {
- return w.Get("scrollY").Int()
- }
- func (w *window) Parent() Window {
- return &window{w.Get("parent")}
- }
- func (w *window) ScreenX() int {
- return w.Get("screenX").Int()
- }
- func (w *window) ScreenY() int {
- return w.Get("screenY").Int()
- }
- func (w *window) ScrollMaxX() int {
- return w.Get("scrollMaxX").Int()
- }
- func (w *window) ScrollMaxY() int {
- return w.Get("scrollMaxY").Int()
- }
- func (w *window) Top() Window {
- return &window{w.Get("top")}
- }
- func (w *window) History() History {
- // FIXME implement
- return nil
- }
- func (w *window) Navigator() Navigator {
- // FIXME implement
- panic("not implemented")
- }
- func (w *window) Screen() *Screen {
- return &Screen{Object: w.Get("screen")}
- }
- func (w *window) Alert(msg string) {
- w.Call("alert", msg)
- }
- func (w *window) Back() {
- w.Call("back")
- }
- func (w *window) Blur() {
- w.Call("blur")
- }
- func (w *window) ClearInterval(id int) {
- w.Call("clearInterval", id)
- }
- func (w *window) ClearTimeout(id int) {
- w.Call("clearTimeout", id)
- }
- func (w *window) Close() {
- w.Call("close")
- }
- func (w *window) Confirm(prompt string) bool {
- return w.Call("confirm", prompt).Bool()
- }
- func (w *window) Focus() {
- w.Call("focus")
- }
- func (w *window) Forward() {
- w.Call("forward")
- }
- // GetComputedStyle returns the values of all CSS properties of an
- // element after applying the active stylesheets. pseudoElt specifies
- // the pseudo-element to match. For normal elements, it must be the
- // empty string.
- func (w *window) GetComputedStyle(el Element, pseudoElt string) *CSSStyleDeclaration {
- var optArg interface{}
- if pseudoElt != "" {
- optArg = pseudoElt
- }
- return &CSSStyleDeclaration{w.Call("getComputedStyle", el.Underlying(), optArg)}
- }
- func (w *window) GetSelection() Selection {
- // FIXME implement
- panic("not implemented")
- }
- func (w *window) Home() {
- w.Call("home")
- }
- func (w *window) MoveBy(dx, dy int) {
- w.Call("moveBy", dx, dy)
- }
- func (w *window) MoveTo(x, y int) {
- w.Call("moveTo", x, y)
- }
- func (w *window) Open(url, name, features string) Window {
- return &window{w.Call("open", url, name, features)}
- }
- func (w *window) OpenDialog(url, name, features string, args []interface{}) Window {
- return &window{w.Call("openDialog", url, name, features, args)}
- }
- func (w *window) PostMessage(message string, target string, transfer []interface{}) {
- w.Call("postMessage", message, target, transfer)
- }
- func (w *window) Print() {
- w.Call("print")
- }
- func (w *window) Prompt(prompt string, initial string) string {
- return w.Call("prompt", prompt, initial).String()
- }
- func (w *window) ResizeBy(dw, dh int) {
- w.Call("resizeBy", dw, dh)
- }
- func (w *window) ResizeTo(width, height int) {
- w.Call("resizeTo", width, height)
- }
- func (w *window) Scroll(x, y int) {
- w.Call("scroll", x, y)
- }
- func (w *window) ScrollBy(dx, dy int) {
- w.Call("scrollBy", dx, dy)
- }
- func (w *window) ScrollByLines(i int) {
- w.Call("scrollByLines", i)
- }
- func (w *window) ScrollTo(x, y int) {
- w.Call("scrollTo", x, y)
- }
- func (w *window) SetCursor(name string) {
- w.Call("setCursor", name)
- }
- func (w *window) SetInterval(fn func(), delay int) int {
- return w.Call("setInterval", fn, delay).Int()
- }
- func (w *window) SetTimeout(fn func(), delay int) int {
- return w.Call("setTimeout", fn, delay).Int()
- }
- func (w *window) Stop() {
- w.Call("stop")
- }
- // TODO reuse util.EventTarget
- func (w *window) AddEventListener(typ string, useCapture bool, listener func(Event)) func(o *js.Object) {
- wrapper := func(o *js.Object) { listener(wrapEvent(o)) }
- w.Call("addEventListener", typ, wrapper, useCapture)
- return wrapper
- }
- func (w *window) RemoveEventListener(typ string, useCapture bool, listener func(*js.Object)) {
- w.Call("removeEventListener", typ, listener, useCapture)
- }
- func (w *window) DispatchEvent(event Event) bool {
- return w.Call("dispatchEvent", event).Bool()
- }
- func wrapDOMHighResTimeStamp(o *js.Object) time.Duration {
- return time.Duration(o.Float() * float64(time.Millisecond))
- }
- func (w *window) RequestAnimationFrame(callback func(time.Duration)) int {
- wrapper := func(o *js.Object) { callback(wrapDOMHighResTimeStamp(o)) }
- return w.Call("requestAnimationFrame", wrapper).Int()
- }
- func (w *window) CancelAnimationFrame(requestID int) {
- w.Call("cancelAnimationFrame", requestID)
- }
- // TODO all the other window methods
- type Selection interface {
- // TODO
- }
- type Screen struct {
- *js.Object
- AvailTop int `js:"availTop"`
- AvailLeft int `js:"availLeft"`
- AvailHeight int `js:"availHeight"`
- AvailWidth int `js:"availWidth"`
- ColorDepth int `js:"colorDepth"`
- Height int `js:"height"`
- Left int `js:"left"`
- PixelDepth int `js:"pixelDepth"`
- Top int `js:"top"`
- Width int `js:"width"`
- }
- func (s *Screen) Orientation() *ScreenOrientation { return &ScreenOrientation{s.Get("orientation")} }
- type ScreenOrientation struct{ *js.Object }
- func (so *ScreenOrientation) AddEventListener(typ string, useCapture bool, listener func(Event)) func(o *js.Object) {
- wrapper := func(o *js.Object) { listener(wrapEvent(o)) }
- so.Call("addEventListener", typ, wrapper, useCapture)
- return wrapper
- }
- func (so *ScreenOrientation) RemoveEventListener(typ string, useCapture bool, listener func(*js.Object)) {
- so.Call("removeEventListener", typ, listener, useCapture)
- }
- func (so *ScreenOrientation) DispatchEvent(event Event) bool {
- return so.Call("dispatchEvent", event).Bool()
- }
- type Navigator interface {
- NavigatorID
- NavigatorLanguage
- NavigatorOnLine
- NavigatorGeolocation
- // NavigatorPlugins
- // NetworkInformation
- CookieEnabled() bool
- DoNotTrack() string
- RegisterProtocolHandler(protocol, uri, title string)
- }
- type NavigatorID interface {
- AppName() string
- AppVersion() string
- Platform() string
- Product() string
- UserAgent() string
- }
- type NavigatorLanguage interface {
- Language() string
- }
- type NavigatorOnLine interface {
- Online() bool
- }
- type NavigatorGeolocation interface {
- Geolocation() Geolocation
- }
- type Geolocation interface {
- // TODO wrap PositionOptions into something that uses the JS
- // object
- CurrentPosition(success func(Position), err func(PositionError), opts PositionOptions) Position
- WatchPosition(success func(Position), err func(PositionError), opts PositionOptions) int
- ClearWatch(int)
- }
- type PositionError struct {
- *js.Object
- Code int `js:"code"`
- }
- func (err *PositionError) Error() string {
- return err.Call("message").String()
- }
- type PositionOptions struct {
- EnableHighAccuracy bool
- Timeout time.Duration
- MaximumAge time.Duration
- }
- type Position struct {
- Coords *Coordinates
- Timestamp time.Time
- }
- type Coordinates struct {
- *js.Object
- Latitude float64 `js:"latitude"`
- Longitude float64 `js:"longitude"`
- Altitude float64 `js:"altitude"`
- Accuracy float64 `js:"accuracy"`
- AltitudeAccuracy float64 `js:"altitudeAccuracy"`
- Heading float64 `js:"heading"`
- Speed float64 `js:"speed"`
- }
- type History interface {
- Length() int
- State() interface{}
- Back()
- Forward()
- Go(offset int)
- PushState(state interface{}, title string, url string)
- ReplaceState(state interface{}, title string, url string)
- }
- type Console struct {
- *js.Object
- // TODO will replace the js/console package
- }
- type SVGDocument interface{}
- type DocumentType interface{}
- type DOMImplementation interface{}
- type StyleSheet interface{}
- type CSSStyleSheet interface{}
- type Node interface {
- EventTarget
- Underlying() *js.Object
- BaseURI() string
- ChildNodes() []Node
- FirstChild() Node
- LastChild() Node
- NextSibling() Node
- NodeName() string
- NodeType() int
- NodeValue() string
- SetNodeValue(string)
- OwnerDocument() Document
- ParentNode() Node
- ParentElement() Element
- PreviousSibling() Node
- TextContent() string
- SetTextContent(string)
- AppendChild(Node)
- CloneNode(deep bool) Node
- CompareDocumentPosition(Node) int
- Contains(Node) bool
- HasChildNodes() bool
- InsertBefore(which Node, before Node)
- IsDefaultNamespace(string) bool
- IsEqualNode(Node) bool
- LookupPrefix() string
- LookupNamespaceURI(string) string
- Normalize()
- RemoveChild(Node)
- ReplaceChild(newChild, oldChild Node)
- }
- // Type BasicNode implements the Node interface and is embedded by
- // concrete node types and element types.
- type BasicNode struct {
- *js.Object
- }
- func (n *BasicNode) Underlying() *js.Object {
- return n.Object
- }
- func (n *BasicNode) AddEventListener(typ string, useCapture bool, listener func(Event)) func(*js.Object) {
- wrapper := func(o *js.Object) { listener(wrapEvent(o)) }
- n.Call("addEventListener", typ, wrapper, useCapture)
- return wrapper
- }
- func (n *BasicNode) RemoveEventListener(typ string, useCapture bool, listener func(*js.Object)) {
- n.Call("removeEventListener", typ, listener, useCapture)
- }
- func (n *BasicNode) DispatchEvent(event Event) bool {
- return n.Call("dispatchEvent", event).Bool()
- }
- func (n *BasicNode) BaseURI() string {
- return n.Get("baseURI").String()
- }
- func (n *BasicNode) ChildNodes() []Node {
- return nodeListToNodes(n.Get("childNodes"))
- }
- func (n *BasicNode) FirstChild() Node {
- return wrapNode(n.Get("firstChild"))
- }
- func (n *BasicNode) LastChild() Node {
- return wrapNode(n.Get("lastChild"))
- }
- func (n *BasicNode) NextSibling() Node {
- return wrapNode(n.Get("nextSibling"))
- }
- func (n *BasicNode) NodeName() string {
- return n.Get("nodeName").String()
- }
- func (n *BasicNode) NodeType() int {
- return n.Get("nodeType").Int()
- }
- func (n *BasicNode) NodeValue() string {
- return toString(n.Get("nodeValue"))
- }
- func (n *BasicNode) SetNodeValue(s string) {
- n.Set("nodeValue", s)
- }
- func (n *BasicNode) OwnerDocument() Document {
- // FIXME implement
- panic("not implemented")
- }
- func (n *BasicNode) ParentNode() Node {
- return wrapNode(n.Get("parentNode"))
- }
- func (n *BasicNode) ParentElement() Element {
- return wrapElement(n.Get("parentElement"))
- }
- func (n *BasicNode) PreviousSibling() Node {
- return wrapNode(n.Get("previousSibling"))
- }
- func (n *BasicNode) TextContent() string {
- return toString(n.Get("textContent"))
- }
- func (n *BasicNode) SetTextContent(s string) {
- n.Set("textContent", s)
- }
- func (n *BasicNode) AppendChild(newchild Node) {
- n.Call("appendChild", newchild.Underlying())
- }
- func (n *BasicNode) CloneNode(deep bool) Node {
- return wrapNode(n.Call("cloneNode", deep))
- }
- const (
- DocumentPositionDisconnected = 1
- DocumentPositionPreceding = 2
- DocumentPositionFollowing = 4
- DocumentPositionContains = 8
- DocumentPositionContainedBy = 16
- DocumentPositionImplementationSpecific = 32
- )
- func (n *BasicNode) CompareDocumentPosition(other Node) int {
- return n.Call("compareDocumentPosition", other.Underlying()).Int()
- }
- func (n *BasicNode) Contains(other Node) bool {
- return n.Call("contains", other.Underlying()).Bool()
- }
- func (n *BasicNode) HasChildNodes() bool {
- return n.Call("hasChildNodes").Bool()
- }
- func (n *BasicNode) InsertBefore(which Node, before Node) {
- var o interface{}
- if before != nil {
- o = before.Underlying()
- }
- n.Call("insertBefore", which.Underlying(), o)
- }
- func (n *BasicNode) IsDefaultNamespace(s string) bool {
- return n.Call("isDefaultNamespace", s).Bool()
- }
- func (n *BasicNode) IsEqualNode(other Node) bool {
- return n.Call("isEqualNode", other.Underlying()).Bool()
- }
- func (n *BasicNode) LookupPrefix() string {
- return n.Call("lookupPrefix").String()
- }
- func (n *BasicNode) LookupNamespaceURI(s string) string {
- return toString(n.Call("lookupNamespaceURI", s))
- }
- func (n *BasicNode) Normalize() {
- n.Call("normalize")
- }
- func (n *BasicNode) RemoveChild(other Node) {
- n.Call("removeChild", other.Underlying())
- }
- func (n *BasicNode) ReplaceChild(newChild, oldChild Node) {
- n.Call("replaceChild", newChild.Underlying(), oldChild.Underlying())
- }
- type Element interface {
- Node
- ParentNode
- ChildNode
- Attributes() map[string]string
- Class() *TokenList
- Closest(string) Element
- ID() string
- SetID(string)
- TagName() string
- GetAttribute(string) string // TODO can attributes only be strings?
- GetAttributeNS(ns string, name string) string // can attributes only be strings?
- GetBoundingClientRect() ClientRect
- GetElementsByClassName(string) []Element
- GetElementsByTagName(string) []Element
- GetElementsByTagNameNS(ns string, name string) []Element
- HasAttribute(string) bool
- HasAttributeNS(ns string, name string) bool
- Matches(string) bool
- QuerySelector(string) Element
- QuerySelectorAll(string) []Element
- Remove()
- RemoveAttribute(string)
- RemoveAttributeNS(ns string, name string)
- SetAttribute(name string, value string)
- SetAttributeNS(ns string, name string, value string)
- InnerHTML() string
- SetInnerHTML(string)
- OuterHTML() string
- SetOuterHTML(string)
- }
- type ClientRect struct {
- *js.Object
- Height float64 `js:"height"`
- Width float64 `js:"width"`
- Left float64 `js:"left"`
- Right float64 `js:"right"`
- Top float64 `js:"top"`
- Bottom float64 `js:"bottom"`
- }
- type ParentNode interface {
- // No properties/methods that aren't experimental
- }
- type ChildNode interface {
- PreviousElementSibling() Element
- NextElementSibling() Element
- }
- // Type BasicHTMLElement implements the HTMLElement interface and is
- // embedded by concrete HTML element types.
- type BasicHTMLElement struct {
- *BasicElement
- // TODO globalEventHandlers
- }
- func (e *BasicHTMLElement) AccessKey() string {
- return e.Get("accessKey").String()
- }
- func (e *BasicHTMLElement) Dataset() map[string]string {
- o := e.Get("dataset")
- data := map[string]string{}
- keys := js.Keys(o)
- for _, key := range keys {
- data[key] = o.Get(key).String()
- }
- return data
- }
- func (e *BasicHTMLElement) SetAccessKey(s string) {
- e.Set("accessKey", s)
- }
- func (e *BasicHTMLElement) AccessKeyLabel() string {
- return e.Get("accessKeyLabel").String()
- }
- func (e *BasicHTMLElement) SetAccessKeyLabel(s string) {
- e.Set("accessKeyLabel", s)
- }
- func (e *BasicHTMLElement) ContentEditable() string {
- return e.Get("contentEditable").String()
- }
- func (e *BasicHTMLElement) SetContentEditable(s string) {
- e.Set("contentEditable", s)
- }
- func (e *BasicHTMLElement) IsContentEditable() bool {
- return e.Get("isContentEditable").Bool()
- }
- func (e *BasicHTMLElement) Dir() string {
- return e.Get("dir").String()
- }
- func (e *BasicHTMLElement) SetDir(s string) {
- e.Set("dir", s)
- }
- func (e *BasicHTMLElement) Draggable() bool {
- return e.Get("draggable").Bool()
- }
- func (e *BasicHTMLElement) SetDraggable(b bool) {
- e.Set("draggable", b)
- }
- func (e *BasicHTMLElement) Lang() string {
- return e.Get("lang").String()
- }
- func (e *BasicHTMLElement) SetLang(s string) {
- e.Set("lang", s)
- }
- func (e *BasicHTMLElement) OffsetHeight() float64 {
- return e.Get("offsetHeight").Float()
- }
- func (e *BasicHTMLElement) OffsetLeft() float64 {
- return e.Get("offsetLeft").Float()
- }
- func (e *BasicHTMLElement) OffsetParent() HTMLElement {
- return wrapHTMLElement(e.Get("offsetParent"))
- }
- func (e *BasicHTMLElement) OffsetTop() float64 {
- return e.Get("offsetTop").Float()
- }
- func (e *BasicHTMLElement) OffsetWidth() float64 {
- return e.Get("offsetWidth").Float()
- }
- func (e *BasicHTMLElement) Style() *CSSStyleDeclaration {
- return &CSSStyleDeclaration{e.Get("style")}
- }
- func (e *BasicHTMLElement) TabIndex() int {
- return e.Get("tabIndex").Int()
- }
- func (e *BasicHTMLElement) SetTabIndex(i int) {
- e.Set("tabIndex", i)
- }
- func (e *BasicHTMLElement) Title() string {
- return e.Get("title").String()
- }
- func (e *BasicHTMLElement) SetTitle(s string) {
- e.Set("title", s)
- }
- func (e *BasicHTMLElement) Blur() {
- e.Call("blur")
- }
- func (e *BasicHTMLElement) Click() {
- e.Call("click")
- }
- func (e *BasicHTMLElement) Focus() {
- e.Call("focus")
- }
- // Type BasicElement implements the Element interface and is embedded
- // by concrete element types and HTML element types.
- type BasicElement struct {
- *BasicNode
- }
- func (e *BasicElement) Attributes() map[string]string {
- o := e.Get("attributes")
- attrs := map[string]string{}
- length := o.Get("length").Int()
- for i := 0; i < length; i++ {
- item := o.Call("item", i)
- attrs[item.Get("name").String()] = item.Get("value").String()
- }
- return attrs
- }
- func (e *BasicElement) GetBoundingClientRect() ClientRect {
- obj := e.Call("getBoundingClientRect")
- return ClientRect{Object: obj}
- }
- func (e *BasicElement) PreviousElementSibling() Element {
- return wrapElement(e.Get("previousElementSibling"))
- }
- func (e *BasicElement) NextElementSibling() Element {
- return wrapElement(e.Get("nextElementSibling"))
- }
- func (e *BasicElement) Class() *TokenList {
- return &TokenList{dtl: e.Get("classList"), o: e.Object, sa: "className"}
- }
- // SetClass sets the element's className attribute to s. Consider
- // using the Class method instead.
- func (e *BasicElement) SetClass(s string) {
- e.Set("className", s)
- }
- func (e *BasicElement) Closest(s string) Element {
- return wrapElement(e.Call("closest", s))
- }
- func (e *BasicElement) ID() string {
- return e.Get("id").String()
- }
- func (e *BasicElement) SetID(s string) {
- e.Set("id", s)
- }
- func (e *BasicElement) TagName() string {
- return e.Get("tagName").String()
- }
- func (e *BasicElement) GetAttribute(name string) string {
- return toString(e.Call("getAttribute", name))
- }
- func (e *BasicElement) GetAttributeNS(ns string, name string) string {
- return toString(e.Call("getAttributeNS", ns, name))
- }
- func (e *BasicElement) GetElementsByClassName(s string) []Element {
- return nodeListToElements(e.Call("getElementsByClassName", s))
- }
- func (e *BasicElement) GetElementsByTagName(s string) []Element {
- return nodeListToElements(e.Call("getElementsByTagName", s))
- }
- func (e *BasicElement) GetElementsByTagNameNS(ns string, name string) []Element {
- return nodeListToElements(e.Call("getElementsByTagNameNS", ns, name))
- }
- func (e *BasicElement) HasAttribute(s string) bool {
- return e.Call("hasAttribute", s).Bool()
- }
- func (e *BasicElement) HasAttributeNS(ns string, name string) bool {
- return e.Call("hasAttributeNS", ns, name).Bool()
- }
- func (e *BasicElement) Matches(s string) bool {
- return e.Call("matches", s).Bool()
- }
- func (e *BasicElement) QuerySelector(s string) Element {
- return wrapElement(e.Call("querySelector", s))
- }
- func (e *BasicElement) QuerySelectorAll(s string) []Element {
- return nodeListToElements(e.Call("querySelectorAll", s))
- }
- func (e *BasicElement) Remove() {
- e.Call("remove")
- }
- func (e *BasicElement) RemoveAttribute(s string) {
- e.Call("removeAttribute", s)
- }
- func (e *BasicElement) RemoveAttributeNS(ns string, name string) {
- e.Call("removeAttributeNS", ns, name)
- }
- func (e *BasicElement) SetAttribute(name string, value string) {
- e.Call("setAttribute", name, value)
- }
- func (e *BasicElement) SetAttributeNS(ns string, name string, value string) {
- e.Call("setAttributeNS", ns, name, value)
- }
- func (e *BasicElement) InnerHTML() string {
- return e.Get("innerHTML").String()
- }
- func (e *BasicElement) SetInnerHTML(s string) {
- e.Set("innerHTML", s)
- }
- func (e *BasicElement) OuterHTML() string {
- return e.Get("outerHTML").String()
- }
- func (e *BasicElement) SetOuterHTML(s string) {
- e.Set("outerHTML", s)
- }
- type HTMLAnchorElement struct {
- *BasicHTMLElement
- *URLUtils
- HrefLang string `js:"hreflang"`
- Media string `js:"media"`
- TabIndex int `js:"tabIndex"`
- Target string `js:"target"`
- Text string `js:"text"`
- Type string `js:"type"`
- }
- func (e *HTMLAnchorElement) Rel() *TokenList {
- return &TokenList{dtl: e.Get("relList"), o: e.Object, sa: "rel"}
- }
- type HTMLAppletElement struct {
- *BasicHTMLElement
- Alt string `js:"alt"`
- Coords string `js:"coords"`
- HrefLang string `js:"hreflang"`
- Media string `js:"media"`
- Search string `js:"search"`
- Shape string `js:"shape"`
- TabIndex int `js:"tabIndex"`
- Target string `js:"target"`
- Type string `js:"type"`
- }
- func (e *HTMLAppletElement) Rel() *TokenList {
- return &TokenList{dtl: e.Get("relList"), o: e.Object, sa: "rel"}
- }
- type HTMLAreaElement struct {
- *BasicHTMLElement
- *URLUtils
- Alt string `js:"alt"`
- Coords string `js:"coords"`
- HrefLang string `js:"hreflang"`
- Media string `js:"media"`
- Search string `js:"search"`
- Shape string `js:"shape"`
- TabIndex int `js:"tabIndex"`
- Target string `js:"target"`
- Type string `js:"type"`
- }
- func (e *HTMLAreaElement) Rel() *TokenList {
- return &TokenList{dtl: e.Get("relList"), o: e.Object, sa: "rel"}
- }
- type HTMLAudioElement struct{ *HTMLMediaElement }
- type HTMLBRElement struct{ *BasicHTMLElement }
- type HTMLBaseElement struct{ *BasicHTMLElement }
- func (e *HTMLBaseElement) Href() string {
- return e.Get("href").String()
- }
- func (e *HTMLBaseElement) Target() string {
- return e.Get("target").String()
- }
- type HTMLBodyElement struct{ *BasicHTMLElement }
- type HTMLButtonElement struct {
- *BasicHTMLElement
- AutoFocus bool `js:"autofocus"`
- Disabled bool `js:"disabled"`
- FormAction string `js:"formAction"`
- FormEncType string `js:"formEncType"`
- FormMethod string `js:"formMethod"`
- FormNoValidate bool `js:"formNoValidate"`
- FormTarget string `js:"formTarget"`
- Name string `js:"name"`
- TabIndex int `js:"tabIndex"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- Value string `js:"value"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLButtonElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLButtonElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLButtonElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLButtonElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLButtonElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLCanvasElement struct {
- *BasicHTMLElement
- Height int `js:"height"`
- Width int `js:"width"`
- }
- type CanvasRenderingContext2D struct {
- *js.Object
- // Colors, Styles, and Shadows
- FillStyle string `js:"fillStyle"`
- StrokeStyle string `js:"strokeStyle"`
- ShadowColor string `js:"shadowColor"`
- ShadowBlur int `js:"shadowBlur"`
- ShadowOffsetX int `js:"shadowOffsetX"`
- ShadowOffsetY int `js:"shadowOffsetY"`
- // Line Styles
- LineCap string `js:"lineCap"`
- LineJoin string `js:"lineJoin"`
- LineWidth int `js:"lineWidth"`
- MiterLimit int `js:"miterLimit"`
- // Text
- Font string `js:"font"`
- TextAlign string `js:"textAlign"`
- TextBaseline string `js:"textBaseline"`
- // Compositing
- GlobalAlpha float64 `js:"globalAlpha"`
- GlobalCompositeOperation string `js:"globalCompositeOperation"`
- }
- type ImageData struct {
- *js.Object
- Width int `js:"width"`
- Height int `js:"height"`
- Data *js.Object `js:"data"`
- }
- func (m *ImageData) ColorModel() color.Model { return color.NRGBAModel }
- func (m *ImageData) Bounds() image.Rectangle {
- return image.Rect(0, 0, m.Width, m.Height)
- }
- func (m *ImageData) At(x, y int) color.Color {
- return m.NRGBAAt(x, y)
- }
- func (m *ImageData) NRGBAAt(x, y int) color.NRGBA {
- if x < 0 || x >= m.Width ||
- y < 0 || y >= m.Height {
- return color.NRGBA{}
- }
- i := (y*m.Width + x) * 4
- return color.NRGBA{
- R: uint8(m.Data.Index(i + 0).Int()),
- G: uint8(m.Data.Index(i + 1).Int()),
- B: uint8(m.Data.Index(i + 2).Int()),
- A: uint8(m.Data.Index(i + 3).Int()),
- }
- }
- func (m *ImageData) Set(x, y int, c color.Color) {
- if x < 0 || x >= m.Width ||
- y < 0 || y >= m.Height {
- return
- }
- c1 := color.NRGBAModel.Convert(c).(color.NRGBA)
- i := (y*m.Width + x) * 4
- m.Data.SetIndex(i+0, c1.R)
- m.Data.SetIndex(i+1, c1.G)
- m.Data.SetIndex(i+2, c1.B)
- m.Data.SetIndex(i+3, c1.A)
- }
- func (m *ImageData) SetNRGBA(x, y int, c color.NRGBA) {
- if x < 0 || x >= m.Width ||
- y < 0 || y >= m.Height {
- return
- }
- i := (y*m.Width + x) * 4
- m.Data.SetIndex(i+0, c.R)
- m.Data.SetIndex(i+1, c.G)
- m.Data.SetIndex(i+2, c.B)
- m.Data.SetIndex(i+3, c.A)
- }
- // CanvasGradient represents an opaque object describing a gradient.
- // It is returned by the methods CanvasRenderingContext2D.CreateLinearGradient
- // or CanvasRenderingContext2D.CreateRadialGradient.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient.
- type CanvasGradient struct {
- *js.Object
- }
- // AddColorStop adds a new stop, defined by an offset and a color, to the gradient.
- // It panics with *js.Error if the offset is not between 0 and 1, or if the color
- // can't be parsed as a CSS <color>.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasGradient/addColorStop.
- func (cg *CanvasGradient) AddColorStop(offset float64, color string) {
- cg.Call("addColorStop", offset, color)
- }
- // CanvasPattern represents an opaque object describing a pattern.
- // It is based on an image, a canvas or a video, created by the
- // CanvasRenderingContext2D.CreatePattern method.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern.
- type CanvasPattern struct {
- *js.Object
- }
- type TextMetrics struct {
- *js.Object
- Width float64 `js:"width"`
- ActualBoundingBoxLeft float64 `js:"actualBoundingBoxLeft"`
- ActualBoundingBoxRight float64 `js:"actualBoundingBoxRight"`
- FontBoundingBoxAscent float64 `js:"fontBoundingBoxAscent"`
- FontBoundingBoxDescent float64 `js:"fontBoundingBoxDescent"`
- ActualBoundingBoxAscent float64 `js:"actualBoundingBoxAscent"`
- ActualBoundingBoxDescent float64 `js:"actualBoundingBoxDescent"`
- EmHeightAscent float64 `js:"emHeightAscent"`
- EmHeightDescent float64 `js:"emHeightDescent"`
- HangingBaseline float64 `js:"hangingBaseline"`
- AlphabeticBaseline float64 `js:"alphabeticBaseline"`
- IdeographicBaseline float64 `js:"ideographicBaseline"`
- }
- // Creating canvas 2d context
- func (e *HTMLCanvasElement) GetContext2d() *CanvasRenderingContext2D {
- ctx := e.GetContext("2d")
- return &CanvasRenderingContext2D{Object: ctx}
- }
- func (e *HTMLCanvasElement) GetContext(param string) *js.Object {
- return e.Call("getContext", param)
- }
- // Drawing Rectangles
- func (ctx *CanvasRenderingContext2D) ClearRect(x, y, width, height float64) {
- ctx.Call("clearRect", x, y, width, height)
- }
- func (ctx *CanvasRenderingContext2D) FillRect(x, y, width, height float64) {
- ctx.Call("fillRect", x, y, width, height)
- }
- func (ctx *CanvasRenderingContext2D) StrokeRect(x, y, width, height float64) {
- ctx.Call("strokeRect", x, y, width, height)
- }
- // Drawing Text
- // FillText fills a given text at the given (x, y) position.
- // If the optional maxWidth parameter is not -1,
- // the text will be scaled to fit that width.
- func (ctx *CanvasRenderingContext2D) FillText(text string, x, y, maxWidth float64) {
- if maxWidth == -1 {
- ctx.Call("fillText", text, x, y)
- return
- }
- ctx.Call("fillText", text, x, y, maxWidth)
- }
- // StrokeText strokes a given text at the given (x, y) position.
- // If the optional maxWidth parameter is not -1,
- // the text will be scaled to fit that width.
- func (ctx *CanvasRenderingContext2D) StrokeText(text string, x, y, maxWidth float64) {
- if maxWidth == -1 {
- ctx.Call("strokeText", text, x, y)
- return
- }
- ctx.Call("strokeText", text, x, y, maxWidth)
- }
- func (ctx *CanvasRenderingContext2D) MeasureText(text string) *TextMetrics {
- textMetrics := ctx.Call("measureText", text)
- return &TextMetrics{Object: textMetrics}
- }
- // Line styles
- func (ctx *CanvasRenderingContext2D) GetLineDash() []float64 {
- var dashes []float64
- for _, dash := range ctx.Call("getLineDash").Interface().([]interface{}) {
- dashes = append(dashes, dash.(float64))
- }
- return dashes
- }
- func (ctx *CanvasRenderingContext2D) SetLineDash(dashes []float64) {
- ctx.Call("setLineDash", dashes)
- }
- // Gradients and patterns
- // CreateLinearGradient creates a linear gradient along the line given
- // by the coordinates represented by the parameters.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createLinearGradient.
- func (ctx *CanvasRenderingContext2D) CreateLinearGradient(x0, y0, x1, y1 float64) *CanvasGradient {
- return &CanvasGradient{Object: ctx.Call("createLinearGradient", x0, y0, x1, y1)}
- }
- // CreateRadialGradient creates a radial gradient given by the coordinates of the two circles
- // represented by the parameters.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createRadialGradient.
- func (ctx *CanvasRenderingContext2D) CreateRadialGradient(x0, y0, r0, x1, y1, r1 float64) *CanvasGradient {
- return &CanvasGradient{Object: ctx.Call("createRadialGradient", x0, y0, r0, x1, y1, r1)}
- }
- // CreatePattern creates a pattern using the specified image (a CanvasImageSource).
- // It repeats the source in the directions specified by the repetition argument.
- //
- // Reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/createPattern.
- func (ctx *CanvasRenderingContext2D) CreatePattern(image Element, repetition string) *CanvasPattern {
- return &CanvasPattern{Object: ctx.Call("createPattern", image, repetition)}
- }
- // Paths
- func (ctx *CanvasRenderingContext2D) BeginPath() {
- ctx.Call("beginPath")
- }
- func (ctx *CanvasRenderingContext2D) ClosePath() {
- ctx.Call("closePath")
- }
- func (ctx *CanvasRenderingContext2D) MoveTo(x, y float64) {
- ctx.Call("moveTo", x, y)
- }
- func (ctx *CanvasRenderingContext2D) LineTo(x, y float64) {
- ctx.Call("lineTo", x, y)
- }
- func (ctx *CanvasRenderingContext2D) BezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y float64) {
- ctx.Call("bezierCurveTo", cp1x, cp1y, cp2x, cp2y, x, y)
- }
- func (ctx *CanvasRenderingContext2D) QuadraticCurveTo(cpx, cpy, x, y float64) {
- ctx.Call("quadraticCurveTo", cpx, cpy, x, y)
- }
- func (ctx *CanvasRenderingContext2D) Arc(x, y, r, sAngle, eAngle float64, counterclockwise bool) {
- ctx.Call("arc", x, y, r, sAngle, eAngle, counterclockwise)
- }
- func (ctx *CanvasRenderingContext2D) ArcTo(x1, y1, x2, y2, r float64) {
- ctx.Call("arcTo", x1, y1, x2, y2, r)
- }
- func (ctx *CanvasRenderingContext2D) Ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle float64, anticlockwise bool) {
- ctx.Call("ellipse", x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise)
- }
- func (ctx *CanvasRenderingContext2D) Rect(x, y, width, height float64) {
- ctx.Call("rect", x, y, width, height)
- }
- // Drawing paths
- func (ctx *CanvasRenderingContext2D) Fill() {
- ctx.Call("fill")
- }
- func (ctx *CanvasRenderingContext2D) Stroke() {
- ctx.Call("stroke")
- }
- func (ctx *CanvasRenderingContext2D) DrawFocusIfNeeded(element HTMLElement, path *js.Object) {
- ctx.Call("drawFocusIfNeeded", element, path)
- }
- func (ctx *CanvasRenderingContext2D) ScrollPathIntoView(path *js.Object) {
- ctx.Call("scrollPathIntoView", path)
- }
- func (ctx *CanvasRenderingContext2D) Clip() {
- ctx.Call("clip")
- }
- func (ctx *CanvasRenderingContext2D) IsPointInPath(x, y float64) bool {
- return ctx.Call("isPointInPath", x, y).Bool()
- }
- func (ctx *CanvasRenderingContext2D) IsPointInStroke(path *js.Object, x, y float64) bool {
- return ctx.Call("isPointInStroke", path, x, y).Bool()
- }
- // Transformations
- func (ctx *CanvasRenderingContext2D) Rotate(angle float64) {
- ctx.Call("rotate", angle)
- }
- func (ctx *CanvasRenderingContext2D) Scale(scaleWidth, scaleHeight float64) {
- ctx.Call("scale", scaleWidth, scaleHeight)
- }
- func (ctx *CanvasRenderingContext2D) Translate(x, y float64) {
- ctx.Call("translate", x, y)
- }
- func (ctx *CanvasRenderingContext2D) Transform(a, b, c, d, e, f float64) {
- ctx.Call("transform", a, b, c, d, e, f)
- }
- func (ctx *CanvasRenderingContext2D) SetTransform(a, b, c, d, e, f float64) {
- ctx.Call("setTransform", a, b, c, d, e, f)
- }
- func (ctx *CanvasRenderingContext2D) ResetTransform() {
- ctx.Call("resetTransform")
- }
- // Drawing images
- func (ctx *CanvasRenderingContext2D) DrawImage(image Element, dx, dy float64) {
- ctx.Call("drawImage", image, dx, dy)
- }
- func (ctx *CanvasRenderingContext2D) DrawImageWithDst(image Element, dx, dy, dWidth, dHeight float64) {
- ctx.Call("drawImage", image, dx, dy, dWidth, dHeight)
- }
- func (ctx *CanvasRenderingContext2D) DrawImageWithSrcAndDst(image Element, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight float64) {
- ctx.Call("drawImage", image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight)
- }
- // Pixel manipulation
- func (ctx *CanvasRenderingContext2D) CreateImageData(width, height int) *ImageData {
- return &ImageData{Object: ctx.Call("createImageData", width, height)}
- }
- func (ctx *CanvasRenderingContext2D) GetImageData(sx, sy, sw, sh int) *ImageData {
- return &ImageData{Object: ctx.Call("getImageData", sx, sy, sw, sh)}
- }
- func (ctx *CanvasRenderingContext2D) PutImageData(imageData *ImageData, dx, dy float64) {
- ctx.Call("putImageData", imageData, dx, dy)
- }
- func (ctx *CanvasRenderingContext2D) PutImageDataDirty(imageData *ImageData, dx, dy float64, dirtyX, dirtyY, dirtyWidth, dirtyHeight int) {
- ctx.Call("putImageData", imageData, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
- }
- // State
- func (ctx *CanvasRenderingContext2D) Save() {
- ctx.Call("save")
- }
- func (ctx *CanvasRenderingContext2D) Restore() {
- ctx.Call("restore")
- }
- // TODO Hit regions:
- // addHitRegion
- // removeHitRegion
- // clearHitRegions
- type HTMLDListElement struct{ *BasicHTMLElement }
- type HTMLDataElement struct {
- *BasicHTMLElement
- Value string `js:"value"`
- }
- type HTMLDataListElement struct{ *BasicHTMLElement }
- func (e *HTMLDataListElement) Options() []*HTMLOptionElement {
- return getOptions(e.Object, "options")
- }
- type HTMLDetailsElement struct {
- *BasicHTMLElement
- Open bool `js:"open"`
- }
- type HTMLDirectoryElement struct{ *BasicHTMLElement }
- type HTMLDivElement struct{ *BasicHTMLElement }
- type HTMLEmbedElement struct {
- *BasicHTMLElement
- Src string `js:"src"`
- Type string `js:"type"`
- Width string `js:"width"`
- }
- type HTMLFieldSetElement struct {
- *BasicHTMLElement
- Disabled bool `js:"disabled"`
- Name string `js:"name"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLFieldSetElement) Elements() []HTMLElement {
- return nodeListToHTMLElements(e.Get("elements"))
- }
- func (e *HTMLFieldSetElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLFieldSetElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLFieldSetElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLFieldSetElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLFontElement struct{ *BasicHTMLElement }
- type HTMLFormElement struct {
- *BasicHTMLElement
- AcceptCharset string `js:"acceptCharset"`
- Action string `js:"action"`
- Autocomplete string `js:"autocomplete"`
- Encoding string `js:"encoding"`
- Enctype string `js:"enctype"`
- Length int `js:"length"`
- Method string `js:"method"`
- Name string `js:"name"`
- NoValidate bool `js:"noValidate"`
- Target string `js:"target"`
- }
- func (e *HTMLFormElement) Elements() []HTMLElement {
- return nodeListToHTMLElements(e.Get("elements"))
- }
- func (e *HTMLFormElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLFormElement) Submit() {
- e.Call("submit")
- }
- func (e *HTMLFormElement) Reset() {
- e.Call("reset")
- }
- func (e *HTMLFormElement) Item(index int) HTMLElement {
- return wrapHTMLElement(e.Call("item", index))
- }
- func (e *HTMLFormElement) NamedItem(name string) HTMLElement {
- return wrapHTMLElement(e.Call("namedItem", name))
- }
- type HTMLFrameElement struct{ *BasicHTMLElement }
- type HTMLFrameSetElement struct{ *BasicHTMLElement }
- type HTMLHRElement struct{ *BasicHTMLElement }
- type HTMLHeadElement struct{ *BasicHTMLElement }
- type HTMLHeadingElement struct{ *BasicHTMLElement }
- type HTMLHtmlElement struct{ *BasicHTMLElement }
- type HTMLIFrameElement struct {
- *BasicHTMLElement
- Width string `js:"width"`
- Height string `js:"height"`
- Name string `js:"name"`
- Src string `js:"src"`
- SrcDoc string `js:"srcdoc"`
- Seamless bool `js:"seamless"`
- // TODO sandbox attribute
- }
- func (e *HTMLIFrameElement) ContentDocument() Document {
- return wrapDocument(e.Get("contentDocument"))
- }
- func (e *HTMLIFrameElement) ContentWindow() Window {
- return &window{e.Get("contentWindow")}
- }
- type HTMLImageElement struct {
- *BasicHTMLElement
- Complete bool `js:"complete"`
- CrossOrigin string `js:"crossOrigin"`
- Height int `js:"height"`
- IsMap bool `js:"isMap"`
- NaturalHeight int `js:"naturalHeight"`
- NaturalWidth int `js:"naturalWidth"`
- Src string `js:"src"`
- UseMap string `js:"useMap"`
- Width int `js:"width"`
- // TODO constructor
- }
- type HTMLInputElement struct {
- *BasicHTMLElement
- Accept string `js:"accept"`
- Alt string `js:"alt"`
- Autocomplete string `js:"autocomplete"`
- Autofocus bool `js:"autofocus"`
- Checked bool `js:"checked"`
- DefaultChecked bool `js:"defaultChecked"`
- DefaultValue string `js:"defaultValue"`
- DirName string `js:"dirName"`
- Disabled bool `js:"disabled"`
- FormAction string `js:"formAction"`
- FormEncType string `js:"formEncType"`
- FormMethod string `js:"formMethod"`
- FormNoValidate bool `js:"formNoValidate"`
- FormTarget string `js:"formTarget"`
- Height string `js:"height"`
- Indeterminate bool `js:"indeterminate"`
- Max string `js:"max"`
- MaxLength int `js:"maxLength"`
- Min string `js:"min"`
- Multiple bool `js:"multiple"`
- Name string `js:"name"`
- Pattern string `js:"pattern"`
- Placeholder string `js:"placeholder"`
- ReadOnly bool `js:"readOnly"`
- Required bool `js:"required"`
- SelectionDirection string `js:"selectionDirection"`
- SelectionEnd int `js:"selectionEnd"`
- SelectionStart int `js:"selectionStart"`
- Size int `js:"size"`
- Src string `js:"src"`
- Step string `js:"step"`
- TabIndex int `js:"tabIndex"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- Value string `js:"value"`
- ValueAsDate time.Time `js:"valueAsDate"`
- ValueAsNumber float64 `js:"valueAsNumber"`
- Width string `js:"width"`
- WillValidate bool `js:"willValidate"`
- }
- // File represents files as can be obtained from file choosers or drag
- // and drop. The dom package does not define any methods on File nor
- // does it provide access to the blob or a way to read it.
- type File struct {
- *js.Object
- }
- func (e *HTMLInputElement) Files() []*File {
- files := e.Get("files")
- out := make([]*File, files.Get("length").Int())
- for i := range out {
- out[i] = &File{files.Call("item", i)}
- }
- return out
- }
- func (e *HTMLInputElement) List() *HTMLDataListElement {
- list := wrapHTMLElement(e.Get("list"))
- if list == nil {
- return nil
- }
- return list.(*HTMLDataListElement)
- }
- func (e *HTMLInputElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLInputElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLInputElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLInputElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLInputElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- func (e *HTMLInputElement) Select() {
- e.Call("select")
- }
- func (e *HTMLInputElement) SetSelectionRange(start, end int, direction string) {
- e.Call("setSelectionRange", start, end, direction)
- }
- func (e *HTMLInputElement) StepDown(n int) error {
- return callRecover(e.Object, "stepDown", n)
- }
- func (e *HTMLInputElement) StepUp(n int) error {
- return callRecover(e.Object, "stepUp", n)
- }
- type HTMLKeygenElement struct {
- *BasicHTMLElement
- Autofocus bool `js:"autofocus"`
- Challenge string `js:"challenge"`
- Disabled bool `js:"disabled"`
- Keytype string `js:"keytype"`
- Name string `js:"name"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLKeygenElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLKeygenElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLKeygenElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLKeygenElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLKeygenElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLLIElement struct {
- *BasicHTMLElement
- Value int `js:"value"`
- }
- type HTMLLabelElement struct {
- *BasicHTMLElement
- For string `js:"htmlFor"`
- }
- func (e *HTMLLabelElement) Control() HTMLElement {
- return wrapHTMLElement(e.Get("control"))
- }
- func (e *HTMLLabelElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- type HTMLLegendElement struct{ *BasicHTMLElement }
- func (e *HTMLLegendElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- type HTMLLinkElement struct {
- *BasicHTMLElement
- Disabled bool `js:"disabled"`
- Href string `js:"href"`
- HrefLang string `js:"hrefLang"`
- Media string `js:"media"`
- Type string `js:"type"`
- }
- func (e *HTMLLinkElement) Rel() *TokenList {
- return &TokenList{dtl: e.Get("relList"), o: e.Object, sa: "rel"}
- }
- func (e *HTMLLinkElement) Sizes() *TokenList {
- return &TokenList{dtl: e.Get("sizes"), o: e.Object}
- }
- func (e *HTMLLinkElement) Sheet() StyleSheet {
- // FIXME implement
- panic("not implemented")
- }
- type HTMLMapElement struct {
- *BasicHTMLElement
- Name string `js:"name"`
- }
- func (e *HTMLMapElement) Areas() []*HTMLAreaElement {
- areas := nodeListToElements(e.Get("areas"))
- out := make([]*HTMLAreaElement, len(areas))
- for i, area := range areas {
- out[i] = area.(*HTMLAreaElement)
- }
- return out
- }
- func (e *HTMLMapElement) Images() []HTMLElement {
- return nodeListToHTMLElements(e.Get("areas"))
- }
- type HTMLMediaElement struct {
- *BasicHTMLElement
- Paused bool `js:"paused"`
- }
- func (e *HTMLMediaElement) Play() {
- e.Call("play")
- }
- func (e *HTMLMediaElement) Pause() {
- e.Call("pause")
- }
- type HTMLMenuElement struct{ *BasicHTMLElement }
- type HTMLMetaElement struct {
- *BasicHTMLElement
- Content string `js:"content"`
- HTTPEquiv string `js:"httpEquiv"`
- Name string `js:"name"`
- }
- type HTMLMeterElement struct {
- *BasicHTMLElement
- High float64 `js:"high"`
- Low float64 `js:"low"`
- Max float64 `js:"max"`
- Min float64 `js:"min"`
- Optimum float64 `js:"optimum"`
- }
- func (e HTMLMeterElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- type HTMLModElement struct {
- *BasicHTMLElement
- Cite string `js:"cite"`
- DateTime string `js:"dateTime"`
- }
- type HTMLOListElement struct {
- *BasicHTMLElement
- Reversed bool `js:"reversed"`
- Start int `js:"start"`
- Type string `js:"type"`
- }
- type HTMLObjectElement struct {
- *BasicHTMLElement
- Data string `js:"data"`
- Height string `js:"height"`
- Name string `js:"name"`
- TabIndex int `js:"tabIndex"`
- Type string `js:"type"`
- TypeMustMatch bool `js:"typeMustMatch"`
- UseMap string `js:"useMap"`
- ValidationMessage string `js:"validationMessage"`
- With string `js:"with"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLObjectElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLObjectElement) ContentDocument() Document {
- return wrapDocument(e.Get("contentDocument"))
- }
- func (e *HTMLObjectElement) ContentWindow() Window {
- return &window{e.Get("contentWindow")}
- }
- func (e *HTMLObjectElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLObjectElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLObjectElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLOptGroupElement struct {
- *BasicHTMLElement
- Disabled bool `js:"disabled"`
- Label string `js:"label"`
- }
- type HTMLOptionElement struct {
- *BasicHTMLElement
- DefaultSelected bool `js:"defaultSelected"`
- Disabled bool `js:"disabled"`
- Index int `js:"index"`
- Label string `js:"label"`
- Selected bool `js:"selected"`
- Text string `js:"text"`
- Value string `js:"value"`
- }
- func (e *HTMLOptionElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- type HTMLOutputElement struct {
- *BasicHTMLElement
- DefaultValue string `js:"defaultValue"`
- Name string `js:"name"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- Value string `js:"value"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLOutputElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLOutputElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLOutputElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLOutputElement) For() *TokenList {
- return &TokenList{dtl: e.Get("htmlFor"), o: e.Object}
- }
- func (e *HTMLOutputElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLOutputElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLParagraphElement struct{ *BasicHTMLElement }
- type HTMLParamElement struct {
- *BasicHTMLElement
- Name string `js:"name"`
- Value string `js:"value"`
- }
- type HTMLPreElement struct{ *BasicHTMLElement }
- type HTMLProgressElement struct {
- *BasicHTMLElement
- Max float64 `js:"max"`
- Position float64 `js:"position"`
- Value float64 `js:"value"`
- }
- func (e HTMLProgressElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- type HTMLQuoteElement struct {
- *BasicHTMLElement
- Cite string `js:"cite"`
- }
- type HTMLScriptElement struct {
- *BasicHTMLElement
- Type string `js:"type"`
- Src string `js:"src"`
- Charset string `js:"charset"`
- Async bool `js:"async"`
- Defer bool `js:"defer"`
- Text string `js:"text"`
- }
- type HTMLSelectElement struct {
- *BasicHTMLElement
- Autofocus bool `js:"autofocus"`
- Disabled bool `js:"disabled"`
- Length int `js:"length"`
- Multiple bool `js:"multiple"`
- Name string `js:"name"`
- Required bool `js:"required"`
- SelectedIndex int `js:"selectedIndex"`
- Size int `js:"size"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- Value string `js:"value"`
- WillValidate bool `js:"willValidate"`
- }
- func (e *HTMLSelectElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLSelectElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLSelectElement) Options() []*HTMLOptionElement {
- return getOptions(e.Object, "options")
- }
- func (e *HTMLSelectElement) SelectedOptions() []*HTMLOptionElement {
- return getOptions(e.Object, "selectedOptions")
- }
- func (e *HTMLSelectElement) Item(index int) *HTMLOptionElement {
- el := wrapHTMLElement(e.Call("item", index))
- if el == nil {
- return nil
- }
- return el.(*HTMLOptionElement)
- }
- func (e *HTMLSelectElement) NamedItem(name string) *HTMLOptionElement {
- el := wrapHTMLElement(e.Call("namedItem", name))
- if el == nil {
- return nil
- }
- return el.(*HTMLOptionElement)
- }
- // TODO(dominikh): Not implementing Add or Remove for now. For one,
- // Add with "before" behaves weird when dealing with optgroups. Also,
- // there's already InsertBefore and RemoveChild which can be used
- // instead.
- func (e *HTMLSelectElement) Validity() *ValidityState {
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLSelectElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLSelectElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- type HTMLSourceElement struct {
- *BasicHTMLElement
- Media string `js:"media"`
- Src string `js:"src"`
- Type string `js:"type"`
- }
- type HTMLSpanElement struct{ *BasicHTMLElement }
- type HTMLStyleElement struct{ *BasicHTMLElement }
- type HTMLTableCaptionElement struct{ *BasicHTMLElement }
- type HTMLTableCellElement struct {
- *BasicHTMLElement
- ColSpan int `js:"colSpan"`
- RowSpan int `js:"rowSpan"`
- CellIndex int `js:"cellIndex"`
- // TODO headers
- }
- type HTMLTableColElement struct {
- *BasicHTMLElement
- Span int `js:"span"`
- }
- type HTMLTableDataCellElement struct{ *BasicHTMLElement }
- type HTMLTableElement struct{ *BasicHTMLElement }
- type HTMLTableHeaderCellElement struct {
- *BasicHTMLElement
- Abbr string `js:"abbr"`
- Scope string `js:"scope"`
- }
- type HTMLTableRowElement struct {
- *BasicHTMLElement
- RowIndex int `js:"rowIndex"`
- SectionRowIndex int `js:"sectionRowIndex"`
- }
- func (e *HTMLTableRowElement) Cells() []*HTMLTableCellElement {
- cells := nodeListToElements(e.Get("cells"))
- out := make([]*HTMLTableCellElement, len(cells))
- for i, cell := range cells {
- out[i] = cell.(*HTMLTableCellElement)
- }
- return out
- }
- func (e *HTMLTableRowElement) InsertCell(index int) *HTMLTableCellElement {
- return wrapHTMLElement(e.Call("insertCell", index)).(*HTMLTableCellElement)
- }
- func (e *HTMLTableRowElement) DeleteCell(index int) {
- // FIXME exception handling/check that index is in bounds
- e.Call("deleteCell", index)
- }
- type HTMLTableSectionElement struct{ *BasicHTMLElement }
- func (e *HTMLTableSectionElement) Rows() []*HTMLTableRowElement {
- rows := nodeListToElements(e.Get("rows"))
- out := make([]*HTMLTableRowElement, len(rows))
- for i, row := range rows {
- out[i] = row.(*HTMLTableRowElement)
- }
- return out
- }
- func (e *HTMLTableSectionElement) DeleteRow(index int) {
- // FIXME exception handling/check that index is in bounds
- e.Call("deleteRow", index)
- }
- func (e *HTMLTableSectionElement) InsertRow(index int) *HTMLTableRowElement {
- return wrapHTMLElement(e.Call("insertRow", index)).(*HTMLTableRowElement)
- }
- type HTMLTemplateElement struct{ *BasicHTMLElement }
- func (e *HTMLTemplateElement) Content() DocumentFragment {
- return wrapDocumentFragment(e.Get("content"))
- }
- type HTMLTextAreaElement struct {
- *BasicHTMLElement
- Autocomplete string `js:"autocomplete"`
- Autofocus bool `js:"autofocus"`
- Cols int `js:"cols"`
- DefaultValue string `js:"defaultValue"`
- DirName string `js:"dirName"`
- Disabled bool `js:"disabled"`
- MaxLength int `js:"maxLength"`
- Name string `js:"name"`
- Placeholder string `js:"placeholder"`
- ReadOnly bool `js:"readOnly"`
- Required bool `js:"required"`
- Rows int `js:"rows"`
- SelectionDirection string `js:"selectionDirection"`
- SelectionStart int `js:"selectionStart"`
- SelectionEnd int `js:"selectionEnd"`
- TabIndex int `js:"tabIndex"`
- TextLength int `js:"textLength"`
- Type string `js:"type"`
- ValidationMessage string `js:"validationMessage"`
- Value string `js:"value"`
- WillValidate bool `js:"willValidate"`
- Wrap string `js:"wrap"`
- }
- func (e *HTMLTextAreaElement) Form() *HTMLFormElement {
- return getForm(e.Object)
- }
- func (e *HTMLTextAreaElement) Labels() []*HTMLLabelElement {
- return getLabels(e.Object)
- }
- func (e *HTMLTextAreaElement) Validity() *ValidityState {
- // TODO replace with a field once GopherJS supports that
- return &ValidityState{Object: e.Get("validity")}
- }
- func (e *HTMLTextAreaElement) CheckValidity() bool {
- return e.Call("checkValidity").Bool()
- }
- func (e *HTMLTextAreaElement) SetCustomValidity(s string) {
- e.Call("setCustomValidity", s)
- }
- func (e *HTMLTextAreaElement) Select() {
- e.Call("select")
- }
- func (e *HTMLTextAreaElement) SetSelectionRange(start, end int, direction string) {
- e.Call("setSelectionRange", start, end, direction)
- }
- type HTMLTimeElement struct {
- *BasicHTMLElement
- DateTime string `js:"dateTime"`
- }
- type HTMLTitleElement struct {
- *BasicHTMLElement
- Text string `js:"text"`
- }
- // TextTrack represents text track data for <track> elements. It does
- // not currently provide any methods or attributes and it hasn't been
- // decided yet whether they will be added to this package or a
- // separate package.
- type TextTrack struct{ *js.Object }
- type HTMLTrackElement struct {
- *BasicHTMLElement
- Kind string `js:"kind"`
- Src string `js:"src"`
- Srclang string `js:"srclang"`
- Label string `js:"label"`
- Default bool `js:"default"`
- ReadyState int `js:"readyState"`
- }
- func (e *HTMLTrackElement) Track() *TextTrack {
- return &TextTrack{e.Get("track")}
- }
- type HTMLUListElement struct{ *BasicHTMLElement }
- type HTMLUnknownElement struct{ *BasicHTMLElement }
- type HTMLVideoElement struct{ *HTMLMediaElement }
- type ValidityState struct {
- *js.Object
- CustomError bool `js:"customError"`
- PatternMismatch bool `js:"patternMismatch"`
- RangeOverflow bool `js:"rangeOverflow"`
- RangeUnderflow bool `js:"rangeUnderflow"`
- StepMismatch bool `js:"stepMismatch"`
- TooLong bool `js:"tooLong"`
- TypeMismatch bool `js:"typeMismatch"`
- Valid bool `js:"valid"`
- ValueMissing bool `js:"valueMissing"`
- }
- type CSSStyleDeclaration struct{ *js.Object }
- func (css *CSSStyleDeclaration) ToMap() map[string]string {
- m := make(map[string]string)
- N := css.Get("length").Int()
- for i := 0; i < N; i++ {
- name := css.Call("item", i).String()
- value := css.Call("getPropertyValue", name).String()
- m[name] = value
- }
- return m
- }
- func (css *CSSStyleDeclaration) RemoveProperty(name string) {
- css.Call("removeProperty", name)
- }
- func (css *CSSStyleDeclaration) GetPropertyValue(name string) string {
- return toString(css.Call("getPropertyValue", name))
- }
- func (css *CSSStyleDeclaration) GetPropertyPriority(name string) string {
- return toString(css.Call("getPropertyPriority", name))
- }
- func (css *CSSStyleDeclaration) SetProperty(name, value, priority string) {
- css.Call("setProperty", name, value, priority)
- }
- func (css *CSSStyleDeclaration) Index(idx int) string {
- return css.Call("index", idx).String()
- }
- func (css *CSSStyleDeclaration) Length() int {
- return css.Get("length").Int()
- }
- type Text struct {
- *BasicNode
- }
- // DataTransfer holds the data that is being
- // dragged during a drag and drop operation.
- type DataTransfer struct{ *js.Object }
- func (dt *DataTransfer) GetData(format string) string {
- return dt.Call("getData", format).String()
- }
|