LayoutBlockBox.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #include "precompiled.h"
  28. #include "LayoutBlockBox.h"
  29. #include "LayoutBlockBoxSpace.h"
  30. #include "LayoutEngine.h"
  31. #include <Rocket/Core/Element.h>
  32. #include <Rocket/Core/ElementUtilities.h>
  33. #include <Rocket/Core/ElementScroll.h>
  34. #include <Rocket/Core/Property.h>
  35. #include <Rocket/Core/StyleSheetKeywords.h>
  36. namespace Rocket {
  37. namespace Core {
  38. // Creates a new block box for rendering a block element.
  39. LayoutBlockBox::LayoutBlockBox(LayoutEngine* _layout_engine, LayoutBlockBox* _parent, Element* _element) : position(0, 0)
  40. {
  41. space = new LayoutBlockBoxSpace(this);
  42. layout_engine = _layout_engine;
  43. parent = _parent;
  44. context = BLOCK;
  45. element = _element;
  46. interrupted_chain = NULL;
  47. box_cursor = 0;
  48. vertical_overflow = false;
  49. // Get our offset root from our parent, if it has one; otherwise, our element is the offset parent.
  50. if (parent != NULL &&
  51. parent->offset_root->GetElement() != NULL)
  52. offset_root = parent->offset_root;
  53. else
  54. offset_root = this;
  55. // Determine the offset parent for this element.
  56. LayoutBlockBox* self_offset_parent;
  57. if (parent != NULL &&
  58. parent->offset_parent->GetElement() != NULL)
  59. self_offset_parent = parent->offset_parent;
  60. else
  61. self_offset_parent = this;
  62. // Determine the offset parent for our children.
  63. if (parent != NULL &&
  64. parent->offset_parent->GetElement() != NULL &&
  65. (element == NULL || element->GetProperty< int >(POSITION) == POSITION_STATIC))
  66. offset_parent = parent->offset_parent;
  67. else
  68. offset_parent = this;
  69. // Build the box for our element, and position it if we can.
  70. if (parent != NULL)
  71. {
  72. space->ImportSpace(*parent->space);
  73. // Build our box if possible; if not, it will have to be set up manually.
  74. layout_engine->BuildBox(box, min_height, max_height, parent, element);
  75. // Position ourselves within our containing block (if we have a valid offset parent).
  76. if (parent->GetElement() != NULL)
  77. {
  78. if (self_offset_parent != this)
  79. {
  80. // Get the next position within our offset parent's containing block.
  81. parent->PositionBlockBox(position, box, element->GetProperty< int >(CLEAR));
  82. element->SetOffset(position - (self_offset_parent->GetPosition() - offset_root->GetPosition()), self_offset_parent->GetElement());
  83. }
  84. else
  85. element->SetOffset(position, NULL);
  86. }
  87. }
  88. if (element != NULL)
  89. {
  90. wrap_content = element->GetProperty< int >(WHITE_SPACE) != WHITE_SPACE_NOWRAP;
  91. // Determine if this element should have scrollbars or not, and create them if so.
  92. overflow_x_property = element->GetProperty< int >(OVERFLOW_X);
  93. overflow_y_property = element->GetProperty< int >(OVERFLOW_Y);
  94. if (overflow_x_property == OVERFLOW_SCROLL)
  95. element->GetElementScroll()->EnableScrollbar(ElementScroll::HORIZONTAL, box.GetSize(Box::PADDING).x);
  96. else
  97. element->GetElementScroll()->DisableScrollbar(ElementScroll::HORIZONTAL);
  98. if (overflow_y_property == OVERFLOW_SCROLL)
  99. element->GetElementScroll()->EnableScrollbar(ElementScroll::VERTICAL, box.GetSize(Box::PADDING).x);
  100. else
  101. element->GetElementScroll()->DisableScrollbar(ElementScroll::VERTICAL);
  102. }
  103. else
  104. {
  105. wrap_content = true;
  106. overflow_x_property = OVERFLOW_VISIBLE;
  107. overflow_y_property = OVERFLOW_VISIBLE;
  108. }
  109. }
  110. // Creates a new block box in an inline context.
  111. LayoutBlockBox::LayoutBlockBox(LayoutEngine* _layout_engine, LayoutBlockBox* _parent) : position(-1, -1)
  112. {
  113. layout_engine = _layout_engine;
  114. parent = _parent;
  115. offset_parent = parent->offset_parent;
  116. offset_root = parent->offset_root;
  117. space = _parent->space;
  118. context = INLINE;
  119. line_boxes.push_back(new LayoutLineBox(this));
  120. wrap_content = parent->wrap_content;
  121. element = NULL;
  122. interrupted_chain = NULL;
  123. box_cursor = 0;
  124. vertical_overflow = false;
  125. layout_engine->BuildBox(box, min_height, max_height, parent, NULL);
  126. parent->PositionBlockBox(position, box, 0);
  127. box.SetContent(Vector2f(box.GetSize(Box::CONTENT).x, -1));
  128. // Reset the min and max heights; they're not valid for inline block boxes.
  129. min_height = 0;
  130. max_height = FLT_MAX;
  131. }
  132. // Releases the block box.
  133. LayoutBlockBox::~LayoutBlockBox()
  134. {
  135. for (size_t i = 0; i < block_boxes.size(); i++)
  136. delete block_boxes[i];
  137. for (size_t i = 0; i < line_boxes.size(); i++)
  138. delete line_boxes[i];
  139. if (context == BLOCK)
  140. delete space;
  141. }
  142. // Closes the box.
  143. LayoutBlockBox::CloseResult LayoutBlockBox::Close()
  144. {
  145. // If the last child of this block box is an inline box, then we haven't closed it; close it now!
  146. if (context == BLOCK)
  147. {
  148. CloseResult result = CloseInlineBlockBox();
  149. if (result != OK)
  150. return LAYOUT_SELF;
  151. }
  152. // Otherwise, we're an inline context box; so close our last line, which will still be open.
  153. else
  154. {
  155. line_boxes.back()->Close();
  156. // Expand our content area if any line boxes had to push themselves out.
  157. Vector2f content_area = box.GetSize();
  158. for (size_t i = 0; i < line_boxes.size(); i++)
  159. content_area.x = Math::Max(content_area.x, line_boxes[i]->GetDimensions().x);
  160. box.SetContent(content_area);
  161. }
  162. // Set this box's height, if necessary.
  163. if (box.GetSize(Box::CONTENT).y < 0)
  164. {
  165. Vector2f content_area = box.GetSize();
  166. content_area.y = Math::Clamp(box_cursor, min_height, max_height);
  167. if (element != NULL)
  168. content_area.y = Math::Max(content_area.y, space->GetDimensions().y);
  169. box.SetContent(content_area);
  170. }
  171. // Set the computed box on the element.
  172. if (element != NULL)
  173. {
  174. if (context == BLOCK)
  175. {
  176. // Calculate the dimensions of the box's *internal* content; this is the tightest-fitting box around all of the
  177. // internal elements, plus this element's padding.
  178. Vector2f content_box(0, 0);
  179. for (size_t i = 0; i < block_boxes.size(); i++)
  180. content_box.x = Math::Max(content_box.x, block_boxes[i]->GetBox().GetSize(Box::MARGIN).x);
  181. // Check how big our floated area is.
  182. Vector2f space_box = space->GetDimensions();
  183. content_box.x = Math::Max(content_box.x, space_box.x);
  184. // If our content is larger than our window, then we can either extend our box, if we're set to not wrap
  185. // our inline content, or enable the horizontal scrollbar, if we're set to auto-scrollbars. If we're set to
  186. // always use scrollbars, then the horiontal scrollbar will already have been enabled in the constructor.
  187. if (content_box.x > box.GetSize().x)
  188. {
  189. if (!wrap_content)
  190. box.SetContent(Vector2f(content_box.x, box.GetSize().y));
  191. else if (overflow_x_property == OVERFLOW_AUTO)
  192. {
  193. element->GetElementScroll()->EnableScrollbar(ElementScroll::HORIZONTAL, box.GetSize(Box::PADDING).x);
  194. if (!CatchVerticalOverflow())
  195. return LAYOUT_SELF;
  196. }
  197. }
  198. content_box.x += (box.GetEdge(Box::PADDING, Box::LEFT) + box.GetEdge(Box::PADDING, Box::RIGHT));
  199. content_box.y = box_cursor;
  200. content_box.y = Math::Max(content_box.y, space_box.y);
  201. if (!CatchVerticalOverflow(content_box.y))
  202. return LAYOUT_SELF;
  203. content_box.y += (box.GetEdge(Box::PADDING, Box::TOP) + box.GetEdge(Box::PADDING, Box::BOTTOM));
  204. element->SetBox(box);
  205. element->SetContentBox(space->GetOffset(), content_box);
  206. // Format any scrollbars which were enabled on this element.
  207. element->GetElementScroll()->FormatScrollbars();
  208. }
  209. else
  210. element->SetBox(box);
  211. }
  212. // Increment the parent's cursor.
  213. if (parent != NULL)
  214. {
  215. // If this close fails, it means this block box has caused our parent block box to generate an automatic
  216. // vertical scrollbar.
  217. if (!parent->CloseBlockBox(this))
  218. return LAYOUT_PARENT;
  219. }
  220. // If we represent a positioned element, then we can now (as we've been sized) act as the containing block for all
  221. // the absolutely-positioned elements of our descendants.
  222. if (context == BLOCK &&
  223. element != NULL)
  224. {
  225. if (element->GetProperty< int >(POSITION) != POSITION_STATIC)
  226. CloseAbsoluteElements();
  227. }
  228. return OK;
  229. }
  230. // Called by a closing block box child.
  231. bool LayoutBlockBox::CloseBlockBox(LayoutBlockBox* child)
  232. {
  233. ROCKET_ASSERT(context == BLOCK);
  234. box_cursor = (child->GetPosition().y - child->box.GetEdge(Box::MARGIN, Box::TOP) - (box.GetPosition().y + position.y)) + child->GetBox().GetSize(Box::MARGIN).y;
  235. return CatchVerticalOverflow();
  236. }
  237. // Called by a closing line box child.
  238. LayoutInlineBox* LayoutBlockBox::CloseLineBox(LayoutLineBox* child, LayoutInlineBox* overflow, LayoutInlineBox* overflow_chain)
  239. {
  240. ROCKET_ASSERT(context == INLINE);
  241. if (child->GetDimensions().x > 0)
  242. box_cursor = (child->GetPosition().y - (box.GetPosition().y + position.y)) + child->GetDimensions().y;
  243. // If we have any pending floating elements for our parent, then this would be an ideal time to position them.
  244. if (!float_elements.empty())
  245. {
  246. for (size_t i = 0; i < float_elements.size(); ++i)
  247. parent->PositionFloat(float_elements[i], box_cursor);
  248. float_elements.clear();
  249. }
  250. // Add a new line box.
  251. line_boxes.push_back(new LayoutLineBox(this));
  252. if (overflow_chain != NULL)
  253. line_boxes.back()->AddChainedBox(overflow_chain);
  254. if (overflow != NULL)
  255. return line_boxes.back()->AddBox(overflow);
  256. return NULL;
  257. }
  258. // Adds a new block element to this block box.
  259. LayoutBlockBox* LayoutBlockBox::AddBlockElement(Element* element)
  260. {
  261. ROCKET_ASSERT(context == BLOCK);
  262. // Check if our most previous block box is rendering in an inline context.
  263. if (!block_boxes.empty() &&
  264. block_boxes.back()->context == INLINE)
  265. {
  266. LayoutBlockBox* inline_block_box = block_boxes.back();
  267. LayoutInlineBox* open_inline_box = inline_block_box->line_boxes.back()->GetOpenInlineBox();
  268. if (open_inline_box != NULL)
  269. {
  270. // There's an open inline box chain, which means this block element is parented to it. The chain needs to
  271. // be positioned (if it hasn't already), closed and duplicated after this block box closes. Also, this
  272. // block needs to be aware of its parentage, so it can correctly compute its relative position. First of
  273. // all, we need to close the inline box; this will position the last line if necessary, but it will also
  274. // create a new line in the inline block box; we want this line to be in an inline box after our block
  275. // element.
  276. if (inline_block_box->Close() != OK)
  277. return NULL;
  278. interrupted_chain = open_inline_box;
  279. }
  280. else
  281. {
  282. // There are no open inline boxes, so this inline box just needs to be closed.
  283. if (CloseInlineBlockBox() != OK)
  284. return NULL;
  285. }
  286. }
  287. block_boxes.push_back(new LayoutBlockBox(layout_engine, this, element));
  288. return block_boxes.back();
  289. }
  290. // Adds a new inline element to this inline box.
  291. LayoutInlineBox* LayoutBlockBox::AddInlineElement(Element* element, const Box& box)
  292. {
  293. if (context == BLOCK)
  294. {
  295. LayoutInlineBox* inline_box;
  296. // If we have an open child rendering in an inline context, we can add this element into it.
  297. if (!block_boxes.empty() &&
  298. block_boxes.back()->context == INLINE)
  299. inline_box = block_boxes.back()->AddInlineElement(element, box);
  300. // No dice! Ah well, nothing for it but to open a new inline context block box.
  301. else
  302. {
  303. block_boxes.push_back(new LayoutBlockBox(layout_engine, this));
  304. if (interrupted_chain != NULL)
  305. {
  306. block_boxes.back()->line_boxes.back()->AddChainedBox(interrupted_chain);
  307. interrupted_chain = NULL;
  308. }
  309. inline_box = block_boxes.back()->AddInlineElement(element, box);
  310. }
  311. return inline_box;
  312. }
  313. else
  314. {
  315. // We're an inline context box, so we'll add this new inline element into our line boxes.
  316. return line_boxes.back()->AddElement(element, box);
  317. }
  318. }
  319. // Adds a line-break to this block box.
  320. void LayoutBlockBox::AddBreak()
  321. {
  322. int line_height = ElementUtilities::GetLineHeight(element);
  323. // Check for an inline box as our last child; if so, we can simply end its line and bail.
  324. if (!block_boxes.empty())
  325. {
  326. LayoutBlockBox* block_box = block_boxes.back();
  327. if (block_box->context == INLINE)
  328. {
  329. LayoutLineBox* last_line = block_box->line_boxes.back();
  330. if (last_line->GetDimensions().y < 0)
  331. block_box->box_cursor += line_height;
  332. else
  333. last_line->Close();
  334. return;
  335. }
  336. }
  337. // No inline box as our last child; no problem, just increment the cursor by the line height of this element.
  338. box_cursor += line_height;
  339. }
  340. // Adds an element to this block box to be handled as a floating element.
  341. bool LayoutBlockBox::AddFloatElement(Element* element)
  342. {
  343. // If we have an open inline block box, then we have to position the box a little differently.
  344. if (!block_boxes.empty() &&
  345. block_boxes.back()->context == INLINE)
  346. block_boxes.back()->float_elements.push_back(element);
  347. // Nope ... just place it!
  348. else
  349. PositionFloat(element);
  350. return true;
  351. }
  352. // Adds an element to this block box to be handled as an absolutely-positioned element.
  353. void LayoutBlockBox::AddAbsoluteElement(Element* element)
  354. {
  355. ROCKET_ASSERT(context == BLOCK);
  356. AbsoluteElement absolute_element;
  357. absolute_element.element = element;
  358. PositionBox(absolute_element.position, 0);
  359. // If we have an open inline-context block box as our last child, then the absolute element must appear after it,
  360. // but not actually close the box.
  361. if (!block_boxes.empty()
  362. && block_boxes.back()->context == INLINE)
  363. {
  364. LayoutBlockBox* inline_context_box = block_boxes.back();
  365. float last_line_height = inline_context_box->line_boxes.back()->GetDimensions().y;
  366. absolute_element.position.y += (inline_context_box->box_cursor + Math::Max(0.0f, last_line_height));
  367. }
  368. // Find the positioned parent for this element.
  369. LayoutBlockBox* absolute_parent = this;
  370. while (absolute_parent != absolute_parent->offset_parent)
  371. absolute_parent = absolute_parent->parent;
  372. absolute_parent->absolute_elements.push_back(absolute_element);
  373. }
  374. // Lays out, sizes, and positions all absolute elements in this block relative to the containing block.
  375. void LayoutBlockBox::CloseAbsoluteElements()
  376. {
  377. if (!absolute_elements.empty())
  378. {
  379. // The size of the containing box, including the padding. This is used to resolve relative offsets.
  380. Vector2f containing_block = GetBox().GetSize(Box::PADDING);
  381. for (size_t i = 0; i < absolute_elements.size(); i++)
  382. {
  383. Element* absolute_element = absolute_elements[i].element;
  384. Vector2f absolute_position = absolute_elements[i].position;
  385. absolute_position -= position - offset_root->GetPosition();
  386. // Lay out the element.
  387. LayoutEngine layout_engine;
  388. layout_engine.FormatElement(absolute_element, containing_block);
  389. // Now that the element's box has been built, we can offset the position we determined was appropriate for
  390. // it by the element's margin. This is necessary because the coordinate system for the box begins at the
  391. // border, not the margin.
  392. absolute_position.x += absolute_element->GetBox().GetEdge(Box::MARGIN, Box::LEFT);
  393. absolute_position.y += absolute_element->GetBox().GetEdge(Box::MARGIN, Box::TOP);
  394. // Set the offset of the element; the element itself will take care of any RCSS-defined positional offsets.
  395. absolute_element->SetOffset(absolute_position, element);
  396. }
  397. absolute_elements.clear();
  398. }
  399. }
  400. // Returns the offset from the top-left corner of this box that the next child box will be positioned at.
  401. void LayoutBlockBox::PositionBox(Vector2f& box_position, float top_margin, int clear_property) const
  402. {
  403. // If our element is establishing a new offset hierarchy, then any children of ours don't inherit our offset.
  404. box_position = GetPosition();
  405. box_position += box.GetPosition();
  406. box_position.y += box_cursor;
  407. float clear_margin = space->ClearBoxes(box_position.y + top_margin, clear_property) - (box_position.y + top_margin);
  408. if (clear_margin > 0)
  409. box_position.y += clear_margin;
  410. else
  411. {
  412. // Check for a collapsing vertical margin.
  413. if (!block_boxes.empty() &&
  414. block_boxes.back()->context == BLOCK)
  415. {
  416. float bottom_margin = block_boxes.back()->GetBox().GetEdge(Box::MARGIN, Box::BOTTOM);
  417. box_position.y -= Math::Min(top_margin, bottom_margin);
  418. }
  419. }
  420. }
  421. // Returns the offset from the top-left corner of this box's offset element the next child block box, of the given
  422. // dimensions, will be positioned at. This will include the margins on the new block box.
  423. void LayoutBlockBox::PositionBlockBox(Vector2f& box_position, const Box& box, int clear_property) const
  424. {
  425. PositionBox(box_position, box.GetEdge(Box::MARGIN, Box::TOP), clear_property);
  426. box_position.x += box.GetEdge(Box::MARGIN, Box::LEFT);
  427. box_position.y += box.GetEdge(Box::MARGIN, Box::TOP);
  428. LayoutEngine::Round(box_position);
  429. }
  430. // Returns the offset from the top-left corner of this box for the next line.
  431. void LayoutBlockBox::PositionLineBox(Vector2f& box_position, float& box_width, bool& _wrap_content, const Vector2f& dimensions) const
  432. {
  433. Vector2f cursor;
  434. PositionBox(cursor);
  435. space->PositionBox(box_position, box_width, cursor.y, dimensions);
  436. // Also, probably shouldn't check for widths when positioning the box?
  437. _wrap_content = wrap_content;
  438. }
  439. // Returns the block box's element.
  440. Element* LayoutBlockBox::GetElement() const
  441. {
  442. return element;
  443. }
  444. // Returns the block box's parent.
  445. LayoutBlockBox* LayoutBlockBox::GetParent() const
  446. {
  447. return parent;
  448. }
  449. // Returns the position of the block box, relative to its parent's content area.
  450. const Vector2f& LayoutBlockBox::GetPosition() const
  451. {
  452. return position;
  453. }
  454. // Returns the element against which all positions of boxes in the hierarchy are calculated relative to.
  455. LayoutBlockBox* LayoutBlockBox::GetOffsetParent() const
  456. {
  457. return offset_parent;
  458. }
  459. // Returns the block box against which all positions of boxes in the hierarchy are calculated relative to.
  460. LayoutBlockBox* LayoutBlockBox::GetOffsetRoot() const
  461. {
  462. return offset_root;
  463. }
  464. // Returns the block box's dimension box.
  465. Box& LayoutBlockBox::GetBox()
  466. {
  467. return box;
  468. }
  469. // Returns the block box's dimension box.
  470. const Box& LayoutBlockBox::GetBox() const
  471. {
  472. return box;
  473. }
  474. void* LayoutBlockBox::operator new(size_t size)
  475. {
  476. void* memory = LayoutEngine::AllocateLayoutChunk(size);
  477. return memory;
  478. }
  479. void LayoutBlockBox::operator delete(void* chunk)
  480. {
  481. LayoutEngine::DeallocateLayoutChunk(chunk);
  482. }
  483. // Closes our last block box, if it is an open inline block box.
  484. LayoutBlockBox::CloseResult LayoutBlockBox::CloseInlineBlockBox()
  485. {
  486. if (!block_boxes.empty() &&
  487. block_boxes.back()->context == INLINE)
  488. return block_boxes.back()->Close();
  489. return OK;
  490. }
  491. // Positions a floating element within this block box.
  492. void LayoutBlockBox::PositionFloat(Element* element, float offset)
  493. {
  494. Vector2f box_position;
  495. PositionBox(box_position);
  496. space->PositionBox(box_position.y + offset, element);
  497. }
  498. // Checks if we have a new vertical overflow on an auto-scrolling element.
  499. bool LayoutBlockBox::CatchVerticalOverflow(float cursor)
  500. {
  501. if (cursor == -1)
  502. cursor = box_cursor;
  503. float box_height = box.GetSize().y;
  504. if (box_height < 0)
  505. box_height = max_height;
  506. // If we're auto-scrolling and our height is fixed, we have to check if this box has exceeded our client height.
  507. if (!vertical_overflow &&
  508. box_height >= 0 &&
  509. overflow_y_property == OVERFLOW_AUTO)
  510. {
  511. if (cursor > box_height - element->GetElementScroll()->GetScrollbarSize(ElementScroll::HORIZONTAL))
  512. {
  513. vertical_overflow = true;
  514. element->GetElementScroll()->EnableScrollbar(ElementScroll::VERTICAL, box.GetSize(Box::PADDING).x);
  515. for (size_t i = 0; i < block_boxes.size(); i++)
  516. delete block_boxes[i];
  517. block_boxes.clear();
  518. delete space;
  519. space = new LayoutBlockBoxSpace(this);
  520. box_cursor = 0;
  521. interrupted_chain = NULL;
  522. return false;
  523. }
  524. }
  525. return true;
  526. }
  527. }
  528. }