<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>19641</bug_id>
          
          <creation_ts>2012-10-19 19:10:05 +0000</creation_ts>
          <short_desc>example &quot;This canvas element has a couple of checkboxes&quot;  don`t work.</short_desc>
          <delta_ts>2013-09-17 00:21:59 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>HTML Canvas 2D Context</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>CR</keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="alex">__igor</reporter>
          <assigned_to name="Jay Munro">jaymunro</assigned_to>
          <cc>ian</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>76733</commentid>
    <comment_count>0</comment_count>
    <who name="alex">__igor</who>
    <bug_when>2012-10-19 19:10:05 +0000</bug_when>
    <thetext>In the  section  &quot;8 The current default path&quot; 
example &quot;This canvas element has a couple of checkboxes&quot;  don`t work.
The example&apos;s string : &quot;var metrics = context.measureText(element.labels[0].textContent);&quot;  is not  correctly. 
May be this is right: &quot;var metrics = context.measureText(element.textContent);&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81003</commentid>
    <comment_count>1</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-01-07 18:57:27 +0000</bug_when>
    <thetext>I don&apos;t think that var metrics = context.measureText(element.textContent); would work either, since it&apos;s the label that contains the text, not the checkbox. Creating ids for the labels, and passing those in seem to work. 



&lt;! doctype html&gt;
&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;stuff&lt;/title&gt;
    &lt;/head&gt;
&lt;body&gt;

&lt;canvas height=400 width=750&gt;
 &lt;label id=&quot;showAA&quot;&gt;&lt;input type=checkbox id=&quot;showA&quot;&gt; Show As&lt;/label&gt;
 &lt;label id=&quot;showBB&quot;&gt;&lt;input type=checkbox id=&quot;showB&quot;&gt; Show Bs&lt;/label&gt;
   &lt;!-- ... --&gt;
&lt;/canvas&gt;
&lt;script&gt;
  function drawCheckbox(context, element, x, y, paint) {
    context.save();
    context.font = &apos;10px sans-serif&apos;;
    context.textAlign = &apos;left&apos;;
    context.textBaseline = &apos;middle&apos;;
    var metrics = context.measureText(element.textContent);
    
    if (paint) {
      context.beginPath();
      context.strokeStyle = &apos;black&apos;;
      context.rect(x - 5, y - 5, 10, 10);
      context.stroke();
      if (element.checked) {
        context.fillStyle = &apos;black&apos;;
        context.fill();
      }
      context.fillText(element.textContent, x + 5, y);
    }
    context.beginPath();
    context.rect(x - 7, y - 7, 12 + metrics.width + 2, 14);
    if (paint &amp;&amp; context.drawCustomFocusRing(element)) {
      context.strokeStyle = &apos;silver&apos;;
      context.stroke();
    }
    context.restore();
  }
  function drawBase() { /* ... */ }
  function drawAs() { /* ... */ }
  function drawBs() { /* ... */ }
  function redraw() {
    var canvas = document.getElementsByTagName(&apos;canvas&apos;)[0];
    var context = canvas.getContext(&apos;2d&apos;);
    context.clearRect(0, 0, canvas.width, canvas.height);
    drawCheckbox(context, document.getElementById(&apos;showAA&apos;), 20, 40, true);
    drawCheckbox(context, document.getElementById(&apos;showBB&apos;), 20, 60, true);
    drawBase();
    if (document.getElementById(&apos;showA&apos;).checked)
      drawAs();
    if (document.getElementById(&apos;showB&apos;).checked)
      drawBs();
  }
  function processClick(event) {
    var canvas = document.getElementsByTagName(&apos;canvas&apos;)[0];
    var context = canvas.getContext(&apos;2d&apos;);
    var x = event.clientX;
    var y = event.clientY;
    var node = event.target;
    while (node) {
      x -= node.offsetLeft - node.scrollLeft;
      y -= node.offsetTop - node.scrollTop;
      node = node.offsetParent;
    }
    drawCheckbox(context, document.getElementById(&apos;showA&apos;), 20, 40, false);
    if (context.isPointInPath(x, y))
      document.getElementById(&apos;showA&apos;).checked = !(document.getElementById(&apos;showA&apos;).checked);
    drawCheckbox(context, document.getElementById(&apos;showB&apos;), 20, 60, false);
    if (context.isPointInPath(x, y))
      document.getElementById(&apos;showB&apos;).checked = !(document.getElementById(&apos;showB&apos;).checked);
    redraw();
  }
  document.getElementsByTagName(&apos;canvas&apos;)[0].addEventListener(&apos;focus&apos;, redraw, true);
  document.getElementsByTagName(&apos;canvas&apos;)[0].addEventListener(&apos;blur&apos;, redraw, true);
  document.getElementsByTagName(&apos;canvas&apos;)[0].addEventListener(&apos;change&apos;, redraw, true);
  document.getElementsByTagName(&apos;canvas&apos;)[0].addEventListener(&apos;click&apos;, processClick, false);
  redraw();
&lt;/script&gt;

  &lt;/body&gt;
  &lt;/html&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81140</commentid>
    <comment_count>2</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-01-09 18:52:41 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: This is an Editor&apos;s Response to your comment. If you are
