File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ Length::Length(const std::string &s)
1010 auto unit = parser.getUnit ();
1111 if (unit == " %" )
1212 {
13- relative = parser.getValue ();
13+ relative = parser.getValue () / 100.0 ;
1414 }
1515 else if (unit == " px" || unit.empty ())
1616 {
Original file line number Diff line number Diff line change 22#define GFX_LENGTH
33
44#include < string>
5+ #include < stdexcept>
56
67#include " base/text/valueunit.h"
78
@@ -19,16 +20,24 @@ class Length
1920 static Length Absolute (double value) { return Length (value, 0 ); }
2021 static Length Relative (double value) { return Length (0 , value); }
2122
22- Length (double abs, double rel) :
23+ Length (double abs, double rel = 0.0 ) :
2324 absolute (abs), relative(rel)
2425 {}
2526
2627 explicit Length (const std::string &s);
2728
29+ bool isAbsolute () const { return relative == 0.0 ; }
30+ bool isRelative () const { return absolute == 0.0 ; }
31+
2832 double get (double reference) const {
2933 return absolute + relative * reference;
3034 }
3135
36+ double get () const {
37+ if (isAbsolute ()) return absolute;
38+ throw std::logic_error (" internal error: relative length wo. reference" );
39+ }
40+
3241 explicit operator std::string () const ;
3342
3443 bool operator ==(const Length &other) const {
You can’t perform that action at this time.
0 commit comments