00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "xml/dom_stringimpl.h"
00025
00026 #include "render_style.h"
00027
00028 #include "kdebug.h"
00029
00030 using namespace khtml;
00031
00032
00033
00034
00035 StyleSurroundData::StyleSurroundData()
00036 : margin( Fixed ), padding( Variable )
00037 {
00038 }
00039
00040 StyleSurroundData::StyleSurroundData(const StyleSurroundData& o )
00041 : Shared<StyleSurroundData>(),
00042 offset( o.offset ), margin( o.margin ), padding( o.padding ),
00043 border( o.border )
00044 {
00045 }
00046
00047 bool StyleSurroundData::operator==(const StyleSurroundData& o) const
00048 {
00049 return offset==o.offset && margin==o.margin &&
00050 padding==o.padding && border==o.border;
00051 }
00052
00053 StyleBoxData::StyleBoxData()
00054 : z_index( ZAUTO )
00055 {
00056 }
00057
00058 StyleBoxData::StyleBoxData(const StyleBoxData& o )
00059 : Shared<StyleBoxData>(),
00060 width( o.width ), height( o.height ),
00061 min_width( o.min_width ), max_width( o.max_width ),
00062 min_height ( o.min_height ), max_height( o.max_height ),
00063 z_index( o.z_index )
00064 {
00065 }
00066
00067 bool StyleBoxData::operator==(const StyleBoxData& o) const
00068 {
00069 return
00070 width == o.width &&
00071 height == o.height &&
00072 min_width == o.min_width &&
00073 max_width == o.max_width &&
00074 min_height == o.min_height &&
00075 max_height == o.max_height &&
00076 z_index == o.z_index;
00077 }
00078
00079 StyleVisualData::StyleVisualData()
00080 : colspan( 1 ), counter_increment( 0 ), counter_reset( 0 ),
00081 palette( QApplication::palette() )
00082 {
00083 }
00084
00085 StyleVisualData::~StyleVisualData() {
00086 }
00087
00088 StyleVisualData::StyleVisualData(const StyleVisualData& o )
00089 : Shared<StyleVisualData>(),
00090 clip( o.clip ), colspan( o.colspan ),
00091 counter_increment( o.counter_increment ), counter_reset( o.counter_reset ),
00092 palette( o.palette )
00093 {
00094 }
00095
00096
00097
00098 StyleBackgroundData::StyleBackgroundData()
00099 : image( 0 )
00100 {
00101 }
00102
00103 StyleBackgroundData::StyleBackgroundData(const StyleBackgroundData& o )
00104 : Shared<StyleBackgroundData>(),
00105 color( o.color ), image( o.image ),
00106 x_position( o.x_position ), y_position( o.y_position ),
00107 outline( o.outline )
00108 {
00109 }
00110
00111 bool StyleBackgroundData::operator==(const StyleBackgroundData& o) const
00112 {
00113 return
00114 color == o.color &&
00115 image == o.image &&
00116 x_position == o.x_position &&
00117 y_position == o.y_position &&
00118 outline == o.outline;
00119 }
00120
00121
00122
00123 StyleInheritedData::StyleInheritedData()
00124 : indent( Fixed ), line_height( -100, Percent ), style_image( 0 ),
00125 font(), color( Qt::black ), decoration_color( Qt::black ), border_spacing( 0 )
00126 {
00127 }
00128
00129 StyleInheritedData::~StyleInheritedData()
00130 {
00131 }
00132
00133 StyleInheritedData::StyleInheritedData(const StyleInheritedData& o )
00134 : Shared<StyleInheritedData>(),
00135 indent( o.indent ), line_height( o.line_height ), style_image( o.style_image ),
00136 font( o.font ), color( o.color ), decoration_color( o.decoration_color ),
00137 border_spacing( o.border_spacing )
00138 {
00139 }
00140
00141 bool StyleInheritedData::operator==(const StyleInheritedData& o) const
00142 {
00143 return
00144 indent == o.indent &&
00145 line_height == o.line_height &&
00146 border_spacing == o.border_spacing &&
00147 style_image == o.style_image &&
00148 font == o.font &&
00149 color == o.color &&
00150 decoration_color == o.decoration_color;
00151
00152
00153
00154 }
00155
00156 RenderStyle::RenderStyle()
00157 {
00158
00159 if (!_default)
00160 _default = new RenderStyle(true);
00161
00162 box = _default->box;
00163 visual = _default->visual;
00164 background = _default->background;
00165 surround = _default->surround;
00166
00167 inherited = _default->inherited;
00168
00169 setBitDefaults();
00170
00171 pseudoStyle = 0;
00172 content = 0;
00173 }
00174
00175 RenderStyle::RenderStyle(bool)
00176 {
00177 setBitDefaults();
00178
00179 box.init();
00180 visual.init();
00181 background.init();
00182 surround.init();
00183
00184 inherited.init();
00185
00186 pseudoStyle = 0;
00187 content = 0;
00188 }
00189
00190 RenderStyle::RenderStyle(const RenderStyle& o)
00191 : Shared<RenderStyle>(),
00192 inherited_flags( o.inherited_flags ), noninherited_flags( o.noninherited_flags ),
00193 box( o.box ), visual( o.visual ), background( o.background ), surround( o.surround ),
00194 inherited( o.inherited ), pseudoStyle( 0 ), content( o.content )
00195 {
00196 }
00197
00198 void RenderStyle::inheritFrom(const RenderStyle* inheritParent)
00199 {
00200 inherited = inheritParent->inherited;
00201 inherited_flags = inheritParent->inherited_flags;
00202 }
00203
00204 RenderStyle::~RenderStyle()
00205 {
00206 RenderStyle *ps = pseudoStyle;
00207 RenderStyle *prev = 0;
00208
00209 while (ps) {
00210 prev = ps;
00211 ps = ps->pseudoStyle;
00212
00213
00214
00215 prev->pseudoStyle = 0;
00216 prev->deref();
00217 }
00218 delete content;
00219 }
00220
00221 bool RenderStyle::operator==(const RenderStyle& o) const
00222 {
00223
00224 return (inherited_flags == o.inherited_flags &&
00225 noninherited_flags == o.noninherited_flags &&
00226 box == o.box &&
00227 visual == o.visual &&
00228 background == o.background &&
00229 surround == o.surround &&
00230 inherited == o.inherited);
00231 }
00232
00233 RenderStyle* RenderStyle::getPseudoStyle(PseudoId pid)
00234 {
00235 RenderStyle *ps = 0;
00236 if (noninherited_flags._styleType==NOPSEUDO)
00237 for (ps = pseudoStyle; ps; ps = ps->pseudoStyle)
00238 if (ps->noninherited_flags._styleType==pid)
00239 break;
00240 return ps;
00241 }
00242
00243 RenderStyle* RenderStyle::addPseudoStyle(PseudoId pid)
00244 {
00245 RenderStyle *ps = getPseudoStyle(pid);
00246
00247 if (!ps)
00248 {
00249 ps = new RenderStyle(*this);
00250 ps->ref();
00251 ps->noninherited_flags._styleType = pid;
00252 ps->pseudoStyle = pseudoStyle;
00253
00254 pseudoStyle = ps;
00255 }
00256
00257 return ps;
00258 }
00259
00260 void RenderStyle::removePseudoStyle(PseudoId pid)
00261 {
00262 RenderStyle *ps = pseudoStyle;
00263 RenderStyle *prev = this;
00264
00265 while (ps) {
00266 if (ps->noninherited_flags._styleType==pid) {
00267 prev->pseudoStyle = ps->pseudoStyle;
00268 ps->deref();
00269 return;
00270 }
00271 prev = ps;
00272 ps = ps->pseudoStyle;
00273 }
00274 }
00275
00276
00277 bool RenderStyle::inheritedNotEqual( RenderStyle *other ) const
00278 {
00279 return
00280 (
00281 inherited_flags != other->inherited_flags ||
00282 inherited != other->inherited
00283 );
00284 }
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301 RenderStyle::Diff RenderStyle::diff( const RenderStyle *other ) const
00302 {
00303 Diff d = Equal;
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322 if ( *box.get() != *other->box.get() ||
00323 *visual.get() != *other->visual.get() ||
00324 *surround.get() != *other->surround.get() ||
00325 *inherited.get() != *other->inherited.get()
00326 )
00327 d = CbLayout;
00328
00329 if ( d == CbLayout )
00330 return d;
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341 if ( ((int)noninherited_flags._display) >= TABLE ) {
00342
00343
00344
00345 if ( !(inherited_flags._border_collapse == other->inherited_flags._border_collapse) ||
00346 !(inherited_flags._empty_cells == other->inherited_flags._empty_cells) ||
00347 !(inherited_flags._caption_side == other->inherited_flags._caption_side) ||
00348 !(noninherited_flags._table_layout == other->noninherited_flags._table_layout) ||
00349 !(noninherited_flags._position == other->noninherited_flags._position) ||
00350 !(noninherited_flags._floating == other->noninherited_flags._floating) )
00351
00352 d = CbLayout;
00353 }
00354
00355
00356
00357
00358 if (noninherited_flags._display == LIST_ITEM ) {
00359 if ( !(inherited_flags._list_style_type == other->inherited_flags._list_style_type) ||
00360 !(inherited_flags._list_style_position == other->inherited_flags._list_style_position) )
00361 d = Layout;
00362 }
00363
00364 if ( d == Layout )
00365 return d;
00366
00367
00368
00369
00370
00371
00372
00373
00374 if ( !(inherited_flags._text_align == other->inherited_flags._text_align) ||
00375 !(inherited_flags._text_transform == other->inherited_flags._text_transform) ||
00376 !(inherited_flags._direction == other->inherited_flags._direction) ||
00377 !(inherited_flags._white_space == other->inherited_flags._white_space) ||
00378 !(inherited_flags._font_variant == other->inherited_flags._font_variant) ||
00379 !(noninherited_flags._clear == other->noninherited_flags._clear)
00380 )
00381 d = Layout;
00382
00383
00384
00385
00386 if ( !(noninherited_flags._display == INLINE) ) {
00387 if ( !(noninherited_flags._vertical_align == other->noninherited_flags._vertical_align))
00388 d = Layout;
00389 }
00390
00391 if ( d == Layout )
00392 return d;
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402 if ( !(inherited_flags._visibility == other->inherited_flags._visibility) ||
00403 !(noninherited_flags._overflow == other->noninherited_flags._overflow) ||
00404 !(noninherited_flags._bg_repeat == other->noninherited_flags._bg_repeat) ||
00405 !(noninherited_flags._bg_attachment == other->noninherited_flags._bg_attachment) ||
00406 !(noninherited_flags._clipSpecified == other->noninherited_flags._clipSpecified) ||
00407 !(inherited_flags._text_decoration == other->inherited_flags._text_decoration) ||
00408 *background.get() != *other->background.get()
00409 )
00410 d = Visible;
00411
00412
00413
00414 return d;
00415 }
00416
00417
00418 RenderStyle* RenderStyle::_default = 0;
00419
00420
00421
00422 void RenderStyle::cleanup()
00423 {
00424 delete _default;
00425 _default = 0;
00426
00427
00428 }
00429
00430 void RenderStyle::setContent(CachedObject* o)
00431 {
00432 if ( !content )
00433 content = new ContentData;
00434 else
00435 content->clearContent();
00436
00437 content->_content.object = o;
00438 content->_contentType = o ? CONTENT_OBJECT : CONTENT_NONE;
00439 }
00440
00441
00442 void RenderStyle::setPaletteColor(QPalette::ColorGroup g, QColorGroup::ColorRole r, const QColor& c)
00443 {
00444 visual.access()->palette.setColor(g,r,c);
00445 }
00446
00447 void RenderStyle::setClip( Length top, Length right, Length bottom, Length left )
00448 {
00449 StyleVisualData *data = visual.access();
00450 data->clip.top = top;
00451 data->clip.right = right;
00452 data->clip.bottom = bottom;
00453 data->clip.left = left;
00454 }
00455
00456 void RenderStyle::setContent(DOM::DOMStringImpl* s)
00457 {
00458 if ( !content )
00459 content = new ContentData;
00460 else
00461 content->clearContent();
00462
00463 content->_content.text = s;
00464
00465 if (s) {
00466 content->_content.text->ref();
00467 content->_contentType = CONTENT_TEXT;
00468 }
00469 else
00470 content->_contentType = CONTENT_NONE;
00471 }
00472
00473 ContentData::~ContentData()
00474 {
00475 clearContent();
00476 }
00477
00478 void ContentData::clearContent()
00479 {
00480 switch (_contentType)
00481 {
00482 case CONTENT_OBJECT:
00483
00484 _content.object = 0;
00485 break;
00486 case CONTENT_TEXT:
00487 _content.text->deref();
00488 _content.text = 0;
00489 default:
00490 ;
00491 }
00492 }