1<?php
2class GenericInlineBox extends GenericContainerBox {
3  function GenericInlineBox() {
4    $this->GenericContainerBox();
5  }
6
7  // @todo this code is duplicated in box.block.php
8  //
9  function reflow(&$parent, &$context) {
10    switch ($this->get_css_property(CSS_POSITION)) {
11    case POSITION_STATIC:
12      return $this->reflow_static($parent, $context);
13
14    case POSITION_RELATIVE:
15      /**
16       * CSS 2.1:
17       * Once a box has been laid out according to the normal flow or floated, it may be shifted relative
18       * to this position. This is called relative positioning. Offsetting a box (B1) in this way has no
19       * effect on the box (B2) that follows: B2 is given a position as if B1 were not offset and B2 is
20       * not re-positioned after B1's offset is applied. This implies that relative positioning may cause boxes
21       * to overlap. However, if relative positioning causes an 'overflow:auto' box to have overflow, the UA must
22       * allow the user to access this content, which, through the creation of scrollbars, may affect layout.
23       *
24       * @link http://www.w3.org/TR/CSS21/visuren.html#x28 CSS 2.1 Relative positioning
25       */
26
27      $this->reflow_static($parent, $context);
28      $this->offsetRelative();
29      return;
30    }
31  }
32
33  // Checks if current inline box should cause a line break inside the parent box
34  //
35  // @param $parent reference to a parent box
36  // @param $content flow context
37  // @return true if line break occurred; false otherwise
38  //
39  function maybe_line_break(&$parent, &$context) {
40    if (!$parent->line_break_allowed()) {
41      return false;
42    };
43
44    // Calculate the x-coordinate of this box right edge
45    $right_x = $this->get_full_width() + $parent->_current_x;
46
47    $need_break = false;
48
49    // Check for right-floating boxes
50    // If upper-right corner of this inline box is inside of some float, wrap the line
51    if ($context->point_in_floats($right_x, $parent->_current_y)) {
52      $need_break = true;
53    };
54
55    // No floats; check if we had run out the right edge of container
56    // TODO: nobr-before, nobr-after
57
58    if (($right_x > $parent->get_right() + EPSILON)) {
59      // Now check if parent line box contains any other boxes;
60      // if not, we should draw this box unless we have a floating box to the left
61
62      $first = $parent->get_first();
63
64      // FIXME: what's this? This condition is invariant!
65      $text_indent = $parent->get_css_property(CSS_TEXT_INDENT);
66      $indent_offset = ($first->uid == $this->uid || 1) ? $text_indent->calculate($parent) : 0;
67
68      if ($parent->_current_x > $parent->get_left() + $indent_offset + EPSILON) {
69        $need_break = true;
70      };
71    }
72
73    // As close-line will not change the current-Y parent coordinate if no
74    // items were in the line box, we need to offset this explicitly in this case
75    //
76    if ($parent->line_box_empty() && $need_break) {
77      $parent->_current_y -= $this->get_height();
78    };
79
80    if ($need_break) {
81      $parent->close_line($context);
82
83      // Check if parent inline boxes have left padding/margins and add them to current_x
84      $element = $this->parent;
85      while (!is_null($element) && is_a($element,"GenericInlineBox")) {
86        $parent->_current_x += $element->get_extra_left();
87        $element = $element->parent;
88      };
89    };
90
91    return $need_break;
92  }
93
94  function get_ascender() {
95    $first =& $this->get_first();
96    if (is_null($first)) { return 0; };
97    return $first->get_ascender();
98  }
99
100  function get_baseline() {
101    $first =& $this->get_first();
102    if (is_null($first)) { return 0; };
103    return $first->get_baseline();
104  }
105
106  function get_descender() {
107    $first =& $this->get_first();
108    if (is_null($first)) { return 0; };
109    return $first->get_descender();
110  }
111}
112?>