Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Merge 0ac85cc into ed04a17
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazhafiz committed Jan 3, 2019
2 parents ed04a17 + 0ac85cc commit c9b0afc
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 36 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Expand Up @@ -11,7 +11,11 @@ CMakeCache.txt
Makefile

.idea/
.vs/
bin/
cmake-build-debug/
cmake-build-coverage/
CMakeFiles/
Debug/
gtest.dir/
x64/
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -10,6 +10,7 @@
# `sherpa_41` :mountain:

[![Build Status](https://travis-ci.com/ayazhafiz/sherpa_41.svg?branch=master)](https://travis-ci.com/ayazhafiz/sherpa_41)
[![Build status](https://ci.appveyor.com/api/projects/status/kr7k3fc7o1iwpc97/branch/master?svg=true)](https://ci.appveyor.com/project/ayazhafiz/sherpa-41/branch/master)
[![Coverage Status](https://coveralls.io/repos/github/ayazhafiz/sherpa_41/badge.svg?branch=master)](https://coveralls.io/github/ayazhafiz/sherpa_41?branch=master)

`sherpa_41` is a toy browser engine, based somewhat on [Limpet's _Let's build a browser engine!_](https://limpet.net/mbrubeck/2014/08/08/toy-layout-engine-1.html)
Expand Down
23 changes: 13 additions & 10 deletions appveyor.yml
@@ -1,23 +1,26 @@
version: '{build}'

image: Visual Studio 2017

platform:
- x64
- x86
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
platform: x86
FLAGS: "/std:c++17"
GENERATOR: Visual Studio 15 2017

configuration:
- Debug
- Release
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
platform: x64
FLAGS: "/std:c++17"
GENERATOR: Visual Studio 15 2017

install:
- git submodule update --init --recursive

before_build:
- cmake -DEXECUTABLE="OFF" -DCMAKE_CXX_FLAGS="/std:c++17" -G "Visual Studio 15 2017 Win64" .
- cmake -DEXECUTABLE="OFF" -DCMAKE_CXX_FLAGS="%FLAGS%" -G "%GENERATOR%" .

build:
project: $(APPVEYOR_BUILD_FOLDER)\$(APPVEYOR_PROJECT_NAME).sln
build_script:
- cmake --build . --config Debug

test_script:
- '%APPVEYOR_BUILD_FOLDER%\%CONFIGURATION%\sherpa_41-test.exe'
18 changes: 15 additions & 3 deletions include/css.hpp
Expand Up @@ -103,7 +103,11 @@ struct TextValue : public Value {
*/
explicit TextValue(std::string value);

TextValue(const TextValue & rhs) = default;
/**
* Copy ctor
* @param rhs TextValue to copy
*/
TextValue(const TextValue & rhs);

/**
* Clones a TextValue
Expand Down Expand Up @@ -137,7 +141,11 @@ struct UnitValue : public Value {
*/
UnitValue(double value, Unit unit);

UnitValue(const UnitValue & rhs) = default;
/**
* Copy ctor
* @param rhs UnitValue to copy
*/
UnitValue(const UnitValue & rhs);

/**
* Clones a UnitValue
Expand Down Expand Up @@ -172,7 +180,11 @@ struct ColorValue : public Value {
*/
ColorValue(uint8_t r, uint8_t g, uint8_t b, double a);

ColorValue(const ColorValue & rhs) = default;
/**
* Copy ctor
* @param rhs ColorValue to copy
*/
ColorValue(const ColorValue & rhs);

/**
* Clones a ColorValue
Expand Down
6 changes: 3 additions & 3 deletions include/display.hpp
Expand Up @@ -83,9 +83,9 @@ class Command {
* @return color value, or nullptr if it does not exist
*/
template <typename... Args>
static CSS::ColorValue * getColor(const Layout::BoxPtr & box,
const std::string & style,
const Args &... backup);
static CSS::ValuePtr getColor(const Layout::BoxPtr & box,
const std::string & style,
const Args &... backup);
};

/**
Expand Down
25 changes: 24 additions & 1 deletion src/css.cpp
Expand Up @@ -15,7 +15,7 @@
*/
std::string CSS::normalizeFp(double value) {
auto val = std::to_string(value);
uint64_t offset = 1;
uint32_t offset = 1;
if (val.find_last_not_of('0') == val.find('.')) {
offset = 0;
}
Expand Down Expand Up @@ -59,6 +59,13 @@ double CSS::Value::unitValue() const {
CSS::TextValue::TextValue(std::string value) : value(std::move(value)) {
}

/**
* Copy ctor
* @param rhs TextValue to copy
*/
CSS::TextValue::TextValue(const TextValue & rhs) : value(rhs.value) {
}

/**
* Clones a TextValue
* @return cloned value
Expand Down Expand Up @@ -92,6 +99,14 @@ CSS::UnitValue::UnitValue(double value, CSS::Unit unit)
: value(value), unit(unit) {
}

/**
* Copy ctor
* @param rhs UnitValue to copy
*/
CSS::UnitValue::UnitValue(const UnitValue & rhs)
: value(rhs.value), unit(rhs.unit) {
}

/**
* Clones a UnitValue
* @return cloned value
Expand Down Expand Up @@ -119,6 +134,14 @@ CSS::ColorValue::ColorValue(uint8_t r, uint8_t g, uint8_t b, double a)
: r(r), g(g), b(b), a(a) {
}

/**
* Copy ctor
* @param rhs ColorValue to copy
*/
CSS::ColorValue::ColorValue(const ColorValue & rhs)
: r(rhs.r), g(rhs.g), b(rhs.b), a(rhs.a) {
}

/**
* Clones a ColorValue
* @return cloned value
Expand Down
31 changes: 16 additions & 15 deletions src/display.cpp
Expand Up @@ -49,21 +49,21 @@ void Display::Command::renderBox(const Layout::BoxPtr & box,
*/
void Display::Command::renderBackground(const Layout::BoxPtr & box,
Display::CommandQueue & queue) {
auto colorPtr = getColor(box, "background-color", "background");
// only render box if it actually has a background
if (auto color = getColor(box, "background-color", "background")) {
if (auto color = dynamic_cast<CSS::ColorValue *>(colorPtr.get())) {
// create rectangle of padding area and background color
queue.push(CommandPtr(
new RectangleCmd(box->getDimensions().paddingArea(), *color)));
queue.push(
CommandPtr(new RectangleCmd(box->getDimensions().paddingArea(),
CSS::ColorValue(*color))));
}
}

void Display::Command::renderBorders(const Layout::BoxPtr & box,
Display::CommandQueue & queue) {
// use background if no explicit border color provided
auto color = getColor(box,
"border-color",
"background-color",
"background");
auto colorPtr = getColor(box, "background-color", "background");
auto color = dynamic_cast<CSS::ColorValue *>(colorPtr.get());
if (color == nullptr) {
return; // nothing to render if no border color
}
Expand All @@ -77,7 +77,7 @@ void Display::Command::renderBorders(const Layout::BoxPtr & box,
borderArea.origin.y,
borderArea.width,
dims.border.top),
*color)));
CSS::ColorValue(*color))));
// right border
queue.push(
CommandPtr(new RectangleCmd(Layout::Rectangle(borderArea.origin.x +
Expand All @@ -86,7 +86,7 @@ void Display::Command::renderBorders(const Layout::BoxPtr & box,
borderArea.origin.y,
dims.border.right,
borderArea.height),
*color)));
CSS::ColorValue(*color))));
// bottom border
queue.push(
CommandPtr(new RectangleCmd(Layout::Rectangle(borderArea.origin.x,
Expand All @@ -95,14 +95,14 @@ void Display::Command::renderBorders(const Layout::BoxPtr & box,
dims.border.bottom,
borderArea.width,
dims.border.bottom),
*color)));
CSS::ColorValue(*color))));
// left border
queue.push(
CommandPtr(new RectangleCmd(Layout::Rectangle(borderArea.origin.x,
borderArea.origin.y,
dims.border.left,
borderArea.height),
*color)));
CSS::ColorValue(*color))));
}

