Commit c4d3fb72 authored by Neil Fraser's avatar Neil Fraser

Make scrolling margins be more accurate (issue 82).

parent da122e2a
......@@ -1324,8 +1324,8 @@ b=0;b<e.length;b++)for(var c=e[b];c;)setTimeout(c.setCollapsed.bind(c,!1),a),c=c
Blockly.removeAllRanges=function(){getSelection()&&setTimeout(function(){try{getSelection().removeAllRanges()}catch(a){}},0)};Blockly.isTargetInput_=function(a){return"textarea"==a.target.type||"text"==a.target.type||"number"==a.target.type||"email"==a.target.type||"password"==a.target.type||"search"==a.target.type||"tel"==a.target.type||"url"==a.target.type};
Blockly.loadAudio_=function(a,b){if(window.Audio&&a.length){for(var c,d=new window.Audio,e=0;e<a.length;e++){var f=a[e],g=f.match(/\.(\w+)$/);if(g&&d.canPlayType("audio/"+g[1])){c=new window.Audio(f);break}}c&&c.play&&(Blockly.SOUNDS_[b]=c)}};Blockly.preloadAudio_=function(){for(var a in Blockly.SOUNDS_){var b=Blockly.SOUNDS_[a];b.volume=.01;b.play();b.pause();if(goog.userAgent.IPAD||goog.userAgent.IPHONE)break}};
Blockly.playAudio=function(a,b){var c=Blockly.SOUNDS_[a];c&&(c=goog.userAgent.DOCUMENT_MODE&&9===goog.userAgent.DOCUMENT_MODE||goog.userAgent.IPAD||goog.userAgent.ANDROID?c:c.cloneNode(),c.volume=void 0===b?1:b,c.play())};
Blockly.getMainWorkspaceMetrics_=function(){var a=Blockly.svgSize();Blockly.mainWorkspace.toolbox_&&(a.width-=Blockly.mainWorkspace.toolbox_.width);var b=a.width-Blockly.Scrollbar.scrollbarThickness,c=a.height-Blockly.Scrollbar.scrollbarThickness;try{var d=Blockly.mainWorkspace.getCanvas().getBBox()}catch(e){return null}if(Blockly.mainWorkspace.scrollbar)var f=Math.min(d.x-b/2,d.x+d.width-b),b=Math.max(d.x+d.width+b/2,d.x+b),g=Math.min(d.y-c/2,d.y+d.height-c),c=Math.max(d.y+d.height+c/2,d.y+c);else f=
d.x,b=f+d.width,g=d.y,c=g+d.height;d=0;!Blockly.RTL&&Blockly.mainWorkspace.toolbox_&&(d=Blockly.mainWorkspace.toolbox_.width);return{viewHeight:a.height,viewWidth:a.width,contentHeight:c-g,contentWidth:b-f,viewTop:-Blockly.mainWorkspace.scrollY,viewLeft:-Blockly.mainWorkspace.scrollX,contentTop:g,contentLeft:f,absoluteTop:0,absoluteLeft:d}};
Blockly.getMainWorkspaceMetrics_=function(){var a=Blockly.svgSize();Blockly.mainWorkspace.toolbox_&&(a.width-=Blockly.mainWorkspace.toolbox_.width);var b=a.width-Blockly.Scrollbar.scrollbarThickness,c=a.height-Blockly.Scrollbar.scrollbarThickness;try{var d=Blockly.mainWorkspace.getCanvas().getBBox()}catch(e){return null}if(Blockly.mainWorkspace.scrollbar)var f=Blockly.RTL?0:Blockly.Scrollbar.scrollbarThickness,g=Math.min(d.x-b/2,d.x+d.width-b-(Blockly.RTL?Blockly.Scrollbar.scrollbarThickness:0)+5),
b=Math.max(d.x+d.width+b/2,d.x+b+f-5),f=Math.min(d.y-c/2,d.y+d.height-c+5),c=Math.max(d.y+d.height+c/2,d.y+c+Blockly.Scrollbar.scrollbarThickness-5);else g=d.x,b=g+d.width,f=d.y,c=f+d.height;d=0;!Blockly.RTL&&Blockly.mainWorkspace.toolbox_&&(d=Blockly.mainWorkspace.toolbox_.width);return{viewHeight:a.height,viewWidth:a.width,contentHeight:c-f,contentWidth:b-g,viewTop:-Blockly.mainWorkspace.scrollY,viewLeft:-Blockly.mainWorkspace.scrollX,contentTop:f,contentLeft:g,absoluteTop:0,absoluteLeft:d}};
Blockly.setMainWorkspaceMetrics_=function(a){if(!Blockly.mainWorkspace.scrollbar)throw"Attempt to set main workspace scroll without scrollbars.";var b=Blockly.getMainWorkspaceMetrics_();goog.isNumber(a.x)&&(Blockly.mainWorkspace.scrollX=-b.contentWidth*a.x-b.contentLeft);goog.isNumber(a.y)&&(Blockly.mainWorkspace.scrollY=-b.contentHeight*a.y-b.contentTop);a=Blockly.mainWorkspace.scrollX+b.absoluteLeft;b=Blockly.mainWorkspace.scrollY+b.absoluteTop;Blockly.mainWorkspace.translate(a,b);Blockly.mainWorkspacePattern_.setAttribute("x",
a);Blockly.mainWorkspacePattern_.setAttribute("y",b)};Blockly.doCommand=function(a){Blockly.Realtime.isEnabled?Blockly.Realtime.doCommand(a):a()};Blockly.addChangeListener=function(a){return Blockly.bindEvent_(Blockly.mainWorkspace.getCanvas(),"blocklyWorkspaceChange",null,a)};Blockly.removeChangeListener=function(a){Blockly.unbindEvent_(a)};Blockly.getMainWorkspace=function(){return Blockly.mainWorkspace};goog.global.Blockly||(goog.global.Blockly={});goog.global.Blockly.getMainWorkspace=Blockly.getMainWorkspace;
goog.global.Blockly.addChangeListener=Blockly.addChangeListener;goog.global.Blockly.removeChangeListener=Blockly.removeChangeListener;
\ No newline at end of file
......@@ -714,14 +714,18 @@ Blockly.getMainWorkspaceMetrics_ = function() {
if (Blockly.mainWorkspace.scrollbar) {
// Add a border around the content that is at least half a screenful wide.
// Ensure border is wide enough that blocks can scroll over entire screen.
var MARGIN = 5;
var leftScroll = Blockly.RTL ? Blockly.Scrollbar.scrollbarThickness : 0;
var rightScroll = Blockly.RTL ? 0 : Blockly.Scrollbar.scrollbarThickness;
var leftEdge = Math.min(blockBox.x - viewWidth / 2,
blockBox.x + blockBox.width - viewWidth);
blockBox.x + blockBox.width - viewWidth - leftScroll + MARGIN);
var rightEdge = Math.max(blockBox.x + blockBox.width + viewWidth / 2,
blockBox.x + viewWidth);
blockBox.x + viewWidth + rightScroll - MARGIN);
var topEdge = Math.min(blockBox.y - viewHeight / 2,
blockBox.y + blockBox.height - viewHeight);
blockBox.y + blockBox.height - viewHeight + MARGIN);
var bottomEdge = Math.max(blockBox.y + blockBox.height + viewHeight / 2,
blockBox.y + viewHeight);
blockBox.y + viewHeight + Blockly.Scrollbar.scrollbarThickness -
MARGIN);
} else {
var leftEdge = blockBox.x;
var rightEdge = leftEdge + blockBox.width;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment