Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
style.hh
Go to the documentation of this file.
1#ifndef __DW_STYLE_HH__
2#define __DW_STYLE_HH__
3
4#include <stdint.h>
5#include <math.h>
6
7#ifndef __INCLUDED_FROM_DW_CORE_HH__
8# error Do not include this file directly, use "core.hh" instead.
9#endif
10
11#include <limits.h>
12
13#include "../lout/signal.hh"
14#include "../lout/debug.hh"
15
16namespace dw {
17namespace core {
18
199namespace style {
200
218
223
236
243
248
256
267
274
291
297
325
331
336
343
350
358
366
372
379
380enum {
388 Z_INDEX_AUTO = INT_MAX
390
429typedef int Length;
430
432inline Length createAbsLength(int n) { return (n << 2) | 1; }
433
435inline Length createPerLength(double v) {
436 return ((int)(v * (1 << 18)) & ~3) | 2; }
437
439inline Length createRelLength(double v) {
440 return ((int)(v * (1 << 18)) & ~3) | 3; }
441
443inline bool isAbsLength(Length l) { return (l & 3) == 1; }
444
446inline bool isPerLength(Length l) { return (l & 3) == 2; }
447
449inline bool isRelLength(Length l) { return (l & 3) == 3; }
450
452inline int absLengthVal(Length l) { return l >> 2; }
453
460{ return (double)(l & ~3) / (1 << 18); }
461
467inline double relLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
468
474inline int multiplyWithPerLength(int x, Length l) {
475 return (int) round((double) x * perLengthVal_useThisOnlyForDebugging (l));
476}
477
487
488inline int multiplyWithRelLength(int x, Length l) {
489 return x * relLengthVal(l);
490}
491
492
493enum {
495 LENGTH_AUTO = 0
497
504class Box
505{
506public:
507 /* in future also percentages */
509
510 inline void setVal(int val) { top = right = bottom = left = val; }
511 inline bool equals (Box *other) {
512 return top == other->top &&
513 right == other->right &&
514 bottom == other->bottom &&
515 left == other->left;
516 }
517 inline int hashValue () {
518 return top + right + bottom + left;
519 }
520};
521
522class Tooltip;
523class Font;
524class Color;
525class StyleImage;
526
531{
532public:
534 int textDecoration; /* No TextDecoration because of problems converting
535 * TextDecoration <-> int */
540 Length backgroundPositionX; // "left" defined by "0%" etc. (see CSS spec)
541 Length backgroundPositionY; // "top" defined by "0%" etc. (see CSS spec)
542
545 char textAlignChar; /* In future, strings will be supported. */
547
548 FloatType vloat; /* "float" is a keyword. */
550
552
555
559
562 struct { Color *top, *right, *bottom, *left; } borderColor;
564
571
573 int x_img;
575 char x_lang[2]; /* Either x_lang[0] == x_lang[1] == 0 (no language
576 set), or x_lang contains the RFC 1766 country
577 code in lower case letters. (Only two letters
578 allowed, currently.) */
579
580 void initValues ();
581 void resetValues ();
582
583 bool sizeDiffs (StyleAttrs *otherStyleAttrs);
584
585 inline void setBorderColor(Color *val) {
586 borderColor.top = borderColor.right = borderColor.bottom
587 = borderColor.left = val; }
588 inline void setBorderStyle(BorderStyle val) {
589 borderStyle.top = borderStyle.right = borderStyle.bottom
590 = borderStyle.left = val; }
591
592 inline int boxOffsetX ()
593 { return margin.left + borderWidth.left + padding.left; }
594 inline int boxRestWidth ()
595 { return margin.right + borderWidth.right + padding.right; }
596 inline int boxDiffWidth () { return boxOffsetX () + boxRestWidth (); }
597 inline int boxOffsetY ()
598 { return margin.top + borderWidth.top + padding.top; }
599 inline int boxRestHeight ()
601 inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); }
602
603 inline bool hasBackground ()
604 { return backgroundColor != NULL || backgroundImage != NULL; }
605
606 bool equals (lout::object::Object *other);
607 int hashValue ();
608};
609
610
614class Style: public StyleAttrs
615{
616private:
617 static int totalRef;
619 static lout::container::typed::HashTable <StyleAttrs, Style> *styleTable;
620
621 Style (StyleAttrs *attrs);
622
623protected:
624 ~Style();
625
626 void copyAttrs (StyleAttrs *attrs);
627
628public:
629 inline static Style *create (StyleAttrs *attrs)
630 {
631 Style *style = styleTable->get (attrs);
632 if (style) {
633 style->ref ();
634 } else {
635 style = new Style (attrs);
636 styleTable->put(style, style);
637 }
638 return style;
639 }
640
641 inline void ref () { refCount++; }
642 inline void unref () { if (--refCount == 0) delete this; }
643};
644
645
650{
651public:
652 TooltipAttrs(const char *text): lout::object::String(text) { }
653};
654
659{
660private:
662
663protected:
664 Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; }
665
666public:
667 static Tooltip *create (dw::core::Layout *layout, const char *text);
668 inline void ref () { refCount++; }
669 inline void unref ()
670 { if (--refCount == 0) delete this; }
671
672 inline virtual void onEnter () { }
673 inline virtual void onLeave () { }
674 inline virtual void onMotion () { }
675};
676
677
682{
683public:
684 const char *name;
685 int size;
690
691 bool equals(lout::object::Object *other);
692 int hashValue();
693};
694
695
699class Font: public FontAttrs
700{
701private:
703
704 static Font *create0 (Layout *layout, FontAttrs *attrs, bool tryEverything);
705
706protected:
707 inline Font () {
708 DBG_OBJ_CREATE ("dw::core::style::Font");
709 refCount = 0;
710 }
711 virtual ~Font ();
712
713 void copyAttrs (FontAttrs *attrs);
714
715public:
720
721 static Font *create (Layout *layout, FontAttrs *attrs);
722 static bool exists (Layout *layout, const char *name);
723
724 inline void ref () { refCount++; }
725 inline void unref () { if (--refCount == 0) delete this; }
726};
727
728
733{
734protected:
735 int color;
736
737public:
738 inline ColorAttrs(int color)
739 {
740 this->color = color;
741 }
742
743 inline int getColor () { return color; }
744
745 bool equals(lout::object::Object *other);
746 int hashValue();
747};
748
749
753class Color: public ColorAttrs
754{
755private:
757
759 int shadeColor (int color, int d);
760
761protected:
762 inline Color (int color): ColorAttrs (color) {
763 DBG_OBJ_CREATE ("dw::core::style::Color");
764 refCount = 0;
765 }
766 virtual ~Color ();
767
768public:
771
772protected:
773 int shadeColor (int color, Shading shading);
774
775public:
776 static Color *create (Layout *layout, int color);
777
778 inline void ref () { refCount++; }
779 inline void unref ()
780 { if (--refCount == 0) delete this; }
781};
782
783
785{
786private:
788 {
789 private:
791
792 public:
793 inline StyleImgRenderer (StyleImage *image) { this->image = image; }
794
795 void setBuffer (core::Imgbuf *buffer, bool resize);
796 void drawRow (int row);
797 void finish ();
798 void fatal ();
799 };
800
805
806 StyleImage ();
807 ~StyleImage ();
808
809public:
815 {
816 public:
817 void setBuffer (core::Imgbuf *buffer, bool resize);
818 void drawRow (int row);
819 void finish ();
820 void fatal ();
821
825 virtual bool readyToDraw () = 0;
826
830 virtual void getBgArea (int *x, int *y, int *width, int *height) = 0;
831
837 virtual void getRefArea (int *xRef, int *yRef, int *widthRef,
838 int *heightRef) = 0;
839
845
850 virtual void draw (int x, int y, int width, int height) = 0;
851 };
852
857 {
858 public:
859 void getPaddingArea (int *x, int *y, int *width, int *height);
860
866
870 virtual Style *getStyle () = 0;
871 };
872
873 static StyleImage *create () { return new StyleImage (); }
874
875 inline void ref () { refCount++; }
876 inline void unref ()
877 { if (--refCount == 0) delete this; }
878
879 inline Imgbuf *getImgbufSrc () { return imgbufSrc; }
880 inline Imgbuf *getImgbufTiled (bool repeatX, bool repeatY)
881 { return (imgbufTiled && repeatX && repeatY) ? imgbufTiled : imgbufSrc; }
882 inline int getTilesX (bool repeatX, bool repeatY)
883 { return (imgbufTiled && repeatX && repeatY) ? tilesX : 1; }
884 inline int getTilesY (bool repeatX, bool repeatY)
885 { return (imgbufTiled && repeatX && repeatY) ? tilesY : 1; }
887
893 { imgRendererDist->put (ir); }
894
900};
901
902void drawBorder (View *view, Layout *layout, Rectangle *area,
903 int x, int y, int width, int height,
904 Style *style, bool inverse);
905void drawBackground (View *view, Layout *layout, Rectangle *area,
906 int x, int y, int width, int height,
907 int xRef, int yRef, int widthRef, int heightRef,
908 Style *style, Color *bgColor, bool inverse, bool atTop);
909void drawBackgroundImage (View *view, StyleImage *backgroundImage,
910 BackgroundRepeat backgroundRepeat,
911 BackgroundAttachment backgroundAttachment,
912 Length backgroundPositionX,
913 Length backgroundPositionY,
914 int x, int y, int width, int height,
915 int xRef, int yRef, int widthRef, int heightRef);
916void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType);
917
918} // namespace style
919} // namespace core
920} // namespace dw
921
922#endif // __DW_STYLE_HH__
923
Implementation of ImgRenderer, which distributes all calls to a set of other implementations of ImgRe...
void remove(ImgRenderer *child)
void put(ImgRenderer *child)
The platform independent interface for image buffers.
Definition imgbuf.hh:162
The central class for managing and drawing a widget tree.
Definition layout.hh:17
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
Represents a dimension box according to the CSS box model.
Definition style.hh:505
bool equals(Box *other)
Definition style.hh:511
void setVal(int val)
Definition style.hh:510
bool equals(lout::object::Object *other)
Returns, whether two objects are equal.
Definition style.cc:456
int hashValue()
Return a hash value for the object.
Definition style.cc:462
int shadeColor(int color, int d)
Definition style.cc:472
void remove(dw::core::Layout *layout)
static Color * create(Layout *layout, int color)
Definition style.cc:529
FontVariant fontVariant
Definition style.hh:688
bool equals(lout::object::Object *other)
Returns, whether two objects are equal.
Definition style.cc:398
int hashValue()
Return a hash value for the object.
Definition style.cc:411
static bool exists(Layout *layout, const char *name)
Definition style.cc:449
static Font * create(Layout *layout, FontAttrs *attrs)
Definition style.cc:444
void copyAttrs(FontAttrs *attrs)
Definition style.cc:428
static Font * create0(Layout *layout, FontAttrs *attrs, bool tryEverything)
Definition style.cc:438
ListStyleType listStyleType
Definition style.hh:568
ListStylePosition listStylePosition
Definition style.hh:567
TextTransform textTransform
Definition style.hh:546
StyleImage * backgroundImage
Definition style.hh:537
bool equals(lout::object::Object *other)
Returns, whether two objects are equal.
Definition style.cc:155
BackgroundRepeat backgroundRepeat
Definition style.hh:538
struct dw::core::style::StyleAttrs::@20 borderColor
BackgroundAttachment backgroundAttachment
Definition style.hh:539
int hashValue()
Return a hash value for the object.
Definition style.cc:216
void setBorderStyle(BorderStyle val)
Definition style.hh:588
bool sizeDiffs(StyleAttrs *otherStyleAttrs)
This method returns whether something may change its size, when its style changes from this style to ...
Definition style.cc:150
void setBorderColor(Color *val)
Definition style.hh:585
BorderCollapse borderCollapse
Definition style.hh:561
TextAlignType textAlign
Definition style.hh:543
struct dw::core::style::StyleAttrs::@21 borderStyle
void resetValues()
Reset those style attributes to their standard values, which are not inherited, according to CSS.
Definition style.cc:104
Useful (but not mandatory) base class for updates of areas with background images.
Definition style.hh:815
void finish()
Called, when all image data has been retrieved.
Definition style.cc:699
virtual void draw(int x, int y, int width, int height)=0
Draw (or queue for drawing) an area, which is given in canvas coordinates.
virtual BackgroundRepeat getBackgroundRepeat()=0
virtual BackgroundAttachment getBackgroundAttachment()=0
void drawRow(int row)
Called, when data from a row is available and has been copied into the image buffer.
Definition style.cc:651
virtual void getBgArea(int *x, int *y, int *width, int *height)=0
Return the area covered by the background image.
void fatal()
Called, when there are problems with the retrieval of image data.
Definition style.cc:711
virtual bool readyToDraw()=0
If this method returns false, nothing is done at all.
virtual void getRefArea(int *xRef, int *yRef, int *widthRef, int *heightRef)=0
Return the "reference area".
void setBuffer(core::Imgbuf *buffer, bool resize)
Called, when an image buffer is attached.
Definition style.cc:645
Suitable for widgets and parts of widgets.
Definition style.hh:857
virtual Style * getStyle()=0
Return the style this background image is part of.
void getPaddingArea(int *x, int *y, int *width, int *height)
void fatal()
Called, when there are problems with the retrieval of image data.
Definition style.cc:614
void setBuffer(core::Imgbuf *buffer, bool resize)
Called, when an image buffer is attached.
Definition style.cc:543
void drawRow(int row)
Called, when data from a row is available and has been copied into the image buffer.
Definition style.cc:585
void finish()
Called, when all image data has been retrieved.
Definition style.cc:609
void putExternalImgRenderer(ImgRenderer *ir)
Add an additional ImgRenderer, especially used for drawing.
Definition style.hh:892
int getTilesX(bool repeatX, bool repeatY)
Definition style.hh:882
Imgbuf * getImgbufTiled(bool repeatX, bool repeatY)
Definition style.hh:880
StyleImgRenderer * styleImgRenderer
Definition style.hh:804
int getTilesY(bool repeatX, bool repeatY)
Definition style.hh:884
ImgRenderer * getMainImgRenderer()
Definition style.hh:886
void removeExternalImgRenderer(ImgRenderer *ir)
Remove a previously added additional ImgRenderer.
Definition style.hh:898
static StyleImage * create()
Definition style.hh:873
ImgRendererDist * imgRendererDist
Definition style.hh:803
static lout::container::typed::HashTable< StyleAttrs, Style > * styleTable
Definition style.hh:619
static Style * create(StyleAttrs *attrs)
Definition style.hh:629
static int totalRef
Definition style.hh:617
void copyAttrs(StyleAttrs *attrs)
Definition style.cc:343
TooltipAttrs(const char *text)
Definition style.hh:652
virtual void onMotion()
Definition style.hh:674
virtual void onLeave()
Definition style.hh:673
virtual void onEnter()
Definition style.hh:672
static Tooltip * create(dw::core::Layout *layout, const char *text)
Definition style.cc:536
Tooltip(const char *text)
Definition style.hh:664
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:25
An object::Object wrapper for strings (char*).
Definition object.hh:186
An observed object has a signal emitter, which tells the receivers, when the object is deleted.
Definition signal.hh:275
#define DBG_OBJ_CREATE(klass)
static Layout * layout
int multiplyWithRelLength(int x, Length l)
Definition style.hh:488
@ LIST_STYLE_POSITION_INSIDE
Definition style.hh:299
@ LIST_STYLE_POSITION_OUTSIDE
Definition style.hh:300
int multiplyWithPerLength(int x, Length l)
Multiply an int with a percentage length, returning int.
Definition style.hh:474
@ BACKGROUND_ATTACHMENT_FIXED
Definition style.hh:246
@ BACKGROUND_ATTACHMENT_SCROLL
Definition style.hh:245
@ BACKGROUND_NO_REPEAT
Definition style.hh:241
@ BACKGROUND_REPEAT_Y
Definition style.hh:240
@ BACKGROUND_REPEAT_X
Definition style.hh:239
void drawBackground(View *view, Layout *layout, Rectangle *area, int x, int y, int width, int height, int xRef, int yRef, int widthRef, int heightRef, Style *style, Color *bgColor, bool inverse, bool atTop)
Draw the background (content plus padding) of a region in window, according to style.
Definition style.cc:1233
@ LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO
Definition style.hh:307
@ LIST_STYLE_TYPE_HIRAGANA
Definition style.hh:319
@ LIST_STYLE_TYPE_DISC
Definition style.hh:303
@ LIST_STYLE_TYPE_GEORGIAN
Definition style.hh:317
@ LIST_STYLE_TYPE_LOWER_LATIN
Definition style.hh:312
@ LIST_STYLE_TYPE_UPPER_LATIN
Definition style.hh:314
@ LIST_STYLE_TYPE_HEBREW
Definition style.hh:315
@ LIST_STYLE_TYPE_UPPER_ALPHA
Definition style.hh:313
@ LIST_STYLE_TYPE_LOWER_ALPHA
Definition style.hh:311
@ LIST_STYLE_TYPE_HIRAGANA_IROHA
Definition style.hh:321
@ LIST_STYLE_TYPE_LOWER_GREEK
Definition style.hh:310
@ LIST_STYLE_TYPE_KATAKANA
Definition style.hh:320
@ LIST_STYLE_TYPE_ARMENIAN
Definition style.hh:316
@ LIST_STYLE_TYPE_CIRCLE
Definition style.hh:304
@ LIST_STYLE_TYPE_UPPER_ROMAN
Definition style.hh:309
@ LIST_STYLE_TYPE_KATAKANA_IROHA
Definition style.hh:322
@ LIST_STYLE_TYPE_DECIMAL
Definition style.hh:306
@ LIST_STYLE_TYPE_SQUARE
Definition style.hh:305
@ LIST_STYLE_TYPE_CJK_IDEOGRAPHIC
Definition style.hh:318
@ LIST_STYLE_TYPE_NONE
Definition style.hh:323
@ LIST_STYLE_TYPE_LOWER_ROMAN
Definition style.hh:308
void drawBackgroundImage(View *view, StyleImage *backgroundImage, BackgroundRepeat backgroundRepeat, BackgroundAttachment backgroundAttachment, Length backgroundPositionX, Length backgroundPositionY, int x, int y, int width, int height, int xRef, int yRef, int widthRef, int heightRef)
Definition style.cc:1286
double relLengthVal(Length l)
Returns the value of a relative length, as a float.
Definition style.hh:467
@ DISPLAY_TABLE_HEADER_GROUP
Definition style.hh:286
@ DISPLAY_TABLE_ROW_GROUP
Definition style.hh:285
@ DISPLAY_INLINE_BLOCK
Definition style.hh:281
@ DISPLAY_TABLE_FOOTER_GROUP
Definition style.hh:287
int multiplyWithPerLengthRounded(int x, Length l)
Like multiplyWithPerLength, but rounds to nearest integer instead of down.
Definition style.hh:484
Length createPerLength(double v)
Returns a percentage, v is relative to 1, not to 100.
Definition style.hh:435
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:429
@ TEXT_TRANSFORM_LOWERCASE
Definition style.hh:272
@ TEXT_TRANSFORM_UPPERCASE
Definition style.hh:271
@ TEXT_TRANSFORM_CAPITALIZE
Definition style.hh:270
@ TEXT_TRANSFORM_NONE
Definition style.hh:269
double perLengthVal_useThisOnlyForDebugging(Length l)
Returns the value of a percentage, relative to 1, as a double.
Definition style.hh:459
Length createAbsLength(int n)
Returns a length of n pixels.
Definition style.hh:432
@ TEXT_DECORATION_OVERLINE
Definition style.hh:354
@ TEXT_DECORATION_LINE_THROUGH
Definition style.hh:355
@ TEXT_DECORATION_BLINK
Definition style.hh:356
@ TEXT_DECORATION_UNDERLINE
Definition style.hh:353
@ TEXT_DECORATION_NONE
Definition style.hh:352
bool isRelLength(Length l)
Returns true if l is a relative length.
Definition style.hh:449
void drawBorder(View *view, Layout *layout, Rectangle *area, int x, int y, int width, int height, Style *style, bool inverse)
Draw the border of a region in window, according to style.
Definition style.cc:1168
@ FONT_VARIANT_NORMAL
Definition style.hh:333
@ FONT_VARIANT_SMALL_CAPS
Definition style.hh:334
void numtostr(int num, char *buf, int buflen, ListStyleType listStyleType)
Convert a number into a string, in a given list style.
Definition style.cc:1422
@ BORDER_MODEL_SEPARATE
Definition style.hh:220
@ BORDER_MODEL_COLLAPSE
Definition style.hh:221
Length createRelLength(double v)
Returns a relative length.
Definition style.hh:439
@ Z_INDEX_AUTO
'z-index' is stored as int; use this for the value 'auto'.
Definition style.hh:388
bool isPerLength(Length l)
Returns true if l is a percentage.
Definition style.hh:446
bool isAbsLength(Length l)
Returns true if l is an absolute length.
Definition style.hh:443
int absLengthVal(Length l)
Returns the value of a length in pixels, as an integer.
Definition style.hh:452
@ LENGTH_AUTO
Represents "auto" lengths.
Definition style.hh:495
@ WHITE_SPACE_PRE_LINE
Definition style.hh:364
@ WHITE_SPACE_PRE_WRAP
Definition style.hh:363
Dw is in this namespace, or sub namespaces of this one.
int roundInt(double d)
Definition misc.hh:82