nsFrameSetFrame.cpp 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* rendering object for HTML <frameset> elements */
  6. #include "nsFrameSetFrame.h"
  7. #include "gfxContext.h"
  8. #include "gfxUtils.h"
  9. #include "mozilla/DebugOnly.h"
  10. #include "mozilla/gfx/2D.h"
  11. #include "mozilla/gfx/Helpers.h"
  12. #include "mozilla/Likely.h"
  13. #include "nsGenericHTMLElement.h"
  14. #include "nsAttrValueInlines.h"
  15. #include "nsLeafFrame.h"
  16. #include "nsContainerFrame.h"
  17. #include "nsLayoutUtils.h"
  18. #include "nsPresContext.h"
  19. #include "nsIPresShell.h"
  20. #include "nsGkAtoms.h"
  21. #include "nsStyleConsts.h"
  22. #include "nsStyleContext.h"
  23. #include "nsHTMLParts.h"
  24. #include "nsRenderingContext.h"
  25. #include "nsIDOMMutationEvent.h"
  26. #include "nsNameSpaceManager.h"
  27. #include "nsCSSAnonBoxes.h"
  28. #include "mozilla/StyleSetHandle.h"
  29. #include "mozilla/StyleSetHandleInlines.h"
  30. #include "mozilla/dom/Element.h"
  31. #include "nsDisplayList.h"
  32. #include "nsNodeUtils.h"
  33. #include "mozAutoDocUpdate.h"
  34. #include "mozilla/Preferences.h"
  35. #include "mozilla/dom/HTMLFrameSetElement.h"
  36. #include "mozilla/LookAndFeel.h"
  37. #include "mozilla/MouseEvents.h"
  38. #include "nsSubDocumentFrame.h"
  39. using namespace mozilla;
  40. using namespace mozilla::dom;
  41. using namespace mozilla::gfx;
  42. // masks for mEdgeVisibility
  43. #define LEFT_VIS 0x0001
  44. #define RIGHT_VIS 0x0002
  45. #define TOP_VIS 0x0004
  46. #define BOTTOM_VIS 0x0008
  47. #define ALL_VIS 0x000F
  48. #define NONE_VIS 0x0000
  49. /*******************************************************************************
  50. * nsFramesetDrag
  51. ******************************************************************************/
  52. nsFramesetDrag::nsFramesetDrag()
  53. {
  54. UnSet();
  55. }
  56. void nsFramesetDrag::Reset(bool aVertical,
  57. int32_t aIndex,
  58. int32_t aChange,
  59. nsHTMLFramesetFrame* aSource)
  60. {
  61. mVertical = aVertical;
  62. mIndex = aIndex;
  63. mChange = aChange;
  64. mSource = aSource;
  65. }
  66. void nsFramesetDrag::UnSet()
  67. {
  68. mVertical = true;
  69. mIndex = -1;
  70. mChange = 0;
  71. mSource = nullptr;
  72. }
  73. /*******************************************************************************
  74. * nsHTMLFramesetBorderFrame
  75. ******************************************************************************/
  76. class nsHTMLFramesetBorderFrame : public nsLeafFrame
  77. {
  78. public:
  79. NS_DECL_FRAMEARENA_HELPERS
  80. #ifdef DEBUG_FRAME_DUMP
  81. virtual nsresult GetFrameName(nsAString& aResult) const override;
  82. #endif
  83. virtual nsresult HandleEvent(nsPresContext* aPresContext,
  84. WidgetGUIEvent* aEvent,
  85. nsEventStatus* aEventStatus) override;
  86. virtual nsresult GetCursor(const nsPoint& aPoint,
  87. nsIFrame::Cursor& aCursor) override;
  88. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  89. const nsDisplayListSet& aLists) override;
  90. virtual void Reflow(nsPresContext* aPresContext,
  91. ReflowOutput& aDesiredSize,
  92. const ReflowInput& aReflowInput,
  93. nsReflowStatus& aStatus) override;
  94. bool GetVisibility() { return mVisibility; }
  95. void SetVisibility(bool aVisibility);
  96. void SetColor(nscolor aColor);
  97. void PaintBorder(DrawTarget* aDrawTarget, nsPoint aPt);
  98. protected:
  99. nsHTMLFramesetBorderFrame(nsStyleContext* aContext, int32_t aWidth, bool aVertical, bool aVisible);
  100. virtual ~nsHTMLFramesetBorderFrame();
  101. virtual nscoord GetIntrinsicISize() override;
  102. virtual nscoord GetIntrinsicBSize() override;
  103. // the prev and next neighbors are indexes into the row (for a horizontal border) or col (for
  104. // a vertical border) of nsHTMLFramesetFrames or nsHTMLFrames
  105. int32_t mPrevNeighbor;
  106. int32_t mNextNeighbor;
  107. nscolor mColor;
  108. int32_t mWidth;
  109. bool mVertical;
  110. bool mVisibility;
  111. bool mCanResize;
  112. friend class nsHTMLFramesetFrame;
  113. };
  114. /*******************************************************************************
  115. * nsHTMLFramesetBlankFrame
  116. ******************************************************************************/
  117. class nsHTMLFramesetBlankFrame : public nsLeafFrame
  118. {
  119. public:
  120. NS_DECL_QUERYFRAME_TARGET(nsHTMLFramesetBlankFrame)
  121. NS_DECL_QUERYFRAME
  122. NS_DECL_FRAMEARENA_HELPERS
  123. #ifdef DEBUG_FRAME_DUMP
  124. virtual nsresult GetFrameName(nsAString& aResult) const override
  125. {
  126. return MakeFrameName(NS_LITERAL_STRING("FramesetBlank"), aResult);
  127. }
  128. #endif
  129. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  130. const nsDisplayListSet& aLists) override;
  131. virtual void Reflow(nsPresContext* aPresContext,
  132. ReflowOutput& aDesiredSize,
  133. const ReflowInput& aReflowInput,
  134. nsReflowStatus& aStatus) override;
  135. protected:
  136. explicit nsHTMLFramesetBlankFrame(nsStyleContext* aContext) : nsLeafFrame(aContext) {}
  137. virtual ~nsHTMLFramesetBlankFrame();
  138. virtual nscoord GetIntrinsicISize() override;
  139. virtual nscoord GetIntrinsicBSize() override;
  140. friend class nsHTMLFramesetFrame;
  141. friend class nsHTMLFrameset;
  142. };
  143. /*******************************************************************************
  144. * nsHTMLFramesetFrame
  145. ******************************************************************************/
  146. bool nsHTMLFramesetFrame::gDragInProgress = false;
  147. #define DEFAULT_BORDER_WIDTH_PX 6
  148. nsHTMLFramesetFrame::nsHTMLFramesetFrame(nsStyleContext* aContext)
  149. : nsContainerFrame(aContext)
  150. {
  151. mNumRows = 0;
  152. mNumCols = 0;
  153. mEdgeVisibility = 0;
  154. mParentFrameborder = eFrameborder_Yes; // default
  155. mParentBorderWidth = -1; // default not set
  156. mParentBorderColor = NO_COLOR; // default not set
  157. mFirstDragPoint.x = mFirstDragPoint.y = 0;
  158. mMinDrag = nsPresContext::CSSPixelsToAppUnits(2);
  159. mNonBorderChildCount = 0;
  160. mNonBlankChildCount = 0;
  161. mDragger = nullptr;
  162. mChildCount = 0;
  163. mTopLevelFrameset = nullptr;
  164. mEdgeColors.Set(NO_COLOR);
  165. }
  166. nsHTMLFramesetFrame::~nsHTMLFramesetFrame()
  167. {
  168. }
  169. NS_QUERYFRAME_HEAD(nsHTMLFramesetFrame)
  170. NS_QUERYFRAME_ENTRY(nsHTMLFramesetFrame)
  171. NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
  172. void
  173. nsHTMLFramesetFrame::Init(nsIContent* aContent,
  174. nsContainerFrame* aParent,
  175. nsIFrame* aPrevInFlow)
  176. {
  177. nsContainerFrame::Init(aContent, aParent, aPrevInFlow);
  178. // find the highest ancestor that is a frameset
  179. nsIFrame* parentFrame = GetParent();
  180. mTopLevelFrameset = this;
  181. while (parentFrame) {
  182. nsHTMLFramesetFrame* frameset = do_QueryFrame(parentFrame);
  183. if (frameset) {
  184. mTopLevelFrameset = frameset;
  185. parentFrame = parentFrame->GetParent();
  186. } else {
  187. break;
  188. }
  189. }
  190. nsPresContext* presContext = PresContext();
  191. nsIPresShell* shell = presContext->PresShell();
  192. nsFrameborder frameborder = GetFrameBorder();
  193. int32_t borderWidth = GetBorderWidth(presContext, false);
  194. nscolor borderColor = GetBorderColor();
  195. // Get the rows= cols= data
  196. HTMLFrameSetElement* ourContent = HTMLFrameSetElement::FromContent(mContent);
  197. NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!");
  198. const nsFramesetSpec* rowSpecs = nullptr;
  199. const nsFramesetSpec* colSpecs = nullptr;
  200. // GetRowSpec and GetColSpec can fail, but when they do they set
  201. // mNumRows and mNumCols respectively to 0, so we deal with it fine.
  202. ourContent->GetRowSpec(&mNumRows, &rowSpecs);
  203. ourContent->GetColSpec(&mNumCols, &colSpecs);
  204. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < UINT_MAX / sizeof(nscoord),
  205. "Maximum value of mNumRows and mNumCols is NS_MAX_FRAMESET_SPEC_COUNT");
  206. mRowSizes = MakeUnique<nscoord[]>(mNumRows);
  207. mColSizes = MakeUnique<nscoord[]>(mNumCols);
  208. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < INT32_MAX / NS_MAX_FRAMESET_SPEC_COUNT,
  209. "Should not overflow numCells");
  210. int32_t numCells = mNumRows*mNumCols;
  211. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < UINT_MAX / sizeof(nsHTMLFramesetBorderFrame*),
  212. "Should not overflow nsHTMLFramesetBorderFrame");
  213. mVerBorders = MakeUnique<nsHTMLFramesetBorderFrame*[]>(mNumCols); // 1 more than number of ver borders
  214. for (int verX = 0; verX < mNumCols; verX++)
  215. mVerBorders[verX] = nullptr;
  216. mHorBorders = MakeUnique<nsHTMLFramesetBorderFrame*[]>(mNumRows); // 1 more than number of hor borders
  217. for (int horX = 0; horX < mNumRows; horX++)
  218. mHorBorders[horX] = nullptr;
  219. static_assert(NS_MAX_FRAMESET_SPEC_COUNT
  220. < UINT_MAX / sizeof(int32_t) / NS_MAX_FRAMESET_SPEC_COUNT,
  221. "Should not overflow numCells");
  222. static_assert(NS_MAX_FRAMESET_SPEC_COUNT
  223. < UINT_MAX / sizeof(nsFrameborder) / NS_MAX_FRAMESET_SPEC_COUNT,
  224. "Should not overflow numCells");
  225. static_assert(NS_MAX_FRAMESET_SPEC_COUNT
  226. < UINT_MAX / sizeof(nsBorderColor) / NS_MAX_FRAMESET_SPEC_COUNT,
  227. "Should not overflow numCells");
  228. mChildFrameborder = MakeUnique<nsFrameborder[]>(numCells);
  229. mChildBorderColors = MakeUnique<nsBorderColor[]>(numCells);
  230. // create the children frames; skip content which isn't <frameset> or <frame>
  231. mChildCount = 0; // number of <frame> or <frameset> children
  232. nsIFrame* frame;
  233. // number of any type of children
  234. uint32_t numChildren = mContent->GetChildCount();
  235. for (uint32_t childX = 0; childX < numChildren; childX++) {
  236. if (mChildCount == numCells) { // we have more <frame> or <frameset> than cells
  237. // Clear the lazy bits in the remaining children. Also clear
  238. // the restyle flags, like nsCSSFrameConstructor::ProcessChildren does.
  239. for (uint32_t i = childX; i < numChildren; i++) {
  240. nsIContent *child = mContent->GetChildAt(i);
  241. child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
  242. child->UnsetRestyleFlagsIfGecko();
  243. }
  244. break;
  245. }
  246. nsIContent *child = mContent->GetChildAt(childX);
  247. child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
  248. // Also clear the restyle flags in the child like
  249. // nsCSSFrameConstructor::ProcessChildren does.
  250. child->UnsetRestyleFlagsIfGecko();
  251. // IMPORTANT: This must match the conditions in
  252. // nsCSSFrameConstructor::ContentAppended/Inserted/Removed
  253. if (!child->IsHTMLElement())
  254. continue;
  255. if (child->IsAnyOfHTMLElements(nsGkAtoms::frameset, nsGkAtoms::frame)) {
  256. RefPtr<nsStyleContext> kidSC;
  257. kidSC = shell->StyleSet()->ResolveStyleFor(child->AsElement(),
  258. mStyleContext);
  259. if (child->IsHTMLElement(nsGkAtoms::frameset)) {
  260. frame = NS_NewHTMLFramesetFrame(shell, kidSC);
  261. nsHTMLFramesetFrame* childFrame = (nsHTMLFramesetFrame*)frame;
  262. childFrame->SetParentFrameborder(frameborder);
  263. childFrame->SetParentBorderWidth(borderWidth);
  264. childFrame->SetParentBorderColor(borderColor);
  265. frame->Init(child, this, nullptr);
  266. mChildBorderColors[mChildCount].Set(childFrame->GetBorderColor());
  267. } else { // frame
  268. frame = NS_NewSubDocumentFrame(shell, kidSC);
  269. frame->Init(child, this, nullptr);
  270. mChildFrameborder[mChildCount] = GetFrameBorder(child);
  271. mChildBorderColors[mChildCount].Set(GetBorderColor(child));
  272. }
  273. child->SetPrimaryFrame(frame);
  274. mFrames.AppendFrame(nullptr, frame);
  275. mChildCount++;
  276. }
  277. }
  278. mNonBlankChildCount = mChildCount;
  279. // add blank frames for frameset cells that had no content provided
  280. for (int blankX = mChildCount; blankX < numCells; blankX++) {
  281. RefPtr<nsStyleContext> pseudoStyleContext;
  282. pseudoStyleContext = shell->StyleSet()->
  283. ResolveAnonymousBoxStyle(nsCSSAnonBoxes::framesetBlank, mStyleContext);
  284. // XXX the blank frame is using the content of its parent - at some point it
  285. // should just have null content, if we support that
  286. nsHTMLFramesetBlankFrame* blankFrame = new (shell) nsHTMLFramesetBlankFrame(pseudoStyleContext);
  287. blankFrame->Init(mContent, this, nullptr);
  288. mFrames.AppendFrame(nullptr, blankFrame);
  289. mChildBorderColors[mChildCount].Set(NO_COLOR);
  290. mChildCount++;
  291. }
  292. mNonBorderChildCount = mChildCount;
  293. }
  294. void
  295. nsHTMLFramesetFrame::SetInitialChildList(ChildListID aListID,
  296. nsFrameList& aChildList)
  297. {
  298. // We do this weirdness where we create our child frames in Init(). On the
  299. // other hand, we're going to get a SetInitialChildList() with an empty list
  300. // and null list name after the frame constructor is done creating us. So
  301. // just ignore that call.
  302. if (aListID == kPrincipalList && aChildList.IsEmpty()) {
  303. return;
  304. }
  305. nsContainerFrame::SetInitialChildList(aListID, aChildList);
  306. }
  307. // XXX should this try to allocate twips based on an even pixel boundary?
  308. void nsHTMLFramesetFrame::Scale(nscoord aDesired,
  309. int32_t aNumIndicies,
  310. int32_t* aIndicies,
  311. int32_t aNumItems,
  312. int32_t* aItems)
  313. {
  314. int32_t actual = 0;
  315. int32_t i, j;
  316. // get the actual total
  317. for (i = 0; i < aNumIndicies; i++) {
  318. j = aIndicies[i];
  319. actual += aItems[j];
  320. }
  321. if (actual > 0) {
  322. float factor = (float)aDesired / (float)actual;
  323. actual = 0;
  324. // scale the items up or down
  325. for (i = 0; i < aNumIndicies; i++) {
  326. j = aIndicies[i];
  327. aItems[j] = NSToCoordRound((float)aItems[j] * factor);
  328. actual += aItems[j];
  329. }
  330. } else if (aNumIndicies != 0) {
  331. // All the specs say zero width, but we have to fill up space
  332. // somehow. Distribute it equally.
  333. nscoord width = NSToCoordRound((float)aDesired / (float)aNumIndicies);
  334. actual = width * aNumIndicies;
  335. for (i = 0; i < aNumIndicies; i++) {
  336. aItems[aIndicies[i]] = width;
  337. }
  338. }
  339. if (aNumIndicies > 0 && aDesired != actual) {
  340. int32_t unit = (aDesired > actual) ? 1 : -1;
  341. for (i=0; (i < aNumIndicies) && (aDesired != actual); i++) {
  342. j = aIndicies[i];
  343. if (j < aNumItems) {
  344. aItems[j] += unit;
  345. actual += unit;
  346. }
  347. }
  348. }
  349. }
  350. /**
  351. * Translate the rows/cols specs into an array of integer sizes for
  352. * each cell in the frameset. Sizes are allocated based on the priorities of the
  353. * specifier - fixed sizes have the highest priority, percentage sizes have the next
  354. * highest priority and relative sizes have the lowest.
  355. */
  356. void nsHTMLFramesetFrame::CalculateRowCol(nsPresContext* aPresContext,
  357. nscoord aSize,
  358. int32_t aNumSpecs,
  359. const nsFramesetSpec* aSpecs,
  360. nscoord* aValues)
  361. {
  362. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < UINT_MAX / sizeof(int32_t),
  363. "aNumSpecs maximum value is NS_MAX_FRAMESET_SPEC_COUNT");
  364. int32_t fixedTotal = 0;
  365. int32_t numFixed = 0;
  366. auto fixed = MakeUnique<int32_t[]>(aNumSpecs);
  367. int32_t numPercent = 0;
  368. auto percent = MakeUnique<int32_t[]>(aNumSpecs);
  369. int32_t relativeSums = 0;
  370. int32_t numRelative = 0;
  371. auto relative = MakeUnique<int32_t[]>(aNumSpecs);
  372. if (MOZ_UNLIKELY(!fixed || !percent || !relative)) {
  373. return; // NS_ERROR_OUT_OF_MEMORY
  374. }
  375. int32_t i, j;
  376. // initialize the fixed, percent, relative indices, allocate the fixed sizes and zero the others
  377. for (i = 0; i < aNumSpecs; i++) {
  378. aValues[i] = 0;
  379. switch (aSpecs[i].mUnit) {
  380. case eFramesetUnit_Fixed:
  381. aValues[i] = nsPresContext::CSSPixelsToAppUnits(aSpecs[i].mValue);
  382. fixedTotal += aValues[i];
  383. fixed[numFixed] = i;
  384. numFixed++;
  385. break;
  386. case eFramesetUnit_Percent:
  387. percent[numPercent] = i;
  388. numPercent++;
  389. break;
  390. case eFramesetUnit_Relative:
  391. relative[numRelative] = i;
  392. numRelative++;
  393. relativeSums += aSpecs[i].mValue;
  394. break;
  395. }
  396. }
  397. // scale the fixed sizes if they total too much (or too little and there aren't any percent or relative)
  398. if ((fixedTotal > aSize) || ((fixedTotal < aSize) && (0 == numPercent) && (0 == numRelative))) {
  399. Scale(aSize, numFixed, fixed.get(), aNumSpecs, aValues);
  400. return;
  401. }
  402. int32_t percentMax = aSize - fixedTotal;
  403. int32_t percentTotal = 0;
  404. // allocate the percentage sizes from what is left over from the fixed allocation
  405. for (i = 0; i < numPercent; i++) {
  406. j = percent[i];
  407. aValues[j] = NSToCoordRound((float)aSpecs[j].mValue * (float)aSize / 100.0f);
  408. percentTotal += aValues[j];
  409. }
  410. // scale the percent sizes if they total too much (or too little and there aren't any relative)
  411. if ((percentTotal > percentMax) || ((percentTotal < percentMax) && (0 == numRelative))) {
  412. Scale(percentMax, numPercent, percent.get(), aNumSpecs, aValues);
  413. return;
  414. }
  415. int32_t relativeMax = percentMax - percentTotal;
  416. int32_t relativeTotal = 0;
  417. // allocate the relative sizes from what is left over from the percent allocation
  418. for (i = 0; i < numRelative; i++) {
  419. j = relative[i];
  420. aValues[j] = NSToCoordRound((float)aSpecs[j].mValue * (float)relativeMax / (float)relativeSums);
  421. relativeTotal += aValues[j];
  422. }
  423. // scale the relative sizes if they take up too much or too little
  424. if (relativeTotal != relativeMax) {
  425. Scale(relativeMax, numRelative, relative.get(), aNumSpecs, aValues);
  426. }
  427. }
  428. /**
  429. * Translate the rows/cols integer sizes into an array of specs for
  430. * each cell in the frameset. Reverse of CalculateRowCol() behaviour.
  431. * This allows us to maintain the user size info through reflows.
  432. */
  433. void nsHTMLFramesetFrame::GenerateRowCol(nsPresContext* aPresContext,
  434. nscoord aSize,
  435. int32_t aNumSpecs,
  436. const nsFramesetSpec* aSpecs,
  437. nscoord* aValues,
  438. nsString& aNewAttr)
  439. {
  440. int32_t i;
  441. for (i = 0; i < aNumSpecs; i++) {
  442. if (!aNewAttr.IsEmpty())
  443. aNewAttr.Append(char16_t(','));
  444. switch (aSpecs[i].mUnit) {
  445. case eFramesetUnit_Fixed:
  446. aNewAttr.AppendInt(nsPresContext::AppUnitsToIntCSSPixels(aValues[i]));
  447. break;
  448. case eFramesetUnit_Percent: // XXX Only accurate to 1%, need 1 pixel
  449. case eFramesetUnit_Relative:
  450. // Add 0.5 to the percentage to make rounding work right.
  451. aNewAttr.AppendInt(uint32_t((100.0*aValues[i])/aSize + 0.5));
  452. aNewAttr.Append(char16_t('%'));
  453. break;
  454. }
  455. }
  456. }
  457. int32_t nsHTMLFramesetFrame::GetBorderWidth(nsPresContext* aPresContext,
  458. bool aTakeForcingIntoAccount)
  459. {
  460. nsFrameborder frameborder = GetFrameBorder();
  461. if (frameborder == eFrameborder_No) {
  462. return 0;
  463. }
  464. nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
  465. if (content) {
  466. const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::border);
  467. if (attr) {
  468. int32_t intVal = 0;
  469. if (attr->Type() == nsAttrValue::eInteger) {
  470. intVal = attr->GetIntegerValue();
  471. if (intVal < 0) {
  472. intVal = 0;
  473. }
  474. }
  475. return nsPresContext::CSSPixelsToAppUnits(intVal);
  476. }
  477. }
  478. if (mParentBorderWidth >= 0) {
  479. return mParentBorderWidth;
  480. }
  481. return nsPresContext::CSSPixelsToAppUnits(DEFAULT_BORDER_WIDTH_PX);
  482. }
  483. void
  484. nsHTMLFramesetFrame::GetDesiredSize(nsPresContext* aPresContext,
  485. const ReflowInput& aReflowInput,
  486. ReflowOutput& aDesiredSize)
  487. {
  488. WritingMode wm = aReflowInput.GetWritingMode();
  489. LogicalSize desiredSize(wm);
  490. nsHTMLFramesetFrame* framesetParent = do_QueryFrame(GetParent());
  491. if (nullptr == framesetParent) {
  492. if (aPresContext->IsPaginated()) {
  493. // XXX This needs to be changed when framesets paginate properly
  494. desiredSize.ISize(wm) = aReflowInput.AvailableISize();
  495. desiredSize.BSize(wm) = aReflowInput.AvailableBSize();
  496. } else {
  497. LogicalSize area(wm, aPresContext->GetVisibleArea().Size());
  498. desiredSize.ISize(wm) = area.ISize(wm);
  499. desiredSize.BSize(wm) = area.BSize(wm);
  500. }
  501. } else {
  502. LogicalSize size(wm);
  503. framesetParent->GetSizeOfChild(this, wm, size);
  504. desiredSize.ISize(wm) = size.ISize(wm);
  505. desiredSize.BSize(wm) = size.BSize(wm);
  506. }
  507. aDesiredSize.SetSize(wm, desiredSize);
  508. }
  509. // only valid for non border children
  510. void nsHTMLFramesetFrame::GetSizeOfChildAt(int32_t aIndexInParent,
  511. WritingMode aWM,
  512. LogicalSize& aSize,
  513. nsIntPoint& aCellIndex)
  514. {
  515. int32_t row = aIndexInParent / mNumCols;
  516. int32_t col = aIndexInParent - (row * mNumCols); // remainder from dividing index by mNumCols
  517. if ((row < mNumRows) && (col < mNumCols)) {
  518. aSize.ISize(aWM) = mColSizes[col];
  519. aSize.BSize(aWM) = mRowSizes[row];
  520. aCellIndex.x = col;
  521. aCellIndex.y = row;
  522. } else {
  523. aSize.SizeTo(aWM, 0, 0);
  524. aCellIndex.x = aCellIndex.y = 0;
  525. }
  526. }
  527. // only valid for non border children
  528. void nsHTMLFramesetFrame::GetSizeOfChild(nsIFrame* aChild,
  529. WritingMode aWM,
  530. LogicalSize& aSize)
  531. {
  532. // Reflow only creates children frames for <frameset> and <frame> content.
  533. // this assumption is used here
  534. int i = 0;
  535. for (nsIFrame* child : mFrames) {
  536. if (aChild == child) {
  537. nsIntPoint ignore;
  538. GetSizeOfChildAt(i, aWM, aSize, ignore);
  539. return;
  540. }
  541. i++;
  542. }
  543. aSize.SizeTo(aWM, 0, 0);
  544. }
  545. nsresult nsHTMLFramesetFrame::HandleEvent(nsPresContext* aPresContext,
  546. WidgetGUIEvent* aEvent,
  547. nsEventStatus* aEventStatus)
  548. {
  549. NS_ENSURE_ARG_POINTER(aEventStatus);
  550. if (mDragger) {
  551. // the nsFramesetBorderFrame has captured NS_MOUSE_DOWN
  552. switch (aEvent->mMessage) {
  553. case eMouseMove:
  554. MouseDrag(aPresContext, aEvent);
  555. break;
  556. case eMouseUp:
  557. if (aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
  558. EndMouseDrag(aPresContext);
  559. }
  560. break;
  561. default:
  562. break;
  563. }
  564. *aEventStatus = nsEventStatus_eConsumeNoDefault;
  565. } else {
  566. *aEventStatus = nsEventStatus_eIgnore;
  567. }
  568. return NS_OK;
  569. }
  570. nsresult
  571. nsHTMLFramesetFrame::GetCursor(const nsPoint& aPoint,
  572. nsIFrame::Cursor& aCursor)
  573. {
  574. if (mDragger) {
  575. aCursor.mCursor = (mDragger->mVertical) ? NS_STYLE_CURSOR_EW_RESIZE : NS_STYLE_CURSOR_NS_RESIZE;
  576. } else {
  577. aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
  578. }
  579. return NS_OK;
  580. }
  581. void
  582. nsHTMLFramesetFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
  583. const nsDisplayListSet& aLists)
  584. {
  585. BuildDisplayListForInline(aBuilder, aLists);
  586. if (mDragger && aBuilder->IsForEventDelivery()) {
  587. aLists.Content()->AppendNewToTop(
  588. new (aBuilder) nsDisplayEventReceiver(aBuilder, this));
  589. }
  590. }
  591. void
  592. nsHTMLFramesetFrame::ReflowPlaceChild(nsIFrame* aChild,
  593. nsPresContext* aPresContext,
  594. const ReflowInput& aReflowInput,
  595. nsPoint& aOffset,
  596. nsSize& aSize,
  597. nsIntPoint* aCellIndex)
  598. {
  599. // reflow the child
  600. ReflowInput reflowInput(aPresContext, aReflowInput, aChild,
  601. LogicalSize(aChild->GetWritingMode(), aSize));
  602. reflowInput.SetComputedWidth(std::max(0, aSize.width - reflowInput.ComputedPhysicalBorderPadding().LeftRight()));
  603. reflowInput.SetComputedHeight(std::max(0, aSize.height - reflowInput.ComputedPhysicalBorderPadding().TopBottom()));
  604. ReflowOutput reflowOutput(aReflowInput);
  605. reflowOutput.Width() = aSize.width;
  606. reflowOutput.Height() = aSize.height;
  607. nsReflowStatus status;
  608. ReflowChild(aChild, aPresContext, reflowOutput, reflowInput, aOffset.x,
  609. aOffset.y, 0, status);
  610. NS_ASSERTION(NS_FRAME_IS_COMPLETE(status), "bad status");
  611. // Place and size the child
  612. reflowOutput.Width() = aSize.width;
  613. reflowOutput.Height() = aSize.height;
  614. FinishReflowChild(aChild, aPresContext, reflowOutput, nullptr, aOffset.x, aOffset.y, 0);
  615. }
  616. static
  617. nsFrameborder GetFrameBorderHelper(nsGenericHTMLElement* aContent)
  618. {
  619. if (nullptr != aContent) {
  620. const nsAttrValue* attr = aContent->GetParsedAttr(nsGkAtoms::frameborder);
  621. if (attr && attr->Type() == nsAttrValue::eEnum) {
  622. switch (attr->GetEnumValue())
  623. {
  624. case NS_STYLE_FRAME_YES:
  625. case NS_STYLE_FRAME_1:
  626. return eFrameborder_Yes;
  627. case NS_STYLE_FRAME_NO:
  628. case NS_STYLE_FRAME_0:
  629. return eFrameborder_No;
  630. }
  631. }
  632. }
  633. return eFrameborder_Notset;
  634. }
  635. nsFrameborder nsHTMLFramesetFrame::GetFrameBorder()
  636. {
  637. nsFrameborder result = eFrameborder_Notset;
  638. nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
  639. if (content) {
  640. result = GetFrameBorderHelper(content);
  641. }
  642. if (eFrameborder_Notset == result) {
  643. return mParentFrameborder;
  644. }
  645. return result;
  646. }
  647. nsFrameborder nsHTMLFramesetFrame::GetFrameBorder(nsIContent* aContent)
  648. {
  649. nsFrameborder result = eFrameborder_Notset;
  650. nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(aContent);
  651. if (content) {
  652. result = GetFrameBorderHelper(content);
  653. }
  654. if (eFrameborder_Notset == result) {
  655. return GetFrameBorder();
  656. }
  657. return result;
  658. }
  659. nscolor nsHTMLFramesetFrame::GetBorderColor()
  660. {
  661. nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
  662. if (content) {
  663. const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::bordercolor);
  664. if (attr) {
  665. nscolor color;
  666. if (attr->GetColorValue(color)) {
  667. return color;
  668. }
  669. }
  670. }
  671. return mParentBorderColor;
  672. }
  673. nscolor nsHTMLFramesetFrame::GetBorderColor(nsIContent* aContent)
  674. {
  675. nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(aContent);
  676. if (content) {
  677. const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::bordercolor);
  678. if (attr) {
  679. nscolor color;
  680. if (attr->GetColorValue(color)) {
  681. return color;
  682. }
  683. }
  684. }
  685. return GetBorderColor();
  686. }
  687. void
  688. nsHTMLFramesetFrame::Reflow(nsPresContext* aPresContext,
  689. ReflowOutput& aDesiredSize,
  690. const ReflowInput& aReflowInput,
  691. nsReflowStatus& aStatus)
  692. {
  693. MarkInReflow();
  694. DO_GLOBAL_REFLOW_COUNT("nsHTMLFramesetFrame");
  695. DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
  696. nsIPresShell *shell = aPresContext->PresShell();
  697. StyleSetHandle styleSet = shell->StyleSet();
  698. GetParent()->AddStateBits(NS_FRAME_CONTAINS_RELATIVE_BSIZE);
  699. //printf("FramesetFrame2::Reflow %X (%d,%d) \n", this, aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight());
  700. // Always get the size so that the caller knows how big we are
  701. GetDesiredSize(aPresContext, aReflowInput, aDesiredSize);
  702. nscoord width = (aDesiredSize.Width() <= aReflowInput.AvailableWidth())
  703. ? aDesiredSize.Width() : aReflowInput.AvailableWidth();
  704. nscoord height = (aDesiredSize.Height() <= aReflowInput.AvailableHeight())
  705. ? aDesiredSize.Height() : aReflowInput.AvailableHeight();
  706. // We might be reflowed more than once with NS_FRAME_FIRST_REFLOW;
  707. // that's allowed. (Though it will only happen for misuse of frameset
  708. // that includes it within other content.) So measure firstTime by
  709. // what we care about, which is whether we've processed the data we
  710. // process below if firstTime is true.
  711. MOZ_ASSERT(!mChildFrameborder == !mChildBorderColors);
  712. bool firstTime = !!mChildFrameborder;
  713. // subtract out the width of all of the potential borders. There are
  714. // only borders between <frame>s. There are none on the edges (e.g the
  715. // leftmost <frame> has no left border).
  716. int32_t borderWidth = GetBorderWidth(aPresContext, true);
  717. width -= (mNumCols - 1) * borderWidth;
  718. if (width < 0) width = 0;
  719. height -= (mNumRows - 1) * borderWidth;
  720. if (height < 0) height = 0;
  721. HTMLFrameSetElement* ourContent = HTMLFrameSetElement::FromContent(mContent);
  722. NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!");
  723. const nsFramesetSpec* rowSpecs = nullptr;
  724. const nsFramesetSpec* colSpecs = nullptr;
  725. int32_t rows = 0;
  726. int32_t cols = 0;
  727. ourContent->GetRowSpec(&rows, &rowSpecs);
  728. ourContent->GetColSpec(&cols, &colSpecs);
  729. // If the number of cols or rows has changed, the frame for the frameset
  730. // will be re-created.
  731. if (mNumRows != rows || mNumCols != cols) {
  732. aStatus = NS_FRAME_COMPLETE;
  733. mDrag.UnSet();
  734. NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
  735. return;
  736. }
  737. CalculateRowCol(aPresContext, width, mNumCols, colSpecs, mColSizes.get());
  738. CalculateRowCol(aPresContext, height, mNumRows, rowSpecs, mRowSizes.get());
  739. UniquePtr<bool[]> verBordersVis; // vertical borders visibility
  740. UniquePtr<nscolor[]> verBorderColors;
  741. UniquePtr<bool[]> horBordersVis; // horizontal borders visibility
  742. UniquePtr<nscolor[]> horBorderColors;
  743. nscolor borderColor = GetBorderColor();
  744. nsFrameborder frameborder = GetFrameBorder();
  745. if (firstTime) {
  746. // Check for overflow in memory allocations using mNumCols and mNumRows
  747. // which have a maxium value of NS_MAX_FRAMESET_SPEC_COUNT.
  748. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < UINT_MAX / sizeof(bool),
  749. "Check for overflow");
  750. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < UINT_MAX / sizeof(nscolor),
  751. "Check for overflow");
  752. verBordersVis = MakeUnique<bool[]>(mNumCols);
  753. verBorderColors = MakeUnique<nscolor[]>(mNumCols);
  754. for (int verX = 0; verX < mNumCols; verX++) {
  755. verBordersVis[verX] = false;
  756. verBorderColors[verX] = NO_COLOR;
  757. }
  758. horBordersVis = MakeUnique<bool[]>(mNumRows);
  759. horBorderColors = MakeUnique<nscolor[]>(mNumRows);
  760. for (int horX = 0; horX < mNumRows; horX++) {
  761. horBordersVis[horX] = false;
  762. horBorderColors[horX] = NO_COLOR;
  763. }
  764. }
  765. // reflow the children
  766. int32_t lastRow = 0;
  767. int32_t lastCol = 0;
  768. int32_t borderChildX = mNonBorderChildCount; // index of border children
  769. nsHTMLFramesetBorderFrame* borderFrame = nullptr;
  770. nsPoint offset(0,0);
  771. nsSize size, lastSize;
  772. WritingMode wm = GetWritingMode();
  773. LogicalSize logicalSize(wm);
  774. nsIFrame* child = mFrames.FirstChild();
  775. for (int32_t childX = 0; childX < mNonBorderChildCount; childX++) {
  776. nsIntPoint cellIndex;
  777. GetSizeOfChildAt(childX, wm, logicalSize, cellIndex);
  778. size = logicalSize.GetPhysicalSize(wm);
  779. if (lastRow != cellIndex.y) { // changed to next row
  780. offset.x = 0;
  781. offset.y += lastSize.height;
  782. if (firstTime) { // create horizontal border
  783. RefPtr<nsStyleContext> pseudoStyleContext;
  784. pseudoStyleContext = styleSet->
  785. ResolveAnonymousBoxStyle(nsCSSAnonBoxes::horizontalFramesetBorder,
  786. mStyleContext);
  787. borderFrame = new (shell) nsHTMLFramesetBorderFrame(pseudoStyleContext,
  788. borderWidth,
  789. false,
  790. false);
  791. borderFrame->Init(mContent, this, nullptr);
  792. mChildCount++;
  793. mFrames.AppendFrame(nullptr, borderFrame);
  794. mHorBorders[cellIndex.y-1] = borderFrame;
  795. // set the neighbors for determining drag boundaries
  796. borderFrame->mPrevNeighbor = lastRow;
  797. borderFrame->mNextNeighbor = cellIndex.y;
  798. } else {
  799. borderFrame = (nsHTMLFramesetBorderFrame*)mFrames.FrameAt(borderChildX);
  800. borderFrame->mWidth = borderWidth;
  801. borderChildX++;
  802. }
  803. nsSize borderSize(aDesiredSize.Width(), borderWidth);
  804. ReflowPlaceChild(borderFrame, aPresContext, aReflowInput, offset, borderSize);
  805. borderFrame = nullptr;
  806. offset.y += borderWidth;
  807. } else {
  808. if (cellIndex.x > 0) { // moved to next col in same row
  809. if (0 == cellIndex.y) { // in 1st row
  810. if (firstTime) { // create vertical border
  811. RefPtr<nsStyleContext> pseudoStyleContext;
  812. pseudoStyleContext = styleSet->
  813. ResolveAnonymousBoxStyle(nsCSSAnonBoxes::verticalFramesetBorder,
  814. mStyleContext);
  815. borderFrame = new (shell) nsHTMLFramesetBorderFrame(pseudoStyleContext,
  816. borderWidth,
  817. true,
  818. false);
  819. borderFrame->Init(mContent, this, nullptr);
  820. mChildCount++;
  821. mFrames.AppendFrame(nullptr, borderFrame);
  822. mVerBorders[cellIndex.x-1] = borderFrame;
  823. // set the neighbors for determining drag boundaries
  824. borderFrame->mPrevNeighbor = lastCol;
  825. borderFrame->mNextNeighbor = cellIndex.x;
  826. } else {
  827. borderFrame = (nsHTMLFramesetBorderFrame*)mFrames.FrameAt(borderChildX);
  828. borderFrame->mWidth = borderWidth;
  829. borderChildX++;
  830. }
  831. nsSize borderSize(borderWidth, aDesiredSize.Height());
  832. ReflowPlaceChild(borderFrame, aPresContext, aReflowInput, offset, borderSize);
  833. borderFrame = nullptr;
  834. }
  835. offset.x += borderWidth;
  836. }
  837. }
  838. ReflowPlaceChild(child, aPresContext, aReflowInput, offset, size, &cellIndex);
  839. if (firstTime) {
  840. int32_t childVis;
  841. nsHTMLFramesetFrame* framesetFrame = do_QueryFrame(child);
  842. nsSubDocumentFrame* subdocFrame;
  843. if (framesetFrame) {
  844. childVis = framesetFrame->mEdgeVisibility;
  845. mChildBorderColors[childX] = framesetFrame->mEdgeColors;
  846. } else if ((subdocFrame = do_QueryFrame(child))) {
  847. if (eFrameborder_Yes == mChildFrameborder[childX]) {
  848. childVis = ALL_VIS;
  849. } else if (eFrameborder_No == mChildFrameborder[childX]) {
  850. childVis = NONE_VIS;
  851. } else { // notset
  852. childVis = (eFrameborder_No == frameborder) ? NONE_VIS : ALL_VIS;
  853. }
  854. } else { // blank
  855. #ifdef DEBUG
  856. nsHTMLFramesetBlankFrame* blank = do_QueryFrame(child);
  857. MOZ_ASSERT(blank, "unexpected child frame type");
  858. #endif
  859. childVis = NONE_VIS;
  860. }
  861. nsBorderColor childColors = mChildBorderColors[childX];
  862. // set the visibility, color of our edge borders based on children
  863. if (0 == cellIndex.x) {
  864. if (!(mEdgeVisibility & LEFT_VIS)) {
  865. mEdgeVisibility |= (LEFT_VIS & childVis);
  866. }
  867. if (NO_COLOR == mEdgeColors.mLeft) {
  868. mEdgeColors.mLeft = childColors.mLeft;
  869. }
  870. }
  871. if (0 == cellIndex.y) {
  872. if (!(mEdgeVisibility & TOP_VIS)) {
  873. mEdgeVisibility |= (TOP_VIS & childVis);
  874. }
  875. if (NO_COLOR == mEdgeColors.mTop) {
  876. mEdgeColors.mTop = childColors.mTop;
  877. }
  878. }
  879. if (mNumCols-1 == cellIndex.x) {
  880. if (!(mEdgeVisibility & RIGHT_VIS)) {
  881. mEdgeVisibility |= (RIGHT_VIS & childVis);
  882. }
  883. if (NO_COLOR == mEdgeColors.mRight) {
  884. mEdgeColors.mRight = childColors.mRight;
  885. }
  886. }
  887. if (mNumRows-1 == cellIndex.y) {
  888. if (!(mEdgeVisibility & BOTTOM_VIS)) {
  889. mEdgeVisibility |= (BOTTOM_VIS & childVis);
  890. }
  891. if (NO_COLOR == mEdgeColors.mBottom) {
  892. mEdgeColors.mBottom = childColors.mBottom;
  893. }
  894. }
  895. // set the visibility of borders that the child may affect
  896. if (childVis & RIGHT_VIS) {
  897. verBordersVis[cellIndex.x] = true;
  898. }
  899. if (childVis & BOTTOM_VIS) {
  900. horBordersVis[cellIndex.y] = true;
  901. }
  902. if ((cellIndex.x > 0) && (childVis & LEFT_VIS)) {
  903. verBordersVis[cellIndex.x-1] = true;
  904. }
  905. if ((cellIndex.y > 0) && (childVis & TOP_VIS)) {
  906. horBordersVis[cellIndex.y-1] = true;
  907. }
  908. // set the colors of borders that the child may affect
  909. if (NO_COLOR == verBorderColors[cellIndex.x]) {
  910. verBorderColors[cellIndex.x] = mChildBorderColors[childX].mRight;
  911. }
  912. if (NO_COLOR == horBorderColors[cellIndex.y]) {
  913. horBorderColors[cellIndex.y] = mChildBorderColors[childX].mBottom;
  914. }
  915. if ((cellIndex.x > 0) && (NO_COLOR == verBorderColors[cellIndex.x-1])) {
  916. verBorderColors[cellIndex.x-1] = mChildBorderColors[childX].mLeft;
  917. }
  918. if ((cellIndex.y > 0) && (NO_COLOR == horBorderColors[cellIndex.y-1])) {
  919. horBorderColors[cellIndex.y-1] = mChildBorderColors[childX].mTop;
  920. }
  921. }
  922. lastRow = cellIndex.y;
  923. lastCol = cellIndex.x;
  924. lastSize = size;
  925. offset.x += size.width;
  926. child = child->GetNextSibling();
  927. }
  928. if (firstTime) {
  929. nscolor childColor;
  930. // set the visibility, color, mouse sensitivity of borders
  931. for (int verX = 0; verX < mNumCols-1; verX++) {
  932. if (mVerBorders[verX]) {
  933. mVerBorders[verX]->SetVisibility(verBordersVis[verX]);
  934. SetBorderResize(mVerBorders[verX]);
  935. childColor = (NO_COLOR == verBorderColors[verX]) ? borderColor : verBorderColors[verX];
  936. mVerBorders[verX]->SetColor(childColor);
  937. }
  938. }
  939. for (int horX = 0; horX < mNumRows-1; horX++) {
  940. if (mHorBorders[horX]) {
  941. mHorBorders[horX]->SetVisibility(horBordersVis[horX]);
  942. SetBorderResize(mHorBorders[horX]);
  943. childColor = (NO_COLOR == horBorderColors[horX]) ? borderColor : horBorderColors[horX];
  944. mHorBorders[horX]->SetColor(childColor);
  945. }
  946. }
  947. mChildFrameborder.reset();
  948. mChildBorderColors.reset();
  949. }
  950. aStatus = NS_FRAME_COMPLETE;
  951. mDrag.UnSet();
  952. aDesiredSize.SetOverflowAreasToDesiredBounds();
  953. FinishAndStoreOverflow(&aDesiredSize);
  954. NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
  955. }
  956. nsIAtom*
  957. nsHTMLFramesetFrame::GetType() const
  958. {
  959. return nsGkAtoms::frameSetFrame;
  960. }
  961. #ifdef DEBUG_FRAME_DUMP
  962. nsresult
  963. nsHTMLFramesetFrame::GetFrameName(nsAString& aResult) const
  964. {
  965. return MakeFrameName(NS_LITERAL_STRING("Frameset"), aResult);
  966. }
  967. #endif
  968. bool
  969. nsHTMLFramesetFrame::IsLeaf() const
  970. {
  971. // We handle constructing our kids manually
  972. return true;
  973. }
  974. bool
  975. nsHTMLFramesetFrame::CanResize(bool aVertical,
  976. bool aLeft)
  977. {
  978. int32_t childX;
  979. int32_t startX;
  980. if (aVertical) {
  981. startX = (aLeft) ? 0 : mNumCols-1;
  982. for (childX = startX; childX < mNonBorderChildCount; childX += mNumCols) {
  983. if (!CanChildResize(aVertical, aLeft, childX)) {
  984. return false;
  985. }
  986. }
  987. } else {
  988. startX = (aLeft) ? 0 : (mNumRows - 1) * mNumCols;
  989. int32_t endX = startX + mNumCols;
  990. for (childX = startX; childX < endX; childX++) {
  991. if (!CanChildResize(aVertical, aLeft, childX)) {
  992. return false;
  993. }
  994. }
  995. }
  996. return true;
  997. }
  998. bool
  999. nsHTMLFramesetFrame::GetNoResize(nsIFrame* aChildFrame)
  1000. {
  1001. nsIContent* content = aChildFrame->GetContent();
  1002. return content && content->HasAttr(kNameSpaceID_None, nsGkAtoms::noresize);
  1003. }
  1004. bool
  1005. nsHTMLFramesetFrame::CanChildResize(bool aVertical, bool aLeft, int32_t aChildX)
  1006. {
  1007. nsIFrame* child = mFrames.FrameAt(aChildX);
  1008. nsHTMLFramesetFrame* frameset = do_QueryFrame(child);
  1009. return frameset ? frameset->CanResize(aVertical, aLeft) : !GetNoResize(child);
  1010. }
  1011. // This calculates and sets the resizability of all border frames
  1012. void
  1013. nsHTMLFramesetFrame::RecalculateBorderResize()
  1014. {
  1015. if (!mContent) {
  1016. return;
  1017. }
  1018. static_assert(NS_MAX_FRAMESET_SPEC_COUNT < INT32_MAX / NS_MAX_FRAMESET_SPEC_COUNT,
  1019. "Check for overflow");
  1020. static_assert(NS_MAX_FRAMESET_SPEC_COUNT
  1021. < UINT_MAX / sizeof(int32_t) / NS_MAX_FRAMESET_SPEC_COUNT,
  1022. "Check for overflow");
  1023. // set the visibility and mouse sensitivity of borders
  1024. int32_t verX;
  1025. for (verX = 0; verX < mNumCols-1; verX++) {
  1026. if (mVerBorders[verX]) {
  1027. mVerBorders[verX]->mCanResize = true;
  1028. SetBorderResize(mVerBorders[verX]);
  1029. }
  1030. }
  1031. int32_t horX;
  1032. for (horX = 0; horX < mNumRows-1; horX++) {
  1033. if (mHorBorders[horX]) {
  1034. mHorBorders[horX]->mCanResize = true;
  1035. SetBorderResize(mHorBorders[horX]);
  1036. }
  1037. }
  1038. }
  1039. void
  1040. nsHTMLFramesetFrame::SetBorderResize(nsHTMLFramesetBorderFrame* aBorderFrame)
  1041. {
  1042. if (aBorderFrame->mVertical) {
  1043. for (int rowX = 0; rowX < mNumRows; rowX++) {
  1044. int32_t childX = aBorderFrame->mPrevNeighbor + (rowX * mNumCols);
  1045. if (!CanChildResize(true, false, childX) ||
  1046. !CanChildResize(true, true, childX+1)) {
  1047. aBorderFrame->mCanResize = false;
  1048. }
  1049. }
  1050. } else {
  1051. int32_t childX = aBorderFrame->mPrevNeighbor * mNumCols;
  1052. int32_t endX = childX + mNumCols;
  1053. for (; childX < endX; childX++) {
  1054. if (!CanChildResize(false, false, childX)) {
  1055. aBorderFrame->mCanResize = false;
  1056. }
  1057. }
  1058. endX = endX + mNumCols;
  1059. for (; childX < endX; childX++) {
  1060. if (!CanChildResize(false, true, childX)) {
  1061. aBorderFrame->mCanResize = false;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. void
  1067. nsHTMLFramesetFrame::StartMouseDrag(nsPresContext* aPresContext,
  1068. nsHTMLFramesetBorderFrame* aBorder,
  1069. WidgetGUIEvent* aEvent)
  1070. {
  1071. #if 0
  1072. int32_t index;
  1073. IndexOf(aBorder, index);
  1074. NS_ASSERTION((nullptr != aBorder) && (index >= 0), "invalid dragger");
  1075. #endif
  1076. nsIPresShell::SetCapturingContent(GetContent(), CAPTURE_IGNOREALLOWED);
  1077. mDragger = aBorder;
  1078. mFirstDragPoint = aEvent->mRefPoint;
  1079. // Store the original frame sizes
  1080. if (mDragger->mVertical) {
  1081. mPrevNeighborOrigSize = mColSizes[mDragger->mPrevNeighbor];
  1082. mNextNeighborOrigSize = mColSizes[mDragger->mNextNeighbor];
  1083. } else {
  1084. mPrevNeighborOrigSize = mRowSizes[mDragger->mPrevNeighbor];
  1085. mNextNeighborOrigSize = mRowSizes[mDragger->mNextNeighbor];
  1086. }
  1087. gDragInProgress = true;
  1088. }
  1089. void
  1090. nsHTMLFramesetFrame::MouseDrag(nsPresContext* aPresContext,
  1091. WidgetGUIEvent* aEvent)
  1092. {
  1093. // if the capture ended, reset the drag state
  1094. if (nsIPresShell::GetCapturingContent() != GetContent()) {
  1095. mDragger = nullptr;
  1096. gDragInProgress = false;
  1097. return;
  1098. }
  1099. int32_t change; // measured positive from left-to-right or top-to-bottom
  1100. nsWeakFrame weakFrame(this);
  1101. if (mDragger->mVertical) {
  1102. change = aPresContext->DevPixelsToAppUnits(
  1103. aEvent->mRefPoint.x - mFirstDragPoint.x);
  1104. if (change > mNextNeighborOrigSize - mMinDrag) {
  1105. change = mNextNeighborOrigSize - mMinDrag;
  1106. } else if (change <= mMinDrag - mPrevNeighborOrigSize) {
  1107. change = mMinDrag - mPrevNeighborOrigSize;
  1108. }
  1109. mColSizes[mDragger->mPrevNeighbor] = mPrevNeighborOrigSize + change;
  1110. mColSizes[mDragger->mNextNeighbor] = mNextNeighborOrigSize - change;
  1111. if (change != 0) {
  1112. // Recompute the specs from the new sizes.
  1113. nscoord width = mRect.width - (mNumCols - 1) * GetBorderWidth(aPresContext, true);
  1114. HTMLFrameSetElement* ourContent = HTMLFrameSetElement::FromContent(mContent);
  1115. NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!");
  1116. const nsFramesetSpec* colSpecs = nullptr;
  1117. ourContent->GetColSpec(&mNumCols, &colSpecs);
  1118. nsAutoString newColAttr;
  1119. GenerateRowCol(aPresContext, width, mNumCols, colSpecs, mColSizes.get(),
  1120. newColAttr);
  1121. // Setting the attr will trigger a reflow
  1122. mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::cols, newColAttr, true);
  1123. }
  1124. } else {
  1125. change = aPresContext->DevPixelsToAppUnits(
  1126. aEvent->mRefPoint.y - mFirstDragPoint.y);
  1127. if (change > mNextNeighborOrigSize - mMinDrag) {
  1128. change = mNextNeighborOrigSize - mMinDrag;
  1129. } else if (change <= mMinDrag - mPrevNeighborOrigSize) {
  1130. change = mMinDrag - mPrevNeighborOrigSize;
  1131. }
  1132. mRowSizes[mDragger->mPrevNeighbor] = mPrevNeighborOrigSize + change;
  1133. mRowSizes[mDragger->mNextNeighbor] = mNextNeighborOrigSize - change;
  1134. if (change != 0) {
  1135. // Recompute the specs from the new sizes.
  1136. nscoord height = mRect.height - (mNumRows - 1) * GetBorderWidth(aPresContext, true);
  1137. HTMLFrameSetElement* ourContent = HTMLFrameSetElement::FromContent(mContent);
  1138. NS_ASSERTION(ourContent, "Someone gave us a broken frameset element!");
  1139. const nsFramesetSpec* rowSpecs = nullptr;
  1140. ourContent->GetRowSpec(&mNumRows, &rowSpecs);
  1141. nsAutoString newRowAttr;
  1142. GenerateRowCol(aPresContext, height, mNumRows, rowSpecs, mRowSizes.get(),
  1143. newRowAttr);
  1144. // Setting the attr will trigger a reflow
  1145. mContent->SetAttr(kNameSpaceID_None, nsGkAtoms::rows, newRowAttr, true);
  1146. }
  1147. }
  1148. ENSURE_TRUE(weakFrame.IsAlive());
  1149. if (change != 0) {
  1150. mDrag.Reset(mDragger->mVertical, mDragger->mPrevNeighbor, change, this);
  1151. }
  1152. }
  1153. void
  1154. nsHTMLFramesetFrame::EndMouseDrag(nsPresContext* aPresContext)
  1155. {
  1156. nsIPresShell::SetCapturingContent(nullptr, 0);
  1157. mDragger = nullptr;
  1158. gDragInProgress = false;
  1159. }
  1160. nsIFrame*
  1161. NS_NewHTMLFramesetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
  1162. {
  1163. #ifdef DEBUG
  1164. const nsStyleDisplay* disp = aContext->StyleDisplay();
  1165. NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle() && !disp->IsFloatingStyle(),
  1166. "Framesets should not be positioned and should not float");
  1167. #endif
  1168. return new (aPresShell) nsHTMLFramesetFrame(aContext);
  1169. }
  1170. NS_IMPL_FRAMEARENA_HELPERS(nsHTMLFramesetFrame)
  1171. /*******************************************************************************
  1172. * nsHTMLFramesetBorderFrame
  1173. ******************************************************************************/
  1174. nsHTMLFramesetBorderFrame::nsHTMLFramesetBorderFrame(nsStyleContext* aContext,
  1175. int32_t aWidth,
  1176. bool aVertical,
  1177. bool aVisibility)
  1178. : nsLeafFrame(aContext), mWidth(aWidth), mVertical(aVertical), mVisibility(aVisibility)
  1179. {
  1180. mCanResize = true;
  1181. mColor = NO_COLOR;
  1182. mPrevNeighbor = 0;
  1183. mNextNeighbor = 0;
  1184. }
  1185. nsHTMLFramesetBorderFrame::~nsHTMLFramesetBorderFrame()
  1186. {
  1187. //printf("nsHTMLFramesetBorderFrame destructor %p \n", this);
  1188. }
  1189. NS_IMPL_FRAMEARENA_HELPERS(nsHTMLFramesetBorderFrame)
  1190. nscoord nsHTMLFramesetBorderFrame::GetIntrinsicISize()
  1191. {
  1192. // No intrinsic width
  1193. return 0;
  1194. }
  1195. nscoord nsHTMLFramesetBorderFrame::GetIntrinsicBSize()
  1196. {
  1197. // No intrinsic height
  1198. return 0;
  1199. }
  1200. void nsHTMLFramesetBorderFrame::SetVisibility(bool aVisibility)
  1201. {
  1202. mVisibility = aVisibility;
  1203. }
  1204. void nsHTMLFramesetBorderFrame::SetColor(nscolor aColor)
  1205. {
  1206. mColor = aColor;
  1207. }
  1208. void
  1209. nsHTMLFramesetBorderFrame::Reflow(nsPresContext* aPresContext,
  1210. ReflowOutput& aDesiredSize,
  1211. const ReflowInput& aReflowInput,
  1212. nsReflowStatus& aStatus)
  1213. {
  1214. DO_GLOBAL_REFLOW_COUNT("nsHTMLFramesetBorderFrame");
  1215. DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
  1216. // Override Reflow(), since we don't want to deal with what our
  1217. // computed values are.
  1218. SizeToAvailSize(aReflowInput, aDesiredSize);
  1219. aDesiredSize.SetOverflowAreasToDesiredBounds();
  1220. aStatus = NS_FRAME_COMPLETE;
  1221. }
  1222. class nsDisplayFramesetBorder : public nsDisplayItem {
  1223. public:
  1224. nsDisplayFramesetBorder(nsDisplayListBuilder* aBuilder,
  1225. nsHTMLFramesetBorderFrame* aFrame)
  1226. : nsDisplayItem(aBuilder, aFrame) {
  1227. MOZ_COUNT_CTOR(nsDisplayFramesetBorder);
  1228. }
  1229. #ifdef NS_BUILD_REFCNT_LOGGING
  1230. virtual ~nsDisplayFramesetBorder() {
  1231. MOZ_COUNT_DTOR(nsDisplayFramesetBorder);
  1232. }
  1233. #endif
  1234. // REVIEW: see old GetFrameForPoint
  1235. // Receives events in its bounds
  1236. virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
  1237. HitTestState* aState,
  1238. nsTArray<nsIFrame*> *aOutFrames) override {
  1239. aOutFrames->AppendElement(mFrame);
  1240. }
  1241. virtual void Paint(nsDisplayListBuilder* aBuilder,
  1242. nsRenderingContext* aCtx) override;
  1243. NS_DISPLAY_DECL_NAME("FramesetBorder", TYPE_FRAMESET_BORDER)
  1244. };
  1245. void nsDisplayFramesetBorder::Paint(nsDisplayListBuilder* aBuilder,
  1246. nsRenderingContext* aCtx)
  1247. {
  1248. static_cast<nsHTMLFramesetBorderFrame*>(mFrame)->
  1249. PaintBorder(aCtx->GetDrawTarget(), ToReferenceFrame());
  1250. }
  1251. void
  1252. nsHTMLFramesetBorderFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
  1253. const nsDisplayListSet& aLists)
  1254. {
  1255. aLists.Content()->AppendNewToTop(
  1256. new (aBuilder) nsDisplayFramesetBorder(aBuilder, this));
  1257. }
  1258. void nsHTMLFramesetBorderFrame::PaintBorder(DrawTarget* aDrawTarget,
  1259. nsPoint aPt)
  1260. {
  1261. nscoord widthInPixels = nsPresContext::AppUnitsToIntCSSPixels(mWidth);
  1262. nscoord pixelWidth = nsPresContext::CSSPixelsToAppUnits(1);
  1263. if (widthInPixels <= 0)
  1264. return;
  1265. ColorPattern bgColor(ToDeviceColor(
  1266. LookAndFeel::GetColor(LookAndFeel::eColorID_WidgetBackground,
  1267. NS_RGB(200, 200, 200))));
  1268. ColorPattern fgColor(ToDeviceColor(
  1269. LookAndFeel::GetColor(LookAndFeel::eColorID_WidgetForeground,
  1270. NS_RGB(0, 0, 0))));
  1271. ColorPattern hltColor(ToDeviceColor(
  1272. LookAndFeel::GetColor(LookAndFeel::eColorID_Widget3DHighlight,
  1273. NS_RGB(255, 255, 255))));
  1274. ColorPattern sdwColor(ToDeviceColor(
  1275. LookAndFeel::GetColor(LookAndFeel::eColorID_Widget3DShadow,
  1276. NS_RGB(128, 128, 128))));
  1277. ColorPattern color(ToDeviceColor(NS_RGB(255, 255, 255))); // default to white
  1278. if (mVisibility) {
  1279. color = (NO_COLOR == mColor) ? bgColor :
  1280. ColorPattern(ToDeviceColor(mColor));
  1281. }
  1282. int32_t appUnitsPerDevPixel = PresContext()->AppUnitsPerDevPixel();
  1283. Point toRefFrame = NSPointToPoint(aPt, appUnitsPerDevPixel);
  1284. AutoRestoreTransform autoRestoreTransform(aDrawTarget);
  1285. aDrawTarget->SetTransform(
  1286. aDrawTarget->GetTransform().PreTranslate(toRefFrame));
  1287. nsPoint start(0, 0);
  1288. nsPoint end = mVertical ? nsPoint(0, mRect.height) : nsPoint(mRect.width, 0);
  1289. // draw grey or white first
  1290. for (int i = 0; i < widthInPixels; i++) {
  1291. StrokeLineWithSnapping(start, end, appUnitsPerDevPixel, *aDrawTarget,
  1292. color);
  1293. if (mVertical) {
  1294. start.x += pixelWidth;
  1295. end.x = start.x;
  1296. } else {
  1297. start.y += pixelWidth;
  1298. end.y = start.y;
  1299. }
  1300. }
  1301. if (!mVisibility)
  1302. return;
  1303. if (widthInPixels >= 5) {
  1304. start.x = (mVertical) ? pixelWidth : 0;
  1305. start.y = (mVertical) ? 0 : pixelWidth;
  1306. end.x = (mVertical) ? start.x : mRect.width;
  1307. end.y = (mVertical) ? mRect.height : start.y;
  1308. StrokeLineWithSnapping(start, end, appUnitsPerDevPixel, *aDrawTarget,
  1309. hltColor);
  1310. }
  1311. if (widthInPixels >= 2) {
  1312. start.x = (mVertical) ? mRect.width - (2 * pixelWidth) : 0;
  1313. start.y = (mVertical) ? 0 : mRect.height - (2 * pixelWidth);
  1314. end.x = (mVertical) ? start.x : mRect.width;
  1315. end.y = (mVertical) ? mRect.height : start.y;
  1316. StrokeLineWithSnapping(start, end, appUnitsPerDevPixel, *aDrawTarget,
  1317. sdwColor);
  1318. }
  1319. if (widthInPixels >= 1) {
  1320. start.x = (mVertical) ? mRect.width - pixelWidth : 0;
  1321. start.y = (mVertical) ? 0 : mRect.height - pixelWidth;
  1322. end.x = (mVertical) ? start.x : mRect.width;
  1323. end.y = (mVertical) ? mRect.height : start.y;
  1324. StrokeLineWithSnapping(start, end, appUnitsPerDevPixel, *aDrawTarget,
  1325. fgColor);
  1326. }
  1327. }
  1328. nsresult
  1329. nsHTMLFramesetBorderFrame::HandleEvent(nsPresContext* aPresContext,
  1330. WidgetGUIEvent* aEvent,
  1331. nsEventStatus* aEventStatus)
  1332. {
  1333. NS_ENSURE_ARG_POINTER(aEventStatus);
  1334. *aEventStatus = nsEventStatus_eIgnore;
  1335. //XXX Mouse setting logic removed. The remaining logic should also move.
  1336. if (!mCanResize) {
  1337. return NS_OK;
  1338. }
  1339. if (aEvent->mMessage == eMouseDown &&
  1340. aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
  1341. nsHTMLFramesetFrame* parentFrame = do_QueryFrame(GetParent());
  1342. if (parentFrame) {
  1343. parentFrame->StartMouseDrag(aPresContext, this, aEvent);
  1344. *aEventStatus = nsEventStatus_eConsumeNoDefault;
  1345. }
  1346. }
  1347. return NS_OK;
  1348. }
  1349. nsresult
  1350. nsHTMLFramesetBorderFrame::GetCursor(const nsPoint& aPoint,
  1351. nsIFrame::Cursor& aCursor)
  1352. {
  1353. if (!mCanResize) {
  1354. aCursor.mCursor = NS_STYLE_CURSOR_DEFAULT;
  1355. } else {
  1356. aCursor.mCursor = (mVertical) ? NS_STYLE_CURSOR_EW_RESIZE : NS_STYLE_CURSOR_NS_RESIZE;
  1357. }
  1358. return NS_OK;
  1359. }
  1360. #ifdef DEBUG_FRAME_DUMP
  1361. nsresult nsHTMLFramesetBorderFrame::GetFrameName(nsAString& aResult) const
  1362. {
  1363. return MakeFrameName(NS_LITERAL_STRING("FramesetBorder"), aResult);
  1364. }
  1365. #endif
  1366. /*******************************************************************************
  1367. * nsHTMLFramesetBlankFrame
  1368. ******************************************************************************/
  1369. NS_QUERYFRAME_HEAD(nsHTMLFramesetBlankFrame)
  1370. NS_QUERYFRAME_ENTRY(nsHTMLFramesetBlankFrame)
  1371. NS_QUERYFRAME_TAIL_INHERITING(nsLeafFrame)
  1372. NS_IMPL_FRAMEARENA_HELPERS(nsHTMLFramesetBlankFrame)
  1373. nsHTMLFramesetBlankFrame::~nsHTMLFramesetBlankFrame()
  1374. {
  1375. //printf("nsHTMLFramesetBlankFrame destructor %p \n", this);
  1376. }
  1377. nscoord nsHTMLFramesetBlankFrame::GetIntrinsicISize()
  1378. {
  1379. // No intrinsic width
  1380. return 0;
  1381. }
  1382. nscoord nsHTMLFramesetBlankFrame::GetIntrinsicBSize()
  1383. {
  1384. // No intrinsic height
  1385. return 0;
  1386. }
  1387. void
  1388. nsHTMLFramesetBlankFrame::Reflow(nsPresContext* aPresContext,
  1389. ReflowOutput& aDesiredSize,
  1390. const ReflowInput& aReflowInput,
  1391. nsReflowStatus& aStatus)
  1392. {
  1393. DO_GLOBAL_REFLOW_COUNT("nsHTMLFramesetBlankFrame");
  1394. // Override Reflow(), since we don't want to deal with what our
  1395. // computed values are.
  1396. SizeToAvailSize(aReflowInput, aDesiredSize);
  1397. aDesiredSize.SetOverflowAreasToDesiredBounds();
  1398. aStatus = NS_FRAME_COMPLETE;
  1399. }
  1400. class nsDisplayFramesetBlank : public nsDisplayItem {
  1401. public:
  1402. nsDisplayFramesetBlank(nsDisplayListBuilder* aBuilder,
  1403. nsIFrame* aFrame) :
  1404. nsDisplayItem(aBuilder, aFrame) {
  1405. MOZ_COUNT_CTOR(nsDisplayFramesetBlank);
  1406. }
  1407. #ifdef NS_BUILD_REFCNT_LOGGING
  1408. virtual ~nsDisplayFramesetBlank() {
  1409. MOZ_COUNT_DTOR(nsDisplayFramesetBlank);
  1410. }
  1411. #endif
  1412. virtual void Paint(nsDisplayListBuilder* aBuilder,
  1413. nsRenderingContext* aCtx) override;
  1414. NS_DISPLAY_DECL_NAME("FramesetBlank", TYPE_FRAMESET_BLANK)
  1415. };
  1416. void nsDisplayFramesetBlank::Paint(nsDisplayListBuilder* aBuilder,
  1417. nsRenderingContext* aCtx)
  1418. {
  1419. DrawTarget* drawTarget = aCtx->GetDrawTarget();
  1420. int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
  1421. Rect rect =
  1422. NSRectToSnappedRect(mVisibleRect, appUnitsPerDevPixel, *drawTarget);
  1423. ColorPattern white(ToDeviceColor(Color(1.f, 1.f, 1.f, 1.f)));
  1424. drawTarget->FillRect(rect, white);
  1425. }
  1426. void
  1427. nsHTMLFramesetBlankFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
  1428. const nsDisplayListSet& aLists)
  1429. {
  1430. aLists.Content()->AppendNewToTop(
  1431. new (aBuilder) nsDisplayFramesetBlank(aBuilder, this));
  1432. }