Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RealHtml: introduce RealHtmlHideHorizontalScroll style #533

Merged
merged 1 commit into from Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/fform/renderfform.flow
Expand Up @@ -1112,8 +1112,9 @@ renderFForm(rform : FForm, zorder : Transform<[int]>) -> FRenderResult {
onError = extractStruct(style, OnError(nop1)).fn;
onDone = \s -> if (s == "OK") onPageLoaded() else onError(s);
shrink2fit = containsStruct(style, RealHtmlShrink2Fit());
hideHorizontalScroll = containsStruct(style, RealHtmlHideHorizontalScroll());

clip = makeWebClip(url, domain, updateCachedContent, reloadBlock, flowCallback, onDone, shrink2fit);
clip = makeWebClip(url, domain, updateCachedContent, reloadBlock, flowCallback, onDone, shrink2fit, hideHorizontalScroll);

disp =
fold(
Expand Down
4 changes: 3 additions & 1 deletion lib/fform/sfform.flow
Expand Up @@ -59,7 +59,7 @@ export {

SFRealHTML(url : string, wh : WidthHeight, style : [SFRealHTMLStyle]);
SFRealHTMLStyle ::= UpdateCachedContent, OverridePageDomain, SZoomEnabled, ReloadBlock, SMouseDisabled, SandBoxJS, RealHtmlShrink2Fit,
WhitelistDomains, SViewBounds;
WhitelistDomains, SViewBounds, RealHtmlHideHorizontalScroll;

SZoomEnabled(enabled : bool);
SMouseDisabled(disabled : bool);
Expand Down Expand Up @@ -262,6 +262,7 @@ RealHTMLStyle2SFRealHTMLStyle(style : [RealHTMLStyle]) -> [SFRealHTMLStyle] {
ReloadBlock(__) : Some(s);
WhitelistDomains(__) : Some(s);
ViewBounds(bounds) : Some(SViewBounds(fgetValue(bounds)));
RealHtmlHideHorizontalScroll(): Some(s);
}
)
}
Expand Down Expand Up @@ -417,6 +418,7 @@ SFRealHTMLStyle2RealHTMLStyle(style : [SFRealHTMLStyle]) -> [RealHTMLStyle] {
ReloadBlock(__) : s;
WhitelistDomains(__) : s;
SViewBounds(bounds) : ViewBounds(const(bounds));
RealHtmlHideHorizontalScroll(): s;
}
)
}
Expand Down
5 changes: 4 additions & 1 deletion lib/form/form.flow
Expand Up @@ -96,7 +96,8 @@ Camera : (filename : string, parameters : [RecordParameter], listeners: [RecordS
RealHTML2 : (url : string, wh : Behaviour<WidthHeight>, style : [RealHTMLStyle]);

RealHTMLStyle ::= UpdateCachedContent, OverridePageDomain, FlowCallback, PageHostcallSetter,
OnError, OnPageLoaded, ZoomEnabled, ReloadBlock, PageEvalJS, MouseDisabled, SandBoxJS, RealHtmlShrink2Fit, WhitelistDomains, ViewBounds;
OnError, OnPageLoaded, ZoomEnabled, ReloadBlock, PageEvalJS, MouseDisabled, SandBoxJS,
RealHtmlShrink2Fit, WhitelistDomains, ViewBounds, RealHtmlHideHorizontalScroll;

// UpdateCachedContent - download the latest version of resources when online. true by default.
// When false WebView shows cached version even online.
Expand All @@ -119,6 +120,8 @@ RealHTMLStyle ::= UpdateCachedContent, OverridePageDomain, FlowCallback, PageHos
RealHtmlShrink2Fit();
// list of trusted domains to open inside RealHTML on mobiles
WhitelistDomains : (domains : [string]);
// hide horizontal scroll in resulting iframe
RealHtmlHideHorizontalScroll();

ViewBounds(bounds : Transform<Bounds>);

Expand Down
4 changes: 3 additions & 1 deletion lib/form/renderform.flow
Expand Up @@ -1691,6 +1691,7 @@ renderForm(rform : Form, available : Behaviour<WidthHeight>, zorder : [int], tab
whitelist_domains = ref [];
shrink2fit = ref false;
viewBounds = ref None();
hideHorizontalScroll = ref false;

iter(style, \s -> {
switch (s : RealHTMLStyle) {
Expand All @@ -1716,14 +1717,15 @@ renderForm(rform : Form, available : Behaviour<WidthHeight>, zorder : [int], tab
);
WhitelistDomains(domains) : whitelist_domains := domains;
RealHtmlShrink2Fit(): shrink2fit := true;
RealHtmlHideHorizontalScroll(): hideHorizontalScroll := true;
ViewBounds(bounds): viewBounds := Some(bounds);
}
});

callback = \args : [string] -> ^flow_callback(args);
ondone = \s : string -> if (s == "OK") ^on_page_loaded() else ^on_error(s);

bridge_clip = makeWebClip(url, ^domain, !^update_cached_content, ^reload_block, callback, ondone, ^shrink2fit);
bridge_clip = makeWebClip(url, ^domain, !^update_cached_content, ^reload_block, callback, ondone, ^shrink2fit, ^hideHorizontalScroll);

switch (^sandbox : Maybe) {
Some(sb) : setWebClipSandBox(bridge_clip, sb);
Expand Down
2 changes: 1 addition & 1 deletion lib/rendersupport.flow
Expand Up @@ -152,7 +152,7 @@ export {
native setMaxChars : io (native, int) -> void = RenderSupport.setMaxChars;
native setCursor : io (string) -> void = RenderSupport.setCursor;
native getCursor : io () -> string = RenderSupport.getCursor;
native makeWebClip : (string, string, bool, bool, ([string]) -> string, (string) -> void, bool)-> native = RenderSupport.makeWebClip;
native makeWebClip : (string, string, bool, bool, ([string]) -> string, (string) -> void, bool, bool)-> native = RenderSupport.makeWebClip;
native setWebClipSandBox : (native, string) -> void = RenderSupport.setWebClipSandBox;
native setWebClipDisabled : (native, bool) -> void = RenderSupport.setWebClipDisabled;
native webClipHostCall : (native, string, [string]) -> string = RenderSupport.webClipHostCall;
Expand Down
2 changes: 1 addition & 1 deletion platforms/java/com/area9innovation/flow/RenderSupport.java
Expand Up @@ -42,7 +42,7 @@ public Object makeGraphics() {
public Object currentClip() {
return null;
}
public Object makeWebClip(String url,String domain,Boolean useCache, Boolean reloadBlock, Func1<String,Object[]> cb, Func1<Object,String> ondone, Boolean shrinkToFit) {
public Object makeWebClip(String url,String domain,Boolean useCache, Boolean reloadBlock, Func1<String,Object[]> cb, Func1<Object,String> ondone, Boolean shrinkToFit, Boolean hideHorizontalScroll) {
return null;
}
public String webClipHostCall(Object clip,String fn,Object[] args) {
Expand Down
Expand Up @@ -440,7 +440,7 @@ public Object currentClip() {
return stage_clip;
}
@Override
public Object makeWebClip(String url,String domain,Boolean useCache, Boolean reloadBlock, Func1<String,Object[]> cb, Func1<Object,String> ondone, Boolean shrinkToFit) {
public Object makeWebClip(String url,String domain,Boolean useCache, Boolean reloadBlock, Func1<String,Object[]> cb, Func1<Object,String> ondone, Boolean shrinkToFit, Boolean hideHorizontalScroll) {
System.out.println("makeWebClip not implemented");
return new Clip();
}
Expand Down
4 changes: 2 additions & 2 deletions platforms/js/RenderSupport.hx
Expand Up @@ -2781,8 +2781,8 @@ class RenderSupport {
// cb - callback in the flow code which accepts [flow]
// To call it in the embedded HTML use frameElement.callflow([args]))
// Default web clip size = 100x100. Scale clip to resize
public static function makeWebClip(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool) : WebClip {
return new WebClip(url, domain, useCache, reloadBlock, cb, ondone, shrinkToFit);
public static function makeWebClip(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool, hideHorizontalScroll : Bool) : WebClip {
return new WebClip(url, domain, useCache, reloadBlock, cb, ondone, shrinkToFit, hideHorizontalScroll);
}

public static function webClipHostCall(clip : WebClip, name : String, args : Array<String>) : String {
Expand Down
2 changes: 1 addition & 1 deletion platforms/js/RenderSupportNodeJs.hx
Expand Up @@ -159,7 +159,7 @@ class RenderSupport {
return null;
}

public static function makeWebClip(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool) : Dynamic {
public static function makeWebClip(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool, hideHorizontalScroll : Bool) : Dynamic {
return null;
}

Expand Down
8 changes: 7 additions & 1 deletion platforms/js/WebClip.hx
Expand Up @@ -8,6 +8,7 @@ class WebClip extends NativeWidgetClip {
private var htmlPageWidth : Dynamic = null;
private var htmlPageHeight : Dynamic = null;
private var shrinkToFit : Dynamic = null;
private var hideHorizontalScroll : Dynamic = null;

private static function isUrl(str) : Bool {
return ~/^(\S+[.?][^\/\s]+(\/\S+|\/|))$/g.match(str);
Expand Down Expand Up @@ -46,7 +47,7 @@ class WebClip extends NativeWidgetClip {
nativeWidget.appendChild(div);
}

public function new(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool) {
public function new(url : String, domain : String, useCache : Bool, reloadBlock : Bool, cb : Array<String> -> String, ondone : String -> Void, shrinkToFit : Bool, hideHorizontalScroll : Bool) {
super();

if (domain != "") {
Expand All @@ -63,6 +64,7 @@ class WebClip extends NativeWidgetClip {
}

this.shrinkToFit = shrinkToFit;
this.hideHorizontalScroll = hideHorizontalScroll;

iframe = Browser.document.createElement("iframe");
iframe.style.visibility = "hidden";
Expand Down Expand Up @@ -99,6 +101,10 @@ class WebClip extends NativeWidgetClip {
}
}

if (hideHorizontalScroll) {
untyped iframeDocument.body.style["overflow-x"] = "hidden";
}

if (shrinkToFit) {
try {
this.htmlPageWidth = iframeDocument.body.scrollWidth;
Expand Down
10 changes: 5 additions & 5 deletions tools/flowc/backends/cpp/flow_rendersupport.hpp
Expand Up @@ -83,8 +83,8 @@ void setSelection(const native& , const int start, const int end) { FLOW_ABORT }
void setTabIndex(const native& , const int ) { FLOW_ABORT }
void setTextDirection(const native& clip, const flow::string& direction) { FLOW_ABORT }
void setTextAndStyle(const native& textfield, const flow::string& text, const flow::string& fontfamily, const double fontsize,
const int fontweight, const flow::string& fontslope,
const int fillcolour, const double fillopacity, const int letterspacing,
const int fontweight, const flow::string& fontslope,
const int fillcolour, const double fillopacity, const int letterspacing,
const int backgroundcolour, const double backgroundopacity, const bool forTextinput) { FLOW_ABORT }
void setTextFieldHeight(const native& clip, const double width) { FLOW_ABORT }
void setTextFieldWidth(const native& clip, const double width) { FLOW_ABORT }
Expand All @@ -93,8 +93,8 @@ void setTextInput(const native& ) { FLOW_ABORT }
struct PlayerControl;
void setVideoControls(const native& clip, const flow::array<PlayerControl>& ctl) { FLOW_ABORT }
void setVideoLooping(const native& clip, const bool looping) { FLOW_ABORT }
void setVideoSubtitle(const native& clip, const flow::string& text, const flow::string& fontfamily, const double fontsize,
const int fontweight, const flow::string& fontslope,
void setVideoSubtitle(const native& clip, const flow::string& text, const flow::string& fontfamily, const double fontsize,
const int fontweight, const flow::string& fontslope,
const int fillcolour, const double fillopacity, const int letterspacing, const int backgroundcolour, const double backgroundopacity) { FLOW_ABORT }
void setVideoVolume(const native& clip, const double volume) { FLOW_ABORT }
void setWebClipDisabled(const native& , const bool ) { FLOW_ABORT }
Expand All @@ -107,7 +107,7 @@ void timer(const int , const std::function<void()>& ) { FLOW_ABORT }
void toggleFullWindow(const bool fs) { FLOW_ABORT }

void impersonateCallstackItem(const native& item, const int flags) { /*FLOW_ABORT*/ }
native makeWebClip(const flow::string&, const flow::string&, const bool, const bool, const std::function<flow_t(flow::array<flow_t>)>&, const std::function<void(flow::string)>&, const bool) { FLOW_ABORT }
native makeWebClip(const flow::string&, const flow::string&, const bool, const bool, const std::function<flow_t(flow::array<flow_t>)>&, const std::function<void(flow::string)>&, const bool, const bool) { FLOW_ABORT }
void setAccessAttributes(const native& clip, const flow::array<flow::array<flow_t>>& properties) { FLOW_ABORT }
flow_t webClipEvalJS(const native& , const flow::string& ) { FLOW_ABORT }
flow_t webClipHostCall(const native& , const flow::string& , const flow::array<flow_t>& ) { FLOW_ABORT }
Expand Down