KHtml

css_renderstyledeclarationimpl.cpp
1 /**
2  * css_renderstyledeclarationimpl.cpp
3  *
4  * Copyright 2004 Zack Rusin <[email protected]>
5  * Copyright 2004,2005 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 #include "css_renderstyledeclarationimpl.h"
23 
24 #include "rendering/render_object.h"
25 
26 #include "cssproperties.h"
27 #include "cssvalues.h"
28 
29 #include <dom/dom_exception.h>
30 
31 using namespace DOM;
32 using namespace khtml;
33 
34 // List of all properties we know how to compute, omitting shorthands.
35 static const int computedProperties[] = {
36  CSS_PROP_BACKGROUND_COLOR,
37  CSS_PROP_BACKGROUND_CLIP,
38  CSS_PROP_BACKGROUND_IMAGE,
39  CSS_PROP_BACKGROUND_REPEAT,
40  CSS_PROP_BACKGROUND_ATTACHMENT,
41  CSS_PROP_BACKGROUND_ORIGIN,
42  CSS_PROP_BACKGROUND_POSITION,
43  CSS_PROP_BACKGROUND_POSITION_X,
44  CSS_PROP_BACKGROUND_POSITION_Y,
45  CSS_PROP_BACKGROUND_SIZE,
46  CSS_PROP_BORDER_COLLAPSE,
47  CSS_PROP_BORDER_SPACING,
48  CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING,
49  CSS_PROP__KHTML_BORDER_VERTICAL_SPACING,
50  CSS_PROP_BORDER_TOP_RIGHT_RADIUS,
51  CSS_PROP_BORDER_BOTTOM_RIGHT_RADIUS,
52  CSS_PROP_BORDER_BOTTOM_LEFT_RADIUS,
53  CSS_PROP_BORDER_TOP_LEFT_RADIUS,
54  CSS_PROP_BORDER_TOP_COLOR,
55  CSS_PROP_BORDER_RIGHT_COLOR,
56  CSS_PROP_BORDER_BOTTOM_COLOR,
57  CSS_PROP_BORDER_LEFT_COLOR,
58  CSS_PROP_BORDER_TOP_STYLE,
59  CSS_PROP_BORDER_RIGHT_STYLE,
60  CSS_PROP_BORDER_BOTTOM_STYLE,
61  CSS_PROP_BORDER_LEFT_STYLE,
62  CSS_PROP_BORDER_TOP_WIDTH,
63  CSS_PROP_BORDER_RIGHT_WIDTH,
64  CSS_PROP_BORDER_BOTTOM_WIDTH,
65  CSS_PROP_BORDER_LEFT_WIDTH,
66  CSS_PROP_BOTTOM,
67  CSS_PROP_BOX_SIZING,
68  CSS_PROP_CAPTION_SIDE,
69  CSS_PROP_CLEAR,
70  CSS_PROP_COLOR,
71  CSS_PROP_CURSOR,
72  CSS_PROP_DIRECTION,
73  CSS_PROP_DISPLAY,
74  CSS_PROP_EMPTY_CELLS,
75  CSS_PROP_FLOAT,
76  CSS_PROP_FONT_FAMILY,
77  CSS_PROP_FONT_SIZE,
78  CSS_PROP_FONT_STYLE,
79  CSS_PROP_FONT_VARIANT,
80  CSS_PROP_FONT_WEIGHT,
81  CSS_PROP_HEIGHT,
82  CSS_PROP_LEFT,
83  CSS_PROP_LETTER_SPACING,
84  CSS_PROP_LINE_HEIGHT,
85  CSS_PROP_LIST_STYLE_IMAGE,
86  CSS_PROP_LIST_STYLE_POSITION,
87  CSS_PROP_LIST_STYLE_TYPE,
88  CSS_PROP_MARGIN_TOP,
89  CSS_PROP_MARGIN_RIGHT,
90  CSS_PROP_MARGIN_BOTTOM,
91  CSS_PROP_MARGIN_LEFT,
92  CSS_PROP__KHTML_MARQUEE_DIRECTION,
93  CSS_PROP__KHTML_MARQUEE_INCREMENT,
94  CSS_PROP__KHTML_MARQUEE_REPETITION,
95  CSS_PROP__KHTML_MARQUEE_STYLE,
96  CSS_PROP_MAX_HEIGHT,
97  CSS_PROP_MAX_WIDTH,
98  CSS_PROP_MIN_HEIGHT,
99  CSS_PROP_MIN_WIDTH,
100  CSS_PROP_OPACITY,
101  CSS_PROP_ORPHANS,
102  CSS_PROP_OUTLINE_STYLE,
103  CSS_PROP_OVERFLOW,
104  CSS_PROP_OVERFLOW_X,
105  CSS_PROP_OVERFLOW_Y,
106  CSS_PROP_PADDING_TOP,
107  CSS_PROP_PADDING_RIGHT,
108  CSS_PROP_PADDING_BOTTOM,
109  CSS_PROP_PADDING_LEFT,
110  CSS_PROP_PAGE_BREAK_AFTER,
111  CSS_PROP_PAGE_BREAK_BEFORE,
112  CSS_PROP_PAGE_BREAK_INSIDE,
113  CSS_PROP_POSITION,
114  CSS_PROP_RIGHT,
115  CSS_PROP_TABLE_LAYOUT,
116  CSS_PROP_TEXT_ALIGN,
117  CSS_PROP_TEXT_DECORATION,
118  CSS_PROP_TEXT_INDENT,
119  CSS_PROP_TEXT_OVERFLOW,
120  CSS_PROP_TEXT_SHADOW,
121  CSS_PROP_TEXT_TRANSFORM,
122  CSS_PROP_TOP,
123  CSS_PROP_UNICODE_BIDI,
124  CSS_PROP_VERTICAL_ALIGN,
125  CSS_PROP_VISIBILITY,
126  CSS_PROP_WHITE_SPACE,
127  CSS_PROP_WIDOWS,
128  CSS_PROP_WIDTH,
129  CSS_PROP_WORD_SPACING,
130  CSS_PROP_Z_INDEX
131 };
132 
133 const unsigned numComputedProperties = sizeof(computedProperties) / sizeof(computedProperties[0]);
134 
135 static CSSPrimitiveValueImpl *valueForLength(const Length &length, int max)
136 {
137  if (length.isPercent()) {
138  return new CSSPrimitiveValueImpl(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
139  } else {
140  return new CSSPrimitiveValueImpl(length.minWidth(max), CSSPrimitiveValue::CSS_PX);
141  }
142 }
143 
144 static CSSPrimitiveValueImpl *valueForLength2(const Length &length)
145 {
146  if (length.isPercent()) {
147  return new CSSPrimitiveValueImpl(length.percent(), CSSPrimitiveValue::CSS_PERCENTAGE);
148  } else {
149  return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
150  }
151 }
152 
153 static CSSValueImpl *valueForBorderStyle(EBorderStyle style)
154 {
155  switch (style) {
156  case khtml::BNATIVE:
157  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NATIVE);
158  case khtml::BNONE:
159  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
160  case khtml::BHIDDEN:
161  return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
162  case khtml::INSET:
163  return new CSSPrimitiveValueImpl(CSS_VAL_INSET);
164  case khtml::GROOVE:
165  return new CSSPrimitiveValueImpl(CSS_VAL_GROOVE);
166  case khtml::RIDGE:
167  return new CSSPrimitiveValueImpl(CSS_VAL_RIDGE);
168  case khtml::OUTSET:
169  return new CSSPrimitiveValueImpl(CSS_VAL_OUTSET);
170  case khtml::DOTTED:
171  return new CSSPrimitiveValueImpl(CSS_VAL_DOTTED);
172  case khtml::DASHED:
173  return new CSSPrimitiveValueImpl(CSS_VAL_DASHED);
174  case khtml::SOLID:
175  return new CSSPrimitiveValueImpl(CSS_VAL_SOLID);
176  case khtml::DOUBLE:
177  return new CSSPrimitiveValueImpl(CSS_VAL_DOUBLE);
178  }
179  Q_ASSERT(0);
180  return nullptr;
181 }
182 
183 static CSSValueImpl *valueForBorderRadii(BorderRadii radii)
184 {
185  CSSPrimitiveValueImpl *h = valueForLength2(radii.horizontal);
186  CSSPrimitiveValueImpl *v = valueForLength2(radii.vertical);
187  return new CSSPrimitiveValueImpl(new PairImpl(h, v));
188 }
189 
190 static CSSValueImpl *valueForTextAlign(ETextAlign align)
191 {
192  switch (align) {
193  case khtml::TAAUTO:
194  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
195  case khtml::LEFT:
196  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
197  case khtml::RIGHT:
198  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
199  case khtml::CENTER:
200  return new CSSPrimitiveValueImpl(CSS_VAL_CENTER);
201  case khtml::JUSTIFY:
202  return new CSSPrimitiveValueImpl(CSS_VAL_JUSTIFY);
203  case khtml::KHTML_LEFT:
204  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
205  case khtml::KHTML_RIGHT:
206  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
207  case khtml::KHTML_CENTER:
208  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_CENTER);
209  }
210  Q_ASSERT(0);
211  return nullptr;
212 }
213 
214 DOMString khtml::stringForListStyleType(EListStyleType type)
215 {
216  switch (type) {
217  case khtml::LDISC:
218  return "disc";
219  case khtml::LCIRCLE:
220  return "circle";
221  case khtml::LSQUARE:
222  return "square";
223  case khtml::LBOX:
224  return "box";
225  case khtml::LDIAMOND:
226  return "-khtml-diamond";
227  case khtml::LDECIMAL:
228  return "decimal";
229  case khtml::DECIMAL_LEADING_ZERO:
230  return "decimal-leading-zero";
231  case khtml::ARABIC_INDIC:
232  return "-khtml-arabic-indic";
233  case khtml::LAO:
234  return "-khtml-lao";
235  case khtml::PERSIAN:
236  return "-khtml-persian";
237  case khtml::URDU:
238  return "-khtml-urdu";
239  case khtml::THAI:
240  return "-khtml-thai";
241  case khtml::TIBETAN:
242  return "-khtml-tibetan";
243  case khtml::LOWER_ROMAN:
244  return "lower-roman";
245  case khtml::UPPER_ROMAN:
246  return "upper-roman";
247  case khtml::HEBREW:
248  return "hebrew";
249  case khtml::ARMENIAN:
250  return "armenian";
251  case khtml::GEORGIAN:
252  return "georgian";
253  case khtml::CJK_IDEOGRAPHIC:
254  return "cjk-ideographic";
255  case khtml::JAPANESE_FORMAL:
256  return "-khtml-japanese-formal";
257  case khtml::JAPANESE_INFORMAL:
258  return "-khtml-japanese-informal";
259  case khtml::SIMP_CHINESE_FORMAL:
260  return "-khtml-simp-chinese-formal";
261  case khtml::SIMP_CHINESE_INFORMAL:
262  return "-khtml-simp-chinese-informal";
263  case khtml::TRAD_CHINESE_FORMAL:
264  return "-khtml-trad-chinese-formal";
265  case khtml::TRAD_CHINESE_INFORMAL:
266  return "-khtml-trad-chinese-informal";
267  case khtml::LOWER_GREEK:
268  return "lower-greek";
269  case khtml::UPPER_GREEK:
270  return "-khtml-upper-greek";
271  case khtml::LOWER_ALPHA:
272  return "lower-alpha";
273  case khtml::UPPER_ALPHA:
274  return "upper-alpha";
275  case khtml::LOWER_LATIN:
276  return "lower-latin";
277  case khtml::UPPER_LATIN:
278  return "upper-latin";
279  case khtml::HIRAGANA:
280  return "hiragana";
281  case khtml::KATAKANA:
282  return "katakana";
283  case khtml::HIRAGANA_IROHA:
284  return "hiragana-iroha";
285  case khtml::KATAKANA_IROHA:
286  return "katakana_iroha";
287  case khtml::LNONE:
288  return "none";
289  }
290  Q_ASSERT(0);
291  return "";
292 }
293 
294 static CSSPrimitiveValueImpl *valueForColor(QColor color)
295 {
296  if (color.isValid()) {
297  return new CSSPrimitiveValueImpl(color.rgba());
298  } else {
299  return new CSSPrimitiveValueImpl(khtml::transparentColor);
300  }
301 }
302 
303 static CSSValueImpl *valueForShadow(const ShadowData *shadow)
304 {
305  if (!shadow) {
306  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
307  }
308  CSSValueListImpl *list = new CSSValueListImpl(CSSValueListImpl::Comma);
309  for (const ShadowData *s = shadow; s; s = s->next) {
310  CSSPrimitiveValueImpl *x = new CSSPrimitiveValueImpl(s->x, CSSPrimitiveValue::CSS_PX);
311  CSSPrimitiveValueImpl *y = new CSSPrimitiveValueImpl(s->y, CSSPrimitiveValue::CSS_PX);
312  CSSPrimitiveValueImpl *blur = new CSSPrimitiveValueImpl(s->blur, CSSPrimitiveValue::CSS_PX);
313  CSSPrimitiveValueImpl *color = valueForColor(s->color);
314  list->append(new ShadowValueImpl(x, y, blur, color));
315  }
316  return list;
317 }
318 
319 static CSSValueImpl *getPositionOffsetValue(RenderObject *renderer, int propertyID)
320 {
321  if (!renderer) {
322  return nullptr;
323  }
324 
325  RenderStyle *style = renderer->style();
326  if (!style) {
327  return nullptr;
328  }
329 
330  Length l;
331  switch (propertyID) {
332  case CSS_PROP_LEFT:
333  l = style->left();
334  break;
335  case CSS_PROP_RIGHT:
336  l = style->right();
337  break;
338  case CSS_PROP_TOP:
339  l = style->top();
340  break;
341  case CSS_PROP_BOTTOM:
342  l = style->bottom();
343  break;
344  default:
345  return nullptr;
346  }
347 
348  if (renderer->isPositioned()) {
349  return valueForLength(l, renderer->contentWidth());
350  }
351 
352  if (renderer->isRelPositioned())
353  // FIXME: It's not enough to simply return "auto" values for one offset if the other side is defined.
354  // In other words if left is auto and right is not auto, then left's computed value is negative right.
355  // So we should get the opposite length unit and see if it is auto.
356  {
357  return valueForLength(l, renderer->contentWidth());
358  }
359 
360  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
361 }
362 
363 RenderStyleDeclarationImpl::RenderStyleDeclarationImpl(DOM::NodeImpl *node)
364  : CSSStyleDeclarationImpl(nullptr), m_node(node)
365 {
366  //qCDebug(KHTML_LOG) << "Render Style Declaration created";
367 }
368 
369 RenderStyleDeclarationImpl::~RenderStyleDeclarationImpl()
370 {
371  //qCDebug(KHTML_LOG) << "Render Style Declaration destroyed";
372 }
373 
374 DOM::DOMString RenderStyleDeclarationImpl::cssText() const
375 {
376  DOMString result;
377 
378  for (unsigned i = 0; i < numComputedProperties; i++) {
379  if (i != 0) {
380  result += " ";
381  }
382  result += getPropertyName(computedProperties[i]);
383  result += ": ";
384  result += getPropertyValue(computedProperties[i]);
385  result += ";";
386  }
387 
388  return result;
389 }
390 
391 void RenderStyleDeclarationImpl::setCssText(DOM::DOMString)
392 {
393  // ### report that this sucka is read only
394 }
395 
396 CSSValueImpl *RenderStyleDeclarationImpl::getPropertyCSSValue(int propertyID) const
397 {
398  NodeImpl *node = m_node.get();
399  if (!node) {
400  return nullptr;
401  }
402 
403  // Make sure our layout is up to date before we allow a query on these attributes.
404  DocumentImpl *docimpl = node->document();
405  if (docimpl) {
406  docimpl->updateLayout();
407  }
408 
409  RenderStyle *style = node->computedStyle();
410  if (!style) {
411  return nullptr;
412  }
413  RenderObject *renderer = node->renderer(); // can be NULL
414 
415  // temporary(?) measure to handle with missing render object
416  // check how we can better deal with it on a case-by-case basis
417 #define RETURN_NULL_ON_NULL(ptr) if(ptr == nullptr) return nullptr;
418 
419  switch (propertyID) {
420  case CSS_PROP_BACKGROUND_COLOR:
421  return valueForColor(style->backgroundColor());
422  case CSS_PROP_BACKGROUND_CLIP:
423  switch (style->backgroundLayers()->backgroundClip()) {
424  case BGBORDER:
425  return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
426  case BGPADDING:
427  return new CSSPrimitiveValueImpl(CSS_VAL_PADDING_BOX);
428  case BGCONTENT:
429  return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
430  }
431  Q_ASSERT(0);
432  break;
433  case CSS_PROP_BACKGROUND_IMAGE:
434  if (style->backgroundImage())
435  return new CSSPrimitiveValueImpl(style->backgroundImage()->url(),
436  CSSPrimitiveValue::CSS_URI);
437  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
438  case CSS_PROP_BACKGROUND_REPEAT:
439  switch (style->backgroundRepeat()) {
440  case khtml::REPEAT:
441  return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT);
442  case khtml::REPEAT_X:
443  return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_X);
444  case khtml::REPEAT_Y:
445  return new CSSPrimitiveValueImpl(CSS_VAL_REPEAT_Y);
446  case khtml::NO_REPEAT:
447  return new CSSPrimitiveValueImpl(CSS_VAL_NO_REPEAT);
448  default:
449  Q_ASSERT(0);
450  }
451  break;
452  case CSS_PROP_BACKGROUND_ATTACHMENT:
453  switch (style->backgroundAttachment()) {
454  case khtml::BGASCROLL:
455  return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
456  case khtml::BGAFIXED:
457  return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
458  case khtml::BGALOCAL:
459  return new CSSPrimitiveValueImpl(CSS_VAL_LOCAL);
460  default:
461  Q_ASSERT(0);
462  }
463  break;
464  case CSS_PROP_BACKGROUND_ORIGIN:
465  switch (style->backgroundLayers()->backgroundOrigin()) {
466  case BGBORDER:
467  return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
468  case BGPADDING:
469  return new CSSPrimitiveValueImpl(CSS_VAL_PADDING_BOX);
470  case BGCONTENT:
471  return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
472  }
473  Q_ASSERT(0);
474  break;
475  case CSS_PROP_BACKGROUND_POSITION: {
476  RETURN_NULL_ON_NULL(renderer);
477  CSSValueListImpl *values = new CSSValueListImpl(CSSValueListImpl::Space);
478  values->append(valueForLength(style->backgroundXPosition(), renderer->contentWidth()));
479  values->append(valueForLength(style->backgroundYPosition(), renderer->contentHeight()));
480  return values;
481  }
482  case CSS_PROP_BACKGROUND_POSITION_X:
483  RETURN_NULL_ON_NULL(renderer);
484  return valueForLength(style->backgroundXPosition(), renderer->contentWidth());
485  case CSS_PROP_BACKGROUND_POSITION_Y:
486  RETURN_NULL_ON_NULL(renderer);
487  return valueForLength(style->backgroundYPosition(), renderer->contentHeight());
488  case CSS_PROP_BACKGROUND_SIZE: {
489  const EBackgroundSizeType backgroundSizeType = style->backgroundLayers()->backgroundSize().type;
490  switch (backgroundSizeType) {
491  case BGSCONTAIN:
492  return new CSSPrimitiveValueImpl(CSS_VAL_CONTAIN);
493  case BGSCOVER:
494  return new CSSPrimitiveValueImpl(CSS_VAL_COVER);
495  case BGSLENGTH: {
496  const BGSize bgSize = style->backgroundLayers()->backgroundSize();
497  CSSValueListImpl *values = new CSSValueListImpl(CSSValueListImpl::Space);
498  switch (bgSize.width.type()) {
499  case Auto:
500  values->append(new CSSPrimitiveValueImpl(CSS_VAL_AUTO));
501  break;
502  case Percent:
503  values->append(new CSSPrimitiveValueImpl(bgSize.width.percent(), CSSPrimitiveValue::CSS_PERCENTAGE));
504  break;
505  default:
506  values->append(new CSSPrimitiveValueImpl(bgSize.width.value(), CSSPrimitiveValue::CSS_PX));
507  }
508  switch (bgSize.height.type()) {
509  case Auto:
510  values->append(new CSSPrimitiveValueImpl(CSS_VAL_AUTO));
511  break;
512  case Percent:
513  values->append(new CSSPrimitiveValueImpl(bgSize.height.percent(), CSSPrimitiveValue::CSS_PERCENTAGE));
514  break;
515  default:
516  values->append(new CSSPrimitiveValueImpl(bgSize.height.value(), CSSPrimitiveValue::CSS_PX));
517  }
518  return values;
519  }
520  default:
521  Q_ASSERT(0);
522  }
523  break;
524  }
525  case CSS_PROP_BORDER_COLLAPSE:
526  if (style->borderCollapse()) {
527  return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
528  } else {
529  return new CSSPrimitiveValueImpl(CSS_VAL_SEPARATE);
530  }
531  case CSS_PROP_BORDER_SPACING: {
532  CSSValueListImpl *values = new CSSValueListImpl(CSSValueListImpl::Space);
533  values->append(new CSSPrimitiveValueImpl(style->borderHorizontalSpacing(), CSSPrimitiveValue::CSS_PX));
534  values->append(new CSSPrimitiveValueImpl(style->borderVerticalSpacing(), CSSPrimitiveValue::CSS_PX));
535  return values;
536  }
537  case CSS_PROP__KHTML_BORDER_HORIZONTAL_SPACING:
538  return new CSSPrimitiveValueImpl(style->borderHorizontalSpacing(), CSSPrimitiveValue::CSS_PX);
539  case CSS_PROP__KHTML_BORDER_VERTICAL_SPACING:
540  return new CSSPrimitiveValueImpl(style->borderVerticalSpacing(), CSSPrimitiveValue::CSS_PX);
541  case CSS_PROP_BORDER_TOP_RIGHT_RADIUS:
542  return valueForBorderRadii(style->borderTopRightRadius());
543  case CSS_PROP_BORDER_BOTTOM_RIGHT_RADIUS:
544  return valueForBorderRadii(style->borderBottomRightRadius());
545  case CSS_PROP_BORDER_BOTTOM_LEFT_RADIUS:
546  return valueForBorderRadii(style->borderBottomLeftRadius());
547  case CSS_PROP_BORDER_TOP_LEFT_RADIUS:
548  return valueForBorderRadii(style->borderTopLeftRadius());
549  case CSS_PROP_BORDER_TOP_COLOR:
550  return valueForColor(style->borderTopColor());
551  case CSS_PROP_BORDER_RIGHT_COLOR:
552  return valueForColor(style->borderRightColor());
553  case CSS_PROP_BORDER_BOTTOM_COLOR:
554  return valueForColor(style->borderBottomColor());
555  case CSS_PROP_BORDER_LEFT_COLOR:
556  return valueForColor(style->borderLeftColor());
557  case CSS_PROP_BORDER_TOP_STYLE:
558  return valueForBorderStyle(style->borderTopStyle());
559  case CSS_PROP_BORDER_RIGHT_STYLE:
560  return valueForBorderStyle(style->borderRightStyle());
561  case CSS_PROP_BORDER_BOTTOM_STYLE:
562  return valueForBorderStyle(style->borderBottomStyle());
563  case CSS_PROP_BORDER_LEFT_STYLE:
564  return valueForBorderStyle(style->borderLeftStyle());
565  case CSS_PROP_BORDER_TOP_WIDTH:
566  return new CSSPrimitiveValueImpl(style->borderTopWidth(), CSSPrimitiveValue::CSS_PX);
567  case CSS_PROP_BORDER_RIGHT_WIDTH:
568  return new CSSPrimitiveValueImpl(style->borderRightWidth(), CSSPrimitiveValue::CSS_PX);
569  case CSS_PROP_BORDER_BOTTOM_WIDTH:
570  return new CSSPrimitiveValueImpl(style->borderBottomWidth(), CSSPrimitiveValue::CSS_PX);
571  case CSS_PROP_BORDER_LEFT_WIDTH:
572  return new CSSPrimitiveValueImpl(style->borderLeftWidth(), CSSPrimitiveValue::CSS_PX);
573  case CSS_PROP_BOTTOM:
574  RETURN_NULL_ON_NULL(renderer);
575  return getPositionOffsetValue(renderer, CSS_PROP_BOTTOM);
576  case CSS_PROP_BOX_SIZING:
577  if (style->boxSizing() == BORDER_BOX) {
578  return new CSSPrimitiveValueImpl(CSS_VAL_BORDER_BOX);
579  } else {
580  return new CSSPrimitiveValueImpl(CSS_VAL_CONTENT_BOX);
581  }
582  case CSS_PROP_CAPTION_SIDE:
583  switch (style->captionSide()) {
584  case CAPLEFT:
585  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
586  case CAPRIGHT:
587  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
588  case CAPTOP:
589  return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
590  case CAPBOTTOM:
591  return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
592  }
593  Q_ASSERT(0);
594  break;
595  case CSS_PROP_CLEAR:
596  switch (style->clear()) {
597  case CNONE:
598  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
599  case CLEFT:
600  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
601  case CRIGHT:
602  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
603  case CBOTH:
604  return new CSSPrimitiveValueImpl(CSS_VAL_BOTH);
605  }
606  Q_ASSERT(0);
607  break;
608  case CSS_PROP_CLIP:
609  break;
610  case CSS_PROP_COLOR:
611  return valueForColor(style->color());
612  case CSS_PROP_CONTENT:
613  break;
614  case CSS_PROP_COUNTER_INCREMENT:
615  break;
616  case CSS_PROP_COUNTER_RESET:
617  break;
618  case CSS_PROP_CURSOR:
619  switch (style->cursor()) {
620  case CURSOR_AUTO:
621  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
622  case CURSOR_DEFAULT:
623  return new CSSPrimitiveValueImpl(CSS_VAL_DEFAULT);
624  case CURSOR_NONE:
625  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
626  case CURSOR_CONTEXT_MENU:
627  return new CSSPrimitiveValueImpl(CSS_VAL_CONTEXT_MENU);
628  case CURSOR_HELP:
629  return new CSSPrimitiveValueImpl(CSS_VAL_HELP);
630  case CURSOR_POINTER:
631  return new CSSPrimitiveValueImpl(CSS_VAL_POINTER);
632  case CURSOR_PROGRESS:
633  return new CSSPrimitiveValueImpl(CSS_VAL_PROGRESS);
634  case CURSOR_WAIT:
635  return new CSSPrimitiveValueImpl(CSS_VAL_WAIT);
636  case CURSOR_CELL:
637  return new CSSPrimitiveValueImpl(CSS_VAL_CELL);
638  case CURSOR_CROSS:
639  return new CSSPrimitiveValueImpl(CSS_VAL_CROSSHAIR);
640  case CURSOR_TEXT:
641  return new CSSPrimitiveValueImpl(CSS_VAL_TEXT);
642  case CURSOR_VERTICAL_TEXT:
643  return new CSSPrimitiveValueImpl(CSS_VAL_VERTICAL_TEXT);
644  case CURSOR_ALIAS:
645  return new CSSPrimitiveValueImpl(CSS_VAL_ALIAS);
646  case CURSOR_COPY:
647  return new CSSPrimitiveValueImpl(CSS_VAL_COPY);
648  case CURSOR_MOVE:
649  return new CSSPrimitiveValueImpl(CSS_VAL_MOVE);
650  case CURSOR_NO_DROP:
651  return new CSSPrimitiveValueImpl(CSS_VAL_NO_DROP);
652  case CURSOR_NOT_ALLOWED:
653  return new CSSPrimitiveValueImpl(CSS_VAL_NOT_ALLOWED);
654  case CURSOR_E_RESIZE:
655  return new CSSPrimitiveValueImpl(CSS_VAL_E_RESIZE);
656  case CURSOR_N_RESIZE:
657  return new CSSPrimitiveValueImpl(CSS_VAL_N_RESIZE);
658  case CURSOR_NE_RESIZE:
659  return new CSSPrimitiveValueImpl(CSS_VAL_NE_RESIZE);
660  case CURSOR_NW_RESIZE:
661  return new CSSPrimitiveValueImpl(CSS_VAL_NW_RESIZE);
662  case CURSOR_S_RESIZE:
663  return new CSSPrimitiveValueImpl(CSS_VAL_S_RESIZE);
664  case CURSOR_SE_RESIZE:
665  return new CSSPrimitiveValueImpl(CSS_VAL_SE_RESIZE);
666  case CURSOR_SW_RESIZE:
667  return new CSSPrimitiveValueImpl(CSS_VAL_SW_RESIZE);
668  case CURSOR_W_RESIZE:
669  return new CSSPrimitiveValueImpl(CSS_VAL_W_RESIZE);
670  case CURSOR_EW_RESIZE:
671  return new CSSPrimitiveValueImpl(CSS_VAL_EW_RESIZE);
672  case CURSOR_NS_RESIZE:
673  return new CSSPrimitiveValueImpl(CSS_VAL_NS_RESIZE);
674  case CURSOR_NESW_RESIZE:
675  return new CSSPrimitiveValueImpl(CSS_VAL_NESW_RESIZE);
676  case CURSOR_NWSE_RESIZE:
677  return new CSSPrimitiveValueImpl(CSS_VAL_NWSE_RESIZE);
678  case CURSOR_COL_RESIZE:
679  return new CSSPrimitiveValueImpl(CSS_VAL_COL_RESIZE);
680  case CURSOR_ROW_RESIZE:
681  return new CSSPrimitiveValueImpl(CSS_VAL_ROW_RESIZE);
682  case CURSOR_ALL_SCROLL:
683  return new CSSPrimitiveValueImpl(CSS_VAL_ALL_SCROLL);
684  }
685  Q_ASSERT(0);
686  break;
687  case CSS_PROP_DIRECTION:
688  switch (style->direction()) {
689  case LTR:
690  return new CSSPrimitiveValueImpl(CSS_VAL_LTR);
691  case RTL:
692  return new CSSPrimitiveValueImpl(CSS_VAL_RTL);
693  }
694  Q_ASSERT(0);
695  break;
696  case CSS_PROP_DISPLAY:
697  switch (style->display()) {
698  case INLINE:
699  return new CSSPrimitiveValueImpl(CSS_VAL_INLINE);
700  case BLOCK:
701  return new CSSPrimitiveValueImpl(CSS_VAL_BLOCK);
702  case LIST_ITEM:
703  return new CSSPrimitiveValueImpl(CSS_VAL_LIST_ITEM);
704  case RUN_IN:
705  return new CSSPrimitiveValueImpl(CSS_VAL_RUN_IN);
706  case COMPACT:
707  return new CSSPrimitiveValueImpl(CSS_VAL_COMPACT);
708  case INLINE_BLOCK:
709  return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_BLOCK);
710  case TABLE:
711  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE);
712  case INLINE_TABLE:
713  return new CSSPrimitiveValueImpl(CSS_VAL_INLINE_TABLE);
714  case TABLE_ROW_GROUP:
715  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW_GROUP);
716  case TABLE_HEADER_GROUP:
717  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_HEADER_GROUP);
718  case TABLE_FOOTER_GROUP:
719  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_FOOTER_GROUP);
720  case TABLE_ROW:
721  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_ROW);
722  case TABLE_COLUMN_GROUP:
723  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN_GROUP);
724  case TABLE_COLUMN:
725  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_COLUMN);
726  case TABLE_CELL:
727  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CELL);
728  case TABLE_CAPTION:
729  return new CSSPrimitiveValueImpl(CSS_VAL_TABLE_CAPTION);
730  case NONE:
731  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
732  }
733  Q_ASSERT(0);
734  break;
735  case CSS_PROP_EMPTY_CELLS:
736  switch (style->emptyCells()) {
737  case SHOW:
738  return new CSSPrimitiveValueImpl(CSS_VAL_SHOW);
739  case HIDE:
740  return new CSSPrimitiveValueImpl(CSS_VAL_HIDE);
741  }
742  Q_ASSERT(0);
743  break;
744  case CSS_PROP_FLOAT: {
745  switch (style->floating()) {
746  case FNONE:
747  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
748  case FLEFT:
749  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
750  case FRIGHT:
751  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
752  case FLEFT_ALIGN:
753  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_LEFT);
754  case FRIGHT_ALIGN:
755  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_RIGHT);
756  }
757  Q_ASSERT(0);
758  break;
759  }
760  case CSS_PROP_FONT_FAMILY: {
761  FontDef def = style->htmlFont().getFontDef();
762  return new CSSPrimitiveValueImpl(DOMString(def.family), CSSPrimitiveValue::CSS_STRING);
763  }
764  case CSS_PROP_FONT_SIZE: {
765  FontDef def = style->htmlFont().getFontDef();
766  return new CSSPrimitiveValueImpl(def.size, CSSPrimitiveValue::CSS_PX);
767  }
768  case CSS_PROP_FONT_STYLE: {
769  // FIXME: handle oblique
770  FontDef def = style->htmlFont().getFontDef();
771  if (def.italic) {
772  return new CSSPrimitiveValueImpl(CSS_VAL_ITALIC);
773  } else {
774  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
775  }
776  }
777  case CSS_PROP_FONT_VARIANT: {
778  FontDef def = style->htmlFont().getFontDef();
779  if (def.smallCaps) {
780  return new CSSPrimitiveValueImpl(CSS_VAL_SMALL_CAPS);
781  } else {
782  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
783  }
784  }
785  case CSS_PROP_FONT_WEIGHT: {
786  // FIXME: this does not reflect the full range of weights
787  // that can be expressed with CSS
788  FontDef def = style->htmlFont().getFontDef();
789  switch (def.weight) {
790  case QFont::Light:
791  return new CSSPrimitiveValueImpl(CSS_VAL_300);
792  case QFont::Normal:
793  //return new CSSPrimitiveValueImpl(CSS_VAL_400);
794  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
795  case QFont::DemiBold:
796  return new CSSPrimitiveValueImpl(CSS_VAL_600);
797  case QFont::Bold:
798  //return new CSSPrimitiveValueImpl(CSS_VAL_700);
799  return new CSSPrimitiveValueImpl(CSS_VAL_BOLD);
800  case QFont::Black:
801  return new CSSPrimitiveValueImpl(CSS_VAL_900);
802  default:
803  // Should not happen
804  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
805  }
806  }
807  case CSS_PROP_HEIGHT:
808  if (renderer) {
809  return new CSSPrimitiveValueImpl(renderer->contentHeight(), CSSPrimitiveValue::CSS_PX);
810  }
811  return valueForLength2(style->height());
812  case CSS_PROP_LEFT:
813  RETURN_NULL_ON_NULL(renderer);
814  return getPositionOffsetValue(renderer, CSS_PROP_LEFT);
815  case CSS_PROP_LETTER_SPACING:
816  if (style->letterSpacing() == 0) {
817  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
818  }
819  return new CSSPrimitiveValueImpl(style->letterSpacing(), CSSPrimitiveValue::CSS_PX);
820  case CSS_PROP_LINE_HEIGHT: {
821  // Note: internally a specified <number> value gets encoded as a percentage,
822  // so the isPercent() case corresponds to the <number> case;
823  // values < 0 are used to mark "normal"; and specified %%
824  // get computed down to px by the time they get to RenderStyle
825  // already
826  Length length(style->lineHeight());
827  if (length.isNegative()) {
828  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
829  }
830  if (length.isPercent()) {
831  //XXX: merge from webcore the computedStyle/specifiedStyle distinction in rendering/font.h
832  float computedSize = style->htmlFont().getFontDef().size;
833  return new CSSPrimitiveValueImpl((int)(length.percent() * computedSize) / 100, CSSPrimitiveValue::CSS_PX);
834  } else {
835  return new CSSPrimitiveValueImpl(length.value(), CSSPrimitiveValue::CSS_PX);
836  }
837  }
838  case CSS_PROP_LIST_STYLE_IMAGE:
839  if (style->listStyleImage()) {
840  return new CSSPrimitiveValueImpl(style->listStyleImage()->url(), CSSPrimitiveValue::CSS_URI);
841  }
842  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
843  case CSS_PROP_LIST_STYLE_POSITION:
844  switch (style->listStylePosition()) {
845  case OUTSIDE:
846  return new CSSPrimitiveValueImpl(CSS_VAL_OUTSIDE);
847  case INSIDE:
848  return new CSSPrimitiveValueImpl(CSS_VAL_INSIDE);
849  }
850  Q_ASSERT(0);
851  break;
852  case CSS_PROP_LIST_STYLE_TYPE:
853  return new CSSPrimitiveValueImpl(stringForListStyleType(style->listStyleType()), CSSPrimitiveValue::CSS_STRING);
854  case CSS_PROP_MARGIN_TOP:
855  if (renderer) {
856  return new CSSPrimitiveValueImpl(renderer->marginTop(), CSSPrimitiveValue::CSS_PX);
857  }
858  return valueForLength2(style->marginTop());
859  case CSS_PROP_MARGIN_RIGHT:
860  if (renderer) {
861  return new CSSPrimitiveValueImpl(renderer->marginRight(), CSSPrimitiveValue::CSS_PX);
862  }
863  return valueForLength2(style->marginRight());
864  case CSS_PROP_MARGIN_BOTTOM:
865  if (renderer) {
866  return new CSSPrimitiveValueImpl(renderer->marginBottom(), CSSPrimitiveValue::CSS_PX);
867  }
868  return valueForLength2(style->marginBottom());
869  case CSS_PROP_MARGIN_LEFT:
870  if (renderer) {
871  return new CSSPrimitiveValueImpl(renderer->marginLeft(), CSSPrimitiveValue::CSS_PX);
872  }
873  return valueForLength2(style->marginLeft());
874  case CSS_PROP__KHTML_MARQUEE:
875  // FIXME: unimplemented
876  break;
877  case CSS_PROP__KHTML_MARQUEE_DIRECTION:
878  switch (style->marqueeDirection()) {
879  case MFORWARD:
880  return new CSSPrimitiveValueImpl(CSS_VAL_FORWARDS);
881  case MBACKWARD:
882  return new CSSPrimitiveValueImpl(CSS_VAL_BACKWARDS);
883  case MAUTO:
884  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
885  case MUP:
886  return new CSSPrimitiveValueImpl(CSS_VAL_UP);
887  case MDOWN:
888  return new CSSPrimitiveValueImpl(CSS_VAL_DOWN);
889  case MLEFT:
890  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
891  case MRIGHT:
892  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
893  }
894  Q_ASSERT(0);
895  return nullptr;
896  case CSS_PROP__KHTML_MARQUEE_INCREMENT:
897  RETURN_NULL_ON_NULL(renderer);
898  return valueForLength(style->marqueeIncrement(), renderer->contentWidth());
899  case CSS_PROP__KHTML_MARQUEE_REPETITION:
900  if (style->marqueeLoopCount() < 0) {
901  return new CSSPrimitiveValueImpl(CSS_VAL_INFINITE);
902  }
903  return new CSSPrimitiveValueImpl(style->marqueeLoopCount(), CSSPrimitiveValue::CSS_NUMBER);
904  case CSS_PROP__KHTML_MARQUEE_SPEED:
905  // FIXME: unimplemented
906  break;
907  case CSS_PROP__KHTML_MARQUEE_STYLE:
908  switch (style->marqueeBehavior()) {
909  case MNONE:
910  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
911  case MSCROLL:
912  return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
913  case MSLIDE:
914  return new CSSPrimitiveValueImpl(CSS_VAL_SLIDE);
915  case MALTERNATE:
916  return new CSSPrimitiveValueImpl(CSS_VAL_ALTERNATE);
917  case MUNFURL:
918  return new CSSPrimitiveValueImpl(CSS_VAL_UNFURL);
919  }
920  Q_ASSERT(0);
921  return nullptr;
922  case CSS_PROP_MAX_HEIGHT:
923  RETURN_NULL_ON_NULL(renderer);
924  return new CSSPrimitiveValueImpl(renderer->availableHeight(),
925  CSSPrimitiveValue::CSS_PX);
926  break;
927  case CSS_PROP_MAX_WIDTH:
928  RETURN_NULL_ON_NULL(renderer);
929  return new CSSPrimitiveValueImpl(renderer->maxWidth(),
930  CSSPrimitiveValue::CSS_PX);
931  break;
932  case CSS_PROP_MIN_HEIGHT:
933  RETURN_NULL_ON_NULL(renderer);
934  return new CSSPrimitiveValueImpl(renderer->contentHeight(),
935  CSSPrimitiveValue::CSS_PX);
936  break;
937  case CSS_PROP_MIN_WIDTH:
938  RETURN_NULL_ON_NULL(renderer);
939  return new CSSPrimitiveValueImpl(renderer->minWidth(),
940  CSSPrimitiveValue::CSS_PX);
941  break;
942  case CSS_PROP_OPACITY:
943  return new CSSPrimitiveValueImpl(style->opacity(), CSSPrimitiveValue::CSS_NUMBER);
944  case CSS_PROP_ORPHANS:
945  return new CSSPrimitiveValueImpl(style->orphans(), CSSPrimitiveValue::CSS_NUMBER);
946  case CSS_PROP_OUTLINE_COLOR:
947  break;
948  case CSS_PROP_OUTLINE_OFFSET:
949  break;
950  case CSS_PROP_OUTLINE_STYLE:
951  if (style->outlineStyleIsAuto()) {
952  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
953  }
954  return valueForBorderStyle(style->outlineStyle());
955  case CSS_PROP_OUTLINE_WIDTH:
956  break;
957  case CSS_PROP_OVERFLOW:
958  case CSS_PROP_OVERFLOW_X:
959  case CSS_PROP_OVERFLOW_Y: {
960  EOverflow overflow;
961  switch (propertyID) {
962  case CSS_PROP_OVERFLOW_X:
963  overflow = style->overflowX();
964  break;
965  case CSS_PROP_OVERFLOW_Y:
966  overflow = style->overflowY();
967  break;
968  default:
969  overflow = qMax(style->overflowX(), style->overflowY());
970  }
971  switch (overflow) {
972  case OVISIBLE:
973  return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
974  case OHIDDEN:
975  return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
976  case OSCROLL:
977  return new CSSPrimitiveValueImpl(CSS_VAL_SCROLL);
978  case OAUTO:
979  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
980  case OMARQUEE:
981  return new CSSPrimitiveValueImpl(CSS_VAL_MARQUEE);
982  }
983  Q_ASSERT(0);
984  return nullptr;
985  }
986  case CSS_PROP_PADDING_TOP:
987  if (renderer) {
988  return new CSSPrimitiveValueImpl(renderer->paddingTop(), CSSPrimitiveValue::CSS_PX);
989  }
990  return valueForLength2(style->paddingTop());
991  case CSS_PROP_PADDING_RIGHT:
992  if (renderer) {
993  return new CSSPrimitiveValueImpl(renderer->paddingRight(), CSSPrimitiveValue::CSS_PX);
994  }
995  return valueForLength2(style->paddingRight());
996  case CSS_PROP_PADDING_BOTTOM:
997  if (renderer) {
998  return new CSSPrimitiveValueImpl(renderer->paddingBottom(), CSSPrimitiveValue::CSS_PX);
999  }
1000  return valueForLength2(style->paddingBottom());
1001  case CSS_PROP_PADDING_LEFT:
1002  if (renderer) {
1003  return new CSSPrimitiveValueImpl(renderer->paddingLeft(), CSSPrimitiveValue::CSS_PX);
1004  }
1005  return valueForLength2(style->paddingLeft());
1006  case CSS_PROP_PAGE_BREAK_AFTER:
1007  switch (style->pageBreakAfter()) {
1008  case PBAUTO:
1009  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1010  case PBALWAYS:
1011  return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
1012  case PBAVOID:
1013  return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
1014  case PBLEFT:
1015  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
1016  case PBRIGHT:
1017  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
1018  }
1019  Q_ASSERT(0);
1020  break;
1021  case CSS_PROP_PAGE_BREAK_BEFORE:
1022  switch (style->pageBreakBefore()) {
1023  case PBAUTO:
1024  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1025  case PBALWAYS:
1026  return new CSSPrimitiveValueImpl(CSS_VAL_ALWAYS);
1027  case PBAVOID:
1028  return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
1029  case PBLEFT:
1030  return new CSSPrimitiveValueImpl(CSS_VAL_LEFT);
1031  case PBRIGHT:
1032  return new CSSPrimitiveValueImpl(CSS_VAL_RIGHT);
1033  }
1034  Q_ASSERT(0);
1035  break;
1036  case CSS_PROP_PAGE_BREAK_INSIDE:
1037  if (style->pageBreakInside()) {
1038  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1039  } else {
1040  return new CSSPrimitiveValueImpl(CSS_VAL_AVOID);
1041  }
1042  Q_ASSERT(0);
1043  break;
1044  case CSS_PROP_POSITION:
1045  switch (style->position()) {
1046  case PSTATIC:
1047  return new CSSPrimitiveValueImpl(CSS_VAL_STATIC);
1048  case PRELATIVE:
1049  return new CSSPrimitiveValueImpl(CSS_VAL_RELATIVE);
1050  case PABSOLUTE:
1051  return new CSSPrimitiveValueImpl(CSS_VAL_ABSOLUTE);
1052  case PFIXED:
1053  return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
1054  }
1055  Q_ASSERT(0);
1056  break;
1057  case CSS_PROP_QUOTES:
1058  break;
1059  case CSS_PROP_RIGHT:
1060  RETURN_NULL_ON_NULL(renderer);
1061  return getPositionOffsetValue(renderer, CSS_PROP_RIGHT);
1062  case CSS_PROP_SIZE:
1063  break;
1064  case CSS_PROP_TABLE_LAYOUT:
1065  switch (style->tableLayout()) {
1066  case TAUTO:
1067  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1068  case TFIXED:
1069  return new CSSPrimitiveValueImpl(CSS_VAL_FIXED);
1070  }
1071  Q_ASSERT(0);
1072  break;
1073  case CSS_PROP_TEXT_ALIGN:
1074  return valueForTextAlign(style->textAlign());
1075  case CSS_PROP_TEXT_DECORATION: {
1076  QString string;
1077  if (style->textDecoration() & khtml::UNDERLINE) {
1078  string += "underline";
1079  }
1080  if (style->textDecoration() & khtml::OVERLINE) {
1081  if (string.length() > 0) {
1082  string += " ";
1083  }
1084  string += "overline";
1085  }
1086  if (style->textDecoration() & khtml::LINE_THROUGH) {
1087  if (string.length() > 0) {
1088  string += " ";
1089  }
1090  string += "line-through";
1091  }
1092  if (style->textDecoration() & khtml::BLINK) {
1093  if (string.length() > 0) {
1094  string += " ";
1095  }
1096  string += "blink";
1097  }
1098  if (string.length() == 0) {
1099  string = "none";
1100  }
1101  return new CSSPrimitiveValueImpl(DOMString(string), CSSPrimitiveValue::CSS_STRING);
1102  }
1103  case CSS_PROP_TEXT_INDENT:
1104  RETURN_NULL_ON_NULL(renderer);
1105  return valueForLength(style->textIndent(), renderer->contentWidth());
1106  case CSS_PROP_TEXT_SHADOW:
1107  return valueForShadow(style->textShadow());
1108  case CSS_PROP_TEXT_TRANSFORM:
1109  switch (style->textTransform()) {
1110  case CAPITALIZE:
1111  return new CSSPrimitiveValueImpl(CSS_VAL_CAPITALIZE);
1112  case UPPERCASE:
1113  return new CSSPrimitiveValueImpl(CSS_VAL_UPPERCASE);
1114  case LOWERCASE:
1115  return new CSSPrimitiveValueImpl(CSS_VAL_LOWERCASE);
1116  case TTNONE:
1117  return new CSSPrimitiveValueImpl(CSS_VAL_NONE);
1118  }
1119  Q_ASSERT(0);
1120  break;
1121  case CSS_PROP_TOP:
1122  RETURN_NULL_ON_NULL(renderer);
1123  return getPositionOffsetValue(renderer, CSS_PROP_TOP);
1124  case CSS_PROP_UNICODE_BIDI:
1125  switch (style->unicodeBidi()) {
1126  case UBNormal:
1127  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1128  case Embed:
1129  return new CSSPrimitiveValueImpl(CSS_VAL_EMBED);
1130  case Override:
1131  return new CSSPrimitiveValueImpl(CSS_VAL_BIDI_OVERRIDE);
1132  }
1133  Q_ASSERT(0);
1134  break;
1135  case CSS_PROP_VERTICAL_ALIGN: {
1136  switch (style->verticalAlign()) {
1137  case BASELINE:
1138  return new CSSPrimitiveValueImpl(CSS_VAL_BASELINE);
1139  case MIDDLE:
1140  return new CSSPrimitiveValueImpl(CSS_VAL_MIDDLE);
1141  case SUB:
1142  return new CSSPrimitiveValueImpl(CSS_VAL_SUB);
1143  case SUPER:
1144  return new CSSPrimitiveValueImpl(CSS_VAL_SUPER);
1145  case TEXT_TOP:
1146  return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_TOP);
1147  case TEXT_BOTTOM:
1148  return new CSSPrimitiveValueImpl(CSS_VAL_TEXT_BOTTOM);
1149  case TOP:
1150  return new CSSPrimitiveValueImpl(CSS_VAL_TOP);
1151  case BOTTOM:
1152  return new CSSPrimitiveValueImpl(CSS_VAL_BOTTOM);
1153  case BASELINE_MIDDLE:
1154  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_BASELINE_MIDDLE);
1155  case LENGTH:
1156  RETURN_NULL_ON_NULL(renderer);
1157  return valueForLength(style->verticalAlignLength(), renderer->contentWidth());
1158  }
1159  Q_ASSERT(0);
1160  break;
1161  }
1162  case CSS_PROP_VISIBILITY:
1163  switch (style->visibility()) {
1164  case khtml::VISIBLE:
1165  return new CSSPrimitiveValueImpl(CSS_VAL_VISIBLE);
1166  case khtml::HIDDEN:
1167  return new CSSPrimitiveValueImpl(CSS_VAL_HIDDEN);
1168  case khtml::COLLAPSE:
1169  return new CSSPrimitiveValueImpl(CSS_VAL_COLLAPSE);
1170  }
1171  Q_ASSERT(0);
1172  break;
1173  case CSS_PROP_WHITE_SPACE: {
1174  switch (style->whiteSpace()) {
1175  case NORMAL:
1176  return new CSSPrimitiveValueImpl(CSS_VAL_NORMAL);
1177  case PRE:
1178  return new CSSPrimitiveValueImpl(CSS_VAL_PRE);
1179  case PRE_WRAP:
1180  return new CSSPrimitiveValueImpl(CSS_VAL_PRE_WRAP);
1181  case PRE_LINE:
1182  return new CSSPrimitiveValueImpl(CSS_VAL_PRE_LINE);
1183  case NOWRAP:
1184  return new CSSPrimitiveValueImpl(CSS_VAL_NOWRAP);
1185  case KHTML_NOWRAP:
1186  return new CSSPrimitiveValueImpl(CSS_VAL__KHTML_NOWRAP);
1187  }
1188  Q_ASSERT(0);
1189  break;
1190  }
1191  case CSS_PROP_WIDOWS:
1192  return new CSSPrimitiveValueImpl(style->widows(), CSSPrimitiveValue::CSS_NUMBER);
1193  case CSS_PROP_WIDTH:
1194  if (renderer)
1195  return new CSSPrimitiveValueImpl(renderer->contentWidth(),
1196  CSSPrimitiveValue::CSS_PX);
1197  return valueForLength2(style->width());
1198  case CSS_PROP_WORD_SPACING:
1199  return new CSSPrimitiveValueImpl(style->wordSpacing(), CSSPrimitiveValue::CSS_PX);
1200  case CSS_PROP_Z_INDEX:
1201  if (style->hasAutoZIndex()) {
1202  return new CSSPrimitiveValueImpl(CSS_VAL_AUTO);
1203  }
1204  return new CSSPrimitiveValueImpl(style->zIndex(), CSSPrimitiveValue::CSS_NUMBER);
1205  case CSS_PROP_BACKGROUND:
1206  break;
1207  case CSS_PROP_BORDER:
1208  break;
1209  case CSS_PROP_BORDER_COLOR:
1210  break;
1211  case CSS_PROP_BORDER_STYLE:
1212  break;
1213  case CSS_PROP_BORDER_TOP:
1214  RETURN_NULL_ON_NULL(renderer);
1215  return new CSSPrimitiveValueImpl(renderer->borderTop(),
1216  CSSPrimitiveValue::CSS_PX);
1217  break;
1218  case CSS_PROP_BORDER_RIGHT:
1219  RETURN_NULL_ON_NULL(renderer);
1220  return new CSSPrimitiveValueImpl(renderer->borderRight(),
1221  CSSPrimitiveValue::CSS_PX);
1222  break;
1223  case CSS_PROP_BORDER_BOTTOM:
1224  RETURN_NULL_ON_NULL(renderer);
1225  return new CSSPrimitiveValueImpl(renderer->borderBottom(),
1226  CSSPrimitiveValue::CSS_PX);
1227  break;
1228  case CSS_PROP_BORDER_LEFT:
1229  RETURN_NULL_ON_NULL(renderer);
1230  return new CSSPrimitiveValueImpl(renderer->borderLeft(),
1231  CSSPrimitiveValue::CSS_PX);
1232  break;
1233  case CSS_PROP_BORDER_WIDTH:
1234  break;
1235  case CSS_PROP_FONT:
1236  break;
1237  case CSS_PROP_LIST_STYLE:
1238  break;
1239  case CSS_PROP_MARGIN:
1240  break;
1241  case CSS_PROP_OUTLINE:
1242  break;
1243  case CSS_PROP_PADDING:
1244  break;
1245  case CSS_PROP_SCROLLBAR_BASE_COLOR:
1246  break;
1247  case CSS_PROP_SCROLLBAR_FACE_COLOR:
1248  break;
1249  case CSS_PROP_SCROLLBAR_SHADOW_COLOR:
1250  break;
1251  case CSS_PROP_SCROLLBAR_HIGHLIGHT_COLOR:
1252  break;
1253  case CSS_PROP_SCROLLBAR_3DLIGHT_COLOR:
1254  break;
1255  case CSS_PROP_SCROLLBAR_DARKSHADOW_COLOR:
1256  break;
1257  case CSS_PROP_SCROLLBAR_TRACK_COLOR:
1258  break;
1259  case CSS_PROP_SCROLLBAR_ARROW_COLOR:
1260  break;
1261  case CSS_PROP__KHTML_FLOW_MODE:
1262  break;
1263  case CSS_PROP__KHTML_USER_INPUT:
1264  break;
1265  case CSS_PROP_TEXT_OVERFLOW:
1266  if (style->textOverflow()) {
1267  return new CSSPrimitiveValueImpl(CSS_VAL_ELLIPSIS);
1268  } else {
1269  return new CSSPrimitiveValueImpl(CSS_VAL_CLIP);
1270  }
1271  break;
1272  default:
1273  qCWarning(KHTML_LOG) << "Unhandled property:" << getPropertyName(propertyID);
1274  //Q_ASSERT( 0 );
1275  break;
1276  }
1277  return nullptr;
1278 }
1279 
1280 #undef RETURN_NULL_ON_NULL
1281 
1282 DOMString RenderStyleDeclarationImpl::getPropertyValue(int propertyID) const
1283 {
1284  CSSValueImpl *value = getPropertyCSSValue(propertyID);
1285  if (value) {
1286  DOMString val = value->cssText();
1287  delete value;
1288  return val;
1289  }
1290  return "";
1291 }
1292 
1293 bool RenderStyleDeclarationImpl::getPropertyPriority(int) const
1294 {
1295  // All computed styles have a priority of false (not "important").
1296  return false;
1297 }
1298 
1299 void RenderStyleDeclarationImpl::removeProperty(int, DOM::DOMString *)
1300 {
1301  // ### emit error since we're read-only
1302 }
1303 
1304 bool RenderStyleDeclarationImpl::removePropertiesInSet(const int *, unsigned)
1305 {
1306  // ### emit error since we're read-only
1307  return false;
1308 }
1309 
1310 bool RenderStyleDeclarationImpl::setProperty(int, const DOM::DOMString &, bool, int &ec)
1311 {
1312  ec = DOMException::NO_MODIFICATION_ALLOWED_ERR;
1313  return false;
1314 }
1315 
1316 bool RenderStyleDeclarationImpl::setProperty(int, const DOM::DOMString &, bool)
1317 {
1318  // ### emit error since we're read-only
1319  return false;
1320 }
1321 
1322 void RenderStyleDeclarationImpl::setProperty(int, int, bool)
1323 {
1324  // ### emit error since we're read-only
1325 }
1326 
1327 void RenderStyleDeclarationImpl::setLengthProperty(int, const DOM::DOMString &, bool,
1328  bool)
1329 {
1330  // ### emit error since we're read-only
1331 }
1332 
1333 void RenderStyleDeclarationImpl::setProperty(const DOMString &)
1334 {
1335  // ### emit error since we're read-only
1336 }
1337 
1338 unsigned long RenderStyleDeclarationImpl::length() const
1339 {
1340  return numComputedProperties;
1341 }
1342 
1343 DOM::DOMString RenderStyleDeclarationImpl::item(unsigned long i) const
1344 {
1345  if (i >= numComputedProperties) {
1346  return DOMString();
1347  }
1348 
1349  return getPropertyName(computedProperties[i]);
1350 }
1351 
1352 CSSProperty RenderStyleDeclarationImpl::property(int id) const
1353 {
1354  CSSProperty prop;
1355  prop.m_id = id;
1356  prop.m_important = false;
1357 
1358  CSSValueImpl *v = getPropertyCSSValue(id);
1359  if (!v) {
1360  v = new CSSPrimitiveValueImpl;
1361  }
1362  prop.setValue(v);
1363  return prop;
1364 }
1365 
This file is part of the HTML rendering engine for KDE.
QVector< V > values(const QMultiHash< K, V > &c)
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
This library provides a full-featured HTML parser and widget.
Base Class for all rendering tree objects.
QRgb rgba() const const
bool isValid() const const
KIOFILEWIDGETS_EXPORT QStringList list(const QString &fileClass)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 16 2021 22:47:51 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.