/**
Expand All @@ -115,12 +115,13 @@ void Display::Command::renderBorders(const Layout::BoxPtr & box,
* @return color value, or nullptr if it does not exist
*/
template <typename... Args>
CSS::ColorValue * Display::Command::getColor(const Layout::BoxPtr & box,
const std::string & style,
const Args &... backup) {
CSS::ValuePtr Display::Command::getColor(const Layout::BoxPtr & box,
const std::string & style,
const Args &... backup) {
if (auto sBox = dynamic_cast<Layout::StyledBox *>(box.get())) {
auto bg = sBox->getContent().value(style, backup...);
return dynamic_cast<CSS::ColorValue *>(bg.get());
return bg->clone();
// return dynamic_cast<CSS::ColorValue *>(bg.get());
}
return nullptr;
}
Expand Down
4 changes: 2 additions & 2 deletions src/layout.cpp
Expand Up @@ -396,8 +396,8 @@ void Layout::StyledBox::setPosition(const Layout::BoxDimensions & container) {
* explicit height is given
*/
void Layout::StyledBox::setHeight() {
if (auto height = dynamic_cast<CSS::UnitValue *>(
content.value("height").get())) {
auto heightPtr = content.value("height");
if (auto height = dynamic_cast<CSS::UnitValue *>(heightPtr.get())) {
dimensions.height = height->value;
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/parser/css.cpp
Expand Up @@ -120,8 +120,9 @@ CSS::ValuePtr CSSParser::parseValue() {
auto notFloat = std::not_fn(cisfloat);

if (peek(cisfloat)) {
return CSS::ValuePtr(
new CSS::UnitValue(std::stod(build_until(notFloat)), parseUnit()));
auto val = std::stod(build_until(notFloat));
auto unit = parseUnit();
return CSS::ValuePtr(new CSS::UnitValue(val, unit));
} else if (peek("rgb")) {
return parseRGB();
} else if (peek("#")) {
Expand Down

0 comments on commit c9b0afc

Please sign in to comment.