KHtml

css_value.cpp
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright 1999 Lars Knoll ([email protected])
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "dom/css_rule.h"
24 #include "dom/dom_exception.h"
25 
26 #include "css/css_renderstyledeclarationimpl.h"
27 #include "css/css_valueimpl.h"
28 
29 namespace DOM
30 {
31 
32 CSSStyleDeclaration::CSSStyleDeclaration()
33 {
34  impl = nullptr;
35 }
36 
37 CSSStyleDeclaration::CSSStyleDeclaration(const CSSStyleDeclaration &other)
38 {
39  impl = other.impl;
40  if (impl) {
41  impl->ref();
42  }
43 }
44 
45 CSSStyleDeclaration::CSSStyleDeclaration(CSSStyleDeclarationImpl *i)
46 {
47  impl = i;
48  if (impl) {
49  impl->ref();
50  }
51 }
52 
53 CSSStyleDeclaration &CSSStyleDeclaration::operator = (const CSSStyleDeclaration &other)
54 {
55  if (impl != other.impl) {
56  if (impl) {
57  impl->deref();
58  }
59  impl = other.impl;
60  if (impl) {
61  impl->ref();
62  }
63  }
64  return *this;
65 }
66 
67 CSSStyleDeclaration::~CSSStyleDeclaration()
68 {
69  if (impl) {
70  impl->deref();
71  }
72 }
73 
75 {
76  if (!impl) {
77  return DOMString();
78  }
79  return static_cast<CSSStyleDeclarationImpl *>(impl)->cssText();
80 }
81 
83 {
84  if (!impl) {
85  return;
86  }
87  impl->setCssText(value);
88 }
89 
91 {
92  if (!impl) {
93  return DOMString();
94  }
95  return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyValue(propertyName);
96 }
97 
99 {
100  if (!impl) {
101  return nullptr;
102  }
103  return static_cast<CSSStyleDeclarationImpl *>(impl)->getPropertyCSSValue(propertyName);
104 }
105 
107 {
108  if (!impl) {
109  return DOMString();
110  }
111  return static_cast<CSSStyleDeclarationImpl *>(impl)->removeProperty(propertyName);
112 }
113 
115 {
116  if (!impl) {
117  return DOMString();
118  }
119  return impl->getPropertyPriority(propertyName);
120 }
121 
122 void CSSStyleDeclaration::setProperty(const DOMString &propName, const DOMString &value, const DOMString &priority)
123 {
124  if (!impl) {
125  return;
126  }
127  if (value.isEmpty()) {
128  static_cast<CSSStyleDeclarationImpl *>(impl)->removeProperty(propName);
129  return;
130  }
131  static_cast<CSSStyleDeclarationImpl *>(impl)->setProperty(propName, value, priority);
132 }
133 
134 unsigned long CSSStyleDeclaration::length() const
135 {
136  if (!impl) {
137  return 0;
138  }
139  return static_cast<CSSStyleDeclarationImpl *>(impl)->length();
140 }
141 
142 DOMString CSSStyleDeclaration::item(unsigned long index) const
143 {
144  if (!impl) {
145  return DOMString();
146  }
147  return static_cast<CSSStyleDeclarationImpl *>(impl)->item(index);
148 }
150 {
151  if (!impl) {
152  return nullptr;
153  }
154  return static_cast<CSSStyleDeclarationImpl *>(impl)->parentRule();
155 }
156 
157 CSSStyleDeclarationImpl *CSSStyleDeclaration::handle() const
158 {
159  return impl;
160 }
161 
162 bool CSSStyleDeclaration::isNull() const
163 {
164  return (impl == nullptr);
165 }
166 
167 // ----------------------------------------------------------
168 
169 CSSValue::CSSValue()
170 {
171  impl = nullptr;
172 }
173 
174 CSSValue::CSSValue(const CSSValue &other)
175 {
176  impl = other.impl;
177  if (impl) {
178  impl->ref();
179  }
180 }
181 
182 CSSValue::CSSValue(CSSValueImpl *i)
183 {
184  impl = i;
185  if (impl) {
186  impl->ref();
187  }
188 }
189 
190 CSSValue &CSSValue::operator = (const CSSValue &other)
191 {
192  if (impl != other.impl) {
193  if (impl) {
194  impl->deref();
195  }
196  impl = other.impl;
197  if (impl) {
198  impl->ref();
199  }
200  }
201  return *this;
202 }
203 
204 CSSValue::~CSSValue()
205 {
206  if (impl) {
207  impl->deref();
208  }
209 }
210 
212 {
213  if (!impl) {
214  return DOMString();
215  }
216  return ((CSSValueImpl *)impl)->cssText();
217 }
218 
219 void CSSValue::setCssText(const DOMString &value)
220 {
221  if (!impl) {
222  return;
223  }
224  ((CSSValueImpl *)impl)->setCssText(value);
225 }
226 
227 unsigned short CSSValue::cssValueType() const
228 {
229  if (!impl) {
230  return 0;
231  }
232  return ((CSSValueImpl *)impl)->cssValueType();
233 }
234 
236 {
237  if (!impl) {
238  return false;
239  }
240  return ((CSSValueImpl *)impl)->isValueList();
241 }
242 
243 bool CSSValue::isCSSPrimitiveValue() const
244 {
245  if (!impl) {
246  return false;
247  }
248  return ((CSSValueImpl *)impl)->isPrimitiveValue();
249 }
250 
251 CSSValueImpl *CSSValue::handle() const
252 {
253  return impl;
254 }
255 
256 bool CSSValue::isNull() const
257 {
258  return (impl == nullptr);
259 }
260 
261 // ----------------------------------------------------------
262 
263 CSSValueList::CSSValueList() : CSSValue()
264 {
265 }
266 
267 CSSValueList::CSSValueList(const CSSValueList &other) : CSSValue(other)
268 {
269 }
270 
271 CSSValueList::CSSValueList(const CSSValue &other)
272 {
273  impl = nullptr;
274  operator=(other);
275 }
276 
277 CSSValueList::CSSValueList(CSSValueListImpl *impl) : CSSValue(impl)
278 {
279 }
280 
281 CSSValueList &CSSValueList::operator = (const CSSValueList &other)
282 {
283  if (impl != other.impl) {
284  if (impl) {
285  impl->deref();
286  }
287  impl = other.handle();
288  if (impl) {
289  impl->ref();
290  }
291  }
292  return *this;
293 }
294 
295 CSSValueList &CSSValueList::operator = (const CSSValue &other)
296 {
297  CSSValueImpl *ohandle = other.handle();
298  if (impl != ohandle) {
299  if (impl) {
300  impl->deref();
301  }
302  if (!other.isNull() && !other.isCSSValueList()) {
303  impl = nullptr;
304  } else {
305  impl = ohandle;
306  if (impl) {
307  impl->ref();
308  }
309  }
310  }
311  return *this;
312 }
313 
314 CSSValueList::~CSSValueList()
315 {
316 }
317 
318 unsigned long CSSValueList::length() const
319 {
320  if (!impl) {
321  return 0;
322  }
323  return ((CSSValueListImpl *)impl)->length();
324 }
325 
326 CSSValue CSSValueList::item(unsigned long index)
327 {
328  if (!impl) {
329  return nullptr;
330  }
331  return ((CSSValueListImpl *)impl)->item(index);
332 }
333 
334 // ----------------------------------------------------------
335 
336 CSSPrimitiveValue::CSSPrimitiveValue() : CSSValue()
337 {
338 }
339 
340 CSSPrimitiveValue::CSSPrimitiveValue(const CSSPrimitiveValue &other) : CSSValue(other)
341 {
342 }
343 
344 CSSPrimitiveValue::CSSPrimitiveValue(const CSSValue &other) : CSSValue(other)
345 {
346  impl = nullptr;
347  operator=(other);
348 }
349 
350 CSSPrimitiveValue::CSSPrimitiveValue(CSSPrimitiveValueImpl *impl) : CSSValue(impl)
351 {
352 }
353 
354 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSPrimitiveValue &other)
355 {
356  if (impl != other.impl) {
357  if (impl) {
358  impl->deref();
359  }
360  impl = other.handle();
361  if (impl) {
362  impl->ref();
363  }
364  }
365  return *this;
366 }
367 
368 CSSPrimitiveValue &CSSPrimitiveValue::operator = (const CSSValue &other)
369 {
370  CSSValueImpl *ohandle = other.handle();
371  if (impl != ohandle) {
372  if (impl) {
373  impl->deref();
374  }
375  if (!other.isNull() && !other.isCSSPrimitiveValue()) {
376  impl = nullptr;
377  } else {
378  impl = ohandle;
379  if (impl) {
380  impl->ref();
381  }
382  }
383  }
384  return *this;
385 }
386 
387 CSSPrimitiveValue::~CSSPrimitiveValue()
388 {
389 }
390 
391 unsigned short CSSPrimitiveValue::primitiveType() const
392 {
393  if (!impl) {
394  return 0;
395  }
396  return ((CSSPrimitiveValueImpl *)impl)->primitiveType();
397 }
398 
399 void CSSPrimitiveValue::setFloatValue(unsigned short unitType, float floatValue)
400 {
401  if (!impl) {
402  return;
403  }
404  int exceptioncode = 0;
405  ((CSSPrimitiveValueImpl *)impl)->setFloatValue(unitType, floatValue, exceptioncode);
406  if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
407  throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
408  }
409  if (exceptioncode) {
410  throw DOMException(exceptioncode);
411  }
412 }
413 
414 float CSSPrimitiveValue::getFloatValue(unsigned short unitType) const
415 {
416  if (!impl) {
417  return 0;
418  }
419  // ### add unit conversion
420  if (primitiveType() != unitType) {
421  throw CSSException(CSSException::SYNTAX_ERR);
422  }
423  return ((CSSPrimitiveValueImpl *)impl)->floatValue(unitType);
424 }
425 
426 void CSSPrimitiveValue::setStringValue(unsigned short stringType, const DOMString &stringValue)
427 {
428  int exceptioncode = 0;
429  if (impl) {
430  ((CSSPrimitiveValueImpl *)impl)->setStringValue(stringType, stringValue, exceptioncode);
431  }
432  if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
433  throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
434  }
435  if (exceptioncode) {
436  throw DOMException(exceptioncode);
437  }
438 
439 }
440 
442 {
443  if (!impl) {
444  return DOMString();
445  }
446  return ((CSSPrimitiveValueImpl *)impl)->getStringValue();
447 }
448 
450 {
451  if (!impl) {
452  return Counter();
453  }
454  return ((CSSPrimitiveValueImpl *)impl)->getCounterValue();
455 }
456 
458 {
459  if (!impl) {
460  return Rect();
461  }
462  return ((CSSPrimitiveValueImpl *)impl)->getRectValue();
463 }
464 
466 {
467  // ###
468  return RGBColor();
469  //if(!impl) return RGBColor();
470  //return ((CSSPrimitiveValueImpl *)impl)->getRGBColorValue( );
471 }
472 
473 // -------------------------------------------------------------------
474 
475 Counter::Counter()
476 {
477 }
478 
479 Counter::Counter(const Counter &/*other*/)
480 {
481  impl = nullptr;
482 }
483 
484 Counter &Counter::operator = (const Counter &other)
485 {
486  if (impl != other.impl) {
487  if (impl) {
488  impl->deref();
489  }
490  impl = other.impl;
491  if (impl) {
492  impl->ref();
493  }
494  }
495  return *this;
496 }
497 
498 Counter::Counter(CounterImpl *i)
499 {
500  impl = i;
501  if (impl) {
502  impl->ref();
503  }
504 }
505 
506 Counter::~Counter()
507 {
508  if (impl) {
509  impl->deref();
510  }
511 }
512 
514 {
515  if (!impl) {
516  return DOMString();
517  }
518  return impl->identifier();
519 }
520 
522 {
523  if (!impl) {
524  return DOMString();
525  }
526  return khtml::stringForListStyleType((khtml::EListStyleType)impl->listStyle());
527 }
528 
530 {
531  if (!impl) {
532  return DOMString();
533  }
534  return impl->separator();
535 }
536 
537 CounterImpl *Counter::handle() const
538 {
539  return impl;
540 }
541 
542 bool Counter::isNull() const
543 {
544  return (impl == nullptr);
545 }
546 
547 // --------------------------------------------------------------------
548 
549 RGBColor::RGBColor()
550 {
551 }
552 
553 RGBColor::RGBColor(const RGBColor &other)
554 {
555  m_color = other.m_color;
556 }
557 
558 RGBColor::RGBColor(QRgb color)
559 {
560  m_color = color;
561 }
562 
563 RGBColor &RGBColor::operator = (const RGBColor &other)
564 {
565  m_color = other.m_color;
566  return *this;
567 }
568 
569 RGBColor::~RGBColor()
570 {
571 }
572 
574 {
575  return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qRed(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
576 }
577 
579 {
580  return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qGreen(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
581 }
582 
584 {
585  return new CSSPrimitiveValueImpl(float(qAlpha(m_color) ? qBlue(m_color) : 0), CSSPrimitiveValue::CSS_DIMENSION);
586 }
587 
588 // ---------------------------------------------------------------------
589 
590 Rect::Rect()
591 {
592  impl = nullptr;
593 }
594 
595 Rect::Rect(const Rect &other)
596 {
597  impl = other.impl;
598  if (impl) {
599  impl->ref();
600  }
601 }
602 
603 Rect::Rect(RectImpl *i)
604 {
605  impl = i;
606  if (impl) {
607  impl->ref();
608  }
609 }
610 
611 Rect &Rect::operator = (const Rect &other)
612 {
613  if (impl != other.impl) {
614  if (impl) {
615  impl->deref();
616  }
617  impl = other.impl;
618  if (impl) {
619  impl->ref();
620  }
621  }
622  return *this;
623 }
624 
625 Rect::~Rect()
626 {
627  if (impl) {
628  impl->deref();
629  }
630 }
631 
633 {
634  if (!impl) {
635  return nullptr;
636  }
637  return impl->top();
638 }
639 
641 {
642  if (!impl) {
643  return nullptr;
644  }
645  return impl->right();
646 }
647 
649 {
650  if (!impl) {
651  return nullptr;
652  }
653  return impl->bottom();
654 }
655 
657 {
658  if (!impl) {
659  return nullptr;
660  }
661  return impl->left();
662 }
663 
664 RectImpl *Rect::handle() const
665 {
666  return impl;
667 }
668 
669 bool Rect::isNull() const
670 {
671  return (impl == nullptr);
672 }
673 
674 } // namespace
675 
DOM::DOMString cssText() const
The parsable textual representation of the declaration block (including the surrounding curly braces)...
Definition: css_value.cpp:74
CSSPrimitiveValue red() const
This attribute is used for the red value of the RGB color.
Definition: css_value.cpp:573
RGBColor getRGBColorValue() const
This method is used to get the RGB color.
Definition: css_value.cpp:465
void setStringValue(unsigned short stringType, const DOM::DOMString &stringValue)
A method to set the string value with a specified unit.
Definition: css_value.cpp:426
unsigned long length() const
The number of properties that have been explicitly set in this declaration block. ...
Definition: css_value.cpp:134
RectImpl * handle() const
Definition: css_value.cpp:664
DOM::DOMString cssText() const
A string representation of the current value.
Definition: css_value.cpp:211
CSSPrimitiveValue blue() const
This attribute is used for the blue value of the RGB color.
Definition: css_value.cpp:583
CSSStyleDeclarationImpl * handle() const
Definition: css_value.cpp:157
DOM::DOMString separator() const
This attribute is used for the separator of nested counters.
Definition: css_value.cpp:529
void setCssText(const DOM::DOMString &)
see cssText SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable...
Definition: css_value.cpp:82
DOM::DOMString listStyle() const
This attribute is used for the style of the list.
Definition: css_value.cpp:521
DOM::DOMString item(unsigned long index) const
Used to retrieve the properties that have been explicitly set in this declaration block...
Definition: css_value.cpp:142
CSSPrimitiveValue left() const
This attribute is used for the left of the rect.
Definition: css_value.cpp:656
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
The CSSValueList interface provides the absraction of an ordered collection of CSS values...
Definition: css_value.h:311
DOM::DOMString getPropertyValue(const DOM::DOMString &propertyName) const
Used to retrieve the value of a CSS property if it has been explicitly set within this declaration bl...
Definition: css_value.cpp:90
Rect getRectValue() const
This method is used to get the Rect value.
Definition: css_value.cpp:457
float getFloatValue(unsigned short unitType) const
This method is used to get a float value in a specified unit.
Definition: css_value.cpp:414
CSSPrimitiveValue top() const
This attribute is used for the top of the rect.
Definition: css_value.cpp:632
CSSValue getPropertyCSSValue(const DOM::DOMString &propertyName) const
Used to retrieve the object representation of the value of a CSS property if it has been explicitly s...
Definition: css_value.cpp:98
void setCssText(const DOM::DOMString &)
see cssText SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable...
Definition: css_value.cpp:219
The CSSPrimitiveValue interface represents a single CSS value .
Definition: css_value.h:367
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
CSSPrimitiveValue right() const
This attribute is used for the right of the rect.
Definition: css_value.cpp:640
Counter getCounterValue() const
This method is used to get the Counter value.
Definition: css_value.cpp:449
DOM::DOMString removeProperty(const DOM::DOMString &propertyName)
Used to remove a CSS property if it has been explicitly set within this declaration block...
Definition: css_value.cpp:106
unsigned short cssValueType() const
A code defining the type of the value as defined above.
Definition: css_value.cpp:227
void setFloatValue(unsigned short unitType, float floatValue)
A method to set the float value with a specified unit.
Definition: css_value.cpp:399
DOM::DOMString getStringValue() const
This method is used to get the string value in a specified unit.
Definition: css_value.cpp:441
CSSValue item(unsigned long index)
Used to retrieve a CSS rule by ordinal index.
Definition: css_value.cpp:326
The Rect interface is used to represent any rect value.
Definition: css_value.h:639
DOM::DOMString identifier() const
This attribute is used for the identifier of the counter.
Definition: css_value.cpp:513
This library provides a full-featured HTML parser and widget.
void setProperty(const DOM::DOMString &propertyName, const DOM::DOMString &value, const DOM::DOMString &priority)
Used to set a property value and priority within this declaration block.
Definition: css_value.cpp:122
CounterImpl * handle() const
Definition: css_value.cpp:537
The CSSRule interface is the abstract base interface for any type of CSS statement ...
Definition: css_rule.h:53
unsigned long length() const
The number of CSSValue s in the list.
Definition: css_value.cpp:318
The RGBColor interface is used to represent any RGB color value.
Definition: css_value.h:582
This exception is raised when a specific CSS operation is impossible to perform.
bool isCSSValueList() const
Definition: css_value.cpp:235
The CSSValue interface represents a simple or a complexe value.
Definition: css_value.h:237
unsigned short primitiveType() const
The type of the value as defined by the constants specified above.
Definition: css_value.cpp:391
The Counter interface is used to represent any counter or counters function value.
Definition: css_value.h:696
DOM::DOMString getPropertyPriority(const DOM::DOMString &propertyName) const
Used to retrieve the priority of a CSS property (e.g.
Definition: css_value.cpp:114
CSSPrimitiveValue green() const
This attribute is used for the green value of the RGB color.
Definition: css_value.cpp:578
CSSRule parentRule() const
The CSS rule that contains this declaration block.
Definition: css_value.cpp:149
CSSPrimitiveValue bottom() const
This attribute is used for the bottom of the rect.
Definition: css_value.cpp:648
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Sep 19 2020 22:45:57 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.