KHtml

css_stylesheet.cpp
1 
24 #include "dom/dom_exception.h"
25 #include "dom/css_rule.h"
26 #include "dom/dom_doc.h"
27 
28 #include "xml/dom_docimpl.h"
29 
30 #include "html/html_headimpl.h"
31 
32 #include "css/css_stylesheetimpl.h"
33 
34 #include <stdio.h>
35 
36 using namespace DOM;
37 
38 StyleSheet::StyleSheet()
39 {
40  impl = nullptr;
41 }
42 
43 StyleSheet::StyleSheet(const StyleSheet &other)
44 {
45  impl = other.impl;
46  if (impl) {
47  impl->ref();
48  }
49 }
50 
51 StyleSheet::StyleSheet(StyleSheetImpl *i)
52 {
53  impl = i;
54  if (impl) {
55  impl->ref();
56  }
57 }
58 
59 StyleSheet &StyleSheet::operator = (const StyleSheet &other)
60 {
61  if (impl != other.impl) {
62  if (impl) {
63  impl->deref();
64  }
65  impl = other.impl;
66  if (impl) {
67  impl->ref();
68  }
69  }
70  return *this;
71 }
72 
73 StyleSheet::~StyleSheet()
74 {
75  if (impl) {
76  impl->deref();
77  }
78 }
79 
81 {
82  if (!impl) {
83  return DOMString();
84  }
85  return ((StyleSheetImpl *)impl)->type();
86 }
87 
89 {
90  if (!impl) {
91  return 0;
92  }
93  return ((StyleSheetImpl *)impl)->disabled();
94 }
95 
96 void StyleSheet::setDisabled(bool _disabled)
97 {
98  if (impl) {
99  ((StyleSheetImpl *)impl)->setDisabled(_disabled);
100  }
101 }
102 
104 {
105  if (!impl) {
106  return Node();
107  }
108  return ((StyleSheetImpl *)impl)->ownerNode();
109 }
110 
112 {
113  if (!impl) {
114  return nullptr;
115  }
116  return ((StyleSheetImpl *)impl)->parentStyleSheet();
117 }
118 
120 {
121  if (!impl) {
122  return DOMString();
123  }
124  return ((StyleSheetImpl *)impl)->href();
125 }
126 
128 {
129  if (!impl) {
130  return DOMString();
131  }
132  return ((StyleSheetImpl *)impl)->title();
133 }
134 
136 {
137  if (!impl) {
138  return nullptr;
139  }
140  return ((StyleSheetImpl *)impl)->media();
141 }
142 
143 bool StyleSheet::isCSSStyleSheet() const
144 {
145  if (!impl) {
146  return false;
147  }
148  return ((StyleSheetImpl *)impl)->isCSSStyleSheet();
149 }
150 
152 {
153  if (!impl) {
154  return QUrl();
155  }
156  return ((StyleSheetImpl *)impl)->baseURL();
157 }
158 
160 {
161  return codeAsString(code);
162 }
163 
164 bool CSSException::isCSSExceptionCode(int exceptioncode)
165 {
166  return exceptioncode >= _EXCEPTION_OFFSET && exceptioncode < _EXCEPTION_MAX;
167 }
168 
170 {
171  switch (code) {
172  case SYNTAX_ERR:
173  return DOMString("SYNTAX_ERR");
174  case INVALID_MODIFICATION_ERR:
175  return DOMString("INVALID_MODIFICATION_ERR");
176  default:
177  return DOMString("(unknown exception code)");
178  }
179 }
180 
181 CSSStyleSheet::CSSStyleSheet() : StyleSheet()
182 {
183 }
184 
185 CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet &other) : StyleSheet(other)
186 {
187 }
188 
189 CSSStyleSheet::CSSStyleSheet(const StyleSheet &other)
190 {
191  if (!other.isCSSStyleSheet()) {
192  impl = nullptr;
193  } else {
194  operator=(other);
195  }
196 }
197 
198 CSSStyleSheet::CSSStyleSheet(CSSStyleSheetImpl *impl) : StyleSheet(impl)
199 {
200 }
201 
202 CSSStyleSheet &CSSStyleSheet::operator = (const CSSStyleSheet &other)
203 {
204  StyleSheet::operator = (other);
205  return *this;
206 }
207 
208 CSSStyleSheet &CSSStyleSheet::operator = (const StyleSheet &other)
209 {
210  if (!other.handle()->isCSSStyleSheet()) {
211  if (impl) {
212  impl->deref();
213  }
214  impl = nullptr;
215  } else {
216  StyleSheet::operator = (other);
217  }
218  return *this;
219 }
220 
221 CSSStyleSheet::~CSSStyleSheet()
222 {
223 }
224 
226 {
227  if (!impl) {
228  return nullptr;
229  }
230  return ((CSSStyleSheetImpl *)impl)->ownerRule();
231 }
232 
234 {
235  if (!impl) {
236  return (CSSRuleListImpl *)nullptr;
237  }
238  return ((CSSStyleSheetImpl *)impl)->cssRules();
239 }
240 
241 unsigned long CSSStyleSheet::insertRule(const DOMString &rule, unsigned long index)
242 {
243  int exceptioncode = 0;
244  if (!impl) {
245  return 0;
246  }
247  unsigned long retval = ((CSSStyleSheetImpl *)impl)->insertRule(rule, index, exceptioncode);
248  if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
249  throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
250  }
251  if (exceptioncode) {
252  throw DOMException(exceptioncode);
253  }
254  return retval;
255 }
256 
257 void CSSStyleSheet::deleteRule(unsigned long index)
258 {
259  int exceptioncode = 0;
260  if (impl) {
261  ((CSSStyleSheetImpl *)impl)->deleteRule(index, exceptioncode);
262  }
263  if (exceptioncode >= CSSException::_EXCEPTION_OFFSET) {
264  throw CSSException(exceptioncode - CSSException::_EXCEPTION_OFFSET);
265  }
266  if (exceptioncode) {
267  throw DOMException(exceptioncode);
268  }
269 }
270 
272 {
273  if (!impl) {
274  return DOMString();
275  }
276  return static_cast<CSSStyleSheetImpl *>(impl)->charset();
277 }
278 
279 StyleSheetList::StyleSheetList()
280 {
281  impl = nullptr;
282 }
283 
284 StyleSheetList::StyleSheetList(const StyleSheetList &other)
285 {
286  impl = other.impl;
287  if (impl) {
288  impl->ref();
289  }
290 }
291 
292 StyleSheetList::StyleSheetList(StyleSheetListImpl *i)
293 {
294  impl = i;
295  if (impl) {
296  impl->ref();
297  }
298 }
299 
300 StyleSheetList &StyleSheetList::operator = (const StyleSheetList &other)
301 {
302  if (impl != other.impl) {
303  if (impl) {
304  impl->deref();
305  }
306  impl = other.impl;
307  if (impl) {
308  impl->ref();
309  }
310  }
311  return *this;
312 }
313 
314 StyleSheetList::~StyleSheetList()
315 {
316  if (impl) {
317  impl->deref();
318  }
319 }
320 
321 unsigned long StyleSheetList::length() const
322 {
323  if (!impl) {
324  return 0;
325  }
326  return ((StyleSheetListImpl *)impl)->length();
327 }
328 
329 StyleSheet StyleSheetList::item(unsigned long index)
330 {
331  if (!impl) {
332  return StyleSheet();
333  }
334  return ((StyleSheetListImpl *)impl)->item(index);
335 }
336 
337 StyleSheetListImpl *StyleSheetList::handle() const
338 {
339  return impl;
340 }
341 
342 bool StyleSheetList::isNull() const
343 {
344  return (impl == nullptr);
345 }
346 
347 // ----------------------------------------------------------
348 
349 MediaList::MediaList()
350 {
351  impl = nullptr;
352 }
353 
354 MediaList::MediaList(const MediaList &other)
355 {
356  impl = other.impl;
357  if (impl) {
358  impl->ref();
359  }
360 }
361 
362 MediaList::MediaList(MediaListImpl *i)
363 {
364  impl = i;
365  if (impl) {
366  impl->ref();
367  }
368 }
369 
370 MediaList &MediaList::operator = (const MediaList &other)
371 {
372  if (impl != other.impl) {
373  if (impl) {
374  impl->deref();
375  }
376  impl = other.impl;
377  if (impl) {
378  impl->ref();
379  }
380  }
381  return *this;
382 }
383 
384 MediaList::~MediaList()
385 {
386  if (impl) {
387  impl->deref();
388  }
389 }
390 
392 {
393  if (!impl) {
394  return DOMString();
395  }
396  return static_cast<MediaListImpl *>(impl)->mediaText();
397 }
398 
400 {
401  if (!impl) {
402  return;
403  }
404  int exceptioncode = 0;
405  static_cast<MediaListImpl *>(impl)->setMediaText(value, exceptioncode);
406  if (exceptioncode) {
407  throw DOMException(exceptioncode);
408  }
409 }
410 
411 unsigned long MediaList::length() const
412 {
413  if (!impl) {
414  return 0;
415  }
416  return ((MediaListImpl *)impl)->length();
417 }
418 
419 DOM::DOMString MediaList::item(unsigned long index) const
420 {
421  if (!impl) {
422  return DOMString();
423  }
424  return ((MediaListImpl *)impl)->item(index);
425 }
426 
428 {
429  if (!impl) {
430  return;
431  }
432  int exceptioncode = 0;
433  ((MediaListImpl *)impl)->deleteMedium(oldMedium, exceptioncode);
434  if (exceptioncode) {
435  throw DOMException(exceptioncode);
436  }
437 }
438 
440 {
441  if (!impl) {
442  return;
443  }
444  int exceptioncode = 0;
445  ((MediaListImpl *)impl)->appendMedium(newMedium, exceptioncode);
446  if (exceptioncode) {
447  throw DOMException(exceptioncode);
448  }
449 }
450 
451 MediaListImpl *MediaList::handle() const
452 {
453  return impl;
454 }
455 
456 bool MediaList::isNull() const
457 {
458  return (impl == nullptr);
459 }
460 
461 // ----------------------------------------------------------
462 
463 LinkStyle::LinkStyle()
464 {
465  node = nullptr;
466 }
467 
468 LinkStyle::LinkStyle(const LinkStyle &other)
469 {
470  node = other.node;
471  if (node) {
472  node->ref();
473  }
474 }
475 
476 LinkStyle &LinkStyle::operator = (const LinkStyle &other)
477 {
478  if (node != other.node) {
479  if (node) {
480  node->deref();
481  }
482  node = other.node;
483  if (node) {
484  node->ref();
485  }
486  }
487  return *this;
488 }
489 
490 LinkStyle &LinkStyle::operator = (const Node &other)
491 {
492  if (node) {
493  node->deref();
494  }
495  node = nullptr;
496  // ### add processing instructions
497  NodeImpl *n = other.handle();
498 
499  // ### check link is really linking a style sheet
500  if (n && n->isElementNode() &&
501  (n->id() == ID_STYLE || n->id() == ID_LINK)) {
502  node = n;
503  if (node) {
504  node->ref();
505  }
506  }
507  return *this;
508 }
509 
510 LinkStyle::~LinkStyle()
511 {
512  if (node) {
513  node->deref();
514  }
515 }
516 
517 StyleSheet LinkStyle::sheet()
518 {
519  int id = node ? node->id() : 0;
520  // ### add PI
521  return
522  (id == ID_STYLE) ?
523  static_cast<HTMLStyleElementImpl *>(node)->sheet()
524  : ((id == ID_LINK) ?
525  static_cast<HTMLLinkElementImpl *>(node)->sheet()
526  : StyleSheet());
527 }
528 
529 bool LinkStyle::isNull() const
530 {
531  return (node == nullptr);
532 }
533 
534 // ----------------------------------------------------------
535 
536 DocumentStyle::DocumentStyle()
537 {
538  doc = nullptr;
539 }
540 
541 DocumentStyle::DocumentStyle(const DocumentStyle &other)
542 {
543  doc = other.doc;
544  if (doc) {
545  doc->ref();
546  }
547 }
548 
549 DocumentStyle &DocumentStyle::operator = (const DocumentStyle &other)
550 {
551  if (doc != other.doc) {
552  if (doc) {
553  doc->deref();
554  }
555  doc = other.doc;
556  if (doc) {
557  doc->ref();
558  }
559  }
560  return *this;
561 }
562 
563 DocumentStyle &DocumentStyle::operator = (const Document &other)
564 {
565  DocumentImpl *odoc = static_cast<DocumentImpl *>(other.handle());
566  if (doc != odoc) {
567  if (doc) {
568  doc->deref();
569  }
570  doc = odoc;
571  if (doc) {
572  doc->ref();
573  }
574  }
575  return *this;
576 }
577 
578 DocumentStyle::~DocumentStyle()
579 {
580  if (doc) {
581  doc->deref();
582  }
583 }
584 
585 StyleSheetList DocumentStyle::styleSheets() const
586 {
587  return doc->styleSheets();
588 }
589 
590 DOMString DocumentStyle::preferredStylesheetSet() const
591 {
592  return doc->preferredStylesheetSet();
593 }
594 
595 void DocumentStyle::setSelectedStylesheetSet(const DOMString &aStr)
596 {
597  return doc->setSelectedStylesheetSet(aStr);
598 }
599 
600 DOMString DocumentStyle::selectedStylesheetSet() const
601 {
602  return doc->selectedStylesheetSet();
603 }
DOM::DOMString charset() const
DOM::DOMString href() const
If the style sheet is a linked style sheet, the value of its attribute is its location.
The Node interface is the primary datatype for the entire Document Object Model.
Definition: dom_node.h:278
The CSSNamespaceRule interface represents an.
Definition: css_rule.h:455
StyleSheet parentStyleSheet() const
For style sheet languages that support the concept of style sheet inclusion, this attribute represent...
bool disabled() const
false if the style sheet is applied to the document.
CSSRuleList cssRules() const
The list of all CSS rules contained within the style sheet.
StyleSheetListImpl * handle() const
void setMediaText(const DOM::DOMString &value)
see mediaText
CSSRule ownerRule() const
If this style sheet comes from an @import rule, the ownerRule attribute will contain the CSSImportRul...
DOM::DOMString item(unsigned long index) const
Returns the indexth in the list.
DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impos...
Definition: dom_exception.h:58
unsigned long insertRule(const DOM::DOMString &rule, unsigned long index)
Used to insert a new rule into the style sheet.
The CSSStyleSheet interface is a concrete interface used to represent a CSS style sheet i...
void setDisabled(bool)
see disabled
MediaList media() const
The intended destination media for style information.
The MediaList interface provides the abstraction of an ordered collection of media, without defining or constraining how this collection is implemented.
DOM::DOMString title() const
The advisory title.
The StyleSheetList interface provides the abstraction of an ordered collection of style sheets...
void deleteMedium(const DOM::DOMString &oldMedium)
Deletes the medium indicated by oldMedium from the list.
MediaListImpl * handle() const
This class implements the basic string we use in the DOM.
Definition: dom_string.h:44
The Document interface represents the entire HTML or XML document.
Definition: dom_doc.h:246
DOMString codeAsString() const
Returns the name of this error.
unsigned long length() const
The number of media in the list.
void deleteRule(unsigned long index)
Used to delete a rule from the style sheet.
DOM::DOMString mediaText() const
The parsable textual representation of the media list.
This library provides a full-featured HTML parser and widget.
void appendMedium(const DOM::DOMString &newMedium)
Adds the medium newMedium to the end of the list.
The CSSRuleList interface provides the abstraction of an ordered collection of CSS rules...
Definition: css_rule.h:507
The StyleSheet interface is the abstract base interface for any type of style sheet.
DOM::DOMString type() const
This specifies the style sheet language for this style sheet.
unsigned long length() const
The number of StyleSheet in the list.
The CSSRule interface is the abstract base interface for any type of CSS statement ...
Definition: css_rule.h:53
StyleSheet item(unsigned long index)
Used to retrieve a style sheet by ordinal index.
DOM::Node ownerNode() const
The node that associates this style sheet with the document.
This exception is raised when a specific CSS operation is impossible to perform.
NodeImpl * handle() const
Definition: dom_node.h:936
static bool isCSSExceptionCode(int exceptioncode)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Sep 29 2020 22:52:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.