Dillo v3.1.1-46-g8a360e32
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
6#ifndef __INCLUDED_FROM_DW_CORE_HH__
7# error Do not include this file directly, use "core.hh" instead.
8#endif
9
10#include <limits.h>
11
12#include "../lout/signal.hh"
13#include "../lout/debug.hh"
14
15namespace dw {
16namespace core {
17
198namespace style {
199
217
222
235
242
247
255
266
273
290
296
324
330
335
342
349
357
365
371
378
379enum {
387 Z_INDEX_AUTO = INT_MAX
389
428typedef int Length;
429
431inline Length createAbsLength(int n) { return (n << 2) | 1; }
432
434inline Length createPerLength(double v) {
435 return ((int)(v * (1 << 18)) & ~3) | 2; }
436
438inline Length createRelLength(double v) {
439 return ((int)(v * (1 << 18)) & ~3) | 3; }
440
442inline bool isAbsLength(Length l) { return (l & 3) == 1; }
443
445inline bool isPerLength(Length l) { return (l & 3) == 2; }
446
448inline bool isRelLength(Length l) { return (l & 3) == 3; }
449
451inline int absLengthVal(Length l) { return l >> 2; }
452
459{ return (double)(l & ~3) / (1 << 18); }
460
466inline double relLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
467
473inline int multiplyWithPerLength(int x, Length l) {
475}
476
486
487inline int multiplyWithRelLength(int x, Length l) {
488 return x * relLengthVal(l);
489}
490
491
492enum {
494 LENGTH_AUTO = 0
496
503class Box
504{
505public:
506 /* in future also percentages */
508
509 inline void setVal(int val) { top = right = bottom = left = val; }
510 inline bool equals (Box *other) {
511 return top == other->top &&
512 right == other->right &&
513 bottom == other->bottom &&
514 left == other->left;
515 }
516 inline int hashValue () {
517 return top + right + bottom + left;
518 }
519};
520
521class Tooltip;
522class Font;
523class Color;
524class StyleImage;
525
530{
531public:
533 int textDecoration; /* No TextDecoration because of problems converting
534 * TextDecoration <-> int */
539 Length backgroundPositionX; // "left" defined by "0%" etc. (see CSS spec)
540 Length backgroundPositionY; // "top" defined by "0%" etc. (see CSS spec)
541
544 char textAlignChar; /* In future, strings will be supported. */
546
547 FloatType vloat; /* "float" is a keyword. */
549
551
554
558
561 struct { Color *top, *right, *bottom, *left; } borderColor;
563
570
572 int x_img;
574 char x_lang[2]; /* Either x_lang[0] == x_lang[1] == 0 (no language
575 set), or x_lang contains the RFC 1766 country
576 code in lower case letters. (Only two letters
577 allowed, currently.) */
578
579 void initValues ();
580 void resetValues ();
581
582 bool sizeDiffs (StyleAttrs *otherStyleAttrs);
583
584 inline void setBorderColor(Color *val) {
585 borderColor.top = borderColor.right = borderColor.bottom
586 = borderColor.left = val; }
587 inline void setBorderStyle(BorderStyle val) {
588 borderStyle.top = borderStyle.right = borderStyle.bottom
589 = borderStyle.left = val; }
590
591 inline int boxOffsetX ()
592 { return margin.left + borderWidth.left + padding.left; }
593 inline int boxRestWidth ()
594 { return margin.right + borderWidth.right + padding.right; }
595 inline int boxDiffWidth () { return boxOffsetX () + boxRestWidth (); }
596 inline int boxOffsetY ()
597 { return margin.top + borderWidth.top + padding.top; }
598 inline int boxRestHeight ()
600 inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); }
601
602 inline bool hasBackground ()
603 { return backgroundColor != NULL || backgroundImage != NULL; }
604
605 bool equals (lout::object::Object *other);
606 int hashValue ();
607};
608
609
613class Style: public StyleAttrs
614{
615private:
616 static int totalRef;
618 static lout::container::typed::HashTable <StyleAttrs, Style> *styleTable;
619
620 Style (StyleAttrs *attrs);
621
622protected:
623 ~Style();
624
625 void copyAttrs (StyleAttrs *attrs);
626
627public:
628 inline static Style *create (StyleAttrs *attrs)
629 {
630 Style *style = styleTable->get (attrs);
631 if (style) {
632 style->ref ();
633 } else {
634 style = new Style (attrs);
635 styleTable->put(style, style);
636 }
637 return style;
638 }
639
640 inline void ref () { refCount++; }
641 inline void unref () { if (--refCount == 0) delete this; }
642};
643
644
649{
650public:
651 TooltipAttrs(const char *text): lout::object::String(text) { }
652};
653
658{
659private:
661
662protected:
663 Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; }
664
665public:
666 static Tooltip *create (dw::core::Layout *layout, const char *text);
667 inline void ref () { refCount++; }
668 inline void unref ()
669 { if (--refCount == 0) delete this; }
670
671 inline virtual void onEnter () { }
672 inline virtual void onLeave () { }
673 inline virtual void onMotion () { }
674};
675
676
681{
682public:
683 const char *name;
684 int size;
689
690 bool equals(lout::object::Object *other);
691 int hashValue();
692};
693
694
698class Font: public FontAttrs
699{
700private:
702
703 static Font *create0 (Layout *layout, FontAttrs *attrs, bool tryEverything);
704
705protected:
706 inline Font () {
707 DBG_OBJ_CREATE ("dw::core::style::Font");
708 refCount = 0;
709 }
710 virtual ~Font ();
711
712 void copyAttrs (FontAttrs *attrs);
713
714public:
718
719 static Font *create (Layout *layout, FontAttrs *attrs);
720 static bool exists (Layout *layout, const char *name);
721
722 inline void ref () { refCount++; }
723 inline void unref () { if (--refCount == 0) delete this; }
724};
725
726
731{
732protected:
733 int color;
734
735public:
736 inline ColorAttrs(int color)
737 {
738 this->color = color;
739 }
740
741 inline int getColor () { return color; }
742
743 bool equals(lout::object::Object *other);
744 int hashValue();
745};
746
747
751class Color: public ColorAttrs
752{
753private:
755
757 int shadeColor (int color, int d);
758
759protected:
760 inline Color (int color): ColorAttrs (color) {
761 DBG_OBJ_CREATE ("dw::core::style::Color");
762 refCount = 0;
763 }
764 virtual ~Color ();
765
766public:
769
770protected:
771 int shadeColor (int color, Shading shading);
772
773public:
774 static Color *create (Layout *layout, int color);
775
776 inline void ref () { refCount++; }
777 inline void unref ()
778 { if (--refCount == 0) delete this; }
779};
780
781
783{
784private:
786 {
787 private:
789
790 public:
791 inline StyleImgRenderer (StyleImage *image) { this->image = image; }
792
793 void setBuffer (core::Imgbuf *buffer, bool resize);
794 void drawRow (int row);
795 void finish ();
796 void fatal ();
797 };
798
803
804 StyleImage ();
805 ~StyleImage ();
806
807public:
813 {
814 public:
815 void setBuffer (core::Imgbuf *buffer, bool resize);
816 void drawRow (int row);
817 void finish ();
818 void fatal ();
819
823 virtual bool readyToDraw () = 0;
824
828 virtual void getBgArea (int *x, int *y, int *width, int *height) = 0;
829
835 virtual void getRefArea (int *xRef, int *yRef, int *widthRef,
836 int *heightRef) = 0;
837
843
848 virtual void draw (int x, int y, int width, int height) = 0;
849 };
850
855 {
856 public:
857 void getPaddingArea (int *x, int *y, int *width, int *height);
858
864
868 virtual Style *getStyle () = 0;
869 };
870
871 static StyleImage *create () { return new StyleImage (); }
872
873 inline void ref () { refCount++; }
874 inline void unref ()
875 { if (--refCount == 0) delete this; }
876
877 inline Imgbuf *getImgbufSrc () { return imgbufSrc; }
878 inline Imgbuf *getImgbufTiled (bool repeatX, bool repeatY)
879 { return (imgbufTiled && repeatX && repeatY) ? imgbufTiled : imgbufSrc; }
880 inline int getTilesX (bool repeatX, bool repeatY)
881 { return (imgbufTiled && repeatX && repeatY) ? tilesX : 1; }
882 inline int getTilesY (bool repeatX, bool repeatY)
883 { return (imgbufTiled && repeatX && repeatY) ? tilesY : 1; }
885
891 { imgRendererDist->put (ir); }
892
898};
899
900void drawBorder (View *view, Layout *layout, Rectangle *area,
901 int x, int y, int width, int height,
902 Style *style, bool inverse);
903void drawBackground (View *view, Layout *layout, Rectangle *area,
904 int x, int y, int width, int height,
905 int xRef, int yRef, int widthRef, int heightRef,
906 Style *style, Color *bgColor, bool inverse, bool atTop);
907void drawBackgroundImage (View *view, StyleImage *backgroundImage,
908 BackgroundRepeat backgroundRepeat,
909 BackgroundAttachment backgroundAttachment,
910 Length backgroundPositionX,
911 Length backgroundPositionY,
912 int x, int y, int width, int height,
913 int xRef, int yRef, int widthRef, int heightRef);
914void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType);
915
916} // namespace style
917} // namespace core
918} // namespace dw
919
920#endif // __DW_STYLE_HH__
921
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:504
bool equals(Box *other)
Definition style.hh:510
void setVal(int val)
Definition style.hh:509
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:687
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:567
ListStylePosition listStylePosition
Definition style.hh:566
TextTransform textTransform
Definition style.hh:545
StyleImage * backgroundImage
Definition style.hh:536
bool equals(lout::object::Object *other)
Returns, whether two objects are equal.
Definition style.cc:155
BackgroundRepeat backgroundRepeat
Definition style.hh:537
struct dw::core::style::StyleAttrs::@20 borderColor
BackgroundAttachment backgroundAttachment
Definition style.hh:538
int hashValue()
Return a hash value for the object.
Definition style.cc:216
void setBorderStyle(BorderStyle val)
Definition style.hh:587
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:584
BorderCollapse borderCollapse
Definition style.hh:560
TextAlignType textAlign
Definition style.hh:542
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:813
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:855
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:890
int getTilesX(bool repeatX, bool repeatY)
Definition style.hh:880
Imgbuf * getImgbufTiled(bool repeatX, bool repeatY)
Definition style.hh:878
StyleImgRenderer * styleImgRenderer
Definition style.hh:802
int getTilesY(bool repeatX, bool repeatY)
Definition style.hh:882
ImgRenderer * getMainImgRenderer()
Definition style.hh:884
void removeExternalImgRenderer(ImgRenderer *ir)
Remove a previously added additional ImgRenderer.
Definition style.hh:896
static StyleImage * create()
Definition style.hh:871
ImgRendererDist * imgRendererDist
Definition style.hh:801
static lout::container::typed::HashTable< StyleAttrs, Style > * styleTable
Definition style.hh:618
static Style * create(StyleAttrs *attrs)
Definition style.hh:628
static int totalRef
Definition style.hh:616
void copyAttrs(StyleAttrs *attrs)
Definition style.cc:343
TooltipAttrs(const char *text)
Definition style.hh:651
virtual void onMotion()
Definition style.hh:673
virtual void onLeave()
Definition style.hh:672
virtual void onEnter()
Definition style.hh:671
static Tooltip * create(dw::core::Layout *layout, const char *text)
Definition style.cc:536
Tooltip(const char *text)
Definition style.hh:663
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:487
@ LIST_STYLE_POSITION_INSIDE
Definition style.hh:298
@ LIST_STYLE_POSITION_OUTSIDE
Definition style.hh:299
int multiplyWithPerLength(int x, Length l)
Multiply an int with a percentage length, returning int.
Definition style.hh:473
@ BACKGROUND_ATTACHMENT_FIXED
Definition style.hh:245
@ BACKGROUND_ATTACHMENT_SCROLL
Definition style.hh:244
@ BACKGROUND_NO_REPEAT
Definition style.hh:240
@ BACKGROUND_REPEAT_Y
Definition style.hh:239
@ BACKGROUND_REPEAT_X
Definition style.hh:238
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:306
@ LIST_STYLE_TYPE_HIRAGANA
Definition style.hh:318
@ LIST_STYLE_TYPE_DISC
Definition style.hh:302
@ LIST_STYLE_TYPE_GEORGIAN
Definition style.hh:316
@ LIST_STYLE_TYPE_LOWER_LATIN
Definition style.hh:311
@ LIST_STYLE_TYPE_UPPER_LATIN
Definition style.hh:313
@ LIST_STYLE_TYPE_HEBREW
Definition style.hh:314
@ LIST_STYLE_TYPE_UPPER_ALPHA
Definition style.hh:312
@ LIST_STYLE_TYPE_LOWER_ALPHA
Definition style.hh:310
@ LIST_STYLE_TYPE_HIRAGANA_IROHA
Definition style.hh:320
@ LIST_STYLE_TYPE_LOWER_GREEK
Definition style.hh:309
@ LIST_STYLE_TYPE_KATAKANA
Definition style.hh:319
@ LIST_STYLE_TYPE_ARMENIAN
Definition style.hh:315
@ LIST_STYLE_TYPE_CIRCLE
Definition style.hh:303
@ LIST_STYLE_TYPE_UPPER_ROMAN
Definition style.hh:308
@ LIST_STYLE_TYPE_KATAKANA_IROHA
Definition style.hh:321
@ LIST_STYLE_TYPE_DECIMAL
Definition style.hh:305
@ LIST_STYLE_TYPE_SQUARE
Definition style.hh:304
@ LIST_STYLE_TYPE_CJK_IDEOGRAPHIC
Definition style.hh:317
@ LIST_STYLE_TYPE_NONE
Definition style.hh:322
@ LIST_STYLE_TYPE_LOWER_ROMAN
Definition style.hh:307
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:466
@ DISPLAY_TABLE_HEADER_GROUP
Definition style.hh:285
@ DISPLAY_TABLE_ROW_GROUP
Definition style.hh:284
@ DISPLAY_INLINE_BLOCK
Definition style.hh:280
@ DISPLAY_TABLE_FOOTER_GROUP
Definition style.hh:286
int multiplyWithPerLengthRounded(int x, Length l)
Like multiplyWithPerLength, but rounds to nearest integer instead of down.
Definition style.hh:483
Length createPerLength(double v)
Returns a percentage, v is relative to 1, not to 100.
Definition style.hh:434
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:428
@ TEXT_TRANSFORM_LOWERCASE
Definition style.hh:271
@ TEXT_TRANSFORM_UPPERCASE
Definition style.hh:270
@ TEXT_TRANSFORM_CAPITALIZE
Definition style.hh:269
@ TEXT_TRANSFORM_NONE
Definition style.hh:268
double perLengthVal_useThisOnlyForDebugging(Length l)
Returns the value of a percentage, relative to 1, as a double.
Definition style.hh:458
Length createAbsLength(int n)
Returns a length of n pixels.
Definition style.hh:431
@ TEXT_DECORATION_OVERLINE
Definition style.hh:353
@ TEXT_DECORATION_LINE_THROUGH
Definition style.hh:354
@ TEXT_DECORATION_BLINK
Definition style.hh:355
@ TEXT_DECORATION_UNDERLINE
Definition style.hh:352
@ TEXT_DECORATION_NONE
Definition style.hh:351
bool isRelLength(Length l)
Returns true if l is a relative length.
Definition style.hh:448
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:332
@ FONT_VARIANT_SMALL_CAPS
Definition style.hh:333
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:219
@ BORDER_MODEL_COLLAPSE
Definition style.hh:220
Length createRelLength(double v)
Returns a relative length.
Definition style.hh:438
@ Z_INDEX_AUTO
'z-index' is stored as int; use this for the value 'auto'.
Definition style.hh:387
bool isPerLength(Length l)
Returns true if l is a percentage.
Definition style.hh:445
bool isAbsLength(Length l)
Returns true if l is an absolute length.
Definition style.hh:442
int absLengthVal(Length l)
Returns the value of a length in pixels, as an integer.
Definition style.hh:451
@ LENGTH_AUTO
Represents "auto" lengths.
Definition style.hh:494
@ WHITE_SPACE_PRE_LINE
Definition style.hh:363
@ WHITE_SPACE_PRE_WRAP
Definition style.hh:362
Dw is in this namespace, or sub namespaces of this one.
int roundInt(double d)
Definition misc.hh:62