satisfied with this response, please change the state of this bug to CLOSED. If
you have additional information and would like the Editor to reconsider, please
reopen this bug. If you would like to escalate the issue to the full HTML
Working Group, please add the TrackerRequest keyword to this bug, and suggest
title and text for the Tracker Issue; or you may create a Tracker Issue
yourself, if you are able to do so. For more details, see this document:

   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Resolved
Change Description: Added IDs to the labels, and used the new label IDs to get the measureText values. 
Rationale: The original code did not work correctly. measureText was trying to get a measure from the text in a checkbox that didn&apos;t have text.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81164</commentid>
    <comment_count>3</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-01-10 01:02:42 +0000</bug_when>
    <thetext>For the record, the &quot;original code&quot; (as in, what&apos;s in the WHATWG spec) works fine per spec. I don&apos;t know why it would be broken for the W3C copy.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81171</commentid>
    <comment_count>4</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-01-10 03:40:43 +0000</bug_when>
    <thetext>It didn&apos;t work in testing on Firefox, Chrome, and IE. There were actually two errors. The label[0] was causing an error since the checkboxes didn&apos;t have a label. The label element that wrapped the checkbox element contained the text, so removing the label[0] portion from the measureText and fillText statements 
and passing the id of the labels allowed it to be displayed correctly. 

Errors: 
In FireFox: 
TypeError: element.label is undefined
var metrics = context.measureText(element.label[0].textContent);

In IE: 
SCRIPT5007: Unable to get property &apos;0&apos; of undefined or null reference 
test1.html, line 19 character 5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81207</commentid>
    <comment_count>5</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-01-10 21:55:56 +0000</bug_when>
    <thetext>Reopening to research this for more optimization.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81208</commentid>
    <comment_count>6</comment_count>
    <who name="Ian &apos;Hixie&apos; Hickson">ian</who>
    <bug_when>2013-01-10 22:30:00 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; It didn&apos;t work in testing on Firefox, Chrome, and IE.

It won&apos;t work in Firefox because they don&apos;t implement .labels yet. It won&apos;t work in Chrome because they don&apos;t implement drawCustomFocusRing() yet. Dunno about IE.


&gt; the checkboxes didn&apos;t have a label

They do in the WHATWG spec&apos;s example, FWIW.


&gt; TypeError: element.label is undefined
&gt; var metrics = context.measureText(element.label[0].textContent);

The attribute is called &quot;labels&quot;. The WHATWG example gets this right as far as I can tell.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>81249</commentid>
    <comment_count>7</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-01-11 16:42:42 +0000</bug_when>
    <thetext>&gt;&gt;The attribute is called &quot;labels&quot;. The WHATWG example gets this right as far as I can tell.

Right, sorry, a typo in transfer. I was inserting and removing pieces of code to check compatibility. It does however, throw an &quot;element.labels is undefined&quot; error in firefox, and an &quot;unable to get property &apos;0&apos; of undefined or null reference&quot; in IE with the original code. 

If I&apos;m seeing this example correctly, it should demonstrate path, drawCustomFocusRing(), and isPointInPath(). To have additional unsupported features doesn&apos;t seem very practical unless they&apos;re directly related to the example. I&apos;d rather see this reduced to a simpler example that runs across browsers and demonstrates just the features we&apos;re discussing (drawCustomFocusRing() and isPointInPath()).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83948</commentid>
    <comment_count>8</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-03-04 17:44:37 +0000</bug_when>
    <thetext>EDITOR&apos;S RESPONSE: 
This is an Editor&apos;s Response to your comment. If
you are satisfied with this response, please change the state of
this bug to CLOSED. If you have additional information and would
like the Editor to reconsider, please reopen this bug. If you would
like to escalate the issue to the full HTML Working Group, please
add the TrackerRequest keyword to this bug, and suggest title and
text for the Tracker Issue; or you may create a Tracker Issue
yourself, if you are able to do so. For more details, see this
document:
       http://dev.w3.org/html5/decision-policy/decision-policy.html

Status:                      Rejected
Rationale:               suggestions appear too confusing, or not different enough in functionality than the current state.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>83949</commentid>
    <comment_count>9</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-03-04 17:45:49 +0000</bug_when>
    <thetext>reopening for fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>92689</commentid>
    <comment_count>10</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-08-28 17:34:22 +0000</bug_when>
    <thetext>Added CR keyword</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>93467</commentid>
    <comment_count>11</comment_count>
    <who name="Jay Munro">jaymunro</who>
    <bug_when>2013-09-17 00:21:59 +0000</bug_when>
    <thetext>As an example on how to call drawCustomFocusRing() and isPoingInPath() the example seems to do its job without any changes. The change suggested doesn&apos;t seem to affect how to call the two APIs.   
 

EDITOR&apos;S RESPONSE: 
This is an Editor&apos;s Response to your comment. If
you are satisfied with this response, please change the state of
this bug to CLOSED. If you have additional information and would
like the Editor to reconsider, please reopen this bug. If you would
like to escalate the issue to the full HTML Working Group, please
add the TrackerRequest keyword to this bug, and suggest title and
text for the Tracker Issue; or you may create a Tracker Issue
yourself, if you are able to do so. For more details, see this
document:
       http://dev.w3.org/html5/decision-policy/decision-policy.html

Status:                      Rejected
Rationale:               suggestions appear too confusing, or not different enough in functionality than the current state.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>