Skip to content

Commit

Permalink
refactor the errorstack function in parser and lexer, and rename the …
Browse files Browse the repository at this point in the history
…HNDiv to HNDivLayout
  • Loading branch information
hsllany committed Jul 11, 2017
1 parent 8eb6cdb commit c18d066
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import android.view.ViewGroup;
import android.widget.TextView;

import com.mozz.htmlnative.view.HNDiv;
import com.mozz.htmlnative.view.HNDivLayout;

/**
* @author Yang Tao, 17/4/18.
Expand All @@ -18,44 +18,44 @@ public class TestActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HNDiv divView = new HNDiv(this);
HNDivLayout divView = new HNDivLayout(this);
divView.setPadding(10, 20, 30, 0);

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

params.positionMode = HNDiv.HNDivLayoutParams.POSITION_STATIC;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_STATIC;
divView.addView(generateView("hello world", Color.GREEN));
}

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_LEFT;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_LEFT;
divView.addView(generateView("left", Color.RED), params);
}

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_LEFT;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_LEFT;
params.setMargins(10, 20, 0, 0);
divView.addView(generateView("left2", Color.BLUE), params);
}

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
params.setMargins(10, 20, 0, 0);
divView.addView(generateView("right right right", Color.CYAN), params);
}

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
params.setMargins(10, 20, 0, 0);
divView.addView(generateView("right right rightright right rightright right " +
"rightright right rightright right rightright right rightright right " +
Expand All @@ -64,9 +64,9 @@ protected void onCreate(Bundle savedInstanceState) {
}

{
HNDiv.HNDivLayoutParams params = new HNDiv.HNDivLayoutParams(ViewGroup.LayoutParams
HNDivLayout.HNDivLayoutParams params = new HNDivLayout.HNDivLayoutParams(ViewGroup.LayoutParams
.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_LEFT;
params.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_LEFT;
params.setMargins(10, 20, 0, 0);
divView.addView(generateView("left2 left2 left2 left2 left2 left2 left2 left2 left2 "
+ "left2 left2 left2 left2 left2 left2 left2 left2 left2", Color.YELLOW),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mozz.htmlnative.view.HNDiv
<com.mozz.htmlnative.view.HNDivLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:padding="10px">

<com.mozz.htmlnative.view.HNDiv
<com.mozz.htmlnative.view.HNDivLayout
android:layout_width="match_parent"
android:layout_height="300px"
android:background="@color/colorAccent"/>
</com.mozz.htmlnative.view.HNDiv>
</com.mozz.htmlnative.view.HNDivLayout>

</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayout;
import com.mozz.htmlnative.view.HNDiv;
import com.mozz.htmlnative.view.HNDivLayout;
import com.mozz.htmlnative.view.HNImg;
import com.mozz.htmlnative.view.HNText;

Expand All @@ -37,12 +37,12 @@ public final class ViewTypeRelations {
private static Map<String, String> sExtraTagClassTable;

static {
sReservedTagClassTable.put(BOX, HNDiv.class.getName());
sReservedTagClassTable.put(LINEAR_BOX, HNDiv.class.getName());
sReservedTagClassTable.put(BOX, HNDivLayout.class.getName());
sReservedTagClassTable.put(LINEAR_BOX, HNDivLayout.class.getName());
sReservedTagClassTable.put(FLEX_BOX, FlexboxLayout.class.getName());

sReservedTagClassTable.put(HtmlTag.BODY, HNDiv.class.getName());
sReservedTagClassTable.put(HtmlTag.TEMPLATE, HNDiv.class.getName());
sReservedTagClassTable.put(HtmlTag.BODY, HNDivLayout.class.getName());
sReservedTagClassTable.put(HtmlTag.TEMPLATE, HNDivLayout.class.getName());

sReservedTagClassTable.put(HtmlTag.P, HNText.class.getName());
sReservedTagClassTable.put(HtmlTag.TEXT, HNText.class.getName());
Expand All @@ -53,7 +53,7 @@ public final class ViewTypeRelations {
sReservedTagClassTable.put(HtmlTag.IFRAME, WebView.class.getName());
sReservedTagClassTable.put(HtmlTag.WEB, WebView.class.getName());
sReservedTagClassTable.put(HtmlTag.A, HNText.class.getName());
sReservedTagClassTable.put(HtmlTag.SPAN, HNDiv.class.getName());
sReservedTagClassTable.put(HtmlTag.SPAN, HNDivLayout.class.getName());
sReservedTagClassTable.put(HtmlTag.H1, HNText.class.getName());
sReservedTagClassTable.put(HtmlTag.H2, HNText.class.getName());
sReservedTagClassTable.put(HtmlTag.H3, HNText.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.mozz.htmlnative.utils.ParametersUtils;
import com.mozz.htmlnative.utils.ResourceUtils;
import com.mozz.htmlnative.view.BackgroundViewDelegate;
import com.mozz.htmlnative.view.HNDiv;
import com.mozz.htmlnative.view.HNDivLayout;
import com.mozz.htmlnative.view.IBackgroundView;
import com.mozz.htmlnative.view.LayoutParamsCreator;

Expand Down Expand Up @@ -375,10 +375,10 @@ public void onClick(View v) {
case ATTR_FLOAT: {
switch (style.toString()) {
case "left":
layoutCreator.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_LEFT;
layoutCreator.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_LEFT;
break;
case "right":
layoutCreator.positionMode = HNDiv.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
layoutCreator.positionMode = HNDivLayout.HNDivLayoutParams.POSITION_FLOAT_RIGHT;
break;
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import com.mozz.htmlnative.css.InheritStylesRegistry;
import com.mozz.htmlnative.dom.DomElement;
import com.mozz.htmlnative.exception.AttrApplyException;
import com.mozz.htmlnative.view.HNDiv;
import com.mozz.htmlnative.view.HNDivLayout;
import com.mozz.htmlnative.view.LayoutParamsCreator;

class HtmlLayoutStyleHandler extends StyleHandler {
class DivLayoutStyleHandler extends StyleHandler {
@Override
public void apply(Context context, View v, DomElement domElement, View parent,
LayoutParamsCreator paramsCreator, String params, Object value)
throws AttrApplyException {

if (InheritStylesRegistry.isInherit(params)) {
HNDiv div = (HNDiv) v;
HNDivLayout div = (HNDivLayout) v;
div.saveInheritStyles(params, value);
}
}
Expand All @@ -38,6 +38,6 @@ public void setDefault(Context context, View v, DomElement domElement,

@Override
public Object getStyle(View v, String styleName) {
return ((HNDiv) v).getInheritStyle(styleName);
return ((HNDivLayout) v).getInheritStyle(styleName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
import android.view.ViewGroup;
import android.view.ViewParent;
import android.webkit.WebView;
import android.widget.AbsoluteLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.android.flexbox.FlexboxLayout;
import com.mozz.htmlnative.view.HNDiv;
import com.mozz.htmlnative.view.HNDivLayout;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -24,10 +23,9 @@ public final class StyleHandlerFactory {

private static TextViewStyleHandler sText = new TextViewStyleHandler();
private static ImageViewStyleHandler sImage = new ImageViewStyleHandler();
private static HtmlLayoutStyleHandler sLinear = new HtmlLayoutStyleHandler();
private static DivLayoutStyleHandler sDiv = new DivLayoutStyleHandler();
private static FlexBoxLayoutStyleHandler sFlex = new FlexBoxLayoutStyleHandler();
private static WebViewStyleHandler sWebview = new WebViewStyleHandler();
private static AbsoluteStyleHandler sAbsolute = new AbsoluteStyleHandler();
@NonNull
private static Map<Class<? extends View>, StyleHandler> sAttrHandlerCache = new HashMap<>();
private static Map<Class<? extends View>, StyleHandler> sExtraAttrHandlerCache = new
Expand All @@ -44,14 +42,12 @@ public static StyleHandler byClass(@NonNull Class<? extends View> clazz) {
return sText;
} else if (ImageView.class.isAssignableFrom(clazz)) {
return sImage;
} else if (clazz.equals(HNDiv.class)) {
return sLinear;
} else if (clazz.equals(HNDivLayout.class)) {
return sDiv;
} else if (clazz.equals(FlexboxLayout.class)) {
return sFlex;
} else if (clazz.equals(WebView.class)) {
return sWebview;
} else if (clazz.equals(AbsoluteLayout.class)) {
return sAbsolute;
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public final class CssParser implements SyntaxExceptionSource {
private static final int CHAIN_CHILD = 0x02;
private static final int CHAIN_GROUP = 0x03;

private long mMarkedLine = -1;
private long mMarkedColumn = -1;


@Nullable
private Token mCurToken;
Expand Down Expand Up @@ -347,7 +350,7 @@ void process(HNSegment segment) throws EOFException, HNSyntaxError {
// if parse process didn't end, then there is a syntax error.
default:
mSyntaxErrorHandler.throwException("unknown token " + mCurToken.toString() +
" when " + "parsing css", mCurToken.getLine(), mCurToken.getColumn());
" when " + "parsing css");
}
}
}
Expand All @@ -367,19 +370,30 @@ private void scan() throws EOFException, HNSyntaxError {
}
mCurToken = lexer.scan();

if (mCurToken != null) {
mark(mCurToken.getLine(), mCurToken.getColumn());
} else {
mark(-1, -1);
}

HNLog.d(HNLog.CSS_PARSER, "StyleSheet -> next is " + mCurToken.toString());
}

private void mark(long line, long column) {
mMarkedColumn = column;
mMarkedLine = line;
}

private boolean shouldScanValue = false;

@Override
public long getLine() {
return lexer.getLine();
return mMarkedLine;
}

@Override
public long getColumn() {
return lexer.getColumn();
return mMarkedColumn;
}

@Override
Expand Down
Loading

0 comments on commit c18d066

Please sign in to comment.