Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fdelm.cpp 82KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
  2. *
  3. * Copyright (C) 2000-2011 Opera Software ASA. All rights reserved.
  4. *
  5. * This file is part of the Opera web browser.
  6. * It may not be distributed under any circumstances.
  7. */
  8. #include "core/pch.h"
  9. #include "modules/dochand/fdelm.h"
  10. #include "modules/doc/frm_doc.h"
  11. #include "modules/doc/html_doc.h"
  12. #include "modules/dochand/win.h"
  13. #include "modules/display/prn_dev.h"
  14. #include "modules/probetools/probepoints.h"
  15. #include "modules/dom/domenvironment.h"
  16. #include "modules/dom/domutils.h"
  17. #include "modules/hardcore/mh/constant.h"
  18. #include "modules/pi/ui/OpUiInfo.h"
  19. #ifdef SVG_SUPPORT
  20. # include "modules/svg/SVGManager.h"
  21. # include "modules/svg/svg_image.h"
  22. #endif // SVG_SUPPORT
  23. #ifdef NEARBY_INTERACTIVE_ITEM_DETECTION
  24. # include "modules/widgets/OpScrollbar.h"
  25. #endif // NEARBY_INTERACTIVE_ITEM_DETECTION
  26. #include "modules/prefs/prefsmanager/collections/pc_display.h"
  27. #include "modules/security_manager/include/security_manager.h"
  28. void FramesDocElm::SetFrameScrolling(BYTE scrolling)
  29. {
  30. frame_scrolling = scrolling;
  31. }
  32. void FramesDocElm::Reset(int type, int val, FramesDocElm* parent_frmset, HTML_Element *helm)
  33. {
  34. frame_spacing = 0;
  35. SetFrameBorder(TRUE);
  36. SetFrameBorders(FALSE, FALSE, FALSE, FALSE);
  37. BOOL normal_frames_mode = !GetParentFramesDoc()->GetSmartFrames() && !GetParentFramesDoc()->GetFramesStacked();
  38. if (!helm)
  39. helm = GetHtmlElement();
  40. if (helm)
  41. {
  42. SetIsFrameset(helm->IsMatchingType(HE_FRAMESET, NS_HTML));
  43. SetFrameNoresize(IsFrameset() || helm->GetFrameNoresize());
  44. SetFrameScrolling(helm->GetFrameScrolling());
  45. /* Images should never have scrollbars. If this is a pseudo iframe used
  46. to implement for instance an SVG image in an IMG element, then make
  47. sure we don't display any scrollbars in it. */
  48. if (helm->IsMatchingType(HE_IMG, NS_HTML))
  49. frame_scrolling = SCROLLING_NO;
  50. frame_margin_width = helm->GetFrameMarginWidth();
  51. frame_margin_height = helm->GetFrameMarginHeight();
  52. BOOL check_parent_frame_border = TRUE;
  53. short frame_spacing_attr = ATTR_FRAMESPACING;
  54. if (!helm->HasAttr(ATTR_FRAMESPACING))
  55. {
  56. if (helm->HasAttr(ATTR_BORDER))
  57. frame_spacing_attr = ATTR_BORDER;
  58. else
  59. frame_spacing_attr = 0;
  60. }
  61. if (frame_spacing_attr)
  62. {
  63. frame_spacing = helm->GetNumAttr(frame_spacing_attr);
  64. if (frame_spacing == 0)
  65. {
  66. SetFrameBorder(FALSE);
  67. check_parent_frame_border = FALSE;
  68. }
  69. }
  70. else if (parent_frmset)
  71. frame_spacing = parent_frmset->GetFrameSpacing();
  72. else
  73. frame_spacing = FRAME_BORDER_SIZE;
  74. if (helm->HasAttr(ATTR_FRAMEBORDER))
  75. SetFrameBorder(helm->GetBoolAttr(ATTR_FRAMEBORDER));
  76. else if (check_parent_frame_border && parent_frmset)
  77. SetFrameBorder(parent_frmset->GetFrameBorder());
  78. }
  79. else
  80. {
  81. SetIsFrameset(TRUE);
  82. SetFrameNoresize(TRUE);
  83. frame_scrolling = SCROLLING_AUTO;
  84. frame_margin_width = 0;
  85. frame_margin_height = 0;
  86. //frameset_border = 0;
  87. }
  88. pos.SetTranslation(0, 0);
  89. width = 0;
  90. height = 0;
  91. packed1.size_type = type;
  92. size_val = val;
  93. SetIsRow(TRUE);
  94. if (frm_dev)
  95. frm_dev->SetScrollType(normal_frames_mode ? (VisualDevice::ScrollType) frame_scrolling : VisualDevice::VD_SCROLLING_NO);
  96. }
  97. void FramesDocElm::CheckSpecialObject(HTML_Element* he)
  98. {
  99. if (he && he->IsMatchingType(HE_OBJECT, NS_HTML))
  100. {
  101. const uni_char* class_id = he->GetStringAttr(ATTR_CLASSID);
  102. if (class_id && uni_stri_eq(class_id, "HTTP://WWW.OPERA.COM/ERA"))
  103. {
  104. for (HTML_Element* child = he->FirstChild(); child; child = child->Suc())
  105. if (child->IsMatchingType(HE_PARAM, NS_HTML))
  106. {
  107. const uni_char* param_name = child->GetPARAM_Name();
  108. if (param_name && uni_stri_eq(param_name, "RM"))
  109. {
  110. packed1.special_object = 1;
  111. packed1.special_object_layout_mode = LAYOUT_NORMAL;
  112. const uni_char* param_value = child->GetPARAM_Value();
  113. if (param_value)
  114. {
  115. if (uni_stri_eq(param_value, "1"))
  116. packed1.special_object_layout_mode = LAYOUT_SSR;
  117. else
  118. if (uni_stri_eq(param_value, "2"))
  119. packed1.special_object_layout_mode = LAYOUT_CSSR;
  120. else
  121. if (uni_stri_eq(param_value, "3"))
  122. packed1.special_object_layout_mode = LAYOUT_AMSR;
  123. else
  124. if (uni_stri_eq(param_value, "4"))
  125. packed1.special_object_layout_mode = LAYOUT_MSR;
  126. #ifdef TV_RENDERING
  127. else
  128. if (uni_stri_eq(param_value, "5"))
  129. packed1.special_object_layout_mode = LAYOUT_TVR;
  130. #endif // TV_RENDERING
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. /*virtual*/ void FramesDocElm::FDEElmRef::OnDelete(FramesDocument *document)
  138. {
  139. m_fde->DetachHtmlElement();
  140. if (m_fde->IsInlineFrame() && (!document || !document->IsPrintCopyBeingDeleted()))
  141. {
  142. m_fde->Out();
  143. FramesDocument *doc = m_fde->GetCurrentDoc();
  144. /* This function might be called from a script executing in
  145. the iframe or during reflow, in which case the iframe must be
  146. deleted later. */
  147. if (document && doc && (doc->IsESActive(TRUE) || doc->IsReflowing()))
  148. document->DeleteIFrame(m_fde);
  149. else
  150. OP_DELETE(m_fde);
  151. }
  152. }
  153. FramesDocElm::FramesDocElm(int id, int x, int y, int w, int h, FramesDocument* frm_doc, HTML_Element* he, VisualDevice* vd, int type, int val, BOOL inline_frm, FramesDocElm* parent_frmset, BOOL secondary) : m_helm(this)
  154. {
  155. OP_ASSERT(frm_doc);
  156. OP_ASSERT(!he || he->GetInserted() != HE_INSERTED_BY_PARSE_AHEAD);
  157. packed1_init = 0;
  158. parent_frm_doc = frm_doc;
  159. parent_layout_input_ctx = NULL;
  160. packed1.is_inline = inline_frm;
  161. packed1.is_in_doc_coords = inline_frm;
  162. packed1.is_secondary = secondary;
  163. packed1.normal_row = TRUE;
  164. sub_win_id = id;
  165. doc_manager = NULL;
  166. frm_dev = NULL;
  167. if (he && !secondary)
  168. {
  169. #ifdef _DEBUG
  170. OP_ASSERT(FramesDocElm::GetFrmDocElmByHTML(he) == NULL || !"The element we create a FramesDocElm for already has a FramesDocElm. Doh");
  171. #endif // _DEBUG
  172. CheckSpecialObject(he);
  173. }
  174. #ifdef _PRINT_SUPPORT_
  175. m_print_twin_elm = NULL;
  176. #endif // _PRINT_SUPPORT_
  177. Reset(type, val, parent_frmset, he);
  178. /* FIXME: VIEWPORT_SUPPORT should make sure that the following coordinates
  179. are scaled according to IsInDocCoords() (if anyone cares, that is). */
  180. pos.SetTranslation(x, y);
  181. width = w;
  182. height = h;
  183. #ifndef MOUSELESS
  184. drag_val = 0;
  185. drag_offset = 0;
  186. #endif // !MOUSELESS
  187. normal_width = w;
  188. normal_height = h;
  189. reinit_data = NULL;
  190. // turn off scrolling if this is a frame generated by an object element in mail window
  191. if (he && inline_frm && he->IsMatchingType(HE_OBJECT, NS_HTML) && vd && vd->GetWindow()->IsMailOrNewsfeedWindow())
  192. frame_scrolling = SCROLLING_NO;
  193. frame_index = FRAME_NOT_IN_ROOT;
  194. }
  195. FramesDocElm::~FramesDocElm()
  196. {
  197. packed1.is_being_deleted = TRUE;
  198. FramesDocument* top_doc = parent_frm_doc->GetTopDocument();
  199. top_doc->FramesDocElmDeleted(this);
  200. parent_frm_doc->GetMessageHandler()->UnsetCallBack(parent_frm_doc, MSG_REINIT_FRAME, (MH_PARAM_1) this);
  201. RemoveReinitData();
  202. if (m_helm.GetElm())
  203. DetachHtmlElement();
  204. OP_DELETE(doc_manager);
  205. OP_DELETE(frm_dev);
  206. }
  207. AffinePos FramesDocElm::ToDocIfScreen(const AffinePos& val) const
  208. {
  209. if (IsInDocCoords())
  210. return val;
  211. else
  212. {
  213. VisualDevice* vis_dev = doc_manager->GetWindow()->VisualDev();
  214. return vis_dev->ScaleToDoc(val);
  215. }
  216. }
  217. int FramesDocElm::ToDocIfScreen(int val, BOOL round_up) const
  218. {
  219. if (IsInDocCoords())
  220. return val;
  221. else
  222. {
  223. VisualDevice* vis_dev = doc_manager->GetWindow()->VisualDev();
  224. int result = vis_dev->ScaleToDoc(val);
  225. if (round_up)
  226. result = vis_dev->ApplyScaleRoundingNearestUp(result);
  227. return result;
  228. }
  229. }
  230. int FramesDocElm::ToScreenIfScreen(int val, BOOL round_up) const
  231. {
  232. if (IsInDocCoords())
  233. return val;
  234. else
  235. {
  236. VisualDevice* vis_dev = doc_manager->GetWindow()->VisualDev();
  237. int result = vis_dev->ScaleToScreen(val);
  238. if (round_up)
  239. result = vis_dev->ApplyScaleRoundingNearestUp(result);
  240. return result;
  241. }
  242. }
  243. AffinePos FramesDocElm::GetDocOrScreenAbsPos() const
  244. {
  245. if (Parent() && Parent()->Parent())
  246. {
  247. AffinePos parent_pos = Parent()->GetDocOrScreenAbsPos();
  248. parent_pos.Append(pos);
  249. return parent_pos;
  250. }
  251. return pos;
  252. }
  253. int FramesDocElm::GetDocOrScreenAbsX() const
  254. {
  255. OpPoint abs_pos = GetDocOrScreenAbsPos().GetTranslation();
  256. return abs_pos.x;
  257. }
  258. int FramesDocElm::GetDocOrScreenAbsY() const
  259. {
  260. OpPoint abs_pos = GetDocOrScreenAbsPos().GetTranslation();
  261. return abs_pos.y;
  262. }
  263. AffinePos FramesDocElm::GetPos() const
  264. {
  265. return ToDocIfScreen(pos);
  266. }
  267. int FramesDocElm::GetX() const
  268. {
  269. return ToDocIfScreen(pos.GetTranslation().x, FALSE);
  270. }
  271. int FramesDocElm::GetY() const
  272. {
  273. return ToDocIfScreen(pos.GetTranslation().y, FALSE);
  274. }
  275. void FramesDocElm::SetX(int x)
  276. {
  277. OpPoint new_pos = pos.GetTranslation();
  278. new_pos.x = ToScreenIfScreen(x, FALSE);
  279. pos.SetTranslation(new_pos.x, new_pos.y);
  280. }
  281. void FramesDocElm::SetY(int y)
  282. {
  283. OpPoint new_pos = pos.GetTranslation();
  284. new_pos.y = ToScreenIfScreen(y, FALSE);
  285. pos.SetTranslation(new_pos.x, new_pos.y);
  286. }
  287. OP_STATUS FramesDocElm::Init(HTML_Element *helm, VisualDevice* vd, OpView* clipview)
  288. {
  289. /* NOTE: GetHtmlElement() will return NULL for the secondary objects
  290. created per row in BuildTree() if both rows and cols attributes were
  291. specified. This is fully compatible with what this function currently
  292. uses 'helm' for, but beware when changing this function! */
  293. if (helm)
  294. {
  295. OP_ASSERT(!packed1.is_secondary);
  296. SetHtmlElement(helm);
  297. RETURN_IF_ERROR(SetName(helm->GetStringAttr(ATTR_NAME)));
  298. RETURN_IF_MEMORY_ERROR(frame_id.Set(helm->GetId()));
  299. }
  300. doc_manager = OP_NEW(DocumentManager, (parent_frm_doc->GetWindow(), this, parent_frm_doc));
  301. if (!doc_manager || OpStatus::IsMemoryError(doc_manager->Construct()))
  302. return OpStatus::ERR_NO_MEMORY;
  303. if (vd && helm && helm->Type() != HE_FRAMESET
  304. #ifdef _PRINT_SUPPORT_
  305. && !vd->IsPrinter()
  306. #endif
  307. )
  308. {
  309. VisualDevice::ScrollType scroll_type = (VisualDevice::ScrollType) frame_scrolling;
  310. if (GetParentFramesDoc()->GetFramesStacked())
  311. scroll_type = VisualDevice::VD_SCROLLING_NO;
  312. if (!IsInlineFrame() && GetParentFramesDoc()->GetSmartFrames())
  313. scroll_type = VisualDevice::VD_SCROLLING_NO;
  314. OP_STATUS result = vd->GetNewVisualDevice(frm_dev, doc_manager, scroll_type, vd->GetView());
  315. if (OpStatus::IsError(result))
  316. return result;
  317. doc_manager->SetVisualDevice(frm_dev);
  318. BOOL hide = FALSE;
  319. # ifdef _PRINT_SUPPORT_
  320. // In preview mode we don't want more than one visible visual device,
  321. // otherwise the frames will not be shown, since we only use one
  322. // visual device for drawing even if there are frames in the document.
  323. if (vd->GetWindow()->GetPreviewMode()) //rg test with printing from preview.
  324. hide = TRUE;
  325. # endif // _PRINT_SUPPORT_
  326. // Have to set IFRAMES as hidden by default because they are not hidden until
  327. // formatting is done. For empty IFRAMES with "visibility: hidden" formatting will
  328. // never be done.
  329. if (helm->IsMatchingType(HE_IFRAME, NS_HTML) && frm_dev)
  330. hide = TRUE;
  331. if (hide)
  332. Hide(FALSE);
  333. }
  334. else
  335. frm_dev = NULL;
  336. return OpStatus::OK;
  337. }
  338. #ifndef MOUSELESS
  339. FramesDocElm* FramesDocElm::IsSeparator(int x, int y/*, int border*/)
  340. {
  341. FramesDocument* doc = doc_manager->GetCurrentDoc();
  342. if (doc)
  343. {
  344. if (doc->IsFrameDoc())
  345. {
  346. FramesDocElm* fde = doc->GetFrmDocRoot();
  347. if (fde)
  348. return fde->IsSeparator(x, y/*, fde->Border()*/);
  349. }
  350. return 0;
  351. }
  352. else
  353. {
  354. FramesDocElm* fde = FirstChild();
  355. while (fde)
  356. {
  357. if (IsRow())
  358. {
  359. if (y > fde->GetY() && y < fde->GetY() + fde->GetHeight())
  360. return fde->IsSeparator(x, y - fde->GetY());
  361. }
  362. else
  363. if (x > fde->GetX() && x < fde->GetX() + fde->GetWidth())
  364. return fde->IsSeparator(x - fde->GetX(), y);
  365. FramesDocElm* prev_fde = fde->Pred();
  366. if (prev_fde && prev_fde->CanResize() && fde->CanResize())
  367. {
  368. if (IsRow())
  369. {
  370. if (y <= fde->GetY() && y >= prev_fde->GetY() + prev_fde->GetHeight())
  371. return fde;
  372. }
  373. else
  374. if (x <= fde->GetX() && x >= prev_fde->GetX() + prev_fde->GetWidth())
  375. return fde;
  376. }
  377. fde = fde->Suc();
  378. }
  379. }
  380. return 0;
  381. }
  382. void FramesDocElm::StartMoveSeparator(int x, int y)
  383. {
  384. FramesDocElm* prnt = Parent();
  385. if (!prnt)
  386. return;
  387. int border = 0;
  388. FramesDocElm* prev_fde = Pred();
  389. if (prnt->IsRow())
  390. {
  391. if (prev_fde)
  392. border = GetY() - prev_fde->GetY() - prev_fde->GetHeight();
  393. drag_val = GetAbsY() - border;
  394. drag_offset = drag_val - y;
  395. }
  396. else
  397. {
  398. if (prev_fde)
  399. border = GetX() - prev_fde->GetX() - prev_fde->GetWidth();
  400. drag_val = GetAbsX() - border;
  401. drag_offset = drag_val - x;
  402. }
  403. MoveSeparator(x, y);
  404. }
  405. void FramesDocElm::MoveSeparator(int x, int y)
  406. {
  407. FramesDocElm* prnt = Parent();
  408. if (!prnt)
  409. return;
  410. int border = 0;
  411. FramesDocElm* fde = Pred();
  412. if (prnt->IsRow())
  413. {
  414. if (fde)
  415. border = GetY() - fde->GetY() - fde->GetHeight();
  416. int prnt_absy = prnt->GetAbsY();
  417. int use_y = y - prnt_absy + drag_offset;
  418. if (use_y < GetY())
  419. {
  420. // check min pos
  421. fde = Pred();
  422. if (fde)
  423. {
  424. int p_min_y = fde->GetMinHeight() + fde->GetY() + border;
  425. if (use_y < p_min_y)
  426. use_y = p_min_y;
  427. }
  428. else
  429. if (use_y < 0)
  430. use_y = 0;
  431. }
  432. else
  433. if (use_y > GetY())
  434. {
  435. // check max pos
  436. int max_y = GetMaxY() - border;
  437. if (use_y > max_y)
  438. use_y = max_y;
  439. }
  440. if (use_y != GetY())
  441. {
  442. drag_val = prnt_absy + use_y;
  443. Reformat(x, y + drag_offset);
  444. }
  445. }
  446. else
  447. {
  448. if (fde)
  449. border = GetX() - fde->GetX() - fde->GetWidth();
  450. int prnt_absx = prnt->GetAbsX();
  451. int use_x = x - prnt_absx + drag_offset;
  452. if (use_x < GetX())
  453. {
  454. // check min pos
  455. fde = Pred();
  456. if (fde)
  457. {
  458. int p_min_x = fde->GetMinWidth() + fde->GetX() + border;
  459. if (use_x < p_min_x)
  460. use_x = p_min_x;
  461. }
  462. else
  463. if (use_x < 0)
  464. use_x = 0;
  465. }
  466. else
  467. if (use_x > GetX())
  468. {
  469. // check max pos
  470. int max_x = GetMaxX() - border;
  471. if (use_x > max_x)
  472. use_x = max_x;
  473. }
  474. if (use_x != GetX())
  475. {
  476. drag_val = prnt_absx + use_x;
  477. Reformat(x + drag_offset, y);
  478. }
  479. }
  480. }
  481. void FramesDocElm::Reformat(int x, int y)
  482. {
  483. FramesDocElm* prnt = Parent();
  484. if (!prnt)
  485. return;
  486. int border = 0;
  487. FramesDocElm* prev_fde = Pred();
  488. if (prev_fde)
  489. {
  490. if (prnt->IsRow())
  491. border = GetY() - prev_fde->GetY() - prev_fde->GetHeight();
  492. else
  493. border = GetX() - prev_fde->GetX() - prev_fde->GetWidth();
  494. }
  495. if (prnt->IsRow())
  496. SetY(drag_val - prnt->GetAbsY() + border);
  497. else
  498. SetX(drag_val - prnt->GetAbsX() + border);
  499. // set new width if changed
  500. BOOL reformat = FALSE;
  501. if (prnt->IsRow())
  502. {
  503. int new_height;
  504. if (Suc())
  505. new_height = Suc()->GetY() - GetY() - border;
  506. else
  507. new_height = prnt->GetHeight() - GetY();
  508. if (new_height != GetHeight())
  509. {
  510. reformat = TRUE;
  511. SetGeometry(GetPos(), GetWidth(), new_height);
  512. if (prev_fde)
  513. prev_fde->SetGeometry(prev_fde->GetPos(), prev_fde->GetWidth(), GetY() - prev_fde->GetY() - border);
  514. }
  515. }
  516. else
  517. {
  518. int new_width;
  519. if (Suc())
  520. new_width = Suc()->GetX() - GetX() - border;
  521. else
  522. new_width = prnt->GetWidth() - GetX();
  523. if (new_width != GetWidth())
  524. {
  525. reformat = TRUE;
  526. SetGeometry(GetPos(), new_width, GetHeight());
  527. if (prev_fde)
  528. prev_fde->SetGeometry(prev_fde->GetPos(), GetX() - prev_fde->GetX() - border, prev_fde->GetHeight());
  529. }
  530. }
  531. // propagate sizes and reformat this and previous frame if necessary
  532. if (reformat)
  533. {
  534. OP_STATUS status = OpStatus::OK;
  535. OpStatus::Ignore(status);
  536. if (prev_fde)
  537. {
  538. prev_fde->PropagateSizeChanges(FALSE, !prnt->IsRow(), FALSE, prnt->IsRow()/*, border*/);
  539. // Make sure that changes are propagated to hidden children
  540. if (prev_fde->GetCurrentDoc())
  541. {
  542. if (prev_fde->FormatFrames(prnt->IsRow(), !prnt->IsRow()) == OpStatus::ERR_NO_MEMORY)
  543. status = OpStatus::ERR_NO_MEMORY;
  544. }
  545. }
  546. PropagateSizeChanges(!prnt->IsRow(), FALSE, prnt->IsRow(), FALSE/*, border*/);
  547. FramesDocument* doc = GetCurrentDoc();
  548. // Make sure that changes are propagated to hidden children
  549. if (doc)
  550. {
  551. if (FormatFrames(prnt->IsRow(), !prnt->IsRow()) == OpStatus::ERR_NO_MEMORY)
  552. status = OpStatus::ERR_NO_MEMORY;
  553. }
  554. while (prnt->Parent())
  555. prnt = prnt->Parent();
  556. if (status == OpStatus::ERR_NO_MEMORY)
  557. GetWindow()->RaiseCondition(status);
  558. }
  559. }
  560. void FramesDocElm::EndMoveSeparator(int x, int y) //, int border)
  561. {
  562. FramesDocElm* prnt = Parent();
  563. if (!prnt)
  564. return;
  565. Reformat(x, y);
  566. }
  567. BOOL FramesDocElm::CanResize()
  568. {
  569. BOOL can_resize = TRUE;
  570. FramesDocElm* fde = FirstChild();
  571. if (fde)
  572. {
  573. while (can_resize && fde)
  574. {
  575. can_resize = fde->CanResize();
  576. fde = fde->Suc();
  577. }
  578. }
  579. else
  580. can_resize = !GetFrameNoresize();
  581. return can_resize;
  582. }
  583. int FramesDocElm::GetMaxX()
  584. {
  585. int max_x = GetWidth();
  586. FramesDocElm* fde = FirstChild();
  587. if (IsRow())
  588. {
  589. while (fde)
  590. {
  591. int x = fde->GetMaxX();
  592. if (x < max_x)
  593. max_x = x;
  594. fde = fde->Suc();
  595. }
  596. }
  597. else
  598. if (fde)
  599. max_x = fde->GetMaxX();
  600. return max_x + GetX();
  601. }
  602. int FramesDocElm::GetMaxY()
  603. {
  604. int max_y = GetHeight();
  605. FramesDocElm* fde = FirstChild();
  606. if (!IsRow())
  607. {
  608. while (fde)
  609. {
  610. int y = fde->GetMaxY();
  611. if (y < max_y)
  612. max_y = y;
  613. fde = fde->Suc();
  614. }
  615. }
  616. else
  617. if (fde)
  618. max_y = fde->GetMaxY();
  619. return max_y + GetY();
  620. }
  621. int FramesDocElm::GetMinWidth()
  622. {
  623. int min_w = 0;
  624. FramesDocElm* fde = FirstChild();
  625. if (IsRow())
  626. {
  627. while (fde)
  628. {
  629. int w = fde->GetMinWidth();
  630. if (w > min_w)
  631. min_w = w;
  632. fde = fde->Suc();
  633. }
  634. }
  635. else
  636. if (fde)
  637. min_w = fde->GetMinWidth();
  638. return min_w;
  639. }
  640. int FramesDocElm::GetMinHeight()
  641. {
  642. int min_h = 0;
  643. FramesDocElm* fde = FirstChild();
  644. if (!IsRow())
  645. {
  646. while (fde)
  647. {
  648. int h = fde->GetMinHeight();
  649. if (h > min_h)
  650. min_h = h;
  651. fde = fde->Suc();
  652. }
  653. }
  654. else
  655. if (fde)
  656. min_h = fde->GetMinHeight();
  657. return min_h;
  658. }
  659. #endif // !MOUSELESS
  660. BOOL FramesDocElm::IsInDocCoords() const
  661. {
  662. if (packed1.is_in_doc_coords)
  663. return TRUE;
  664. return doc_manager->GetWindow()->GetTrueZoom();
  665. }
  666. AffinePos FramesDocElm::GetAbsPos() const
  667. {
  668. return ToDocIfScreen(GetDocOrScreenAbsPos());
  669. }
  670. int FramesDocElm::GetAbsX() const
  671. {
  672. return ToDocIfScreen(GetDocOrScreenAbsX(), FALSE);
  673. }
  674. int FramesDocElm::GetAbsY() const
  675. {
  676. return ToDocIfScreen(GetDocOrScreenAbsY(), FALSE);
  677. }
  678. int FramesDocElm::GetWidth() const
  679. {
  680. return ToDocIfScreen(width, TRUE);
  681. }
  682. int FramesDocElm::GetHeight() const
  683. {
  684. return ToDocIfScreen(height, TRUE);
  685. }
  686. int FramesDocElm::GetNormalWidth() const
  687. {
  688. return ToDocIfScreen(normal_width, TRUE);
  689. }
  690. int FramesDocElm::GetNormalHeight() const
  691. {
  692. return ToDocIfScreen(normal_height, TRUE);
  693. }
  694. void FramesDocElm::SetPosition(const AffinePos& doc_pos)
  695. {
  696. if (IsInDocCoords())
  697. {
  698. pos = doc_pos;
  699. }
  700. else
  701. {
  702. VisualDevice* vis_dev = GetWindow()->VisualDev();
  703. pos = vis_dev->ScaleToScreen(doc_pos);
  704. }
  705. UpdateGeometry();
  706. }
  707. void FramesDocElm::SetSize(int w, int h)
  708. {
  709. if (IsInDocCoords())
  710. {
  711. width = w;
  712. height = h;
  713. normal_width = w;
  714. normal_height = h;
  715. }
  716. else
  717. {
  718. VisualDevice* vis_dev = GetWindow()->VisualDev();
  719. width = vis_dev->ScaleToScreen(w);
  720. height = vis_dev->ScaleToScreen(h);
  721. normal_width = vis_dev->ScaleToScreen(w);
  722. normal_height = vis_dev->ScaleToScreen(h);
  723. }
  724. if (FramesDocument* doc = GetCurrentDoc())
  725. doc->RecalculateLayoutViewSize(TRUE); // FIXME: assuming "user action"
  726. UpdateGeometry();
  727. }
  728. void FramesDocElm::SetGeometry(const AffinePos& doc_pos, int w, int h)
  729. {
  730. if (IsInDocCoords())
  731. {
  732. pos = doc_pos;
  733. width = w;
  734. height = h;
  735. normal_width = w;
  736. normal_height = h;
  737. }
  738. else
  739. {
  740. VisualDevice* vis_dev = GetWindow()->VisualDev();
  741. pos = vis_dev->ScaleToScreen(doc_pos);
  742. width = vis_dev->ScaleToScreen(w);
  743. height = vis_dev->ScaleToScreen(h);
  744. normal_width = vis_dev->ScaleToScreen(w);
  745. normal_height = vis_dev->ScaleToScreen(h);
  746. }
  747. if (FramesDocument* doc = GetCurrentDoc())
  748. doc->RecalculateLayoutViewSize(TRUE); // FIXME: assuming "user action"
  749. UpdateGeometry();
  750. }
  751. void FramesDocElm::ForceHeight(int h)
  752. {
  753. if (IsInDocCoords())
  754. height = h;
  755. else
  756. {
  757. VisualDevice* vis_dev = GetWindow()->VisualDev();
  758. height = vis_dev->ScaleToScreen(h);
  759. }
  760. UpdateGeometry();
  761. }
  762. OP_STATUS FramesDocElm::ShowFrames()
  763. {
  764. if (frm_dev)
  765. {
  766. BOOL update_scrollbar = !frm_dev->GetVisible();
  767. RETURN_IF_ERROR(Show());
  768. #ifdef SVG_SUPPORT
  769. SVGCheckWantMouseEvents();
  770. #endif // SVG_SUPPORT
  771. if (update_scrollbar)
  772. frm_dev->UpdateScrollbars();
  773. }
  774. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  775. RETURN_IF_ERROR(fde->ShowFrames());
  776. return OpStatus::OK;
  777. }
  778. void FramesDocElm::HideFrames()
  779. {
  780. Hide(FALSE);
  781. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  782. fde->HideFrames();
  783. }
  784. void FramesDocElm::UpdateGeometry()
  785. {
  786. if (frm_dev)
  787. {
  788. VisualDevice* parent_vd = GetParentFramesDoc()->GetVisualDevice();
  789. OP_ASSERT(parent_vd);
  790. if (!parent_vd)
  791. return;
  792. int view_x = parent_vd->ScaleToScreen(parent_vd->GetRenderingViewX());
  793. int view_y = parent_vd->ScaleToScreen(parent_vd->GetRenderingViewY());
  794. int old_rendering_width = frm_dev->GetRenderingViewWidth();
  795. int old_rendering_height = frm_dev->GetRenderingViewHeight();
  796. AffinePos doc_or_screen_pos = GetDocOrScreenAbsPos();
  797. AffinePos screen_pos;
  798. int width_screen_coords;
  799. int height_screen_coords;
  800. if (IsInDocCoords())
  801. {
  802. screen_pos = frm_dev->ScaleToScreen(doc_or_screen_pos);
  803. #ifdef CSS_TRANSFORMS
  804. // If page is zoomed, we don't want to apply the
  805. // zoom/scalefactor to the width/height, but to the
  806. // transform.
  807. if (screen_pos.IsTransform())
  808. {
  809. width_screen_coords = width;
  810. height_screen_coords = height;
  811. }
  812. else
  813. #endif // CSS_TRANSFORMS
  814. {
  815. width_screen_coords = frm_dev->ScaleToScreen(width);
  816. height_screen_coords = frm_dev->ScaleToScreen(height);
  817. }
  818. }
  819. else
  820. {
  821. screen_pos = doc_or_screen_pos;
  822. width_screen_coords = width;
  823. height_screen_coords = height;
  824. }
  825. AffinePos view_ctm(-view_x, -view_y);
  826. screen_pos.Prepend(view_ctm);
  827. frm_dev->SetRenderingViewGeometryScreenCoords(screen_pos,
  828. width_screen_coords,
  829. height_screen_coords);
  830. if (FramesDocument* doc = GetCurrentDoc())
  831. if (old_rendering_width != frm_dev->GetRenderingViewWidth() || old_rendering_height != frm_dev->GetRenderingViewHeight())
  832. if (g_pcdisplay->GetIntegerPref(PrefsCollectionDisplay::ShowActiveFrame, doc->GetHostName()))
  833. {
  834. DocumentManager* top_doc_man = doc_manager->GetWindow()->DocManager();
  835. if (FramesDocument* top_frames_doc = top_doc_man->GetCurrentDoc())
  836. if (FramesDocument* active_doc = top_frames_doc->GetActiveSubDoc())
  837. if (active_doc == doc)
  838. // Make sure that the frame border is updated.
  839. frm_dev->UpdateAll();
  840. }
  841. }
  842. }
  843. FramesDocElm* FramesDocElm::Parent() const
  844. {
  845. if (packed1.is_deleted)
  846. return NULL;
  847. return (FramesDocElm *) Tree::Parent();
  848. }
  849. #ifndef MOUSELESS
  850. void FramesDocElm::PropagateSizeChanges(BOOL left, BOOL right, BOOL top, BOOL bottom/*, int border*/)
  851. {
  852. FramesDocument* doc = doc_manager->GetCurrentDoc();
  853. if (!doc)
  854. {
  855. FramesDocElm* fde, *prev_fde;
  856. if (IsRow())
  857. {
  858. if (bottom)
  859. {
  860. // update last child height
  861. fde = LastChild();
  862. if (fde)
  863. if (fde->GetHeight() != GetHeight() - fde->GetY())
  864. {
  865. fde->SetGeometry(fde->GetPos(), fde->GetWidth(), GetHeight() - fde->GetY());
  866. fde->PropagateSizeChanges(left, right, top, bottom);
  867. }
  868. }
  869. else
  870. if (top)
  871. {
  872. // update all child y pos
  873. prev_fde = 0;
  874. for (fde = LastChild(); fde; fde = fde->Pred())
  875. {
  876. int old_h = fde->GetHeight();
  877. int new_h = old_h;
  878. if (!fde->Pred())
  879. {
  880. // update first child y pos and height
  881. fde->SetY(0);
  882. if (prev_fde)
  883. new_h = prev_fde->GetY() - GetFrameSpacing();
  884. else
  885. new_h = GetHeight();
  886. }
  887. else
  888. if (prev_fde)
  889. fde->SetY(prev_fde->GetY() - fde->GetHeight() - GetFrameSpacing());
  890. else
  891. fde->SetY(GetHeight() - fde->GetHeight());
  892. if (old_h != new_h)
  893. {
  894. fde->SetSize(fde->GetWidth(), new_h);
  895. fde->PropagateSizeChanges(left, right, top, bottom);
  896. }
  897. prev_fde = fde;
  898. }
  899. }
  900. else
  901. if (left || right)
  902. for (fde = FirstChild(); fde; fde = fde->Suc())
  903. {
  904. if (fde->GetWidth() == GetWidth())
  905. break; // all widths equal
  906. // update all child width
  907. fde->SetSize(GetWidth(), fde->GetHeight());
  908. fde->PropagateSizeChanges(left, right, top, bottom);
  909. }
  910. }
  911. else
  912. {
  913. if (right)
  914. {
  915. // update last child width
  916. fde = LastChild();
  917. if (fde)
  918. if (fde->GetWidth() != GetWidth() - fde->GetX())
  919. {
  920. fde->SetSize(GetWidth() - fde->GetX(), fde->GetHeight());
  921. fde->PropagateSizeChanges(left, right, top, bottom);
  922. }
  923. }
  924. else
  925. if (left)
  926. {
  927. // update all child x pos
  928. prev_fde = 0;
  929. for (fde = LastChild(); fde; fde = fde->Pred())
  930. {
  931. int old_w = fde->GetWidth();
  932. int new_w = old_w;
  933. if (!fde->Pred())
  934. {
  935. // update first child x pos and width
  936. fde->SetX(0);
  937. if (prev_fde)
  938. new_w = prev_fde->GetX() - GetFrameSpacing();
  939. else
  940. new_w = GetWidth();
  941. }
  942. else
  943. if (prev_fde)
  944. fde->SetX(prev_fde->GetX() - fde->GetWidth() - GetFrameSpacing());
  945. else
  946. fde->SetX(GetWidth() - fde->GetWidth());
  947. if (old_w != new_w)
  948. {
  949. fde->SetSize(new_w, fde->GetHeight());
  950. fde->PropagateSizeChanges(left, right, top, bottom);
  951. }
  952. prev_fde = fde;
  953. }
  954. }
  955. else
  956. if (top || bottom)
  957. for (fde = FirstChild(); fde; fde = fde->Suc())
  958. {
  959. if (fde->GetHeight() == GetHeight())
  960. break; // all heights equal
  961. // update all child height
  962. fde->SetSize(fde->GetWidth(), GetHeight());
  963. fde->PropagateSizeChanges(left, right, top, bottom);
  964. }
  965. }
  966. }
  967. }
  968. #endif // !MOUSELESS
  969. DocListElm* FramesDocElm::GetHistoryElmAt(int pos, BOOL forward)
  970. {
  971. if (doc_manager)
  972. {
  973. DocListElm *tmp_dle = doc_manager->CurrentDocListElm();
  974. if (tmp_dle)
  975. {
  976. if (forward)
  977. {
  978. while (tmp_dle && tmp_dle->Number() < pos)
  979. tmp_dle = tmp_dle->Suc();
  980. }
  981. else // forward
  982. {
  983. while (tmp_dle && tmp_dle->Number() > pos)
  984. tmp_dle = tmp_dle->Pred();
  985. }
  986. if (tmp_dle)
  987. {
  988. if (tmp_dle->Number() == pos)
  989. return tmp_dle;
  990. else
  991. return tmp_dle->Doc()->GetHistoryElmAt(pos, forward);
  992. }
  993. }
  994. FramesDocElm *tmp_fde = FirstChild();
  995. while (tmp_fde)
  996. {
  997. tmp_dle = tmp_fde->GetHistoryElmAt(pos, forward);
  998. if (tmp_dle)
  999. return tmp_dle;
  1000. tmp_fde = tmp_fde->Suc();
  1001. }
  1002. }
  1003. return NULL;
  1004. }
  1005. void FramesDocElm::CheckHistory(int decrement, int& minhist, int& maxhist)
  1006. {
  1007. doc_manager->CheckHistory(decrement, minhist, maxhist);
  1008. FramesDocElm *fde = FirstChild();
  1009. while (fde)
  1010. {
  1011. fde->CheckHistory(decrement, minhist, maxhist);
  1012. fde = fde->Suc();
  1013. }
  1014. }
  1015. void FramesDocElm::RemoveFromHistory(int from)
  1016. {
  1017. doc_manager->RemoveFromHistory(from);
  1018. FramesDocElm *fde = FirstChild();
  1019. while (fde)
  1020. {
  1021. fde->RemoveFromHistory(from);
  1022. fde = fde->Suc();
  1023. }
  1024. }
  1025. void FramesDocElm::RemoveUptoHistory(int to)
  1026. {
  1027. doc_manager->RemoveUptoHistory(to);
  1028. FramesDocElm *fde = FirstChild();
  1029. while (fde)
  1030. {
  1031. fde->RemoveUptoHistory(to);
  1032. fde = fde->Suc();
  1033. }
  1034. }
  1035. void FramesDocElm::RemoveElementFromHistory(int pos)
  1036. {
  1037. doc_manager->RemoveElementFromHistory(pos);
  1038. FramesDocElm *fde = FirstChild();
  1039. while (fde)
  1040. {
  1041. fde->RemoveElementFromHistory(pos);
  1042. fde = fde->Suc();
  1043. }
  1044. }
  1045. HTML_Element *FramesDocElm::GetHtmlElement()
  1046. {
  1047. OP_PROBE4(OP_PROBE_FDELM_GETHTMLELEMENT);
  1048. if (packed1.is_secondary)
  1049. return Parent() ? Parent()->GetHtmlElement() : NULL;
  1050. return m_helm.GetElm();
  1051. }
  1052. void FramesDocElm::SetHtmlElement(HTML_Element *elm)
  1053. {
  1054. OP_ASSERT(m_helm.GetElm() == NULL);
  1055. m_helm.SetElm(elm);
  1056. }
  1057. void FramesDocElm::DetachHtmlElement()
  1058. {
  1059. OP_ASSERT(m_helm.GetElm());
  1060. m_helm.Reset();
  1061. }
  1062. const uni_char* FramesDocElm::GetName()
  1063. {
  1064. return name.CStr();
  1065. }
  1066. OP_STATUS FramesDocElm::SetName(const uni_char* str)
  1067. {
  1068. return name.Set(str);
  1069. }
  1070. OP_STATUS FramesDocElm::Undisplay(BOOL will_be_destroyed)
  1071. {
  1072. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1073. OP_STATUS status = OpStatus::OK;
  1074. if (doc)
  1075. status = doc->Undisplay(will_be_destroyed);
  1076. else
  1077. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1078. if (fde->Undisplay(will_be_destroyed) == OpStatus::ERR_NO_MEMORY)
  1079. status = OpStatus::ERR_NO_MEMORY;
  1080. return status;
  1081. }
  1082. OP_STATUS FramesDocElm::Show()
  1083. {
  1084. if (frm_dev)
  1085. RETURN_IF_ERROR(frm_dev->Show(parent_frm_doc->GetVisualDevice()->GetView()));
  1086. return OpStatus::OK;
  1087. }
  1088. void FramesDocElm::Hide(BOOL free_views /*= FALSE*/)
  1089. {
  1090. if (frm_dev)
  1091. frm_dev->Hide(free_views);
  1092. }
  1093. void FramesDocElm::CheckFrameEdges(BOOL& outer_top, BOOL& outer_left, BOOL& outer_right, BOOL& outer_bottom, BOOL top_checked, BOOL left_checked, BOOL right_checked, BOOL bottom_checked)
  1094. {
  1095. if (!IsFrameset())
  1096. {
  1097. outer_top = TRUE;
  1098. outer_left = TRUE;
  1099. outer_right = TRUE;
  1100. outer_bottom = TRUE;
  1101. }
  1102. FramesDocElm* prnt = Parent();
  1103. if (prnt)
  1104. {
  1105. if (prnt->IsRow())
  1106. {
  1107. if (!top_checked && Pred())
  1108. {
  1109. outer_top = FALSE;
  1110. top_checked = TRUE;
  1111. }
  1112. if (!bottom_checked && Suc())
  1113. {
  1114. outer_bottom = FALSE;
  1115. bottom_checked = TRUE;
  1116. }
  1117. }
  1118. else
  1119. {
  1120. if (!left_checked && Pred())
  1121. {
  1122. outer_left = FALSE;
  1123. left_checked = TRUE;
  1124. }
  1125. if (!right_checked && Suc())
  1126. {
  1127. outer_right = FALSE;
  1128. right_checked = TRUE;
  1129. }
  1130. }
  1131. prnt->CheckFrameEdges(outer_top, outer_left, outer_right, outer_bottom, top_checked, left_checked, right_checked, bottom_checked);
  1132. }
  1133. }
  1134. OP_STATUS FramesDocElm::ReactivateDocument()
  1135. {
  1136. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1137. if (doc)
  1138. return doc->ReactivateDocument();
  1139. OP_STATUS stat = OpStatus::OK;
  1140. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1141. if (fde->ReactivateDocument() == OpStatus::ERR_NO_MEMORY)
  1142. stat = OpStatus::ERR_NO_MEMORY;
  1143. return stat;
  1144. }
  1145. BOOL FramesDocElm::IsLoaded(BOOL inlines_loaded)
  1146. {
  1147. if (!doc_manager->IsCurrentDocLoaded(inlines_loaded))
  1148. return FALSE;
  1149. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1150. if (!fde->IsLoaded(inlines_loaded))
  1151. return FALSE;
  1152. return TRUE;
  1153. }
  1154. void FramesDocElm::SetInlinesUsed(BOOL used)
  1155. {
  1156. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1157. if (doc)
  1158. doc->SetInlinesUsed(used);
  1159. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1160. fde->SetInlinesUsed(used);
  1161. }
  1162. void FramesDocElm::Free(BOOL layout_only/*=FALSE*/, FramesDocument::FreeImportance free_importance /*= FramesDocument::UNIMPORTANT*/)
  1163. {
  1164. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1165. if (doc)
  1166. doc->Free(layout_only, free_importance);
  1167. else
  1168. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1169. fde->Free(layout_only, free_importance);
  1170. }
  1171. OP_BOOLEAN FramesDocElm::CheckSource()
  1172. {
  1173. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1174. OP_BOOLEAN stat = OpStatus::OK;
  1175. if (doc)
  1176. stat = doc->CheckSource();
  1177. else
  1178. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1179. {
  1180. stat = fde->CheckSource();
  1181. if (OpStatus::IsError(stat))
  1182. break;
  1183. }
  1184. return stat;
  1185. }
  1186. void FramesDocElm::StopLoading(BOOL format, BOOL abort/*=FALSE*/)
  1187. {
  1188. doc_manager->StopLoading(format, FALSE, abort);
  1189. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1190. fde->StopLoading(format, abort);
  1191. }
  1192. OP_STATUS FramesDocElm::SetMode(BOOL win_show_images, BOOL win_load_images, CSSMODE win_css_mode, CheckExpiryType check_expiry)
  1193. {
  1194. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1195. if (doc)
  1196. {
  1197. if (!frm_dev->GetView())
  1198. {
  1199. RETURN_IF_ERROR(Show());
  1200. }
  1201. doc_manager->SetCheckExpiryType(check_expiry);
  1202. return doc->SetMode(win_show_images, win_load_images, win_css_mode, check_expiry);
  1203. }
  1204. else
  1205. {
  1206. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1207. if (fde->SetMode(win_show_images, win_load_images, win_css_mode, check_expiry) == OpStatus::ERR_NO_MEMORY)
  1208. return OpStatus::ERR_NO_MEMORY;
  1209. return OpStatus::OK;
  1210. }
  1211. }
  1212. OP_STATUS FramesDocElm::SetAsCurrentDoc(BOOL state, BOOL visible_if_current)
  1213. {
  1214. if (!state || GetCurrentDoc() && !GetCurrentDoc()->IsCurrentDoc())
  1215. SetOnLoadCalled(FALSE);
  1216. OP_STATUS stat = doc_manager->UpdateCallbacks(state);
  1217. FramesDocElm* fde = FirstChild();
  1218. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1219. if (!fde || doc)
  1220. {
  1221. if (doc && !state)
  1222. {
  1223. stat = doc->Undisplay();
  1224. if (doc->SetAsCurrentDoc(state, visible_if_current) == OpStatus::ERR_NO_MEMORY)
  1225. stat = OpStatus::ERR_NO_MEMORY;
  1226. }
  1227. if (OpStatus::IsError(stat))
  1228. return stat;
  1229. if (frm_dev)
  1230. {
  1231. if (doc && doc->IsFrameDoc() || (IsInlineFrame() || !doc || !doc->IsFrameDoc()) && (!state || visible_if_current))
  1232. {
  1233. if (state)
  1234. RETURN_IF_ERROR(Show());
  1235. else
  1236. Hide(TRUE);
  1237. }
  1238. }
  1239. if (doc && state)
  1240. stat = doc->SetAsCurrentDoc(state, visible_if_current);
  1241. }
  1242. else
  1243. {
  1244. // check if any windows even if no document
  1245. if (frm_dev && (!IsInlineFrame() || !state))
  1246. Hide(TRUE);
  1247. for (; fde; fde = fde->Suc())
  1248. if (OpStatus::IsMemoryError(fde->SetAsCurrentDoc(state, visible_if_current)))
  1249. stat = OpStatus::ERR_NO_MEMORY;
  1250. }
  1251. return stat;
  1252. }
  1253. void FramesDocElm::ReloadIfModified()
  1254. {
  1255. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1256. if (!IsFrameset())
  1257. {
  1258. if (doc)
  1259. {
  1260. URL doc_url = doc->GetURL();
  1261. DocumentReferrer doc_ref_url = doc->GetRefURL();
  1262. doc_manager->OpenURL(doc_url, doc_ref_url, TRUE, TRUE, FALSE, FALSE, NotEnteredByUser, FALSE, TRUE);
  1263. }
  1264. else
  1265. {
  1266. // FIXME: OOM
  1267. LoadFrames();
  1268. }
  1269. }
  1270. else
  1271. {
  1272. OP_ASSERT(!doc);
  1273. FramesDocElm* fde = FirstChild();
  1274. if (fde)
  1275. {
  1276. for (; fde; fde = fde->Suc())
  1277. fde->ReloadIfModified();
  1278. }
  1279. else
  1280. FramesDocument::CheckOnLoad(NULL, this);
  1281. }
  1282. }
  1283. int ScaleToMSR(int val, FramesDocument* doc, BOOL row)
  1284. {
  1285. if (row)
  1286. return (val * doc->GetLayoutViewHeight()) / 600;
  1287. else
  1288. return (val * doc->GetLayoutViewWidth()) / 800;
  1289. }
  1290. FramesDocElm* FindFramesDocElm(Head* existing_frames, HTML_Element* he)
  1291. {
  1292. for (FramesDocElm* fde = (FramesDocElm*) existing_frames->Last(); fde; fde = (FramesDocElm*) fde->Pred())
  1293. if (fde->GetHtmlElement() == he)
  1294. {
  1295. fde->Out();
  1296. return fde;
  1297. }
  1298. return NULL;
  1299. }
  1300. OP_STATUS FramesDocElm::BuildTree(FramesDocument* top_frm_doc, Head* existing_frames)
  1301. {
  1302. OP_STATUS stat = DocStatus::DOC_CANNOT_FORMAT;
  1303. OpStatus::Ignore(stat);
  1304. if (HTML_Element *helm = GetHtmlElement())
  1305. {
  1306. if (helm->IsMatchingType(HE_FRAME, NS_HTML))
  1307. return DocStatus::DOC_FORMATTING;
  1308. else if (helm->IsMatchingType(HE_FRAMESET, NS_HTML))
  1309. {
  1310. const uni_char* row_spec = helm->GetFramesetRowspec();
  1311. const uni_char* col_spec = helm->GetFramesetColspec();
  1312. VisualDevice* parent_vd = GetParentFramesDoc()->GetVisualDevice();
  1313. if (row_spec && col_spec)
  1314. {
  1315. //not a tree
  1316. // 22/04/97: changed this to take rows first since Netscape 3.01 always takes rows first
  1317. int first_count = helm->GetFramesetRowCount();
  1318. int next_count = helm->GetFramesetColCount();
  1319. SetIsRow(TRUE);
  1320. SetNormalRow(TRUE);
  1321. int first_child_count = 0;
  1322. HTML_Element* he = helm->FirstChildActual();
  1323. while (he && first_child_count < first_count)
  1324. {
  1325. if (he->GetNsType() != NS_HTML || (he->Type() != HE_FRAMESET && he->Type() != HE_FRAME))
  1326. {
  1327. he = he->SucActual();
  1328. continue;
  1329. }
  1330. int val = 1;
  1331. int type = FRAMESET_RELATIVE_SIZED;
  1332. helm->GetFramesetRow(first_child_count++, val, type);
  1333. FramesDocElm* felm = NULL;
  1334. if (existing_frames)
  1335. felm = FindFramesDocElm(existing_frames, helm);
  1336. if (felm)
  1337. felm->Reset(type, val, this, helm);
  1338. else
  1339. {
  1340. felm = OP_NEW(FramesDocElm, (top_frm_doc->GetNewSubWinId(), 0, 0, 0, 0, GetParentFramesDoc(), helm, parent_vd, type, val, FALSE, this, TRUE));
  1341. if (!felm)
  1342. return DocStatus::ERR_NO_MEMORY;
  1343. if (OpStatus::IsError(felm->Init(NULL, parent_vd, NULL)))
  1344. {
  1345. OP_DELETE((felm));
  1346. felm = NULL;
  1347. return DocStatus::ERR_NO_MEMORY;
  1348. }
  1349. }
  1350. felm->Under(this);
  1351. felm->SetIsRow(FALSE);
  1352. felm->SetNormalRow(FALSE);
  1353. if (GetParentFramesDoc()->GetFramesStacked())
  1354. felm->SetIsRow(TRUE);
  1355. int next_child_count = 0;
  1356. while (he && next_child_count < next_count)
  1357. {
  1358. if (he->GetNsType() == NS_HTML && (he->Type() == HE_FRAMESET || he->Type() == HE_FRAME))
  1359. {
  1360. int val = 1;
  1361. int type = FRAMESET_RELATIVE_SIZED;
  1362. helm->GetFramesetCol(next_child_count++, val, type);
  1363. FramesDocElm* new_felm = NULL;
  1364. if (existing_frames)
  1365. new_felm = FindFramesDocElm(existing_frames, he);
  1366. if (new_felm)
  1367. new_felm->Reset(type, val, felm, he);
  1368. else
  1369. {
  1370. new_felm = OP_NEW(FramesDocElm, (top_frm_doc->GetNewSubWinId(), 0, 0, 0, 0, GetParentFramesDoc(), he, parent_vd, type, val, FALSE, felm));
  1371. if (!new_felm)
  1372. return DocStatus::ERR_NO_MEMORY;
  1373. if (OpStatus::IsError(new_felm->Init(he, parent_vd, NULL)))
  1374. {
  1375. OP_DELETE((new_felm));
  1376. return DocStatus::ERR_NO_MEMORY;
  1377. }
  1378. }
  1379. new_felm->Under(felm);
  1380. stat = new_felm->BuildTree(top_frm_doc, existing_frames);
  1381. }
  1382. he = he->SucActual();
  1383. }
  1384. }
  1385. }
  1386. else
  1387. {
  1388. SetIsRow(helm->GetFramesetRowspec() != 0);
  1389. if (!IsRow())
  1390. SetIsRow(helm->GetFramesetColspec() == 0); // default row ???
  1391. SetNormalRow(IsRow());
  1392. int child_count = 0;
  1393. for (HTML_Element* he = helm->FirstChildActual(); he; he = he->SucActual())
  1394. if (he->GetNsType() == NS_HTML && (he->Type() == HE_FRAMESET || he->Type() == HE_FRAME))
  1395. {
  1396. int val = 100;
  1397. int type = FRAMESET_PERCENTAGE_SIZED;
  1398. BOOL has_spec = FALSE;
  1399. if (IsRow())
  1400. has_spec = helm->GetFramesetRow(child_count++, val, type);
  1401. else
  1402. has_spec = helm->GetFramesetCol(child_count++, val, type);
  1403. // ignore children outside the rowspec/colspec if specified
  1404. if (has_spec || (IsRow() && !row_spec && child_count == 1) || (!IsRow() && !col_spec && child_count == 1))
  1405. {
  1406. FramesDocElm* felm = NULL;
  1407. if (existing_frames)
  1408. felm = FindFramesDocElm(existing_frames, he);
  1409. if (felm)
  1410. felm->Reset(type, val, this, he);
  1411. else
  1412. {
  1413. felm = OP_NEW(FramesDocElm, (top_frm_doc->GetNewSubWinId(), 0, 0, 0, 0, GetParentFramesDoc(), he, parent_vd, type, val, FALSE, this));
  1414. if (!felm)
  1415. return DocStatus::ERR_NO_MEMORY;
  1416. if (OpStatus::IsError(felm->Init(he, parent_vd, NULL)))
  1417. {
  1418. OP_DELETE((felm));
  1419. return DocStatus::ERR_NO_MEMORY;
  1420. }
  1421. }
  1422. felm->Under(this);
  1423. stat = felm->BuildTree(top_frm_doc, existing_frames);
  1424. }
  1425. }
  1426. }
  1427. // If we have an empty frameset, call onload because it won't be triggered by any child frames.
  1428. if (!this->FirstChild())
  1429. return FramesDocument::CheckOnLoad(NULL, this);
  1430. if (GetParentFramesDoc()->GetFramesStacked())
  1431. SetIsRow(TRUE);
  1432. // check percentage
  1433. int psum = 0;
  1434. for (FramesDocElm* felm = FirstChild(); felm; felm = felm->Suc())
  1435. if (felm->GetSizeType() == FRAMESET_PERCENTAGE_SIZED)
  1436. psum += felm->size_val;
  1437. if (psum > 100)
  1438. for (FramesDocElm* felm = FirstChild(); felm; felm = felm->Suc())
  1439. if (felm->GetSizeType() == FRAMESET_PERCENTAGE_SIZED)
  1440. felm->size_val = (int)(((int)felm->size_val*100) / psum);
  1441. }
  1442. }
  1443. return stat;
  1444. }
  1445. void FramesDocElm::SetRootSize(int width, int height)
  1446. {
  1447. OP_ASSERT(!frm_dev);
  1448. OP_ASSERT(!Parent());
  1449. this->width = width;
  1450. this->height = height;
  1451. this->normal_width = width;
  1452. this->normal_height = height;
  1453. }
  1454. OP_STATUS FramesDocElm::FormatFrames(BOOL format_rows, BOOL format_cols)
  1455. {
  1456. OP_STATUS stat = DocStatus::DOC_CANNOT_FORMAT;
  1457. OpStatus::Ignore(stat);
  1458. FramesDocElm* inherit_fde = Parent();
  1459. if (!inherit_fde)
  1460. inherit_fde = parent_frm_doc->GetDocManager()->GetFrame();
  1461. if (inherit_fde && !packed1.is_in_doc_coords)
  1462. packed1.is_in_doc_coords = inherit_fde->packed1.is_in_doc_coords;
  1463. if (!IsFrameset())
  1464. {
  1465. if (GetFrameBorder())
  1466. {
  1467. if (IsInlineFrame())
  1468. SetFrameBorders(TRUE, TRUE, TRUE, TRUE);
  1469. else
  1470. {
  1471. BOOL outer_top, outer_left, outer_right, outer_bottom;
  1472. CheckFrameEdges(outer_top, outer_left, outer_right, outer_bottom);
  1473. SetFrameBorders(!outer_top, !outer_left, !outer_right, !outer_bottom);
  1474. }
  1475. }
  1476. return DocStatus::DOC_FORMATTING;
  1477. }
  1478. else
  1479. {
  1480. FramesDocElm* felm;
  1481. int size_used = 0;
  1482. BOOL use_doc_coords = IsInDocCoords();
  1483. if (!Parent())
  1484. if (FramesDocElm* frame = parent_frm_doc->GetDocManager()->GetFrame())
  1485. {
  1486. // Root frameset in a sub-document. Set available size.
  1487. width = frame->width;
  1488. height = frame->height;
  1489. normal_width = frame->normal_width;
  1490. normal_height = frame->normal_height;
  1491. }
  1492. int avail_size = (IsRow()) ? height : width;
  1493. if (parent_frm_doc->GetSmartFrames())
  1494. avail_size = (IsRow()) ? normal_height : normal_width;
  1495. int abs_size_used = 0;
  1496. int extra_space = 0;
  1497. int child_count = 0;
  1498. int abs_child_count = 0;
  1499. int rel_childs = 0;
  1500. int per_val = 0;
  1501. VisualDevice* top_vis_dev = doc_manager->GetWindow()->VisualDev();
  1502. FramesDocument* top_doc = doc_manager->GetWindow()->GetCurrentDoc();
  1503. BOOL scale_to_msr = GetLayoutMode() != LAYOUT_NORMAL && GetParentFramesDoc()->GetSmartFrames();
  1504. for (felm = FirstChild(); felm; felm = felm->Suc())
  1505. {
  1506. int val = felm->size_val;
  1507. int type = felm->GetSizeType();
  1508. if (scale_to_msr && type == FRAMESET_ABSOLUTE_SIZED)
  1509. val = ScaleToMSR(val, top_doc, IsRow());
  1510. if ((IsRow() && format_rows) || (!IsRow() && format_cols))
  1511. {
  1512. if (type == FRAMESET_ABSOLUTE_SIZED)
  1513. {
  1514. if (!use_doc_coords)
  1515. val = top_vis_dev->ScaleToScreen(val);
  1516. size_used += val;
  1517. abs_size_used += val;
  1518. abs_child_count++;
  1519. }
  1520. else
  1521. if (type == FRAMESET_PERCENTAGE_SIZED)
  1522. {
  1523. int use_size = int((avail_size * val) / 100);
  1524. size_used += use_size;
  1525. per_val += val;
  1526. }
  1527. else
  1528. rel_childs++;
  1529. }
  1530. if (!GetParentFramesDoc()->GetSmartFrames())
  1531. if (felm->Pred())
  1532. avail_size -= GetFrameSpacing();
  1533. child_count++;
  1534. }
  1535. if (avail_size < 0)
  1536. avail_size = 0;
  1537. int abs_size_avail = abs_size_used;
  1538. if (abs_size_avail > avail_size || child_count == abs_child_count)
  1539. abs_size_avail = avail_size;
  1540. int per_size_avail = ((avail_size * per_val) / 100);
  1541. if (per_size_avail > avail_size - abs_size_avail)
  1542. per_size_avail = avail_size - abs_size_avail;
  1543. int per_count = child_count - abs_child_count - rel_childs;
  1544. BOOL per2rel = per_count && !rel_childs;
  1545. if (per2rel)
  1546. rel_childs = per_count;
  1547. if (per_count && per_size_avail/per_count < RELATIVE_MIN_SIZE)
  1548. {
  1549. if (abs_child_count)
  1550. {
  1551. int take_from_abs = RELATIVE_MIN_SIZE * per_count;
  1552. if (take_from_abs > abs_size_avail/2)
  1553. take_from_abs = abs_size_avail / 2;
  1554. abs_size_avail -= take_from_abs;
  1555. per_size_avail += take_from_abs;
  1556. }
  1557. }
  1558. if (!rel_childs)
  1559. {
  1560. extra_space = avail_size - size_used;
  1561. if (extra_space < 0)
  1562. extra_space = 0;
  1563. }
  1564. BOOL add_to_abs_sized = (avail_size < abs_size_used);
  1565. size_used = 0;
  1566. int i = 0;
  1567. int rel_child_count = 0;
  1568. int rel_child_val = 0;
  1569. FramesDocElm* prev_felm = NULL;
  1570. for (felm = FirstChild(); felm; felm = felm->Suc())
  1571. {
  1572. int val = felm->size_val;
  1573. int type = felm->GetSizeType();
  1574. if (scale_to_msr && type == FRAMESET_ABSOLUTE_SIZED)
  1575. val = ScaleToMSR(val, top_doc, IsRow());
  1576. int new_width = (IsRow()) ? width : felm->width;
  1577. int new_height = (IsRow()) ? felm->height : height;
  1578. if ((IsRow() && format_rows) || (!IsRow() && format_cols))
  1579. {
  1580. OpPoint new_pos = felm->pos.GetTranslation();
  1581. if (prev_felm)
  1582. {
  1583. int frm_ex = 0;
  1584. if (!GetParentFramesDoc()->GetSmartFrames())
  1585. frm_ex += GetFrameSpacing();
  1586. OpPoint prev_pos = prev_felm->pos.GetTranslation();
  1587. if (IsRow())
  1588. new_pos.y = prev_pos.y + prev_felm->height + frm_ex;
  1589. else
  1590. new_pos.x = prev_pos.x + prev_felm->width + frm_ex;
  1591. }
  1592. felm->pos.SetTranslation(new_pos.x, new_pos.y);
  1593. if (!felm->Suc() && !rel_childs)
  1594. {
  1595. // use rest of space
  1596. int use_size = (int) (avail_size - size_used);
  1597. size_used += use_size;
  1598. if (IsRow())
  1599. new_height = use_size;
  1600. else
  1601. new_width = use_size;
  1602. }
  1603. else
  1604. {
  1605. int add_space = 0;
  1606. if (extra_space && (add_to_abs_sized || type == FRAMESET_PERCENTAGE_SIZED))
  1607. {
  1608. int ccount = child_count-i-rel_childs+rel_child_count;
  1609. if (!add_to_abs_sized)
  1610. ccount = child_count-abs_child_count-i-rel_childs+rel_child_count;
  1611. if (ccount)
  1612. add_space = (int) (extra_space/ccount);
  1613. extra_space -= add_space;
  1614. }
  1615. if (type == FRAMESET_ABSOLUTE_SIZED)
  1616. {
  1617. int use_size = val;
  1618. if (abs_size_used)
  1619. use_size = (int)(((int)val * abs_size_avail) / abs_size_used);
  1620. use_size += add_space;
  1621. if (use_size < 0)
  1622. {
  1623. if (extra_space)
  1624. extra_space += use_size;
  1625. use_size = 0;
  1626. }
  1627. if (!use_doc_coords)
  1628. use_size = top_vis_dev->ScaleToScreen(use_size);
  1629. size_used += use_size;
  1630. if (IsRow())
  1631. new_height = use_size;
  1632. else
  1633. new_width = use_size;
  1634. }
  1635. else if (type == FRAMESET_PERCENTAGE_SIZED && !per2rel)
  1636. {
  1637. int use_size = 0;
  1638. if (per_val)
  1639. use_size = (int) ((per_size_avail*val) / per_val);
  1640. use_size += add_space;
  1641. if (use_size < 0)
  1642. {
  1643. if (extra_space)
  1644. extra_space += use_size;
  1645. use_size = 0;
  1646. }
  1647. size_used += use_size;
  1648. if (IsRow())
  1649. new_height = use_size;
  1650. else
  1651. new_width = use_size;
  1652. }
  1653. else
  1654. {
  1655. rel_child_count++;
  1656. rel_child_val += val;
  1657. }
  1658. }
  1659. }
  1660. // we set the size without redrawing to avoid drawing in wrong position
  1661. felm->width = new_width;
  1662. felm->height = new_height;
  1663. felm->normal_width = new_width;
  1664. felm->normal_height = new_height;
  1665. prev_felm = felm;
  1666. i++;
  1667. }
  1668. if ((IsRow() && format_rows) || (!IsRow() && format_cols))
  1669. {
  1670. // set size on relatively sized frames
  1671. if (rel_child_count && ((!IsRow() && size_used < width) || (IsRow() && size_used < height)))
  1672. {
  1673. if (!rel_child_val)
  1674. rel_child_val = 1;
  1675. i = 1;
  1676. float rel_size = ((float)avail_size - size_used) / rel_child_val;
  1677. prev_felm = NULL;
  1678. for (felm = FirstChild(); felm; felm = felm->Suc())
  1679. {
  1680. OpPoint new_pos = felm->pos.GetTranslation();
  1681. if (prev_felm)
  1682. {
  1683. int frm_ex = 0;
  1684. if (!GetParentFramesDoc()->GetSmartFrames())
  1685. frm_ex += GetFrameSpacing();
  1686. OpPoint prev_pos = prev_felm->pos.GetTranslation();
  1687. if (IsRow())
  1688. new_pos.y = prev_pos.y + prev_felm->height + frm_ex;
  1689. else
  1690. new_pos.x = prev_pos.x + prev_felm->width + frm_ex;
  1691. }
  1692. felm->pos.SetTranslation(new_pos.x, new_pos.y);
  1693. int new_width = felm->width;
  1694. int new_height = felm->height;
  1695. if (felm->GetSizeType() == FRAMESET_RELATIVE_SIZED || (per2rel && felm->GetSizeType() == FRAMESET_PERCENTAGE_SIZED))
  1696. {
  1697. int child_size;
  1698. if (i == rel_childs)
  1699. child_size = (int) (avail_size - size_used); // use rest of space
  1700. else
  1701. child_size = (int) (rel_size * felm->size_val);
  1702. if (IsRow())
  1703. new_height = child_size;
  1704. else
  1705. new_width = child_size;
  1706. size_used += child_size;
  1707. i++;
  1708. }
  1709. // we set the size without redrawing to avoid drawing in wrong position
  1710. felm->width = new_width;
  1711. felm->height = new_height;
  1712. felm->normal_width = new_width;
  1713. felm->normal_height = new_height;
  1714. prev_felm = felm;
  1715. }
  1716. }
  1717. }
  1718. // format each frame
  1719. for (felm = FirstChild(); felm; felm = felm->Suc())
  1720. {
  1721. if (parent_frm_doc->GetFramesStacked())
  1722. /* Document height (root layout box height) never gets smaller than
  1723. layout viewport height, and in frame stacking mode, we want frames to
  1724. take up as little space as possible. Therefore, set layout viewport
  1725. height to 0. */
  1726. felm->normal_height = 0;
  1727. stat = felm->FormatFrames(format_rows, format_cols);
  1728. if (FramesDocument* doc = felm->GetCurrentDoc())
  1729. doc->RecalculateLayoutViewSize(TRUE); // FIXME: assuming "user action". Is that correct?
  1730. }
  1731. }
  1732. if (stat == DocStatus::DOC_CANNOT_FORMAT)
  1733. SetOnLoadCalled(TRUE);
  1734. return stat;
  1735. }
  1736. OP_STATUS FramesDocElm::LoadFrames(ES_Thread *origin_thread)
  1737. {
  1738. if (IsFrameset())
  1739. {
  1740. for (FramesDocElm* felm = FirstChild(); felm; felm = felm->Suc())
  1741. RETURN_IF_ERROR(felm->LoadFrames());
  1742. if (!FirstChild())
  1743. FramesDocument::CheckOnLoad(NULL, this);
  1744. }
  1745. else
  1746. {
  1747. URL frm_url;
  1748. URL about_blank_url = g_url_api->GetURL("about:blank");
  1749. if (HTML_Element *helm = GetHtmlElement())
  1750. {
  1751. URL* url_ptr = NULL;
  1752. if (helm->GetNsType() == NS_HTML)
  1753. {
  1754. short attr = ATTR_SRC;
  1755. if (helm->Type() == HE_OBJECT)
  1756. attr = ATTR_DATA;
  1757. url_ptr = helm->GetUrlAttr(attr, NS_IDX_HTML, GetParentFramesDoc() ? GetParentFramesDoc()->GetLogicalDocument() : NULL);
  1758. }
  1759. #ifdef SVG_SUPPORT
  1760. else if (g_svg_manager->AllowFrameForElement(helm))
  1761. {
  1762. URL* root_url = &GetParentFramesDoc()->GetURL();
  1763. url_ptr = g_svg_manager->GetXLinkURL(helm, root_url);
  1764. }
  1765. #endif // SVG_SUPPORT
  1766. if (url_ptr && !url_ptr->IsEmpty())
  1767. frm_url = *url_ptr;
  1768. else
  1769. frm_url = about_blank_url;
  1770. }
  1771. else
  1772. {
  1773. // if helm==NULL then this is a frame with freed content and current doc has the original url
  1774. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1775. if (doc)
  1776. frm_url = doc->GetURL();
  1777. }
  1778. #ifdef _MIME_SUPPORT_
  1779. // check if frm_url equals to any ancestor of this frame
  1780. FramesDocument* ancestor_doc = GetParentFramesDoc();
  1781. #endif // _MIME_SUPPORT_
  1782. BOOL bypass_frame_access_check = FALSE;
  1783. #ifdef _MIME_SUPPORT_
  1784. if (ancestor_doc->GetSuppress(frm_url.Type()) ||
  1785. DocumentManager::IsSpecialURL(frm_url))
  1786. {
  1787. if (ancestor_doc->MakeFrameSuppressUrl(frm_url) == OpStatus::ERR_NO_MEMORY)
  1788. return OpStatus::OK;
  1789. bypass_frame_access_check = TRUE;
  1790. }
  1791. #endif // _MIME_SUPPORT_
  1792. #if DOCHAND_MAX_FRAMES_ON_PAGE > 0
  1793. if (!IsContentAllowed() && (!(frm_url == about_blank_url)))
  1794. frm_url = about_blank_url;
  1795. #endif // DOCHAND_MAX_FRAMES_ON_PAGE > 0
  1796. if (!doc_manager->GetCurrentDoc() &&
  1797. (frm_url == about_blank_url || frm_url.Type() == URL_JAVASCRIPT)
  1798. #ifdef ON_DEMAND_PLUGIN
  1799. // Allow frame to load a placeholder even when plugin element has no URL to load.
  1800. && !GetHtmlElement()->IsPluginPlaceholder()
  1801. #endif // ON_DEMAND_PLUGIN
  1802. )
  1803. {
  1804. RETURN_IF_ERROR(doc_manager->CreateInitialEmptyDocument(frm_url.Type() == URL_JAVASCRIPT, frm_url == about_blank_url && origin_thread != NULL));
  1805. if (frm_url == about_blank_url)
  1806. {
  1807. /* If a thread initiated the loading of about:blank, then add an
  1808. async onload check. Once it is signalled and the 'origin_thread'
  1809. hasn't caused the document to be navigated away, only then will
  1810. an about:blank onload be sent. */
  1811. if (origin_thread && doc_manager->GetCurrentDoc())
  1812. RETURN_IF_ERROR(doc_manager->GetCurrentDoc()->ScheduleAsyncOnloadCheck(origin_thread, TRUE));
  1813. /* Nothing more to do. */
  1814. return OpStatus::OK;
  1815. }
  1816. }
  1817. DocumentReferrer frm_ref_url(GetParentFramesDoc());
  1818. DocumentManager *parent_docman = GetParentFramesDoc()->GetDocManager();
  1819. BOOL check_if_expired = parent_docman->GetCheckExpiryType() != CHECK_EXPIRY_NEVER;
  1820. BOOL reload = parent_docman->GetReload();
  1821. BOOL user_initiated = FALSE;
  1822. BOOL create_doc_now = GetParentFramesDoc()->IsGeneratedByOpera() && frm_url.Status(TRUE) == URL_LOADED && !GetParentFramesDoc()->IsReflowing();
  1823. BOOL is_walking_in_history = parent_docman->IsWalkingInHistory();
  1824. doc_manager->SetUseHistoryNumber(parent_docman->CurrentDocListElm()->Number());
  1825. doc_manager->SetReload(reload);
  1826. doc_manager->SetReloadFlags(parent_docman->GetReloadDocument(), parent_docman->GetConditionallyRequestDocument(), parent_docman->GetReloadInlines(), parent_docman->GetConditionallyRequestInlines());
  1827. DocumentManager::OpenURLOptions options;
  1828. options.user_initiated = user_initiated;
  1829. options.create_doc_now = create_doc_now;
  1830. options.is_walking_in_history = is_walking_in_history;
  1831. options.bypass_url_access_check = bypass_frame_access_check;
  1832. options.origin_thread = origin_thread;
  1833. options.from_html_attribute = TRUE;
  1834. doc_manager->OpenURL(frm_url, frm_ref_url, check_if_expired, reload, options);
  1835. // In case we created a new document for a javascript url and the script load
  1836. // command failed completely, we need to clean up the about:blank state
  1837. if (frm_url.Type() == URL_JAVASCRIPT && doc_manager->GetLoadStatus() == NOT_LOADING)
  1838. {
  1839. doc_manager->GetCurrentDoc()->SetWaitForJavascriptURL(FALSE);
  1840. doc_manager->GetCurrentDoc()->CheckFinishDocument();
  1841. }
  1842. }
  1843. return OpStatus::OK;
  1844. }
  1845. OP_STATUS FramesDocElm::FormatDocs()
  1846. {
  1847. OP_STATUS stat = DocStatus::DOC_OK;
  1848. OpStatus::Ignore(stat);
  1849. FramesDocument* doc = doc_manager->GetCurrentDoc();
  1850. if (doc)
  1851. stat = doc->Reflow(TRUE);
  1852. else
  1853. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  1854. if (fde->FormatDocs() == OpStatus::ERR_NO_MEMORY)
  1855. stat = OpStatus::ERR_NO_MEMORY;
  1856. return stat;
  1857. }
  1858. #ifdef _PRINT_SUPPORT_
  1859. OP_STATUS FramesDocElm::CopyFrames(FramesDocElm* new_frm)
  1860. {
  1861. new_frm->SetIsRow(IsRow());
  1862. FramesDocElm* fde = FirstChild();
  1863. while (fde)
  1864. {
  1865. OP_ASSERT(!fde->m_helm.GetElm() || fde->m_print_twin_elm || !"It need to have a print twin to connect it to");
  1866. FramesDocElm* new_fde = OP_NEW(FramesDocElm, (fde->GetSubWinId(), 0, 0, 0, 0, new_frm->GetParentFramesDoc(), fde->m_print_twin_elm, NULL, fde->GetSizeType(), fde->GetSizeVal(), fde->IsInlineFrame(), new_frm));
  1867. if( ! new_fde )
  1868. return OpStatus::ERR_NO_MEMORY;
  1869. if (OpStatus::IsError(new_fde->Init(fde->m_print_twin_elm, NULL, NULL)))
  1870. {
  1871. OP_DELETE((new_fde));
  1872. return OpStatus::ERR_NO_MEMORY;
  1873. }
  1874. new_fde->Under(new_frm);
  1875. RETURN_IF_ERROR(fde->CopyFrames(new_fde));
  1876. fde = fde->Suc();
  1877. }
  1878. // FIXME: potentially incorrectly assuming print preview here (but there's nothing new about that):
  1879. RETURN_IF_MEMORY_ERROR(new_frm->GetDocManager()->SetPrintMode(TRUE, this, TRUE));
  1880. return OpStatus::OK;
  1881. }
  1882. OP_STATUS FramesDocElm::CreatePrintLayoutAllPages(PrintDevice* pd, FramesDocElm* print_root)
  1883. {
  1884. FramesDocument* doc = GetCurrentDoc();
  1885. if (doc)
  1886. {
  1887. int page_ypos = 0;
  1888. FramesDocElm* prev_fde = print_root->LastChild();
  1889. if (prev_fde)
  1890. page_ypos = prev_fde->GetAbsY() + prev_fde->GetHeight();
  1891. FramesDocElm* fde;
  1892. HTML_Element* html_element;
  1893. if (IsInlineFrame())
  1894. {
  1895. OP_ASSERT(m_print_twin_elm); // Without this the cloned FramesDocElm won't be found anyway
  1896. if (!m_print_twin_elm)
  1897. {
  1898. return OpStatus::OK;
  1899. }
  1900. OP_ASSERT(GetFrmDocElmByHTML(m_print_twin_elm) == NULL);
  1901. html_element = m_print_twin_elm;
  1902. fde = OP_NEW(FramesDocElm, (GetSubWinId(), GetAbsX(), GetAbsY(), pd->GetRenderingViewWidth(), pd->GetRenderingViewHeight(),
  1903. print_root->GetParentFramesDoc(), m_print_twin_elm, pd, FRAMESET_ABSOLUTE_SIZED, 0, TRUE, print_root));
  1904. }
  1905. else
  1906. {
  1907. html_element = NULL;
  1908. fde = OP_NEW(FramesDocElm, (GetSubWinId(), 0, page_ypos, pd->GetRenderingViewWidth(), pd->GetRenderingViewHeight(),
  1909. print_root->GetParentFramesDoc(), NULL, pd, FRAMESET_ABSOLUTE_SIZED, 0, FALSE, print_root));
  1910. }
  1911. if (!fde)
  1912. return OpStatus::ERR_NO_MEMORY;
  1913. if (OpStatus::IsError(fde->Init(html_element, pd, NULL)))
  1914. {
  1915. OP_DELETE((fde));
  1916. fde = NULL;
  1917. return OpStatus::ERR_NO_MEMORY;
  1918. }
  1919. #ifdef _DEBUG
  1920. if (IsInlineFrame())
  1921. {
  1922. OP_ASSERT(fde->GetHtmlElement() == m_print_twin_elm);
  1923. }
  1924. #endif // _DEBUG
  1925. fde->Under(print_root);
  1926. if (fde->GetDocManager()->SetPrintMode(TRUE, this, TRUE) == OpStatus::ERR_NO_MEMORY)
  1927. {
  1928. fde->Out();
  1929. OP_DELETE(fde);
  1930. return OpStatus::ERR_NO_MEMORY;
  1931. }
  1932. int w = fde->GetWidth();
  1933. int h = fde->GetHeight();
  1934. FramesDocument* printdoc = fde->GetDocManager()->GetPrintDoc();
  1935. if (printdoc)
  1936. {
  1937. w = printdoc->Width();
  1938. h = printdoc->Height();
  1939. }
  1940. AffinePos fde_abs_pos = fde->GetAbsPos();
  1941. fde->SetGeometry(fde_abs_pos, w, h);
  1942. print_root->SetGeometry(print_root->GetAbsPos(), w, fde_abs_pos.GetTranslation().y + h);
  1943. }
  1944. else
  1945. {
  1946. FramesDocElm* fde = FirstChild();
  1947. while (fde)
  1948. {
  1949. RETURN_IF_ERROR(fde->CreatePrintLayoutAllPages(pd, print_root));
  1950. fde = fde->Suc();
  1951. }
  1952. }
  1953. return OpStatus::OK;
  1954. }
  1955. #endif // _PRINT_SUPPORT_
  1956. /* static */
  1957. FramesDocElm* FramesDocElm::GetFrmDocElmByHTML(HTML_Element * elm)
  1958. {
  1959. if (elm)
  1960. {
  1961. ElementRef *ref = elm->GetFirstReferenceOfType(ElementRef::FRAMESDOCELM);
  1962. if (ref)
  1963. return static_cast<FDEElmRef*>(ref)->GetFramesDocElm();
  1964. }
  1965. return NULL;
  1966. }
  1967. #ifdef _PRINT_SUPPORT_
  1968. void FramesDocElm::Display(VisualDevice* vd, const RECT& rect)
  1969. {
  1970. Window* window = GetDocManager()->GetWindow();
  1971. FramesDocument* doc = doc_manager->GetPrintDoc();
  1972. if (doc)
  1973. {
  1974. int abs_x = GetAbsX();
  1975. int abs_y = GetAbsY();
  1976. if (IsInlineFrame())
  1977. {
  1978. OpRect frame_clip_rect(0, 0, GetWidth(), GetHeight());
  1979. frame_clip_rect = vd->ScaleToDoc(frame_clip_rect);
  1980. vd->BeginClipping(frame_clip_rect);
  1981. VDState vd_state = vd->PushState();
  1982. doc->Display(rect, vd);
  1983. vd->PopState(vd_state);
  1984. vd->EndClipping();
  1985. }
  1986. else if (window->GetFramesPrintType() == PRINT_AS_SCREEN)
  1987. {
  1988. vd->TranslateView(-abs_x, -abs_y);
  1989. OpRect frame_clip_rect(0, 0, GetWidth(), GetHeight());
  1990. vd->BeginClipping(frame_clip_rect);
  1991. if (vd->IsPrinter() && !IsInlineFrame())
  1992. doc->PrintPage((PrintDevice*) vd, 1, FALSE);
  1993. else
  1994. doc->Display(rect, vd);
  1995. vd->EndClipping();
  1996. vd->TranslateView(abs_x, abs_y);
  1997. }
  1998. else
  1999. {
  2000. vd->TranslateView(0, -abs_y);
  2001. doc->Display(rect, vd);
  2002. vd->TranslateView(0, abs_y);
  2003. }
  2004. }
  2005. else
  2006. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2007. fde->Display(vd, rect);
  2008. }
  2009. #endif // _PRINT_SUPPORT_
  2010. void FramesDocElm::DisplayBorder(VisualDevice* vd)
  2011. {
  2012. UINT32 gray = g_op_ui_info->GetSystemColor(OP_SYSTEM_COLOR_BUTTON);
  2013. UINT32 lgray = g_op_ui_info->GetSystemColor(OP_SYSTEM_COLOR_BUTTON_LIGHT);
  2014. UINT32 dgray = g_op_ui_info->GetSystemColor(OP_SYSTEM_COLOR_BUTTON_DARK);
  2015. BOOL scale_100 = !IsInDocCoords();
  2016. UINT32 old_scale = 0;
  2017. if (scale_100)
  2018. old_scale = vd->SetTemporaryScale(100);
  2019. if (frame_spacing)
  2020. {
  2021. // If a frame is not visible, clear that area so we don't show parts of old documents there.
  2022. FramesDocElm* fde = FirstChild();
  2023. if ((!fde || (GetVisualDevice() && !GetVisualDevice()->GetVisible())) && !GetWindow()->IsBackgroundTransparent())
  2024. {
  2025. // Not sure why this case happens yet but it does when nesting framesets. /emil
  2026. vd->SetBgColor(g_op_ui_info->GetSystemColor(OP_SYSTEM_COLOR_DOCUMENT_BACKGROUND));
  2027. vd->DrawBgColor(OpRect(GetAbsX(), GetAbsY(), GetWidth(), GetHeight()));
  2028. }
  2029. // Paint background between frames
  2030. vd->SetBgColor(g_op_ui_info->GetSystemColor(OP_SYSTEM_COLOR_BUTTON));
  2031. while (fde && fde->Suc())
  2032. {
  2033. FramesDocElm* fde_suc = fde->Suc();
  2034. if (IsRow())
  2035. {
  2036. int y = fde->GetY() + fde->GetHeight();
  2037. vd->DrawBgColor(OpRect(GetX(), GetY() + y, GetWidth(), fde_suc->GetY() - y));
  2038. }
  2039. else
  2040. {
  2041. int x = fde->GetX() + fde->GetWidth();
  2042. vd->DrawBgColor(OpRect(GetX() + x, GetY(), fde_suc->GetX() - x, GetHeight()));
  2043. }
  2044. fde = fde_suc;
  2045. }
  2046. UINT32 black = OP_RGB(0, 0, 0);
  2047. if (GetFrameTopBorder())
  2048. {
  2049. vd->SetColor32(dgray);
  2050. vd->DrawLine(OpPoint(GetAbsX() - 2, GetAbsY() - 2), GetWidth() + 4, TRUE, 1);
  2051. vd->SetColor32(black);
  2052. vd->DrawLine(OpPoint(GetAbsX() - 1, GetAbsY() - 1), GetWidth() + 2, TRUE, 1);
  2053. }
  2054. if (GetFrameBottomBorder())
  2055. {
  2056. vd->SetColor32(gray);
  2057. vd->DrawLine(OpPoint(GetAbsX(), GetAbsY() + GetHeight()), GetWidth(), TRUE, 1);
  2058. vd->SetColor32(lgray);
  2059. vd->DrawLine(OpPoint(GetAbsX() - 1, GetAbsY() + GetHeight() + 1), GetWidth() + 2, TRUE, 1);
  2060. }
  2061. if (GetFrameLeftBorder())
  2062. {
  2063. vd->SetColor32(dgray);
  2064. vd->DrawLine(OpPoint(GetAbsX() - 2, GetAbsY() - 2), GetHeight() + 4, FALSE, 1);
  2065. vd->SetColor32(black);
  2066. vd->DrawLine(OpPoint(GetAbsX() - 1, GetAbsY() - 1), GetHeight() + 2, FALSE, 1);
  2067. }
  2068. if (GetFrameRightBorder())
  2069. {
  2070. vd->SetColor32(gray);
  2071. vd->DrawLine(OpPoint(GetAbsX() + GetWidth(), GetAbsY() - 1), GetHeight() + 2, FALSE, 1);
  2072. vd->SetColor32(lgray);
  2073. vd->DrawLine(OpPoint(GetAbsX() + GetWidth() + 1, GetAbsY() - 2), GetHeight() + 4, FALSE, 1);
  2074. }
  2075. }
  2076. if (scale_100)
  2077. vd->SetTemporaryScale(old_scale);
  2078. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2079. fde->DisplayBorder(vd);
  2080. }
  2081. #ifdef _PRINT_SUPPORT_
  2082. OP_DOC_STATUS FramesDocElm::PrintPage(PrintDevice* pd, int page_num, BOOL selected_only)
  2083. {
  2084. FramesDocElm* fde = FirstChild();
  2085. if (fde)
  2086. {
  2087. while (fde)
  2088. {
  2089. OP_STATUS dstat = fde->PrintPage(pd, page_num, selected_only);
  2090. if (dstat == DocStatus::DOC_PAGE_OUT_OF_RANGE)
  2091. page_num -= fde->CountPages();
  2092. else
  2093. return dstat;
  2094. fde = fde->Suc();
  2095. }
  2096. return DocStatus::DOC_CANNOT_PRINT;
  2097. }
  2098. else
  2099. {
  2100. DocumentManager *old_doc_man = pd->GetDocumentManager();
  2101. pd->SetDocumentManager(doc_manager);
  2102. OP_DOC_STATUS ret = doc_manager->PrintPage(pd, page_num, selected_only);
  2103. pd->SetDocumentManager(old_doc_man);
  2104. return ret;
  2105. }
  2106. }
  2107. #endif // _PRINT_SUPPORT_
  2108. int FramesDocElm::CountPages()
  2109. {
  2110. #ifdef _PRINT_SUPPORT_
  2111. FramesDocument* doc = doc_manager->GetPrintDoc();
  2112. if (doc)
  2113. return doc->CountPages();
  2114. else
  2115. #endif // _PRINT_SUPPORT_
  2116. {
  2117. int page_count = 0;
  2118. FramesDocElm* fde = FirstChild();
  2119. while (fde)
  2120. {
  2121. page_count += fde->CountPages();
  2122. fde = fde->Suc();
  2123. }
  2124. return page_count;
  2125. }
  2126. }
  2127. LayoutMode FramesDocElm::GetLayoutMode() const
  2128. {
  2129. if (packed1.special_object)
  2130. return (LayoutMode) packed1.special_object_layout_mode;
  2131. else
  2132. return parent_frm_doc->GetLayoutMode();
  2133. }
  2134. void FramesDocElm::CheckERA_LayoutMode()
  2135. {
  2136. FramesDocument* doc = GetCurrentDoc();
  2137. if (doc)
  2138. {
  2139. if (doc && doc->IsFrameDoc())
  2140. doc->CheckERA_LayoutMode();
  2141. }
  2142. else
  2143. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2144. fde->CheckERA_LayoutMode();
  2145. }
  2146. void FramesDocElm::UpdateFrameMargins(HTML_Element *he)
  2147. {
  2148. if (he)
  2149. {
  2150. frame_margin_width = he->GetFrameMarginWidth();
  2151. frame_margin_height = he->GetFrameMarginHeight();
  2152. if (frame_margin_width == 0) // 0 isn't allowed according to spec and brakes updating (Bug 96454)
  2153. frame_margin_width = 1;
  2154. if (frame_margin_height == 0)
  2155. frame_margin_height = 1;
  2156. }
  2157. }
  2158. void FramesDocElm::SetCurrentHistoryPos(int n, BOOL parent_doc_changed, BOOL is_user_initiated)
  2159. {
  2160. FramesDocument* doc = GetCurrentDoc();
  2161. if (doc)
  2162. doc_manager->SetCurrentHistoryPos(n, parent_doc_changed, is_user_initiated);
  2163. else
  2164. {
  2165. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2166. fde->SetCurrentHistoryPos(n, parent_doc_changed, is_user_initiated);
  2167. }
  2168. }
  2169. FramesDocument* FramesDocElm::GetTopFramesDoc()
  2170. {
  2171. return GetParentFramesDoc()->GetTopFramesDoc();
  2172. }
  2173. void FramesDocElm::CheckSmartFrames(BOOL on)
  2174. {
  2175. OP_ASSERT(!IsInlineFrame());
  2176. pos.SetTranslation(0, 0);
  2177. width = 0;
  2178. height = 0;
  2179. if (frm_dev)
  2180. frm_dev->SetScrollType(on ? VisualDevice::VD_SCROLLING_NO : (VisualDevice::ScrollType) frame_scrolling);
  2181. FramesDocument* doc = GetCurrentDoc();
  2182. if (doc && doc->IsFrameDoc())
  2183. doc->CheckSmartFrames(on);
  2184. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2185. fde->CheckSmartFrames(on);
  2186. }
  2187. void FramesDocElm::ExpandFrameSize(int inc_width, int inc_height)
  2188. {
  2189. OP_ASSERT(inc_width >= 0);
  2190. OP_ASSERT(inc_height >= 0);
  2191. width += inc_width;
  2192. height += inc_height;
  2193. FramesDocElm* fde = FirstChild();
  2194. if (fde)
  2195. {
  2196. int inc_used = 0;
  2197. int child_count = 0;
  2198. for (; fde; fde = fde->Suc())
  2199. child_count++;
  2200. int child_width_inc = inc_width;
  2201. int child_height_inc = inc_height;
  2202. if (IsRow())
  2203. child_height_inc = (inc_height + child_count - 1) / child_count;
  2204. else
  2205. child_width_inc = (inc_width + child_count - 1) / child_count;
  2206. for (fde = FirstChild(); fde; fde = fde->Suc())
  2207. {
  2208. if (IsRow())
  2209. fde->pos.AppendTranslation(0, inc_used);
  2210. else
  2211. fde->pos.AppendTranslation(inc_used, 0);
  2212. fde->ExpandFrameSize(child_width_inc, child_height_inc);
  2213. if (IsRow())
  2214. {
  2215. inc_used += child_height_inc;
  2216. if (inc_used == inc_height)
  2217. child_height_inc = 0;
  2218. }
  2219. else
  2220. {
  2221. inc_used += child_width_inc;
  2222. if (inc_used == inc_width)
  2223. child_width_inc = 0;
  2224. }
  2225. }
  2226. }
  2227. else
  2228. {
  2229. FramesDocument* doc = GetCurrentDoc();
  2230. if (doc && doc->IsFrameDoc())
  2231. doc->ExpandFrameSize(inc_width, inc_height);
  2232. }
  2233. }
  2234. void FramesDocElm::CalculateFrameSizes(int frames_policy)
  2235. {
  2236. BOOL use_doc_coords = IsInDocCoords();
  2237. FramesDocElm* fde = FirstChild();
  2238. if (fde)
  2239. {
  2240. int next_y = 0;
  2241. if (frames_policy == FRAMES_POLICY_FRAME_STACKING)
  2242. {
  2243. for (; fde; fde = fde->Suc())
  2244. {
  2245. OpPoint fde_pos = fde->pos.GetTranslation();
  2246. fde_pos.y = next_y;
  2247. fde->pos.SetTranslation(fde_pos.x, fde_pos.y);
  2248. fde->width = width;
  2249. fde->CalculateFrameSizes(frames_policy);
  2250. next_y += fde->height;
  2251. }
  2252. height = next_y;
  2253. }
  2254. else if (frames_policy == FRAMES_POLICY_SMART_FRAMES)
  2255. {
  2256. int next_x = 0;
  2257. width = normal_width;
  2258. height = normal_height;
  2259. for (; fde; fde = fde->Suc())
  2260. {
  2261. OpPoint fde_pos = fde->pos.GetTranslation();
  2262. if (IsRow())
  2263. fde_pos.y = next_y;
  2264. else
  2265. fde_pos.x = next_x;
  2266. fde->pos.SetTranslation(fde_pos.x, fde_pos.y);
  2267. fde->CalculateFrameSizes(frames_policy);
  2268. if (IsRow())
  2269. {
  2270. if (width < fde->width)
  2271. width = fde->width;
  2272. next_y += fde->height;
  2273. }
  2274. else
  2275. {
  2276. if (height < fde->height)
  2277. height = fde->height;
  2278. next_x += fde->width;
  2279. }
  2280. }
  2281. if (IsRow())
  2282. height = next_y;
  2283. else
  2284. width = next_x;
  2285. for (fde = FirstChild(); fde; fde = fde->Suc())
  2286. {
  2287. if (IsRow())
  2288. {
  2289. if (width > fde->width)
  2290. fde->ExpandFrameSize(width - fde->width, 0);
  2291. }
  2292. else
  2293. {
  2294. if (height > fde->height)
  2295. fde->ExpandFrameSize(0, height - fde->height);
  2296. }
  2297. }
  2298. }
  2299. }
  2300. else
  2301. {
  2302. OP_ASSERT(!IsInlineFrame());
  2303. FramesDocument* doc = GetCurrentDoc();
  2304. if (doc)
  2305. {
  2306. if (doc && doc->IsFrameDoc())
  2307. doc->CalculateFrameSizes();
  2308. if (frames_policy == FRAMES_POLICY_FRAME_STACKING)
  2309. {
  2310. if (!HasExplicitZeroSize())
  2311. height = use_doc_coords ? doc->Height() : doc->GetVisualDevice()->ScaleToScreen(doc->Height());
  2312. else
  2313. height = 0;
  2314. }
  2315. else if (frames_policy == FRAMES_POLICY_SMART_FRAMES)
  2316. {
  2317. int doc_height = doc->Height();
  2318. int doc_width = doc->GetHtmlDocument() ? doc->GetHtmlDocument()->Width() : doc->Width();
  2319. if (!use_doc_coords)
  2320. {
  2321. doc_height = doc->GetVisualDevice()->ScaleToScreen(doc_height);
  2322. doc_width = doc->GetVisualDevice()->ScaleToScreen(doc_width);
  2323. }
  2324. width = normal_width;
  2325. height = normal_height;
  2326. if (!HasExplicitZeroSize() && height < doc_height)
  2327. height = doc_height;
  2328. if (!HasExplicitZeroSize() && width < doc_width)
  2329. width = doc_width;
  2330. }
  2331. }
  2332. }
  2333. }
  2334. void FramesDocElm::CheckFrameStacking(BOOL stack_frames)
  2335. {
  2336. SetIsRow(stack_frames || packed1.normal_row);
  2337. packed1.is_inline = stack_frames && !Parent();
  2338. pos.SetTranslation(0, 0);
  2339. width = 0;
  2340. height = 0;
  2341. if (frm_dev)
  2342. frm_dev->SetScrollType(stack_frames ? VisualDevice::VD_SCROLLING_NO : (VisualDevice::ScrollType) frame_scrolling);
  2343. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2344. fde->CheckFrameStacking(stack_frames);
  2345. }
  2346. BOOL FramesDocElm::HasExplicitZeroSize()
  2347. {
  2348. return !size_val && packed1.size_type == FRAMESET_ABSOLUTE_SIZED;
  2349. }
  2350. OP_STATUS FramesDocElm::HandleLoading(OpMessage msg, URL_ID url_id, MH_PARAM_2 user_data)
  2351. {
  2352. OP_STATUS stat = OpStatus::OK;
  2353. FramesDocElm* fde = FirstChild();
  2354. if (fde)
  2355. {
  2356. for (; fde; fde = fde->Suc())
  2357. {
  2358. stat = fde->HandleLoading(msg, url_id, user_data);
  2359. if( OpStatus::IsError(stat) )
  2360. break;
  2361. }
  2362. }
  2363. else if (!IsFrameset())
  2364. stat = doc_manager->HandleLoading((doc_manager->GetLoadStatus() == WAIT_FOR_HEADER && msg == MSG_URL_DATA_LOADED) ? MSG_HEADER_LOADED : msg, url_id, user_data);
  2365. return stat;
  2366. }
  2367. #ifdef _PRINT_SUPPORT_
  2368. void FramesDocElm::DeletePrintCopy()
  2369. {
  2370. FramesDocument* doc = doc_manager->GetCurrentDoc();
  2371. if (doc)
  2372. doc->DeletePrintCopy();
  2373. else
  2374. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2375. fde->DeletePrintCopy();
  2376. }
  2377. #endif // _PRINT_SUPPORT_
  2378. void FramesDocElm::UpdateSecurityState(BOOL include_loading_docs)
  2379. {
  2380. FramesDocument* doc = doc_manager->GetCurrentDoc();
  2381. if (doc)
  2382. doc_manager->UpdateSecurityState(include_loading_docs);
  2383. else
  2384. {
  2385. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2386. {
  2387. fde->UpdateSecurityState(include_loading_docs);
  2388. }
  2389. }
  2390. }
  2391. void FramesDocElm::AppendChildrenToList(Head* list)
  2392. {
  2393. for (FramesDocElm* fde = FirstChild(); fde; fde = FirstChild())
  2394. {
  2395. fde->AppendChildrenToList(list);
  2396. fde->Out();
  2397. if (fde->packed1.is_secondary)
  2398. OP_DELETE(fde);
  2399. else
  2400. fde->Into(list);
  2401. }
  2402. }
  2403. int FramesDocElm::CountFrames()
  2404. {
  2405. FramesDocument* doc = doc_manager->GetCurrentDoc();
  2406. if (doc || frm_dev)
  2407. {
  2408. if (doc && doc->IsFrameDoc())
  2409. return doc->CountFrames();
  2410. else
  2411. return 1;
  2412. }
  2413. else
  2414. {
  2415. int count = 0;
  2416. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2417. count += fde->CountFrames();
  2418. return count;
  2419. }
  2420. }
  2421. FramesDocElm* FramesDocElm::GetFrameByNumber(int& num)
  2422. {
  2423. FramesDocument* doc = doc_manager->GetCurrentDoc();
  2424. if (doc || frm_dev)
  2425. {
  2426. if (doc && doc->IsFrameDoc())
  2427. return doc->GetFrameByNumber(num);
  2428. else
  2429. {
  2430. num--;
  2431. if (num == 0)
  2432. return this;
  2433. else
  2434. return NULL;
  2435. }
  2436. }
  2437. else
  2438. {
  2439. FramesDocElm* frame = NULL;
  2440. for (FramesDocElm* fde = FirstChild(); !frame && fde; fde = fde->Suc())
  2441. frame = fde->GetFrameByNumber(num);
  2442. return frame;
  2443. }
  2444. }
  2445. FramesDocElm* FramesDocElm::LastLeafActive()
  2446. {
  2447. FramesDocElm *last_leaf = this;
  2448. FramesDocElm *child = last_leaf->LastChildActive();
  2449. while (child)
  2450. {
  2451. last_leaf = child;
  2452. child = last_leaf->LastChildActive();
  2453. }
  2454. return last_leaf;
  2455. }
  2456. FramesDocElm* FramesDocElm::ParentActive()
  2457. {
  2458. if (Parent())
  2459. return Parent();
  2460. return GetParentFramesDoc()->GetDocManager()->GetFrame();
  2461. }
  2462. FramesDocElm* FramesDocElm::FirstChildActive()
  2463. {
  2464. FramesDocElm *candidate = (GetCurrentDoc() && GetCurrentDoc()->GetIFrmRoot())
  2465. ? GetCurrentDoc()->GetIFrmRoot()->FirstChild() : NULL;
  2466. while (candidate)
  2467. {
  2468. if (candidate->GetVisualDevice())
  2469. {
  2470. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2471. if (frm_doc && frm_doc->GetFrmDocRoot())
  2472. {
  2473. FramesDocElm *tmp_candidate = frm_doc->GetFrmDocRoot()->FirstChildActive();
  2474. if (tmp_candidate)
  2475. return tmp_candidate;
  2476. }
  2477. else
  2478. return candidate;
  2479. }
  2480. candidate = candidate->Suc();
  2481. }
  2482. candidate = FirstChild();
  2483. while (candidate)
  2484. {
  2485. if (candidate->GetVisualDevice())
  2486. {
  2487. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2488. if (frm_doc && frm_doc->GetFrmDocRoot())
  2489. {
  2490. FramesDocElm *tmp_candidate = frm_doc->GetFrmDocRoot()->FirstChildActive();
  2491. if (tmp_candidate)
  2492. return tmp_candidate;
  2493. }
  2494. else
  2495. return candidate;
  2496. }
  2497. candidate = candidate->FirstChild();
  2498. }
  2499. return NULL;
  2500. }
  2501. FramesDocElm* FramesDocElm::NextActive()
  2502. {
  2503. FramesDocElm *candidate = FirstChildActive();
  2504. if (candidate)
  2505. return candidate;
  2506. for (FramesDocElm *leaf = this; leaf; leaf = leaf->ParentActive())
  2507. if (leaf->Suc())
  2508. {
  2509. FramesDocElm *candidate = leaf->Suc();
  2510. if (candidate->GetVisualDevice())
  2511. {
  2512. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2513. if (frm_doc && frm_doc->GetFrmDocRoot())
  2514. {
  2515. FramesDocElm *tmp_candidate = frm_doc->GetFrmDocRoot()->NextActive();
  2516. if (tmp_candidate)
  2517. return tmp_candidate;
  2518. }
  2519. else
  2520. return candidate;
  2521. }
  2522. else
  2523. {
  2524. FramesDocElm *tmp_candidate = candidate->NextActive();
  2525. if (tmp_candidate)
  2526. return tmp_candidate;
  2527. }
  2528. }
  2529. return NULL;
  2530. }
  2531. FramesDocElm* FramesDocElm::LastChildActive()
  2532. {
  2533. FramesDocElm *candidate = LastChild();
  2534. if (candidate)
  2535. {
  2536. if (candidate->GetVisualDevice())
  2537. {
  2538. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2539. if (frm_doc && frm_doc->GetFrmDocRoot())
  2540. {
  2541. FramesDocElm *tmp_candidate = frm_doc->GetFrmDocRoot()->LastChildActive();
  2542. if (tmp_candidate)
  2543. return tmp_candidate;
  2544. }
  2545. else
  2546. return candidate;
  2547. }
  2548. else
  2549. return candidate->LastChildActive();
  2550. }
  2551. candidate = (GetCurrentDoc() && GetCurrentDoc()->GetFrmDocRoot())
  2552. ? GetCurrentDoc()->GetFrmDocRoot() : NULL;
  2553. if (candidate)
  2554. {
  2555. FramesDocElm *tmp_candidate = candidate->LastChildActive();
  2556. if (tmp_candidate)
  2557. return tmp_candidate;
  2558. }
  2559. candidate = (GetCurrentDoc() && GetCurrentDoc()->GetIFrmRoot())
  2560. ? GetCurrentDoc()->GetIFrmRoot()->LastChild() : NULL;
  2561. if (candidate)
  2562. {
  2563. while (candidate)
  2564. {
  2565. if (candidate->GetVisualDevice())
  2566. {
  2567. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2568. if (frm_doc && frm_doc->GetFrmDocRoot())
  2569. {
  2570. FramesDocElm *tmp_candidate = frm_doc->GetFrmDocRoot()->LastChildActive();
  2571. if (tmp_candidate)
  2572. return tmp_candidate;
  2573. }
  2574. else
  2575. return candidate;
  2576. }
  2577. candidate = candidate->Pred();
  2578. }
  2579. }
  2580. return NULL;
  2581. }
  2582. FramesDocElm* FramesDocElm::PrevActive()
  2583. {
  2584. if (Pred())
  2585. {
  2586. FramesDocElm* leaf = Pred();
  2587. FramesDocElm* last_child = leaf->LastChildActive();
  2588. while (last_child)
  2589. {
  2590. leaf = last_child;
  2591. last_child = leaf->LastChildActive();
  2592. }
  2593. return leaf;
  2594. }
  2595. FramesDocElm *candidate = ParentActive();
  2596. if (candidate)
  2597. {
  2598. if (candidate->GetVisualDevice())
  2599. {
  2600. FramesDocument *frm_doc = candidate->GetCurrentDoc();
  2601. if (frm_doc && !frm_doc->GetFrmDocRoot())
  2602. return candidate;
  2603. }
  2604. return candidate->PrevActive();
  2605. }
  2606. return NULL;
  2607. }
  2608. OP_STATUS FramesDocElm::OnlineModeChanged()
  2609. {
  2610. if (GetCurrentDoc())
  2611. return doc_manager->OnlineModeChanged();
  2612. else
  2613. {
  2614. OP_STATUS status = OpStatus::OK;
  2615. for (FramesDocElm *child = FirstChild(); child; child = child->Suc())
  2616. if (OpStatus::IsMemoryError(child->OnlineModeChanged()))
  2617. {
  2618. OpStatus::Ignore(status);
  2619. status = OpStatus::ERR_NO_MEMORY;
  2620. }
  2621. return status;
  2622. }
  2623. }
  2624. void FramesDocElm::OnRenderingViewportChanged(const OpRect &rendering_rect)
  2625. {
  2626. FramesDocument* doc = doc_manager->GetCurrentDoc();
  2627. // Translate rect to local coordinates and clip
  2628. OpRect local_rect(rendering_rect.x - GetX(), rendering_rect.y - GetY(), rendering_rect.width, rendering_rect.height);
  2629. OpRect local_visible_rect(0, 0, GetWidth(), GetHeight());
  2630. local_visible_rect.IntersectWith(local_rect);
  2631. if (doc)
  2632. doc->OnRenderingViewportChanged(local_visible_rect);
  2633. else
  2634. for (FramesDocElm* fde = FirstChild(); fde; fde = fde->Suc())
  2635. fde->OnRenderingViewportChanged(local_visible_rect);
  2636. }
  2637. OP_STATUS FramesDocElm::SetReinitData(int history_num, BOOL visible, LayoutMode frame_layout_mode)
  2638. {
  2639. if (reinit_data)
  2640. {
  2641. if (history_num != -1)
  2642. reinit_data->m_history_num = history_num;
  2643. reinit_data->m_visible = visible;
  2644. reinit_data->m_old_layout_mode = frame_layout_mode;
  2645. return OpStatus::OK;
  2646. }
  2647. else
  2648. {
  2649. reinit_data = OP_NEW(FrameReinitData, (history_num, visible, frame_layout_mode));
  2650. if (!reinit_data)
  2651. return OpStatus::ERR_NO_MEMORY;
  2652. return OpStatus::OK;
  2653. }
  2654. }
  2655. void FramesDocElm::RemoveReinitData()
  2656. {
  2657. OP_DELETE(reinit_data);
  2658. reinit_data = NULL;
  2659. }
  2660. BOOL FramesDocElm::IsFrameRoot(FramesDocElm* head)
  2661. {
  2662. FramesDocElm* iframe_root = parent_frm_doc->GetIFrmRoot();
  2663. FramesDocElm* frame_root = parent_frm_doc->GetFrmDocRoot();
  2664. while (head)
  2665. {
  2666. if (head == iframe_root || head == frame_root)
  2667. return TRUE;
  2668. head = head->Parent();
  2669. }
  2670. return FALSE;
  2671. }
  2672. void FramesDocElm::Out()
  2673. {
  2674. #if DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2675. FramesDocument *top_doc = parent_frm_doc->GetTopDocument();
  2676. DocumentTreeIterator iter(this);
  2677. iter.SetIncludeThis();
  2678. iter.SetIncludeEmpty();
  2679. while (iter.Next())
  2680. {
  2681. FramesDocElm *fde = iter.GetFramesDocElm();
  2682. if (fde->frame_index != FRAME_NOT_IN_ROOT)
  2683. {
  2684. top_doc->OnFrameRemoved();
  2685. fde->frame_index = FRAME_NOT_IN_ROOT;
  2686. }
  2687. }
  2688. #endif // DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2689. #ifdef SCOPE_PROFILER
  2690. parent_frm_doc->GetDocManager()->OnRemoveChild(GetDocManager());
  2691. #endif // SCOPE_PROFILER
  2692. Tree::Out();
  2693. }
  2694. void FramesDocElm::Under(FramesDocElm* elm)
  2695. {
  2696. #if DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2697. FramesDocument *top_doc = parent_frm_doc->GetTopDocument();
  2698. if (IsFrameRoot(elm))
  2699. top_doc->OnFrameAdded();
  2700. frame_index = top_doc->GetNumFramesAdded();
  2701. #endif // DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2702. #ifdef SCOPE_PROFILER
  2703. parent_frm_doc->GetDocManager()->OnAddChild(GetDocManager());
  2704. #endif // SCOPE_PROFILER
  2705. Tree::Under(elm);
  2706. }
  2707. BOOL FramesDocElm::IsContentAllowed()
  2708. {
  2709. #if DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2710. return ((frame_index - parent_frm_doc->GetTopDocument()->GetNumFramesRemoved()) <= DOCHAND_MAX_FRAMES_ON_PAGE);
  2711. #else
  2712. return TRUE;
  2713. #endif // DOCHAND_MAX_FRAMES_ON_PAGE > 0
  2714. }
  2715. #ifdef NEARBY_INTERACTIVE_ITEM_DETECTION
  2716. OP_STATUS FramesDocElm::AddFrameScrollbars(OpRect& rect_of_interest, List<InteractiveItemInfo>& list)
  2717. {
  2718. OpScrollbar *h_scr, *v_scr;
  2719. OpRect clip_rect;
  2720. OpRect vis_viewport = frm_dev->GetRenderingViewport(); // This is the same as visual viewport for a frame.
  2721. OpPoint inner_pos = frm_dev->GetInnerPosition();
  2722. frm_dev->GetScrollbarObjects(&h_scr, &v_scr);
  2723. for (int i = 0; i < 2; i++)
  2724. {
  2725. OpScrollbar* current_scrollbar = i ? h_scr : v_scr;
  2726. if (!(current_scrollbar && current_scrollbar->IsVisible()))
  2727. continue;
  2728. OpRect rect = current_scrollbar->GetRect();
  2729. /* Adjust the rect position according to the document view's top left, because we want to keep it
  2730. relative to the point (in this frame), where the document's top left is. */
  2731. rect.OffsetBy(-inner_pos);
  2732. rect = frm_dev->ScaleToDoc(rect);
  2733. // Offset by visual viewport position, so that we are in the same coordinate system as rect_of_interest/
  2734. rect.OffsetBy(vis_viewport.x, vis_viewport.y);
  2735. if (!rect.Intersecting(rect_of_interest))
  2736. continue;
  2737. // Remove the part of the rect_of_interest that overlap the current scrollbar.
  2738. if (current_scrollbar->IsHorizontal())
  2739. {
  2740. if (rect_of_interest.y >= rect.y && rect.Bottom() > rect_of_interest.y)
  2741. {
  2742. INT32 diff = rect.Bottom() - rect_of_interest.y;
  2743. rect_of_interest.y += diff;
  2744. rect_of_interest.height -= diff;
  2745. }
  2746. else if (rect_of_interest.Bottom() > rect.y)
  2747. rect_of_interest.height -= rect_of_interest.Bottom() - rect.y;
  2748. }
  2749. else
  2750. {
  2751. if (rect_of_interest.x >= rect.x && rect.Right() > rect_of_interest.x)
  2752. {
  2753. INT32 diff = rect.Right() - rect_of_interest.x;
  2754. rect_of_interest.x += diff;
  2755. rect_of_interest.width -= diff;
  2756. }
  2757. else if (rect_of_interest.Right() > rect.x)
  2758. rect_of_interest.width -= rect_of_interest.Right() - rect.x;
  2759. }
  2760. if (clip_rect.IsEmpty()) // Compute that only once.
  2761. {
  2762. clip_rect = GetParentFramesDoc()->GetVisualDevice()->GetDocumentInnerViewClipRect();
  2763. GetAbsPos().ApplyInverse(clip_rect);
  2764. // Scrollbar's rect is already adjusted by the document's visual viewport top left.
  2765. clip_rect.OffsetBy(vis_viewport.x, vis_viewport.y);
  2766. }
  2767. rect.IntersectWith(clip_rect);
  2768. /* This is implied from the method's assumption about visiblity of the frame.
  2769. First of all, clip_rect can't be empty otherwise this frame can't be visible inside
  2770. top document's visual viewport at all. Secondly if scrollbar rect intersects the
  2771. rect_of_interest, which is inside the clip_rect, it must also intersect the clip_rect. */
  2772. OP_ASSERT(!rect.IsEmpty());
  2773. InteractiveItemInfo* item = InteractiveItemInfo::CreateInteractiveItemInfo(1,
  2774. InteractiveItemInfo::INTERACTIVE_ITEM_TYPE_SCROLLBAR);
  2775. if (!item)
  2776. return OpStatus::ERR_NO_MEMORY;
  2777. InteractiveItemInfo::ItemRect* rect_array = item->GetRects();
  2778. rect_array[0].rect = rect;
  2779. rect_array[0].affine_pos = NULL;
  2780. item->Into(&list);
  2781. }
  2782. return OpStatus::OK;
  2783. }
  2784. #endif // NEARBY_INTERACTIVE_ITEM_DETECTION
  2785. void FramesDocElm::SetParentLayoutInputContext(OpInputContext* context)
  2786. {
  2787. if (!frm_dev || context == parent_layout_input_ctx)
  2788. return;
  2789. parent_layout_input_ctx = context;
  2790. frm_dev->SetParentInputContext(parent_layout_input_ctx ? parent_layout_input_ctx : parent_frm_doc->GetVisualDevice(), TRUE);
  2791. }
  2792. BOOL FramesDocElm::CheckForUnloadTarget()
  2793. {
  2794. BOOL has_unload_handler = GetHasUnloadHandler();
  2795. if (!GetCheckedUnloadHandler())
  2796. {
  2797. has_unload_handler = FALSE;
  2798. FramesDocElm *fde = this;
  2799. while (FramesDocElm *lc = fde->LastChild())
  2800. fde = lc;
  2801. while (!has_unload_handler)
  2802. {
  2803. if (fde->GetCheckedUnloadHandler() && fde->GetHasUnloadHandler())
  2804. has_unload_handler = TRUE;
  2805. else if (FramesDocument *frames_doc = fde->GetCurrentDoc())
  2806. {
  2807. if (DOM_Environment *environment = frames_doc->GetDOMEnvironment())
  2808. {
  2809. if (environment->HasWindowEventHandler(ONUNLOAD))
  2810. has_unload_handler = TRUE;
  2811. }
  2812. else if (HTML_Element *fde_target = frames_doc->GetWindowEventTarget(ONUNLOAD))
  2813. has_unload_handler = fde_target->HasEventHandlerAttribute(frames_doc, ONUNLOAD);
  2814. fde->SetCheckedUnloadHandler(TRUE);
  2815. fde->SetHasUnloadHandler(has_unload_handler);
  2816. }
  2817. if (fde == this)
  2818. break;
  2819. fde = fde->Prev();
  2820. }
  2821. SetCheckedUnloadHandler(TRUE);
  2822. SetHasUnloadHandler(has_unload_handler);
  2823. }
  2824. return has_unload_handler;
  2825. }
  2826. void FramesDocElm::UpdateUnloadTarget(BOOL added)
  2827. {
  2828. if (GetCheckedUnloadHandler() && added == GetHasUnloadHandler())
  2829. return;
  2830. /* If we add or remove an unload handler, the computed
  2831. information on ancestor elements must be recomputed.
  2832. Do not recompute here but simply clear the cached
  2833. flags on the ancestors. */
  2834. FramesDocElm *fde = Parent();
  2835. while (fde)
  2836. {
  2837. fde->SetCheckedUnloadHandler(FALSE);
  2838. fde = fde->Parent();
  2839. }
  2840. /* The target of the unload addition/removal is unknown, it
  2841. may not have been for the element of this FramesDocElm.
  2842. Update the flag by doing a full check. */
  2843. SetCheckedUnloadHandler(FALSE);
  2844. CheckForUnloadTarget();
  2845. }
  2846. #ifdef SVG_SUPPORT
  2847. static BOOL
  2848. SVGShouldDisableMouseEvents(FramesDocElm* frame)
  2849. {
  2850. HTML_Element* frame_elm = frame->GetHtmlElement();
  2851. if (!frame_elm)
  2852. return FALSE;
  2853. if (frame_elm->GetNsType() != NS_HTML)
  2854. return FALSE;
  2855. switch (frame_elm->Type())
  2856. {
  2857. case Markup::HTE_IMG:
  2858. return TRUE;
  2859. case Markup::HTE_IFRAME:
  2860. return (frame_elm->GetInserted() == HE_INSERTED_BY_SVG);
  2861. case Markup::HTE_OBJECT:
  2862. if (FramesDocument* doc = frame->GetCurrentDoc())
  2863. if (LogicalDocument* logdoc = doc->GetLogicalDocument())
  2864. if (SVGImage* svg = g_svg_manager->GetSVGImage(logdoc, logdoc->GetDocRoot()))
  2865. return !svg->IsInteractive();
  2866. // Fall through.
  2867. #ifdef ON_DEMAND_PLUGIN
  2868. case Markup::HTE_EMBED:
  2869. case Markup::HTE_APPLET:
  2870. return frame_elm->IsPluginPlaceholder();
  2871. #endif // ON_DEMAND_PLUGIN
  2872. default:
  2873. return FALSE;
  2874. }
  2875. }
  2876. void
  2877. FramesDocElm::SVGCheckWantMouseEvents()
  2878. {
  2879. if (SVGShouldDisableMouseEvents(this))
  2880. {
  2881. CoreView *view = frm_dev->GetContainerView();
  2882. OP_ASSERT(view || !"View not yet (re)initialized");
  2883. if (view)
  2884. view->SetWantMouseEvents(FALSE);
  2885. }
  2886. }
  2887. #endif // SVG_SUPPORT