Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
// $Header: /cvsroot/html2ps/box.block.inline.php,v 1.21 2007/04/07 11:16:33 Konstantin Exp $
3
 
4
/**
5
 * @package HTML2PS
6
 * @subpackage Document
7
 *
8
 * Describes document elements with 'display: inline-block'.
9
 *
10
 * @link http://www.w3.org/TR/CSS21/visuren.html#value-def-inline-block CSS 2.1 description of 'display: inline-block'
11
 */
12
class InlineBlockBox extends GenericContainerBox {
13
  /**
14
   * Create new 'inline-block' element; add content from the parsed HTML tree automatically.
15
   *
16
   * @see InlineBlockBox::InlineBlockBox()
17
   * @see GenericContainerBox::create_content()
18
   */
19
  function &create(&$root, &$pipeline) {
20
    $box = new InlineBlockBox();
21
    $box->readCSS($pipeline->get_current_css_state());
22
    $box->create_content($root, $pipeline);
23
    return $box;
24
  }
25
 
26
  function InlineBlockBox() {
27
    $this->GenericContainerBox();
28
  }
29
 
30
  /**
31
   * Layout current inline-block element
32
   *
33
   * @param GenericContainerBox $parent The document element which should be treated as the parent of current element
34
   * @param FlowContext $context The flow context containing the additional layout data
35
   *
36
   * @see FlowContext
37
   * @see GenericContainerBox
38
   * @see BlockBox::reflow
39
   *
40
   * @todo this 'reflow' skeleton is common for all element types; thus, we probably should move the generic 'reflow'
41
   * definition to the GenericFormattedBox class, leaving only box-specific 'reflow_static' definitions in specific classes.
42
   *
43
   * @todo make relative positioning more CSS 2.1 compliant; currently, 'bottom' and 'right' CSS properties are ignored.
44
   *
45
   * @todo check whether percentage values should be really ignored during relative positioning
46
   */
47
  function reflow(&$parent, &$context) {
48
    /**
49
     * Note that we may not worry about 'position: absolute' and 'position: fixed',
50
     * as, according to CSS 2.1 paragraph 9.7, these values of 'position'
51
     * will cause 'display' value to change to either 'block' or 'table'. Thus,
52
     * 'inline-block' boxes will never have 'position' value other than 'static' or 'relative'
53
     *
54
     * @link http://www.w3.org/TR/CSS21/visuren.html#dis-pos-flo CSS 2.1: Relationships between 'display', 'position', and 'float'
55
     */
56
 
57
    switch ($this->get_css_property(CSS_POSITION)) {
58
    case POSITION_STATIC:
59
      return $this->reflow_static($parent, $context);
60
 
61
    case POSITION_RELATIVE:
62
      /**
63
       * CSS 2.1:
64
       * Once a box has been laid out according to the normal flow or floated, it may be shifted relative
65
       * to this position. This is called relative positioning. Offsetting a box (B1) in this way has no
66
       * effect on the box (B2) that follows: B2 is given a position as if B1 were not offset and B2 is
67
       * not re-positioned after B1's offset is applied. This implies that relative positioning may cause boxes
68
       * to overlap. However, if relative positioning causes an 'overflow:auto' box to have overflow, the UA must
69
       * allow the user to access this content, which, through the creation of scrollbars, may affect layout.
70
       *
71
       * @link http://www.w3.org/TR/CSS21/visuren.html#x28 CSS 2.1 Relative positioning
72
       */
73
 
74
      $this->reflow_static($parent, $context);
75
      $this->offsetRelative();
76
 
77
      return;
78
    }
79
  }
80
 
81
  /**
82
   * Layout current 'inline-block' element assument it has 'position: static'
83
   *
84
   * @param GenericContainerBox $parent The document element which should
85
   * be treated as the parent of current element
86
   *
87
   * @param FlowContext $context The flow context containing the additional layout data
88
   *
89
   * @see FlowContext
90
   * @see GenericContainerBox
91
   *
92
   * @todo re-check this layout routine; it seems that 'inline-block' boxes have
93
   * their width calculated incorrectly
94
   */
95
  function reflow_static(&$parent, &$context) {
96
    GenericFormattedBox::reflow($parent, $context);
97
 
98
    /**
99
     * Calculate margin values if they have been set as a percentage
100
     */
101
    $this->_calc_percentage_margins($parent);
102
    $this->_calc_percentage_padding($parent);
103
 
104
    /**
105
     * Calculate width value if it had been set as a percentage
106
     */
107
    $this->_calc_percentage_width($parent, $context);
108
 
109
    /**
110
     * Calculate 'auto' values of width and margins
111
     */
112
    $this->_calc_auto_width_margins($parent);
113
 
114
    /**
115
     * add current box to the parent's line-box (alone)
116
     */
117
    $parent->append_line($this);
118
 
119
    /**
120
     * Calculate position of the upper-left corner of the current box
121
     */
122
    $this->guess_corner($parent);
123
 
124
    /**
125
     * By default, child block box will fill all available parent width;
126
     * note that actual content width will be smaller because of non-zero padding, border and margins
127
     */
128
    $this->put_full_width($parent->get_width());
129
 
130
    /**
131
     * Layout element's children
132
     */
133
    $this->reflow_content($context);
134
 
135
    /**
136
     * Calculate element's baseline, as it should be aligned inside the
137
     * parent's line box vertically
138
     */
139
    $font = $this->get_css_property(CSS_FONT);
140
    $this->default_baseline = $this->get_height() + $font->size->getPoints();
141
 
142
    /**
143
     * Extend parent's height to fit current box
144
     */
145
    $parent->extend_height($this->get_bottom_margin());
146
 
147
    /**
148
     * Offset current x coordinate of parent box
149
     */
150
    $parent->_current_x = $this->get_right_margin();
151
  }
152
}
153
?>