functioncreateCORSRequest(method, url) { var xhr = newXMLHttpRequest(); if ("withCredentials"in xhr) {
// Check if the XMLHttpRequest object has a "withCredentials" property. // "withCredentials" only exists on XMLHTTPRequest2 objects. xhr.open(method, url, true);
} elseif (typeofXDomainRequest != "undefined") {
// Otherwise, check if XDomainRequest. // XDomainRequest only exists in IE, and is IE's way of making CORS requests. xhr = newXDomainRequest(); xhr.open(method, url);
} else {
// Otherwise, CORS is not supported by the browser. xhr = null;
} return xhr; }
var xhr = createCORSRequest('GET', url); if (!xhr) { thrownewError('CORS not supported'); }
// Create the XHR object. functioncreateCORSRequest(method, url) { var xhr = newXMLHttpRequest(); if ("withCredentials"in xhr) { // XHR for Chrome/Firefox/Opera/Safari. xhr.open(method, url, true); } elseif (typeofXDomainRequest != "undefined") { // XDomainRequest for IE. xhr = newXDomainRequest(); xhr.open(method, url); } else { // CORS not supported. xhr = null; } return xhr; }
// Helper method to parse the title tag from the response. functiongetTitle(text) { return text.match('<title>(.*)?</title>')[1]; }
// Make the actual CORS request. functionmakeCorsRequest() { // This is a sample server that supports CORS. var url = 'http://html5rocks-cors.s3-website-us-east-1.amazonaws.com/index.html';
var xhr = createCORSRequest('GET', url); if (!xhr) { alert('CORS not supported'); return; }
// Response handlers. xhr.onload = function() { var text = xhr.responseText; var title = getTitle(text); alert('Response from CORS request to ' + url + ': ' + title); };
xhr.onerror = function() { alert('Woops, there was an error making the request.'); };
fix($compile): [BREAKING_CHANGE] couple of unit tests for IE9 Older IEs serialize html uppercased, but IE9 does not... Would be better to expect case insensitive, unfortunately jasmine does not allow to user regexps for throw expectations. Document change on eggjs/egg#123 Closes #392 BREAKING CHANGE: Breaks foo.bar api, foo.baz should be used instead
在绘制阶段,系统会遍历呈现树,并调用呈现器的paint方法,将呈现器的内容显示在屏幕上。和布局一样,绘制也分为全局(绘制整个呈现树)和增量两种。在增量绘制中,部分呈现器发生了更改,但是不会影响整个树。更改后的呈现器将其在屏幕上对应的矩形区域设为无效,这导致 OS 将其视为一块“dirty 区域”,并生成“paint”事件。OS会很巧妙地将多个区域合并成一个。
事情到了HTML这里变得麻烦了些。首先,HTML解析器的任务是将HTML标记解析成解析树。HTML词汇和语法在W3C的规范(目前版本是HTML5)中有着定义。但是HTML并不能很容易地用解析器所需的与上下文无关的语法来定义。HTML的正规格式DTD(Document Type Definition)并不是一种上下文无关的语法。
switch (style->display()) { case NONE: break; case INLINE: o = new (arena) RenderInline(node); break; case BLOCK: o = new (arena) RenderBlock(node); break; case INLINE_BLOCK: o = new (arena) RenderBlock(node); break; case LIST_ITEM: o = new (arena) RenderListItem(node); break; ... }
<html> <body> <divclass="err"id="div1"> <p> this is a <spanclass="big"> big error </span> this is also a <spanclass="big"> very big error</span> error </p> </div> <divclass="err"id="div2">another error</div> </body> </html>
假设我们解析 HTML 时遇到了第二个<div>标记,我们需要为此节点创建样式上下文,并填充其样式结构。经过规则匹配,我们发现该<div>的匹配规则是第1、2和6条。这意味着规则树中已有一条路径可供我们的元素使用,我们只需要再为其添加一个节点以匹配第6条规则(规则树中的F节点)。我们将创建样式上下文并将其放入上下文树中。新的样式上下文将指向规则树中的F节点。