nsComputedDOMStyle.cpp 208 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* DOM object returned from element.getComputedStyle() */
  6. #include "nsComputedDOMStyle.h"
  7. #include "mozilla/ArrayUtils.h"
  8. #include "mozilla/Preferences.h"
  9. #include "nsError.h"
  10. #include "nsDOMString.h"
  11. #include "nsIDOMCSSPrimitiveValue.h"
  12. #include "nsIFrame.h"
  13. #include "nsIFrameInlines.h"
  14. #include "nsStyleContext.h"
  15. #include "nsIScrollableFrame.h"
  16. #include "nsContentUtils.h"
  17. #include "nsIContent.h"
  18. #include "nsDOMCSSRect.h"
  19. #include "nsDOMCSSRGBColor.h"
  20. #include "nsDOMCSSValueList.h"
  21. #include "nsFlexContainerFrame.h"
  22. #include "nsGridContainerFrame.h"
  23. #include "nsGkAtoms.h"
  24. #include "mozilla/ReflowInput.h"
  25. #include "nsStyleUtil.h"
  26. #include "nsStyleStructInlines.h"
  27. #include "nsROCSSPrimitiveValue.h"
  28. #include "nsPresContext.h"
  29. #include "nsIDocument.h"
  30. #include "nsCSSPseudoElements.h"
  31. #include "mozilla/StyleSetHandle.h"
  32. #include "mozilla/StyleSetHandleInlines.h"
  33. #include "imgIRequest.h"
  34. #include "nsLayoutUtils.h"
  35. #include "nsCSSKeywords.h"
  36. #include "nsStyleCoord.h"
  37. #include "nsDisplayList.h"
  38. #include "nsDOMCSSDeclaration.h"
  39. #include "nsStyleTransformMatrix.h"
  40. #include "mozilla/dom/Element.h"
  41. #include "prtime.h"
  42. #include "nsWrapperCacheInlines.h"
  43. #include "mozilla/AppUnits.h"
  44. #include <algorithm>
  45. using namespace mozilla;
  46. using namespace mozilla::dom;
  47. typedef nsCSSProps::KTableEntry KTableEntry;
  48. #if defined(DEBUG_bzbarsky) || defined(DEBUG_caillon)
  49. #define DEBUG_ComputedDOMStyle
  50. #endif
  51. /*
  52. * This is the implementation of the readonly CSSStyleDeclaration that is
  53. * returned by the getComputedStyle() function.
  54. */
  55. already_AddRefed<nsComputedDOMStyle>
  56. NS_NewComputedDOMStyle(dom::Element* aElement,
  57. const nsAString& aPseudoElt,
  58. nsIDocument* aDocument,
  59. nsComputedDOMStyle::StyleType aStyleType)
  60. {
  61. RefPtr<nsComputedDOMStyle> computedStyle;
  62. computedStyle = new nsComputedDOMStyle(aElement, aPseudoElt, aDocument, aStyleType);
  63. return computedStyle.forget();
  64. }
  65. static nsDOMCSSValueList*
  66. GetROCSSValueList(bool aCommaDelimited)
  67. {
  68. return new nsDOMCSSValueList(aCommaDelimited, true);
  69. }
  70. template<typename T>
  71. already_AddRefed<CSSValue>
  72. GetBackgroundList(T nsStyleImageLayers::Layer::* aMember,
  73. uint32_t nsStyleImageLayers::* aCount,
  74. const nsStyleImageLayers& aLayers,
  75. const KTableEntry aTable[])
  76. {
  77. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  78. for (uint32_t i = 0, i_end = aLayers.*aCount; i < i_end; ++i) {
  79. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  80. val->SetIdent(nsCSSProps::ValueToKeywordEnum(aLayers.mLayers[i].*aMember, aTable));
  81. valueList->AppendCSSValue(val.forget());
  82. }
  83. return valueList.forget();
  84. }
  85. /**
  86. * An object that represents the ordered set of properties that are exposed on
  87. * an nsComputedDOMStyle object and how their computed values can be obtained.
  88. */
  89. struct nsComputedStyleMap
  90. {
  91. friend class nsComputedDOMStyle;
  92. struct Entry
  93. {
  94. // Create a pointer-to-member-function type.
  95. typedef already_AddRefed<CSSValue> (nsComputedDOMStyle::*ComputeMethod)();
  96. nsCSSPropertyID mProperty;
  97. ComputeMethod mGetter;
  98. bool IsLayoutFlushNeeded() const
  99. {
  100. return nsCSSProps::PropHasFlags(mProperty,
  101. CSS_PROPERTY_GETCS_NEEDS_LAYOUT_FLUSH);
  102. }
  103. bool IsEnabled() const
  104. {
  105. return nsCSSProps::IsEnabled(mProperty, CSSEnabledState::eForAllContent);
  106. }
  107. };
  108. // We define this enum just to count the total number of properties that can
  109. // be exposed on an nsComputedDOMStyle, including properties that may be
  110. // disabled.
  111. enum {
  112. #define COMPUTED_STYLE_PROP(prop_, method_) \
  113. eComputedStyleProperty_##prop_,
  114. #include "nsComputedDOMStylePropertyList.h"
  115. #undef COMPUTED_STYLE_PROP
  116. eComputedStyleProperty_COUNT
  117. };
  118. /**
  119. * Returns the number of properties that should be exposed on an
  120. * nsComputedDOMStyle, ecxluding any disabled properties.
  121. */
  122. uint32_t Length()
  123. {
  124. Update();
  125. return mExposedPropertyCount;
  126. }
  127. /**
  128. * Returns the property at the given index in the list of properties
  129. * that should be exposed on an nsComputedDOMStyle, excluding any
  130. * disabled properties.
  131. */
  132. nsCSSPropertyID PropertyAt(uint32_t aIndex)
  133. {
  134. Update();
  135. return kEntries[EntryIndex(aIndex)].mProperty;
  136. }
  137. /**
  138. * Searches for and returns the computed style map entry for the given
  139. * property, or nullptr if the property is not exposed on nsComputedDOMStyle
  140. * or is currently disabled.
  141. */
  142. const Entry* FindEntryForProperty(nsCSSPropertyID aPropID)
  143. {
  144. Update();
  145. for (uint32_t i = 0; i < mExposedPropertyCount; i++) {
  146. const Entry* entry = &kEntries[EntryIndex(i)];
  147. if (entry->mProperty == aPropID) {
  148. return entry;
  149. }
  150. }
  151. return nullptr;
  152. }
  153. /**
  154. * Records that mIndexMap needs updating, due to prefs changing that could
  155. * affect the set of properties exposed on an nsComputedDOMStyle.
  156. */
  157. void MarkDirty() { mExposedPropertyCount = 0; }
  158. // The member variables are public so that we can use an initializer in
  159. // nsComputedDOMStyle::GetComputedStyleMap. Use the member functions
  160. // above to get information from this object.
  161. /**
  162. * An entry for each property that can be exposed on an nsComputedDOMStyle.
  163. */
  164. const Entry kEntries[eComputedStyleProperty_COUNT];
  165. /**
  166. * The number of properties that should be exposed on an nsComputedDOMStyle.
  167. * This will be less than eComputedStyleProperty_COUNT if some property
  168. * prefs are disabled. A value of 0 indicates that it and mIndexMap are out
  169. * of date.
  170. */
  171. uint32_t mExposedPropertyCount;
  172. /**
  173. * A map of indexes on the nsComputedDOMStyle object to indexes into kEntries.
  174. */
  175. uint32_t mIndexMap[eComputedStyleProperty_COUNT];
  176. private:
  177. /**
  178. * Returns whether mExposedPropertyCount and mIndexMap are out of date.
  179. */
  180. bool IsDirty() { return mExposedPropertyCount == 0; }
  181. /**
  182. * Updates mExposedPropertyCount and mIndexMap to take into account properties
  183. * whose prefs are currently disabled.
  184. */
  185. void Update();
  186. /**
  187. * Maps an nsComputedDOMStyle indexed getter index to an index into kEntries.
  188. */
  189. uint32_t EntryIndex(uint32_t aIndex) const
  190. {
  191. MOZ_ASSERT(aIndex < mExposedPropertyCount);
  192. return mIndexMap[aIndex];
  193. }
  194. };
  195. void
  196. nsComputedStyleMap::Update()
  197. {
  198. if (!IsDirty()) {
  199. return;
  200. }
  201. uint32_t index = 0;
  202. for (uint32_t i = 0; i < eComputedStyleProperty_COUNT; i++) {
  203. if (kEntries[i].IsEnabled()) {
  204. mIndexMap[index++] = i;
  205. }
  206. }
  207. mExposedPropertyCount = index;
  208. }
  209. nsComputedDOMStyle::nsComputedDOMStyle(dom::Element* aElement,
  210. const nsAString& aPseudoElt,
  211. nsIDocument* aDocument,
  212. StyleType aStyleType)
  213. : mDocumentWeak(nullptr)
  214. , mOuterFrame(nullptr)
  215. , mInnerFrame(nullptr)
  216. , mPresShell(nullptr)
  217. , mStyleType(aStyleType)
  218. , mStyleContextGeneration(0)
  219. , mExposeVisitedStyle(false)
  220. , mResolvedStyleContext(false)
  221. {
  222. MOZ_ASSERT(aElement);
  223. MOZ_ASSERT(aDocument);
  224. // TODO(emilio, bug 548397, https://github.com/w3c/csswg-drafts/issues/2403):
  225. // Should use aElement->OwnerDoc() instead.
  226. mDocumentWeak = do_GetWeakReference(aDocument);
  227. mElement = aElement;
  228. if (!DOMStringIsNull(aPseudoElt) && !aPseudoElt.IsEmpty() &&
  229. aPseudoElt.First() == char16_t(':')) {
  230. // deal with two-colon forms of aPseudoElt
  231. nsAString::const_iterator start, end;
  232. aPseudoElt.BeginReading(start);
  233. aPseudoElt.EndReading(end);
  234. NS_ASSERTION(start != end, "aPseudoElt is not empty!");
  235. ++start;
  236. bool haveTwoColons = true;
  237. if (start == end || *start != char16_t(':')) {
  238. --start;
  239. haveTwoColons = false;
  240. }
  241. mPseudo = NS_Atomize(Substring(start, end));
  242. MOZ_ASSERT(mPseudo);
  243. // There aren't any non-CSS2 pseudo-elements with a single ':'
  244. if (!haveTwoColons &&
  245. (!nsCSSPseudoElements::IsPseudoElement(mPseudo) ||
  246. !nsCSSPseudoElements::IsCSS2PseudoElement(mPseudo))) {
  247. // XXXbz I'd really rather we threw an exception or something, but
  248. // the DOM spec sucks.
  249. mPseudo = nullptr;
  250. }
  251. }
  252. }
  253. nsComputedDOMStyle::~nsComputedDOMStyle()
  254. {
  255. ClearStyleContext();
  256. }
  257. NS_IMPL_CYCLE_COLLECTION_CLASS(nsComputedDOMStyle)
  258. NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsComputedDOMStyle)
  259. tmp->ClearStyleContext(); // remove observer before clearing mElement
  260. NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement)
  261. NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
  262. NS_IMPL_CYCLE_COLLECTION_UNLINK_END
  263. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsComputedDOMStyle)
  264. NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
  265. NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
  266. NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(nsComputedDOMStyle)
  267. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(nsComputedDOMStyle)
  268. return tmp->IsBlack();
  269. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_END
  270. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_BEGIN(nsComputedDOMStyle)
  271. return tmp->IsBlack();
  272. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_IN_CC_END
  273. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_BEGIN(nsComputedDOMStyle)
  274. return tmp->IsBlack();
  275. NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_THIS_END
  276. // QueryInterface implementation for nsComputedDOMStyle
  277. NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsComputedDOMStyle)
  278. NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
  279. NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
  280. NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
  281. NS_IMPL_CYCLE_COLLECTING_ADDREF(nsComputedDOMStyle)
  282. NS_IMPL_CYCLE_COLLECTING_RELEASE(nsComputedDOMStyle)
  283. NS_IMETHODIMP
  284. nsComputedDOMStyle::GetPropertyValue(const nsCSSPropertyID aPropID,
  285. nsAString& aValue)
  286. {
  287. // This is mostly to avoid code duplication with GetPropertyCSSValue(); if
  288. // perf ever becomes an issue here (doubtful), we can look into changing
  289. // this.
  290. return GetPropertyValue(
  291. NS_ConvertASCIItoUTF16(nsCSSProps::GetStringValue(aPropID)),
  292. aValue);
  293. }
  294. NS_IMETHODIMP
  295. nsComputedDOMStyle::SetPropertyValue(const nsCSSPropertyID aPropID,
  296. const nsAString& aValue)
  297. {
  298. return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  299. }
  300. NS_IMETHODIMP
  301. nsComputedDOMStyle::GetCssText(nsAString& aCssText)
  302. {
  303. aCssText.Truncate();
  304. return NS_OK;
  305. }
  306. NS_IMETHODIMP
  307. nsComputedDOMStyle::SetCssText(const nsAString& aCssText)
  308. {
  309. return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  310. }
  311. NS_IMETHODIMP
  312. nsComputedDOMStyle::GetLength(uint32_t* aLength)
  313. {
  314. uint32_t length = GetComputedStyleMap()->Length();
  315. // Make sure we have up to date style so that we can include custom
  316. // properties.
  317. UpdateCurrentStyleSources(false);
  318. if (mStyleContext) {
  319. length += StyleVariables()->mVariables.Count();
  320. } else {
  321. length = 0;
  322. }
  323. *aLength = length;
  324. ClearCurrentStyleSources();
  325. return NS_OK;
  326. }
  327. NS_IMETHODIMP
  328. nsComputedDOMStyle::GetParentRule(nsIDOMCSSRule** aParentRule)
  329. {
  330. *aParentRule = nullptr;
  331. return NS_OK;
  332. }
  333. NS_IMETHODIMP
  334. nsComputedDOMStyle::GetPropertyValue(const nsAString& aPropertyName,
  335. nsAString& aReturn)
  336. {
  337. aReturn.Truncate();
  338. ErrorResult error;
  339. RefPtr<CSSValue> val = GetPropertyCSSValue(aPropertyName, error);
  340. if (error.Failed()) {
  341. return error.StealNSResult();
  342. }
  343. if (val) {
  344. nsString text;
  345. val->GetCssText(text, error);
  346. aReturn.Assign(text);
  347. return error.StealNSResult();
  348. }
  349. return NS_OK;
  350. }
  351. NS_IMETHODIMP
  352. nsComputedDOMStyle::GetAuthoredPropertyValue(const nsAString& aPropertyName,
  353. nsAString& aReturn)
  354. {
  355. // Authored style doesn't make sense to return from computed DOM style,
  356. // so just return whatever GetPropertyValue() returns.
  357. return GetPropertyValue(aPropertyName, aReturn);
  358. }
  359. /* static */
  360. already_AddRefed<nsStyleContext>
  361. nsComputedDOMStyle::GetStyleContextForElement(Element* aElement,
  362. nsIAtom* aPseudo,
  363. nsIPresShell* aPresShell,
  364. StyleType aStyleType)
  365. {
  366. // If the content has a pres shell, we must use it. Otherwise we'd
  367. // potentially mix rule trees by using the wrong pres shell's style
  368. // set. Using the pres shell from the content also means that any
  369. // content that's actually *in* a document will get the style from the
  370. // correct document.
  371. nsCOMPtr<nsIPresShell> presShell = GetPresShellForContent(aElement);
  372. if (!presShell) {
  373. presShell = aPresShell;
  374. if (!presShell)
  375. return nullptr;
  376. }
  377. presShell->FlushPendingNotifications(Flush_Style);
  378. return GetStyleContextForElementNoFlush(aElement, aPseudo, presShell,
  379. aStyleType);
  380. }
  381. /* static */
  382. already_AddRefed<nsStyleContext>
  383. nsComputedDOMStyle::GetStyleContextForElementNoFlush(Element* aElement,
  384. nsIAtom* aPseudo,
  385. nsIPresShell* aPresShell,
  386. StyleType aStyleType)
  387. {
  388. MOZ_ASSERT(aElement, "NULL element");
  389. // If the content has a pres shell, we must use it. Otherwise we'd
  390. // potentially mix rule trees by using the wrong pres shell's style
  391. // set. Using the pres shell from the content also means that any
  392. // content that's actually *in* a document will get the style from the
  393. // correct document.
  394. nsIPresShell *presShell = GetPresShellForContent(aElement);
  395. bool inDocWithShell = true;
  396. if (!presShell) {
  397. inDocWithShell = false;
  398. presShell = aPresShell;
  399. if (!presShell)
  400. return nullptr;
  401. }
  402. // XXX the !aElement->IsHTMLElement(nsGkAtoms::area)
  403. // check is needed due to bug 135040 (to avoid using
  404. // mPrimaryFrame). Remove it once that's fixed.
  405. if (!aPseudo && aStyleType == eAll && inDocWithShell &&
  406. !aElement->IsHTMLElement(nsGkAtoms::area)) {
  407. nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
  408. if (frame) {
  409. nsStyleContext* result = frame->StyleContext();
  410. // Don't use the style context if it was influenced by
  411. // pseudo-elements, since then it's not the primary style
  412. // for this element.
  413. if (!result->HasPseudoElementData()) {
  414. // this function returns an addrefed style context
  415. RefPtr<nsStyleContext> ret = result;
  416. return ret.forget();
  417. }
  418. }
  419. }
  420. // No frame has been created, or we have a pseudo, or we're looking
  421. // for the default style, so resolve the style ourselves.
  422. RefPtr<nsStyleContext> parentContext;
  423. nsIContent* parent = aPseudo ? aElement : aElement->GetParent();
  424. // Don't resolve parent context for document fragments.
  425. if (parent && parent->IsElement())
  426. parentContext = GetStyleContextForElementNoFlush(parent->AsElement(),
  427. nullptr, presShell,
  428. aStyleType);
  429. nsPresContext *presContext = presShell->GetPresContext();
  430. if (!presContext)
  431. return nullptr;
  432. StyleSetHandle styleSet = presShell->StyleSet();
  433. RefPtr<nsStyleContext> sc;
  434. if (aPseudo) {
  435. CSSPseudoElementType type = nsCSSPseudoElements::
  436. GetPseudoType(aPseudo, CSSEnabledState::eIgnoreEnabledState);
  437. if (type >= CSSPseudoElementType::Count) {
  438. return nullptr;
  439. }
  440. nsIFrame* frame = nsLayoutUtils::GetStyleFrame(aElement);
  441. Element* pseudoElement =
  442. frame && inDocWithShell ? frame->GetPseudoElement(type) : nullptr;
  443. sc = styleSet->ResolvePseudoElementStyle(aElement, type, parentContext,
  444. pseudoElement);
  445. } else {
  446. sc = styleSet->ResolveStyleFor(aElement, parentContext);
  447. }
  448. if (aStyleType == eDefaultOnly) {
  449. if (styleSet->IsServo()) {
  450. NS_ERROR("stylo: ServoStyleSets cannot supply UA-only styles yet");
  451. return nullptr;
  452. }
  453. // We really only want the user and UA rules. Filter out the other ones.
  454. nsTArray< nsCOMPtr<nsIStyleRule> > rules;
  455. for (nsRuleNode* ruleNode = sc->RuleNode();
  456. !ruleNode->IsRoot();
  457. ruleNode = ruleNode->GetParent()) {
  458. if (ruleNode->GetLevel() == SheetType::Agent ||
  459. ruleNode->GetLevel() == SheetType::User) {
  460. rules.AppendElement(ruleNode->GetRule());
  461. }
  462. }
  463. // We want to build a list of user/ua rules that is in order from least to
  464. // most important, so we have to reverse the list.
  465. // Integer division to get "stop" is purposeful here: if length is odd, we
  466. // don't have to do anything with the middle element of the array.
  467. for (uint32_t i = 0, length = rules.Length(), stop = length / 2;
  468. i < stop; ++i) {
  469. rules[i].swap(rules[length - i - 1]);
  470. }
  471. sc = styleSet->AsGecko()->ResolveStyleForRules(parentContext, rules);
  472. }
  473. return sc.forget();
  474. }
  475. nsMargin
  476. nsComputedDOMStyle::GetAdjustedValuesForBoxSizing()
  477. {
  478. // We want the width/height of whatever parts 'width' or 'height' controls,
  479. // which can be different depending on the value of the 'box-sizing' property.
  480. const nsStylePosition* stylePos = StylePosition();
  481. nsMargin adjustment;
  482. if (stylePos->mBoxSizing == StyleBoxSizing::Border) {
  483. adjustment = mInnerFrame->GetUsedBorderAndPadding();
  484. }
  485. return adjustment;
  486. }
  487. /* static */
  488. nsIPresShell*
  489. nsComputedDOMStyle::GetPresShellForContent(nsIContent* aContent)
  490. {
  491. nsIDocument* composedDoc = aContent->GetComposedDoc();
  492. if (!composedDoc)
  493. return nullptr;
  494. return composedDoc->GetShell();
  495. }
  496. // nsDOMCSSDeclaration abstract methods which should never be called
  497. // on a nsComputedDOMStyle object, but must be defined to avoid
  498. // compile errors.
  499. DeclarationBlock*
  500. nsComputedDOMStyle::GetCSSDeclaration(Operation)
  501. {
  502. NS_RUNTIMEABORT("called nsComputedDOMStyle::GetCSSDeclaration");
  503. return nullptr;
  504. }
  505. nsresult
  506. nsComputedDOMStyle::SetCSSDeclaration(DeclarationBlock*)
  507. {
  508. NS_RUNTIMEABORT("called nsComputedDOMStyle::SetCSSDeclaration");
  509. return NS_ERROR_FAILURE;
  510. }
  511. nsIDocument*
  512. nsComputedDOMStyle::DocToUpdate()
  513. {
  514. NS_RUNTIMEABORT("called nsComputedDOMStyle::DocToUpdate");
  515. return nullptr;
  516. }
  517. void
  518. nsComputedDOMStyle::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
  519. {
  520. NS_RUNTIMEABORT("called nsComputedDOMStyle::GetCSSParsingEnvironment");
  521. // Just in case NS_RUNTIMEABORT ever stops killing us for some reason
  522. aCSSParseEnv.mPrincipal = nullptr;
  523. }
  524. void
  525. nsComputedDOMStyle::ClearStyleContext()
  526. {
  527. if (mResolvedStyleContext) {
  528. mResolvedStyleContext = false;
  529. mElement->RemoveMutationObserver(this);
  530. }
  531. mStyleContext = nullptr;
  532. }
  533. void
  534. nsComputedDOMStyle::SetResolvedStyleContext(RefPtr<nsStyleContext>&& aContext)
  535. {
  536. if (!mResolvedStyleContext) {
  537. mResolvedStyleContext = true;
  538. mElement->AddMutationObserver(this);
  539. }
  540. mStyleContext = aContext;
  541. }
  542. void
  543. nsComputedDOMStyle::SetFrameStyleContext(nsStyleContext* aContext)
  544. {
  545. ClearStyleContext();
  546. mStyleContext = aContext;
  547. }
  548. /**
  549. * The following function checks whether we need to explicitly resolve the style
  550. * again, even though we have a style context coming from the frame.
  551. *
  552. * This basically checks whether the style is or may be under a ::first-line or
  553. * ::first-letter frame, in which case we can't return the frame style, and we
  554. * need to resolve it. See bug 505515.
  555. */
  556. static bool
  557. MustReresolveStyle(const nsStyleContext* aContext)
  558. {
  559. MOZ_ASSERT(aContext);
  560. if (aContext->HasPseudoElementData()) {
  561. if (!aContext->GetPseudo() ||
  562. aContext->StyleSource().IsServoComputedValues()) {
  563. // TODO(emilio): When ::first-line is supported in Servo, we may want to
  564. // fix this to avoid re-resolving pseudo-element styles.
  565. return true;
  566. }
  567. return aContext->GetParent() &&
  568. aContext->GetParent()->HasPseudoElementData();
  569. }
  570. return false;
  571. }
  572. void
  573. nsComputedDOMStyle::UpdateCurrentStyleSources(bool aNeedsLayoutFlush)
  574. {
  575. nsCOMPtr<nsIDocument> document = do_QueryReferent(mDocumentWeak);
  576. if (!document) {
  577. ClearStyleContext();
  578. return;
  579. }
  580. document->FlushPendingLinkUpdates();
  581. // Flush _before_ getting the presshell, since that could create a new
  582. // presshell. Also note that we want to flush the style on the document
  583. // we're computing style in, not on the document mElement is in -- the two
  584. // may be different.
  585. document->FlushPendingNotifications(
  586. aNeedsLayoutFlush ? Flush_Layout : Flush_Style);
  587. #ifdef DEBUG
  588. mFlushedPendingReflows = aNeedsLayoutFlush;
  589. #endif
  590. nsCOMPtr<nsIPresShell> presShellForContent = GetPresShellForContent(mElement);
  591. if (presShellForContent && presShellForContent != document->GetShell()) {
  592. presShellForContent->FlushPendingNotifications(Flush_Style);
  593. }
  594. mPresShell = document->GetShell();
  595. if (!mPresShell || !mPresShell->GetPresContext()) {
  596. ClearStyleContext();
  597. return;
  598. }
  599. uint64_t currentGeneration =
  600. mPresShell->GetPresContext()->GetRestyleGeneration();
  601. if (mStyleContext) {
  602. // We can't rely on the undisplayed restyle generation if mElement is
  603. // out-of-document, since that generation is not incremented for DOM changes
  604. // on out-of-document elements.
  605. if (mStyleContextGeneration == currentGeneration &&
  606. mElement->IsInComposedDoc()) {
  607. // Our cached style context is still valid.
  608. return;
  609. }
  610. // We've processed some restyles, so the cached style context might
  611. // be out of date.
  612. mStyleContext = nullptr;
  613. }
  614. // XXX the !mElement->IsHTMLElement(nsGkAtoms::area)
  615. // check is needed due to bug 135040 (to avoid using
  616. // mPrimaryFrame). Remove it once that's fixed.
  617. if (mStyleType == eAll && !mElement->IsHTMLElement(nsGkAtoms::area)) {
  618. mOuterFrame = nullptr;
  619. if (!mPseudo) {
  620. mOuterFrame = mElement->GetPrimaryFrame();
  621. } else if (mPseudo == nsCSSPseudoElements::before ||
  622. mPseudo == nsCSSPseudoElements::after) {
  623. nsIAtom* property = mPseudo == nsCSSPseudoElements::before
  624. ? nsGkAtoms::beforePseudoProperty
  625. : nsGkAtoms::afterPseudoProperty;
  626. auto* pseudo = static_cast<Element*>(mElement->GetProperty(property));
  627. mOuterFrame = pseudo ? pseudo->GetPrimaryFrame() : nullptr;
  628. }
  629. mInnerFrame = mOuterFrame;
  630. if (mOuterFrame) {
  631. nsIAtom* type = mOuterFrame->GetType();
  632. if (type == nsGkAtoms::tableWrapperFrame) {
  633. // If the frame is a table wrapper frame then we should get the style
  634. // from the inner table frame.
  635. mInnerFrame = mOuterFrame->PrincipalChildList().FirstChild();
  636. NS_ASSERTION(mInnerFrame, "table wrapper must have an inner");
  637. NS_ASSERTION(!mInnerFrame->GetNextSibling(),
  638. "table wrapper frames should have just one child, "
  639. "the inner table");
  640. }
  641. SetFrameStyleContext(mInnerFrame->StyleContext());
  642. NS_ASSERTION(mStyleContext, "Frame without style context?");
  643. }
  644. }
  645. if (!mStyleContext || MustReresolveStyle(mStyleContext)) {
  646. #ifdef DEBUG
  647. if (mStyleContext) {
  648. // We want to check that going through this path because of
  649. // HasPseudoElementData is rare, because it slows us down a good
  650. // bit. So check that we're really inside something associated
  651. // with a pseudo-element that contains elements. (We also allow
  652. // the element to be NAC, just in case some chrome JS calls
  653. // getComputedStyle on a NAC-implemented pseudo.)
  654. nsStyleContext* topWithPseudoElementData = mStyleContext;
  655. while (topWithPseudoElementData->GetParent()->HasPseudoElementData()) {
  656. topWithPseudoElementData = topWithPseudoElementData->GetParent();
  657. }
  658. CSSPseudoElementType pseudo = topWithPseudoElementData->GetPseudoType();
  659. nsIAtom* pseudoAtom = nsCSSPseudoElements::GetPseudoAtom(pseudo);
  660. nsAutoString assertMsg(
  661. NS_LITERAL_STRING("we should be in a pseudo-element that is expected to contain elements ("));
  662. assertMsg.Append(nsDependentString(pseudoAtom->GetUTF16String()));
  663. assertMsg.Append(')');
  664. NS_ASSERTION(nsCSSPseudoElements::PseudoElementContainsElements(pseudo) ||
  665. mElement->IsNativeAnonymous(),
  666. NS_LossyConvertUTF16toASCII(assertMsg).get());
  667. }
  668. #endif
  669. // Need to resolve a style context
  670. RefPtr<nsStyleContext> resolvedStyleContext =
  671. nsComputedDOMStyle::GetStyleContextForElementNoFlush(
  672. mElement,
  673. mPseudo,
  674. presShellForContent ? presShellForContent.get() : mPresShell,
  675. mStyleType);
  676. if (!resolvedStyleContext) {
  677. ClearStyleContext();
  678. return;
  679. }
  680. // No need to re-get the generation, even though GetStyleContextForElement
  681. // will flush, since we flushed style at the top of this function.
  682. NS_ASSERTION(mPresShell &&
  683. currentGeneration ==
  684. mPresShell->GetPresContext()->GetRestyleGeneration(),
  685. "why should we have flushed style again?");
  686. SetResolvedStyleContext(Move(resolvedStyleContext));
  687. NS_ASSERTION(mPseudo || !mStyleContext->HasPseudoElementData(),
  688. "should not have pseudo-element data");
  689. }
  690. // mExposeVisitedStyle is set to true only by testing APIs that
  691. // require chrome privilege.
  692. MOZ_ASSERT(!mExposeVisitedStyle || nsContentUtils::IsCallerChrome(),
  693. "mExposeVisitedStyle set incorrectly");
  694. if (mExposeVisitedStyle && mStyleContext->RelevantLinkVisited()) {
  695. nsStyleContext *styleIfVisited = mStyleContext->GetStyleIfVisited();
  696. if (styleIfVisited) {
  697. mStyleContext = styleIfVisited;
  698. }
  699. }
  700. }
  701. void
  702. nsComputedDOMStyle::ClearCurrentStyleSources()
  703. {
  704. mOuterFrame = nullptr;
  705. mInnerFrame = nullptr;
  706. mPresShell = nullptr;
  707. // Release the current style context if we got it off the frame.
  708. // For a style context we resolved, keep it around so that we
  709. // can re-use it next time this object is queried.
  710. if (!mResolvedStyleContext) {
  711. mStyleContext = nullptr;
  712. }
  713. }
  714. already_AddRefed<CSSValue>
  715. nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorResult& aRv)
  716. {
  717. nsCSSPropertyID prop =
  718. nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
  719. bool needsLayoutFlush;
  720. nsComputedStyleMap::Entry::ComputeMethod getter;
  721. if (prop == eCSSPropertyExtra_variable) {
  722. needsLayoutFlush = false;
  723. getter = nullptr;
  724. } else {
  725. // We don't (for now, anyway, though it may make sense to change it
  726. // for all aliases, including those in nsCSSPropAliasList) want
  727. // aliases to be enumerable (via GetLength and IndexedGetter), so
  728. // handle them here rather than adding entries to
  729. // GetQueryablePropertyMap.
  730. if (prop != eCSSProperty_UNKNOWN &&
  731. nsCSSProps::PropHasFlags(prop, CSS_PROPERTY_IS_ALIAS)) {
  732. const nsCSSPropertyID* subprops = nsCSSProps::SubpropertyEntryFor(prop);
  733. MOZ_ASSERT(subprops[1] == eCSSProperty_UNKNOWN,
  734. "must have list of length 1");
  735. prop = subprops[0];
  736. }
  737. const nsComputedStyleMap::Entry* propEntry =
  738. GetComputedStyleMap()->FindEntryForProperty(prop);
  739. if (!propEntry) {
  740. #ifdef DEBUG_ComputedDOMStyle
  741. NS_WARNING(PromiseFlatCString(NS_ConvertUTF16toUTF8(aPropertyName) +
  742. NS_LITERAL_CSTRING(" is not queryable!")).get());
  743. #endif
  744. // NOTE: For branches, we should flush here for compatibility!
  745. return nullptr;
  746. }
  747. needsLayoutFlush = propEntry->IsLayoutFlushNeeded();
  748. getter = propEntry->mGetter;
  749. }
  750. UpdateCurrentStyleSources(needsLayoutFlush);
  751. if (!mStyleContext) {
  752. return nullptr;
  753. }
  754. RefPtr<CSSValue> val;
  755. if (prop == eCSSPropertyExtra_variable) {
  756. val = DoGetCustomProperty(aPropertyName);
  757. } else {
  758. // Call our pointer-to-member-function.
  759. val = (this->*getter)();
  760. }
  761. ClearCurrentStyleSources();
  762. return val.forget();
  763. }
  764. NS_IMETHODIMP
  765. nsComputedDOMStyle::RemoveProperty(const nsAString& aPropertyName,
  766. nsAString& aReturn)
  767. {
  768. return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  769. }
  770. NS_IMETHODIMP
  771. nsComputedDOMStyle::GetPropertyPriority(const nsAString& aPropertyName,
  772. nsAString& aReturn)
  773. {
  774. aReturn.Truncate();
  775. return NS_OK;
  776. }
  777. NS_IMETHODIMP
  778. nsComputedDOMStyle::SetProperty(const nsAString& aPropertyName,
  779. const nsAString& aValue,
  780. const nsAString& aPriority)
  781. {
  782. return NS_ERROR_DOM_NO_MODIFICATION_ALLOWED_ERR;
  783. }
  784. NS_IMETHODIMP
  785. nsComputedDOMStyle::Item(uint32_t aIndex, nsAString& aReturn)
  786. {
  787. return nsDOMCSSDeclaration::Item(aIndex, aReturn);
  788. }
  789. void
  790. nsComputedDOMStyle::IndexedGetter(uint32_t aIndex,
  791. bool& aFound,
  792. nsAString& aPropName)
  793. {
  794. nsComputedStyleMap* map = GetComputedStyleMap();
  795. uint32_t length = map->Length();
  796. if (aIndex < length) {
  797. aFound = true;
  798. CopyASCIItoUTF16(nsCSSProps::GetStringValue(map->PropertyAt(aIndex)),
  799. aPropName);
  800. return;
  801. }
  802. // Custom properties are exposed with indexed properties just after all
  803. // of the built-in properties.
  804. UpdateCurrentStyleSources(false);
  805. if (!mStyleContext) {
  806. aFound = false;
  807. return;
  808. }
  809. const nsStyleVariables* variables = StyleVariables();
  810. if (aIndex - length < variables->mVariables.Count()) {
  811. aFound = true;
  812. nsString varName;
  813. variables->mVariables.GetVariableAt(aIndex - length, varName);
  814. aPropName.AssignLiteral("--");
  815. aPropName.Append(varName);
  816. } else {
  817. aFound = false;
  818. }
  819. ClearCurrentStyleSources();
  820. }
  821. // Property getters...
  822. already_AddRefed<CSSValue>
  823. nsComputedDOMStyle::DoGetBinding()
  824. {
  825. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  826. const nsStyleDisplay* display = StyleDisplay();
  827. if (display->mBinding) {
  828. val->SetURI(display->mBinding->GetURI());
  829. } else {
  830. val->SetIdent(eCSSKeyword_none);
  831. }
  832. return val.forget();
  833. }
  834. already_AddRefed<CSSValue>
  835. nsComputedDOMStyle::DoGetClear()
  836. {
  837. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  838. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mBreakType,
  839. nsCSSProps::kClearKTable));
  840. return val.forget();
  841. }
  842. already_AddRefed<CSSValue>
  843. nsComputedDOMStyle::DoGetFloat()
  844. {
  845. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  846. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mFloat,
  847. nsCSSProps::kFloatKTable));
  848. return val.forget();
  849. }
  850. already_AddRefed<CSSValue>
  851. nsComputedDOMStyle::DoGetBottom()
  852. {
  853. return GetOffsetWidthFor(NS_SIDE_BOTTOM);
  854. }
  855. already_AddRefed<CSSValue>
  856. nsComputedDOMStyle::DoGetStackSizing()
  857. {
  858. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  859. val->SetIdent(StyleXUL()->mStretchStack ? eCSSKeyword_stretch_to_fit :
  860. eCSSKeyword_ignore);
  861. return val.forget();
  862. }
  863. void
  864. nsComputedDOMStyle::SetToRGBAColor(nsROCSSPrimitiveValue* aValue,
  865. nscolor aColor)
  866. {
  867. if (NS_GET_A(aColor) == 0) {
  868. aValue->SetIdent(eCSSKeyword_transparent);
  869. return;
  870. }
  871. nsROCSSPrimitiveValue *red = new nsROCSSPrimitiveValue;
  872. nsROCSSPrimitiveValue *green = new nsROCSSPrimitiveValue;
  873. nsROCSSPrimitiveValue *blue = new nsROCSSPrimitiveValue;
  874. nsROCSSPrimitiveValue *alpha = new nsROCSSPrimitiveValue;
  875. uint8_t a = NS_GET_A(aColor);
  876. nsDOMCSSRGBColor *rgbColor =
  877. new nsDOMCSSRGBColor(red, green, blue, alpha, a < 255);
  878. red->SetNumber(NS_GET_R(aColor));
  879. green->SetNumber(NS_GET_G(aColor));
  880. blue->SetNumber(NS_GET_B(aColor));
  881. alpha->SetNumber(nsStyleUtil::ColorComponentToFloat(a));
  882. aValue->SetColor(rgbColor);
  883. }
  884. void
  885. nsComputedDOMStyle::SetValueFromComplexColor(nsROCSSPrimitiveValue* aValue,
  886. const StyleComplexColor& aColor)
  887. {
  888. SetToRGBAColor(aValue, StyleColor()->CalcComplexColor(aColor));
  889. }
  890. already_AddRefed<CSSValue>
  891. nsComputedDOMStyle::DoGetColor()
  892. {
  893. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  894. SetToRGBAColor(val, StyleColor()->mColor);
  895. return val.forget();
  896. }
  897. already_AddRefed<CSSValue>
  898. nsComputedDOMStyle::DoGetColorAdjust()
  899. {
  900. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  901. val->SetIdent(
  902. nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mColorAdjust,
  903. nsCSSProps::kColorAdjustKTable));
  904. return val.forget();
  905. }
  906. already_AddRefed<CSSValue>
  907. nsComputedDOMStyle::DoGetOpacity()
  908. {
  909. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  910. val->SetNumber(StyleEffects()->mOpacity);
  911. return val.forget();
  912. }
  913. already_AddRefed<CSSValue>
  914. nsComputedDOMStyle::DoGetColumnCount()
  915. {
  916. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  917. const nsStyleColumn* column = StyleColumn();
  918. if (column->mColumnCount == NS_STYLE_COLUMN_COUNT_AUTO) {
  919. val->SetIdent(eCSSKeyword_auto);
  920. } else {
  921. val->SetNumber(column->mColumnCount);
  922. }
  923. return val.forget();
  924. }
  925. already_AddRefed<CSSValue>
  926. nsComputedDOMStyle::DoGetColumnWidth()
  927. {
  928. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  929. // XXX fix the auto case. When we actually have a column frame, I think
  930. // we should return the computed column width.
  931. SetValueToCoord(val, StyleColumn()->mColumnWidth, true);
  932. return val.forget();
  933. }
  934. already_AddRefed<CSSValue>
  935. nsComputedDOMStyle::DoGetColumnGap()
  936. {
  937. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  938. const nsStyleColumn* column = StyleColumn();
  939. if (column->mColumnGap.GetUnit() == eStyleUnit_Normal) {
  940. val->SetAppUnits(StyleFont()->mFont.size);
  941. } else {
  942. SetValueToCoord(val, StyleColumn()->mColumnGap, true);
  943. }
  944. return val.forget();
  945. }
  946. already_AddRefed<CSSValue>
  947. nsComputedDOMStyle::DoGetColumnFill()
  948. {
  949. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  950. val->SetIdent(
  951. nsCSSProps::ValueToKeywordEnum(StyleColumn()->mColumnFill,
  952. nsCSSProps::kColumnFillKTable));
  953. return val.forget();
  954. }
  955. already_AddRefed<CSSValue>
  956. nsComputedDOMStyle::DoGetColumnRuleWidth()
  957. {
  958. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  959. val->SetAppUnits(StyleColumn()->GetComputedColumnRuleWidth());
  960. return val.forget();
  961. }
  962. already_AddRefed<CSSValue>
  963. nsComputedDOMStyle::DoGetColumnRuleStyle()
  964. {
  965. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  966. val->SetIdent(
  967. nsCSSProps::ValueToKeywordEnum(StyleColumn()->mColumnRuleStyle,
  968. nsCSSProps::kBorderStyleKTable));
  969. return val.forget();
  970. }
  971. already_AddRefed<CSSValue>
  972. nsComputedDOMStyle::DoGetColumnRuleColor()
  973. {
  974. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  975. SetValueFromComplexColor(val, StyleColumn()->mColumnRuleColor);
  976. return val.forget();
  977. }
  978. already_AddRefed<CSSValue>
  979. nsComputedDOMStyle::DoGetContent()
  980. {
  981. const nsStyleContent *content = StyleContent();
  982. if (content->ContentCount() == 0) {
  983. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  984. val->SetIdent(eCSSKeyword_none);
  985. return val.forget();
  986. }
  987. if (content->ContentCount() == 1 &&
  988. content->ContentAt(0).mType == eStyleContentType_AltContent) {
  989. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  990. val->SetIdent(eCSSKeyword__moz_alt_content);
  991. return val.forget();
  992. }
  993. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  994. for (uint32_t i = 0, i_end = content->ContentCount(); i < i_end; ++i) {
  995. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  996. const nsStyleContentData &data = content->ContentAt(i);
  997. switch (data.mType) {
  998. case eStyleContentType_String:
  999. {
  1000. nsAutoString str;
  1001. nsStyleUtil::AppendEscapedCSSString(
  1002. nsDependentString(data.mContent.mString), str);
  1003. val->SetString(str);
  1004. }
  1005. break;
  1006. case eStyleContentType_Image:
  1007. {
  1008. nsCOMPtr<nsIURI> uri;
  1009. if (data.mContent.mImage) {
  1010. data.mContent.mImage->GetURI(getter_AddRefs(uri));
  1011. }
  1012. val->SetURI(uri);
  1013. }
  1014. break;
  1015. case eStyleContentType_Attr:
  1016. {
  1017. nsAutoString str;
  1018. nsStyleUtil::AppendEscapedCSSIdent(
  1019. nsDependentString(data.mContent.mString), str);
  1020. val->SetString(str, nsIDOMCSSPrimitiveValue::CSS_ATTR);
  1021. }
  1022. break;
  1023. case eStyleContentType_Counter:
  1024. case eStyleContentType_Counters:
  1025. {
  1026. /* FIXME: counters should really use an object */
  1027. nsAutoString str;
  1028. if (data.mType == eStyleContentType_Counter) {
  1029. str.AppendLiteral("counter(");
  1030. }
  1031. else {
  1032. str.AppendLiteral("counters(");
  1033. }
  1034. // WRITE ME
  1035. nsCSSValue::Array *a = data.mContent.mCounters;
  1036. nsStyleUtil::AppendEscapedCSSIdent(
  1037. nsDependentString(a->Item(0).GetStringBufferValue()), str);
  1038. int32_t typeItem = 1;
  1039. if (data.mType == eStyleContentType_Counters) {
  1040. typeItem = 2;
  1041. str.AppendLiteral(", ");
  1042. nsStyleUtil::AppendEscapedCSSString(
  1043. nsDependentString(a->Item(1).GetStringBufferValue()), str);
  1044. }
  1045. MOZ_ASSERT(eCSSUnit_None != a->Item(typeItem).GetUnit(),
  1046. "'none' should be handled as identifier value");
  1047. nsString type;
  1048. a->Item(typeItem).AppendToString(eCSSProperty_list_style_type,
  1049. type, nsCSSValue::eNormalized);
  1050. if (!type.LowerCaseEqualsLiteral("decimal")) {
  1051. str.AppendLiteral(", ");
  1052. str.Append(type);
  1053. }
  1054. str.Append(char16_t(')'));
  1055. val->SetString(str, nsIDOMCSSPrimitiveValue::CSS_COUNTER);
  1056. }
  1057. break;
  1058. case eStyleContentType_OpenQuote:
  1059. val->SetIdent(eCSSKeyword_open_quote);
  1060. break;
  1061. case eStyleContentType_CloseQuote:
  1062. val->SetIdent(eCSSKeyword_close_quote);
  1063. break;
  1064. case eStyleContentType_NoOpenQuote:
  1065. val->SetIdent(eCSSKeyword_no_open_quote);
  1066. break;
  1067. case eStyleContentType_NoCloseQuote:
  1068. val->SetIdent(eCSSKeyword_no_close_quote);
  1069. break;
  1070. case eStyleContentType_AltContent:
  1071. default:
  1072. NS_NOTREACHED("unexpected type");
  1073. break;
  1074. }
  1075. valueList->AppendCSSValue(val.forget());
  1076. }
  1077. return valueList.forget();
  1078. }
  1079. already_AddRefed<CSSValue>
  1080. nsComputedDOMStyle::DoGetCounterIncrement()
  1081. {
  1082. const nsStyleContent *content = StyleContent();
  1083. if (content->CounterIncrementCount() == 0) {
  1084. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1085. val->SetIdent(eCSSKeyword_none);
  1086. return val.forget();
  1087. }
  1088. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  1089. for (uint32_t i = 0, i_end = content->CounterIncrementCount(); i < i_end; ++i) {
  1090. RefPtr<nsROCSSPrimitiveValue> name = new nsROCSSPrimitiveValue;
  1091. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  1092. const nsStyleCounterData& data = content->CounterIncrementAt(i);
  1093. nsAutoString escaped;
  1094. nsStyleUtil::AppendEscapedCSSIdent(data.mCounter, escaped);
  1095. name->SetString(escaped);
  1096. value->SetNumber(data.mValue); // XXX This should really be integer
  1097. valueList->AppendCSSValue(name.forget());
  1098. valueList->AppendCSSValue(value.forget());
  1099. }
  1100. return valueList.forget();
  1101. }
  1102. /* Convert the stored representation into a list of two values and then hand
  1103. * it back.
  1104. */
  1105. already_AddRefed<CSSValue>
  1106. nsComputedDOMStyle::DoGetTransformOrigin()
  1107. {
  1108. /* We need to build up a list of two values. We'll call them
  1109. * width and height.
  1110. */
  1111. /* Store things as a value list */
  1112. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  1113. /* Now, get the values. */
  1114. const nsStyleDisplay* display = StyleDisplay();
  1115. RefPtr<nsROCSSPrimitiveValue> width = new nsROCSSPrimitiveValue;
  1116. SetValueToCoord(width, display->mTransformOrigin[0], false,
  1117. &nsComputedDOMStyle::GetFrameBoundsWidthForTransform);
  1118. valueList->AppendCSSValue(width.forget());
  1119. RefPtr<nsROCSSPrimitiveValue> height = new nsROCSSPrimitiveValue;
  1120. SetValueToCoord(height, display->mTransformOrigin[1], false,
  1121. &nsComputedDOMStyle::GetFrameBoundsHeightForTransform);
  1122. valueList->AppendCSSValue(height.forget());
  1123. if (display->mTransformOrigin[2].GetUnit() != eStyleUnit_Coord ||
  1124. display->mTransformOrigin[2].GetCoordValue() != 0) {
  1125. RefPtr<nsROCSSPrimitiveValue> depth = new nsROCSSPrimitiveValue;
  1126. SetValueToCoord(depth, display->mTransformOrigin[2], false,
  1127. nullptr);
  1128. valueList->AppendCSSValue(depth.forget());
  1129. }
  1130. return valueList.forget();
  1131. }
  1132. /* Convert the stored representation into a list of two values and then hand
  1133. * it back.
  1134. */
  1135. already_AddRefed<CSSValue>
  1136. nsComputedDOMStyle::DoGetPerspectiveOrigin()
  1137. {
  1138. /* We need to build up a list of two values. We'll call them
  1139. * width and height.
  1140. */
  1141. /* Store things as a value list */
  1142. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  1143. /* Now, get the values. */
  1144. const nsStyleDisplay* display = StyleDisplay();
  1145. RefPtr<nsROCSSPrimitiveValue> width = new nsROCSSPrimitiveValue;
  1146. SetValueToCoord(width, display->mPerspectiveOrigin[0], false,
  1147. &nsComputedDOMStyle::GetFrameBoundsWidthForTransform);
  1148. valueList->AppendCSSValue(width.forget());
  1149. RefPtr<nsROCSSPrimitiveValue> height = new nsROCSSPrimitiveValue;
  1150. SetValueToCoord(height, display->mPerspectiveOrigin[1], false,
  1151. &nsComputedDOMStyle::GetFrameBoundsHeightForTransform);
  1152. valueList->AppendCSSValue(height.forget());
  1153. return valueList.forget();
  1154. }
  1155. already_AddRefed<CSSValue>
  1156. nsComputedDOMStyle::DoGetPerspective()
  1157. {
  1158. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1159. SetValueToCoord(val, StyleDisplay()->mChildPerspective, false);
  1160. return val.forget();
  1161. }
  1162. already_AddRefed<CSSValue>
  1163. nsComputedDOMStyle::DoGetBackfaceVisibility()
  1164. {
  1165. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1166. val->SetIdent(
  1167. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mBackfaceVisibility,
  1168. nsCSSProps::kBackfaceVisibilityKTable));
  1169. return val.forget();
  1170. }
  1171. already_AddRefed<CSSValue>
  1172. nsComputedDOMStyle::DoGetTransformStyle()
  1173. {
  1174. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1175. val->SetIdent(
  1176. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mTransformStyle,
  1177. nsCSSProps::kTransformStyleKTable));
  1178. return val.forget();
  1179. }
  1180. /* If the property is "none", hand back "none" wrapped in a value.
  1181. * Otherwise, compute the aggregate transform matrix and hands it back in a
  1182. * "matrix" wrapper.
  1183. */
  1184. already_AddRefed<CSSValue>
  1185. nsComputedDOMStyle::DoGetTransform()
  1186. {
  1187. /* First, get the display data. We'll need it. */
  1188. const nsStyleDisplay* display = StyleDisplay();
  1189. /* If there are no transforms, then we should construct a single-element
  1190. * entry and hand it back.
  1191. */
  1192. if (!display->mSpecifiedTransform) {
  1193. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1194. /* Set it to "none." */
  1195. val->SetIdent(eCSSKeyword_none);
  1196. return val.forget();
  1197. }
  1198. /* Otherwise, we need to compute the current value of the transform matrix,
  1199. * store it in a string, and hand it back to the caller.
  1200. */
  1201. /* Use the inner frame for the reference box. If we don't have an inner
  1202. * frame we use empty dimensions to allow us to continue (and percentage
  1203. * values in the transform will simply give broken results).
  1204. * TODO: There is no good way for us to represent the case where there's no
  1205. * frame, which is problematic. The reason is that when we have percentage
  1206. * transforms, there are a total of four stored matrix entries that influence
  1207. * the transform based on the size of the element. However, this poses a
  1208. * problem, because only two of these values can be explicitly referenced
  1209. * using the named transforms. Until a real solution is found, we'll just
  1210. * use this approach.
  1211. */
  1212. nsStyleTransformMatrix::TransformReferenceBox refBox(mInnerFrame,
  1213. nsSize(0, 0));
  1214. RuleNodeCacheConditions dummy;
  1215. bool dummyBool;
  1216. gfx::Matrix4x4 matrix =
  1217. nsStyleTransformMatrix::ReadTransforms(display->mSpecifiedTransform->mHead,
  1218. mStyleContext,
  1219. mStyleContext->PresContext(),
  1220. dummy,
  1221. refBox,
  1222. float(mozilla::AppUnitsPerCSSPixel()),
  1223. &dummyBool);
  1224. return MatrixToCSSValue(matrix);
  1225. }
  1226. already_AddRefed<CSSValue>
  1227. nsComputedDOMStyle::DoGetTransformBox()
  1228. {
  1229. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1230. val->SetIdent(
  1231. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mTransformBox,
  1232. nsCSSProps::kTransformBoxKTable));
  1233. return val.forget();
  1234. }
  1235. /* static */ already_AddRefed<nsROCSSPrimitiveValue>
  1236. nsComputedDOMStyle::MatrixToCSSValue(const mozilla::gfx::Matrix4x4& matrix)
  1237. {
  1238. bool is3D = !matrix.Is2D();
  1239. nsAutoString resultString(NS_LITERAL_STRING("matrix"));
  1240. if (is3D) {
  1241. resultString.AppendLiteral("3d");
  1242. }
  1243. resultString.Append('(');
  1244. resultString.AppendFloat(matrix._11);
  1245. resultString.AppendLiteral(", ");
  1246. resultString.AppendFloat(matrix._12);
  1247. resultString.AppendLiteral(", ");
  1248. if (is3D) {
  1249. resultString.AppendFloat(matrix._13);
  1250. resultString.AppendLiteral(", ");
  1251. resultString.AppendFloat(matrix._14);
  1252. resultString.AppendLiteral(", ");
  1253. }
  1254. resultString.AppendFloat(matrix._21);
  1255. resultString.AppendLiteral(", ");
  1256. resultString.AppendFloat(matrix._22);
  1257. resultString.AppendLiteral(", ");
  1258. if (is3D) {
  1259. resultString.AppendFloat(matrix._23);
  1260. resultString.AppendLiteral(", ");
  1261. resultString.AppendFloat(matrix._24);
  1262. resultString.AppendLiteral(", ");
  1263. resultString.AppendFloat(matrix._31);
  1264. resultString.AppendLiteral(", ");
  1265. resultString.AppendFloat(matrix._32);
  1266. resultString.AppendLiteral(", ");
  1267. resultString.AppendFloat(matrix._33);
  1268. resultString.AppendLiteral(", ");
  1269. resultString.AppendFloat(matrix._34);
  1270. resultString.AppendLiteral(", ");
  1271. }
  1272. resultString.AppendFloat(matrix._41);
  1273. resultString.AppendLiteral(", ");
  1274. resultString.AppendFloat(matrix._42);
  1275. if (is3D) {
  1276. resultString.AppendLiteral(", ");
  1277. resultString.AppendFloat(matrix._43);
  1278. resultString.AppendLiteral(", ");
  1279. resultString.AppendFloat(matrix._44);
  1280. }
  1281. resultString.Append(')');
  1282. /* Create a value to hold our result. */
  1283. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1284. val->SetString(resultString);
  1285. return val.forget();
  1286. }
  1287. already_AddRefed<CSSValue>
  1288. nsComputedDOMStyle::DoGetCounterReset()
  1289. {
  1290. const nsStyleContent *content = StyleContent();
  1291. if (content->CounterResetCount() == 0) {
  1292. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1293. val->SetIdent(eCSSKeyword_none);
  1294. return val.forget();
  1295. }
  1296. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  1297. for (uint32_t i = 0, i_end = content->CounterResetCount(); i < i_end; ++i) {
  1298. RefPtr<nsROCSSPrimitiveValue> name = new nsROCSSPrimitiveValue;
  1299. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  1300. const nsStyleCounterData& data = content->CounterResetAt(i);
  1301. nsAutoString escaped;
  1302. nsStyleUtil::AppendEscapedCSSIdent(data.mCounter, escaped);
  1303. name->SetString(escaped);
  1304. value->SetNumber(data.mValue); // XXX This should really be integer
  1305. valueList->AppendCSSValue(name.forget());
  1306. valueList->AppendCSSValue(value.forget());
  1307. }
  1308. return valueList.forget();
  1309. }
  1310. already_AddRefed<CSSValue>
  1311. nsComputedDOMStyle::DoGetQuotes()
  1312. {
  1313. const auto& quotePairs = StyleList()->GetQuotePairs();
  1314. if (quotePairs.IsEmpty()) {
  1315. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1316. val->SetIdent(eCSSKeyword_none);
  1317. return val.forget();
  1318. }
  1319. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  1320. for (const auto& quotePair : quotePairs) {
  1321. RefPtr<nsROCSSPrimitiveValue> openVal = new nsROCSSPrimitiveValue;
  1322. RefPtr<nsROCSSPrimitiveValue> closeVal = new nsROCSSPrimitiveValue;
  1323. nsAutoString s;
  1324. nsStyleUtil::AppendEscapedCSSString(quotePair.first, s);
  1325. openVal->SetString(s);
  1326. s.Truncate();
  1327. nsStyleUtil::AppendEscapedCSSString(quotePair.second, s);
  1328. closeVal->SetString(s);
  1329. valueList->AppendCSSValue(openVal.forget());
  1330. valueList->AppendCSSValue(closeVal.forget());
  1331. }
  1332. return valueList.forget();
  1333. }
  1334. already_AddRefed<CSSValue>
  1335. nsComputedDOMStyle::DoGetFontFamily()
  1336. {
  1337. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1338. const nsStyleFont* font = StyleFont();
  1339. nsAutoString fontlistStr;
  1340. nsStyleUtil::AppendEscapedCSSFontFamilyList(font->mFont.fontlist,
  1341. fontlistStr);
  1342. val->SetString(fontlistStr);
  1343. return val.forget();
  1344. }
  1345. already_AddRefed<CSSValue>
  1346. nsComputedDOMStyle::DoGetFontSize()
  1347. {
  1348. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1349. // Note: StyleFont()->mSize is the 'computed size';
  1350. // StyleFont()->mFont.size is the 'actual size'
  1351. val->SetAppUnits(StyleFont()->mSize);
  1352. return val.forget();
  1353. }
  1354. already_AddRefed<CSSValue>
  1355. nsComputedDOMStyle::DoGetFontSizeAdjust()
  1356. {
  1357. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1358. const nsStyleFont *font = StyleFont();
  1359. if (font->mFont.sizeAdjust >= 0.0f) {
  1360. val->SetNumber(font->mFont.sizeAdjust);
  1361. } else {
  1362. val->SetIdent(eCSSKeyword_none);
  1363. }
  1364. return val.forget();
  1365. }
  1366. already_AddRefed<CSSValue>
  1367. nsComputedDOMStyle::DoGetOsxFontSmoothing()
  1368. {
  1369. if (nsContentUtils::ShouldResistFingerprinting(
  1370. mPresShell->GetPresContext()->GetDocShell()))
  1371. return nullptr;
  1372. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1373. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.smoothing,
  1374. nsCSSProps::kFontSmoothingKTable));
  1375. return val.forget();
  1376. }
  1377. already_AddRefed<CSSValue>
  1378. nsComputedDOMStyle::DoGetFontStretch()
  1379. {
  1380. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1381. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.stretch,
  1382. nsCSSProps::kFontStretchKTable));
  1383. return val.forget();
  1384. }
  1385. already_AddRefed<CSSValue>
  1386. nsComputedDOMStyle::DoGetFontStyle()
  1387. {
  1388. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1389. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.style,
  1390. nsCSSProps::kFontStyleKTable));
  1391. return val.forget();
  1392. }
  1393. already_AddRefed<CSSValue>
  1394. nsComputedDOMStyle::DoGetFontWeight()
  1395. {
  1396. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1397. const nsStyleFont* font = StyleFont();
  1398. uint16_t weight = font->mFont.weight;
  1399. NS_ASSERTION(weight % 100 == 0, "unexpected value of font-weight");
  1400. val->SetNumber(weight);
  1401. return val.forget();
  1402. }
  1403. already_AddRefed<CSSValue>
  1404. nsComputedDOMStyle::DoGetFontFeatureSettings()
  1405. {
  1406. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1407. const nsStyleFont* font = StyleFont();
  1408. if (font->mFont.fontFeatureSettings.IsEmpty()) {
  1409. val->SetIdent(eCSSKeyword_normal);
  1410. } else {
  1411. nsAutoString result;
  1412. nsStyleUtil::AppendFontFeatureSettings(font->mFont.fontFeatureSettings,
  1413. result);
  1414. val->SetString(result);
  1415. }
  1416. return val.forget();
  1417. }
  1418. already_AddRefed<CSSValue>
  1419. nsComputedDOMStyle::DoGetFontVariationSettings()
  1420. {
  1421. // TODO: This is still a stub, always returning "normal"
  1422. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1423. val->SetIdent(eCSSKeyword_normal);
  1424. return val.forget();
  1425. }
  1426. already_AddRefed<CSSValue>
  1427. nsComputedDOMStyle::DoGetFontKerning()
  1428. {
  1429. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1430. val->SetIdent(
  1431. nsCSSProps::ValueToKeywordEnum(StyleFont()->mFont.kerning,
  1432. nsCSSProps::kFontKerningKTable));
  1433. return val.forget();
  1434. }
  1435. already_AddRefed<CSSValue>
  1436. nsComputedDOMStyle::DoGetFontLanguageOverride()
  1437. {
  1438. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1439. const nsStyleFont* font = StyleFont();
  1440. if (font->mFont.languageOverride.IsEmpty()) {
  1441. val->SetIdent(eCSSKeyword_normal);
  1442. } else {
  1443. nsAutoString str;
  1444. nsStyleUtil::AppendEscapedCSSString(font->mFont.languageOverride, str);
  1445. val->SetString(str);
  1446. }
  1447. return val.forget();
  1448. }
  1449. already_AddRefed<CSSValue>
  1450. nsComputedDOMStyle::DoGetFontSynthesis()
  1451. {
  1452. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1453. int32_t intValue = StyleFont()->mFont.synthesis;
  1454. if (0 == intValue) {
  1455. val->SetIdent(eCSSKeyword_none);
  1456. } else {
  1457. nsAutoString valueStr;
  1458. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_font_synthesis,
  1459. intValue, NS_FONT_SYNTHESIS_WEIGHT,
  1460. NS_FONT_SYNTHESIS_STYLE, valueStr);
  1461. val->SetString(valueStr);
  1462. }
  1463. return val.forget();
  1464. }
  1465. // return a value *only* for valid longhand values from CSS 2.1, either
  1466. // normal or small-caps only
  1467. already_AddRefed<CSSValue>
  1468. nsComputedDOMStyle::DoGetFontVariant()
  1469. {
  1470. const nsFont& f = StyleFont()->mFont;
  1471. // if any of the other font-variant subproperties other than
  1472. // font-variant-caps are not normal then can't calculate a computed value
  1473. if (f.variantAlternates || f.variantEastAsian || f.variantLigatures ||
  1474. f.variantNumeric || f.variantPosition) {
  1475. return nullptr;
  1476. }
  1477. nsCSSKeyword keyword;
  1478. switch (f.variantCaps) {
  1479. case 0:
  1480. keyword = eCSSKeyword_normal;
  1481. break;
  1482. case NS_FONT_VARIANT_CAPS_SMALLCAPS:
  1483. keyword = eCSSKeyword_small_caps;
  1484. break;
  1485. default:
  1486. return nullptr;
  1487. }
  1488. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1489. val->SetIdent(keyword);
  1490. return val.forget();
  1491. }
  1492. already_AddRefed<CSSValue>
  1493. nsComputedDOMStyle::DoGetFontVariantAlternates()
  1494. {
  1495. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1496. int32_t intValue = StyleFont()->mFont.variantAlternates;
  1497. if (0 == intValue) {
  1498. val->SetIdent(eCSSKeyword_normal);
  1499. return val.forget();
  1500. }
  1501. // first, include enumerated values
  1502. nsAutoString valueStr;
  1503. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_font_variant_alternates,
  1504. intValue & NS_FONT_VARIANT_ALTERNATES_ENUMERATED_MASK,
  1505. NS_FONT_VARIANT_ALTERNATES_HISTORICAL,
  1506. NS_FONT_VARIANT_ALTERNATES_HISTORICAL, valueStr);
  1507. // next, include functional values if present
  1508. if (intValue & NS_FONT_VARIANT_ALTERNATES_FUNCTIONAL_MASK) {
  1509. nsStyleUtil::SerializeFunctionalAlternates(StyleFont()->mFont.alternateValues,
  1510. valueStr);
  1511. }
  1512. val->SetString(valueStr);
  1513. return val.forget();
  1514. }
  1515. already_AddRefed<CSSValue>
  1516. nsComputedDOMStyle::DoGetFontVariantCaps()
  1517. {
  1518. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1519. int32_t intValue = StyleFont()->mFont.variantCaps;
  1520. if (0 == intValue) {
  1521. val->SetIdent(eCSSKeyword_normal);
  1522. } else {
  1523. val->SetIdent(
  1524. nsCSSProps::ValueToKeywordEnum(intValue,
  1525. nsCSSProps::kFontVariantCapsKTable));
  1526. }
  1527. return val.forget();
  1528. }
  1529. already_AddRefed<CSSValue>
  1530. nsComputedDOMStyle::DoGetFontVariantEastAsian()
  1531. {
  1532. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1533. int32_t intValue = StyleFont()->mFont.variantEastAsian;
  1534. if (0 == intValue) {
  1535. val->SetIdent(eCSSKeyword_normal);
  1536. } else {
  1537. nsAutoString valueStr;
  1538. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_font_variant_east_asian,
  1539. intValue, NS_FONT_VARIANT_EAST_ASIAN_JIS78,
  1540. NS_FONT_VARIANT_EAST_ASIAN_RUBY, valueStr);
  1541. val->SetString(valueStr);
  1542. }
  1543. return val.forget();
  1544. }
  1545. already_AddRefed<CSSValue>
  1546. nsComputedDOMStyle::DoGetFontVariantLigatures()
  1547. {
  1548. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1549. int32_t intValue = StyleFont()->mFont.variantLigatures;
  1550. if (0 == intValue) {
  1551. val->SetIdent(eCSSKeyword_normal);
  1552. } else if (NS_FONT_VARIANT_LIGATURES_NONE == intValue) {
  1553. val->SetIdent(eCSSKeyword_none);
  1554. } else {
  1555. nsAutoString valueStr;
  1556. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_font_variant_ligatures,
  1557. intValue, NS_FONT_VARIANT_LIGATURES_NONE,
  1558. NS_FONT_VARIANT_LIGATURES_NO_CONTEXTUAL, valueStr);
  1559. val->SetString(valueStr);
  1560. }
  1561. return val.forget();
  1562. }
  1563. already_AddRefed<CSSValue>
  1564. nsComputedDOMStyle::DoGetFontVariantNumeric()
  1565. {
  1566. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1567. int32_t intValue = StyleFont()->mFont.variantNumeric;
  1568. if (0 == intValue) {
  1569. val->SetIdent(eCSSKeyword_normal);
  1570. } else {
  1571. nsAutoString valueStr;
  1572. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_font_variant_numeric,
  1573. intValue, NS_FONT_VARIANT_NUMERIC_LINING,
  1574. NS_FONT_VARIANT_NUMERIC_ORDINAL, valueStr);
  1575. val->SetString(valueStr);
  1576. }
  1577. return val.forget();
  1578. }
  1579. already_AddRefed<CSSValue>
  1580. nsComputedDOMStyle::DoGetFontVariantPosition()
  1581. {
  1582. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1583. int32_t intValue = StyleFont()->mFont.variantPosition;
  1584. if (0 == intValue) {
  1585. val->SetIdent(eCSSKeyword_normal);
  1586. } else {
  1587. val->SetIdent(
  1588. nsCSSProps::ValueToKeywordEnum(intValue,
  1589. nsCSSProps::kFontVariantPositionKTable));
  1590. }
  1591. return val.forget();
  1592. }
  1593. already_AddRefed<CSSValue>
  1594. nsComputedDOMStyle::DoGetBackgroundAttachment()
  1595. {
  1596. return GetBackgroundList(&nsStyleImageLayers::Layer::mAttachment,
  1597. &nsStyleImageLayers::mAttachmentCount,
  1598. StyleBackground()->mImage,
  1599. nsCSSProps::kImageLayerAttachmentKTable);
  1600. }
  1601. already_AddRefed<CSSValue>
  1602. nsComputedDOMStyle::DoGetBackgroundClip()
  1603. {
  1604. return GetBackgroundList(&nsStyleImageLayers::Layer::mClip,
  1605. &nsStyleImageLayers::mClipCount,
  1606. StyleBackground()->mImage,
  1607. nsCSSProps::kBackgroundClipKTable);
  1608. }
  1609. already_AddRefed<CSSValue>
  1610. nsComputedDOMStyle::DoGetBackgroundColor()
  1611. {
  1612. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1613. SetToRGBAColor(val, StyleBackground()->mBackgroundColor);
  1614. return val.forget();
  1615. }
  1616. static void
  1617. SetValueToCalc(const nsStyleCoord::CalcValue* aCalc,
  1618. nsROCSSPrimitiveValue* aValue)
  1619. {
  1620. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1621. nsAutoString tmp, result;
  1622. result.AppendLiteral("calc(");
  1623. val->SetAppUnits(aCalc->mLength);
  1624. val->GetCssText(tmp);
  1625. result.Append(tmp);
  1626. if (aCalc->mHasPercent) {
  1627. result.AppendLiteral(" + ");
  1628. val->SetPercent(aCalc->mPercent);
  1629. val->GetCssText(tmp);
  1630. result.Append(tmp);
  1631. }
  1632. result.Append(')');
  1633. aValue->SetString(result); // not really SetString
  1634. }
  1635. static void
  1636. AppendCSSGradientLength(const nsStyleCoord& aValue,
  1637. nsROCSSPrimitiveValue* aPrimitive,
  1638. nsAString& aString)
  1639. {
  1640. nsAutoString tokenString;
  1641. if (aValue.IsCalcUnit())
  1642. SetValueToCalc(aValue.GetCalcValue(), aPrimitive);
  1643. else if (aValue.GetUnit() == eStyleUnit_Coord)
  1644. aPrimitive->SetAppUnits(aValue.GetCoordValue());
  1645. else
  1646. aPrimitive->SetPercent(aValue.GetPercentValue());
  1647. aPrimitive->GetCssText(tokenString);
  1648. aString.Append(tokenString);
  1649. }
  1650. static void
  1651. AppendCSSGradientToBoxPosition(const nsStyleGradient* aGradient,
  1652. nsAString& aString,
  1653. bool& aNeedSep)
  1654. {
  1655. float xValue = aGradient->mBgPosX.GetPercentValue();
  1656. float yValue = aGradient->mBgPosY.GetPercentValue();
  1657. if (yValue == 1.0f && xValue == 0.5f) {
  1658. // omit "to bottom"
  1659. return;
  1660. }
  1661. NS_ASSERTION(yValue != 0.5f || xValue != 0.5f, "invalid box position");
  1662. aString.AppendLiteral("to");
  1663. if (yValue == 0.0f) {
  1664. aString.AppendLiteral(" top");
  1665. } else if (yValue == 1.0f) {
  1666. aString.AppendLiteral(" bottom");
  1667. } else if (yValue != 0.5f) { // do not write "center" keyword
  1668. NS_NOTREACHED("invalid box position");
  1669. }
  1670. if (xValue == 0.0f) {
  1671. aString.AppendLiteral(" left");
  1672. } else if (xValue == 1.0f) {
  1673. aString.AppendLiteral(" right");
  1674. } else if (xValue != 0.5f) { // do not write "center" keyword
  1675. NS_NOTREACHED("invalid box position");
  1676. }
  1677. aNeedSep = true;
  1678. }
  1679. void
  1680. nsComputedDOMStyle::GetCSSGradientString(const nsStyleGradient* aGradient,
  1681. nsAString& aString)
  1682. {
  1683. if (!aGradient->mLegacySyntax) {
  1684. aString.Truncate();
  1685. } else {
  1686. aString.AssignLiteral("-moz-");
  1687. }
  1688. if (aGradient->mRepeating) {
  1689. aString.AppendLiteral("repeating-");
  1690. }
  1691. bool isRadial = aGradient->mShape != NS_STYLE_GRADIENT_SHAPE_LINEAR;
  1692. if (isRadial) {
  1693. aString.AppendLiteral("radial-gradient(");
  1694. } else {
  1695. aString.AppendLiteral("linear-gradient(");
  1696. }
  1697. bool needSep = false;
  1698. nsAutoString tokenString;
  1699. RefPtr<nsROCSSPrimitiveValue> tmpVal = new nsROCSSPrimitiveValue;
  1700. if (isRadial && !aGradient->mLegacySyntax) {
  1701. if (aGradient->mSize != NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE) {
  1702. if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
  1703. aString.AppendLiteral("circle");
  1704. needSep = true;
  1705. }
  1706. if (aGradient->mSize != NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER) {
  1707. if (needSep) {
  1708. aString.Append(' ');
  1709. }
  1710. AppendASCIItoUTF16(nsCSSProps::
  1711. ValueToKeyword(aGradient->mSize,
  1712. nsCSSProps::kRadialGradientSizeKTable),
  1713. aString);
  1714. needSep = true;
  1715. }
  1716. } else {
  1717. AppendCSSGradientLength(aGradient->mRadiusX, tmpVal, aString);
  1718. if (aGradient->mShape != NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
  1719. aString.Append(' ');
  1720. AppendCSSGradientLength(aGradient->mRadiusY, tmpVal, aString);
  1721. }
  1722. needSep = true;
  1723. }
  1724. }
  1725. if (aGradient->mBgPosX.GetUnit() != eStyleUnit_None) {
  1726. MOZ_ASSERT(aGradient->mBgPosY.GetUnit() != eStyleUnit_None);
  1727. if (!isRadial && !aGradient->mLegacySyntax) {
  1728. AppendCSSGradientToBoxPosition(aGradient, aString, needSep);
  1729. } else if (aGradient->mBgPosX.GetUnit() != eStyleUnit_Percent ||
  1730. aGradient->mBgPosX.GetPercentValue() != 0.5f ||
  1731. aGradient->mBgPosY.GetUnit() != eStyleUnit_Percent ||
  1732. aGradient->mBgPosY.GetPercentValue() != (isRadial ? 0.5f : 1.0f)) {
  1733. if (isRadial && !aGradient->mLegacySyntax) {
  1734. if (needSep) {
  1735. aString.Append(' ');
  1736. }
  1737. aString.AppendLiteral("at ");
  1738. needSep = false;
  1739. }
  1740. AppendCSSGradientLength(aGradient->mBgPosX, tmpVal, aString);
  1741. if (aGradient->mBgPosY.GetUnit() != eStyleUnit_None) {
  1742. aString.Append(' ');
  1743. AppendCSSGradientLength(aGradient->mBgPosY, tmpVal, aString);
  1744. }
  1745. needSep = true;
  1746. }
  1747. }
  1748. if (aGradient->mAngle.GetUnit() != eStyleUnit_None) {
  1749. MOZ_ASSERT(!isRadial || aGradient->mLegacySyntax);
  1750. if (needSep) {
  1751. aString.Append(' ');
  1752. }
  1753. nsStyleUtil::AppendAngleValue(aGradient->mAngle, aString);
  1754. needSep = true;
  1755. }
  1756. if (isRadial && aGradient->mLegacySyntax &&
  1757. (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR ||
  1758. aGradient->mSize != NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER)) {
  1759. MOZ_ASSERT(aGradient->mSize != NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE);
  1760. if (needSep) {
  1761. aString.AppendLiteral(", ");
  1762. needSep = false;
  1763. }
  1764. if (aGradient->mShape == NS_STYLE_GRADIENT_SHAPE_CIRCULAR) {
  1765. aString.AppendLiteral("circle");
  1766. needSep = true;
  1767. }
  1768. if (aGradient->mSize != NS_STYLE_GRADIENT_SIZE_FARTHEST_CORNER) {
  1769. if (needSep) {
  1770. aString.Append(' ');
  1771. }
  1772. AppendASCIItoUTF16(nsCSSProps::
  1773. ValueToKeyword(aGradient->mSize,
  1774. nsCSSProps::kRadialGradientSizeKTable),
  1775. aString);
  1776. }
  1777. needSep = true;
  1778. }
  1779. // color stops
  1780. for (uint32_t i = 0; i < aGradient->mStops.Length(); ++i) {
  1781. if (needSep) {
  1782. aString.AppendLiteral(", ");
  1783. }
  1784. const auto& stop = aGradient->mStops[i];
  1785. if (!stop.mIsInterpolationHint) {
  1786. SetToRGBAColor(tmpVal, stop.mColor);
  1787. tmpVal->GetCssText(tokenString);
  1788. aString.Append(tokenString);
  1789. }
  1790. if (stop.mLocation.GetUnit() != eStyleUnit_None) {
  1791. if (!stop.mIsInterpolationHint) {
  1792. aString.Append(' ');
  1793. }
  1794. AppendCSSGradientLength(stop.mLocation, tmpVal, aString);
  1795. }
  1796. needSep = true;
  1797. }
  1798. aString.Append(')');
  1799. }
  1800. // -moz-image-rect(<uri>, <top>, <right>, <bottom>, <left>)
  1801. void
  1802. nsComputedDOMStyle::GetImageRectString(nsIURI* aURI,
  1803. const nsStyleSides& aCropRect,
  1804. nsString& aString)
  1805. {
  1806. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1807. // <uri>
  1808. RefPtr<nsROCSSPrimitiveValue> valURI = new nsROCSSPrimitiveValue;
  1809. valURI->SetURI(aURI);
  1810. valueList->AppendCSSValue(valURI.forget());
  1811. // <top>, <right>, <bottom>, <left>
  1812. NS_FOR_CSS_SIDES(side) {
  1813. RefPtr<nsROCSSPrimitiveValue> valSide = new nsROCSSPrimitiveValue;
  1814. SetValueToCoord(valSide, aCropRect.Get(side), false);
  1815. valueList->AppendCSSValue(valSide.forget());
  1816. }
  1817. nsAutoString argumentString;
  1818. valueList->GetCssText(argumentString);
  1819. aString = NS_LITERAL_STRING("-moz-image-rect(") +
  1820. argumentString +
  1821. NS_LITERAL_STRING(")");
  1822. }
  1823. void
  1824. nsComputedDOMStyle::SetValueToStyleImage(const nsStyleImage& aStyleImage,
  1825. nsROCSSPrimitiveValue* aValue)
  1826. {
  1827. switch (aStyleImage.GetType()) {
  1828. case eStyleImageType_Image:
  1829. {
  1830. imgIRequest* req = aStyleImage.GetImageData();
  1831. if (!req) {
  1832. // XXXheycam If we had some problem resolving the imgRequestProxy,
  1833. // maybe we should just use the URL stored in the nsStyleImage's
  1834. // mImageValue? (Similarly in DoGetListStyleImage.)
  1835. aValue->SetIdent(eCSSKeyword_none);
  1836. break;
  1837. }
  1838. nsCOMPtr<nsIURI> uri;
  1839. req->GetURI(getter_AddRefs(uri));
  1840. const UniquePtr<nsStyleSides>& cropRect = aStyleImage.GetCropRect();
  1841. if (cropRect) {
  1842. nsAutoString imageRectString;
  1843. GetImageRectString(uri, *cropRect, imageRectString);
  1844. aValue->SetString(imageRectString);
  1845. } else {
  1846. aValue->SetURI(uri);
  1847. }
  1848. break;
  1849. }
  1850. case eStyleImageType_Gradient:
  1851. {
  1852. nsAutoString gradientString;
  1853. GetCSSGradientString(aStyleImage.GetGradientData(),
  1854. gradientString);
  1855. aValue->SetString(gradientString);
  1856. break;
  1857. }
  1858. case eStyleImageType_Element:
  1859. {
  1860. nsAutoString elementId;
  1861. nsStyleUtil::AppendEscapedCSSIdent(
  1862. nsDependentString(aStyleImage.GetElementId()), elementId);
  1863. nsAutoString elementString = NS_LITERAL_STRING("-moz-element(#") +
  1864. elementId +
  1865. NS_LITERAL_STRING(")");
  1866. aValue->SetString(elementString);
  1867. break;
  1868. }
  1869. case eStyleImageType_Null:
  1870. aValue->SetIdent(eCSSKeyword_none);
  1871. break;
  1872. default:
  1873. NS_NOTREACHED("unexpected image type");
  1874. break;
  1875. }
  1876. }
  1877. already_AddRefed<CSSValue>
  1878. nsComputedDOMStyle::DoGetImageLayerImage(const nsStyleImageLayers& aLayers)
  1879. {
  1880. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1881. for (uint32_t i = 0, i_end = aLayers.mImageCount; i < i_end; ++i) {
  1882. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1883. const nsStyleImage& image = aLayers.mLayers[i].mImage;
  1884. // Layer::mImage::GetType() returns eStyleImageType_Null in two conditions:
  1885. // 1. The value of mask-image/bg-image is 'none'.
  1886. // Since this layer does not refer to any source, Layer::mSourceURI must
  1887. // be nullptr too.
  1888. // 2. This layer refers to a local resource, e.g. mask-image:url(#mymask).
  1889. // For local references, there is no need to download any external
  1890. // resource, so Layer::mImage is not used.
  1891. // Instead, we store the local URI in one place -- on Layer::mSourceURI.
  1892. // Hence, we must serialize using mSourceURI (instead of
  1893. // SetValueToStyleImage()/mImage) in this case.
  1894. if (aLayers.mLayers[i].mSourceURI &&
  1895. aLayers.mLayers[i].mSourceURI->IsLocalRef()) {
  1896. // This is how we represent a 'mask-image' reference for a local URI,
  1897. // such as 'mask-image:url(#mymask)' or 'mask:url(#mymask)'
  1898. SetValueToURLValue(aLayers.mLayers[i].mSourceURI, val);
  1899. } else {
  1900. SetValueToStyleImage(image, val);
  1901. }
  1902. valueList->AppendCSSValue(val.forget());
  1903. }
  1904. return valueList.forget();
  1905. }
  1906. already_AddRefed<CSSValue>
  1907. nsComputedDOMStyle::DoGetImageLayerPosition(const nsStyleImageLayers& aLayers)
  1908. {
  1909. if (aLayers.mPositionXCount != aLayers.mPositionYCount) {
  1910. // No value to return. We can't express this combination of
  1911. // values as a shorthand.
  1912. return nullptr;
  1913. }
  1914. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1915. for (uint32_t i = 0, i_end = aLayers.mPositionXCount; i < i_end; ++i) {
  1916. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  1917. SetValueToPosition(aLayers.mLayers[i].mPosition, itemList);
  1918. valueList->AppendCSSValue(itemList.forget());
  1919. }
  1920. return valueList.forget();
  1921. }
  1922. already_AddRefed<CSSValue>
  1923. nsComputedDOMStyle::DoGetImageLayerPositionX(const nsStyleImageLayers& aLayers)
  1924. {
  1925. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1926. for (uint32_t i = 0, i_end = aLayers.mPositionXCount; i < i_end; ++i) {
  1927. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1928. SetValueToPositionCoord(aLayers.mLayers[i].mPosition.mXPosition, val);
  1929. valueList->AppendCSSValue(val.forget());
  1930. }
  1931. return valueList.forget();
  1932. }
  1933. already_AddRefed<CSSValue>
  1934. nsComputedDOMStyle::DoGetImageLayerPositionY(const nsStyleImageLayers& aLayers)
  1935. {
  1936. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1937. for (uint32_t i = 0, i_end = aLayers.mPositionYCount; i < i_end; ++i) {
  1938. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  1939. SetValueToPositionCoord(aLayers.mLayers[i].mPosition.mYPosition, val);
  1940. valueList->AppendCSSValue(val.forget());
  1941. }
  1942. return valueList.forget();
  1943. }
  1944. already_AddRefed<CSSValue>
  1945. nsComputedDOMStyle::DoGetImageLayerRepeat(const nsStyleImageLayers& aLayers)
  1946. {
  1947. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1948. for (uint32_t i = 0, i_end = aLayers.mRepeatCount; i < i_end; ++i) {
  1949. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  1950. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  1951. const uint8_t& xRepeat = aLayers.mLayers[i].mRepeat.mXRepeat;
  1952. const uint8_t& yRepeat = aLayers.mLayers[i].mRepeat.mYRepeat;
  1953. bool hasContraction = true;
  1954. unsigned contraction;
  1955. if (xRepeat == yRepeat) {
  1956. contraction = xRepeat;
  1957. } else if (xRepeat == NS_STYLE_IMAGELAYER_REPEAT_REPEAT &&
  1958. yRepeat == NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT) {
  1959. contraction = NS_STYLE_IMAGELAYER_REPEAT_REPEAT_X;
  1960. } else if (xRepeat == NS_STYLE_IMAGELAYER_REPEAT_NO_REPEAT &&
  1961. yRepeat == NS_STYLE_IMAGELAYER_REPEAT_REPEAT) {
  1962. contraction = NS_STYLE_IMAGELAYER_REPEAT_REPEAT_Y;
  1963. } else {
  1964. hasContraction = false;
  1965. }
  1966. RefPtr<nsROCSSPrimitiveValue> valY;
  1967. if (hasContraction) {
  1968. valX->SetIdent(nsCSSProps::ValueToKeywordEnum(contraction,
  1969. nsCSSProps::kImageLayerRepeatKTable));
  1970. } else {
  1971. valY = new nsROCSSPrimitiveValue;
  1972. valX->SetIdent(nsCSSProps::ValueToKeywordEnum(xRepeat,
  1973. nsCSSProps::kImageLayerRepeatKTable));
  1974. valY->SetIdent(nsCSSProps::ValueToKeywordEnum(yRepeat,
  1975. nsCSSProps::kImageLayerRepeatKTable));
  1976. }
  1977. itemList->AppendCSSValue(valX.forget());
  1978. if (valY) {
  1979. itemList->AppendCSSValue(valY.forget());
  1980. }
  1981. valueList->AppendCSSValue(itemList.forget());
  1982. }
  1983. return valueList.forget();
  1984. }
  1985. already_AddRefed<CSSValue>
  1986. nsComputedDOMStyle::DoGetImageLayerSize(const nsStyleImageLayers& aLayers)
  1987. {
  1988. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  1989. for (uint32_t i = 0, i_end = aLayers.mSizeCount; i < i_end; ++i) {
  1990. const nsStyleImageLayers::Size &size = aLayers.mLayers[i].mSize;
  1991. switch (size.mWidthType) {
  1992. case nsStyleImageLayers::Size::eContain:
  1993. case nsStyleImageLayers::Size::eCover: {
  1994. MOZ_ASSERT(size.mWidthType == size.mHeightType,
  1995. "unsynced types");
  1996. nsCSSKeyword keyword = size.mWidthType == nsStyleImageLayers::Size::eContain
  1997. ? eCSSKeyword_contain
  1998. : eCSSKeyword_cover;
  1999. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2000. val->SetIdent(keyword);
  2001. valueList->AppendCSSValue(val.forget());
  2002. break;
  2003. }
  2004. default: {
  2005. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  2006. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  2007. RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
  2008. if (size.mWidthType == nsStyleImageLayers::Size::eAuto) {
  2009. valX->SetIdent(eCSSKeyword_auto);
  2010. } else {
  2011. MOZ_ASSERT(size.mWidthType ==
  2012. nsStyleImageLayers::Size::eLengthPercentage,
  2013. "bad mWidthType");
  2014. if (!size.mWidth.mHasPercent &&
  2015. // negative values must have come from calc()
  2016. size.mWidth.mLength >= 0) {
  2017. MOZ_ASSERT(size.mWidth.mPercent == 0.0f,
  2018. "Shouldn't have mPercent");
  2019. valX->SetAppUnits(size.mWidth.mLength);
  2020. } else if (size.mWidth.mLength == 0 &&
  2021. // negative values must have come from calc()
  2022. size.mWidth.mPercent >= 0.0f) {
  2023. valX->SetPercent(size.mWidth.mPercent);
  2024. } else {
  2025. SetValueToCalc(&size.mWidth, valX);
  2026. }
  2027. }
  2028. if (size.mHeightType == nsStyleImageLayers::Size::eAuto) {
  2029. valY->SetIdent(eCSSKeyword_auto);
  2030. } else {
  2031. MOZ_ASSERT(size.mHeightType ==
  2032. nsStyleImageLayers::Size::eLengthPercentage,
  2033. "bad mHeightType");
  2034. if (!size.mHeight.mHasPercent &&
  2035. // negative values must have come from calc()
  2036. size.mHeight.mLength >= 0) {
  2037. MOZ_ASSERT(size.mHeight.mPercent == 0.0f,
  2038. "Shouldn't have mPercent");
  2039. valY->SetAppUnits(size.mHeight.mLength);
  2040. } else if (size.mHeight.mLength == 0 &&
  2041. // negative values must have come from calc()
  2042. size.mHeight.mPercent >= 0.0f) {
  2043. valY->SetPercent(size.mHeight.mPercent);
  2044. } else {
  2045. SetValueToCalc(&size.mHeight, valY);
  2046. }
  2047. }
  2048. itemList->AppendCSSValue(valX.forget());
  2049. itemList->AppendCSSValue(valY.forget());
  2050. valueList->AppendCSSValue(itemList.forget());
  2051. break;
  2052. }
  2053. }
  2054. }
  2055. return valueList.forget();
  2056. }
  2057. already_AddRefed<CSSValue>
  2058. nsComputedDOMStyle::DoGetBackgroundImage()
  2059. {
  2060. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2061. return DoGetImageLayerImage(layers);
  2062. }
  2063. already_AddRefed<CSSValue>
  2064. nsComputedDOMStyle::DoGetBackgroundBlendMode()
  2065. {
  2066. return GetBackgroundList(&nsStyleImageLayers::Layer::mBlendMode,
  2067. &nsStyleImageLayers::mBlendModeCount,
  2068. StyleBackground()->mImage,
  2069. nsCSSProps::kBlendModeKTable);
  2070. }
  2071. already_AddRefed<CSSValue>
  2072. nsComputedDOMStyle::DoGetBackgroundOrigin()
  2073. {
  2074. return GetBackgroundList(&nsStyleImageLayers::Layer::mOrigin,
  2075. &nsStyleImageLayers::mOriginCount,
  2076. StyleBackground()->mImage,
  2077. nsCSSProps::kBackgroundOriginKTable);
  2078. }
  2079. void
  2080. nsComputedDOMStyle::SetValueToPositionCoord(
  2081. const Position::Coord& aCoord,
  2082. nsROCSSPrimitiveValue* aValue)
  2083. {
  2084. if (!aCoord.mHasPercent) {
  2085. MOZ_ASSERT(aCoord.mPercent == 0.0f,
  2086. "Shouldn't have mPercent!");
  2087. aValue->SetAppUnits(aCoord.mLength);
  2088. } else if (aCoord.mLength == 0) {
  2089. aValue->SetPercent(aCoord.mPercent);
  2090. } else {
  2091. SetValueToCalc(&aCoord, aValue);
  2092. }
  2093. }
  2094. void
  2095. nsComputedDOMStyle::SetValueToPosition(
  2096. const Position& aPosition,
  2097. nsDOMCSSValueList* aValueList)
  2098. {
  2099. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  2100. SetValueToPositionCoord(aPosition.mXPosition, valX);
  2101. aValueList->AppendCSSValue(valX.forget());
  2102. RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
  2103. SetValueToPositionCoord(aPosition.mYPosition, valY);
  2104. aValueList->AppendCSSValue(valY.forget());
  2105. }
  2106. void
  2107. nsComputedDOMStyle::SetValueToURLValue(const css::URLValueData* aURL,
  2108. nsROCSSPrimitiveValue* aValue)
  2109. {
  2110. if (aURL && aURL->IsLocalRef()) {
  2111. nsString fragment;
  2112. aURL->GetSourceString(fragment);
  2113. fragment.Insert(u"url(\"", 0);
  2114. fragment.Append(u"\")");
  2115. aValue->SetString(fragment);
  2116. } else {
  2117. nsCOMPtr<nsIURI> url;
  2118. if (aURL && (url = aURL->GetURI())) {
  2119. aValue->SetURI(url);
  2120. } else {
  2121. aValue->SetIdent(eCSSKeyword_none);
  2122. }
  2123. }
  2124. }
  2125. already_AddRefed<CSSValue>
  2126. nsComputedDOMStyle::DoGetBackgroundPosition()
  2127. {
  2128. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2129. return DoGetImageLayerPosition(layers);
  2130. }
  2131. already_AddRefed<CSSValue>
  2132. nsComputedDOMStyle::DoGetBackgroundPositionX()
  2133. {
  2134. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2135. return DoGetImageLayerPositionX(layers);
  2136. }
  2137. already_AddRefed<CSSValue>
  2138. nsComputedDOMStyle::DoGetBackgroundPositionY()
  2139. {
  2140. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2141. return DoGetImageLayerPositionY(layers);
  2142. }
  2143. already_AddRefed<CSSValue>
  2144. nsComputedDOMStyle::DoGetBackgroundRepeat()
  2145. {
  2146. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2147. return DoGetImageLayerRepeat(layers);
  2148. }
  2149. already_AddRefed<CSSValue>
  2150. nsComputedDOMStyle::DoGetBackgroundSize()
  2151. {
  2152. const nsStyleImageLayers& layers = StyleBackground()->mImage;
  2153. return DoGetImageLayerSize(layers);
  2154. }
  2155. already_AddRefed<CSSValue>
  2156. nsComputedDOMStyle::DoGetGridTemplateAreas()
  2157. {
  2158. const css::GridTemplateAreasValue* areas =
  2159. StylePosition()->mGridTemplateAreas;
  2160. if (!areas) {
  2161. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2162. val->SetIdent(eCSSKeyword_none);
  2163. return val.forget();
  2164. }
  2165. MOZ_ASSERT(!areas->mTemplates.IsEmpty(),
  2166. "Unexpected empty array in GridTemplateAreasValue");
  2167. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2168. for (uint32_t i = 0; i < areas->mTemplates.Length(); i++) {
  2169. nsAutoString str;
  2170. nsStyleUtil::AppendEscapedCSSString(areas->mTemplates[i], str);
  2171. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2172. val->SetString(str);
  2173. valueList->AppendCSSValue(val.forget());
  2174. }
  2175. return valueList.forget();
  2176. }
  2177. void
  2178. nsComputedDOMStyle::AppendGridLineNames(nsString& aResult,
  2179. const nsTArray<nsString>& aLineNames)
  2180. {
  2181. uint32_t numLines = aLineNames.Length();
  2182. if (numLines == 0) {
  2183. return;
  2184. }
  2185. for (uint32_t i = 0;;) {
  2186. nsStyleUtil::AppendEscapedCSSIdent(aLineNames[i], aResult);
  2187. if (++i == numLines) {
  2188. break;
  2189. }
  2190. aResult.Append(' ');
  2191. }
  2192. }
  2193. void
  2194. nsComputedDOMStyle::AppendGridLineNames(nsDOMCSSValueList* aValueList,
  2195. const nsTArray<nsString>& aLineNames,
  2196. bool aSuppressEmptyList)
  2197. {
  2198. if (aLineNames.IsEmpty() && aSuppressEmptyList) {
  2199. return;
  2200. }
  2201. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2202. nsAutoString lineNamesString;
  2203. lineNamesString.Assign('[');
  2204. AppendGridLineNames(lineNamesString, aLineNames);
  2205. lineNamesString.Append(']');
  2206. val->SetString(lineNamesString);
  2207. aValueList->AppendCSSValue(val.forget());
  2208. }
  2209. void
  2210. nsComputedDOMStyle::AppendGridLineNames(nsDOMCSSValueList* aValueList,
  2211. const nsTArray<nsString>& aLineNames1,
  2212. const nsTArray<nsString>& aLineNames2)
  2213. {
  2214. if (aLineNames1.IsEmpty() && aLineNames2.IsEmpty()) {
  2215. return;
  2216. }
  2217. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2218. nsAutoString lineNamesString;
  2219. lineNamesString.Assign('[');
  2220. if (!aLineNames1.IsEmpty()) {
  2221. AppendGridLineNames(lineNamesString, aLineNames1);
  2222. }
  2223. if (!aLineNames2.IsEmpty()) {
  2224. if (!aLineNames1.IsEmpty()) {
  2225. lineNamesString.Append(' ');
  2226. }
  2227. AppendGridLineNames(lineNamesString, aLineNames2);
  2228. }
  2229. lineNamesString.Append(']');
  2230. val->SetString(lineNamesString);
  2231. aValueList->AppendCSSValue(val.forget());
  2232. }
  2233. already_AddRefed<CSSValue>
  2234. nsComputedDOMStyle::GetGridTrackSize(const nsStyleCoord& aMinValue,
  2235. const nsStyleCoord& aMaxValue)
  2236. {
  2237. if (aMinValue.GetUnit() == eStyleUnit_None) {
  2238. // A fit-content() function.
  2239. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2240. nsAutoString argumentStr, fitContentStr;
  2241. fitContentStr.AppendLiteral("fit-content(");
  2242. MOZ_ASSERT(aMaxValue.IsCoordPercentCalcUnit(),
  2243. "unexpected unit for fit-content() argument value");
  2244. SetValueToCoord(val, aMaxValue, true);
  2245. val->GetCssText(argumentStr);
  2246. fitContentStr.Append(argumentStr);
  2247. fitContentStr.Append(char16_t(')'));
  2248. val->SetString(fitContentStr);
  2249. return val.forget();
  2250. }
  2251. if (aMinValue == aMaxValue) {
  2252. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2253. SetValueToCoord(val, aMinValue, true,
  2254. nullptr, nsCSSProps::kGridTrackBreadthKTable);
  2255. return val.forget();
  2256. }
  2257. // minmax(auto, <flex>) is equivalent to (and is our internal representation
  2258. // of) <flex>, and both compute to <flex>
  2259. if (aMinValue.GetUnit() == eStyleUnit_Auto &&
  2260. aMaxValue.GetUnit() == eStyleUnit_FlexFraction) {
  2261. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2262. SetValueToCoord(val, aMaxValue, true);
  2263. return val.forget();
  2264. }
  2265. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2266. nsAutoString argumentStr, minmaxStr;
  2267. minmaxStr.AppendLiteral("minmax(");
  2268. SetValueToCoord(val, aMinValue, true,
  2269. nullptr, nsCSSProps::kGridTrackBreadthKTable);
  2270. val->GetCssText(argumentStr);
  2271. minmaxStr.Append(argumentStr);
  2272. minmaxStr.AppendLiteral(", ");
  2273. SetValueToCoord(val, aMaxValue, true,
  2274. nullptr, nsCSSProps::kGridTrackBreadthKTable);
  2275. val->GetCssText(argumentStr);
  2276. minmaxStr.Append(argumentStr);
  2277. minmaxStr.Append(char16_t(')'));
  2278. val->SetString(minmaxStr);
  2279. return val.forget();
  2280. }
  2281. already_AddRefed<CSSValue>
  2282. nsComputedDOMStyle::GetGridTemplateColumnsRows(
  2283. const nsStyleGridTemplate& aTrackList,
  2284. const ComputedGridTrackInfo* aTrackInfo)
  2285. {
  2286. if (aTrackList.mIsSubgrid) {
  2287. // XXX TODO: add support for repeat(auto-fill) for 'subgrid' (bug 1234311)
  2288. NS_ASSERTION(aTrackList.mMinTrackSizingFunctions.IsEmpty() &&
  2289. aTrackList.mMaxTrackSizingFunctions.IsEmpty(),
  2290. "Unexpected sizing functions with subgrid");
  2291. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2292. RefPtr<nsROCSSPrimitiveValue> subgridKeyword = new nsROCSSPrimitiveValue;
  2293. subgridKeyword->SetIdent(eCSSKeyword_subgrid);
  2294. valueList->AppendCSSValue(subgridKeyword.forget());
  2295. for (uint32_t i = 0, len = aTrackList.mLineNameLists.Length(); ; ++i) {
  2296. if (MOZ_UNLIKELY(aTrackList.IsRepeatAutoIndex(i))) {
  2297. MOZ_ASSERT(aTrackList.mIsAutoFill, "subgrid can only have 'auto-fill'");
  2298. MOZ_ASSERT(aTrackList.mRepeatAutoLineNameListAfter.IsEmpty(),
  2299. "mRepeatAutoLineNameListAfter isn't used for subgrid");
  2300. RefPtr<nsROCSSPrimitiveValue> start = new nsROCSSPrimitiveValue;
  2301. start->SetString(NS_LITERAL_STRING("repeat(auto-fill,"));
  2302. valueList->AppendCSSValue(start.forget());
  2303. AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListBefore,
  2304. /*aSuppressEmptyList*/ false);
  2305. RefPtr<nsROCSSPrimitiveValue> end = new nsROCSSPrimitiveValue;
  2306. end->SetString(NS_LITERAL_STRING(")"));
  2307. valueList->AppendCSSValue(end.forget());
  2308. }
  2309. if (i == len) {
  2310. break;
  2311. }
  2312. AppendGridLineNames(valueList, aTrackList.mLineNameLists[i],
  2313. /*aSuppressEmptyList*/ false);
  2314. }
  2315. return valueList.forget();
  2316. }
  2317. uint32_t numSizes = aTrackList.mMinTrackSizingFunctions.Length();
  2318. MOZ_ASSERT(aTrackList.mMaxTrackSizingFunctions.Length() == numSizes,
  2319. "Different number of min and max track sizing functions");
  2320. if (aTrackInfo) {
  2321. DebugOnly<bool> isAutoFill =
  2322. aTrackList.HasRepeatAuto() && aTrackList.mIsAutoFill;
  2323. DebugOnly<bool> isAutoFit =
  2324. aTrackList.HasRepeatAuto() && !aTrackList.mIsAutoFill;
  2325. DebugOnly<uint32_t> numExplicitTracks = aTrackInfo->mNumExplicitTracks;
  2326. MOZ_ASSERT(numExplicitTracks == numSizes ||
  2327. (isAutoFill && numExplicitTracks >= numSizes) ||
  2328. (isAutoFit && numExplicitTracks + 1 >= numSizes),
  2329. "expected all explicit tracks (or possibly one less, if there's "
  2330. "an 'auto-fit' track, since that can collapse away)");
  2331. numSizes = aTrackInfo->mSizes.Length();
  2332. }
  2333. // An empty <track-list> without repeats is represented as "none" in syntax.
  2334. if (numSizes == 0 && !aTrackList.HasRepeatAuto()) {
  2335. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2336. val->SetIdent(eCSSKeyword_none);
  2337. return val.forget();
  2338. }
  2339. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2340. if (aTrackInfo) {
  2341. // We've done layout on the grid and have resolved the sizes of its tracks,
  2342. // so we'll return those sizes here. The grid spec says we MAY use
  2343. // repeat(<positive-integer>, Npx) here for consecutive tracks with the same
  2344. // size, but that doesn't seem worth doing since even for repeat(auto-*)
  2345. // the resolved size might differ for the repeated tracks.
  2346. const nsTArray<nscoord>& trackSizes = aTrackInfo->mSizes;
  2347. const uint32_t numExplicitTracks = aTrackInfo->mNumExplicitTracks;
  2348. const uint32_t numLeadingImplicitTracks = aTrackInfo->mNumLeadingImplicitTracks;
  2349. MOZ_ASSERT(numSizes >= numLeadingImplicitTracks + numExplicitTracks);
  2350. // Add any leading implicit tracks.
  2351. for (uint32_t i = 0; i < numLeadingImplicitTracks; ++i) {
  2352. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2353. val->SetAppUnits(trackSizes[i]);
  2354. valueList->AppendCSSValue(val.forget());
  2355. }
  2356. // Then add any explicit tracks and removed auto-fit tracks.
  2357. if (numExplicitTracks || aTrackList.HasRepeatAuto()) {
  2358. int32_t endOfRepeat = 0; // first index after any repeat() tracks
  2359. int32_t offsetToLastRepeat = 0;
  2360. if (aTrackList.HasRepeatAuto()) {
  2361. // offsetToLastRepeat is -1 if all repeat(auto-fit) tracks are empty
  2362. offsetToLastRepeat = numExplicitTracks + 1 - aTrackList.mLineNameLists.Length();
  2363. endOfRepeat = aTrackList.mRepeatAutoIndex + offsetToLastRepeat + 1;
  2364. }
  2365. uint32_t repeatIndex = 0;
  2366. uint32_t numRepeatTracks = aTrackInfo->mRemovedRepeatTracks.Length();
  2367. enum LinePlacement { LinesPrecede, LinesFollow, LinesBetween };
  2368. auto AppendRemovedAutoFits = [this, aTrackInfo, &valueList, aTrackList,
  2369. &repeatIndex,
  2370. numRepeatTracks](LinePlacement aPlacement)
  2371. {
  2372. // Add in removed auto-fit tracks and lines here, if necessary
  2373. bool atLeastOneTrackReported = false;
  2374. while (repeatIndex < numRepeatTracks &&
  2375. aTrackInfo->mRemovedRepeatTracks[repeatIndex]) {
  2376. if ((aPlacement == LinesPrecede) ||
  2377. ((aPlacement == LinesBetween) && atLeastOneTrackReported)) {
  2378. // Precede it with the lines between repeats.
  2379. AppendGridLineNames(valueList,
  2380. aTrackList.mRepeatAutoLineNameListAfter,
  2381. aTrackList.mRepeatAutoLineNameListBefore);
  2382. }
  2383. // Removed 'auto-fit' tracks are reported as 0px.
  2384. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2385. val->SetAppUnits(0);
  2386. valueList->AppendCSSValue(val.forget());
  2387. atLeastOneTrackReported = true;
  2388. if (aPlacement == LinesFollow) {
  2389. // Follow it with the lines between repeats.
  2390. AppendGridLineNames(valueList,
  2391. aTrackList.mRepeatAutoLineNameListAfter,
  2392. aTrackList.mRepeatAutoLineNameListBefore);
  2393. }
  2394. repeatIndex++;
  2395. }
  2396. repeatIndex++;
  2397. };
  2398. for (int32_t i = 0;; i++) {
  2399. if (aTrackList.HasRepeatAuto()) {
  2400. if (i == aTrackList.mRepeatAutoIndex) {
  2401. const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[i];
  2402. if (i == endOfRepeat) {
  2403. // All auto-fit tracks are empty, but we report them anyway.
  2404. AppendGridLineNames(valueList, lineNames,
  2405. aTrackList.mRepeatAutoLineNameListBefore);
  2406. AppendRemovedAutoFits(LinesBetween);
  2407. AppendGridLineNames(valueList,
  2408. aTrackList.mRepeatAutoLineNameListAfter,
  2409. aTrackList.mLineNameLists[i + 1]);
  2410. } else {
  2411. AppendGridLineNames(valueList, lineNames,
  2412. aTrackList.mRepeatAutoLineNameListBefore);
  2413. AppendRemovedAutoFits(LinesFollow);
  2414. }
  2415. } else if (i == endOfRepeat) {
  2416. // Before appending the last line, finish off any removed auto-fits.
  2417. AppendRemovedAutoFits(LinesPrecede);
  2418. const nsTArray<nsString>& lineNames =
  2419. aTrackList.mLineNameLists[aTrackList.mRepeatAutoIndex + 1];
  2420. AppendGridLineNames(valueList,
  2421. aTrackList.mRepeatAutoLineNameListAfter,
  2422. lineNames);
  2423. } else if (i > aTrackList.mRepeatAutoIndex && i < endOfRepeat) {
  2424. AppendGridLineNames(valueList,
  2425. aTrackList.mRepeatAutoLineNameListAfter,
  2426. aTrackList.mRepeatAutoLineNameListBefore);
  2427. AppendRemovedAutoFits(LinesFollow);
  2428. } else {
  2429. uint32_t j = i > endOfRepeat ? i - offsetToLastRepeat : i;
  2430. const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[j];
  2431. AppendGridLineNames(valueList, lineNames);
  2432. }
  2433. } else {
  2434. const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[i];
  2435. AppendGridLineNames(valueList, lineNames);
  2436. }
  2437. if (uint32_t(i) == numExplicitTracks) {
  2438. break;
  2439. }
  2440. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2441. val->SetAppUnits(trackSizes[i + numLeadingImplicitTracks]);
  2442. valueList->AppendCSSValue(val.forget());
  2443. }
  2444. }
  2445. // Add any trailing implicit tracks.
  2446. for (uint32_t i = numLeadingImplicitTracks + numExplicitTracks;
  2447. i < numSizes; ++i) {
  2448. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2449. val->SetAppUnits(trackSizes[i]);
  2450. valueList->AppendCSSValue(val.forget());
  2451. }
  2452. } else {
  2453. // We don't have a frame. So, we'll just return a serialization of
  2454. // the tracks from the style (without resolved sizes).
  2455. for (uint32_t i = 0;; i++) {
  2456. const nsTArray<nsString>& lineNames = aTrackList.mLineNameLists[i];
  2457. if (!lineNames.IsEmpty()) {
  2458. AppendGridLineNames(valueList, lineNames);
  2459. }
  2460. if (i == numSizes) {
  2461. break;
  2462. }
  2463. if (MOZ_UNLIKELY(aTrackList.IsRepeatAutoIndex(i))) {
  2464. RefPtr<nsROCSSPrimitiveValue> start = new nsROCSSPrimitiveValue;
  2465. start->SetString(aTrackList.mIsAutoFill ? NS_LITERAL_STRING("repeat(auto-fill,")
  2466. : NS_LITERAL_STRING("repeat(auto-fit,"));
  2467. valueList->AppendCSSValue(start.forget());
  2468. if (!aTrackList.mRepeatAutoLineNameListBefore.IsEmpty()) {
  2469. AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListBefore);
  2470. }
  2471. valueList->AppendCSSValue(
  2472. GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
  2473. aTrackList.mMaxTrackSizingFunctions[i]));
  2474. if (!aTrackList.mRepeatAutoLineNameListAfter.IsEmpty()) {
  2475. AppendGridLineNames(valueList, aTrackList.mRepeatAutoLineNameListAfter);
  2476. }
  2477. RefPtr<nsROCSSPrimitiveValue> end = new nsROCSSPrimitiveValue;
  2478. end->SetString(NS_LITERAL_STRING(")"));
  2479. valueList->AppendCSSValue(end.forget());
  2480. } else {
  2481. valueList->AppendCSSValue(
  2482. GetGridTrackSize(aTrackList.mMinTrackSizingFunctions[i],
  2483. aTrackList.mMaxTrackSizingFunctions[i]));
  2484. }
  2485. }
  2486. }
  2487. return valueList.forget();
  2488. }
  2489. already_AddRefed<CSSValue>
  2490. nsComputedDOMStyle::DoGetGridAutoFlow()
  2491. {
  2492. nsAutoString str;
  2493. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_grid_auto_flow,
  2494. StylePosition()->mGridAutoFlow,
  2495. NS_STYLE_GRID_AUTO_FLOW_ROW,
  2496. NS_STYLE_GRID_AUTO_FLOW_DENSE,
  2497. str);
  2498. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2499. val->SetString(str);
  2500. return val.forget();
  2501. }
  2502. already_AddRefed<CSSValue>
  2503. nsComputedDOMStyle::DoGetGridAutoColumns()
  2504. {
  2505. return GetGridTrackSize(StylePosition()->mGridAutoColumnsMin,
  2506. StylePosition()->mGridAutoColumnsMax);
  2507. }
  2508. already_AddRefed<CSSValue>
  2509. nsComputedDOMStyle::DoGetGridAutoRows()
  2510. {
  2511. return GetGridTrackSize(StylePosition()->mGridAutoRowsMin,
  2512. StylePosition()->mGridAutoRowsMax);
  2513. }
  2514. already_AddRefed<CSSValue>
  2515. nsComputedDOMStyle::DoGetGridTemplateColumns()
  2516. {
  2517. const ComputedGridTrackInfo* info = nullptr;
  2518. nsGridContainerFrame* gridFrame =
  2519. nsGridContainerFrame::GetGridFrameWithComputedInfo(
  2520. mElement->GetPrimaryFrame());
  2521. if (gridFrame) {
  2522. info = gridFrame->GetComputedTemplateColumns();
  2523. }
  2524. return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateColumns, info);
  2525. }
  2526. already_AddRefed<CSSValue>
  2527. nsComputedDOMStyle::DoGetGridTemplateRows()
  2528. {
  2529. const ComputedGridTrackInfo* info = nullptr;
  2530. nsGridContainerFrame* gridFrame =
  2531. nsGridContainerFrame::GetGridFrameWithComputedInfo(
  2532. mElement->GetPrimaryFrame());
  2533. if (gridFrame) {
  2534. info = gridFrame->GetComputedTemplateRows();
  2535. }
  2536. return GetGridTemplateColumnsRows(StylePosition()->mGridTemplateRows, info);
  2537. }
  2538. already_AddRefed<CSSValue>
  2539. nsComputedDOMStyle::GetGridLine(const nsStyleGridLine& aGridLine)
  2540. {
  2541. if (aGridLine.IsAuto()) {
  2542. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2543. val->SetIdent(eCSSKeyword_auto);
  2544. return val.forget();
  2545. }
  2546. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2547. if (aGridLine.mHasSpan) {
  2548. RefPtr<nsROCSSPrimitiveValue> span = new nsROCSSPrimitiveValue;
  2549. span->SetIdent(eCSSKeyword_span);
  2550. valueList->AppendCSSValue(span.forget());
  2551. }
  2552. if (aGridLine.mInteger != 0) {
  2553. RefPtr<nsROCSSPrimitiveValue> integer = new nsROCSSPrimitiveValue;
  2554. integer->SetNumber(aGridLine.mInteger);
  2555. valueList->AppendCSSValue(integer.forget());
  2556. }
  2557. if (!aGridLine.mLineName.IsEmpty()) {
  2558. RefPtr<nsROCSSPrimitiveValue> lineName = new nsROCSSPrimitiveValue;
  2559. nsString escapedLineName;
  2560. nsStyleUtil::AppendEscapedCSSIdent(aGridLine.mLineName, escapedLineName);
  2561. lineName->SetString(escapedLineName);
  2562. valueList->AppendCSSValue(lineName.forget());
  2563. }
  2564. NS_ASSERTION(valueList->Length() > 0,
  2565. "Should have appended at least one value");
  2566. return valueList.forget();
  2567. }
  2568. already_AddRefed<CSSValue>
  2569. nsComputedDOMStyle::DoGetGridColumnStart()
  2570. {
  2571. return GetGridLine(StylePosition()->mGridColumnStart);
  2572. }
  2573. already_AddRefed<CSSValue>
  2574. nsComputedDOMStyle::DoGetGridColumnEnd()
  2575. {
  2576. return GetGridLine(StylePosition()->mGridColumnEnd);
  2577. }
  2578. already_AddRefed<CSSValue>
  2579. nsComputedDOMStyle::DoGetGridRowStart()
  2580. {
  2581. return GetGridLine(StylePosition()->mGridRowStart);
  2582. }
  2583. already_AddRefed<CSSValue>
  2584. nsComputedDOMStyle::DoGetGridRowEnd()
  2585. {
  2586. return GetGridLine(StylePosition()->mGridRowEnd);
  2587. }
  2588. already_AddRefed<CSSValue>
  2589. nsComputedDOMStyle::DoGetGridColumnGap()
  2590. {
  2591. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2592. SetValueToCoord(val, StylePosition()->mGridColumnGap, true);
  2593. return val.forget();
  2594. }
  2595. already_AddRefed<CSSValue>
  2596. nsComputedDOMStyle::DoGetGridRowGap()
  2597. {
  2598. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2599. SetValueToCoord(val, StylePosition()->mGridRowGap, true);
  2600. return val.forget();
  2601. }
  2602. already_AddRefed<CSSValue>
  2603. nsComputedDOMStyle::DoGetPaddingTop()
  2604. {
  2605. return GetPaddingWidthFor(NS_SIDE_TOP);
  2606. }
  2607. already_AddRefed<CSSValue>
  2608. nsComputedDOMStyle::DoGetPaddingBottom()
  2609. {
  2610. return GetPaddingWidthFor(NS_SIDE_BOTTOM);
  2611. }
  2612. already_AddRefed<CSSValue>
  2613. nsComputedDOMStyle::DoGetPaddingLeft()
  2614. {
  2615. return GetPaddingWidthFor(NS_SIDE_LEFT);
  2616. }
  2617. already_AddRefed<CSSValue>
  2618. nsComputedDOMStyle::DoGetPaddingRight()
  2619. {
  2620. return GetPaddingWidthFor(NS_SIDE_RIGHT);
  2621. }
  2622. already_AddRefed<CSSValue>
  2623. nsComputedDOMStyle::DoGetBorderCollapse()
  2624. {
  2625. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2626. val->SetIdent(
  2627. nsCSSProps::ValueToKeywordEnum(StyleTableBorder()->mBorderCollapse,
  2628. nsCSSProps::kBorderCollapseKTable));
  2629. return val.forget();
  2630. }
  2631. already_AddRefed<CSSValue>
  2632. nsComputedDOMStyle::DoGetBorderSpacing()
  2633. {
  2634. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2635. RefPtr<nsROCSSPrimitiveValue> xSpacing = new nsROCSSPrimitiveValue;
  2636. RefPtr<nsROCSSPrimitiveValue> ySpacing = new nsROCSSPrimitiveValue;
  2637. const nsStyleTableBorder *border = StyleTableBorder();
  2638. xSpacing->SetAppUnits(border->mBorderSpacingCol);
  2639. ySpacing->SetAppUnits(border->mBorderSpacingRow);
  2640. valueList->AppendCSSValue(xSpacing.forget());
  2641. valueList->AppendCSSValue(ySpacing.forget());
  2642. return valueList.forget();
  2643. }
  2644. already_AddRefed<CSSValue>
  2645. nsComputedDOMStyle::DoGetCaptionSide()
  2646. {
  2647. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2648. val->SetIdent(
  2649. nsCSSProps::ValueToKeywordEnum(StyleTableBorder()->mCaptionSide,
  2650. nsCSSProps::kCaptionSideKTable));
  2651. return val.forget();
  2652. }
  2653. already_AddRefed<CSSValue>
  2654. nsComputedDOMStyle::DoGetEmptyCells()
  2655. {
  2656. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2657. val->SetIdent(
  2658. nsCSSProps::ValueToKeywordEnum(StyleTableBorder()->mEmptyCells,
  2659. nsCSSProps::kEmptyCellsKTable));
  2660. return val.forget();
  2661. }
  2662. already_AddRefed<CSSValue>
  2663. nsComputedDOMStyle::DoGetTableLayout()
  2664. {
  2665. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2666. val->SetIdent(
  2667. nsCSSProps::ValueToKeywordEnum(StyleTable()->mLayoutStrategy,
  2668. nsCSSProps::kTableLayoutKTable));
  2669. return val.forget();
  2670. }
  2671. already_AddRefed<CSSValue>
  2672. nsComputedDOMStyle::DoGetBorderTopStyle()
  2673. {
  2674. return GetBorderStyleFor(NS_SIDE_TOP);
  2675. }
  2676. already_AddRefed<CSSValue>
  2677. nsComputedDOMStyle::DoGetBorderBottomStyle()
  2678. {
  2679. return GetBorderStyleFor(NS_SIDE_BOTTOM);
  2680. }
  2681. already_AddRefed<CSSValue>
  2682. nsComputedDOMStyle::DoGetBorderLeftStyle()
  2683. {
  2684. return GetBorderStyleFor(NS_SIDE_LEFT);
  2685. }
  2686. already_AddRefed<CSSValue>
  2687. nsComputedDOMStyle::DoGetBorderRightStyle()
  2688. {
  2689. return GetBorderStyleFor(NS_SIDE_RIGHT);
  2690. }
  2691. already_AddRefed<CSSValue>
  2692. nsComputedDOMStyle::DoGetBorderBottomColors()
  2693. {
  2694. return GetBorderColorsFor(NS_SIDE_BOTTOM);
  2695. }
  2696. already_AddRefed<CSSValue>
  2697. nsComputedDOMStyle::DoGetBorderLeftColors()
  2698. {
  2699. return GetBorderColorsFor(NS_SIDE_LEFT);
  2700. }
  2701. already_AddRefed<CSSValue>
  2702. nsComputedDOMStyle::DoGetBorderRightColors()
  2703. {
  2704. return GetBorderColorsFor(NS_SIDE_RIGHT);
  2705. }
  2706. already_AddRefed<CSSValue>
  2707. nsComputedDOMStyle::DoGetBorderTopColors()
  2708. {
  2709. return GetBorderColorsFor(NS_SIDE_TOP);
  2710. }
  2711. already_AddRefed<CSSValue>
  2712. nsComputedDOMStyle::DoGetBorderBottomLeftRadius()
  2713. {
  2714. return GetEllipseRadii(StyleBorder()->mBorderRadius,
  2715. NS_CORNER_BOTTOM_LEFT);
  2716. }
  2717. already_AddRefed<CSSValue>
  2718. nsComputedDOMStyle::DoGetBorderBottomRightRadius()
  2719. {
  2720. return GetEllipseRadii(StyleBorder()->mBorderRadius,
  2721. NS_CORNER_BOTTOM_RIGHT);
  2722. }
  2723. already_AddRefed<CSSValue>
  2724. nsComputedDOMStyle::DoGetBorderTopLeftRadius()
  2725. {
  2726. return GetEllipseRadii(StyleBorder()->mBorderRadius,
  2727. NS_CORNER_TOP_LEFT);
  2728. }
  2729. already_AddRefed<CSSValue>
  2730. nsComputedDOMStyle::DoGetBorderTopRightRadius()
  2731. {
  2732. return GetEllipseRadii(StyleBorder()->mBorderRadius,
  2733. NS_CORNER_TOP_RIGHT);
  2734. }
  2735. already_AddRefed<CSSValue>
  2736. nsComputedDOMStyle::DoGetBorderTopWidth()
  2737. {
  2738. return GetBorderWidthFor(NS_SIDE_TOP);
  2739. }
  2740. already_AddRefed<CSSValue>
  2741. nsComputedDOMStyle::DoGetBorderBottomWidth()
  2742. {
  2743. return GetBorderWidthFor(NS_SIDE_BOTTOM);
  2744. }
  2745. already_AddRefed<CSSValue>
  2746. nsComputedDOMStyle::DoGetBorderLeftWidth()
  2747. {
  2748. return GetBorderWidthFor(NS_SIDE_LEFT);
  2749. }
  2750. already_AddRefed<CSSValue>
  2751. nsComputedDOMStyle::DoGetBorderRightWidth()
  2752. {
  2753. return GetBorderWidthFor(NS_SIDE_RIGHT);
  2754. }
  2755. already_AddRefed<CSSValue>
  2756. nsComputedDOMStyle::DoGetBorderTopColor()
  2757. {
  2758. return GetBorderColorFor(NS_SIDE_TOP);
  2759. }
  2760. already_AddRefed<CSSValue>
  2761. nsComputedDOMStyle::DoGetBorderBottomColor()
  2762. {
  2763. return GetBorderColorFor(NS_SIDE_BOTTOM);
  2764. }
  2765. already_AddRefed<CSSValue>
  2766. nsComputedDOMStyle::DoGetBorderLeftColor()
  2767. {
  2768. return GetBorderColorFor(NS_SIDE_LEFT);
  2769. }
  2770. already_AddRefed<CSSValue>
  2771. nsComputedDOMStyle::DoGetBorderRightColor()
  2772. {
  2773. return GetBorderColorFor(NS_SIDE_RIGHT);
  2774. }
  2775. already_AddRefed<CSSValue>
  2776. nsComputedDOMStyle::DoGetMarginTopWidth()
  2777. {
  2778. return GetMarginWidthFor(NS_SIDE_TOP);
  2779. }
  2780. already_AddRefed<CSSValue>
  2781. nsComputedDOMStyle::DoGetMarginBottomWidth()
  2782. {
  2783. return GetMarginWidthFor(NS_SIDE_BOTTOM);
  2784. }
  2785. already_AddRefed<CSSValue>
  2786. nsComputedDOMStyle::DoGetMarginLeftWidth()
  2787. {
  2788. return GetMarginWidthFor(NS_SIDE_LEFT);
  2789. }
  2790. already_AddRefed<CSSValue>
  2791. nsComputedDOMStyle::DoGetMarginRightWidth()
  2792. {
  2793. return GetMarginWidthFor(NS_SIDE_RIGHT);
  2794. }
  2795. already_AddRefed<CSSValue>
  2796. nsComputedDOMStyle::DoGetOrient()
  2797. {
  2798. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2799. val->SetIdent(
  2800. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mOrient,
  2801. nsCSSProps::kOrientKTable));
  2802. return val.forget();
  2803. }
  2804. already_AddRefed<CSSValue>
  2805. nsComputedDOMStyle::DoGetScrollBehavior()
  2806. {
  2807. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2808. val->SetIdent(
  2809. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mScrollBehavior,
  2810. nsCSSProps::kScrollBehaviorKTable));
  2811. return val.forget();
  2812. }
  2813. already_AddRefed<CSSValue>
  2814. nsComputedDOMStyle::DoGetScrollSnapType()
  2815. {
  2816. const nsStyleDisplay* display = StyleDisplay();
  2817. if (display->mScrollSnapTypeX != display->mScrollSnapTypeY) {
  2818. // No value to return. We can't express this combination of
  2819. // values as a shorthand.
  2820. return nullptr;
  2821. }
  2822. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2823. val->SetIdent(
  2824. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mScrollSnapTypeX,
  2825. nsCSSProps::kScrollSnapTypeKTable));
  2826. return val.forget();
  2827. }
  2828. already_AddRefed<CSSValue>
  2829. nsComputedDOMStyle::DoGetScrollSnapTypeX()
  2830. {
  2831. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2832. val->SetIdent(
  2833. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mScrollSnapTypeX,
  2834. nsCSSProps::kScrollSnapTypeKTable));
  2835. return val.forget();
  2836. }
  2837. already_AddRefed<CSSValue>
  2838. nsComputedDOMStyle::DoGetScrollSnapTypeY()
  2839. {
  2840. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2841. val->SetIdent(
  2842. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mScrollSnapTypeY,
  2843. nsCSSProps::kScrollSnapTypeKTable));
  2844. return val.forget();
  2845. }
  2846. already_AddRefed<CSSValue>
  2847. nsComputedDOMStyle::DoGetScrollbarWidth()
  2848. {
  2849. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2850. val->SetIdent(
  2851. nsCSSProps::ValueToKeywordEnum(StyleUserInterface()->mScrollbarWidth,
  2852. nsCSSProps::kScrollbarWidthKTable));
  2853. return val.forget();
  2854. }
  2855. already_AddRefed<CSSValue>
  2856. nsComputedDOMStyle::GetScrollSnapPoints(const nsStyleCoord& aCoord)
  2857. {
  2858. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2859. if (aCoord.GetUnit() == eStyleUnit_None) {
  2860. val->SetIdent(eCSSKeyword_none);
  2861. } else {
  2862. nsAutoString argumentString;
  2863. SetCssTextToCoord(argumentString, aCoord);
  2864. nsAutoString tmp;
  2865. tmp.AppendLiteral("repeat(");
  2866. tmp.Append(argumentString);
  2867. tmp.Append(')');
  2868. val->SetString(tmp);
  2869. }
  2870. return val.forget();
  2871. }
  2872. already_AddRefed<CSSValue>
  2873. nsComputedDOMStyle::DoGetScrollSnapPointsX()
  2874. {
  2875. return GetScrollSnapPoints(StyleDisplay()->mScrollSnapPointsX);
  2876. }
  2877. already_AddRefed<CSSValue>
  2878. nsComputedDOMStyle::DoGetScrollSnapPointsY()
  2879. {
  2880. return GetScrollSnapPoints(StyleDisplay()->mScrollSnapPointsY);
  2881. }
  2882. already_AddRefed<CSSValue>
  2883. nsComputedDOMStyle::DoGetScrollSnapDestination()
  2884. {
  2885. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2886. SetValueToPosition(StyleDisplay()->mScrollSnapDestination, valueList);
  2887. return valueList.forget();
  2888. }
  2889. already_AddRefed<CSSValue>
  2890. nsComputedDOMStyle::DoGetScrollSnapCoordinate()
  2891. {
  2892. const nsStyleDisplay* sd = StyleDisplay();
  2893. if (sd->mScrollSnapCoordinate.IsEmpty()) {
  2894. // Having no snap coordinates is interpreted as "none"
  2895. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2896. val->SetIdent(eCSSKeyword_none);
  2897. return val.forget();
  2898. } else {
  2899. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  2900. for (size_t i = 0, i_end = sd->mScrollSnapCoordinate.Length(); i < i_end; ++i) {
  2901. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  2902. SetValueToPosition(sd->mScrollSnapCoordinate[i], itemList);
  2903. valueList->AppendCSSValue(itemList.forget());
  2904. }
  2905. return valueList.forget();
  2906. }
  2907. }
  2908. already_AddRefed<CSSValue>
  2909. nsComputedDOMStyle::DoGetOutlineWidth()
  2910. {
  2911. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2912. const nsStyleOutline* outline = StyleOutline();
  2913. nscoord width;
  2914. if (outline->mOutlineStyle == NS_STYLE_BORDER_STYLE_NONE) {
  2915. NS_ASSERTION(outline->GetOutlineWidth() == 0, "unexpected width");
  2916. width = 0;
  2917. } else {
  2918. width = outline->GetOutlineWidth();
  2919. }
  2920. val->SetAppUnits(width);
  2921. return val.forget();
  2922. }
  2923. already_AddRefed<CSSValue>
  2924. nsComputedDOMStyle::DoGetOutlineStyle()
  2925. {
  2926. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2927. val->SetIdent(
  2928. nsCSSProps::ValueToKeywordEnum(StyleOutline()->mOutlineStyle,
  2929. nsCSSProps::kOutlineStyleKTable));
  2930. return val.forget();
  2931. }
  2932. already_AddRefed<CSSValue>
  2933. nsComputedDOMStyle::DoGetOutlineOffset()
  2934. {
  2935. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2936. val->SetAppUnits(StyleOutline()->mOutlineOffset);
  2937. return val.forget();
  2938. }
  2939. already_AddRefed<CSSValue>
  2940. nsComputedDOMStyle::DoGetOutlineRadiusBottomLeft()
  2941. {
  2942. return GetEllipseRadii(StyleOutline()->mOutlineRadius,
  2943. NS_CORNER_BOTTOM_LEFT);
  2944. }
  2945. already_AddRefed<CSSValue>
  2946. nsComputedDOMStyle::DoGetOutlineRadiusBottomRight()
  2947. {
  2948. return GetEllipseRadii(StyleOutline()->mOutlineRadius,
  2949. NS_CORNER_BOTTOM_RIGHT);
  2950. }
  2951. already_AddRefed<CSSValue>
  2952. nsComputedDOMStyle::DoGetOutlineRadiusTopLeft()
  2953. {
  2954. return GetEllipseRadii(StyleOutline()->mOutlineRadius,
  2955. NS_CORNER_TOP_LEFT);
  2956. }
  2957. already_AddRefed<CSSValue>
  2958. nsComputedDOMStyle::DoGetOutlineRadiusTopRight()
  2959. {
  2960. return GetEllipseRadii(StyleOutline()->mOutlineRadius,
  2961. NS_CORNER_TOP_RIGHT);
  2962. }
  2963. already_AddRefed<CSSValue>
  2964. nsComputedDOMStyle::DoGetOutlineColor()
  2965. {
  2966. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2967. SetValueFromComplexColor(val, StyleOutline()->mOutlineColor);
  2968. return val.forget();
  2969. }
  2970. already_AddRefed<CSSValue>
  2971. nsComputedDOMStyle::GetEllipseRadii(const nsStyleCorners& aRadius,
  2972. uint8_t aFullCorner)
  2973. {
  2974. nsStyleCoord radiusX = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, false));
  2975. nsStyleCoord radiusY = aRadius.Get(NS_FULL_TO_HALF_CORNER(aFullCorner, true));
  2976. // for compatibility, return a single value if X and Y are equal
  2977. if (radiusX == radiusY) {
  2978. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2979. SetValueToCoord(val, radiusX, true);
  2980. return val.forget();
  2981. }
  2982. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  2983. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  2984. RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
  2985. SetValueToCoord(valX, radiusX, true);
  2986. SetValueToCoord(valY, radiusY, true);
  2987. valueList->AppendCSSValue(valX.forget());
  2988. valueList->AppendCSSValue(valY.forget());
  2989. return valueList.forget();
  2990. }
  2991. already_AddRefed<CSSValue>
  2992. nsComputedDOMStyle::GetCSSShadowArray(nsCSSShadowArray* aArray,
  2993. const nscolor& aDefaultColor,
  2994. bool aIsBoxShadow)
  2995. {
  2996. if (!aArray) {
  2997. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  2998. val->SetIdent(eCSSKeyword_none);
  2999. return val.forget();
  3000. }
  3001. static nscoord nsCSSShadowItem::* const shadowValuesNoSpread[] = {
  3002. &nsCSSShadowItem::mXOffset,
  3003. &nsCSSShadowItem::mYOffset,
  3004. &nsCSSShadowItem::mRadius
  3005. };
  3006. static nscoord nsCSSShadowItem::* const shadowValuesWithSpread[] = {
  3007. &nsCSSShadowItem::mXOffset,
  3008. &nsCSSShadowItem::mYOffset,
  3009. &nsCSSShadowItem::mRadius,
  3010. &nsCSSShadowItem::mSpread
  3011. };
  3012. nscoord nsCSSShadowItem::* const * shadowValues;
  3013. uint32_t shadowValuesLength;
  3014. if (aIsBoxShadow) {
  3015. shadowValues = shadowValuesWithSpread;
  3016. shadowValuesLength = ArrayLength(shadowValuesWithSpread);
  3017. } else {
  3018. shadowValues = shadowValuesNoSpread;
  3019. shadowValuesLength = ArrayLength(shadowValuesNoSpread);
  3020. }
  3021. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  3022. for (nsCSSShadowItem *item = aArray->ShadowAt(0),
  3023. *item_end = item + aArray->Length();
  3024. item < item_end; ++item) {
  3025. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  3026. // Color is either the specified shadow color or the foreground color
  3027. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3028. nscolor shadowColor;
  3029. if (item->mHasColor) {
  3030. shadowColor = item->mColor;
  3031. } else {
  3032. shadowColor = aDefaultColor;
  3033. }
  3034. SetToRGBAColor(val, shadowColor);
  3035. itemList->AppendCSSValue(val.forget());
  3036. // Set the offsets, blur radius, and spread if available
  3037. for (uint32_t i = 0; i < shadowValuesLength; ++i) {
  3038. val = new nsROCSSPrimitiveValue;
  3039. val->SetAppUnits(item->*(shadowValues[i]));
  3040. itemList->AppendCSSValue(val.forget());
  3041. }
  3042. if (item->mInset && aIsBoxShadow) {
  3043. // This is an inset box-shadow
  3044. val = new nsROCSSPrimitiveValue;
  3045. val->SetIdent(
  3046. nsCSSProps::ValueToKeywordEnum(
  3047. uint8_t(StyleBoxShadowType::Inset),
  3048. nsCSSProps::kBoxShadowTypeKTable));
  3049. itemList->AppendCSSValue(val.forget());
  3050. }
  3051. valueList->AppendCSSValue(itemList.forget());
  3052. }
  3053. return valueList.forget();
  3054. }
  3055. already_AddRefed<CSSValue>
  3056. nsComputedDOMStyle::DoGetBoxDecorationBreak()
  3057. {
  3058. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3059. val->SetIdent(
  3060. nsCSSProps::ValueToKeywordEnum(StyleBorder()->mBoxDecorationBreak,
  3061. nsCSSProps::kBoxDecorationBreakKTable));
  3062. return val.forget();
  3063. }
  3064. already_AddRefed<CSSValue>
  3065. nsComputedDOMStyle::DoGetBoxShadow()
  3066. {
  3067. return GetCSSShadowArray(StyleEffects()->mBoxShadow,
  3068. StyleColor()->mColor,
  3069. true);
  3070. }
  3071. already_AddRefed<CSSValue>
  3072. nsComputedDOMStyle::DoGetZIndex()
  3073. {
  3074. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3075. SetValueToCoord(val, StylePosition()->mZIndex, false);
  3076. return val.forget();
  3077. }
  3078. already_AddRefed<CSSValue>
  3079. nsComputedDOMStyle::DoGetListStyleImage()
  3080. {
  3081. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3082. const nsStyleList* list = StyleList();
  3083. // XXXheycam As in SetValueToStyleImage, we might want to use the
  3084. // URL stored in the nsStyleImageRequest's mImageValue if we
  3085. // failed to resolve the imgRequestProxy.
  3086. imgRequestProxy* image = list->GetListStyleImage();
  3087. if (!image) {
  3088. val->SetIdent(eCSSKeyword_none);
  3089. } else {
  3090. nsCOMPtr<nsIURI> uri;
  3091. image->GetURI(getter_AddRefs(uri));
  3092. val->SetURI(uri);
  3093. }
  3094. return val.forget();
  3095. }
  3096. already_AddRefed<CSSValue>
  3097. nsComputedDOMStyle::DoGetListStylePosition()
  3098. {
  3099. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3100. val->SetIdent(
  3101. nsCSSProps::ValueToKeywordEnum(StyleList()->mListStylePosition,
  3102. nsCSSProps::kListStylePositionKTable));
  3103. return val.forget();
  3104. }
  3105. already_AddRefed<CSSValue>
  3106. nsComputedDOMStyle::DoGetListStyleType()
  3107. {
  3108. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3109. CounterStyle* style = StyleList()->GetCounterStyle();
  3110. AnonymousCounterStyle* anonymous = style->AsAnonymous();
  3111. nsAutoString tmp;
  3112. if (!anonymous) {
  3113. // want SetIdent
  3114. nsString type;
  3115. StyleList()->GetListStyleType(type);
  3116. nsStyleUtil::AppendEscapedCSSIdent(type, tmp);
  3117. } else if (anonymous->IsSingleString()) {
  3118. const nsTArray<nsString>& symbols = anonymous->GetSymbols();
  3119. MOZ_ASSERT(symbols.Length() == 1);
  3120. nsStyleUtil::AppendEscapedCSSString(symbols[0], tmp);
  3121. } else {
  3122. tmp.AppendLiteral("symbols(");
  3123. uint8_t system = anonymous->GetSystem();
  3124. NS_ASSERTION(system == NS_STYLE_COUNTER_SYSTEM_CYCLIC ||
  3125. system == NS_STYLE_COUNTER_SYSTEM_NUMERIC ||
  3126. system == NS_STYLE_COUNTER_SYSTEM_ALPHABETIC ||
  3127. system == NS_STYLE_COUNTER_SYSTEM_SYMBOLIC ||
  3128. system == NS_STYLE_COUNTER_SYSTEM_FIXED,
  3129. "Invalid system for anonymous counter style.");
  3130. if (system != NS_STYLE_COUNTER_SYSTEM_SYMBOLIC) {
  3131. AppendASCIItoUTF16(nsCSSProps::ValueToKeyword(
  3132. system, nsCSSProps::kCounterSystemKTable), tmp);
  3133. tmp.Append(' ');
  3134. }
  3135. const nsTArray<nsString>& symbols = anonymous->GetSymbols();
  3136. NS_ASSERTION(symbols.Length() > 0,
  3137. "No symbols in the anonymous counter style");
  3138. for (size_t i = 0, iend = symbols.Length(); i < iend; i++) {
  3139. nsStyleUtil::AppendEscapedCSSString(symbols[i], tmp);
  3140. tmp.Append(' ');
  3141. }
  3142. tmp.Replace(tmp.Length() - 1, 1, char16_t(')'));
  3143. }
  3144. val->SetString(tmp);
  3145. return val.forget();
  3146. }
  3147. already_AddRefed<CSSValue>
  3148. nsComputedDOMStyle::DoGetImageRegion()
  3149. {
  3150. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3151. const nsStyleList* list = StyleList();
  3152. if (list->mImageRegion.width <= 0 || list->mImageRegion.height <= 0) {
  3153. val->SetIdent(eCSSKeyword_auto);
  3154. } else {
  3155. // create the cssvalues for the sides, stick them in the rect object
  3156. nsROCSSPrimitiveValue *topVal = new nsROCSSPrimitiveValue;
  3157. nsROCSSPrimitiveValue *rightVal = new nsROCSSPrimitiveValue;
  3158. nsROCSSPrimitiveValue *bottomVal = new nsROCSSPrimitiveValue;
  3159. nsROCSSPrimitiveValue *leftVal = new nsROCSSPrimitiveValue;
  3160. nsDOMCSSRect * domRect = new nsDOMCSSRect(topVal, rightVal,
  3161. bottomVal, leftVal);
  3162. topVal->SetAppUnits(list->mImageRegion.y);
  3163. rightVal->SetAppUnits(list->mImageRegion.width + list->mImageRegion.x);
  3164. bottomVal->SetAppUnits(list->mImageRegion.height + list->mImageRegion.y);
  3165. leftVal->SetAppUnits(list->mImageRegion.x);
  3166. val->SetRect(domRect);
  3167. }
  3168. return val.forget();
  3169. }
  3170. already_AddRefed<CSSValue>
  3171. nsComputedDOMStyle::DoGetInitialLetter()
  3172. {
  3173. const nsStyleTextReset* textReset = StyleTextReset();
  3174. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3175. if (textReset->mInitialLetterSink == 0) {
  3176. val->SetIdent(eCSSKeyword_normal);
  3177. return val.forget();
  3178. } else {
  3179. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3180. val->SetNumber(textReset->mInitialLetterSize);
  3181. valueList->AppendCSSValue(val.forget());
  3182. RefPtr<nsROCSSPrimitiveValue> second = new nsROCSSPrimitiveValue;
  3183. second->SetNumber(textReset->mInitialLetterSink);
  3184. valueList->AppendCSSValue(second.forget());
  3185. return valueList.forget();
  3186. }
  3187. }
  3188. already_AddRefed<CSSValue>
  3189. nsComputedDOMStyle::DoGetLineHeight()
  3190. {
  3191. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3192. nscoord lineHeight;
  3193. if (GetLineHeightCoord(lineHeight)) {
  3194. val->SetAppUnits(lineHeight);
  3195. } else {
  3196. SetValueToCoord(val, StyleText()->mLineHeight, true,
  3197. nullptr, nsCSSProps::kLineHeightKTable);
  3198. }
  3199. return val.forget();
  3200. }
  3201. already_AddRefed<CSSValue>
  3202. nsComputedDOMStyle::DoGetRubyAlign()
  3203. {
  3204. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3205. val->SetIdent(nsCSSProps::ValueToKeywordEnum(
  3206. StyleText()->mRubyAlign, nsCSSProps::kRubyAlignKTable));
  3207. return val.forget();
  3208. }
  3209. already_AddRefed<CSSValue>
  3210. nsComputedDOMStyle::DoGetRubyPosition()
  3211. {
  3212. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3213. val->SetIdent(nsCSSProps::ValueToKeywordEnum(
  3214. StyleText()->mRubyPosition, nsCSSProps::kRubyPositionKTable));
  3215. return val.forget();
  3216. }
  3217. already_AddRefed<CSSValue>
  3218. nsComputedDOMStyle::DoGetVerticalAlign()
  3219. {
  3220. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3221. SetValueToCoord(val, StyleDisplay()->mVerticalAlign, false,
  3222. nullptr, nsCSSProps::kVerticalAlignKTable);
  3223. return val.forget();
  3224. }
  3225. already_AddRefed<CSSValue>
  3226. nsComputedDOMStyle::CreateTextAlignValue(uint8_t aAlign, bool aAlignTrue,
  3227. const KTableEntry aTable[])
  3228. {
  3229. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3230. val->SetIdent(nsCSSProps::ValueToKeywordEnum(aAlign, aTable));
  3231. if (!aAlignTrue) {
  3232. return val.forget();
  3233. }
  3234. RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
  3235. first->SetIdent(eCSSKeyword_unsafe);
  3236. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3237. valueList->AppendCSSValue(first.forget());
  3238. valueList->AppendCSSValue(val.forget());
  3239. return valueList.forget();
  3240. }
  3241. already_AddRefed<CSSValue>
  3242. nsComputedDOMStyle::DoGetTextAlign()
  3243. {
  3244. const nsStyleText* style = StyleText();
  3245. return CreateTextAlignValue(style->mTextAlign, style->mTextAlignTrue,
  3246. nsCSSProps::kTextAlignKTable);
  3247. }
  3248. already_AddRefed<CSSValue>
  3249. nsComputedDOMStyle::DoGetTextAlignLast()
  3250. {
  3251. const nsStyleText* style = StyleText();
  3252. return CreateTextAlignValue(style->mTextAlignLast, style->mTextAlignLastTrue,
  3253. nsCSSProps::kTextAlignLastKTable);
  3254. }
  3255. already_AddRefed<CSSValue>
  3256. nsComputedDOMStyle::DoGetTextCombineUpright()
  3257. {
  3258. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3259. uint8_t tch = StyleText()->mTextCombineUpright;
  3260. if (tch <= NS_STYLE_TEXT_COMBINE_UPRIGHT_ALL) {
  3261. val->SetIdent(
  3262. nsCSSProps::ValueToKeywordEnum(tch,
  3263. nsCSSProps::kTextCombineUprightKTable));
  3264. } else if (tch <= NS_STYLE_TEXT_COMBINE_UPRIGHT_DIGITS_2) {
  3265. val->SetString(NS_LITERAL_STRING("digits 2"));
  3266. } else if (tch <= NS_STYLE_TEXT_COMBINE_UPRIGHT_DIGITS_3) {
  3267. val->SetString(NS_LITERAL_STRING("digits 3"));
  3268. } else {
  3269. val->SetString(NS_LITERAL_STRING("digits 4"));
  3270. }
  3271. return val.forget();
  3272. }
  3273. already_AddRefed<CSSValue>
  3274. nsComputedDOMStyle::DoGetTextDecoration()
  3275. {
  3276. const nsStyleTextReset* textReset = StyleTextReset();
  3277. bool isInitialStyle =
  3278. textReset->mTextDecorationStyle == NS_STYLE_TEXT_DECORATION_STYLE_SOLID;
  3279. StyleComplexColor color = textReset->mTextDecorationColor;
  3280. if (isInitialStyle && color.IsCurrentColor()) {
  3281. return DoGetTextDecorationLine();
  3282. }
  3283. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3284. valueList->AppendCSSValue(DoGetTextDecorationLine());
  3285. if (!isInitialStyle) {
  3286. valueList->AppendCSSValue(DoGetTextDecorationStyle());
  3287. }
  3288. if (!color.IsCurrentColor()) {
  3289. valueList->AppendCSSValue(DoGetTextDecorationColor());
  3290. }
  3291. return valueList.forget();
  3292. }
  3293. already_AddRefed<CSSValue>
  3294. nsComputedDOMStyle::DoGetTextDecorationColor()
  3295. {
  3296. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3297. SetValueFromComplexColor(val, StyleTextReset()->mTextDecorationColor);
  3298. return val.forget();
  3299. }
  3300. already_AddRefed<CSSValue>
  3301. nsComputedDOMStyle::DoGetTextDecorationLine()
  3302. {
  3303. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3304. int32_t intValue = StyleTextReset()->mTextDecorationLine;
  3305. if (NS_STYLE_TEXT_DECORATION_LINE_NONE == intValue) {
  3306. val->SetIdent(eCSSKeyword_none);
  3307. } else {
  3308. nsAutoString decorationLineString;
  3309. // Clear the -moz-anchor-decoration bit and the OVERRIDE_ALL bits -- we
  3310. // don't want these to appear in the computed style.
  3311. intValue &= ~(NS_STYLE_TEXT_DECORATION_LINE_PREF_ANCHORS |
  3312. NS_STYLE_TEXT_DECORATION_LINE_OVERRIDE_ALL);
  3313. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_text_decoration_line,
  3314. intValue, NS_STYLE_TEXT_DECORATION_LINE_UNDERLINE,
  3315. NS_STYLE_TEXT_DECORATION_LINE_BLINK, decorationLineString);
  3316. val->SetString(decorationLineString);
  3317. }
  3318. return val.forget();
  3319. }
  3320. already_AddRefed<CSSValue>
  3321. nsComputedDOMStyle::DoGetTextDecorationStyle()
  3322. {
  3323. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3324. val->SetIdent(
  3325. nsCSSProps::ValueToKeywordEnum(StyleTextReset()->mTextDecorationStyle,
  3326. nsCSSProps::kTextDecorationStyleKTable));
  3327. return val.forget();
  3328. }
  3329. already_AddRefed<CSSValue>
  3330. nsComputedDOMStyle::DoGetTextEmphasisColor()
  3331. {
  3332. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3333. SetValueFromComplexColor(val, StyleText()->mTextEmphasisColor);
  3334. return val.forget();
  3335. }
  3336. already_AddRefed<CSSValue>
  3337. nsComputedDOMStyle::DoGetTextEmphasisPosition()
  3338. {
  3339. auto position = StyleText()->mTextEmphasisPosition;
  3340. MOZ_ASSERT(!(position & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER) !=
  3341. !(position & NS_STYLE_TEXT_EMPHASIS_POSITION_UNDER));
  3342. RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
  3343. first->SetIdent((position & NS_STYLE_TEXT_EMPHASIS_POSITION_OVER) ?
  3344. eCSSKeyword_over : eCSSKeyword_under);
  3345. MOZ_ASSERT(!(position & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT) !=
  3346. !(position & NS_STYLE_TEXT_EMPHASIS_POSITION_RIGHT));
  3347. RefPtr<nsROCSSPrimitiveValue> second = new nsROCSSPrimitiveValue;
  3348. second->SetIdent((position & NS_STYLE_TEXT_EMPHASIS_POSITION_LEFT) ?
  3349. eCSSKeyword_left : eCSSKeyword_right);
  3350. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3351. valueList->AppendCSSValue(first.forget());
  3352. valueList->AppendCSSValue(second.forget());
  3353. return valueList.forget();
  3354. }
  3355. already_AddRefed<CSSValue>
  3356. nsComputedDOMStyle::DoGetTextEmphasisStyle()
  3357. {
  3358. auto style = StyleText()->mTextEmphasisStyle;
  3359. if (style == NS_STYLE_TEXT_EMPHASIS_STYLE_NONE) {
  3360. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3361. val->SetIdent(eCSSKeyword_none);
  3362. return val.forget();
  3363. }
  3364. if (style == NS_STYLE_TEXT_EMPHASIS_STYLE_STRING) {
  3365. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3366. nsAutoString tmp;
  3367. nsStyleUtil::AppendEscapedCSSString(
  3368. StyleText()->mTextEmphasisStyleString, tmp);
  3369. val->SetString(tmp);
  3370. return val.forget();
  3371. }
  3372. RefPtr<nsROCSSPrimitiveValue> fillVal = new nsROCSSPrimitiveValue;
  3373. if ((style & NS_STYLE_TEXT_EMPHASIS_STYLE_FILL_MASK) ==
  3374. NS_STYLE_TEXT_EMPHASIS_STYLE_FILLED) {
  3375. fillVal->SetIdent(eCSSKeyword_filled);
  3376. } else {
  3377. MOZ_ASSERT((style & NS_STYLE_TEXT_EMPHASIS_STYLE_FILL_MASK) ==
  3378. NS_STYLE_TEXT_EMPHASIS_STYLE_OPEN);
  3379. fillVal->SetIdent(eCSSKeyword_open);
  3380. }
  3381. RefPtr<nsROCSSPrimitiveValue> shapeVal = new nsROCSSPrimitiveValue;
  3382. shapeVal->SetIdent(nsCSSProps::ValueToKeywordEnum(
  3383. style & NS_STYLE_TEXT_EMPHASIS_STYLE_SHAPE_MASK,
  3384. nsCSSProps::kTextEmphasisStyleShapeKTable));
  3385. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3386. valueList->AppendCSSValue(fillVal.forget());
  3387. valueList->AppendCSSValue(shapeVal.forget());
  3388. return valueList.forget();
  3389. }
  3390. already_AddRefed<CSSValue>
  3391. nsComputedDOMStyle::DoGetTextIndent()
  3392. {
  3393. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3394. SetValueToCoord(val, StyleText()->mTextIndent, false);
  3395. return val.forget();
  3396. }
  3397. already_AddRefed<CSSValue>
  3398. nsComputedDOMStyle::DoGetTextJustify()
  3399. {
  3400. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3401. val->SetIdent(
  3402. nsCSSProps::ValueToKeywordEnum(StyleText()->mTextJustify,
  3403. nsCSSProps::kTextJustifyKTable));
  3404. return val.forget();
  3405. }
  3406. already_AddRefed<CSSValue>
  3407. nsComputedDOMStyle::DoGetTextOrientation()
  3408. {
  3409. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3410. val->SetIdent(
  3411. nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mTextOrientation,
  3412. nsCSSProps::kTextOrientationKTable));
  3413. return val.forget();
  3414. }
  3415. already_AddRefed<CSSValue>
  3416. nsComputedDOMStyle::DoGetTextOverflow()
  3417. {
  3418. const nsStyleTextReset *style = StyleTextReset();
  3419. RefPtr<nsROCSSPrimitiveValue> first = new nsROCSSPrimitiveValue;
  3420. const nsStyleTextOverflowSide *side = style->mTextOverflow.GetFirstValue();
  3421. if (side->mType == NS_STYLE_TEXT_OVERFLOW_STRING) {
  3422. nsAutoString str;
  3423. nsStyleUtil::AppendEscapedCSSString(side->mString, str);
  3424. first->SetString(str);
  3425. } else {
  3426. first->SetIdent(
  3427. nsCSSProps::ValueToKeywordEnum(side->mType,
  3428. nsCSSProps::kTextOverflowKTable));
  3429. }
  3430. side = style->mTextOverflow.GetSecondValue();
  3431. if (!side) {
  3432. return first.forget();
  3433. }
  3434. RefPtr<nsROCSSPrimitiveValue> second = new nsROCSSPrimitiveValue;
  3435. if (side->mType == NS_STYLE_TEXT_OVERFLOW_STRING) {
  3436. nsAutoString str;
  3437. nsStyleUtil::AppendEscapedCSSString(side->mString, str);
  3438. second->SetString(str);
  3439. } else {
  3440. second->SetIdent(
  3441. nsCSSProps::ValueToKeywordEnum(side->mType,
  3442. nsCSSProps::kTextOverflowKTable));
  3443. }
  3444. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3445. valueList->AppendCSSValue(first.forget());
  3446. valueList->AppendCSSValue(second.forget());
  3447. return valueList.forget();
  3448. }
  3449. already_AddRefed<CSSValue>
  3450. nsComputedDOMStyle::DoGetTextShadow()
  3451. {
  3452. return GetCSSShadowArray(StyleText()->mTextShadow,
  3453. StyleColor()->mColor,
  3454. false);
  3455. }
  3456. already_AddRefed<CSSValue>
  3457. nsComputedDOMStyle::DoGetTextTransform()
  3458. {
  3459. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3460. val->SetIdent(
  3461. nsCSSProps::ValueToKeywordEnum(StyleText()->mTextTransform,
  3462. nsCSSProps::kTextTransformKTable));
  3463. return val.forget();
  3464. }
  3465. already_AddRefed<CSSValue>
  3466. nsComputedDOMStyle::DoGetTabSize()
  3467. {
  3468. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3469. SetValueToCoord(val, StyleText()->mTabSize, true);
  3470. return val.forget();
  3471. }
  3472. already_AddRefed<CSSValue>
  3473. nsComputedDOMStyle::DoGetLetterSpacing()
  3474. {
  3475. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3476. SetValueToCoord(val, StyleText()->mLetterSpacing, false);
  3477. return val.forget();
  3478. }
  3479. already_AddRefed<CSSValue>
  3480. nsComputedDOMStyle::DoGetWordSpacing()
  3481. {
  3482. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3483. SetValueToCoord(val, StyleText()->mWordSpacing, false);
  3484. return val.forget();
  3485. }
  3486. already_AddRefed<CSSValue>
  3487. nsComputedDOMStyle::DoGetWhiteSpace()
  3488. {
  3489. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3490. val->SetIdent(
  3491. nsCSSProps::ValueToKeywordEnum(StyleText()->mWhiteSpace,
  3492. nsCSSProps::kWhitespaceKTable));
  3493. return val.forget();
  3494. }
  3495. already_AddRefed<CSSValue>
  3496. nsComputedDOMStyle::DoGetWindowDragging()
  3497. {
  3498. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3499. val->SetIdent(
  3500. nsCSSProps::ValueToKeywordEnum(StyleUIReset()->mWindowDragging,
  3501. nsCSSProps::kWindowDraggingKTable));
  3502. return val.forget();
  3503. }
  3504. already_AddRefed<CSSValue>
  3505. nsComputedDOMStyle::DoGetWindowShadow()
  3506. {
  3507. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3508. val->SetIdent(
  3509. nsCSSProps::ValueToKeywordEnum(StyleUIReset()->mWindowShadow,
  3510. nsCSSProps::kWindowShadowKTable));
  3511. return val.forget();
  3512. }
  3513. already_AddRefed<CSSValue>
  3514. nsComputedDOMStyle::DoGetWordBreak()
  3515. {
  3516. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3517. val->SetIdent(
  3518. nsCSSProps::ValueToKeywordEnum(StyleText()->mWordBreak,
  3519. nsCSSProps::kWordBreakKTable));
  3520. return val.forget();
  3521. }
  3522. already_AddRefed<CSSValue>
  3523. nsComputedDOMStyle::DoGetOverflowWrap()
  3524. {
  3525. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3526. val->SetIdent(
  3527. nsCSSProps::ValueToKeywordEnum(StyleText()->mOverflowWrap,
  3528. nsCSSProps::kOverflowWrapKTable));
  3529. return val.forget();
  3530. }
  3531. already_AddRefed<CSSValue>
  3532. nsComputedDOMStyle::DoGetHyphens()
  3533. {
  3534. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3535. val->SetIdent(
  3536. nsCSSProps::ValueToKeywordEnum(StyleText()->mHyphens,
  3537. nsCSSProps::kHyphensKTable));
  3538. return val.forget();
  3539. }
  3540. already_AddRefed<CSSValue>
  3541. nsComputedDOMStyle::DoGetTextSizeAdjust()
  3542. {
  3543. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3544. switch (StyleText()->mTextSizeAdjust) {
  3545. default:
  3546. NS_NOTREACHED("unexpected value");
  3547. MOZ_FALLTHROUGH;
  3548. case NS_STYLE_TEXT_SIZE_ADJUST_AUTO:
  3549. val->SetIdent(eCSSKeyword_auto);
  3550. break;
  3551. case NS_STYLE_TEXT_SIZE_ADJUST_NONE:
  3552. val->SetIdent(eCSSKeyword_none);
  3553. break;
  3554. }
  3555. return val.forget();
  3556. }
  3557. already_AddRefed<CSSValue>
  3558. nsComputedDOMStyle::DoGetWebkitTextFillColor()
  3559. {
  3560. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3561. SetValueFromComplexColor(val, StyleText()->mWebkitTextFillColor);
  3562. return val.forget();
  3563. }
  3564. already_AddRefed<CSSValue>
  3565. nsComputedDOMStyle::DoGetWebkitTextStrokeColor()
  3566. {
  3567. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3568. SetValueFromComplexColor(val, StyleText()->mWebkitTextStrokeColor);
  3569. return val.forget();
  3570. }
  3571. already_AddRefed<CSSValue>
  3572. nsComputedDOMStyle::DoGetWebkitTextStrokeWidth()
  3573. {
  3574. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3575. val->SetAppUnits(StyleText()->mWebkitTextStrokeWidth.GetCoordValue());
  3576. return val.forget();
  3577. }
  3578. already_AddRefed<CSSValue>
  3579. nsComputedDOMStyle::DoGetPointerEvents()
  3580. {
  3581. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3582. val->SetIdent(
  3583. nsCSSProps::ValueToKeywordEnum(StyleUserInterface()->mPointerEvents,
  3584. nsCSSProps::kPointerEventsKTable));
  3585. return val.forget();
  3586. }
  3587. already_AddRefed<CSSValue>
  3588. nsComputedDOMStyle::DoGetVisibility()
  3589. {
  3590. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3591. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mVisible,
  3592. nsCSSProps::kVisibilityKTable));
  3593. return val.forget();
  3594. }
  3595. already_AddRefed<CSSValue>
  3596. nsComputedDOMStyle::DoGetWritingMode()
  3597. {
  3598. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3599. val->SetIdent(
  3600. nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mWritingMode,
  3601. nsCSSProps::kWritingModeKTable));
  3602. return val.forget();
  3603. }
  3604. already_AddRefed<CSSValue>
  3605. nsComputedDOMStyle::DoGetDirection()
  3606. {
  3607. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3608. val->SetIdent(
  3609. nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mDirection,
  3610. nsCSSProps::kDirectionKTable));
  3611. return val.forget();
  3612. }
  3613. static_assert(NS_STYLE_UNICODE_BIDI_NORMAL == 0,
  3614. "unicode-bidi style constants not as expected");
  3615. already_AddRefed<CSSValue>
  3616. nsComputedDOMStyle::DoGetUnicodeBidi()
  3617. {
  3618. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3619. val->SetIdent(
  3620. nsCSSProps::ValueToKeywordEnum(StyleTextReset()->mUnicodeBidi,
  3621. nsCSSProps::kUnicodeBidiKTable));
  3622. return val.forget();
  3623. }
  3624. already_AddRefed<CSSValue>
  3625. nsComputedDOMStyle::DoGetCaretColor()
  3626. {
  3627. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3628. SetValueFromComplexColor(val, StyleUserInterface()->mCaretColor);
  3629. return val.forget();
  3630. }
  3631. already_AddRefed<CSSValue>
  3632. nsComputedDOMStyle::DoGetCursor()
  3633. {
  3634. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  3635. const nsStyleUserInterface *ui = StyleUserInterface();
  3636. for (const nsCursorImage& item : ui->mCursorImages) {
  3637. RefPtr<nsDOMCSSValueList> itemList = GetROCSSValueList(false);
  3638. nsCOMPtr<nsIURI> uri;
  3639. item.GetImage()->GetURI(getter_AddRefs(uri));
  3640. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3641. val->SetURI(uri);
  3642. itemList->AppendCSSValue(val.forget());
  3643. if (item.mHaveHotspot) {
  3644. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  3645. RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
  3646. valX->SetNumber(item.mHotspotX);
  3647. valY->SetNumber(item.mHotspotY);
  3648. itemList->AppendCSSValue(valX.forget());
  3649. itemList->AppendCSSValue(valY.forget());
  3650. }
  3651. valueList->AppendCSSValue(itemList.forget());
  3652. }
  3653. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3654. val->SetIdent(nsCSSProps::ValueToKeywordEnum(ui->mCursor,
  3655. nsCSSProps::kCursorKTable));
  3656. valueList->AppendCSSValue(val.forget());
  3657. return valueList.forget();
  3658. }
  3659. already_AddRefed<CSSValue>
  3660. nsComputedDOMStyle::DoGetAppearance()
  3661. {
  3662. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3663. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mAppearance,
  3664. nsCSSProps::kAppearanceKTable));
  3665. return val.forget();
  3666. }
  3667. already_AddRefed<CSSValue>
  3668. nsComputedDOMStyle::DoGetBoxAlign()
  3669. {
  3670. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3671. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleXUL()->mBoxAlign,
  3672. nsCSSProps::kBoxAlignKTable));
  3673. return val.forget();
  3674. }
  3675. already_AddRefed<CSSValue>
  3676. nsComputedDOMStyle::DoGetBoxDirection()
  3677. {
  3678. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3679. val->SetIdent(
  3680. nsCSSProps::ValueToKeywordEnum(StyleXUL()->mBoxDirection,
  3681. nsCSSProps::kBoxDirectionKTable));
  3682. return val.forget();
  3683. }
  3684. already_AddRefed<CSSValue>
  3685. nsComputedDOMStyle::DoGetBoxFlex()
  3686. {
  3687. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3688. val->SetNumber(StyleXUL()->mBoxFlex);
  3689. return val.forget();
  3690. }
  3691. already_AddRefed<CSSValue>
  3692. nsComputedDOMStyle::DoGetBoxOrdinalGroup()
  3693. {
  3694. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3695. val->SetNumber(StyleXUL()->mBoxOrdinal);
  3696. return val.forget();
  3697. }
  3698. already_AddRefed<CSSValue>
  3699. nsComputedDOMStyle::DoGetBoxOrient()
  3700. {
  3701. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3702. val->SetIdent(
  3703. nsCSSProps::ValueToKeywordEnum(StyleXUL()->mBoxOrient,
  3704. nsCSSProps::kBoxOrientKTable));
  3705. return val.forget();
  3706. }
  3707. already_AddRefed<CSSValue>
  3708. nsComputedDOMStyle::DoGetBoxPack()
  3709. {
  3710. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3711. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleXUL()->mBoxPack,
  3712. nsCSSProps::kBoxPackKTable));
  3713. return val.forget();
  3714. }
  3715. already_AddRefed<CSSValue>
  3716. nsComputedDOMStyle::DoGetBoxSizing()
  3717. {
  3718. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3719. val->SetIdent(
  3720. nsCSSProps::ValueToKeywordEnum(StylePosition()->mBoxSizing,
  3721. nsCSSProps::kBoxSizingKTable));
  3722. return val.forget();
  3723. }
  3724. /* Border image properties */
  3725. already_AddRefed<CSSValue>
  3726. nsComputedDOMStyle::DoGetBorderImageSource()
  3727. {
  3728. const nsStyleBorder* border = StyleBorder();
  3729. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3730. const nsStyleImage& image = border->mBorderImageSource;
  3731. SetValueToStyleImage(image, val);
  3732. return val.forget();
  3733. }
  3734. already_AddRefed<CSSValue>
  3735. nsComputedDOMStyle::DoGetBorderImageSlice()
  3736. {
  3737. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3738. const nsStyleBorder* border = StyleBorder();
  3739. // Four slice numbers.
  3740. NS_FOR_CSS_SIDES (side) {
  3741. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3742. SetValueToCoord(val, border->mBorderImageSlice.Get(side), true, nullptr);
  3743. valueList->AppendCSSValue(val.forget());
  3744. }
  3745. // Fill keyword.
  3746. if (NS_STYLE_BORDER_IMAGE_SLICE_FILL == border->mBorderImageFill) {
  3747. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3748. val->SetIdent(eCSSKeyword_fill);
  3749. valueList->AppendCSSValue(val.forget());
  3750. }
  3751. return valueList.forget();
  3752. }
  3753. already_AddRefed<CSSValue>
  3754. nsComputedDOMStyle::DoGetBorderImageWidth()
  3755. {
  3756. const nsStyleBorder* border = StyleBorder();
  3757. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3758. NS_FOR_CSS_SIDES (side) {
  3759. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3760. SetValueToCoord(val, border->mBorderImageWidth.Get(side),
  3761. true, nullptr);
  3762. valueList->AppendCSSValue(val.forget());
  3763. }
  3764. return valueList.forget();
  3765. }
  3766. already_AddRefed<CSSValue>
  3767. nsComputedDOMStyle::DoGetBorderImageOutset()
  3768. {
  3769. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3770. const nsStyleBorder* border = StyleBorder();
  3771. // four slice numbers
  3772. NS_FOR_CSS_SIDES (side) {
  3773. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3774. SetValueToCoord(val, border->mBorderImageOutset.Get(side),
  3775. true, nullptr);
  3776. valueList->AppendCSSValue(val.forget());
  3777. }
  3778. return valueList.forget();
  3779. }
  3780. already_AddRefed<CSSValue>
  3781. nsComputedDOMStyle::DoGetBorderImageRepeat()
  3782. {
  3783. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  3784. const nsStyleBorder* border = StyleBorder();
  3785. // horizontal repeat
  3786. RefPtr<nsROCSSPrimitiveValue> valX = new nsROCSSPrimitiveValue;
  3787. valX->SetIdent(
  3788. nsCSSProps::ValueToKeywordEnum(border->mBorderImageRepeatH,
  3789. nsCSSProps::kBorderImageRepeatKTable));
  3790. valueList->AppendCSSValue(valX.forget());
  3791. // vertical repeat
  3792. RefPtr<nsROCSSPrimitiveValue> valY = new nsROCSSPrimitiveValue;
  3793. valY->SetIdent(
  3794. nsCSSProps::ValueToKeywordEnum(border->mBorderImageRepeatV,
  3795. nsCSSProps::kBorderImageRepeatKTable));
  3796. valueList->AppendCSSValue(valY.forget());
  3797. return valueList.forget();
  3798. }
  3799. already_AddRefed<CSSValue>
  3800. nsComputedDOMStyle::DoGetFlexBasis()
  3801. {
  3802. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3803. // XXXdholbert We could make this more automagic and resolve percentages
  3804. // if we wanted, by passing in a PercentageBaseGetter instead of nullptr
  3805. // below. Logic would go like this:
  3806. // if (i'm a flex item) {
  3807. // if (my flex container is horizontal) {
  3808. // percentageBaseGetter = &nsComputedDOMStyle::GetCBContentWidth;
  3809. // } else {
  3810. // percentageBaseGetter = &nsComputedDOMStyle::GetCBContentHeight;
  3811. // }
  3812. // }
  3813. SetValueToCoord(val, StylePosition()->mFlexBasis, true,
  3814. nullptr, nsCSSProps::kWidthKTable);
  3815. return val.forget();
  3816. }
  3817. already_AddRefed<CSSValue>
  3818. nsComputedDOMStyle::DoGetFlexDirection()
  3819. {
  3820. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3821. val->SetIdent(
  3822. nsCSSProps::ValueToKeywordEnum(StylePosition()->mFlexDirection,
  3823. nsCSSProps::kFlexDirectionKTable));
  3824. return val.forget();
  3825. }
  3826. already_AddRefed<CSSValue>
  3827. nsComputedDOMStyle::DoGetFlexGrow()
  3828. {
  3829. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3830. val->SetNumber(StylePosition()->mFlexGrow);
  3831. return val.forget();
  3832. }
  3833. already_AddRefed<CSSValue>
  3834. nsComputedDOMStyle::DoGetFlexShrink()
  3835. {
  3836. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3837. val->SetNumber(StylePosition()->mFlexShrink);
  3838. return val.forget();
  3839. }
  3840. already_AddRefed<CSSValue>
  3841. nsComputedDOMStyle::DoGetFlexWrap()
  3842. {
  3843. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3844. val->SetIdent(
  3845. nsCSSProps::ValueToKeywordEnum(StylePosition()->mFlexWrap,
  3846. nsCSSProps::kFlexWrapKTable));
  3847. return val.forget();
  3848. }
  3849. already_AddRefed<CSSValue>
  3850. nsComputedDOMStyle::DoGetOrder()
  3851. {
  3852. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3853. val->SetNumber(StylePosition()->mOrder);
  3854. return val.forget();
  3855. }
  3856. already_AddRefed<CSSValue>
  3857. nsComputedDOMStyle::DoGetAlignContent()
  3858. {
  3859. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3860. nsAutoString str;
  3861. auto align = StylePosition()->mAlignContent;
  3862. nsCSSValue::AppendAlignJustifyValueToString(align & NS_STYLE_ALIGN_ALL_BITS, str);
  3863. auto fallback = align >> NS_STYLE_ALIGN_ALL_SHIFT;
  3864. if (fallback) {
  3865. str.Append(' ');
  3866. nsCSSValue::AppendAlignJustifyValueToString(fallback, str);
  3867. }
  3868. val->SetString(str);
  3869. return val.forget();
  3870. }
  3871. already_AddRefed<CSSValue>
  3872. nsComputedDOMStyle::DoGetAlignItems()
  3873. {
  3874. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3875. nsAutoString str;
  3876. auto align = StylePosition()->mAlignItems;
  3877. nsCSSValue::AppendAlignJustifyValueToString(align, str);
  3878. val->SetString(str);
  3879. return val.forget();
  3880. }
  3881. already_AddRefed<CSSValue>
  3882. nsComputedDOMStyle::DoGetAlignSelf()
  3883. {
  3884. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3885. nsAutoString str;
  3886. auto align = StylePosition()->mAlignSelf;
  3887. nsCSSValue::AppendAlignJustifyValueToString(align, str);
  3888. val->SetString(str);
  3889. return val.forget();
  3890. }
  3891. already_AddRefed<CSSValue>
  3892. nsComputedDOMStyle::DoGetJustifyContent()
  3893. {
  3894. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3895. nsAutoString str;
  3896. auto justify = StylePosition()->mJustifyContent;
  3897. nsCSSValue::AppendAlignJustifyValueToString(justify & NS_STYLE_JUSTIFY_ALL_BITS, str);
  3898. auto fallback = justify >> NS_STYLE_JUSTIFY_ALL_SHIFT;
  3899. if (fallback) {
  3900. MOZ_ASSERT(nsCSSProps::ValueToKeywordEnum(fallback & ~NS_STYLE_JUSTIFY_FLAG_BITS,
  3901. nsCSSProps::kAlignSelfPosition)
  3902. != eCSSKeyword_UNKNOWN, "unknown fallback value");
  3903. str.Append(' ');
  3904. nsCSSValue::AppendAlignJustifyValueToString(fallback, str);
  3905. }
  3906. val->SetString(str);
  3907. return val.forget();
  3908. }
  3909. already_AddRefed<CSSValue>
  3910. nsComputedDOMStyle::DoGetJustifyItems()
  3911. {
  3912. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3913. nsAutoString str;
  3914. auto justify =
  3915. StylePosition()->ComputedJustifyItems(mStyleContext->GetParent());
  3916. nsCSSValue::AppendAlignJustifyValueToString(justify, str);
  3917. val->SetString(str);
  3918. return val.forget();
  3919. }
  3920. already_AddRefed<CSSValue>
  3921. nsComputedDOMStyle::DoGetJustifySelf()
  3922. {
  3923. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3924. nsAutoString str;
  3925. auto justify = StylePosition()->mJustifySelf;
  3926. nsCSSValue::AppendAlignJustifyValueToString(justify, str);
  3927. val->SetString(str);
  3928. return val.forget();
  3929. }
  3930. already_AddRefed<CSSValue>
  3931. nsComputedDOMStyle::DoGetFloatEdge()
  3932. {
  3933. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3934. val->SetIdent(
  3935. nsCSSProps::ValueToKeywordEnum(uint8_t(StyleBorder()->mFloatEdge),
  3936. nsCSSProps::kFloatEdgeKTable));
  3937. return val.forget();
  3938. }
  3939. already_AddRefed<CSSValue>
  3940. nsComputedDOMStyle::DoGetForceBrokenImageIcon()
  3941. {
  3942. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3943. val->SetNumber(StyleUIReset()->mForceBrokenImageIcon);
  3944. return val.forget();
  3945. }
  3946. already_AddRefed<CSSValue>
  3947. nsComputedDOMStyle::DoGetImageOrientation()
  3948. {
  3949. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3950. nsAutoString string;
  3951. nsStyleImageOrientation orientation = StyleVisibility()->mImageOrientation;
  3952. if (orientation.IsFromImage()) {
  3953. string.AppendLiteral("from-image");
  3954. } else {
  3955. nsStyleUtil::AppendAngleValue(orientation.AngleAsCoord(), string);
  3956. if (orientation.IsFlipped()) {
  3957. string.AppendLiteral(" flip");
  3958. }
  3959. }
  3960. val->SetString(string);
  3961. return val.forget();
  3962. }
  3963. already_AddRefed<CSSValue>
  3964. nsComputedDOMStyle::DoGetIMEMode()
  3965. {
  3966. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3967. val->SetIdent(
  3968. nsCSSProps::ValueToKeywordEnum(StyleUIReset()->mIMEMode,
  3969. nsCSSProps::kIMEModeKTable));
  3970. return val.forget();
  3971. }
  3972. already_AddRefed<CSSValue>
  3973. nsComputedDOMStyle::DoGetUserFocus()
  3974. {
  3975. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3976. val->SetIdent(
  3977. nsCSSProps::ValueToKeywordEnum(uint8_t(StyleUserInterface()->mUserFocus),
  3978. nsCSSProps::kUserFocusKTable));
  3979. return val.forget();
  3980. }
  3981. already_AddRefed<CSSValue>
  3982. nsComputedDOMStyle::DoGetUserInput()
  3983. {
  3984. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3985. val->SetIdent(
  3986. nsCSSProps::ValueToKeywordEnum(StyleUserInterface()->mUserInput,
  3987. nsCSSProps::kUserInputKTable));
  3988. return val.forget();
  3989. }
  3990. already_AddRefed<CSSValue>
  3991. nsComputedDOMStyle::DoGetUserModify()
  3992. {
  3993. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  3994. val->SetIdent(
  3995. nsCSSProps::ValueToKeywordEnum(StyleUserInterface()->mUserModify,
  3996. nsCSSProps::kUserModifyKTable));
  3997. return val.forget();
  3998. }
  3999. already_AddRefed<CSSValue>
  4000. nsComputedDOMStyle::DoGetUserSelect()
  4001. {
  4002. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4003. val->SetIdent(
  4004. nsCSSProps::ValueToKeywordEnum(StyleUIReset()->mUserSelect,
  4005. nsCSSProps::kUserSelectKTable));
  4006. return val.forget();
  4007. }
  4008. already_AddRefed<CSSValue>
  4009. nsComputedDOMStyle::DoGetDisplay()
  4010. {
  4011. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4012. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mDisplay,
  4013. nsCSSProps::kDisplayKTable));
  4014. return val.forget();
  4015. }
  4016. already_AddRefed<CSSValue>
  4017. nsComputedDOMStyle::DoGetContain()
  4018. {
  4019. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4020. int32_t mask = StyleDisplay()->mContain;
  4021. if (mask == 0) {
  4022. val->SetIdent(eCSSKeyword_none);
  4023. } else if (mask & NS_STYLE_CONTAIN_STRICT) {
  4024. NS_ASSERTION(mask == (NS_STYLE_CONTAIN_STRICT | NS_STYLE_CONTAIN_ALL_BITS),
  4025. "contain: strict should imply contain: layout style paint");
  4026. val->SetIdent(eCSSKeyword_strict);
  4027. } else {
  4028. nsAutoString valueStr;
  4029. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_contain,
  4030. mask, NS_STYLE_CONTAIN_LAYOUT,
  4031. NS_STYLE_CONTAIN_PAINT, valueStr);
  4032. val->SetString(valueStr);
  4033. }
  4034. return val.forget();
  4035. }
  4036. already_AddRefed<CSSValue>
  4037. nsComputedDOMStyle::DoGetPosition()
  4038. {
  4039. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4040. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mPosition,
  4041. nsCSSProps::kPositionKTable));
  4042. return val.forget();
  4043. }
  4044. already_AddRefed<CSSValue>
  4045. nsComputedDOMStyle::DoGetClip()
  4046. {
  4047. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4048. const nsStyleEffects* effects = StyleEffects();
  4049. if (effects->mClipFlags == NS_STYLE_CLIP_AUTO) {
  4050. val->SetIdent(eCSSKeyword_auto);
  4051. } else {
  4052. // create the cssvalues for the sides, stick them in the rect object
  4053. nsROCSSPrimitiveValue *topVal = new nsROCSSPrimitiveValue;
  4054. nsROCSSPrimitiveValue *rightVal = new nsROCSSPrimitiveValue;
  4055. nsROCSSPrimitiveValue *bottomVal = new nsROCSSPrimitiveValue;
  4056. nsROCSSPrimitiveValue *leftVal = new nsROCSSPrimitiveValue;
  4057. nsDOMCSSRect * domRect = new nsDOMCSSRect(topVal, rightVal,
  4058. bottomVal, leftVal);
  4059. if (effects->mClipFlags & NS_STYLE_CLIP_TOP_AUTO) {
  4060. topVal->SetIdent(eCSSKeyword_auto);
  4061. } else {
  4062. topVal->SetAppUnits(effects->mClip.y);
  4063. }
  4064. if (effects->mClipFlags & NS_STYLE_CLIP_RIGHT_AUTO) {
  4065. rightVal->SetIdent(eCSSKeyword_auto);
  4066. } else {
  4067. rightVal->SetAppUnits(effects->mClip.width + effects->mClip.x);
  4068. }
  4069. if (effects->mClipFlags & NS_STYLE_CLIP_BOTTOM_AUTO) {
  4070. bottomVal->SetIdent(eCSSKeyword_auto);
  4071. } else {
  4072. bottomVal->SetAppUnits(effects->mClip.height + effects->mClip.y);
  4073. }
  4074. if (effects->mClipFlags & NS_STYLE_CLIP_LEFT_AUTO) {
  4075. leftVal->SetIdent(eCSSKeyword_auto);
  4076. } else {
  4077. leftVal->SetAppUnits(effects->mClip.x);
  4078. }
  4079. val->SetRect(domRect);
  4080. }
  4081. return val.forget();
  4082. }
  4083. already_AddRefed<CSSValue>
  4084. nsComputedDOMStyle::DoGetWillChange()
  4085. {
  4086. const nsTArray<nsString>& willChange = StyleDisplay()->mWillChange;
  4087. if (willChange.IsEmpty()) {
  4088. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4089. val->SetIdent(eCSSKeyword_auto);
  4090. return val.forget();
  4091. }
  4092. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  4093. for (size_t i = 0; i < willChange.Length(); i++) {
  4094. const nsString& willChangeIdentifier = willChange[i];
  4095. RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
  4096. property->SetString(willChangeIdentifier);
  4097. valueList->AppendCSSValue(property.forget());
  4098. }
  4099. return valueList.forget();
  4100. }
  4101. already_AddRefed<CSSValue>
  4102. nsComputedDOMStyle::DoGetOverflow()
  4103. {
  4104. const nsStyleDisplay* display = StyleDisplay();
  4105. if (display->mOverflowX != display->mOverflowY) {
  4106. // No value to return. We can't express this combination of
  4107. // values as a shorthand.
  4108. return nullptr;
  4109. }
  4110. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4111. val->SetIdent(nsCSSProps::ValueToKeywordEnum(display->mOverflowX,
  4112. nsCSSProps::kOverflowKTable));
  4113. return val.forget();
  4114. }
  4115. already_AddRefed<CSSValue>
  4116. nsComputedDOMStyle::DoGetOverflowX()
  4117. {
  4118. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4119. val->SetIdent(
  4120. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mOverflowX,
  4121. nsCSSProps::kOverflowSubKTable));
  4122. return val.forget();
  4123. }
  4124. already_AddRefed<CSSValue>
  4125. nsComputedDOMStyle::DoGetOverflowY()
  4126. {
  4127. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4128. val->SetIdent(
  4129. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mOverflowY,
  4130. nsCSSProps::kOverflowSubKTable));
  4131. return val.forget();
  4132. }
  4133. already_AddRefed<CSSValue>
  4134. nsComputedDOMStyle::DoGetOverflowClipBox()
  4135. {
  4136. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4137. val->SetIdent(
  4138. nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mOverflowClipBox,
  4139. nsCSSProps::kOverflowClipBoxKTable));
  4140. return val.forget();
  4141. }
  4142. already_AddRefed<CSSValue>
  4143. nsComputedDOMStyle::DoGetResize()
  4144. {
  4145. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4146. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mResize,
  4147. nsCSSProps::kResizeKTable));
  4148. return val.forget();
  4149. }
  4150. already_AddRefed<CSSValue>
  4151. nsComputedDOMStyle::DoGetPageBreakAfter()
  4152. {
  4153. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4154. const nsStyleDisplay *display = StyleDisplay();
  4155. if (display->mBreakAfter) {
  4156. val->SetIdent(eCSSKeyword_always);
  4157. } else {
  4158. val->SetIdent(eCSSKeyword_auto);
  4159. }
  4160. return val.forget();
  4161. }
  4162. already_AddRefed<CSSValue>
  4163. nsComputedDOMStyle::DoGetPageBreakBefore()
  4164. {
  4165. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4166. const nsStyleDisplay *display = StyleDisplay();
  4167. if (display->mBreakBefore) {
  4168. val->SetIdent(eCSSKeyword_always);
  4169. } else {
  4170. val->SetIdent(eCSSKeyword_auto);
  4171. }
  4172. return val.forget();
  4173. }
  4174. already_AddRefed<CSSValue>
  4175. nsComputedDOMStyle::DoGetPageBreakInside()
  4176. {
  4177. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4178. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mBreakInside,
  4179. nsCSSProps::kPageBreakInsideKTable));
  4180. return val.forget();
  4181. }
  4182. already_AddRefed<CSSValue>
  4183. nsComputedDOMStyle::DoGetTouchAction()
  4184. {
  4185. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4186. int32_t intValue = StyleDisplay()->mTouchAction;
  4187. // None and Auto and Manipulation values aren't allowed
  4188. // to be in conjunction with other values.
  4189. // But there are all checks in CSSParserImpl::ParseTouchAction
  4190. nsAutoString valueStr;
  4191. nsStyleUtil::AppendBitmaskCSSValue(eCSSProperty_touch_action, intValue,
  4192. NS_STYLE_TOUCH_ACTION_NONE, NS_STYLE_TOUCH_ACTION_MANIPULATION,
  4193. valueStr);
  4194. val->SetString(valueStr);
  4195. return val.forget();
  4196. }
  4197. already_AddRefed<CSSValue>
  4198. nsComputedDOMStyle::DoGetHeight()
  4199. {
  4200. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4201. bool calcHeight = false;
  4202. if (mInnerFrame) {
  4203. calcHeight = true;
  4204. const nsStyleDisplay* displayData = StyleDisplay();
  4205. if (displayData->mDisplay == mozilla::StyleDisplay::Inline &&
  4206. !(mInnerFrame->IsFrameOfType(nsIFrame::eReplaced)) &&
  4207. // An outer SVG frame should behave the same as eReplaced in this case
  4208. mInnerFrame->GetType() != nsGkAtoms::svgOuterSVGFrame) {
  4209. calcHeight = false;
  4210. }
  4211. }
  4212. if (calcHeight) {
  4213. AssertFlushedPendingReflows();
  4214. nsMargin adjustedValues = GetAdjustedValuesForBoxSizing();
  4215. val->SetAppUnits(mInnerFrame->GetContentRect().height +
  4216. adjustedValues.TopBottom());
  4217. } else {
  4218. const nsStylePosition *positionData = StylePosition();
  4219. nscoord minHeight =
  4220. StyleCoordToNSCoord(positionData->mMinHeight,
  4221. &nsComputedDOMStyle::GetCBContentHeight, 0, true);
  4222. nscoord maxHeight =
  4223. StyleCoordToNSCoord(positionData->mMaxHeight,
  4224. &nsComputedDOMStyle::GetCBContentHeight,
  4225. nscoord_MAX, true);
  4226. SetValueToCoord(val, positionData->mHeight, true, nullptr,
  4227. nsCSSProps::kWidthKTable, minHeight, maxHeight);
  4228. }
  4229. return val.forget();
  4230. }
  4231. already_AddRefed<CSSValue>
  4232. nsComputedDOMStyle::DoGetWidth()
  4233. {
  4234. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4235. bool calcWidth = false;
  4236. if (mInnerFrame) {
  4237. calcWidth = true;
  4238. const nsStyleDisplay *displayData = StyleDisplay();
  4239. if (displayData->mDisplay == mozilla::StyleDisplay::Inline &&
  4240. !(mInnerFrame->IsFrameOfType(nsIFrame::eReplaced)) &&
  4241. // An outer SVG frame should behave the same as eReplaced in this case
  4242. mInnerFrame->GetType() != nsGkAtoms::svgOuterSVGFrame) {
  4243. calcWidth = false;
  4244. }
  4245. }
  4246. if (calcWidth) {
  4247. AssertFlushedPendingReflows();
  4248. nsMargin adjustedValues = GetAdjustedValuesForBoxSizing();
  4249. val->SetAppUnits(mInnerFrame->GetContentRect().width +
  4250. adjustedValues.LeftRight());
  4251. } else {
  4252. const nsStylePosition *positionData = StylePosition();
  4253. nscoord minWidth =
  4254. StyleCoordToNSCoord(positionData->mMinWidth,
  4255. &nsComputedDOMStyle::GetCBContentWidth, 0, true);
  4256. nscoord maxWidth =
  4257. StyleCoordToNSCoord(positionData->mMaxWidth,
  4258. &nsComputedDOMStyle::GetCBContentWidth,
  4259. nscoord_MAX, true);
  4260. SetValueToCoord(val, positionData->mWidth, true, nullptr,
  4261. nsCSSProps::kWidthKTable, minWidth, maxWidth);
  4262. }
  4263. return val.forget();
  4264. }
  4265. already_AddRefed<CSSValue>
  4266. nsComputedDOMStyle::DoGetMaxHeight()
  4267. {
  4268. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4269. SetValueToCoord(val, StylePosition()->mMaxHeight, true,
  4270. nullptr, nsCSSProps::kWidthKTable);
  4271. return val.forget();
  4272. }
  4273. already_AddRefed<CSSValue>
  4274. nsComputedDOMStyle::DoGetMaxWidth()
  4275. {
  4276. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4277. SetValueToCoord(val, StylePosition()->mMaxWidth, true,
  4278. nullptr, nsCSSProps::kWidthKTable);
  4279. return val.forget();
  4280. }
  4281. bool
  4282. nsComputedDOMStyle::ShouldHonorMinSizeAutoInAxis(PhysicalAxis aAxis)
  4283. {
  4284. // A {flex,grid} item's min-{width|height} "auto" value gets special
  4285. // treatment in getComputedStyle().
  4286. // https://drafts.csswg.org/css-flexbox-1/#valdef-min-width-auto
  4287. // https://drafts.csswg.org/css-grid/#min-size-auto
  4288. // In most cases, "min-{width|height}: auto" is mapped to "0px", unless
  4289. // we're a flex item (and the min-size is in the flex container's main
  4290. // axis), or we're a grid item, AND we also have overflow:visible.
  4291. // Note: We only need to bother checking one "overflow" subproperty for
  4292. // "visible", because a non-"visible" value in either axis would force the
  4293. // other axis to also be non-"visible" as well.
  4294. if (mOuterFrame) {
  4295. nsIFrame* containerFrame = mOuterFrame->GetParent();
  4296. if (containerFrame &&
  4297. StyleDisplay()->mOverflowX == NS_STYLE_OVERFLOW_VISIBLE) {
  4298. auto containerType = containerFrame->GetType();
  4299. if (containerType == nsGkAtoms::flexContainerFrame &&
  4300. (static_cast<nsFlexContainerFrame*>(containerFrame)->IsHorizontal() ==
  4301. (aAxis == eAxisHorizontal))) {
  4302. return true;
  4303. }
  4304. if (containerType == nsGkAtoms::gridContainerFrame) {
  4305. return true;
  4306. }
  4307. }
  4308. }
  4309. return false;
  4310. }
  4311. already_AddRefed<CSSValue>
  4312. nsComputedDOMStyle::DoGetMinHeight()
  4313. {
  4314. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4315. nsStyleCoord minHeight = StylePosition()->mMinHeight;
  4316. if (eStyleUnit_Auto == minHeight.GetUnit() &&
  4317. !ShouldHonorMinSizeAutoInAxis(eAxisVertical)) {
  4318. minHeight.SetCoordValue(0);
  4319. }
  4320. SetValueToCoord(val, minHeight, true, nullptr, nsCSSProps::kWidthKTable);
  4321. return val.forget();
  4322. }
  4323. already_AddRefed<CSSValue>
  4324. nsComputedDOMStyle::DoGetMinWidth()
  4325. {
  4326. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4327. nsStyleCoord minWidth = StylePosition()->mMinWidth;
  4328. if (eStyleUnit_Auto == minWidth.GetUnit() &&
  4329. !ShouldHonorMinSizeAutoInAxis(eAxisHorizontal)) {
  4330. minWidth.SetCoordValue(0);
  4331. }
  4332. SetValueToCoord(val, minWidth, true, nullptr, nsCSSProps::kWidthKTable);
  4333. return val.forget();
  4334. }
  4335. already_AddRefed<CSSValue>
  4336. nsComputedDOMStyle::DoGetMixBlendMode()
  4337. {
  4338. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4339. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleEffects()->mMixBlendMode,
  4340. nsCSSProps::kBlendModeKTable));
  4341. return val.forget();
  4342. }
  4343. already_AddRefed<CSSValue>
  4344. nsComputedDOMStyle::DoGetIsolation()
  4345. {
  4346. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4347. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleDisplay()->mIsolation,
  4348. nsCSSProps::kIsolationKTable));
  4349. return val.forget();
  4350. }
  4351. already_AddRefed<CSSValue>
  4352. nsComputedDOMStyle::DoGetObjectFit()
  4353. {
  4354. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4355. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StylePosition()->mObjectFit,
  4356. nsCSSProps::kObjectFitKTable));
  4357. return val.forget();
  4358. }
  4359. already_AddRefed<CSSValue>
  4360. nsComputedDOMStyle::DoGetObjectPosition()
  4361. {
  4362. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  4363. SetValueToPosition(StylePosition()->mObjectPosition, valueList);
  4364. return valueList.forget();
  4365. }
  4366. already_AddRefed<CSSValue>
  4367. nsComputedDOMStyle::DoGetLeft()
  4368. {
  4369. return GetOffsetWidthFor(NS_SIDE_LEFT);
  4370. }
  4371. already_AddRefed<CSSValue>
  4372. nsComputedDOMStyle::DoGetRight()
  4373. {
  4374. return GetOffsetWidthFor(NS_SIDE_RIGHT);
  4375. }
  4376. already_AddRefed<CSSValue>
  4377. nsComputedDOMStyle::DoGetTop()
  4378. {
  4379. return GetOffsetWidthFor(NS_SIDE_TOP);
  4380. }
  4381. already_AddRefed<CSSValue>
  4382. nsComputedDOMStyle::GetOffsetWidthFor(mozilla::css::Side aSide)
  4383. {
  4384. const nsStyleDisplay* display = StyleDisplay();
  4385. AssertFlushedPendingReflows();
  4386. uint8_t position = display->mPosition;
  4387. if (!mOuterFrame) {
  4388. // GetRelativeOffset and GetAbsoluteOffset don't handle elements
  4389. // without frames in any sensible way. GetStaticOffset, however,
  4390. // is perfect for that case.
  4391. position = NS_STYLE_POSITION_STATIC;
  4392. }
  4393. switch (position) {
  4394. case NS_STYLE_POSITION_STATIC:
  4395. return GetStaticOffset(aSide);
  4396. case NS_STYLE_POSITION_RELATIVE:
  4397. return GetRelativeOffset(aSide);
  4398. case NS_STYLE_POSITION_STICKY:
  4399. return GetStickyOffset(aSide);
  4400. case NS_STYLE_POSITION_ABSOLUTE:
  4401. case NS_STYLE_POSITION_FIXED:
  4402. return GetAbsoluteOffset(aSide);
  4403. default:
  4404. NS_ERROR("Invalid position");
  4405. return nullptr;
  4406. }
  4407. }
  4408. already_AddRefed<CSSValue>
  4409. nsComputedDOMStyle::GetAbsoluteOffset(mozilla::css::Side aSide)
  4410. {
  4411. MOZ_ASSERT(mOuterFrame, "need a frame, so we can call GetContainingBlock()");
  4412. nsIFrame* container = mOuterFrame->GetContainingBlock();
  4413. nsMargin margin = mOuterFrame->GetUsedMargin();
  4414. nsMargin border = container->GetUsedBorder();
  4415. nsMargin scrollbarSizes(0, 0, 0, 0);
  4416. nsRect rect = mOuterFrame->GetRect();
  4417. nsRect containerRect = container->GetRect();
  4418. if (container->GetType() == nsGkAtoms::viewportFrame) {
  4419. // For absolutely positioned frames scrollbars are taken into
  4420. // account by virtue of getting a containing block that does
  4421. // _not_ include the scrollbars. For fixed positioned frames,
  4422. // the containing block is the viewport, which _does_ include
  4423. // scrollbars. We have to do some extra work.
  4424. // the first child in the default frame list is what we want
  4425. nsIFrame* scrollingChild = container->PrincipalChildList().FirstChild();
  4426. nsIScrollableFrame *scrollFrame = do_QueryFrame(scrollingChild);
  4427. if (scrollFrame) {
  4428. scrollbarSizes = scrollFrame->GetActualScrollbarSizes();
  4429. }
  4430. }
  4431. nscoord offset = 0;
  4432. switch (aSide) {
  4433. case NS_SIDE_TOP:
  4434. offset = rect.y - margin.top - border.top - scrollbarSizes.top;
  4435. break;
  4436. case NS_SIDE_RIGHT:
  4437. offset = containerRect.width - rect.width -
  4438. rect.x - margin.right - border.right - scrollbarSizes.right;
  4439. break;
  4440. case NS_SIDE_BOTTOM:
  4441. offset = containerRect.height - rect.height -
  4442. rect.y - margin.bottom - border.bottom - scrollbarSizes.bottom;
  4443. break;
  4444. case NS_SIDE_LEFT:
  4445. offset = rect.x - margin.left - border.left - scrollbarSizes.left;
  4446. break;
  4447. default:
  4448. NS_ERROR("Invalid side");
  4449. break;
  4450. }
  4451. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4452. val->SetAppUnits(offset);
  4453. return val.forget();
  4454. }
  4455. static_assert(NS_SIDE_TOP == 0 && NS_SIDE_RIGHT == 1 &&
  4456. NS_SIDE_BOTTOM == 2 && NS_SIDE_LEFT == 3,
  4457. "box side constants not as expected for NS_OPPOSITE_SIDE");
  4458. #define NS_OPPOSITE_SIDE(s_) mozilla::css::Side(((s_) + 2) & 3)
  4459. already_AddRefed<CSSValue>
  4460. nsComputedDOMStyle::GetRelativeOffset(mozilla::css::Side aSide)
  4461. {
  4462. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4463. const nsStylePosition* positionData = StylePosition();
  4464. int32_t sign = 1;
  4465. nsStyleCoord coord = positionData->mOffset.Get(aSide);
  4466. NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord ||
  4467. coord.GetUnit() == eStyleUnit_Percent ||
  4468. coord.GetUnit() == eStyleUnit_Auto ||
  4469. coord.IsCalcUnit(),
  4470. "Unexpected unit");
  4471. if (coord.GetUnit() == eStyleUnit_Auto) {
  4472. coord = positionData->mOffset.Get(NS_OPPOSITE_SIDE(aSide));
  4473. sign = -1;
  4474. }
  4475. PercentageBaseGetter baseGetter;
  4476. if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
  4477. baseGetter = &nsComputedDOMStyle::GetCBContentWidth;
  4478. } else {
  4479. baseGetter = &nsComputedDOMStyle::GetCBContentHeight;
  4480. }
  4481. val->SetAppUnits(sign * StyleCoordToNSCoord(coord, baseGetter, 0, false));
  4482. return val.forget();
  4483. }
  4484. already_AddRefed<CSSValue>
  4485. nsComputedDOMStyle::GetStickyOffset(mozilla::css::Side aSide)
  4486. {
  4487. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4488. const nsStylePosition* positionData = StylePosition();
  4489. nsStyleCoord coord = positionData->mOffset.Get(aSide);
  4490. NS_ASSERTION(coord.GetUnit() == eStyleUnit_Coord ||
  4491. coord.GetUnit() == eStyleUnit_Percent ||
  4492. coord.GetUnit() == eStyleUnit_Auto ||
  4493. coord.IsCalcUnit(),
  4494. "Unexpected unit");
  4495. if (coord.GetUnit() == eStyleUnit_Auto) {
  4496. val->SetIdent(eCSSKeyword_auto);
  4497. return val.forget();
  4498. }
  4499. PercentageBaseGetter baseGetter;
  4500. if (aSide == NS_SIDE_LEFT || aSide == NS_SIDE_RIGHT) {
  4501. baseGetter = &nsComputedDOMStyle::GetScrollFrameContentWidth;
  4502. } else {
  4503. baseGetter = &nsComputedDOMStyle::GetScrollFrameContentHeight;
  4504. }
  4505. val->SetAppUnits(StyleCoordToNSCoord(coord, baseGetter, 0, false));
  4506. return val.forget();
  4507. }
  4508. already_AddRefed<CSSValue>
  4509. nsComputedDOMStyle::GetStaticOffset(mozilla::css::Side aSide)
  4510. {
  4511. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4512. SetValueToCoord(val, StylePosition()->mOffset.Get(aSide), false);
  4513. return val.forget();
  4514. }
  4515. already_AddRefed<CSSValue>
  4516. nsComputedDOMStyle::GetPaddingWidthFor(mozilla::css::Side aSide)
  4517. {
  4518. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4519. if (!mInnerFrame) {
  4520. SetValueToCoord(val, StylePadding()->mPadding.Get(aSide), true);
  4521. } else {
  4522. AssertFlushedPendingReflows();
  4523. val->SetAppUnits(mInnerFrame->GetUsedPadding().Side(aSide));
  4524. }
  4525. return val.forget();
  4526. }
  4527. bool
  4528. nsComputedDOMStyle::GetLineHeightCoord(nscoord& aCoord)
  4529. {
  4530. AssertFlushedPendingReflows();
  4531. nscoord blockHeight = NS_AUTOHEIGHT;
  4532. if (StyleText()->mLineHeight.GetUnit() == eStyleUnit_Enumerated) {
  4533. if (!mInnerFrame)
  4534. return false;
  4535. if (nsLayoutUtils::IsNonWrapperBlock(mInnerFrame)) {
  4536. blockHeight = mInnerFrame->GetContentRect().height;
  4537. } else {
  4538. GetCBContentHeight(blockHeight);
  4539. }
  4540. }
  4541. // lie about font size inflation since we lie about font size (since
  4542. // the inflation only applies to text)
  4543. aCoord = ReflowInput::CalcLineHeight(mElement,
  4544. mStyleContext,
  4545. blockHeight,
  4546. 1.0f);
  4547. // CalcLineHeight uses font->mFont.size, but we want to use
  4548. // font->mSize as the font size. Adjust for that. Also adjust for
  4549. // the text zoom, if any.
  4550. const nsStyleFont* font = StyleFont();
  4551. float fCoord = float(aCoord);
  4552. if (font->mAllowZoom) {
  4553. fCoord /= mPresShell->GetPresContext()->TextZoom();
  4554. }
  4555. if (font->mFont.size != font->mSize) {
  4556. fCoord = fCoord * (float(font->mSize) / float(font->mFont.size));
  4557. }
  4558. aCoord = NSToCoordRound(fCoord);
  4559. return true;
  4560. }
  4561. already_AddRefed<CSSValue>
  4562. nsComputedDOMStyle::GetBorderColorsFor(mozilla::css::Side aSide)
  4563. {
  4564. const nsStyleBorder *border = StyleBorder();
  4565. if (border->mBorderColors) {
  4566. nsBorderColors* borderColors = border->mBorderColors[aSide];
  4567. if (borderColors) {
  4568. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  4569. do {
  4570. RefPtr<nsROCSSPrimitiveValue> primitive = new nsROCSSPrimitiveValue;
  4571. SetToRGBAColor(primitive, borderColors->mColor);
  4572. valueList->AppendCSSValue(primitive.forget());
  4573. borderColors = borderColors->mNext;
  4574. } while (borderColors);
  4575. return valueList.forget();
  4576. }
  4577. }
  4578. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4579. val->SetIdent(eCSSKeyword_none);
  4580. return val.forget();
  4581. }
  4582. already_AddRefed<CSSValue>
  4583. nsComputedDOMStyle::GetBorderWidthFor(mozilla::css::Side aSide)
  4584. {
  4585. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4586. nscoord width;
  4587. if (mInnerFrame) {
  4588. AssertFlushedPendingReflows();
  4589. width = mInnerFrame->GetUsedBorder().Side(aSide);
  4590. } else {
  4591. width = StyleBorder()->GetComputedBorderWidth(aSide);
  4592. }
  4593. val->SetAppUnits(width);
  4594. return val.forget();
  4595. }
  4596. already_AddRefed<CSSValue>
  4597. nsComputedDOMStyle::GetBorderColorFor(mozilla::css::Side aSide)
  4598. {
  4599. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4600. SetValueFromComplexColor(val, StyleBorder()->mBorderColor[aSide]);
  4601. return val.forget();
  4602. }
  4603. already_AddRefed<CSSValue>
  4604. nsComputedDOMStyle::GetMarginWidthFor(mozilla::css::Side aSide)
  4605. {
  4606. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4607. if (!mInnerFrame) {
  4608. SetValueToCoord(val, StyleMargin()->mMargin.Get(aSide), false);
  4609. } else {
  4610. AssertFlushedPendingReflows();
  4611. // For tables, GetUsedMargin always returns an empty margin, so we
  4612. // should read the margin from the table wrapper frame instead.
  4613. val->SetAppUnits(mOuterFrame->GetUsedMargin().Side(aSide));
  4614. NS_ASSERTION(mOuterFrame == mInnerFrame ||
  4615. mInnerFrame->GetUsedMargin() == nsMargin(0, 0, 0, 0),
  4616. "Inner tables must have zero margins");
  4617. }
  4618. return val.forget();
  4619. }
  4620. already_AddRefed<CSSValue>
  4621. nsComputedDOMStyle::GetBorderStyleFor(mozilla::css::Side aSide)
  4622. {
  4623. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4624. val->SetIdent(
  4625. nsCSSProps::ValueToKeywordEnum(StyleBorder()->GetBorderStyle(aSide),
  4626. nsCSSProps::kBorderStyleKTable));
  4627. return val.forget();
  4628. }
  4629. void
  4630. nsComputedDOMStyle::SetValueToCoord(nsROCSSPrimitiveValue* aValue,
  4631. const nsStyleCoord& aCoord,
  4632. bool aClampNegativeCalc,
  4633. PercentageBaseGetter aPercentageBaseGetter,
  4634. const KTableEntry aTable[],
  4635. nscoord aMinAppUnits,
  4636. nscoord aMaxAppUnits)
  4637. {
  4638. NS_PRECONDITION(aValue, "Must have a value to work with");
  4639. switch (aCoord.GetUnit()) {
  4640. case eStyleUnit_Normal:
  4641. aValue->SetIdent(eCSSKeyword_normal);
  4642. break;
  4643. case eStyleUnit_Auto:
  4644. aValue->SetIdent(eCSSKeyword_auto);
  4645. break;
  4646. case eStyleUnit_Percent:
  4647. {
  4648. nscoord percentageBase;
  4649. if (aPercentageBaseGetter &&
  4650. (this->*aPercentageBaseGetter)(percentageBase)) {
  4651. nscoord val = NSCoordSaturatingMultiply(percentageBase,
  4652. aCoord.GetPercentValue());
  4653. aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
  4654. } else {
  4655. aValue->SetPercent(aCoord.GetPercentValue());
  4656. }
  4657. }
  4658. break;
  4659. case eStyleUnit_Factor:
  4660. aValue->SetNumber(aCoord.GetFactorValue());
  4661. break;
  4662. case eStyleUnit_Coord:
  4663. {
  4664. nscoord val = aCoord.GetCoordValue();
  4665. aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
  4666. }
  4667. break;
  4668. case eStyleUnit_Integer:
  4669. aValue->SetNumber(aCoord.GetIntValue());
  4670. break;
  4671. case eStyleUnit_Enumerated:
  4672. NS_ASSERTION(aTable, "Must have table to handle this case");
  4673. aValue->SetIdent(nsCSSProps::ValueToKeywordEnum(aCoord.GetIntValue(),
  4674. aTable));
  4675. break;
  4676. case eStyleUnit_None:
  4677. aValue->SetIdent(eCSSKeyword_none);
  4678. break;
  4679. case eStyleUnit_Calc:
  4680. nscoord percentageBase;
  4681. if (!aCoord.CalcHasPercent()) {
  4682. nscoord val = nsRuleNode::ComputeCoordPercentCalc(aCoord, 0);
  4683. if (aClampNegativeCalc && val < 0) {
  4684. MOZ_ASSERT(aCoord.IsCalcUnit(),
  4685. "parser should have rejected value");
  4686. val = 0;
  4687. }
  4688. aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
  4689. } else if (aPercentageBaseGetter &&
  4690. (this->*aPercentageBaseGetter)(percentageBase)) {
  4691. nscoord val =
  4692. nsRuleNode::ComputeCoordPercentCalc(aCoord, percentageBase);
  4693. if (aClampNegativeCalc && val < 0) {
  4694. MOZ_ASSERT(aCoord.IsCalcUnit(),
  4695. "parser should have rejected value");
  4696. val = 0;
  4697. }
  4698. aValue->SetAppUnits(std::max(aMinAppUnits, std::min(val, aMaxAppUnits)));
  4699. } else {
  4700. nsStyleCoord::Calc *calc = aCoord.GetCalcValue();
  4701. SetValueToCalc(calc, aValue);
  4702. }
  4703. break;
  4704. case eStyleUnit_Degree:
  4705. aValue->SetDegree(aCoord.GetAngleValue());
  4706. break;
  4707. case eStyleUnit_Grad:
  4708. aValue->SetGrad(aCoord.GetAngleValue());
  4709. break;
  4710. case eStyleUnit_Radian:
  4711. aValue->SetRadian(aCoord.GetAngleValue());
  4712. break;
  4713. case eStyleUnit_Turn:
  4714. aValue->SetTurn(aCoord.GetAngleValue());
  4715. break;
  4716. case eStyleUnit_FlexFraction: {
  4717. nsAutoString tmpStr;
  4718. nsStyleUtil::AppendCSSNumber(aCoord.GetFlexFractionValue(), tmpStr);
  4719. tmpStr.AppendLiteral("fr");
  4720. aValue->SetString(tmpStr);
  4721. break;
  4722. }
  4723. default:
  4724. NS_ERROR("Can't handle this unit");
  4725. break;
  4726. }
  4727. }
  4728. nscoord
  4729. nsComputedDOMStyle::StyleCoordToNSCoord(const nsStyleCoord& aCoord,
  4730. PercentageBaseGetter aPercentageBaseGetter,
  4731. nscoord aDefaultValue,
  4732. bool aClampNegativeCalc)
  4733. {
  4734. NS_PRECONDITION(aPercentageBaseGetter, "Must have a percentage base getter");
  4735. if (aCoord.GetUnit() == eStyleUnit_Coord) {
  4736. return aCoord.GetCoordValue();
  4737. }
  4738. if (aCoord.GetUnit() == eStyleUnit_Percent || aCoord.IsCalcUnit()) {
  4739. nscoord percentageBase;
  4740. if ((this->*aPercentageBaseGetter)(percentageBase)) {
  4741. nscoord result =
  4742. nsRuleNode::ComputeCoordPercentCalc(aCoord, percentageBase);
  4743. if (aClampNegativeCalc && result < 0) {
  4744. // It's expected that we can get a negative value here with calc().
  4745. // We can also get a negative value with a percentage value if
  4746. // percentageBase is negative; this isn't expected, but can happen
  4747. // when large length values overflow.
  4748. NS_WARNING_ASSERTION(
  4749. percentageBase >= 0,
  4750. "percentage base value overflowed to become negative for a property "
  4751. "that disallows negative values");
  4752. MOZ_ASSERT(aCoord.IsCalcUnit() ||
  4753. (aCoord.HasPercent() && percentageBase < 0),
  4754. "parser should have rejected value");
  4755. result = 0;
  4756. }
  4757. return result;
  4758. }
  4759. // Fall through to returning aDefaultValue if we have no percentage base.
  4760. }
  4761. return aDefaultValue;
  4762. }
  4763. bool
  4764. nsComputedDOMStyle::GetCBContentWidth(nscoord& aWidth)
  4765. {
  4766. if (!mOuterFrame) {
  4767. return false;
  4768. }
  4769. AssertFlushedPendingReflows();
  4770. nsIFrame* container = mOuterFrame->GetContainingBlock();
  4771. aWidth = container->GetContentRect().width;
  4772. return true;
  4773. }
  4774. bool
  4775. nsComputedDOMStyle::GetCBContentHeight(nscoord& aHeight)
  4776. {
  4777. if (!mOuterFrame) {
  4778. return false;
  4779. }
  4780. AssertFlushedPendingReflows();
  4781. nsIFrame* container = mOuterFrame->GetContainingBlock();
  4782. aHeight = container->GetContentRect().height;
  4783. return true;
  4784. }
  4785. bool
  4786. nsComputedDOMStyle::GetScrollFrameContentWidth(nscoord& aWidth)
  4787. {
  4788. if (!mOuterFrame) {
  4789. return false;
  4790. }
  4791. AssertFlushedPendingReflows();
  4792. nsIScrollableFrame* scrollableFrame =
  4793. nsLayoutUtils::GetNearestScrollableFrame(mOuterFrame->GetParent(),
  4794. nsLayoutUtils::SCROLLABLE_SAME_DOC |
  4795. nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
  4796. if (!scrollableFrame) {
  4797. return false;
  4798. }
  4799. aWidth =
  4800. scrollableFrame->GetScrolledFrame()->GetContentRectRelativeToSelf().width;
  4801. return true;
  4802. }
  4803. bool
  4804. nsComputedDOMStyle::GetScrollFrameContentHeight(nscoord& aHeight)
  4805. {
  4806. if (!mOuterFrame) {
  4807. return false;
  4808. }
  4809. AssertFlushedPendingReflows();
  4810. nsIScrollableFrame* scrollableFrame =
  4811. nsLayoutUtils::GetNearestScrollableFrame(mOuterFrame->GetParent(),
  4812. nsLayoutUtils::SCROLLABLE_SAME_DOC |
  4813. nsLayoutUtils::SCROLLABLE_INCLUDE_HIDDEN);
  4814. if (!scrollableFrame) {
  4815. return false;
  4816. }
  4817. aHeight =
  4818. scrollableFrame->GetScrolledFrame()->GetContentRectRelativeToSelf().height;
  4819. return true;
  4820. }
  4821. bool
  4822. nsComputedDOMStyle::GetFrameBorderRectWidth(nscoord& aWidth)
  4823. {
  4824. if (!mInnerFrame) {
  4825. return false;
  4826. }
  4827. AssertFlushedPendingReflows();
  4828. aWidth = mInnerFrame->GetSize().width;
  4829. return true;
  4830. }
  4831. bool
  4832. nsComputedDOMStyle::GetFrameBorderRectHeight(nscoord& aHeight)
  4833. {
  4834. if (!mInnerFrame) {
  4835. return false;
  4836. }
  4837. AssertFlushedPendingReflows();
  4838. aHeight = mInnerFrame->GetSize().height;
  4839. return true;
  4840. }
  4841. bool
  4842. nsComputedDOMStyle::GetFrameBoundsWidthForTransform(nscoord& aWidth)
  4843. {
  4844. // We need a frame to work with.
  4845. if (!mInnerFrame) {
  4846. return false;
  4847. }
  4848. AssertFlushedPendingReflows();
  4849. aWidth = nsStyleTransformMatrix::TransformReferenceBox(mInnerFrame).Width();
  4850. return true;
  4851. }
  4852. bool
  4853. nsComputedDOMStyle::GetFrameBoundsHeightForTransform(nscoord& aHeight)
  4854. {
  4855. // We need a frame to work with.
  4856. if (!mInnerFrame) {
  4857. return false;
  4858. }
  4859. AssertFlushedPendingReflows();
  4860. aHeight = nsStyleTransformMatrix::TransformReferenceBox(mInnerFrame).Height();
  4861. return true;
  4862. }
  4863. already_AddRefed<CSSValue>
  4864. nsComputedDOMStyle::GetSVGPaintFor(bool aFill)
  4865. {
  4866. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4867. const nsStyleSVG* svg = StyleSVG();
  4868. const nsStyleSVGPaint* paint = nullptr;
  4869. if (aFill)
  4870. paint = &svg->mFill;
  4871. else
  4872. paint = &svg->mStroke;
  4873. nsAutoString paintString;
  4874. switch (paint->Type()) {
  4875. case eStyleSVGPaintType_None:
  4876. val->SetIdent(eCSSKeyword_none);
  4877. break;
  4878. case eStyleSVGPaintType_Color:
  4879. SetToRGBAColor(val, paint->GetColor());
  4880. break;
  4881. case eStyleSVGPaintType_Server: {
  4882. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  4883. RefPtr<nsROCSSPrimitiveValue> fallback = new nsROCSSPrimitiveValue;
  4884. SetValueToURLValue(paint->GetPaintServer(), val);
  4885. SetToRGBAColor(fallback, paint->GetFallbackColor());
  4886. valueList->AppendCSSValue(val.forget());
  4887. valueList->AppendCSSValue(fallback.forget());
  4888. return valueList.forget();
  4889. }
  4890. case eStyleSVGPaintType_ContextFill:
  4891. val->SetIdent(eCSSKeyword_context_fill);
  4892. // XXXheycam context-fill and context-stroke can have fallback colors,
  4893. // so they should be serialized here too
  4894. break;
  4895. case eStyleSVGPaintType_ContextStroke:
  4896. val->SetIdent(eCSSKeyword_context_stroke);
  4897. break;
  4898. }
  4899. return val.forget();
  4900. }
  4901. already_AddRefed<CSSValue>
  4902. nsComputedDOMStyle::DoGetFill()
  4903. {
  4904. return GetSVGPaintFor(true);
  4905. }
  4906. already_AddRefed<CSSValue>
  4907. nsComputedDOMStyle::DoGetStroke()
  4908. {
  4909. return GetSVGPaintFor(false);
  4910. }
  4911. already_AddRefed<CSSValue>
  4912. nsComputedDOMStyle::DoGetMarkerEnd()
  4913. {
  4914. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4915. SetValueToURLValue(StyleSVG()->mMarkerEnd, val);
  4916. return val.forget();
  4917. }
  4918. already_AddRefed<CSSValue>
  4919. nsComputedDOMStyle::DoGetMarkerMid()
  4920. {
  4921. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4922. SetValueToURLValue(StyleSVG()->mMarkerMid, val);
  4923. return val.forget();
  4924. }
  4925. already_AddRefed<CSSValue>
  4926. nsComputedDOMStyle::DoGetMarkerStart()
  4927. {
  4928. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4929. SetValueToURLValue(StyleSVG()->mMarkerStart, val);
  4930. return val.forget();
  4931. }
  4932. already_AddRefed<CSSValue>
  4933. nsComputedDOMStyle::DoGetStrokeDasharray()
  4934. {
  4935. const nsStyleSVG* svg = StyleSVG();
  4936. if (svg->mStrokeDasharray.IsEmpty()) {
  4937. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4938. val->SetIdent(eCSSKeyword_none);
  4939. return val.forget();
  4940. }
  4941. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  4942. for (uint32_t i = 0; i < svg->mStrokeDasharray.Length(); i++) {
  4943. RefPtr<nsROCSSPrimitiveValue> dash = new nsROCSSPrimitiveValue;
  4944. SetValueToCoord(dash, svg->mStrokeDasharray[i], true);
  4945. valueList->AppendCSSValue(dash.forget());
  4946. }
  4947. return valueList.forget();
  4948. }
  4949. already_AddRefed<CSSValue>
  4950. nsComputedDOMStyle::DoGetStrokeDashoffset()
  4951. {
  4952. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4953. SetValueToCoord(val, StyleSVG()->mStrokeDashoffset, false);
  4954. return val.forget();
  4955. }
  4956. already_AddRefed<CSSValue>
  4957. nsComputedDOMStyle::DoGetStrokeWidth()
  4958. {
  4959. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4960. SetValueToCoord(val, StyleSVG()->mStrokeWidth, true);
  4961. return val.forget();
  4962. }
  4963. already_AddRefed<CSSValue>
  4964. nsComputedDOMStyle::DoGetVectorEffect()
  4965. {
  4966. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4967. val->SetIdent(nsCSSProps::ValueToKeywordEnum(StyleSVGReset()->mVectorEffect,
  4968. nsCSSProps::kVectorEffectKTable));
  4969. return val.forget();
  4970. }
  4971. already_AddRefed<CSSValue>
  4972. nsComputedDOMStyle::DoGetFillOpacity()
  4973. {
  4974. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4975. val->SetNumber(StyleSVG()->mFillOpacity);
  4976. return val.forget();
  4977. }
  4978. already_AddRefed<CSSValue>
  4979. nsComputedDOMStyle::DoGetFloodOpacity()
  4980. {
  4981. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4982. val->SetNumber(StyleSVGReset()->mFloodOpacity);
  4983. return val.forget();
  4984. }
  4985. already_AddRefed<CSSValue>
  4986. nsComputedDOMStyle::DoGetStopOpacity()
  4987. {
  4988. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4989. val->SetNumber(StyleSVGReset()->mStopOpacity);
  4990. return val.forget();
  4991. }
  4992. already_AddRefed<CSSValue>
  4993. nsComputedDOMStyle::DoGetStrokeMiterlimit()
  4994. {
  4995. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  4996. val->SetNumber(StyleSVG()->mStrokeMiterlimit);
  4997. return val.forget();
  4998. }
  4999. already_AddRefed<CSSValue>
  5000. nsComputedDOMStyle::DoGetStrokeOpacity()
  5001. {
  5002. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5003. val->SetNumber(StyleSVG()->mStrokeOpacity);
  5004. return val.forget();
  5005. }
  5006. already_AddRefed<CSSValue>
  5007. nsComputedDOMStyle::DoGetClipRule()
  5008. {
  5009. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5010. val->SetIdent(nsCSSProps::ValueToKeywordEnum(
  5011. StyleSVG()->mClipRule, nsCSSProps::kFillRuleKTable));
  5012. return val.forget();
  5013. }
  5014. already_AddRefed<CSSValue>
  5015. nsComputedDOMStyle::DoGetFillRule()
  5016. {
  5017. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5018. val->SetIdent(nsCSSProps::ValueToKeywordEnum(
  5019. StyleSVG()->mFillRule, nsCSSProps::kFillRuleKTable));
  5020. return val.forget();
  5021. }
  5022. already_AddRefed<CSSValue>
  5023. nsComputedDOMStyle::DoGetStrokeLinecap()
  5024. {
  5025. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5026. val->SetIdent(
  5027. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mStrokeLinecap,
  5028. nsCSSProps::kStrokeLinecapKTable));
  5029. return val.forget();
  5030. }
  5031. already_AddRefed<CSSValue>
  5032. nsComputedDOMStyle::DoGetStrokeLinejoin()
  5033. {
  5034. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5035. val->SetIdent(
  5036. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mStrokeLinejoin,
  5037. nsCSSProps::kStrokeLinejoinKTable));
  5038. return val.forget();
  5039. }
  5040. already_AddRefed<CSSValue>
  5041. nsComputedDOMStyle::DoGetTextAnchor()
  5042. {
  5043. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5044. val->SetIdent(
  5045. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mTextAnchor,
  5046. nsCSSProps::kTextAnchorKTable));
  5047. return val.forget();
  5048. }
  5049. already_AddRefed<CSSValue>
  5050. nsComputedDOMStyle::DoGetColorInterpolation()
  5051. {
  5052. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5053. val->SetIdent(
  5054. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mColorInterpolation,
  5055. nsCSSProps::kColorInterpolationKTable));
  5056. return val.forget();
  5057. }
  5058. already_AddRefed<CSSValue>
  5059. nsComputedDOMStyle::DoGetColorInterpolationFilters()
  5060. {
  5061. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5062. val->SetIdent(
  5063. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mColorInterpolationFilters,
  5064. nsCSSProps::kColorInterpolationKTable));
  5065. return val.forget();
  5066. }
  5067. already_AddRefed<CSSValue>
  5068. nsComputedDOMStyle::DoGetDominantBaseline()
  5069. {
  5070. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5071. val->SetIdent(
  5072. nsCSSProps::ValueToKeywordEnum(StyleSVGReset()->mDominantBaseline,
  5073. nsCSSProps::kDominantBaselineKTable));
  5074. return val.forget();
  5075. }
  5076. already_AddRefed<CSSValue>
  5077. nsComputedDOMStyle::DoGetImageRendering()
  5078. {
  5079. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5080. val->SetIdent(
  5081. nsCSSProps::ValueToKeywordEnum(StyleVisibility()->mImageRendering,
  5082. nsCSSProps::kImageRenderingKTable));
  5083. return val.forget();
  5084. }
  5085. already_AddRefed<CSSValue>
  5086. nsComputedDOMStyle::DoGetShapeRendering()
  5087. {
  5088. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5089. val->SetIdent(
  5090. nsCSSProps::ValueToKeywordEnum(StyleSVG()->mShapeRendering,
  5091. nsCSSProps::kShapeRenderingKTable));
  5092. return val.forget();
  5093. }
  5094. already_AddRefed<CSSValue>
  5095. nsComputedDOMStyle::DoGetTextRendering()
  5096. {
  5097. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5098. val->SetIdent(
  5099. nsCSSProps::ValueToKeywordEnum(StyleText()->mTextRendering,
  5100. nsCSSProps::kTextRenderingKTable));
  5101. return val.forget();
  5102. }
  5103. already_AddRefed<CSSValue>
  5104. nsComputedDOMStyle::DoGetFloodColor()
  5105. {
  5106. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5107. SetToRGBAColor(val, StyleSVGReset()->mFloodColor);
  5108. return val.forget();
  5109. }
  5110. already_AddRefed<CSSValue>
  5111. nsComputedDOMStyle::DoGetLightingColor()
  5112. {
  5113. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5114. SetToRGBAColor(val, StyleSVGReset()->mLightingColor);
  5115. return val.forget();
  5116. }
  5117. already_AddRefed<CSSValue>
  5118. nsComputedDOMStyle::DoGetStopColor()
  5119. {
  5120. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5121. SetToRGBAColor(val, StyleSVGReset()->mStopColor);
  5122. return val.forget();
  5123. }
  5124. void
  5125. nsComputedDOMStyle::BoxValuesToString(nsAString& aString,
  5126. const nsTArray<nsStyleCoord>& aBoxValues)
  5127. {
  5128. MOZ_ASSERT(aBoxValues.Length() == 4, "wrong number of box values");
  5129. nsAutoString value1, value2, value3, value4;
  5130. SetCssTextToCoord(value1, aBoxValues[0]);
  5131. SetCssTextToCoord(value2, aBoxValues[1]);
  5132. SetCssTextToCoord(value3, aBoxValues[2]);
  5133. SetCssTextToCoord(value4, aBoxValues[3]);
  5134. // nsROCSSPrimitiveValue do not have binary comparison operators.
  5135. // Compare string results instead.
  5136. aString.Append(value1);
  5137. if (value1 != value2 || value1 != value3 || value1 != value4) {
  5138. aString.Append(' ');
  5139. aString.Append(value2);
  5140. if (value1 != value3 || value2 != value4) {
  5141. aString.Append(' ');
  5142. aString.Append(value3);
  5143. if (value2 != value4) {
  5144. aString.Append(' ');
  5145. aString.Append(value4);
  5146. }
  5147. }
  5148. }
  5149. }
  5150. void
  5151. nsComputedDOMStyle::BasicShapeRadiiToString(nsAString& aCssText,
  5152. const nsStyleCorners& aCorners)
  5153. {
  5154. nsTArray<nsStyleCoord> horizontal, vertical;
  5155. nsAutoString horizontalString, verticalString;
  5156. NS_FOR_CSS_FULL_CORNERS(corner) {
  5157. horizontal.AppendElement(
  5158. aCorners.Get(NS_FULL_TO_HALF_CORNER(corner, false)));
  5159. vertical.AppendElement(
  5160. aCorners.Get(NS_FULL_TO_HALF_CORNER(corner, true)));
  5161. }
  5162. BoxValuesToString(horizontalString, horizontal);
  5163. BoxValuesToString(verticalString, vertical);
  5164. aCssText.Append(horizontalString);
  5165. if (horizontalString == verticalString) {
  5166. return;
  5167. }
  5168. aCssText.AppendLiteral(" / ");
  5169. aCssText.Append(verticalString);
  5170. }
  5171. already_AddRefed<CSSValue>
  5172. nsComputedDOMStyle::CreatePrimitiveValueForBasicShape(
  5173. const StyleBasicShape* aStyleBasicShape)
  5174. {
  5175. MOZ_ASSERT(aStyleBasicShape, "Expect a valid basic shape pointer!");
  5176. StyleBasicShapeType type = aStyleBasicShape->GetShapeType();
  5177. // Shape function name and opening parenthesis.
  5178. nsAutoString shapeFunctionString;
  5179. AppendASCIItoUTF16(nsCSSKeywords::GetStringValue(
  5180. aStyleBasicShape->GetShapeTypeName()),
  5181. shapeFunctionString);
  5182. shapeFunctionString.Append('(');
  5183. switch (type) {
  5184. case StyleBasicShapeType::Polygon: {
  5185. bool hasEvenOdd = aStyleBasicShape->GetFillRule() ==
  5186. StyleFillRule::Evenodd;
  5187. if (hasEvenOdd) {
  5188. shapeFunctionString.AppendLiteral("evenodd");
  5189. }
  5190. for (size_t i = 0;
  5191. i < aStyleBasicShape->Coordinates().Length(); i += 2) {
  5192. nsAutoString coordString;
  5193. if (i > 0 || hasEvenOdd) {
  5194. shapeFunctionString.AppendLiteral(", ");
  5195. }
  5196. SetCssTextToCoord(coordString,
  5197. aStyleBasicShape->Coordinates()[i]);
  5198. shapeFunctionString.Append(coordString);
  5199. shapeFunctionString.Append(' ');
  5200. SetCssTextToCoord(coordString,
  5201. aStyleBasicShape->Coordinates()[i + 1]);
  5202. shapeFunctionString.Append(coordString);
  5203. }
  5204. break;
  5205. }
  5206. case StyleBasicShapeType::Circle:
  5207. case StyleBasicShapeType::Ellipse: {
  5208. const nsTArray<nsStyleCoord>& radii = aStyleBasicShape->Coordinates();
  5209. MOZ_ASSERT(radii.Length() ==
  5210. (type == StyleBasicShapeType::Circle ? 1 : 2),
  5211. "wrong number of radii");
  5212. for (size_t i = 0; i < radii.Length(); ++i) {
  5213. nsAutoString radius;
  5214. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  5215. bool clampNegativeCalc = true;
  5216. SetValueToCoord(value, radii[i], clampNegativeCalc, nullptr,
  5217. nsCSSProps::kShapeRadiusKTable);
  5218. value->GetCssText(radius);
  5219. shapeFunctionString.Append(radius);
  5220. shapeFunctionString.Append(' ');
  5221. }
  5222. shapeFunctionString.AppendLiteral("at ");
  5223. RefPtr<nsDOMCSSValueList> position = GetROCSSValueList(false);
  5224. nsAutoString positionString;
  5225. SetValueToPosition(aStyleBasicShape->GetPosition(), position);
  5226. position->GetCssText(positionString);
  5227. shapeFunctionString.Append(positionString);
  5228. break;
  5229. }
  5230. case StyleBasicShapeType::Inset: {
  5231. BoxValuesToString(shapeFunctionString, aStyleBasicShape->Coordinates());
  5232. if (aStyleBasicShape->HasRadius()) {
  5233. shapeFunctionString.AppendLiteral(" round ");
  5234. nsAutoString radiiString;
  5235. BasicShapeRadiiToString(radiiString, aStyleBasicShape->GetRadius());
  5236. shapeFunctionString.Append(radiiString);
  5237. }
  5238. break;
  5239. }
  5240. default:
  5241. NS_NOTREACHED("unexpected type");
  5242. }
  5243. shapeFunctionString.Append(')');
  5244. RefPtr<nsROCSSPrimitiveValue> functionValue = new nsROCSSPrimitiveValue;
  5245. functionValue->SetString(shapeFunctionString);
  5246. return functionValue.forget();
  5247. }
  5248. template<typename ReferenceBox>
  5249. already_AddRefed<CSSValue>
  5250. nsComputedDOMStyle::CreatePrimitiveValueForShapeSource(
  5251. const StyleBasicShape* aStyleBasicShape,
  5252. ReferenceBox aReferenceBox,
  5253. const KTableEntry aBoxKeywordTable[])
  5254. {
  5255. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  5256. if (aStyleBasicShape) {
  5257. valueList->AppendCSSValue(
  5258. CreatePrimitiveValueForBasicShape(aStyleBasicShape));
  5259. }
  5260. if (aReferenceBox == ReferenceBox::NoBox) {
  5261. return valueList.forget();
  5262. }
  5263. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5264. val->SetIdent(nsCSSProps::ValueToKeywordEnum(aReferenceBox, aBoxKeywordTable));
  5265. valueList->AppendCSSValue(val.forget());
  5266. return valueList.forget();
  5267. }
  5268. template<typename ReferenceBox>
  5269. already_AddRefed<CSSValue>
  5270. nsComputedDOMStyle::GetShapeSource(
  5271. const StyleShapeSource<ReferenceBox>& aShapeSource,
  5272. const KTableEntry aBoxKeywordTable[])
  5273. {
  5274. switch (aShapeSource.GetType()) {
  5275. case StyleShapeSourceType::Shape:
  5276. return CreatePrimitiveValueForShapeSource(aShapeSource.GetBasicShape(),
  5277. aShapeSource.GetReferenceBox(),
  5278. aBoxKeywordTable);
  5279. case StyleShapeSourceType::Box:
  5280. return CreatePrimitiveValueForShapeSource(nullptr,
  5281. aShapeSource.GetReferenceBox(),
  5282. aBoxKeywordTable);
  5283. case StyleShapeSourceType::URL: {
  5284. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5285. SetValueToURLValue(aShapeSource.GetURL(), val);
  5286. return val.forget();
  5287. }
  5288. case StyleShapeSourceType::None: {
  5289. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5290. val->SetIdent(eCSSKeyword_none);
  5291. return val.forget();
  5292. }
  5293. default:
  5294. NS_NOTREACHED("unexpected type");
  5295. }
  5296. return nullptr;
  5297. }
  5298. already_AddRefed<CSSValue>
  5299. nsComputedDOMStyle::DoGetClipPath()
  5300. {
  5301. return GetShapeSource(StyleSVGReset()->mClipPath,
  5302. nsCSSProps::kClipPathGeometryBoxKTable);
  5303. }
  5304. already_AddRefed<CSSValue>
  5305. nsComputedDOMStyle::DoGetShapeOutside()
  5306. {
  5307. return GetShapeSource(StyleDisplay()->mShapeOutside,
  5308. nsCSSProps::kShapeOutsideShapeBoxKTable);
  5309. }
  5310. void
  5311. nsComputedDOMStyle::SetCssTextToCoord(nsAString& aCssText,
  5312. const nsStyleCoord& aCoord)
  5313. {
  5314. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  5315. bool clampNegativeCalc = true;
  5316. SetValueToCoord(value, aCoord, clampNegativeCalc);
  5317. value->GetCssText(aCssText);
  5318. }
  5319. already_AddRefed<CSSValue>
  5320. nsComputedDOMStyle::CreatePrimitiveValueForStyleFilter(
  5321. const nsStyleFilter& aStyleFilter)
  5322. {
  5323. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  5324. // Handle url().
  5325. if (aStyleFilter.GetType() == NS_STYLE_FILTER_URL) {
  5326. MOZ_ASSERT(aStyleFilter.GetURL() &&
  5327. aStyleFilter.GetURL()->GetURI());
  5328. SetValueToURLValue(aStyleFilter.GetURL(), value);
  5329. return value.forget();
  5330. }
  5331. // Filter function name and opening parenthesis.
  5332. nsAutoString filterFunctionString;
  5333. AppendASCIItoUTF16(
  5334. nsCSSProps::ValueToKeyword(aStyleFilter.GetType(),
  5335. nsCSSProps::kFilterFunctionKTable),
  5336. filterFunctionString);
  5337. filterFunctionString.Append('(');
  5338. nsAutoString argumentString;
  5339. if (aStyleFilter.GetType() == NS_STYLE_FILTER_DROP_SHADOW) {
  5340. // Handle drop-shadow()
  5341. RefPtr<CSSValue> shadowValue =
  5342. GetCSSShadowArray(aStyleFilter.GetDropShadow(),
  5343. StyleColor()->mColor,
  5344. false);
  5345. ErrorResult dummy;
  5346. shadowValue->GetCssText(argumentString, dummy);
  5347. } else {
  5348. // Filter function argument.
  5349. SetCssTextToCoord(argumentString, aStyleFilter.GetFilterParameter());
  5350. }
  5351. filterFunctionString.Append(argumentString);
  5352. // Filter function closing parenthesis.
  5353. filterFunctionString.Append(')');
  5354. value->SetString(filterFunctionString);
  5355. return value.forget();
  5356. }
  5357. already_AddRefed<CSSValue>
  5358. nsComputedDOMStyle::DoGetFilter()
  5359. {
  5360. const nsTArray<nsStyleFilter>& filters = StyleEffects()->mFilters;
  5361. if (filters.IsEmpty()) {
  5362. RefPtr<nsROCSSPrimitiveValue> value = new nsROCSSPrimitiveValue;
  5363. value->SetIdent(eCSSKeyword_none);
  5364. return value.forget();
  5365. }
  5366. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(false);
  5367. for(uint32_t i = 0; i < filters.Length(); i++) {
  5368. RefPtr<CSSValue> value = CreatePrimitiveValueForStyleFilter(filters[i]);
  5369. valueList->AppendCSSValue(value.forget());
  5370. }
  5371. return valueList.forget();
  5372. }
  5373. already_AddRefed<CSSValue>
  5374. nsComputedDOMStyle::DoGetMask()
  5375. {
  5376. const nsStyleSVGReset* svg = StyleSVGReset();
  5377. const nsStyleImageLayers::Layer& firstLayer = svg->mMask.mLayers[0];
  5378. // Mask is now a shorthand, but it used to be a longhand, so that we
  5379. // need to support computed style for the cases where it used to be
  5380. // a longhand.
  5381. if (svg->mMask.mImageCount > 1 ||
  5382. firstLayer.mClip != StyleGeometryBox::Border ||
  5383. firstLayer.mOrigin != StyleGeometryBox::Border ||
  5384. firstLayer.mComposite != NS_STYLE_MASK_COMPOSITE_ADD ||
  5385. firstLayer.mMaskMode != NS_STYLE_MASK_MODE_MATCH_SOURCE ||
  5386. !nsStyleImageLayers::IsInitialPositionForLayerType(
  5387. firstLayer.mPosition, nsStyleImageLayers::LayerType::Mask) ||
  5388. !firstLayer.mRepeat.IsInitialValue() ||
  5389. !firstLayer.mSize.IsInitialValue() ||
  5390. !(firstLayer.mImage.GetType() == eStyleImageType_Null ||
  5391. firstLayer.mImage.GetType() == eStyleImageType_Image)) {
  5392. return nullptr;
  5393. }
  5394. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5395. SetValueToURLValue(firstLayer.mSourceURI, val);
  5396. return val.forget();
  5397. }
  5398. already_AddRefed<CSSValue>
  5399. nsComputedDOMStyle::DoGetMaskClip()
  5400. {
  5401. return GetBackgroundList(&nsStyleImageLayers::Layer::mClip,
  5402. &nsStyleImageLayers::mClipCount,
  5403. StyleSVGReset()->mMask,
  5404. nsCSSProps::kMaskClipKTable);
  5405. }
  5406. already_AddRefed<CSSValue>
  5407. nsComputedDOMStyle::DoGetMaskComposite()
  5408. {
  5409. return GetBackgroundList(&nsStyleImageLayers::Layer::mComposite,
  5410. &nsStyleImageLayers::mCompositeCount,
  5411. StyleSVGReset()->mMask,
  5412. nsCSSProps::kImageLayerCompositeKTable);
  5413. }
  5414. already_AddRefed<CSSValue>
  5415. nsComputedDOMStyle::DoGetMaskImage()
  5416. {
  5417. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5418. return DoGetImageLayerImage(layers);
  5419. }
  5420. already_AddRefed<CSSValue>
  5421. nsComputedDOMStyle::DoGetMaskMode()
  5422. {
  5423. return GetBackgroundList(&nsStyleImageLayers::Layer::mMaskMode,
  5424. &nsStyleImageLayers::mMaskModeCount,
  5425. StyleSVGReset()->mMask,
  5426. nsCSSProps::kImageLayerModeKTable);
  5427. }
  5428. already_AddRefed<CSSValue>
  5429. nsComputedDOMStyle::DoGetMaskOrigin()
  5430. {
  5431. return GetBackgroundList(&nsStyleImageLayers::Layer::mOrigin,
  5432. &nsStyleImageLayers::mOriginCount,
  5433. StyleSVGReset()->mMask,
  5434. nsCSSProps::kMaskOriginKTable);
  5435. }
  5436. already_AddRefed<CSSValue>
  5437. nsComputedDOMStyle::DoGetMaskPosition()
  5438. {
  5439. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5440. return DoGetImageLayerPosition(layers);
  5441. }
  5442. already_AddRefed<CSSValue>
  5443. nsComputedDOMStyle::DoGetMaskPositionX()
  5444. {
  5445. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5446. return DoGetImageLayerPositionX(layers);
  5447. }
  5448. already_AddRefed<CSSValue>
  5449. nsComputedDOMStyle::DoGetMaskPositionY()
  5450. {
  5451. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5452. return DoGetImageLayerPositionY(layers);
  5453. }
  5454. already_AddRefed<CSSValue>
  5455. nsComputedDOMStyle::DoGetMaskRepeat()
  5456. {
  5457. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5458. return DoGetImageLayerRepeat(layers);
  5459. }
  5460. already_AddRefed<CSSValue>
  5461. nsComputedDOMStyle::DoGetMaskSize()
  5462. {
  5463. const nsStyleImageLayers& layers = StyleSVGReset()->mMask;
  5464. return DoGetImageLayerSize(layers);
  5465. }
  5466. already_AddRefed<CSSValue>
  5467. nsComputedDOMStyle::DoGetMaskType()
  5468. {
  5469. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5470. val->SetIdent(
  5471. nsCSSProps::ValueToKeywordEnum(StyleSVGReset()->mMaskType,
  5472. nsCSSProps::kMaskTypeKTable));
  5473. return val.forget();
  5474. }
  5475. already_AddRefed<CSSValue>
  5476. nsComputedDOMStyle::DoGetPaintOrder()
  5477. {
  5478. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5479. nsAutoString string;
  5480. uint8_t paintOrder = StyleSVG()->mPaintOrder;
  5481. nsStyleUtil::AppendPaintOrderValue(paintOrder, string);
  5482. val->SetString(string);
  5483. return val.forget();
  5484. }
  5485. already_AddRefed<CSSValue>
  5486. nsComputedDOMStyle::DoGetTransitionDelay()
  5487. {
  5488. const nsStyleDisplay* display = StyleDisplay();
  5489. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5490. MOZ_ASSERT(display->mTransitionDelayCount > 0,
  5491. "first item must be explicit");
  5492. uint32_t i = 0;
  5493. do {
  5494. const StyleTransition *transition = &display->mTransitions[i];
  5495. RefPtr<nsROCSSPrimitiveValue> delay = new nsROCSSPrimitiveValue;
  5496. delay->SetTime((float)transition->GetDelay() / (float)PR_MSEC_PER_SEC);
  5497. valueList->AppendCSSValue(delay.forget());
  5498. } while (++i < display->mTransitionDelayCount);
  5499. return valueList.forget();
  5500. }
  5501. already_AddRefed<CSSValue>
  5502. nsComputedDOMStyle::DoGetTransitionDuration()
  5503. {
  5504. const nsStyleDisplay* display = StyleDisplay();
  5505. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5506. MOZ_ASSERT(display->mTransitionDurationCount > 0,
  5507. "first item must be explicit");
  5508. uint32_t i = 0;
  5509. do {
  5510. const StyleTransition *transition = &display->mTransitions[i];
  5511. RefPtr<nsROCSSPrimitiveValue> duration = new nsROCSSPrimitiveValue;
  5512. duration->SetTime((float)transition->GetDuration() / (float)PR_MSEC_PER_SEC);
  5513. valueList->AppendCSSValue(duration.forget());
  5514. } while (++i < display->mTransitionDurationCount);
  5515. return valueList.forget();
  5516. }
  5517. already_AddRefed<CSSValue>
  5518. nsComputedDOMStyle::DoGetTransitionProperty()
  5519. {
  5520. const nsStyleDisplay* display = StyleDisplay();
  5521. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5522. MOZ_ASSERT(display->mTransitionPropertyCount > 0,
  5523. "first item must be explicit");
  5524. uint32_t i = 0;
  5525. do {
  5526. const StyleTransition *transition = &display->mTransitions[i];
  5527. RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
  5528. nsCSSPropertyID cssprop = transition->GetProperty();
  5529. if (cssprop == eCSSPropertyExtra_all_properties)
  5530. property->SetIdent(eCSSKeyword_all);
  5531. else if (cssprop == eCSSPropertyExtra_no_properties)
  5532. property->SetIdent(eCSSKeyword_none);
  5533. else if (cssprop == eCSSProperty_UNKNOWN ||
  5534. cssprop == eCSSPropertyExtra_variable)
  5535. {
  5536. nsAutoString escaped;
  5537. nsStyleUtil::AppendEscapedCSSIdent(
  5538. nsDependentAtomString(transition->GetUnknownProperty()), escaped);
  5539. property->SetString(escaped); // really want SetIdent
  5540. }
  5541. else
  5542. property->SetString(nsCSSProps::GetStringValue(cssprop));
  5543. valueList->AppendCSSValue(property.forget());
  5544. } while (++i < display->mTransitionPropertyCount);
  5545. return valueList.forget();
  5546. }
  5547. void
  5548. nsComputedDOMStyle::AppendTimingFunction(nsDOMCSSValueList *aValueList,
  5549. const nsTimingFunction& aTimingFunction)
  5550. {
  5551. RefPtr<nsROCSSPrimitiveValue> timingFunction = new nsROCSSPrimitiveValue;
  5552. nsAutoString tmp;
  5553. switch (aTimingFunction.mType) {
  5554. case nsTimingFunction::Type::CubicBezier:
  5555. nsStyleUtil::AppendCubicBezierTimingFunction(aTimingFunction.mFunc.mX1,
  5556. aTimingFunction.mFunc.mY1,
  5557. aTimingFunction.mFunc.mX2,
  5558. aTimingFunction.mFunc.mY2,
  5559. tmp);
  5560. break;
  5561. case nsTimingFunction::Type::StepStart:
  5562. case nsTimingFunction::Type::StepEnd:
  5563. nsStyleUtil::AppendStepsTimingFunction(aTimingFunction.mType,
  5564. aTimingFunction.mSteps,
  5565. tmp);
  5566. break;
  5567. default:
  5568. nsStyleUtil::AppendCubicBezierKeywordTimingFunction(aTimingFunction.mType,
  5569. tmp);
  5570. break;
  5571. }
  5572. timingFunction->SetString(tmp);
  5573. aValueList->AppendCSSValue(timingFunction.forget());
  5574. }
  5575. already_AddRefed<CSSValue>
  5576. nsComputedDOMStyle::DoGetTransitionTimingFunction()
  5577. {
  5578. const nsStyleDisplay* display = StyleDisplay();
  5579. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5580. MOZ_ASSERT(display->mTransitionTimingFunctionCount > 0,
  5581. "first item must be explicit");
  5582. uint32_t i = 0;
  5583. do {
  5584. AppendTimingFunction(valueList,
  5585. display->mTransitions[i].GetTimingFunction());
  5586. } while (++i < display->mTransitionTimingFunctionCount);
  5587. return valueList.forget();
  5588. }
  5589. already_AddRefed<CSSValue>
  5590. nsComputedDOMStyle::DoGetAnimationName()
  5591. {
  5592. const nsStyleDisplay* display = StyleDisplay();
  5593. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5594. MOZ_ASSERT(display->mAnimationNameCount > 0,
  5595. "first item must be explicit");
  5596. uint32_t i = 0;
  5597. do {
  5598. const StyleAnimation *animation = &display->mAnimations[i];
  5599. RefPtr<nsROCSSPrimitiveValue> property = new nsROCSSPrimitiveValue;
  5600. const nsString& name = animation->GetName();
  5601. if (name.IsEmpty()) {
  5602. property->SetIdent(eCSSKeyword_none);
  5603. } else {
  5604. nsAutoString escaped;
  5605. nsStyleUtil::AppendEscapedCSSIdent(animation->GetName(), escaped);
  5606. property->SetString(escaped); // really want SetIdent
  5607. }
  5608. valueList->AppendCSSValue(property.forget());
  5609. } while (++i < display->mAnimationNameCount);
  5610. return valueList.forget();
  5611. }
  5612. already_AddRefed<CSSValue>
  5613. nsComputedDOMStyle::DoGetAnimationDelay()
  5614. {
  5615. const nsStyleDisplay* display = StyleDisplay();
  5616. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5617. MOZ_ASSERT(display->mAnimationDelayCount > 0,
  5618. "first item must be explicit");
  5619. uint32_t i = 0;
  5620. do {
  5621. const StyleAnimation *animation = &display->mAnimations[i];
  5622. RefPtr<nsROCSSPrimitiveValue> delay = new nsROCSSPrimitiveValue;
  5623. delay->SetTime((float)animation->GetDelay() / (float)PR_MSEC_PER_SEC);
  5624. valueList->AppendCSSValue(delay.forget());
  5625. } while (++i < display->mAnimationDelayCount);
  5626. return valueList.forget();
  5627. }
  5628. already_AddRefed<CSSValue>
  5629. nsComputedDOMStyle::DoGetAnimationDuration()
  5630. {
  5631. const nsStyleDisplay* display = StyleDisplay();
  5632. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5633. MOZ_ASSERT(display->mAnimationDurationCount > 0,
  5634. "first item must be explicit");
  5635. uint32_t i = 0;
  5636. do {
  5637. const StyleAnimation *animation = &display->mAnimations[i];
  5638. RefPtr<nsROCSSPrimitiveValue> duration = new nsROCSSPrimitiveValue;
  5639. duration->SetTime((float)animation->GetDuration() / (float)PR_MSEC_PER_SEC);
  5640. valueList->AppendCSSValue(duration.forget());
  5641. } while (++i < display->mAnimationDurationCount);
  5642. return valueList.forget();
  5643. }
  5644. already_AddRefed<CSSValue>
  5645. nsComputedDOMStyle::DoGetAnimationTimingFunction()
  5646. {
  5647. const nsStyleDisplay* display = StyleDisplay();
  5648. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5649. MOZ_ASSERT(display->mAnimationTimingFunctionCount > 0,
  5650. "first item must be explicit");
  5651. uint32_t i = 0;
  5652. do {
  5653. AppendTimingFunction(valueList,
  5654. display->mAnimations[i].GetTimingFunction());
  5655. } while (++i < display->mAnimationTimingFunctionCount);
  5656. return valueList.forget();
  5657. }
  5658. already_AddRefed<CSSValue>
  5659. nsComputedDOMStyle::DoGetAnimationDirection()
  5660. {
  5661. const nsStyleDisplay* display = StyleDisplay();
  5662. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5663. MOZ_ASSERT(display->mAnimationDirectionCount > 0,
  5664. "first item must be explicit");
  5665. uint32_t i = 0;
  5666. do {
  5667. const StyleAnimation *animation = &display->mAnimations[i];
  5668. RefPtr<nsROCSSPrimitiveValue> direction = new nsROCSSPrimitiveValue;
  5669. direction->SetIdent(
  5670. nsCSSProps::ValueToKeywordEnum(
  5671. static_cast<int32_t>(animation->GetDirection()),
  5672. nsCSSProps::kAnimationDirectionKTable));
  5673. valueList->AppendCSSValue(direction.forget());
  5674. } while (++i < display->mAnimationDirectionCount);
  5675. return valueList.forget();
  5676. }
  5677. already_AddRefed<CSSValue>
  5678. nsComputedDOMStyle::DoGetAnimationFillMode()
  5679. {
  5680. const nsStyleDisplay* display = StyleDisplay();
  5681. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5682. MOZ_ASSERT(display->mAnimationFillModeCount > 0,
  5683. "first item must be explicit");
  5684. uint32_t i = 0;
  5685. do {
  5686. const StyleAnimation *animation = &display->mAnimations[i];
  5687. RefPtr<nsROCSSPrimitiveValue> fillMode = new nsROCSSPrimitiveValue;
  5688. fillMode->SetIdent(
  5689. nsCSSProps::ValueToKeywordEnum(
  5690. static_cast<int32_t>(animation->GetFillMode()),
  5691. nsCSSProps::kAnimationFillModeKTable));
  5692. valueList->AppendCSSValue(fillMode.forget());
  5693. } while (++i < display->mAnimationFillModeCount);
  5694. return valueList.forget();
  5695. }
  5696. already_AddRefed<CSSValue>
  5697. nsComputedDOMStyle::DoGetAnimationIterationCount()
  5698. {
  5699. const nsStyleDisplay* display = StyleDisplay();
  5700. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5701. MOZ_ASSERT(display->mAnimationIterationCountCount > 0,
  5702. "first item must be explicit");
  5703. uint32_t i = 0;
  5704. do {
  5705. const StyleAnimation *animation = &display->mAnimations[i];
  5706. RefPtr<nsROCSSPrimitiveValue> iterationCount = new nsROCSSPrimitiveValue;
  5707. float f = animation->GetIterationCount();
  5708. float inf = NS_IEEEPositiveInfinity();
  5709. if (f == inf) {
  5710. iterationCount->SetIdent(eCSSKeyword_infinite);
  5711. } else {
  5712. iterationCount->SetNumber(f);
  5713. }
  5714. valueList->AppendCSSValue(iterationCount.forget());
  5715. } while (++i < display->mAnimationIterationCountCount);
  5716. return valueList.forget();
  5717. }
  5718. already_AddRefed<CSSValue>
  5719. nsComputedDOMStyle::DoGetAnimationPlayState()
  5720. {
  5721. const nsStyleDisplay* display = StyleDisplay();
  5722. RefPtr<nsDOMCSSValueList> valueList = GetROCSSValueList(true);
  5723. MOZ_ASSERT(display->mAnimationPlayStateCount > 0,
  5724. "first item must be explicit");
  5725. uint32_t i = 0;
  5726. do {
  5727. const StyleAnimation *animation = &display->mAnimations[i];
  5728. RefPtr<nsROCSSPrimitiveValue> playState = new nsROCSSPrimitiveValue;
  5729. playState->SetIdent(
  5730. nsCSSProps::ValueToKeywordEnum(animation->GetPlayState(),
  5731. nsCSSProps::kAnimationPlayStateKTable));
  5732. valueList->AppendCSSValue(playState.forget());
  5733. } while (++i < display->mAnimationPlayStateCount);
  5734. return valueList.forget();
  5735. }
  5736. static void
  5737. MarkComputedStyleMapDirty(const char* aPref, void* aData)
  5738. {
  5739. static_cast<nsComputedStyleMap*>(aData)->MarkDirty();
  5740. }
  5741. already_AddRefed<CSSValue>
  5742. nsComputedDOMStyle::DoGetCustomProperty(const nsAString& aPropertyName)
  5743. {
  5744. MOZ_ASSERT(nsCSSProps::IsCustomPropertyName(aPropertyName));
  5745. const nsStyleVariables* variables = StyleVariables();
  5746. nsString variableValue;
  5747. const nsAString& name = Substring(aPropertyName,
  5748. CSS_CUSTOM_NAME_PREFIX_LENGTH);
  5749. if (!variables->mVariables.Get(name, variableValue)) {
  5750. return nullptr;
  5751. }
  5752. RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
  5753. val->SetString(variableValue);
  5754. return val.forget();
  5755. }
  5756. void
  5757. nsComputedDOMStyle::ParentChainChanged(nsIContent* aContent)
  5758. {
  5759. NS_ASSERTION(mElement == aContent, "didn't we register mElement?");
  5760. NS_ASSERTION(mResolvedStyleContext,
  5761. "should have only registered an observer when "
  5762. "mResolvedStyleContext is true");
  5763. ClearStyleContext();
  5764. }
  5765. /* static */ nsComputedStyleMap*
  5766. nsComputedDOMStyle::GetComputedStyleMap()
  5767. {
  5768. static nsComputedStyleMap map = {
  5769. {
  5770. #define COMPUTED_STYLE_PROP(prop_, method_) \
  5771. { eCSSProperty_##prop_, &nsComputedDOMStyle::DoGet##method_ },
  5772. #include "nsComputedDOMStylePropertyList.h"
  5773. #undef COMPUTED_STYLE_PROP
  5774. }
  5775. };
  5776. return &map;
  5777. }
  5778. /* static */ void
  5779. nsComputedDOMStyle::RegisterPrefChangeCallbacks()
  5780. {
  5781. // Note that this will register callbacks for all properties with prefs, not
  5782. // just those that are implemented on computed style objects, as it's not
  5783. // easy to grab specific property data from nsCSSPropList.h based on the
  5784. // entries iterated in nsComputedDOMStylePropertyList.h.
  5785. nsComputedStyleMap* data = GetComputedStyleMap();
  5786. #define REGISTER_CALLBACK(pref_) \
  5787. if (pref_[0]) { \
  5788. Preferences::RegisterCallback(MarkComputedStyleMapDirty, pref_, data); \
  5789. }
  5790. #define CSS_PROP(prop_, id_, method_, flags_, pref_, parsevariant_, \
  5791. kwtable_, stylestruct_, stylestructoffset_, animtype_) \
  5792. REGISTER_CALLBACK(pref_)
  5793. #define CSS_PROP_LIST_INCLUDE_LOGICAL
  5794. #include "nsCSSPropList.h"
  5795. #undef CSS_PROP_LIST_INCLUDE_LOGICAL
  5796. #undef CSS_PROP
  5797. #undef REGISTER_CALLBACK
  5798. }
  5799. /* static */ void
  5800. nsComputedDOMStyle::UnregisterPrefChangeCallbacks()
  5801. {
  5802. nsComputedStyleMap* data = GetComputedStyleMap();
  5803. #define UNREGISTER_CALLBACK(pref_) \
  5804. if (pref_[0]) { \
  5805. Preferences::UnregisterCallback(MarkComputedStyleMapDirty, pref_, data); \
  5806. }
  5807. #define CSS_PROP(prop_, id_, method_, flags_, pref_, parsevariant_, \
  5808. kwtable_, stylestruct_, stylestructoffset_, animtype_) \
  5809. UNREGISTER_CALLBACK(pref_)
  5810. #define CSS_PROP_LIST_INCLUDE_LOGICAL
  5811. #include "nsCSSPropList.h"
  5812. #undef CSS_PROP_LIST_INCLUDE_LOGICAL
  5813. #undef CSS_PROP
  5814. #undef UNREGISTER_CALLBACK
  5815. }