LayoutBlockBox.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  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 "../../Include/Rocket/Core/Element.h"
  32. #include "../../Include/Rocket/Core/ElementUtilities.h"
  33. #include "../../Include/Rocket/Core/ElementScroll.h"
  34. #include "../../Include/Rocket/Core/Property.h"
  35. #include "../../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->GetPosition() == 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->GetWhitespace() != WHITE_SPACE_NOWRAP;
  91. // Determine if this element should have scrollbars or not, and create them if so.
  92. element->GetOverflow(&overflow_x_property, &overflow_y_property);
  93. if (overflow_x_property == OVERFLOW_SCROLL)
  94. element->GetElementScroll()->EnableScrollbar(ElementScroll::HORIZONTAL, box.GetSize(Box::PADDING).x);
  95. else
  96. element->GetElementScroll()->DisableScrollbar(ElementScroll::HORIZONTAL);
  97. if (overflow_y_property == OVERFLOW_SCROLL)
  98. element->GetElementScroll()->EnableScrollbar(ElementScroll::VERTICAL, box.GetSize(Box::PADDING).x);
  99. else
  100. element->GetElementScroll()->DisableScrollbar(ElementScroll::VERTICAL);
  101. }
  102. else
  103. {
  104. wrap_content = true;
  105. overflow_x_property = OVERFLOW_VISIBLE;
  106. overflow_y_property = OVERFLOW_VISIBLE;
  107. }
  108. }
  109. // Creates a new block box in an inline context.
  110. LayoutBlockBox::LayoutBlockBox(LayoutEngine* _layout_engine, LayoutBlockBox* _parent) : position(-1, -1)
  111. {
  112. layout_engine = _layout_engine;
  113. parent = _parent;
  114. offset_parent = parent->offset_parent;
  115. offset_root = parent->offset_root;
  116. space = _parent->space;
  117. context = INLINE;
  118. line_boxes.push_back(new LayoutLineBox(this));
  119. wrap_content = parent->wrap_content;
  120. element = NULL;
  121. interrupted_chain = NULL;
  122. box_cursor = 0;
  123. vertical_overflow = false;
  124. layout_engine->BuildBox(box, min_height, max_height, parent, NULL);
  125. parent->PositionBlockBox(position, box, 0);
  126. box.SetContent(Vector2f(box.GetSize(Box::CONTENT).x, -1));
  127. // Reset the min and max heights; they're not valid for inline block boxes.
  128. min_height = 0;
  129. max_height = FLT_MAX;
  130. }
  131. // Releases the block box.
  132. LayoutBlockBox::~LayoutBlockBox()
  133. {
  134. for (size_t i = 0; i < block_boxes.size(); i++)
  135. delete block_boxes[i];
  136. for (size_t i = 0; i < line_boxes.size(); i++)
  137. delete line_boxes[i];
  138. if (context == BLOCK)
  139. delete space;
  140. }
  141. // Closes the box.
  142. LayoutBlockBox::CloseResult LayoutBlockBox::Close()
  143. {
  144. // If the last child of this block box is an inline box, then we haven't closed it; close it now!
  145. if (context == BLOCK)
  146. {
  147. CloseResult result = CloseInlineBlockBox();
  148. if (result != OK)
  149. return LAYOUT_SELF;
  150. }
  151. // Otherwise, we're an inline context box; so close our last line, which will still be open.
  152. else
  153. {
  154. line_boxes.back()->Close();
  155. // Expand our content area if any line boxes had to push themselves out.
  156. Vector2f content_area = box.GetSize();
  157. for (size_t i = 0; i < line_boxes.size(); i++)
  158. content_area.x = Math::Max(content_area.x, line_boxes[i]->GetDimensions().x);
  159. box.SetContent(content_area);
  160. }
  161. // Set this box's height, if necessary.
  162. if (box.GetSize(Box::CONTENT).y < 0)
  163. {
  164. Vector2f content_area = box.GetSize();
  165. content_area.y = Math::Clamp(box_cursor, min_height, max_height);
  166. if (element != NULL)
  167. content_area.y = Math::Max(content_area.y, space->GetDimensions().y);
  168. box.SetContent(content_area);
  169. }
  170. // Set the computed box on the element.
  171. if (element != NULL)
  172. {
  173. if (context == BLOCK)
  174. {
  175. // Calculate the dimensions of the box's *internal* content; this is the tightest-fitting box around all of the
  176. // internal elements, plus this element's padding.
  177. Vector2f content_box(0, 0);
  178. for (size_t i = 0; i < block_boxes.size(); i++)
  179. content_box.x = Math::Max(content_box.x, block_boxes[i]->GetBox().GetSize(Box::MARGIN).x);
  180. // Check how big our floated area is.
  181. Vector2f space_box = space->GetDimensions();
  182. content_box.x = Math::Max(content_box.x, space_box.x);
  183. // If our content is larger than our window, then we can either extend our box, if we're set to not wrap
  184. // our inline content, or enable the horizontal scrollbar, if we're set to auto-scrollbars. If we're set to
  185. // always use scrollbars, then the horiontal scrollbar will already have been enabled in the constructor.
  186. if (content_box.x > box.GetSize().x)
  187. {
  188. if (!wrap_content)
  189. box.SetContent(Vector2f(content_box.x, box.GetSize().y));
  190. else if (overflow_x_property == OVERFLOW_AUTO)
  191. {
  192. element->GetElementScroll()->EnableScrollbar(ElementScroll::HORIZONTAL, box.GetSize(Box::PADDING).x);
  193. if (!CatchVerticalOverflow())
  194. return LAYOUT_SELF;
  195. }
  196. }
  197. content_box.x += (box.GetEdge(Box::PADDING, Box::LEFT) + box.GetEdge(Box::PADDING, Box::RIGHT));
  198. content_box.y = box_cursor;
  199. content_box.y = Math::Max(content_box.y, space_box.y);
  200. if (!CatchVerticalOverflow(content_box.y))
  201. return LAYOUT_SELF;
  202. content_box.y += (box.GetEdge(Box::PADDING, Box::TOP) + box.GetEdge(Box::PADDING, Box::BOTTOM));
  203. element->SetBox(box);
  204. element->SetContentBox(space->GetOffset(), content_box);
  205. // Format any scrollbars which were enabled on this element.
  206. element->GetElementScroll()->FormatScrollbars();
  207. }
  208. else
  209. element->SetBox(box);
  210. }
  211. // Increment the parent's cursor.
  212. if (parent != NULL)
  213. {
  214. // If this close fails, it means this block box has caused our parent block box to generate an automatic
  215. // vertical scrollbar.
  216. if (!parent->CloseBlockBox(this))
  217. return LAYOUT_PARENT;
  218. }
  219. // If we represent a positioned element, then we can now (as we've been sized) act as the containing block for all
  220. // the absolutely-positioned elements of our descendants.
  221. if (context == BLOCK &&
  222. element != NULL)
  223. {
  224. if (element->GetPosition() != POSITION_STATIC)
  225. CloseAbsoluteElements();
  226. }
  227. return OK;
  228. }
  229. // Called by a closing block box child.
  230. bool LayoutBlockBox::CloseBlockBox(LayoutBlockBox* child)
  231. {
  232. ROCKET_ASSERT(context == BLOCK);
  233. box_cursor = (child->GetPosition().y - child->box.GetEdge(Box::MARGIN, Box::TOP) - (box.GetPosition().y + position.y)) + child->GetBox().GetSize(Box::MARGIN).y;
  234. return CatchVerticalOverflow();
  235. }
  236. // Called by a closing line box child.
  237. LayoutInlineBox* LayoutBlockBox::CloseLineBox(LayoutLineBox* child, LayoutInlineBox* overflow, LayoutInlineBox* overflow_chain)
  238. {
  239. ROCKET_ASSERT(context == INLINE);
  240. if (child->GetDimensions().x > 0)
  241. box_cursor = (child->GetPosition().y - (box.GetPosition().y + position.y)) + child->GetDimensions().y;
  242. // If we have any pending floating elements for our parent, then this would be an ideal time to position them.
  243. if (!float_elements.empty())
  244. {
  245. for (size_t i = 0; i < float_elements.size(); ++i)
  246. parent->PositionFloat(float_elements[i], box_cursor);
  247. float_elements.clear();
  248. }
  249. // Add a new line box.
  250. line_boxes.push_back(new LayoutLineBox(this));
  251. if (overflow_chain != NULL)
  252. line_boxes.back()->AddChainedBox(overflow_chain);
  253. if (overflow != NULL)
  254. return line_boxes.back()->AddBox(overflow);
  255. return NULL;
  256. }
  257. // Adds a new block element to this block box.
  258. LayoutBlockBox* LayoutBlockBox::AddBlockElement(Element* element)
  259. {
  260. ROCKET_ASSERT(context == BLOCK);
  261. // Check if our most previous block box is rendering in an inline context.
  262. if (!block_boxes.empty() &&
  263. block_boxes.back()->context == INLINE)
  264. {
  265. LayoutBlockBox* inline_block_box = block_boxes.back();
  266. LayoutInlineBox* open_inline_box = inline_block_box->line_boxes.back()->GetOpenInlineBox();
  267. if (open_inline_box != NULL)
  268. {
  269. // There's an open inline box chain, which means this block element is parented to it. The chain needs to
  270. // be positioned (if it hasn't already), closed and duplicated after this block box closes. Also, this
  271. // block needs to be aware of its parentage, so it can correctly compute its relative position. First of
  272. // all, we need to close the inline box; this will position the last line if necessary, but it will also
  273. // create a new line in the inline block box; we want this line to be in an inline box after our block
  274. // element.
  275. if (inline_block_box->Close() != OK)
  276. return NULL;
  277. interrupted_chain = open_inline_box;
  278. }
  279. else
  280. {
  281. // There are no open inline boxes, so this inline box just needs to be closed.
  282. if (CloseInlineBlockBox() != OK)
  283. return NULL;
  284. }
  285. }
  286. block_boxes.push_back(new LayoutBlockBox(layout_engine, this, element));
  287. return block_boxes.back();
  288. }
  289. // Adds a new inline element to this inline box.
  290. LayoutInlineBox* LayoutBlockBox::AddInlineElement(Element* element, const Box& box)
  291. {
  292. if (context == BLOCK)
  293. {
  294. LayoutInlineBox* inline_box;
  295. // If we have an open child rendering in an inline context, we can add this element into it.
  296. if (!block_boxes.empty() &&
  297. block_boxes.back()->context == INLINE)
  298. inline_box = block_boxes.back()->AddInlineElement(element, box);
  299. // No dice! Ah well, nothing for it but to open a new inline context block box.
  300. else
  301. {
  302. block_boxes.push_back(new LayoutBlockBox(layout_engine, this));
  303. if (interrupted_chain != NULL)
  304. {
  305. block_boxes.back()->line_boxes.back()->AddChainedBox(interrupted_chain);
  306. interrupted_chain = NULL;
  307. }
  308. inline_box = block_boxes.back()->AddInlineElement(element, box);
  309. }
  310. return inline_box;
  311. }
  312. else
  313. {
  314. // We're an inline context box, so we'll add this new inline element into our line boxes.
  315. return line_boxes.back()->AddElement(element, box);
  316. }
  317. }
  318. // Adds a line-break to this block box.
  319. void LayoutBlockBox::AddBreak()
  320. {
  321. int line_height = ElementUtilities::GetLineHeight(element);
  322. // Check for an inline box as our last child; if so, we can simply end its line and bail.
  323. if (!block_boxes.empty())
  324. {
  325. LayoutBlockBox* block_box = block_boxes.back();
  326. if (block_box->context == INLINE)
  327. {
  328. LayoutLineBox* last_line = block_box->line_boxes.back();
  329. if (last_line->GetDimensions().y < 0)
  330. block_box->box_cursor += line_height;
  331. else
  332. last_line->Close();
  333. return;
  334. }
  335. }
  336. // No inline box as our last child; no problem, just increment the cursor by the line height of this element.
  337. box_cursor += line_height;
  338. }
  339. // Adds an element to this block box to be handled as a floating element.
  340. bool LayoutBlockBox::AddFloatElement(Element* element)
  341. {
  342. // If we have an open inline block box, then we have to position the box a little differently.
  343. if (!block_boxes.empty() &&
  344. block_boxes.back()->context == INLINE)
  345. block_boxes.back()->float_elements.push_back(element);
  346. // Nope ... just place it!
  347. else
  348. PositionFloat(element);
  349. return true;
  350. }
  351. // Adds an element to this block box to be handled as an absolutely-positioned element.
  352. void LayoutBlockBox::AddAbsoluteElement(Element* element)
  353. {
  354. ROCKET_ASSERT(context == BLOCK);
  355. AbsoluteElement absolute_element;
  356. absolute_element.element = element;
  357. PositionBox(absolute_element.position, 0);
  358. // If we have an open inline-context block box as our last child, then the absolute element must appear after it,
  359. // but not actually close the box.
  360. if (!block_boxes.empty()
  361. && block_boxes.back()->context == INLINE)
  362. {
  363. LayoutBlockBox* inline_context_box = block_boxes.back();
  364. float last_line_height = inline_context_box->line_boxes.back()->GetDimensions().y;
  365. absolute_element.position.y += (inline_context_box->box_cursor + Math::Max(0.0f, last_line_height));
  366. }
  367. // Find the positioned parent for this element.
  368. LayoutBlockBox* absolute_parent = this;
  369. while (absolute_parent != absolute_parent->offset_parent)
  370. absolute_parent = absolute_parent->parent;
  371. absolute_parent->absolute_elements.push_back(absolute_element);
  372. }
  373. // Lays out, sizes, and positions all absolute elements in this block relative to the containing block.
  374. void LayoutBlockBox::CloseAbsoluteElements()
  375. {
  376. if (!absolute_elements.empty())
  377. {
  378. // The size of the containing box, including the padding. This is used to resolve relative offsets.
  379. Vector2f containing_block = GetBox().GetSize(Box::PADDING);
  380. for (size_t i = 0; i < absolute_elements.size(); i++)
  381. {
  382. Element* absolute_element = absolute_elements[i].element;
  383. Vector2f absolute_position = absolute_elements[i].position;
  384. absolute_position -= position - offset_root->GetPosition();
  385. // Lay out the element.
  386. LayoutEngine layout_engine;
  387. layout_engine.FormatElement(absolute_element, containing_block);
  388. // Now that the element's box has been built, we can offset the position we determined was appropriate for
  389. // it by the element's margin. This is necessary because the coordinate system for the box begins at the
  390. // border, not the margin.
  391. absolute_position.x += absolute_element->GetBox().GetEdge(Box::MARGIN, Box::LEFT);
  392. absolute_position.y += absolute_element->GetBox().GetEdge(Box::MARGIN, Box::TOP);
  393. // Set the offset of the element; the element itself will take care of any RCSS-defined positional offsets.
  394. absolute_element->SetOffset(absolute_position, element);
  395. }
  396. absolute_elements.clear();
  397. }
  398. }
  399. // Returns the offset from the top-left corner of this box that the next child box will be positioned at.
  400. void LayoutBlockBox::PositionBox(Vector2f& box_position, float top_margin, int clear_property) const
  401. {
  402. // If our element is establishing a new offset hierarchy, then any children of ours don't inherit our offset.
  403. box_position = GetPosition();
  404. box_position += box.GetPosition();
  405. box_position.y += box_cursor;
  406. float clear_margin = space->ClearBoxes(box_position.y + top_margin, clear_property) - (box_position.y + top_margin);
  407. if (clear_margin > 0)
  408. box_position.y += clear_margin;
  409. else
  410. {
  411. // Check for a collapsing vertical margin.
  412. if (!block_boxes.empty() &&
  413. block_boxes.back()->context == BLOCK)
  414. {
  415. float bottom_margin = block_boxes.back()->GetBox().GetEdge(Box::MARGIN, Box::BOTTOM);
  416. box_position.y -= Math::Min(top_margin, bottom_margin);
  417. }
  418. }
  419. }
  420. // Returns the offset from the top-left corner of this box's offset element the next child block box, of the given
  421. // dimensions, will be positioned at. This will include the margins on the new block box.
  422. void LayoutBlockBox::PositionBlockBox(Vector2f& box_position, const Box& box, int clear_property) const
  423. {
  424. PositionBox(box_position, box.GetEdge(Box::MARGIN, Box::TOP), clear_property);
  425. box_position.x += box.GetEdge(Box::MARGIN, Box::LEFT);
  426. box_position.y += box.GetEdge(Box::MARGIN, Box::TOP);
  427. LayoutEngine::Round(box_position);
  428. }
  429. // Returns the offset from the top-left corner of this box for the next line.
  430. void LayoutBlockBox::PositionLineBox(Vector2f& box_position, float& box_width, bool& _wrap_content, const Vector2f& dimensions) const
  431. {
  432. Vector2f cursor;
  433. PositionBox(cursor);
  434. space->PositionBox(box_position, box_width, cursor.y, dimensions);
  435. // Also, probably shouldn't check for widths when positioning the box?
  436. _wrap_content = wrap_content;
  437. }
  438. // Returns the block box's element.
  439. Element* LayoutBlockBox::GetElement() const
  440. {
  441. return element;
  442. }
  443. // Returns the block box's parent.
  444. LayoutBlockBox* LayoutBlockBox::GetParent() const
  445. {
  446. return parent;
  447. }
  448. // Returns the position of the block box, relative to its parent's content area.
  449. const Vector2f& LayoutBlockBox::GetPosition() const
  450. {
  451. return position;
  452. }
  453. // Returns the element against which all positions of boxes in the hierarchy are calculated relative to.
  454. LayoutBlockBox* LayoutBlockBox::GetOffsetParent() const
  455. {
  456. return offset_parent;
  457. }
  458. // Returns the block box against which all positions of boxes in the hierarchy are calculated relative to.
  459. LayoutBlockBox* LayoutBlockBox::GetOffsetRoot() const
  460. {
  461. return offset_root;
  462. }
  463. // Returns the block box's dimension box.
  464. Box& LayoutBlockBox::GetBox()
  465. {
  466. return box;
  467. }
  468. // Returns the block box's dimension box.
  469. const Box& LayoutBlockBox::GetBox() const
  470. {
  471. return box;
  472. }
  473. void* LayoutBlockBox::operator new(size_t size)
  474. {
  475. void* memory = LayoutEngine::AllocateLayoutChunk(size);
  476. return memory;
  477. }
  478. void LayoutBlockBox::operator delete(void* chunk)
  479. {
  480. LayoutEngine::DeallocateLayoutChunk(chunk);
  481. }
  482. // Closes our last block box, if it is an open inline block box.
  483. LayoutBlockBox::CloseResult LayoutBlockBox::CloseInlineBlockBox()
  484. {
  485. if (!block_boxes.empty() &&
  486. block_boxes.back()->context == INLINE)
  487. return block_boxes.back()->Close();
  488. return OK;
  489. }
  490. // Positions a floating element within this block box.
  491. void LayoutBlockBox::PositionFloat(Element* element, float offset)
  492. {
  493. Vector2f box_position;
  494. PositionBox(box_position);
  495. space->PositionBox(box_position.y + offset, element);
  496. }
  497. // Checks if we have a new vertical overflow on an auto-scrolling element.
  498. bool LayoutBlockBox::CatchVerticalOverflow(float cursor)
  499. {
  500. if (cursor == -1)
  501. cursor = box_cursor;
  502. float box_height = box.GetSize().y;
  503. if (box_height < 0)
  504. box_height = max_height;
  505. // If we're auto-scrolling and our height is fixed, we have to check if this box has exceeded our client height.
  506. if (!vertical_overflow &&
  507. box_height >= 0 &&
  508. overflow_y_property == OVERFLOW_AUTO)
  509. {
  510. if (cursor > box_height - element->GetElementScroll()->GetScrollbarSize(ElementScroll::HORIZONTAL))
  511. {
  512. vertical_overflow = true;
  513. element->GetElementScroll()->EnableScrollbar(ElementScroll::VERTICAL, box.GetSize(Box::PADDING).x);
  514. for (size_t i = 0; i < block_boxes.size(); i++)
  515. delete block_boxes[i];
  516. block_boxes.clear();
  517. delete space;
  518. space = new LayoutBlockBoxSpace(this);
  519. box_cursor = 0;
  520. interrupted_chain = NULL;
  521. return false;
  522. }
  523. }
  524. return true;
  525. }
  526. }
  527. }